Replace most uses of assert by ovs_assert.
[sliver-openvswitch.git] / lib / ofp-actions.h
1 /*
2  * Copyright (c) 2012 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OFP_ACTIONS_H
18 #define OFP_ACTIONS_H 1
19
20 #include <stdint.h>
21 #include "meta-flow.h"
22 #include "ofp-errors.h"
23 #include "ofp-util.h"
24 #include "openflow/openflow.h"
25 #include "openflow/nicira-ext.h"
26 #include "openvswitch/types.h"
27
28 /* List of OVS abstracted actions.
29  *
30  * This macro is used directly only internally by this header, but the list is
31  * still of interest to developers.
32  *
33  * Each DEFINE_OFPACT invocation has the following parameters:
34  *
35  * 1. <ENUM>, used below in the enum definition of OFPACT_<ENUM>, and
36  *    elsewhere.
37  *
38  * 2. <STRUCT> corresponding to a structure "struct <STRUCT>", that must be
39  *    defined below.  This structure must be an abstract definition of the
40  *    action.  Its first member must have type "struct ofpact" and name
41  *    "ofpact".  It may be fixed length or end with a flexible array member
42  *    (e.g. "int member[];").
43  *
44  * 3. <MEMBER>, which has one of two possible values:
45  *
46  *        - If "struct <STRUCT>" is fixed-length, it must be "ofpact".
47  *
48  *        - If "struct <STRUCT>" is variable-length, it must be the name of the
49  *          flexible array member.
50  */
51 #define OFPACTS                                                     \
52     /* Output. */                                                   \
53     DEFINE_OFPACT(OUTPUT,          ofpact_output,        ofpact)    \
54     DEFINE_OFPACT(CONTROLLER,      ofpact_controller,    ofpact)    \
55     DEFINE_OFPACT(ENQUEUE,         ofpact_enqueue,       ofpact)    \
56     DEFINE_OFPACT(OUTPUT_REG,      ofpact_output_reg,    ofpact)    \
57     DEFINE_OFPACT(BUNDLE,          ofpact_bundle,        slaves)    \
58                                                                     \
59     /* Header changes. */                                           \
60     DEFINE_OFPACT(SET_VLAN_VID,    ofpact_vlan_vid,      ofpact)    \
61     DEFINE_OFPACT(SET_VLAN_PCP,    ofpact_vlan_pcp,      ofpact)    \
62     DEFINE_OFPACT(STRIP_VLAN,      ofpact_null,          ofpact)    \
63     DEFINE_OFPACT(PUSH_VLAN,       ofpact_null,          ofpact)    \
64     DEFINE_OFPACT(SET_ETH_SRC,     ofpact_mac,           ofpact)    \
65     DEFINE_OFPACT(SET_ETH_DST,     ofpact_mac,           ofpact)    \
66     DEFINE_OFPACT(SET_IPV4_SRC,    ofpact_ipv4,          ofpact)    \
67     DEFINE_OFPACT(SET_IPV4_DST,    ofpact_ipv4,          ofpact)    \
68     DEFINE_OFPACT(SET_IPV4_DSCP,   ofpact_dscp,          ofpact)    \
69     DEFINE_OFPACT(SET_L4_SRC_PORT, ofpact_l4_port,       ofpact)    \
70     DEFINE_OFPACT(SET_L4_DST_PORT, ofpact_l4_port,       ofpact)    \
71     DEFINE_OFPACT(REG_MOVE,        ofpact_reg_move,      ofpact)    \
72     DEFINE_OFPACT(REG_LOAD,        ofpact_reg_load,      ofpact)    \
73     DEFINE_OFPACT(DEC_TTL,         ofpact_cnt_ids,       cnt_ids)   \
74                                                                     \
75     /* Metadata. */                                                 \
76     DEFINE_OFPACT(SET_TUNNEL,      ofpact_tunnel,        ofpact)    \
77     DEFINE_OFPACT(SET_QUEUE,       ofpact_queue,         ofpact)    \
78     DEFINE_OFPACT(POP_QUEUE,       ofpact_null,          ofpact)    \
79     DEFINE_OFPACT(FIN_TIMEOUT,     ofpact_fin_timeout,   ofpact)    \
80                                                                     \
81     /* Flow table interaction. */                                   \
82     DEFINE_OFPACT(RESUBMIT,        ofpact_resubmit,      ofpact)    \
83     DEFINE_OFPACT(LEARN,           ofpact_learn,         specs)     \
84                                                                     \
85     /* Arithmetic. */                                               \
86     DEFINE_OFPACT(MULTIPATH,       ofpact_multipath,     ofpact)    \
87     DEFINE_OFPACT(AUTOPATH,        ofpact_autopath,      ofpact)    \
88                                                                     \
89     /* Other. */                                                    \
90     DEFINE_OFPACT(NOTE,            ofpact_note,          data)      \
91     DEFINE_OFPACT(EXIT,            ofpact_null,          ofpact)    \
92                                                                     \
93     /* Instructions */                                              \
94     /* XXX Write-Actions */                                         \
95     DEFINE_OFPACT(WRITE_METADATA,  ofpact_metadata,      ofpact)    \
96     DEFINE_OFPACT(CLEAR_ACTIONS,   ofpact_null,          ofpact)    \
97     DEFINE_OFPACT(GOTO_TABLE,      ofpact_goto_table,    ofpact)
98
99 /* enum ofpact_type, with a member OFPACT_<ENUM> for each action. */
100 enum OVS_PACKED_ENUM ofpact_type {
101 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) OFPACT_##ENUM,
102     OFPACTS
103 #undef DEFINE_OFPACT
104 };
105
106 /* N_OFPACTS, the number of values of "enum ofpact_type". */
107 enum {
108     N_OFPACTS =
109 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) + 1
110     OFPACTS
111 #undef DEFINE_OFPACT
112 };
113
114 /* Header for an action.
115  *
116  * Each action is a structure "struct ofpact_*" that begins with "struct
117  * ofpact", usually followed by other data that describes the action.  Actions
118  * are padded out to a multiple of OFPACT_ALIGNTO bytes in length.
119  *
120  * The 'compat' member is special:
121  *
122  *     - Most "struct ofpact"s correspond to one particular kind of OpenFlow
123  *       action, at least in a given OpenFlow version.  For example,
124  *       OFPACT_SET_VLAN_VID corresponds to OFPAT10_SET_VLAN_VID in OpenFlow
125  *       1.0.
126  *
127  *       For such actions, the 'compat' member is not meaningful and generally
128  *       should be zero.
129  *
130  *     - A few "struct ofpact"s correspond to multiple OpenFlow actions.  For
131  *       example, OFPACT_SET_TUNNEL can be NXAST_SET_TUNNEL or
132  *       NXAST_SET_TUNNEL64.  In these cases, if the "struct ofpact" originated
133  *       from OpenFlow, then we want to make sure that, if it gets translated
134  *       back to OpenFlow later, it is translated back to the same action type.
135  *       (Otherwise, we'd violate the promise made in DESIGN, in the "Action
136  *       Reproduction" section.)
137  *
138  *       For such actions, the 'compat' member should be the original action
139  *       type.  (If the action didn't originate from OpenFlow, then setting
140  *       'compat' to zero should be fine: code to translate the ofpact to
141  *       OpenFlow must tolerate this case.)
142  */
143 struct ofpact {
144     enum ofpact_type type;      /* OFPACT_*. */
145     enum ofputil_action_code compat; /* Original type when added, if any. */
146     uint16_t len;               /* Length of the action, in bytes, including
147                                  * struct ofpact, excluding padding. */
148 };
149
150 #ifdef __GNUC__
151 /* Make sure that OVS_PACKED_ENUM really worked. */
152 BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4);
153 #endif
154
155 /* Alignment. */
156 #define OFPACT_ALIGNTO 8
157 #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO)
158
159 static inline struct ofpact *
160 ofpact_next(const struct ofpact *ofpact)
161 {
162     return (void *) ((uint8_t *) ofpact + OFPACT_ALIGN(ofpact->len));
163 }
164
165 static inline struct ofpact *
166 ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len)
167 {
168     return (void *) ((uint8_t *) ofpacts + ofpacts_len);
169 }
170
171 /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts
172  * starting at OFPACTS. */
173 #define OFPACT_FOR_EACH(POS, OFPACTS, OFPACTS_LEN)                      \
174     for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN);  \
175          (POS) = ofpact_next(POS))
176 \f
177 /* Action structure for each OFPACT_*. */
178
179 /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS.
180  *
181  * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT,
182  * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS.
183  *
184  * Action structure for actions that do not have any extra data beyond the
185  * action type. */
186 struct ofpact_null {
187     struct ofpact ofpact;
188 };
189
190 /* OFPACT_OUTPUT.
191  *
192  * Used for OFPAT10_OUTPUT. */
193 struct ofpact_output {
194     struct ofpact ofpact;
195     uint16_t port;              /* Output port. */
196     uint16_t max_len;           /* Max send len, for port OFPP_CONTROLLER. */
197 };
198
199 /* OFPACT_CONTROLLER.
200  *
201  * Used for NXAST_CONTROLLER. */
202 struct ofpact_controller {
203     struct ofpact ofpact;
204     uint16_t max_len;           /* Maximum length to send to controller. */
205     uint16_t controller_id;     /* Controller ID to send packet-in. */
206     enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */
207 };
208
209 /* OFPACT_ENQUEUE.
210  *
211  * Used for OFPAT10_ENQUEUE. */
212 struct ofpact_enqueue {
213     struct ofpact ofpact;
214     uint16_t port;
215     uint32_t queue;
216 };
217
218 /* OFPACT_OUTPUT_REG.
219  *
220  * Used for NXAST_OUTPUT_REG. */
221 struct ofpact_output_reg {
222     struct ofpact ofpact;
223     struct mf_subfield src;
224     uint16_t max_len;
225 };
226
227 /* OFPACT_BUNDLE.
228  *
229  * Used for NXAST_BUNDLE. */
230 struct ofpact_bundle {
231     struct ofpact ofpact;
232
233     /* Slave choice algorithm to apply to hash value. */
234     enum nx_bd_algorithm algorithm;
235
236     /* What fields to hash and how. */
237     enum nx_hash_fields fields;
238     uint16_t basis;             /* Universal hash parameter. */
239
240     struct mf_subfield dst;
241
242     /* Slaves for output. */
243     unsigned int n_slaves;
244     uint16_t slaves[];
245 };
246
247 /* OFPACT_SET_VLAN_VID.
248  *
249  * Used for OFPAT10_SET_VLAN_VID. */
250 struct ofpact_vlan_vid {
251     struct ofpact ofpact;
252     uint16_t vlan_vid;          /* VLAN VID in low 12 bits, 0 in other bits. */
253 };
254
255 /* OFPACT_SET_VLAN_PCP.
256  *
257  * Used for OFPAT10_SET_VLAN_PCP. */
258 struct ofpact_vlan_pcp {
259     struct ofpact ofpact;
260     uint8_t vlan_pcp;           /* VLAN PCP in low 3 bits, 0 in other bits. */
261 };
262
263 /* OFPACT_SET_ETH_SRC, OFPACT_SET_ETH_DST.
264  *
265  * Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */
266 struct ofpact_mac {
267     struct ofpact ofpact;
268     uint8_t mac[ETH_ADDR_LEN];
269 };
270
271 /* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST.
272  *
273  * Used for OFPAT10_SET_NW_SRC, OFPAT10_SET_NW_DST. */
274 struct ofpact_ipv4 {
275     struct ofpact ofpact;
276     ovs_be32 ipv4;
277 };
278
279 /* OFPACT_SET_IPV4_DSCP.
280  *
281  * Used for OFPAT10_SET_NW_TOS. */
282 struct ofpact_dscp {
283     struct ofpact ofpact;
284     uint8_t dscp;               /* DSCP in high 6 bits, rest ignored. */
285 };
286
287 /* OFPACT_SET_L4_SRC_PORT, OFPACT_SET_L4_DST_PORT.
288  *
289  * Used for OFPAT10_SET_TP_SRC, OFPAT10_SET_TP_DST. */
290 struct ofpact_l4_port {
291     struct ofpact ofpact;
292     uint16_t port;              /* TCP or UDP port number. */
293 };
294
295 /* OFPACT_REG_MOVE.
296  *
297  * Used for NXAST_REG_MOVE. */
298 struct ofpact_reg_move {
299     struct ofpact ofpact;
300     struct mf_subfield src;
301     struct mf_subfield dst;
302 };
303
304 /* OFPACT_REG_LOAD.
305  *
306  * Used for NXAST_REG_LOAD, OFPAT12_SET_FIELD. */
307 struct ofpact_reg_load {
308     struct ofpact ofpact;
309     struct mf_subfield dst;
310     union mf_subvalue subvalue; /* Least-significant bits are used. */
311 };
312
313 /* OFPACT_SET_TUNNEL.
314  *
315  * Used for NXAST_SET_TUNNEL, NXAST_SET_TUNNEL64. */
316 struct ofpact_tunnel {
317     struct ofpact ofpact;
318     uint64_t tun_id;
319 };
320
321 /* OFPACT_SET_QUEUE.
322  *
323  * Used for NXAST_SET_QUEUE. */
324 struct ofpact_queue {
325     struct ofpact ofpact;
326     uint32_t queue_id;
327 };
328
329 /* OFPACT_FIN_TIMEOUT.
330  *
331  * Used for NXAST_FIN_TIMEOUT. */
332 struct ofpact_fin_timeout {
333     struct ofpact ofpact;
334     uint16_t fin_idle_timeout;
335     uint16_t fin_hard_timeout;
336 };
337
338 /* OFPACT_WRITE_METADATA.
339  *
340  * Used for NXAST_WRITE_METADATA. */
341 struct ofpact_metadata {
342     struct ofpact ofpact;
343     ovs_be64 metadata;
344     ovs_be64 mask;
345 };
346
347 /* OFPACT_RESUBMIT.
348  *
349  * Used for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE. */
350 struct ofpact_resubmit {
351     struct ofpact ofpact;
352     uint16_t in_port;
353     uint8_t table_id;
354 };
355
356 /* Part of struct ofpact_learn, below. */
357 struct ofpact_learn_spec {
358     int n_bits;
359
360     int src_type;
361     struct mf_subfield src;
362     union mf_subvalue src_imm;
363
364     int dst_type;
365     struct mf_subfield dst;
366 };
367
368 /* OFPACT_LEARN.
369  *
370  * Used for NXAST_LEARN. */
371 struct ofpact_learn {
372     struct ofpact ofpact;
373
374     uint16_t idle_timeout;      /* Idle time before discarding (seconds). */
375     uint16_t hard_timeout;      /* Max time before discarding (seconds). */
376     uint16_t priority;          /* Priority level of flow entry. */
377     uint64_t cookie;            /* Cookie for new flow. */
378     uint16_t flags;             /* Either 0 or OFPFF_SEND_FLOW_REM. */
379     uint8_t table_id;           /* Table to insert flow entry. */
380     uint16_t fin_idle_timeout;  /* Idle timeout after FIN, if nonzero. */
381     uint16_t fin_hard_timeout;  /* Hard timeout after FIN, if nonzero. */
382
383     unsigned int n_specs;
384     struct ofpact_learn_spec specs[];
385 };
386
387 /* OFPACT_MULTIPATH.
388  *
389  * Used for NXAST_MULTIPATH. */
390 struct ofpact_multipath {
391     struct ofpact ofpact;
392
393     /* What fields to hash and how. */
394     enum nx_hash_fields fields;
395     uint16_t basis;             /* Universal hash parameter. */
396
397     /* Multipath link choice algorithm to apply to hash value. */
398     enum nx_mp_algorithm algorithm;
399     uint16_t max_link;          /* Number of output links, minus 1. */
400     uint32_t arg;               /* Algorithm-specific argument. */
401
402     /* Where to store the result. */
403     struct mf_subfield dst;
404 };
405
406 /* OFPACT_AUTOPATH.
407  *
408  * Used for NXAST_AUTOPATH. */
409 struct ofpact_autopath {
410     struct ofpact ofpact;
411     struct mf_subfield dst;
412     uint32_t port;
413 };
414
415 /* OFPACT_NOTE.
416  *
417  * Used for NXAST_NOTE. */
418 struct ofpact_note {
419     struct ofpact ofpact;
420     size_t length;
421     uint8_t data[];
422 };
423
424 /* OFPACT_DEC_TTL.
425  *
426  * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */
427 struct ofpact_cnt_ids {
428     struct ofpact ofpact;
429
430     /* Controller ids. */
431     unsigned int n_controllers;
432     uint16_t cnt_ids[];
433 };
434
435 /* OFPACT_GOTO_TABLE
436  *
437  * Used for OFPIT11_GOTO_TABLE */
438 struct ofpact_goto_table {
439     struct ofpact ofpact;
440     uint8_t table_id;
441 };
442
443 /* Converting OpenFlow to ofpacts. */
444 enum ofperr ofpacts_pull_openflow10(struct ofpbuf *openflow,
445                                     unsigned int actions_len,
446                                     struct ofpbuf *ofpacts);
447 enum ofperr ofpacts_pull_openflow11_actions(struct ofpbuf *openflow,
448                                             unsigned int actions_len,
449                                             struct ofpbuf *ofpacts);
450 enum ofperr ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
451                                                  unsigned int instructions_len,
452                                                  struct ofpbuf *ofpacts);
453 enum ofperr ofpacts_check(const struct ofpact[], size_t ofpacts_len,
454                           const struct flow *, int max_ports);
455 enum ofperr ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len);
456
457 /* Converting ofpacts to OpenFlow. */
458 void ofpacts_put_openflow10(const struct ofpact[], size_t ofpacts_len,
459                             struct ofpbuf *openflow);
460 size_t ofpacts_put_openflow11_actions(const struct ofpact[], size_t ofpacts_len,
461                                       struct ofpbuf *openflow);
462 void ofpacts_put_openflow11_instructions(const struct ofpact[],
463                                          size_t ofpacts_len,
464                                          struct ofpbuf *openflow);
465
466 /* Working with ofpacts. */
467 bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len,
468                             uint16_t port);
469 bool ofpacts_equal(const struct ofpact a[], size_t a_len,
470                    const struct ofpact b[], size_t b_len);
471
472 /* Formatting ofpacts.
473  *
474  * (For parsing ofpacts, see ofp-parse.h.) */
475 void ofpacts_format(const struct ofpact[], size_t ofpacts_len, struct ds *);
476
477 /* Internal use by the helpers below. */
478 void ofpact_init(struct ofpact *, enum ofpact_type, size_t len);
479 void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len);
480
481 /* For each OFPACT_<ENUM> with a corresponding struct <STRUCT>, this defines
482  * the following commonly useful functions:
483  *
484  *   struct <STRUCT> *ofpact_put_<ENUM>(struct ofpbuf *ofpacts);
485  *
486  *     Appends a new 'ofpact', of length OFPACT_<ENUM>_RAW_SIZE, to 'ofpacts',
487  *     initializes it with ofpact_init_<ENUM>(), and returns it.  Also sets
488  *     'ofpacts->l2' to the returned action.
489  *
490  *     After using this function to add a variable-length action, add the
491  *     elements of the flexible array (e.g. with ofpbuf_put()), then use
492  *     ofpact_update_len() to update the length embedded into the action.
493  *     (Keep in mind the need to refresh the structure from 'ofpacts->l2' after
494  *     adding data to 'ofpacts'.)
495  *
496  *   struct <STRUCT> *ofpact_get_<ENUM>(const struct ofpact *ofpact);
497  *
498  *     Returns 'ofpact' cast to "struct <STRUCT> *".  'ofpact->type' must be
499  *     OFPACT_<ENUM>.
500  *
501  * as well as the following more rarely useful definitions:
502  *
503  *   void ofpact_init_<ENUM>(struct <STRUCT> *ofpact);
504  *
505  *     Initializes the parts of 'ofpact' that identify it as having type
506  *     OFPACT_<ENUM> and length OFPACT_<ENUM>_RAW_SIZE and zeros the rest.
507  *
508  *   <ENUM>_RAW_SIZE
509  *
510  *     The size of the action structure.  For a fixed-length action, this is
511  *     sizeof(struct <STRUCT>).  For a variable-length action, this is the
512  *     offset to the variable-length part.
513  *
514  *   <ENUM>_SIZE
515  *
516  *     An integer constant, the value of OFPACT_<ENUM>_RAW_SIZE rounded up to a
517  *     multiple of OFPACT_ALIGNTO.
518  */
519 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER)                             \
520     BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0);            \
521                                                                         \
522     enum { OFPACT_##ENUM##_RAW_SIZE                                     \
523            = (offsetof(struct STRUCT, MEMBER)                           \
524               ? offsetof(struct STRUCT, MEMBER)                         \
525               : sizeof(struct STRUCT)) };                               \
526                                                                         \
527     enum { OFPACT_##ENUM##_SIZE                                         \
528            = ROUND_UP(OFPACT_##ENUM##_RAW_SIZE, OFPACT_ALIGNTO) };      \
529                                                                         \
530     static inline struct STRUCT *                                       \
531     ofpact_get_##ENUM(const struct ofpact *ofpact)                      \
532     {                                                                   \
533         ovs_assert(ofpact->type == OFPACT_##ENUM);                      \
534         return (struct STRUCT *) ofpact;                                \
535     }                                                                   \
536                                                                         \
537     static inline struct STRUCT *                                       \
538     ofpact_put_##ENUM(struct ofpbuf *ofpacts)                           \
539     {                                                                   \
540         return ofpact_put(ofpacts, OFPACT_##ENUM,                       \
541                           OFPACT_##ENUM##_RAW_SIZE);                    \
542     }                                                                   \
543                                                                         \
544     static inline void                                                  \
545     ofpact_init_##ENUM(struct STRUCT *ofpact)                           \
546     {                                                                   \
547         ofpact_init(&ofpact->ofpact, OFPACT_##ENUM,                     \
548                     OFPACT_##ENUM##_RAW_SIZE);                          \
549     }
550 OFPACTS
551 #undef DEFINE_OFPACT
552
553 /* Functions to use after adding ofpacts to a buffer. */
554 void ofpact_update_len(struct ofpbuf *, struct ofpact *);
555 void ofpact_pad(struct ofpbuf *);
556
557 /* OpenFlow 1.1 instructions.
558  * The order is sorted in execution order. Not in the value of OFPIT11_xxx.
559  * It is enforced on parser from text string.
560  */
561 #define OVS_INSTRUCTIONS                                    \
562     DEFINE_INST(OFPIT11_APPLY_ACTIONS,                      \
563                 ofp11_instruction_actions,        true,     \
564                 "apply_actions")                            \
565                                                             \
566     DEFINE_INST(OFPIT11_CLEAR_ACTIONS,                      \
567                 ofp11_instruction,                false,    \
568                 "clear_actions")                            \
569                                                             \
570     DEFINE_INST(OFPIT11_WRITE_ACTIONS,                      \
571                 ofp11_instruction_actions,        true,     \
572                 "write_actions")                            \
573                                                             \
574     DEFINE_INST(OFPIT11_WRITE_METADATA,                     \
575                 ofp11_instruction_write_metadata, false,    \
576                 "write_metadata")                           \
577                                                             \
578     DEFINE_INST(OFPIT11_GOTO_TABLE,                         \
579                 ofp11_instruction_goto_table,     false,    \
580                 "goto_table")
581
582 enum ovs_instruction_type {
583 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) OVSINST_##ENUM,
584     OVS_INSTRUCTIONS
585 #undef DEFINE_INST
586 };
587
588 enum {
589 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
590     N_OVS_INSTRUCTIONS = OVS_INSTRUCTIONS
591 #undef DEFINE_INST
592 };
593
594
595 static inline bool
596 ofpact_is_instruction(const struct ofpact *a)
597 {
598     /* XXX Write-Actions */
599     return a->type == OFPACT_CLEAR_ACTIONS
600         || a->type == OFPACT_WRITE_METADATA
601         || a->type == OFPACT_GOTO_TABLE;
602 }
603
604 const char *ofpact_instruction_name_from_type(enum ovs_instruction_type type);
605 int ofpact_instruction_type_from_name(const char *name);
606
607 void ofpact_set_field_init(struct ofpact_reg_load *load,
608                            const struct mf_field *mf, const void *src);
609
610 #endif /* ofp-actions.h */