2 * Copyright (c) 2012, 2013, 2014 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 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.
52 * 4. <NAME>, a quoted string that gives the name of the action, for use in
53 * parsing actions from text.
57 OFPACT(OUTPUT, ofpact_output, ofpact, "output") \
58 OFPACT(GROUP, ofpact_group, ofpact, "group") \
59 OFPACT(CONTROLLER, ofpact_controller, ofpact, "controller") \
60 OFPACT(ENQUEUE, ofpact_enqueue, ofpact, "enqueue") \
61 OFPACT(OUTPUT_REG, ofpact_output_reg, ofpact, "output_reg") \
62 OFPACT(BUNDLE, ofpact_bundle, slaves, "bundle") \
64 /* Header changes. */ \
65 OFPACT(SET_FIELD, ofpact_set_field, ofpact, "set_field") \
66 OFPACT(SET_VLAN_VID, ofpact_vlan_vid, ofpact, "set_vlan_vid") \
67 OFPACT(SET_VLAN_PCP, ofpact_vlan_pcp, ofpact, "set_vlan_pcp") \
68 OFPACT(STRIP_VLAN, ofpact_null, ofpact, "strip_vlan") \
69 OFPACT(PUSH_VLAN, ofpact_null, ofpact, "push_vlan") \
70 OFPACT(SET_ETH_SRC, ofpact_mac, ofpact, "mod_dl_src") \
71 OFPACT(SET_ETH_DST, ofpact_mac, ofpact, "mod_dl_dst") \
72 OFPACT(SET_IPV4_SRC, ofpact_ipv4, ofpact, "mod_nw_src") \
73 OFPACT(SET_IPV4_DST, ofpact_ipv4, ofpact, "mod_nw_dst") \
74 OFPACT(SET_IP_DSCP, ofpact_dscp, ofpact, "mod_nw_tos") \
75 OFPACT(SET_IP_ECN, ofpact_ecn, ofpact, "mod_nw_ecn") \
76 OFPACT(SET_IP_TTL, ofpact_ip_ttl, ofpact, "mod_nw_ttl") \
77 OFPACT(SET_L4_SRC_PORT, ofpact_l4_port, ofpact, "mod_tp_src") \
78 OFPACT(SET_L4_DST_PORT, ofpact_l4_port, ofpact, "mod_tp_dst") \
79 OFPACT(REG_MOVE, ofpact_reg_move, ofpact, "move") \
80 OFPACT(STACK_PUSH, ofpact_stack, ofpact, "push") \
81 OFPACT(STACK_POP, ofpact_stack, ofpact, "pop") \
82 OFPACT(DEC_TTL, ofpact_cnt_ids, cnt_ids, "dec_ttl") \
83 OFPACT(SET_MPLS_LABEL, ofpact_mpls_label, ofpact, "set_mpls_label") \
84 OFPACT(SET_MPLS_TC, ofpact_mpls_tc, ofpact, "set_mpls_tc") \
85 OFPACT(SET_MPLS_TTL, ofpact_mpls_ttl, ofpact, "set_mpls_ttl") \
86 OFPACT(DEC_MPLS_TTL, ofpact_null, ofpact, "dec_mpls_ttl") \
87 OFPACT(PUSH_MPLS, ofpact_push_mpls, ofpact, "push_mpls") \
88 OFPACT(POP_MPLS, ofpact_pop_mpls, ofpact, "pop_mpls") \
91 OFPACT(SET_TUNNEL, ofpact_tunnel, ofpact, "set_tunnel") \
92 OFPACT(SET_QUEUE, ofpact_queue, ofpact, "set_queue") \
93 OFPACT(POP_QUEUE, ofpact_null, ofpact, "pop_queue") \
94 OFPACT(FIN_TIMEOUT, ofpact_fin_timeout, ofpact, "fin_timeout") \
96 /* Flow table interaction. */ \
97 OFPACT(RESUBMIT, ofpact_resubmit, ofpact, "resubmit") \
98 OFPACT(LEARN, ofpact_learn, specs, "learn") \
101 OFPACT(MULTIPATH, ofpact_multipath, ofpact, "multipath") \
104 OFPACT(NOTE, ofpact_note, data, "note") \
105 OFPACT(EXIT, ofpact_null, ofpact, "exit") \
106 OFPACT(SAMPLE, ofpact_sample, ofpact, "sample") \
108 /* Instructions. */ \
109 OFPACT(METER, ofpact_meter, ofpact, "meter") \
110 OFPACT(CLEAR_ACTIONS, ofpact_null, ofpact, "clear_actions") \
111 OFPACT(WRITE_ACTIONS, ofpact_nest, ofpact, "write_actions") \
112 OFPACT(WRITE_METADATA, ofpact_metadata, ofpact, "write_metadata") \
113 OFPACT(GOTO_TABLE, ofpact_goto_table, ofpact, "goto_table")
115 /* enum ofpact_type, with a member OFPACT_<ENUM> for each action. */
116 enum OVS_PACKED_ENUM ofpact_type {
117 #define OFPACT(ENUM, STRUCT, MEMBER, NAME) OFPACT_##ENUM,
122 /* Define N_OFPACTS to the number of types of ofpacts. */
124 #define OFPACT(ENUM, STRUCT, MEMBER, NAME) + 1
129 /* Header for an action.
131 * Each action is a structure "struct ofpact_*" that begins with "struct
132 * ofpact", usually followed by other data that describes the action. Actions
133 * are padded out to a multiple of OFPACT_ALIGNTO bytes in length.
135 * The 'raw' member is special:
137 * - Most "struct ofpact"s correspond to one particular kind of OpenFlow
138 * action, at least in a given OpenFlow version. For example,
139 * OFPACT_SET_VLAN_VID corresponds to OFPAT10_SET_VLAN_VID in OpenFlow
142 * For such actions, the 'raw' member is not meaningful and generally
145 * - A few "struct ofpact"s correspond to multiple OpenFlow actions. For
146 * example, OFPACT_SET_TUNNEL can be NXAST_SET_TUNNEL or
147 * NXAST_SET_TUNNEL64. In these cases, if the "struct ofpact" originated
148 * from OpenFlow, then we want to make sure that, if it gets translated
149 * back to OpenFlow later, it is translated back to the same action type.
150 * (Otherwise, we'd violate the promise made in DESIGN, in the "Action
151 * Reproduction" section.)
153 * For such actions, the 'raw' member should be the "enum ofp_raw_action"
154 * originally extracted from the OpenFlow action. (If the action didn't
155 * originate from OpenFlow, then setting 'raw' to zero should be fine:
156 * code to translate the ofpact to OpenFlow must tolerate this case.)
159 /* We want the space advantage of an 8-bit type here on every
160 * implementation, without giving up the advantage of having a useful type
161 * on implementations that support packed enums. */
162 #ifdef HAVE_PACKED_ENUM
163 enum ofpact_type type; /* OFPACT_*. */
165 uint8_t type; /* OFPACT_* */
168 uint8_t raw; /* Original type when added, if any. */
169 uint16_t len; /* Length of the action, in bytes, including
170 * struct ofpact, excluding padding. */
172 BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4);
175 #define OFPACT_ALIGNTO 8
176 #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO)
178 static inline struct ofpact *
179 ofpact_next(const struct ofpact *ofpact)
181 return (void *) ((uint8_t *) ofpact + OFPACT_ALIGN(ofpact->len));
184 static inline struct ofpact *
185 ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len)
187 return (void *) ((uint8_t *) ofpacts + ofpacts_len);
190 /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts
191 * starting at OFPACTS. */
192 #define OFPACT_FOR_EACH(POS, OFPACTS, OFPACTS_LEN) \
193 for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN); \
194 (POS) = ofpact_next(POS))
196 /* Action structure for each OFPACT_*. */
198 /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS.
200 * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT,
201 * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS.
203 * Action structure for actions that do not have any extra data beyond the
206 struct ofpact ofpact;
211 * Used for OFPAT10_OUTPUT. */
212 struct ofpact_output {
213 struct ofpact ofpact;
214 ofp_port_t port; /* Output port. */
215 uint16_t max_len; /* Max send len, for port OFPP_CONTROLLER. */
218 /* OFPACT_CONTROLLER.
220 * Used for NXAST_CONTROLLER. */
221 struct ofpact_controller {
222 struct ofpact ofpact;
223 uint16_t max_len; /* Maximum length to send to controller. */
224 uint16_t controller_id; /* Controller ID to send packet-in. */
225 enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */
230 * Used for OFPAT10_ENQUEUE. */
231 struct ofpact_enqueue {
232 struct ofpact ofpact;
237 /* OFPACT_OUTPUT_REG.
239 * Used for NXAST_OUTPUT_REG. */
240 struct ofpact_output_reg {
241 struct ofpact ofpact;
243 struct mf_subfield src;
246 /* Bundle slave choice algorithm to apply.
248 * In the descriptions below, 'slaves' is the list of possible slaves in the
249 * order they appear in the OpenFlow action. */
250 enum nx_bd_algorithm {
251 /* Chooses the first live slave listed in the bundle.
253 * O(n_slaves) performance. */
254 NX_BD_ALG_ACTIVE_BACKUP = 0,
256 /* Highest Random Weight.
258 * for i in [0,n_slaves):
259 * weights[i] = hash(flow, i)
260 * slave = { slaves[i] such that weights[i] >= weights[j] for all j != i }
262 * Redistributes 1/n_slaves of traffic when a slave's liveness changes.
263 * O(n_slaves) performance.
265 * Uses the 'fields' and 'basis' parameters. */
271 * Used for NXAST_BUNDLE. */
272 struct ofpact_bundle {
273 struct ofpact ofpact;
275 /* Slave choice algorithm to apply to hash value. */
276 enum nx_bd_algorithm algorithm;
278 /* What fields to hash and how. */
279 enum nx_hash_fields fields;
280 uint16_t basis; /* Universal hash parameter. */
282 struct mf_subfield dst;
284 /* Slaves for output. */
285 unsigned int n_slaves;
289 /* OFPACT_SET_VLAN_VID.
291 * We keep track if vlan was present at action validation time to avoid a
292 * PUSH_VLAN when translating to OpenFlow 1.1+.
294 * We also keep the originating OFPUTIL action code in ofpact.compat.
296 * Used for OFPAT10_SET_VLAN_VID and OFPAT11_SET_VLAN_VID. */
297 struct ofpact_vlan_vid {
298 struct ofpact ofpact;
299 uint16_t vlan_vid; /* VLAN VID in low 12 bits, 0 in other bits. */
300 bool push_vlan_if_needed; /* OF 1.0 semantics if true. */
301 bool flow_has_vlan; /* VLAN present at action validation time? */
304 /* OFPACT_SET_VLAN_PCP.
306 * We keep track if vlan was present at action validation time to avoid a
307 * PUSH_VLAN when translating to OpenFlow 1.1+.
309 * We also keep the originating OFPUTIL action code in ofpact.compat.
311 * Used for OFPAT10_SET_VLAN_PCP and OFPAT11_SET_VLAN_PCP. */
312 struct ofpact_vlan_pcp {
313 struct ofpact ofpact;
314 uint8_t vlan_pcp; /* VLAN PCP in low 3 bits, 0 in other bits. */
315 bool push_vlan_if_needed; /* OF 1.0 semantics if true. */
316 bool flow_has_vlan; /* VLAN present at action validation time? */
319 /* OFPACT_SET_ETH_SRC, OFPACT_SET_ETH_DST.
321 * Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */
323 struct ofpact ofpact;
324 uint8_t mac[ETH_ADDR_LEN];
327 /* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST.
329 * Used for OFPAT10_SET_NW_SRC, OFPAT10_SET_NW_DST. */
331 struct ofpact ofpact;
335 /* OFPACT_SET_IP_DSCP.
337 * Used for OFPAT10_SET_NW_TOS. */
339 struct ofpact ofpact;
340 uint8_t dscp; /* DSCP in high 6 bits, rest ignored. */
343 /* OFPACT_SET_IP_ECN.
345 * Used for OFPAT11_SET_NW_ECN. */
347 struct ofpact ofpact;
348 uint8_t ecn; /* ECN in low 2 bits, rest ignored. */
351 /* OFPACT_SET_IP_TTL.
353 * Used for OFPAT11_SET_NW_TTL. */
354 struct ofpact_ip_ttl {
355 struct ofpact ofpact;
359 /* OFPACT_SET_L4_SRC_PORT, OFPACT_SET_L4_DST_PORT.
361 * Used for OFPAT10_SET_TP_SRC, OFPAT10_SET_TP_DST. */
362 struct ofpact_l4_port {
363 struct ofpact ofpact;
364 uint16_t port; /* TCP, UDP or SCTP port number. */
365 uint8_t flow_ip_proto; /* IP proto from corresponding match, or 0 */
370 * Used for NXAST_REG_MOVE. */
371 struct ofpact_reg_move {
372 struct ofpact ofpact;
373 struct mf_subfield src;
374 struct mf_subfield dst;
377 /* OFPACT_STACK_PUSH.
379 * Used for NXAST_STACK_PUSH and NXAST_STACK_POP. */
380 struct ofpact_stack {
381 struct ofpact ofpact;
382 struct mf_subfield subfield;
387 * Used for NXAST_REG_LOAD and OFPAT12_SET_FIELD. */
388 struct ofpact_set_field {
389 struct ofpact ofpact;
390 const struct mf_field *field;
391 bool flow_has_vlan; /* VLAN present at action validation time. */
392 union mf_value value;
396 /* OFPACT_PUSH_VLAN/MPLS/PBB
398 * Used for NXAST_PUSH_MPLS, OFPAT11_PUSH_MPLS. */
399 struct ofpact_push_mpls {
400 struct ofpact ofpact;
406 * Used for NXAST_POP_MPLS, OFPAT11_POP_MPLS.. */
407 struct ofpact_pop_mpls {
408 struct ofpact ofpact;
412 /* OFPACT_SET_TUNNEL.
414 * Used for NXAST_SET_TUNNEL, NXAST_SET_TUNNEL64. */
415 struct ofpact_tunnel {
416 struct ofpact ofpact;
422 * Used for NXAST_SET_QUEUE. */
423 struct ofpact_queue {
424 struct ofpact ofpact;
428 /* OFPACT_FIN_TIMEOUT.
430 * Used for NXAST_FIN_TIMEOUT. */
431 struct ofpact_fin_timeout {
432 struct ofpact ofpact;
433 uint16_t fin_idle_timeout;
434 uint16_t fin_hard_timeout;
437 /* OFPACT_WRITE_METADATA.
439 * Used for NXAST_WRITE_METADATA. */
440 struct ofpact_metadata {
441 struct ofpact ofpact;
448 * Used for OFPIT13_METER. */
449 struct ofpact_meter {
450 struct ofpact ofpact;
454 /* OFPACT_WRITE_ACTIONS.
456 * Used for OFPIT11_WRITE_ACTIONS. */
458 struct ofpact ofpact;
459 uint8_t pad[PAD_SIZE(sizeof(struct ofpact), OFPACT_ALIGNTO)];
460 struct ofpact actions[];
462 BUILD_ASSERT_DECL(offsetof(struct ofpact_nest, actions) % OFPACT_ALIGNTO == 0);
463 BUILD_ASSERT_DECL(offsetof(struct ofpact_nest, actions)
464 == sizeof(struct ofpact_nest));
467 ofpact_nest_get_action_len(const struct ofpact_nest *on)
469 return on->ofpact.len - offsetof(struct ofpact_nest, actions);
472 void ofpacts_execute_action_set(struct ofpbuf *action_list,
473 const struct ofpbuf *action_set);
477 * Used for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE. */
478 struct ofpact_resubmit {
479 struct ofpact ofpact;
484 /* Part of struct ofpact_learn, below. */
485 struct ofpact_learn_spec {
486 int n_bits; /* Number of bits in source and dest. */
488 int src_type; /* One of NX_LEARN_SRC_*. */
489 struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */
490 union mf_subvalue src_imm; /* NX_LEARN_SRC_IMMEDIATE only. */
492 int dst_type; /* One of NX_LEARN_DST_*. */
493 struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */
497 /* Bits for 'flags' in struct nx_action_learn.
499 * If NX_LEARN_F_SEND_FLOW_REM is set, then the learned flows will have their
500 * OFPFF_SEND_FLOW_REM flag set.
502 * If NX_LEARN_F_DELETE_LEARNED is set, then removing this action will delete
503 * all the flows from the learn action's 'table_id' that have the learn
504 * action's 'cookie'. Important points:
506 * - The deleted flows include those created by this action, those created
507 * by other learn actions with the same 'table_id' and 'cookie', those
508 * created by flow_mod requests by a controller in the specified table
509 * with the specified cookie, and those created through any other
512 * - If multiple flows specify "learn" actions with
513 * NX_LEARN_F_DELETE_LEARNED with the same 'table_id' and 'cookie', then
514 * no deletion occurs until all of those "learn" actions are deleted.
516 * - Deleting a flow that contains a learn action is the most obvious way
517 * to delete a learn action. Modifying a flow's actions, or replacing it
518 * by a new flow, can also delete a learn action. Finally, replacing a
519 * learn action with NX_LEARN_F_DELETE_LEARNED with a learn action
520 * without that flag also effectively deletes the learn action and can
521 * trigger flow deletion.
523 * NX_LEARN_F_DELETE_LEARNED was added in Open vSwitch 2.4. */
524 enum nx_learn_flags {
525 NX_LEARN_F_SEND_FLOW_REM = 1 << 0,
526 NX_LEARN_F_DELETE_LEARNED = 1 << 1,
529 #define NX_LEARN_N_BITS_MASK 0x3ff
531 #define NX_LEARN_SRC_FIELD (0 << 13) /* Copy from field. */
532 #define NX_LEARN_SRC_IMMEDIATE (1 << 13) /* Copy from immediate value. */
533 #define NX_LEARN_SRC_MASK (1 << 13)
535 #define NX_LEARN_DST_MATCH (0 << 11) /* Add match criterion. */
536 #define NX_LEARN_DST_LOAD (1 << 11) /* Add NXAST_REG_LOAD action. */
537 #define NX_LEARN_DST_OUTPUT (2 << 11) /* Add OFPAT_OUTPUT action. */
538 #define NX_LEARN_DST_RESERVED (3 << 11) /* Not yet defined. */
539 #define NX_LEARN_DST_MASK (3 << 11)
543 * Used for NXAST_LEARN. */
544 struct ofpact_learn {
545 struct ofpact ofpact;
547 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
548 uint16_t hard_timeout; /* Max time before discarding (seconds). */
549 uint16_t priority; /* Priority level of flow entry. */
550 uint8_t table_id; /* Table to insert flow entry. */
551 ovs_be64 cookie; /* Cookie for new flow. */
552 enum nx_learn_flags flags; /* NX_LEARN_F_*. */
553 uint16_t fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */
554 uint16_t fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */
556 unsigned int n_specs;
557 struct ofpact_learn_spec specs[];
560 /* Multipath link choice algorithm to apply.
562 * In the descriptions below, 'n_links' is max_link + 1. */
563 enum nx_mp_algorithm {
564 /* link = hash(flow) % n_links.
566 * Redistributes all traffic when n_links changes. O(1) performance. See
569 * Use UINT16_MAX for max_link to get a raw hash value. */
570 NX_MP_ALG_MODULO_N = 0,
572 /* link = hash(flow) / (MAX_HASH / n_links).
574 * Redistributes between one-quarter and one-half of traffic when n_links
575 * changes. O(1) performance. See RFC 2992.
577 NX_MP_ALG_HASH_THRESHOLD = 1,
579 /* Highest Random Weight.
581 * for i in [0,n_links):
582 * weights[i] = hash(flow, i)
583 * link = { i such that weights[i] >= weights[j] for all j != i }
585 * Redistributes 1/n_links of traffic when n_links changes. O(n_links)
586 * performance. If n_links is greater than a threshold (currently 64, but
587 * subject to change), Open vSwitch will substitute another algorithm
588 * automatically. See RFC 2992. */
596 * link = hash(flow, i) % arg
597 * while link > max_link
599 * Redistributes 1/n_links of traffic when n_links changes. O(1)
600 * performance when arg/max_link is bounded by a constant.
602 * Redistributes all traffic when arg changes.
604 * arg must be greater than max_link and for best performance should be no
605 * more than approximately max_link * 2. If arg is outside the acceptable
606 * range, Open vSwitch will automatically substitute the least power of 2
607 * greater than max_link.
609 * This algorithm is specific to Open vSwitch.
611 NX_MP_ALG_ITER_HASH = 3,
616 * Used for NXAST_MULTIPATH. */
617 struct ofpact_multipath {
618 struct ofpact ofpact;
620 /* What fields to hash and how. */
621 enum nx_hash_fields fields;
622 uint16_t basis; /* Universal hash parameter. */
624 /* Multipath link choice algorithm to apply to hash value. */
625 enum nx_mp_algorithm algorithm;
626 uint16_t max_link; /* Number of output links, minus 1. */
627 uint32_t arg; /* Algorithm-specific argument. */
629 /* Where to store the result. */
630 struct mf_subfield dst;
635 * Used for NXAST_NOTE. */
637 struct ofpact ofpact;
644 * Used for NXAST_SAMPLE. */
645 struct ofpact_sample {
646 struct ofpact ofpact;
647 uint16_t probability; // Always >0.
648 uint32_t collector_set_id;
649 uint32_t obs_domain_id;
650 uint32_t obs_point_id;
655 * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */
656 struct ofpact_cnt_ids {
657 struct ofpact ofpact;
659 /* Controller ids. */
660 unsigned int n_controllers;
664 /* OFPACT_SET_MPLS_LABEL.
666 * Used for OFPAT11_SET_MPLS_LABEL and NXAST_SET_MPLS_LABEL */
667 struct ofpact_mpls_label {
668 struct ofpact ofpact;
673 /* OFPACT_SET_MPLS_TC.
675 * Used for OFPAT11_SET_MPLS_TC and NXAST_SET_MPLS_TC */
676 struct ofpact_mpls_tc {
677 struct ofpact ofpact;
682 /* OFPACT_SET_MPLS_TTL.
684 * Used for OFPAT11_SET_MPLS_TTL and NXAST_SET_MPLS_TTL */
685 struct ofpact_mpls_ttl {
686 struct ofpact ofpact;
693 * Used for OFPIT11_GOTO_TABLE */
694 struct ofpact_goto_table {
695 struct ofpact ofpact;
701 * Used for OFPAT11_GROUP. */
702 struct ofpact_group {
703 struct ofpact ofpact;
707 /* Converting OpenFlow to ofpacts. */
708 enum ofperr ofpacts_pull_openflow_actions(struct ofpbuf *openflow,
709 unsigned int actions_len,
710 enum ofp_version version,
711 struct ofpbuf *ofpacts);
712 enum ofperr ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
713 unsigned int instructions_len,
714 enum ofp_version version,
715 struct ofpbuf *ofpacts);
716 enum ofperr ofpacts_check(struct ofpact[], size_t ofpacts_len,
717 struct flow *, ofp_port_t max_ports,
718 uint8_t table_id, uint8_t n_tables,
719 enum ofputil_protocol *usable_protocols);
720 enum ofperr ofpacts_check_consistency(struct ofpact[], size_t ofpacts_len,
721 struct flow *, ofp_port_t max_ports,
722 uint8_t table_id, uint8_t n_tables,
723 enum ofputil_protocol usable_protocols);
724 enum ofperr ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports);
726 /* Converting ofpacts to OpenFlow. */
727 size_t ofpacts_put_openflow_actions(const struct ofpact[], size_t ofpacts_len,
728 struct ofpbuf *openflow, enum ofp_version);
729 void ofpacts_put_openflow_instructions(const struct ofpact[],
731 struct ofpbuf *openflow,
732 enum ofp_version ofp_version);
734 /* Sets of supported actions. */
735 ovs_be32 ofpact_bitmap_to_openflow(uint64_t ofpacts_bitmap, enum ofp_version);
736 uint64_t ofpact_bitmap_from_openflow(ovs_be32 ofpat_bitmap, enum ofp_version);
737 void ofpact_bitmap_format(uint64_t ofpacts_bitmap, struct ds *);
739 /* Working with ofpacts. */
740 bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len,
742 bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len,
744 bool ofpacts_equal(const struct ofpact a[], size_t a_len,
745 const struct ofpact b[], size_t b_len);
746 uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
748 /* Formatting and parsing ofpacts. */
749 void ofpacts_format(const struct ofpact[], size_t ofpacts_len, struct ds *);
750 char *ofpacts_parse_actions(const char *, struct ofpbuf *ofpacts,
751 enum ofputil_protocol *usable_protocols)
753 char *ofpacts_parse_instructions(const char *, struct ofpbuf *ofpacts,
754 enum ofputil_protocol *usable_protocols)
756 const char *ofpact_name(enum ofpact_type);
758 /* Internal use by the helpers below. */
759 void ofpact_init(struct ofpact *, enum ofpact_type, size_t len);
760 void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len);
762 /* For each OFPACT_<ENUM> with a corresponding struct <STRUCT>, this defines
763 * the following commonly useful functions:
765 * struct <STRUCT> *ofpact_put_<ENUM>(struct ofpbuf *ofpacts);
767 * Appends a new 'ofpact', of length OFPACT_<ENUM>_RAW_SIZE, to 'ofpacts',
768 * initializes it with ofpact_init_<ENUM>(), and returns it. Also sets
769 * 'ofpacts->l2' to the returned action.
771 * After using this function to add a variable-length action, add the
772 * elements of the flexible array (e.g. with ofpbuf_put()), then use
773 * ofpact_update_len() to update the length embedded into the action.
774 * (Keep in mind the need to refresh the structure from 'ofpacts->frame'
775 * after adding data to 'ofpacts'.)
777 * struct <STRUCT> *ofpact_get_<ENUM>(const struct ofpact *ofpact);
779 * Returns 'ofpact' cast to "struct <STRUCT> *". 'ofpact->type' must be
782 * as well as the following more rarely useful definitions:
784 * void ofpact_init_<ENUM>(struct <STRUCT> *ofpact);
786 * Initializes the parts of 'ofpact' that identify it as having type
787 * OFPACT_<ENUM> and length OFPACT_<ENUM>_RAW_SIZE and zeros the rest.
791 * The size of the action structure. For a fixed-length action, this is
792 * sizeof(struct <STRUCT>). For a variable-length action, this is the
793 * offset to the variable-length part.
797 * An integer constant, the value of OFPACT_<ENUM>_RAW_SIZE rounded up to a
798 * multiple of OFPACT_ALIGNTO.
800 #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \
801 BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0); \
803 enum { OFPACT_##ENUM##_RAW_SIZE \
804 = (offsetof(struct STRUCT, MEMBER) \
805 ? offsetof(struct STRUCT, MEMBER) \
806 : sizeof(struct STRUCT)) }; \
808 enum { OFPACT_##ENUM##_SIZE \
809 = ROUND_UP(OFPACT_##ENUM##_RAW_SIZE, OFPACT_ALIGNTO) }; \
811 static inline struct STRUCT * \
812 ofpact_get_##ENUM(const struct ofpact *ofpact) \
814 ovs_assert(ofpact->type == OFPACT_##ENUM); \
815 return ALIGNED_CAST(struct STRUCT *, ofpact); \
818 static inline struct STRUCT * \
819 ofpact_put_##ENUM(struct ofpbuf *ofpacts) \
821 return ofpact_put(ofpacts, OFPACT_##ENUM, \
822 OFPACT_##ENUM##_RAW_SIZE); \
826 ofpact_init_##ENUM(struct STRUCT *ofpact) \
828 ofpact_init(&ofpact->ofpact, OFPACT_##ENUM, \
829 OFPACT_##ENUM##_RAW_SIZE); \
834 /* Functions to use after adding ofpacts to a buffer. */
835 void ofpact_update_len(struct ofpbuf *, struct ofpact *);
836 void ofpact_pad(struct ofpbuf *);
838 /* Additional functions for composing ofpacts. */
839 struct ofpact_set_field *ofpact_put_reg_load(struct ofpbuf *ofpacts);
841 /* OpenFlow 1.1 instructions.
842 * The order is sorted in execution order. Not in the value of OFPIT11_xxx.
843 * It is enforced on parser from text string.
845 #define OVS_INSTRUCTIONS \
846 DEFINE_INST(OFPIT13_METER, \
847 ofp13_instruction_meter, false, \
850 DEFINE_INST(OFPIT11_APPLY_ACTIONS, \
851 ofp11_instruction_actions, true, \
854 DEFINE_INST(OFPIT11_CLEAR_ACTIONS, \
855 ofp11_instruction, false, \
858 DEFINE_INST(OFPIT11_WRITE_ACTIONS, \
859 ofp11_instruction_actions, true, \
862 DEFINE_INST(OFPIT11_WRITE_METADATA, \
863 ofp11_instruction_write_metadata, false, \
866 DEFINE_INST(OFPIT11_GOTO_TABLE, \
867 ofp11_instruction_goto_table, false, \
870 enum ovs_instruction_type {
871 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) OVSINST_##ENUM,
877 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
878 N_OVS_INSTRUCTIONS = OVS_INSTRUCTIONS
882 const char *ovs_instruction_name_from_type(enum ovs_instruction_type type);
883 int ovs_instruction_type_from_name(const char *name);
884 enum ovs_instruction_type ovs_instruction_type_from_ofpact_type(
886 enum ofperr ovs_instruction_type_from_inst_type(
887 enum ovs_instruction_type *instruction_type, const uint16_t inst_type);
889 ovs_be32 ovsinst_bitmap_to_openflow(uint32_t ovsinst_bitmap, enum ofp_version);
890 uint32_t ovsinst_bitmap_from_openflow(ovs_be32 ofpit_bitmap,
893 #endif /* ofp-actions.h */