2 * Copyright (c) 2012, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #define OFP_ACTIONS_H 1
22 #include "meta-flow.h"
23 #include "ofp-errors.h"
25 #include "openflow/openflow.h"
26 #include "openflow/nicira-ext.h"
27 #include "openvswitch/types.h"
29 /* List of OVS abstracted actions.
31 * This macro is used directly only internally by this header, but the list is
32 * still of interest to developers.
34 * Each DEFINE_OFPACT invocation has the following parameters:
36 * 1. <ENUM>, used below in the enum definition of OFPACT_<ENUM>, and
39 * 2. <STRUCT> corresponding to a structure "struct <STRUCT>", that must be
40 * defined below. This structure must be an abstract definition of the
41 * action. Its first member must have type "struct ofpact" and name
42 * "ofpact". It may be fixed length or end with a flexible array member
43 * (e.g. "int member[];").
45 * 3. <MEMBER>, which has one of two possible values:
47 * - If "struct <STRUCT>" is fixed-length, it must be "ofpact".
49 * - If "struct <STRUCT>" is variable-length, it must be the name of the
50 * flexible array member.
54 DEFINE_OFPACT(OUTPUT, ofpact_output, ofpact) \
55 DEFINE_OFPACT(GROUP, ofpact_group, ofpact) \
56 DEFINE_OFPACT(CONTROLLER, ofpact_controller, ofpact) \
57 DEFINE_OFPACT(ENQUEUE, ofpact_enqueue, ofpact) \
58 DEFINE_OFPACT(OUTPUT_REG, ofpact_output_reg, ofpact) \
59 DEFINE_OFPACT(BUNDLE, ofpact_bundle, slaves) \
61 /* Header changes. */ \
62 DEFINE_OFPACT(SET_FIELD, ofpact_set_field, ofpact) \
63 DEFINE_OFPACT(SET_VLAN_VID, ofpact_vlan_vid, ofpact) \
64 DEFINE_OFPACT(SET_VLAN_PCP, ofpact_vlan_pcp, ofpact) \
65 DEFINE_OFPACT(STRIP_VLAN, ofpact_null, ofpact) \
66 DEFINE_OFPACT(PUSH_VLAN, ofpact_null, ofpact) \
67 DEFINE_OFPACT(SET_ETH_SRC, ofpact_mac, ofpact) \
68 DEFINE_OFPACT(SET_ETH_DST, ofpact_mac, ofpact) \
69 DEFINE_OFPACT(SET_IPV4_SRC, ofpact_ipv4, ofpact) \
70 DEFINE_OFPACT(SET_IPV4_DST, ofpact_ipv4, ofpact) \
71 DEFINE_OFPACT(SET_IP_DSCP, ofpact_dscp, ofpact) \
72 DEFINE_OFPACT(SET_IP_ECN, ofpact_ecn, ofpact) \
73 DEFINE_OFPACT(SET_IP_TTL, ofpact_ip_ttl, ofpact) \
74 DEFINE_OFPACT(SET_L4_SRC_PORT, ofpact_l4_port, ofpact) \
75 DEFINE_OFPACT(SET_L4_DST_PORT, ofpact_l4_port, ofpact) \
76 DEFINE_OFPACT(REG_MOVE, ofpact_reg_move, ofpact) \
77 DEFINE_OFPACT(REG_LOAD, ofpact_reg_load, ofpact) \
78 DEFINE_OFPACT(STACK_PUSH, ofpact_stack, ofpact) \
79 DEFINE_OFPACT(STACK_POP, ofpact_stack, ofpact) \
80 DEFINE_OFPACT(DEC_TTL, ofpact_cnt_ids, cnt_ids) \
81 DEFINE_OFPACT(SET_MPLS_LABEL, ofpact_mpls_label, ofpact) \
82 DEFINE_OFPACT(SET_MPLS_TC, ofpact_mpls_tc, ofpact) \
83 DEFINE_OFPACT(SET_MPLS_TTL, ofpact_mpls_ttl, ofpact) \
84 DEFINE_OFPACT(DEC_MPLS_TTL, ofpact_null, ofpact) \
85 DEFINE_OFPACT(PUSH_MPLS, ofpact_push_mpls, ofpact) \
86 DEFINE_OFPACT(POP_MPLS, ofpact_pop_mpls, ofpact) \
89 DEFINE_OFPACT(SET_TUNNEL, ofpact_tunnel, ofpact) \
90 DEFINE_OFPACT(SET_QUEUE, ofpact_queue, ofpact) \
91 DEFINE_OFPACT(POP_QUEUE, ofpact_null, ofpact) \
92 DEFINE_OFPACT(FIN_TIMEOUT, ofpact_fin_timeout, ofpact) \
94 /* Flow table interaction. */ \
95 DEFINE_OFPACT(RESUBMIT, ofpact_resubmit, ofpact) \
96 DEFINE_OFPACT(LEARN, ofpact_learn, specs) \
99 DEFINE_OFPACT(MULTIPATH, ofpact_multipath, ofpact) \
102 DEFINE_OFPACT(NOTE, ofpact_note, data) \
103 DEFINE_OFPACT(EXIT, ofpact_null, ofpact) \
104 DEFINE_OFPACT(SAMPLE, ofpact_sample, ofpact) \
107 DEFINE_OFPACT(METER, ofpact_meter, ofpact) \
108 DEFINE_OFPACT(CLEAR_ACTIONS, ofpact_null, ofpact) \
109 DEFINE_OFPACT(WRITE_ACTIONS, ofpact_nest, ofpact) \
110 DEFINE_OFPACT(WRITE_METADATA, ofpact_metadata, ofpact) \
111 DEFINE_OFPACT(GOTO_TABLE, ofpact_goto_table, ofpact)
113 /* enum ofpact_type, with a member OFPACT_<ENUM> for each action. */
114 enum OVS_PACKED_ENUM ofpact_type {
115 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) OFPACT_##ENUM,
120 /* N_OFPACTS, the number of values of "enum ofpact_type". */
123 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) + 1
128 /* Header for an action.
130 * Each action is a structure "struct ofpact_*" that begins with "struct
131 * ofpact", usually followed by other data that describes the action. Actions
132 * are padded out to a multiple of OFPACT_ALIGNTO bytes in length.
134 * The 'compat' member is special:
136 * - Most "struct ofpact"s correspond to one particular kind of OpenFlow
137 * action, at least in a given OpenFlow version. For example,
138 * OFPACT_SET_VLAN_VID corresponds to OFPAT10_SET_VLAN_VID in OpenFlow
141 * For such actions, the 'compat' member is not meaningful and generally
144 * - A few "struct ofpact"s correspond to multiple OpenFlow actions. For
145 * example, OFPACT_SET_TUNNEL can be NXAST_SET_TUNNEL or
146 * NXAST_SET_TUNNEL64. In these cases, if the "struct ofpact" originated
147 * from OpenFlow, then we want to make sure that, if it gets translated
148 * back to OpenFlow later, it is translated back to the same action type.
149 * (Otherwise, we'd violate the promise made in DESIGN, in the "Action
150 * Reproduction" section.)
152 * For such actions, the 'compat' member should be the original action
153 * type. (If the action didn't originate from OpenFlow, then setting
154 * 'compat' to zero should be fine: code to translate the ofpact to
155 * OpenFlow must tolerate this case.)
158 enum ofpact_type type; /* OFPACT_*. */
159 enum ofputil_action_code compat; /* Original type when added, if any. */
160 uint16_t len; /* Length of the action, in bytes, including
161 * struct ofpact, excluding padding. */
165 /* Make sure that OVS_PACKED_ENUM really worked. */
166 BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4);
170 #define OFPACT_ALIGNTO 8
171 #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO)
173 static inline struct ofpact *
174 ofpact_next(const struct ofpact *ofpact)
176 return (void *) ((uint8_t *) ofpact + OFPACT_ALIGN(ofpact->len));
179 static inline struct ofpact *
180 ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len)
182 return (void *) ((uint8_t *) ofpacts + ofpacts_len);
185 /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts
186 * starting at OFPACTS. */
187 #define OFPACT_FOR_EACH(POS, OFPACTS, OFPACTS_LEN) \
188 for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN); \
189 (POS) = ofpact_next(POS))
191 /* Action structure for each OFPACT_*. */
193 /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS.
195 * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT,
196 * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS.
198 * Action structure for actions that do not have any extra data beyond the
201 struct ofpact ofpact;
206 * Used for OFPAT10_OUTPUT. */
207 struct ofpact_output {
208 struct ofpact ofpact;
209 ofp_port_t port; /* Output port. */
210 uint16_t max_len; /* Max send len, for port OFPP_CONTROLLER. */
213 /* OFPACT_CONTROLLER.
215 * Used for NXAST_CONTROLLER. */
216 struct ofpact_controller {
217 struct ofpact ofpact;
218 uint16_t max_len; /* Maximum length to send to controller. */
219 uint16_t controller_id; /* Controller ID to send packet-in. */
220 enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */
225 * Used for OFPAT10_ENQUEUE. */
226 struct ofpact_enqueue {
227 struct ofpact ofpact;
232 /* OFPACT_OUTPUT_REG.
234 * Used for NXAST_OUTPUT_REG. */
235 struct ofpact_output_reg {
236 struct ofpact ofpact;
237 struct mf_subfield src;
243 * Used for NXAST_BUNDLE. */
244 struct ofpact_bundle {
245 struct ofpact ofpact;
247 /* Slave choice algorithm to apply to hash value. */
248 enum nx_bd_algorithm algorithm;
250 /* What fields to hash and how. */
251 enum nx_hash_fields fields;
252 uint16_t basis; /* Universal hash parameter. */
254 struct mf_subfield dst;
256 /* Slaves for output. */
257 unsigned int n_slaves;
261 /* OFPACT_SET_VLAN_VID.
263 * We keep track if vlan was present at action validation time to avoid a
264 * PUSH_VLAN when translating to OpenFlow 1.1+.
266 * We also keep the originating OFPUTIL action code in ofpact.compat.
268 * Used for OFPAT10_SET_VLAN_VID and OFPAT11_SET_VLAN_VID. */
269 struct ofpact_vlan_vid {
270 struct ofpact ofpact;
271 uint16_t vlan_vid; /* VLAN VID in low 12 bits, 0 in other bits. */
272 bool push_vlan_if_needed; /* OF 1.0 semantics if true. */
273 bool flow_has_vlan; /* VLAN present at action validation time? */
276 /* OFPACT_SET_VLAN_PCP.
278 * We keep track if vlan was present at action validation time to avoid a
279 * PUSH_VLAN when translating to OpenFlow 1.1+.
281 * We also keep the originating OFPUTIL action code in ofpact.compat.
283 * Used for OFPAT10_SET_VLAN_PCP and OFPAT11_SET_VLAN_PCP. */
284 struct ofpact_vlan_pcp {
285 struct ofpact ofpact;
286 uint8_t vlan_pcp; /* VLAN PCP in low 3 bits, 0 in other bits. */
287 bool push_vlan_if_needed; /* OF 1.0 semantics if true. */
288 bool flow_has_vlan; /* VLAN present at action validation time? */
291 /* OFPACT_SET_ETH_SRC, OFPACT_SET_ETH_DST.
293 * Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */
295 struct ofpact ofpact;
296 uint8_t mac[ETH_ADDR_LEN];
299 /* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST.
301 * Used for OFPAT10_SET_NW_SRC, OFPAT10_SET_NW_DST. */
303 struct ofpact ofpact;
307 /* OFPACT_SET_IP_DSCP.
309 * Used for OFPAT10_SET_NW_TOS. */
311 struct ofpact ofpact;
312 uint8_t dscp; /* DSCP in high 6 bits, rest ignored. */
315 /* OFPACT_SET_IP_ECN.
317 * Used for OFPAT11_SET_NW_ECN. */
319 struct ofpact ofpact;
320 uint8_t ecn; /* ECN in low 2 bits, rest ignored. */
323 /* OFPACT_SET_IP_TTL.
325 * Used for OFPAT11_SET_NW_TTL. */
326 struct ofpact_ip_ttl {
327 struct ofpact ofpact;
331 /* OFPACT_SET_L4_SRC_PORT, OFPACT_SET_L4_DST_PORT.
333 * Used for OFPAT10_SET_TP_SRC, OFPAT10_SET_TP_DST. */
334 struct ofpact_l4_port {
335 struct ofpact ofpact;
336 uint16_t port; /* TCP, UDP or SCTP port number. */
337 uint8_t flow_ip_proto; /* IP proto from corresponding match, or 0 */
342 * Used for NXAST_REG_MOVE. */
343 struct ofpact_reg_move {
344 struct ofpact ofpact;
345 struct mf_subfield src;
346 struct mf_subfield dst;
349 /* OFPACT_STACK_PUSH.
351 * Used for NXAST_STACK_PUSH and NXAST_STACK_POP. */
352 struct ofpact_stack {
353 struct ofpact ofpact;
354 struct mf_subfield subfield;
359 * Used for NXAST_REG_LOAD. */
360 struct ofpact_reg_load {
361 struct ofpact ofpact;
362 struct mf_subfield dst;
363 union mf_subvalue subvalue; /* Least-significant bits are used. */
366 /* The position in the packet at which to insert an MPLS header.
368 * Used NXAST_PUSH_MPLS, OFPAT11_PUSH_MPLS. */
369 enum ofpact_mpls_position {
370 /* Add the MPLS LSE after the Ethernet header but before any VLAN tags.
371 * OpenFlow 1.3+ requires this behavior. */
372 OFPACT_MPLS_BEFORE_VLAN,
374 /* Add the MPLS LSE after the Ethernet header and any VLAN tags.
375 * OpenFlow 1.1 and 1.2 require this behavior. */
376 OFPACT_MPLS_AFTER_VLAN
381 * Used for OFPAT12_SET_FIELD. */
382 struct ofpact_set_field {
383 struct ofpact ofpact;
384 const struct mf_field *field;
385 bool flow_has_vlan; /* VLAN present at action validation time. */
386 union mf_value value;
389 /* OFPACT_PUSH_VLAN/MPLS/PBB
391 * Used for NXAST_PUSH_MPLS, OFPAT11_PUSH_MPLS. */
392 struct ofpact_push_mpls {
393 struct ofpact ofpact;
395 enum ofpact_mpls_position position;
400 * Used for NXAST_POP_MPLS, OFPAT11_POP_MPLS.. */
401 struct ofpact_pop_mpls {
402 struct ofpact ofpact;
406 /* OFPACT_SET_TUNNEL.
408 * Used for NXAST_SET_TUNNEL, NXAST_SET_TUNNEL64. */
409 struct ofpact_tunnel {
410 struct ofpact ofpact;
416 * Used for NXAST_SET_QUEUE. */
417 struct ofpact_queue {
418 struct ofpact ofpact;
422 /* OFPACT_FIN_TIMEOUT.
424 * Used for NXAST_FIN_TIMEOUT. */
425 struct ofpact_fin_timeout {
426 struct ofpact ofpact;
427 uint16_t fin_idle_timeout;
428 uint16_t fin_hard_timeout;
431 /* OFPACT_WRITE_METADATA.
433 * Used for NXAST_WRITE_METADATA. */
434 struct ofpact_metadata {
435 struct ofpact ofpact;
442 * Used for OFPIT13_METER. */
443 struct ofpact_meter {
444 struct ofpact ofpact;
448 /* OFPACT_WRITE_ACTIONS.
450 * Used for OFPIT11_WRITE_ACTIONS. */
452 struct ofpact ofpact;
453 uint8_t pad[OFPACT_ALIGN(sizeof(struct ofpact)) - sizeof(struct ofpact)];
454 struct ofpact actions[];
456 BUILD_ASSERT_DECL(offsetof(struct ofpact_nest, actions) == OFPACT_ALIGNTO);
459 ofpact_nest_get_action_len(const struct ofpact_nest *on)
461 return on->ofpact.len - offsetof(struct ofpact_nest, actions);
464 void ofpacts_execute_action_set(struct ofpbuf *action_list,
465 const struct ofpbuf *action_set);
469 * Used for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE. */
470 struct ofpact_resubmit {
471 struct ofpact ofpact;
476 /* Part of struct ofpact_learn, below. */
477 struct ofpact_learn_spec {
478 int n_bits; /* Number of bits in source and dest. */
480 int src_type; /* One of NX_LEARN_SRC_*. */
481 struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */
482 union mf_subvalue src_imm; /* NX_LEARN_SRC_IMMEDIATE only. */
484 int dst_type; /* One of NX_LEARN_DST_*. */
485 struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */
490 * Used for NXAST_LEARN. */
491 struct ofpact_learn {
492 struct ofpact ofpact;
494 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
495 uint16_t hard_timeout; /* Max time before discarding (seconds). */
496 uint16_t priority; /* Priority level of flow entry. */
497 uint64_t cookie; /* Cookie for new flow. */
498 enum ofputil_flow_mod_flags flags;
499 uint8_t table_id; /* Table to insert flow entry. */
500 uint16_t fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */
501 uint16_t fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */
503 unsigned int n_specs;
504 struct ofpact_learn_spec specs[];
509 * Used for NXAST_MULTIPATH. */
510 struct ofpact_multipath {
511 struct ofpact ofpact;
513 /* What fields to hash and how. */
514 enum nx_hash_fields fields;
515 uint16_t basis; /* Universal hash parameter. */
517 /* Multipath link choice algorithm to apply to hash value. */
518 enum nx_mp_algorithm algorithm;
519 uint16_t max_link; /* Number of output links, minus 1. */
520 uint32_t arg; /* Algorithm-specific argument. */
522 /* Where to store the result. */
523 struct mf_subfield dst;
528 * Used for NXAST_NOTE. */
530 struct ofpact ofpact;
537 * Used for NXAST_SAMPLE. */
538 struct ofpact_sample {
539 struct ofpact ofpact;
540 uint16_t probability; // Always >0.
541 uint32_t collector_set_id;
542 uint32_t obs_domain_id;
543 uint32_t obs_point_id;
548 * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */
549 struct ofpact_cnt_ids {
550 struct ofpact ofpact;
552 /* Controller ids. */
553 unsigned int n_controllers;
557 /* OFPACT_SET_MPLS_LABEL.
559 * Used for OFPAT11_SET_MPLS_LABEL and NXAST_SET_MPLS_LABEL */
560 struct ofpact_mpls_label {
561 struct ofpact ofpact;
566 /* OFPACT_SET_MPLS_TC.
568 * Used for OFPAT11_SET_MPLS_TC and NXAST_SET_MPLS_TC */
569 struct ofpact_mpls_tc {
570 struct ofpact ofpact;
575 /* OFPACT_SET_MPLS_TTL.
577 * Used for OFPAT11_SET_MPLS_TTL and NXAST_SET_MPLS_TTL */
578 struct ofpact_mpls_ttl {
579 struct ofpact ofpact;
586 * Used for OFPIT11_GOTO_TABLE */
587 struct ofpact_goto_table {
588 struct ofpact ofpact;
594 * Used for OFPAT11_GROUP. */
595 struct ofpact_group {
596 struct ofpact ofpact;
600 /* Converting OpenFlow to ofpacts. */
601 enum ofperr ofpacts_pull_openflow_actions(struct ofpbuf *openflow,
602 unsigned int actions_len,
603 enum ofp_version version,
604 struct ofpbuf *ofpacts);
605 enum ofperr ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
606 unsigned int instructions_len,
607 enum ofp_version version,
608 struct ofpbuf *ofpacts);
609 enum ofperr ofpacts_check(struct ofpact[], size_t ofpacts_len,
610 struct flow *, ofp_port_t max_ports,
611 uint8_t table_id, uint8_t n_tables,
612 enum ofputil_protocol *usable_protocols);
613 enum ofperr ofpacts_check_consistency(struct ofpact[], size_t ofpacts_len,
614 struct flow *, ofp_port_t max_ports,
615 uint8_t table_id, uint8_t n_tables,
616 enum ofputil_protocol usable_protocols);
617 enum ofperr ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len);
618 enum ofperr ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports);
620 /* Converting ofpacts to OpenFlow. */
621 size_t ofpacts_put_openflow_actions(const struct ofpact[], size_t ofpacts_len,
622 struct ofpbuf *openflow, enum ofp_version);
623 void ofpacts_put_openflow_instructions(const struct ofpact[],
625 struct ofpbuf *openflow,
626 enum ofp_version ofp_version);
628 /* Working with ofpacts. */
629 bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len,
631 bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len,
633 bool ofpacts_equal(const struct ofpact a[], size_t a_len,
634 const struct ofpact b[], size_t b_len);
635 uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
637 /* Formatting ofpacts.
639 * (For parsing ofpacts, see ofp-parse.h.) */
640 void ofpacts_format(const struct ofpact[], size_t ofpacts_len, struct ds *);
642 /* Internal use by the helpers below. */
643 void ofpact_init(struct ofpact *, enum ofpact_type, size_t len);
644 void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len);
646 /* For each OFPACT_<ENUM> with a corresponding struct <STRUCT>, this defines
647 * the following commonly useful functions:
649 * struct <STRUCT> *ofpact_put_<ENUM>(struct ofpbuf *ofpacts);
651 * Appends a new 'ofpact', of length OFPACT_<ENUM>_RAW_SIZE, to 'ofpacts',
652 * initializes it with ofpact_init_<ENUM>(), and returns it. Also sets
653 * 'ofpacts->l2' to the returned action.
655 * After using this function to add a variable-length action, add the
656 * elements of the flexible array (e.g. with ofpbuf_put()), then use
657 * ofpact_update_len() to update the length embedded into the action.
658 * (Keep in mind the need to refresh the structure from 'ofpacts->l2' after
659 * adding data to 'ofpacts'.)
661 * struct <STRUCT> *ofpact_get_<ENUM>(const struct ofpact *ofpact);
663 * Returns 'ofpact' cast to "struct <STRUCT> *". 'ofpact->type' must be
666 * as well as the following more rarely useful definitions:
668 * void ofpact_init_<ENUM>(struct <STRUCT> *ofpact);
670 * Initializes the parts of 'ofpact' that identify it as having type
671 * OFPACT_<ENUM> and length OFPACT_<ENUM>_RAW_SIZE and zeros the rest.
675 * The size of the action structure. For a fixed-length action, this is
676 * sizeof(struct <STRUCT>). For a variable-length action, this is the
677 * offset to the variable-length part.
681 * An integer constant, the value of OFPACT_<ENUM>_RAW_SIZE rounded up to a
682 * multiple of OFPACT_ALIGNTO.
684 #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) \
685 BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0); \
687 enum { OFPACT_##ENUM##_RAW_SIZE \
688 = (offsetof(struct STRUCT, MEMBER) \
689 ? offsetof(struct STRUCT, MEMBER) \
690 : sizeof(struct STRUCT)) }; \
692 enum { OFPACT_##ENUM##_SIZE \
693 = ROUND_UP(OFPACT_##ENUM##_RAW_SIZE, OFPACT_ALIGNTO) }; \
695 static inline struct STRUCT * \
696 ofpact_get_##ENUM(const struct ofpact *ofpact) \
698 ovs_assert(ofpact->type == OFPACT_##ENUM); \
699 return ALIGNED_CAST(struct STRUCT *, ofpact); \
702 static inline struct STRUCT * \
703 ofpact_put_##ENUM(struct ofpbuf *ofpacts) \
705 return ofpact_put(ofpacts, OFPACT_##ENUM, \
706 OFPACT_##ENUM##_RAW_SIZE); \
710 ofpact_init_##ENUM(struct STRUCT *ofpact) \
712 ofpact_init(&ofpact->ofpact, OFPACT_##ENUM, \
713 OFPACT_##ENUM##_RAW_SIZE); \
718 /* Functions to use after adding ofpacts to a buffer. */
719 void ofpact_update_len(struct ofpbuf *, struct ofpact *);
720 void ofpact_pad(struct ofpbuf *);
722 /* OpenFlow 1.1 instructions.
723 * The order is sorted in execution order. Not in the value of OFPIT11_xxx.
724 * It is enforced on parser from text string.
726 #define OVS_INSTRUCTIONS \
727 DEFINE_INST(OFPIT13_METER, \
728 ofp13_instruction_meter, false, \
731 DEFINE_INST(OFPIT11_APPLY_ACTIONS, \
732 ofp11_instruction_actions, true, \
735 DEFINE_INST(OFPIT11_CLEAR_ACTIONS, \
736 ofp11_instruction, false, \
739 DEFINE_INST(OFPIT11_WRITE_ACTIONS, \
740 ofp11_instruction_actions, true, \
743 DEFINE_INST(OFPIT11_WRITE_METADATA, \
744 ofp11_instruction_write_metadata, false, \
747 DEFINE_INST(OFPIT11_GOTO_TABLE, \
748 ofp11_instruction_goto_table, false, \
751 enum ovs_instruction_type {
752 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) OVSINST_##ENUM,
758 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
759 N_OVS_INSTRUCTIONS = OVS_INSTRUCTIONS
763 const char *ovs_instruction_name_from_type(enum ovs_instruction_type type);
764 int ovs_instruction_type_from_name(const char *name);
765 enum ovs_instruction_type ovs_instruction_type_from_ofpact_type(
767 #endif /* ofp-actions.h */