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"
29 #include "openflow/nicira-ext.h"
30 #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 *portp);
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;
86 ofputil_protocol_from_ofp_version(enum ofp_version version);
87 enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
89 bool ofputil_protocol_is_valid(enum ofputil_protocol);
90 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
92 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
93 enum ofputil_protocol ofputil_protocol_set_base(
94 enum ofputil_protocol cur, enum ofputil_protocol new_base);
96 const char *ofputil_protocol_to_string(enum ofputil_protocol);
97 char *ofputil_protocols_to_string(enum ofputil_protocol);
98 enum ofputil_protocol ofputil_protocols_from_string(const char *);
99 enum ofputil_protocol ofputil_usable_protocols(const struct match *);
101 void ofputil_format_version(struct ds *, enum ofp_version);
102 void ofputil_format_version_name(struct ds *, enum ofp_version);
104 /* A bitmap of version numbers
106 * Bit offsets correspond to ofp_version numbers which in turn correspond to
107 * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION)
108 * is the mask for Open Flow 1.1. If the bit for a version is set then it is
109 * allowed, otherwise it is disallowed. */
111 void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
112 void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
114 /* Bitmap of OpenFlow versions that Open vSwitch supports. */
115 #define OFPUTIL_SUPPORTED_VERSIONS \
116 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION))
118 /* Bitmap of OpenFlow versions to enable by default (a subset of
119 * OFPUTIL_SUPPORTED_VERSIONS). */
120 #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
122 enum ofputil_protocol ofputil_protocols_from_string(const char *s);
124 const char *ofputil_version_to_string(enum ofp_version ofp_version);
125 uint32_t ofputil_versions_from_string(const char *s);
127 bool ofputil_decode_hello(const struct ofp_header *,
128 uint32_t *allowed_versions);
129 struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
131 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
132 enum ofputil_protocol want,
133 enum ofputil_protocol *next);
136 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
137 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
138 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
139 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
141 /* Work with ofp10_match. */
142 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
143 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
145 void ofputil_normalize_match(struct match *);
146 void ofputil_normalize_match_quiet(struct match *);
147 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
149 /* Work with ofp11_match. */
150 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
151 uint16_t *padded_match_len);
152 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
154 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
156 /* dl_type translation between OpenFlow and 'struct flow' format. */
157 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
158 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
161 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
162 int ofputil_packet_in_format_from_string(const char *);
163 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
164 struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
165 enum nx_packet_in_format);
167 /* NXT_FLOW_MOD_TABLE_ID extension. */
168 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
170 /* Protocol-independent flow_mod.
172 * The handling of cookies across multiple versions of OpenFlow is a bit
173 * confusing. A full description of Open vSwitch's cookie handling is
174 * in the DESIGN file. The following table shows the expected values of
175 * the cookie-related fields for the different flow_mod commands in
176 * OpenFlow 1.0 ("OF10") and NXM. "<used>" and "-" indicate a value
177 * that may be populated and an ignored field, respectively.
179 * cookie cookie_mask new_cookie
180 * ====== =========== ==========
181 * OF10 Add - 0 <used>
182 * OF10 Modify - 0 <used>
185 * NXM Modify <used> <used> <used>
186 * NXM Delete <used> <used> -
188 struct ofputil_flow_mod {
190 unsigned int priority;
191 ovs_be64 cookie; /* Cookie bits to match. */
192 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
193 ovs_be64 new_cookie; /* New cookie to install or -1. */
196 uint16_t idle_timeout;
197 uint16_t hard_timeout;
201 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
202 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
205 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
206 const struct ofp_header *,
207 enum ofputil_protocol,
208 struct ofpbuf *ofpacts);
209 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
210 enum ofputil_protocol);
212 enum ofputil_protocol ofputil_flow_mod_usable_protocols(
213 const struct ofputil_flow_mod *fms, size_t n_fms);
215 /* Flow stats or aggregate stats request, independent of protocol. */
216 struct ofputil_flow_stats_request {
217 bool aggregate; /* Aggregate results? */
220 ovs_be64 cookie_mask;
225 enum ofperr ofputil_decode_flow_stats_request(
226 struct ofputil_flow_stats_request *, const struct ofp_header *);
227 struct ofpbuf *ofputil_encode_flow_stats_request(
228 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
229 enum ofputil_protocol ofputil_flow_stats_request_usable_protocols(
230 const struct ofputil_flow_stats_request *);
232 /* Flow stats reply, independent of protocol. */
233 struct ofputil_flow_stats {
237 uint32_t duration_sec;
238 uint32_t duration_nsec;
240 uint16_t idle_timeout;
241 uint16_t hard_timeout;
242 int idle_age; /* Seconds since last packet, -1 if unknown. */
243 int hard_age; /* Seconds since last change, -1 if unknown. */
244 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
245 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
246 struct ofpact *ofpacts;
250 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
252 bool flow_age_extension,
253 struct ofpbuf *ofpacts);
254 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
255 struct list *replies);
257 /* Aggregate stats reply, independent of protocol. */
258 struct ofputil_aggregate_stats {
259 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
260 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
264 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
265 const struct ofputil_aggregate_stats *stats,
266 const struct ofp_header *request);
267 enum ofperr ofputil_decode_aggregate_stats_reply(
268 struct ofputil_aggregate_stats *,
269 const struct ofp_header *reply);
271 /* Flow removed message, independent of protocol. */
272 struct ofputil_flow_removed {
276 uint8_t reason; /* One of OFPRR_*. */
277 uint8_t table_id; /* 255 if message didn't include table ID. */
278 uint32_t duration_sec;
279 uint32_t duration_nsec;
280 uint16_t idle_timeout;
281 uint16_t hard_timeout;
282 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
283 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
286 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
287 const struct ofp_header *);
288 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
289 enum ofputil_protocol);
291 /* Abstract packet-in message. */
292 struct ofputil_packet_in {
296 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
297 uint16_t controller_id; /* Controller ID to send to. */
303 uint16_t total_len; /* Full length of frame. */
305 struct flow_metadata fmd; /* Metadata at creation time. */
308 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
309 const struct ofp_header *);
310 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
311 enum ofputil_protocol protocol,
312 enum nx_packet_in_format);
314 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
315 bool ofputil_packet_in_reason_from_string(const char *,
316 enum ofp_packet_in_reason *);
318 /* Abstract packet-out message.
320 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
321 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
322 struct ofputil_packet_out {
323 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
324 size_t packet_len; /* Length of packet data in bytes. */
325 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
326 uint16_t in_port; /* Packet's input port. */
327 struct ofpact *ofpacts; /* Actions. */
328 size_t ofpacts_len; /* Size of ofpacts in bytes. */
331 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
332 const struct ofp_header *,
333 struct ofpbuf *ofpacts);
334 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
335 enum ofputil_protocol protocol);
337 enum ofputil_port_config {
338 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
339 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
340 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
341 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
342 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
343 /* OpenFlow 1.0 only. */
344 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
345 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
346 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
347 /* There are no OpenFlow 1.1-only bits. */
350 enum ofputil_port_state {
351 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
352 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
353 /* OpenFlow 1.1 only. */
354 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
355 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
356 /* OpenFlow 1.0 only. */
357 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
358 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
359 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
360 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
361 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
364 /* Abstract ofp10_phy_port or ofp11_port. */
365 struct ofputil_phy_port {
367 uint8_t hw_addr[OFP_ETH_ALEN];
368 char name[OFP_MAX_PORT_NAME_LEN];
369 enum ofputil_port_config config;
370 enum ofputil_port_state state;
372 /* NETDEV_F_* feature bitmasks. */
373 enum netdev_features curr; /* Current features. */
374 enum netdev_features advertised; /* Features advertised by the port. */
375 enum netdev_features supported; /* Features supported by the port. */
376 enum netdev_features peer; /* Features advertised by peer. */
379 uint32_t curr_speed; /* Current speed, in kbps. */
380 uint32_t max_speed; /* Maximum supported speed, in kbps. */
383 enum ofputil_capabilities {
384 /* OpenFlow 1.0, 1.1 and 1.2 share these values for these capabilities. */
385 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
386 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
387 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
388 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
389 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
391 /* OpenFlow 1.0 and 1.1 share this capability. */
392 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
394 /* OpenFlow 1.0 only. */
395 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
397 /* OpenFlow 1.1 and 1.2 share this capability. */
398 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
400 /* OpenFlow 1.2 only */
401 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
404 enum ofputil_action_bitmap {
405 OFPUTIL_A_OUTPUT = 1 << 0,
406 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
407 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
408 OFPUTIL_A_STRIP_VLAN = 1 << 3,
409 OFPUTIL_A_SET_DL_SRC = 1 << 4,
410 OFPUTIL_A_SET_DL_DST = 1 << 5,
411 OFPUTIL_A_SET_NW_SRC = 1 << 6,
412 OFPUTIL_A_SET_NW_DST = 1 << 7,
413 OFPUTIL_A_SET_NW_ECN = 1 << 8,
414 OFPUTIL_A_SET_NW_TOS = 1 << 9,
415 OFPUTIL_A_SET_TP_SRC = 1 << 10,
416 OFPUTIL_A_SET_TP_DST = 1 << 11,
417 OFPUTIL_A_ENQUEUE = 1 << 12,
418 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
419 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
420 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
421 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
422 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
423 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
424 OFPUTIL_A_PUSH_VLAN = 1 << 19,
425 OFPUTIL_A_POP_VLAN = 1 << 20,
426 OFPUTIL_A_PUSH_MPLS = 1 << 21,
427 OFPUTIL_A_POP_MPLS = 1 << 22,
428 OFPUTIL_A_SET_QUEUE = 1 << 23,
429 OFPUTIL_A_GROUP = 1 << 24,
430 OFPUTIL_A_SET_NW_TTL = 1 << 25,
431 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
432 OFPUTIL_A_SET_FIELD = 1 << 27,
435 /* Abstract ofp_switch_features. */
436 struct ofputil_switch_features {
437 uint64_t datapath_id; /* Datapath unique ID. */
438 uint32_t n_buffers; /* Max packets buffered at once. */
439 uint8_t n_tables; /* Number of tables supported by datapath. */
440 enum ofputil_capabilities capabilities;
441 enum ofputil_action_bitmap actions;
444 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
445 struct ofputil_switch_features *,
448 struct ofpbuf *ofputil_encode_switch_features(
449 const struct ofputil_switch_features *, enum ofputil_protocol,
451 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
453 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
455 /* phy_port helper functions. */
456 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
457 struct ofputil_phy_port *);
458 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
460 /* Abstract ofp_port_status. */
461 struct ofputil_port_status {
462 enum ofp_port_reason reason;
463 struct ofputil_phy_port desc;
466 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
467 struct ofputil_port_status *);
468 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
469 enum ofputil_protocol);
471 /* Abstract ofp_port_mod. */
472 struct ofputil_port_mod {
474 uint8_t hw_addr[OFP_ETH_ALEN];
475 enum ofputil_port_config config;
476 enum ofputil_port_config mask;
477 enum netdev_features advertise;
480 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
481 struct ofputil_port_mod *);
482 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
483 enum ofputil_protocol);
485 /* Abstract table stats.
487 * For now we use ofp12_table_stats as a superset of the other protocol
488 * versions' table stats. */
490 struct ofpbuf *ofputil_encode_table_stats_reply(
491 const struct ofp12_table_stats[], int n,
492 const struct ofp_header *request);
494 /* Abstract nx_flow_monitor_request. */
495 struct ofputil_flow_monitor_request {
497 enum nx_flow_monitor_flags flags;
503 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
505 void ofputil_append_flow_monitor_request(
506 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
508 /* Abstract nx_flow_update. */
509 struct ofputil_flow_update {
510 enum nx_flow_update_event event;
512 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
513 enum ofp_flow_removed_reason reason;
514 uint16_t idle_timeout;
515 uint16_t hard_timeout;
520 struct ofpact *ofpacts;
523 /* Used only for NXFME_ABBREV. */
527 int ofputil_decode_flow_update(struct ofputil_flow_update *,
528 struct ofpbuf *msg, struct ofpbuf *ofpacts);
529 void ofputil_start_flow_update(struct list *replies);
530 void ofputil_append_flow_update(const struct ofputil_flow_update *,
531 struct list *replies);
533 /* Abstract nx_flow_monitor_cancel. */
534 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
535 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
537 /* Encoding OpenFlow stats messages. */
538 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
539 const struct ofputil_phy_port *pp,
540 struct list *replies);
542 /* Encoding simple OpenFlow messages. */
543 struct ofpbuf *make_echo_request(enum ofp_version);
544 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
546 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
548 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
549 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
554 /* The type of an action.
556 * For each implemented OFPAT10_* and NXAST_* action type, there is a
557 * corresponding constant prefixed with OFPUTIL_, e.g.:
559 * OFPUTIL_OFPAT10_OUTPUT
560 * OFPUTIL_OFPAT10_SET_VLAN_VID
561 * OFPUTIL_OFPAT10_SET_VLAN_PCP
562 * OFPUTIL_OFPAT10_STRIP_VLAN
563 * OFPUTIL_OFPAT10_SET_DL_SRC
564 * OFPUTIL_OFPAT10_SET_DL_DST
565 * OFPUTIL_OFPAT10_SET_NW_SRC
566 * OFPUTIL_OFPAT10_SET_NW_DST
567 * OFPUTIL_OFPAT10_SET_NW_TOS
568 * OFPUTIL_OFPAT10_SET_TP_SRC
569 * OFPUTIL_OFPAT10_SET_TP_DST
570 * OFPUTIL_OFPAT10_ENQUEUE
571 * OFPUTIL_NXAST_RESUBMIT
572 * OFPUTIL_NXAST_SET_TUNNEL
573 * OFPUTIL_NXAST_SET_METADATA
574 * OFPUTIL_NXAST_SET_QUEUE
575 * OFPUTIL_NXAST_POP_QUEUE
576 * OFPUTIL_NXAST_REG_MOVE
577 * OFPUTIL_NXAST_REG_LOAD
579 * OFPUTIL_NXAST_SET_TUNNEL64
580 * OFPUTIL_NXAST_MULTIPATH
581 * OFPUTIL_NXAST_AUTOPATH
582 * OFPUTIL_NXAST_BUNDLE
583 * OFPUTIL_NXAST_BUNDLE_LOAD
584 * OFPUTIL_NXAST_RESUBMIT_TABLE
585 * OFPUTIL_NXAST_OUTPUT_REG
586 * OFPUTIL_NXAST_LEARN
587 * OFPUTIL_NXAST_DEC_TTL
588 * OFPUTIL_NXAST_FIN_TIMEOUT
590 * (The above list helps developers who want to "grep" for these definitions.)
592 enum OVS_PACKED_ENUM ofputil_action_code {
593 OFPUTIL_ACTION_INVALID,
594 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
595 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
596 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
597 #include "ofp-util.def"
600 /* The number of values of "enum ofputil_action_code". */
602 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
603 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
604 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
605 OFPUTIL_N_ACTIONS = 1
606 #include "ofp-util.def"
609 int ofputil_action_code_from_name(const char *);
611 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
613 /* For each OpenFlow action <ENUM> that has a corresponding action structure
614 * struct <STRUCT>, this defines two functions:
616 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
618 * Initializes the parts of 'action' that identify it as having type <ENUM>
619 * and length 'sizeof *action' and zeros the rest. For actions that have
620 * variable length, the length used and cleared is that of struct <STRUCT>.
622 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
624 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
625 * initializes it with ofputil_init_<ENUM>(), and returns it.
627 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
628 void ofputil_init_##ENUM(struct STRUCT *); \
629 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
630 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
631 void ofputil_init_##ENUM(struct STRUCT *); \
632 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
633 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
634 void ofputil_init_##ENUM(struct STRUCT *); \
635 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
636 #include "ofp-util.def"
638 #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
640 enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
641 const struct flow *, int max_ports);
642 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
644 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
645 union ofp_action **, size_t *);
647 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
648 const union ofp_action *b, size_t n_b);
649 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
651 /* Handy utility for parsing flows and actions. */
652 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
654 struct ofpbuf *ofputlil_dump_ports(enum ofp_version ofp_version, int16_t port);
656 struct ofputil_port_stats {
658 struct netdev_stats stats;
661 struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
663 void ofputil_append_port_stat(struct list *replies,
664 const struct ofputil_port_stats *ops);
665 size_t ofputil_count_port_stats(const struct ofp_header *);
666 int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
667 enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
668 uint16_t *ofp10_port);
670 struct ofputil_queue_stats_request {
676 ofputil_decode_queue_stats_request(const struct ofp_header *request,
677 struct ofputil_queue_stats_request *oqsr);
679 ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
680 const struct ofputil_queue_stats_request *oqsr);
682 struct ofputil_queue_stats {
685 struct netdev_queue_stats stats;
688 size_t ofputil_count_queue_stats(const struct ofp_header *);
689 int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
690 void ofputil_append_queue_stat(struct list *replies,
691 const struct ofputil_queue_stats *oqs);
693 #endif /* ofp-util.h */