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