2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 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.
24 #include "classifier.h"
28 #include "openflow/nicira-ext.h"
29 #include "openvswitch/types.h"
35 enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port, uint16_t *ofp10_port);
36 ovs_be32 ofputil_port_to_ofp11(uint16_t ofp10_port);
38 enum ofperr ofputil_check_output_port(uint16_t ofp_port, int max_ports);
39 bool ofputil_port_from_string(const char *, uint16_t *port);
40 void ofputil_format_port(uint16_t port, struct ds *);
42 /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
43 * to and from IP bitmasks. */
44 ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
45 int ofputil_netmask_to_wcbits(ovs_be32 netmask);
49 * These are arranged from most portable to least portable, or alternatively
50 * from least powerful to most powerful. Formats earlier on the list are more
51 * likely to be understood for the purpose of making requests, but formats
52 * later on the list are more likely to accurately describe a flow within a
55 * On any given OpenFlow connection, a single protocol is in effect at any
56 * given time. These values use separate bits only because that makes it easy
57 * to test whether a particular protocol is within a given set of protocols and
58 * to implement set union and intersection.
60 enum ofputil_protocol {
61 /* OpenFlow 1.0-based protocols. */
62 OFPUTIL_P_OF10 = 1 << 0, /* OpenFlow 1.0 flow format. */
63 OFPUTIL_P_OF10_TID = 1 << 1, /* OF1.0 + flow_mod_table_id extension. */
64 #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10 | OFPUTIL_P_OF10_TID)
66 /* OpenFlow 1.0 with NXM-based flow formats. */
67 OFPUTIL_P_NXM = 1 << 2, /* Nicira extended match. */
68 OFPUTIL_P_NXM_TID = 1 << 3, /* NXM + flow_mod_table_id extension. */
69 #define OFPUTIL_P_NXM_ANY (OFPUTIL_P_NXM | OFPUTIL_P_NXM_TID)
72 OFPUTIL_P_OF12 = 1 << 4, /* OpenFlow 1.2 flow format. */
75 #define OFPUTIL_P_ANY (OFPUTIL_P_OF10_ANY | OFPUTIL_P_NXM_ANY)
77 /* Protocols in which a specific table may be specified in flow_mods. */
78 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_TID | OFPUTIL_P_NXM_TID)
81 /* Protocols to use for flow dumps, from most to least preferred. */
82 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
83 extern size_t ofputil_n_flow_dump_protocols;
85 enum ofputil_protocol ofputil_protocol_from_ofp_version(int version);
86 uint8_t ofputil_protocol_to_ofp_version(enum ofputil_protocol);
88 bool ofputil_protocol_is_valid(enum ofputil_protocol);
89 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
91 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
92 enum ofputil_protocol ofputil_protocol_set_base(
93 enum ofputil_protocol cur, enum ofputil_protocol new_base);
95 const char *ofputil_protocol_to_string(enum ofputil_protocol);
96 char *ofputil_protocols_to_string(enum ofputil_protocol);
97 enum ofputil_protocol ofputil_protocols_from_string(const char *);
98 enum ofputil_protocol ofputil_usable_protocols(const struct cls_rule *);
100 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
101 enum ofputil_protocol want,
102 enum ofputil_protocol *next);
105 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
106 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
107 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
108 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
110 /* Work with ofp10_match. */
111 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
112 void ofputil_cls_rule_from_ofp10_match(const struct ofp10_match *,
113 unsigned int priority,
115 void ofputil_normalize_rule(struct cls_rule *);
116 void ofputil_cls_rule_to_ofp10_match(const struct cls_rule *,
117 struct ofp10_match *);
119 /* Work with ofp11_match. */
120 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, unsigned int priority,
122 enum ofperr ofputil_cls_rule_from_ofp11_match(const struct ofp11_match *,
123 unsigned int priority,
125 void ofputil_cls_rule_to_ofp11_match(const struct cls_rule *,
126 struct ofp11_match *);
128 /* dl_type translation between OpenFlow and 'struct flow' format. */
129 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
130 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
133 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
134 int ofputil_packet_in_format_from_string(const char *);
135 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
136 struct ofpbuf *ofputil_make_set_packet_in_format(enum nx_packet_in_format);
138 /* NXT_FLOW_MOD_TABLE_ID extension. */
139 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
141 /* Protocol-independent flow_mod.
143 * The handling of cookies across multiple versions of OpenFlow is a bit
144 * confusing. A full description of Open vSwitch's cookie handling is
145 * in the DESIGN file. The following table shows the expected values of
146 * the cookie-related fields for the different flow_mod commands in
147 * OpenFlow 1.0 ("OF10") and NXM. "<used>" and "-" indicate a value
148 * that may be populated and an ignored field, respectively.
150 * cookie cookie_mask new_cookie
151 * ====== =========== ==========
152 * OF10 Add - 0 <used>
153 * OF10 Modify - 0 <used>
156 * NXM Modify <used> <used> <used>
157 * NXM Delete <used> <used> -
159 struct ofputil_flow_mod {
161 ovs_be64 cookie; /* Cookie bits to match. */
162 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
163 ovs_be64 new_cookie; /* New cookie to install or -1. */
166 uint16_t idle_timeout;
167 uint16_t hard_timeout;
171 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
172 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
175 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
176 const struct ofp_header *,
177 enum ofputil_protocol,
178 struct ofpbuf *ofpacts);
179 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
180 enum ofputil_protocol);
182 enum ofputil_protocol ofputil_flow_mod_usable_protocols(
183 const struct ofputil_flow_mod *fms, size_t n_fms);
185 /* Flow stats or aggregate stats request, independent of protocol. */
186 struct ofputil_flow_stats_request {
187 bool aggregate; /* Aggregate results? */
188 struct cls_rule match;
190 ovs_be64 cookie_mask;
195 enum ofperr ofputil_decode_flow_stats_request(
196 struct ofputil_flow_stats_request *, const struct ofp_header *);
197 struct ofpbuf *ofputil_encode_flow_stats_request(
198 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
199 enum ofputil_protocol ofputil_flow_stats_request_usable_protocols(
200 const struct ofputil_flow_stats_request *);
202 /* Flow stats reply, independent of protocol. */
203 struct ofputil_flow_stats {
204 struct cls_rule rule;
207 uint32_t duration_sec;
208 uint32_t duration_nsec;
209 uint16_t idle_timeout;
210 uint16_t hard_timeout;
211 int idle_age; /* Seconds since last packet, -1 if unknown. */
212 int hard_age; /* Seconds since last change, -1 if unknown. */
213 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
214 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
215 struct ofpact *ofpacts;
219 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
221 bool flow_age_extension,
222 struct ofpbuf *ofpacts);
223 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
224 struct list *replies);
226 /* Aggregate stats reply, independent of protocol. */
227 struct ofputil_aggregate_stats {
228 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
229 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
233 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
234 const struct ofputil_aggregate_stats *stats,
235 const struct ofp_header *request);
236 enum ofperr ofputil_decode_aggregate_stats_reply(
237 struct ofputil_aggregate_stats *,
238 const struct ofp_header *reply);
240 /* Flow removed message, independent of protocol. */
241 struct ofputil_flow_removed {
242 struct cls_rule rule;
244 uint8_t reason; /* One of OFPRR_*. */
245 uint32_t duration_sec;
246 uint32_t duration_nsec;
247 uint16_t idle_timeout;
248 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
249 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
252 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
253 const struct ofp_header *);
254 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
255 enum ofputil_protocol);
257 /* Abstract packet-in message. */
258 struct ofputil_packet_in {
262 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
263 uint16_t controller_id; /* Controller ID to send to. */
269 uint16_t total_len; /* Full length of frame. */
271 struct flow_metadata fmd; /* Metadata at creation time. */
274 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
275 const struct ofp_header *);
276 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
277 enum nx_packet_in_format);
279 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
280 bool ofputil_packet_in_reason_from_string(const char *,
281 enum ofp_packet_in_reason *);
283 /* Abstract packet-out message.
285 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
286 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
287 struct ofputil_packet_out {
288 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
289 size_t packet_len; /* Length of packet data in bytes. */
290 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
291 uint16_t in_port; /* Packet's input port. */
292 struct ofpact *ofpacts; /* Actions. */
293 size_t ofpacts_len; /* Size of ofpacts in bytes. */
296 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
297 const struct ofp_header *,
298 struct ofpbuf *ofpacts);
299 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *);
301 enum ofputil_port_config {
302 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
303 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
304 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
305 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
306 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
307 /* OpenFlow 1.0 only. */
308 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
309 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
310 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
311 /* There are no OpenFlow 1.1-only bits. */
314 enum ofputil_port_state {
315 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
316 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
317 /* OpenFlow 1.1 only. */
318 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
319 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
320 /* OpenFlow 1.0 only. */
321 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
322 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
323 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
324 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
325 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
328 /* Abstract ofp10_phy_port or ofp11_port. */
329 struct ofputil_phy_port {
331 uint8_t hw_addr[OFP_ETH_ALEN];
332 char name[OFP_MAX_PORT_NAME_LEN];
333 enum ofputil_port_config config;
334 enum ofputil_port_state state;
336 /* NETDEV_F_* feature bitmasks. */
337 enum netdev_features curr; /* Current features. */
338 enum netdev_features advertised; /* Features advertised by the port. */
339 enum netdev_features supported; /* Features supported by the port. */
340 enum netdev_features peer; /* Features advertised by peer. */
343 uint32_t curr_speed; /* Current speed, in kbps. */
344 uint32_t max_speed; /* Maximum supported speed, in kbps. */
347 enum ofputil_capabilities {
348 /* OpenFlow 1.0 and 1.1 share these values for these capabilities. */
349 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
350 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
351 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
352 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
353 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
354 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
356 /* OpenFlow 1.0 only. */
357 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
359 /* OpenFlow 1.1 only. */
360 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
363 enum ofputil_action_bitmap {
364 OFPUTIL_A_OUTPUT = 1 << 0,
365 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
366 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
367 OFPUTIL_A_STRIP_VLAN = 1 << 3,
368 OFPUTIL_A_SET_DL_SRC = 1 << 4,
369 OFPUTIL_A_SET_DL_DST = 1 << 5,
370 OFPUTIL_A_SET_NW_SRC = 1 << 6,
371 OFPUTIL_A_SET_NW_DST = 1 << 7,
372 OFPUTIL_A_SET_NW_ECN = 1 << 8,
373 OFPUTIL_A_SET_NW_TOS = 1 << 9,
374 OFPUTIL_A_SET_TP_SRC = 1 << 10,
375 OFPUTIL_A_SET_TP_DST = 1 << 11,
376 OFPUTIL_A_ENQUEUE = 1 << 12,
377 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
378 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
379 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
380 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
381 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
382 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
383 OFPUTIL_A_PUSH_VLAN = 1 << 19,
384 OFPUTIL_A_POP_VLAN = 1 << 20,
385 OFPUTIL_A_PUSH_MPLS = 1 << 21,
386 OFPUTIL_A_POP_MPLS = 1 << 22,
387 OFPUTIL_A_SET_QUEUE = 1 << 23,
388 OFPUTIL_A_GROUP = 1 << 24,
389 OFPUTIL_A_SET_NW_TTL = 1 << 25,
390 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
393 /* Abstract ofp_switch_features. */
394 struct ofputil_switch_features {
395 uint64_t datapath_id; /* Datapath unique ID. */
396 uint32_t n_buffers; /* Max packets buffered at once. */
397 uint8_t n_tables; /* Number of tables supported by datapath. */
398 enum ofputil_capabilities capabilities;
399 enum ofputil_action_bitmap actions;
402 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
403 struct ofputil_switch_features *,
406 struct ofpbuf *ofputil_encode_switch_features(
407 const struct ofputil_switch_features *, enum ofputil_protocol,
409 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
411 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
413 /* phy_port helper functions. */
414 int ofputil_pull_phy_port(uint8_t ofp_version, struct ofpbuf *,
415 struct ofputil_phy_port *);
416 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
418 /* Abstract ofp_port_status. */
419 struct ofputil_port_status {
420 enum ofp_port_reason reason;
421 struct ofputil_phy_port desc;
424 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
425 struct ofputil_port_status *);
426 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
427 enum ofputil_protocol);
429 /* Abstract ofp_port_mod. */
430 struct ofputil_port_mod {
432 uint8_t hw_addr[OFP_ETH_ALEN];
433 enum ofputil_port_config config;
434 enum ofputil_port_config mask;
435 enum netdev_features advertise;
438 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
439 struct ofputil_port_mod *);
440 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
441 enum ofputil_protocol);
443 /* Abstract nx_flow_monitor_request. */
444 struct ofputil_flow_monitor_request {
446 enum nx_flow_monitor_flags flags;
449 struct cls_rule match;
452 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
454 void ofputil_append_flow_monitor_request(
455 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
457 /* Abstract nx_flow_update. */
458 struct ofputil_flow_update {
459 enum nx_flow_update_event event;
461 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
462 enum ofp_flow_removed_reason reason;
463 uint16_t idle_timeout;
464 uint16_t hard_timeout;
467 struct cls_rule *match;
468 struct ofpact *ofpacts;
471 /* Used only for NXFME_ABBREV. */
475 int ofputil_decode_flow_update(struct ofputil_flow_update *,
476 struct ofpbuf *msg, struct ofpbuf *ofpacts);
477 void ofputil_start_flow_update(struct list *replies);
478 void ofputil_append_flow_update(const struct ofputil_flow_update *,
479 struct list *replies);
481 /* Abstract nx_flow_monitor_cancel. */
482 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
483 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
485 /* Encoding OpenFlow stats messages. */
486 void ofputil_append_port_desc_stats_reply(uint8_t ofp_version,
487 const struct ofputil_phy_port *pp,
488 struct list *replies);
490 /* Encoding simple OpenFlow messages. */
491 struct ofpbuf *make_echo_request(void);
492 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
494 struct ofpbuf *ofputil_encode_barrier_request(void);
496 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
497 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
502 /* The type of an action.
504 * For each implemented OFPAT10_* and NXAST_* action type, there is a
505 * corresponding constant prefixed with OFPUTIL_, e.g.:
507 * OFPUTIL_OFPAT10_OUTPUT
508 * OFPUTIL_OFPAT10_SET_VLAN_VID
509 * OFPUTIL_OFPAT10_SET_VLAN_PCP
510 * OFPUTIL_OFPAT10_STRIP_VLAN
511 * OFPUTIL_OFPAT10_SET_DL_SRC
512 * OFPUTIL_OFPAT10_SET_DL_DST
513 * OFPUTIL_OFPAT10_SET_NW_SRC
514 * OFPUTIL_OFPAT10_SET_NW_DST
515 * OFPUTIL_OFPAT10_SET_NW_TOS
516 * OFPUTIL_OFPAT10_SET_TP_SRC
517 * OFPUTIL_OFPAT10_SET_TP_DST
518 * OFPUTIL_OFPAT10_ENQUEUE
519 * OFPUTIL_NXAST_RESUBMIT
520 * OFPUTIL_NXAST_SET_TUNNEL
521 * OFPUTIL_NXAST_SET_QUEUE
522 * OFPUTIL_NXAST_POP_QUEUE
523 * OFPUTIL_NXAST_REG_MOVE
524 * OFPUTIL_NXAST_REG_LOAD
526 * OFPUTIL_NXAST_SET_TUNNEL64
527 * OFPUTIL_NXAST_MULTIPATH
528 * OFPUTIL_NXAST_AUTOPATH
529 * OFPUTIL_NXAST_BUNDLE
530 * OFPUTIL_NXAST_BUNDLE_LOAD
531 * OFPUTIL_NXAST_RESUBMIT_TABLE
532 * OFPUTIL_NXAST_OUTPUT_REG
533 * OFPUTIL_NXAST_LEARN
534 * OFPUTIL_NXAST_DEC_TTL
535 * OFPUTIL_NXAST_FIN_TIMEOUT
537 * (The above list helps developers who want to "grep" for these definitions.)
539 enum OVS_PACKED_ENUM ofputil_action_code {
540 OFPUTIL_ACTION_INVALID,
541 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
542 #define OFPAT11_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
543 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
544 #include "ofp-util.def"
547 /* The number of values of "enum ofputil_action_code". */
549 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
550 #define OFPAT11_ACTION(ENUM, STRUCT, NAME) + 1
551 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
552 OFPUTIL_N_ACTIONS = 1
553 #include "ofp-util.def"
556 int ofputil_action_code_from_name(const char *);
558 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
560 /* For each OpenFlow action <ENUM> that has a corresponding action structure
561 * struct <STRUCT>, this defines two functions:
563 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
565 * Initializes the parts of 'action' that identify it as having type <ENUM>
566 * and length 'sizeof *action' and zeros the rest. For actions that have
567 * variable length, the length used and cleared is that of struct <STRUCT>.
569 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
571 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
572 * initializes it with ofputil_init_<ENUM>(), and returns it.
574 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
575 void ofputil_init_##ENUM(struct STRUCT *); \
576 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
577 #define OFPAT11_ACTION(ENUM, STRUCT, NAME) \
578 void ofputil_init_##ENUM(struct STRUCT *); \
579 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
580 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
581 void ofputil_init_##ENUM(struct STRUCT *); \
582 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
583 #include "ofp-util.def"
585 #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
587 enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
588 const struct flow *, int max_ports);
589 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
591 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
592 union ofp_action **, size_t *);
594 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
595 const union ofp_action *b, size_t n_b);
596 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
598 /* Handy utility for parsing flows and actions. */
599 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
601 #endif /* ofp-util.h */