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