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 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
50 * a bit extra about the flow match format in use.
52 * These are arranged from most portable to least portable, or alternatively
53 * from least powerful to most powerful. Protocols earlier on the list are
54 * more likely to be understood for the purpose of making requests, but
55 * protocol later on the list are more likely to accurately describe a flow
58 * On any given OpenFlow connection, a single protocol is in effect at any
59 * given time. These values use separate bits only because that makes it easy
60 * to test whether a particular protocol is within a given set of protocols and
61 * to implement set union and intersection.
63 enum ofputil_protocol {
64 /* OpenFlow 1.0 protocols.
66 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
67 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
69 * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
70 * extension has been enabled. The other protocols have it disabled.
72 #define OFPUTIL_P_NONE 0
73 OFPUTIL_P_OF10_STD = 1 << 0,
74 OFPUTIL_P_OF10_STD_TID = 1 << 1,
75 OFPUTIL_P_OF10_NXM = 1 << 2,
76 OFPUTIL_P_OF10_NXM_TID = 1 << 3,
77 #define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
78 #define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
80 /* OpenFlow 1.2+ protocols (only one variant each).
82 * These use the standard OpenFlow Extensible Match (OXM) flow format.
84 * OpenFlow 1.2+ always operates with an equivalent of the
85 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
87 OFPUTIL_P_OF12_OXM = 1 << 4,
88 OFPUTIL_P_OF13_OXM = 1 << 5,
89 #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM)
92 #define OFPUTIL_P_ANY ((1 << 6) - 1)
94 /* Protocols in which a specific table may be specified in flow_mods. */
95 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
96 OFPUTIL_P_OF10_NXM_TID | \
100 /* Protocols to use for flow dumps, from most to least preferred. */
101 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
102 extern size_t ofputil_n_flow_dump_protocols;
104 enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
105 enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
106 enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
108 bool ofputil_protocol_is_valid(enum ofputil_protocol);
109 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
111 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
112 enum ofputil_protocol ofputil_protocol_set_base(
113 enum ofputil_protocol cur, enum ofputil_protocol new_base);
115 const char *ofputil_protocol_to_string(enum ofputil_protocol);
116 char *ofputil_protocols_to_string(enum ofputil_protocol);
117 enum ofputil_protocol ofputil_protocols_from_string(const char *);
118 enum ofputil_protocol ofputil_usable_protocols(const struct match *);
120 void ofputil_format_version(struct ds *, enum ofp_version);
121 void ofputil_format_version_name(struct ds *, enum ofp_version);
123 /* A bitmap of version numbers
125 * Bit offsets correspond to ofp_version numbers which in turn correspond to
126 * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION)
127 * is the mask for Open Flow 1.1. If the bit for a version is set then it is
128 * allowed, otherwise it is disallowed. */
130 void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
131 void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
133 uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
134 enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
136 /* Bitmap of OpenFlow versions that Open vSwitch supports. */
137 #define OFPUTIL_SUPPORTED_VERSIONS \
138 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
140 /* Bitmap of OpenFlow versions to enable by default (a subset of
141 * OFPUTIL_SUPPORTED_VERSIONS). */
142 #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
144 enum ofputil_protocol ofputil_protocols_from_string(const char *s);
146 const char *ofputil_version_to_string(enum ofp_version ofp_version);
147 uint32_t ofputil_versions_from_string(const char *s);
148 uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
150 bool ofputil_decode_hello(const struct ofp_header *,
151 uint32_t *allowed_versions);
152 struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
154 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
155 enum ofputil_protocol want,
156 enum ofputil_protocol *next);
159 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
160 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
161 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
162 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
164 /* Work with ofp10_match. */
165 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
166 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
168 void ofputil_normalize_match(struct match *);
169 void ofputil_normalize_match_quiet(struct match *);
170 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
172 /* Work with ofp11_match. */
173 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
174 uint16_t *padded_match_len);
175 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
177 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
179 /* dl_type translation between OpenFlow and 'struct flow' format. */
180 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
181 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
184 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
185 int ofputil_packet_in_format_from_string(const char *);
186 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
187 struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
188 enum nx_packet_in_format);
190 /* NXT_FLOW_MOD_TABLE_ID extension. */
191 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
193 /* Protocol-independent flow_mod.
195 * The handling of cookies across multiple versions of OpenFlow is a bit
196 * confusing. A full description of Open vSwitch's cookie handling is
197 * in the DESIGN file. The following table shows the expected values of
198 * the cookie-related fields for the different flow_mod commands in
199 * OpenFlow 1.0 ("OF10") and NXM. "<used>" and "-" indicate a value
200 * that may be populated and an ignored field, respectively.
202 * cookie cookie_mask new_cookie
203 * ====== =========== ==========
204 * OF10 Add - 0 <used>
205 * OF10 Modify - 0 <used>
208 * NXM Modify <used> <used> <used>
209 * NXM Delete <used> <used> -
211 struct ofputil_flow_mod {
213 unsigned int priority;
214 ovs_be64 cookie; /* Cookie bits to match. */
215 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
216 ovs_be64 new_cookie; /* New cookie to install or -1. */
219 uint16_t idle_timeout;
220 uint16_t hard_timeout;
224 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
225 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
228 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
229 const struct ofp_header *,
230 enum ofputil_protocol,
231 struct ofpbuf *ofpacts);
232 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
233 enum ofputil_protocol);
235 enum ofputil_protocol ofputil_flow_mod_usable_protocols(
236 const struct ofputil_flow_mod *fms, size_t n_fms);
238 /* Flow stats or aggregate stats request, independent of protocol. */
239 struct ofputil_flow_stats_request {
240 bool aggregate; /* Aggregate results? */
243 ovs_be64 cookie_mask;
248 enum ofperr ofputil_decode_flow_stats_request(
249 struct ofputil_flow_stats_request *, const struct ofp_header *);
250 struct ofpbuf *ofputil_encode_flow_stats_request(
251 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
252 enum ofputil_protocol ofputil_flow_stats_request_usable_protocols(
253 const struct ofputil_flow_stats_request *);
255 /* Flow stats reply, independent of protocol. */
256 struct ofputil_flow_stats {
260 uint32_t duration_sec;
261 uint32_t duration_nsec;
263 uint16_t idle_timeout;
264 uint16_t hard_timeout;
265 int idle_age; /* Seconds since last packet, -1 if unknown. */
266 int hard_age; /* Seconds since last change, -1 if unknown. */
267 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
268 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
269 struct ofpact *ofpacts;
271 uint16_t flags; /* Added for OF 1.3 */
274 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
276 bool flow_age_extension,
277 struct ofpbuf *ofpacts);
278 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
279 struct list *replies);
281 /* Aggregate stats reply, independent of protocol. */
282 struct ofputil_aggregate_stats {
283 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
284 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
288 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
289 const struct ofputil_aggregate_stats *stats,
290 const struct ofp_header *request);
291 enum ofperr ofputil_decode_aggregate_stats_reply(
292 struct ofputil_aggregate_stats *,
293 const struct ofp_header *reply);
295 /* Flow removed message, independent of protocol. */
296 struct ofputil_flow_removed {
300 uint8_t reason; /* One of OFPRR_*. */
301 uint8_t table_id; /* 255 if message didn't include table ID. */
302 uint32_t duration_sec;
303 uint32_t duration_nsec;
304 uint16_t idle_timeout;
305 uint16_t hard_timeout;
306 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
307 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
310 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
311 const struct ofp_header *);
312 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
313 enum ofputil_protocol);
315 /* Abstract packet-in message. */
316 struct ofputil_packet_in {
320 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
321 uint16_t controller_id; /* Controller ID to send to. */
327 uint16_t total_len; /* Full length of frame. */
329 struct flow_metadata fmd; /* Metadata at creation time. */
332 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
333 const struct ofp_header *);
334 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
335 enum ofputil_protocol protocol,
336 enum nx_packet_in_format);
338 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
339 bool ofputil_packet_in_reason_from_string(const char *,
340 enum ofp_packet_in_reason *);
342 /* Abstract packet-out message.
344 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
345 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
346 struct ofputil_packet_out {
347 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
348 size_t packet_len; /* Length of packet data in bytes. */
349 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
350 uint16_t in_port; /* Packet's input port. */
351 struct ofpact *ofpacts; /* Actions. */
352 size_t ofpacts_len; /* Size of ofpacts in bytes. */
355 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
356 const struct ofp_header *,
357 struct ofpbuf *ofpacts);
358 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
359 enum ofputil_protocol protocol);
361 enum ofputil_port_config {
362 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
363 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
364 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
365 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
366 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
367 /* OpenFlow 1.0 only. */
368 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
369 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
370 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
371 /* There are no OpenFlow 1.1-only bits. */
374 enum ofputil_port_state {
375 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
376 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
377 /* OpenFlow 1.1 only. */
378 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
379 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
380 /* OpenFlow 1.0 only. */
381 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
382 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
383 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
384 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
385 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
388 /* Abstract ofp10_phy_port or ofp11_port. */
389 struct ofputil_phy_port {
391 uint8_t hw_addr[OFP_ETH_ALEN];
392 char name[OFP_MAX_PORT_NAME_LEN];
393 enum ofputil_port_config config;
394 enum ofputil_port_state state;
396 /* NETDEV_F_* feature bitmasks. */
397 enum netdev_features curr; /* Current features. */
398 enum netdev_features advertised; /* Features advertised by the port. */
399 enum netdev_features supported; /* Features supported by the port. */
400 enum netdev_features peer; /* Features advertised by peer. */
403 uint32_t curr_speed; /* Current speed, in kbps. */
404 uint32_t max_speed; /* Maximum supported speed, in kbps. */
407 enum ofputil_capabilities {
408 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
409 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
410 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
411 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
412 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
413 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
415 /* OpenFlow 1.0 and 1.1 share this capability. */
416 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
418 /* OpenFlow 1.0 only. */
419 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
421 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
422 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
424 /* OpenFlow 1.2 and 1.3 share this capability */
425 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
428 enum ofputil_action_bitmap {
429 OFPUTIL_A_OUTPUT = 1 << 0,
430 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
431 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
432 OFPUTIL_A_STRIP_VLAN = 1 << 3,
433 OFPUTIL_A_SET_DL_SRC = 1 << 4,
434 OFPUTIL_A_SET_DL_DST = 1 << 5,
435 OFPUTIL_A_SET_NW_SRC = 1 << 6,
436 OFPUTIL_A_SET_NW_DST = 1 << 7,
437 OFPUTIL_A_SET_NW_ECN = 1 << 8,
438 OFPUTIL_A_SET_NW_TOS = 1 << 9,
439 OFPUTIL_A_SET_TP_SRC = 1 << 10,
440 OFPUTIL_A_SET_TP_DST = 1 << 11,
441 OFPUTIL_A_ENQUEUE = 1 << 12,
442 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
443 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
444 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
445 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
446 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
447 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
448 OFPUTIL_A_PUSH_VLAN = 1 << 19,
449 OFPUTIL_A_POP_VLAN = 1 << 20,
450 OFPUTIL_A_PUSH_MPLS = 1 << 21,
451 OFPUTIL_A_POP_MPLS = 1 << 22,
452 OFPUTIL_A_SET_QUEUE = 1 << 23,
453 OFPUTIL_A_GROUP = 1 << 24,
454 OFPUTIL_A_SET_NW_TTL = 1 << 25,
455 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
456 OFPUTIL_A_SET_FIELD = 1 << 27,
459 /* Abstract ofp_switch_features. */
460 struct ofputil_switch_features {
461 uint64_t datapath_id; /* Datapath unique ID. */
462 uint32_t n_buffers; /* Max packets buffered at once. */
463 uint8_t n_tables; /* Number of tables supported by datapath. */
464 uint8_t auxiliary_id; /* Identify auxiliary connections */
465 enum ofputil_capabilities capabilities;
466 enum ofputil_action_bitmap actions;
469 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
470 struct ofputil_switch_features *,
473 struct ofpbuf *ofputil_encode_switch_features(
474 const struct ofputil_switch_features *, enum ofputil_protocol,
476 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
478 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
480 /* phy_port helper functions. */
481 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
482 struct ofputil_phy_port *);
483 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
485 /* Abstract ofp_port_status. */
486 struct ofputil_port_status {
487 enum ofp_port_reason reason;
488 struct ofputil_phy_port desc;
491 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
492 struct ofputil_port_status *);
493 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
494 enum ofputil_protocol);
496 /* Abstract ofp_port_mod. */
497 struct ofputil_port_mod {
499 uint8_t hw_addr[OFP_ETH_ALEN];
500 enum ofputil_port_config config;
501 enum ofputil_port_config mask;
502 enum netdev_features advertise;
505 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
506 struct ofputil_port_mod *);
507 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
508 enum ofputil_protocol);
510 /* Abstract table stats.
512 * For now we use ofp12_table_stats as a superset of the other protocol
513 * versions' table stats. */
515 struct ofpbuf *ofputil_encode_table_stats_reply(
516 const struct ofp12_table_stats[], int n,
517 const struct ofp_header *request);
519 /* Abstract nx_flow_monitor_request. */
520 struct ofputil_flow_monitor_request {
522 enum nx_flow_monitor_flags flags;
528 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
530 void ofputil_append_flow_monitor_request(
531 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
533 /* Abstract nx_flow_update. */
534 struct ofputil_flow_update {
535 enum nx_flow_update_event event;
537 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
538 enum ofp_flow_removed_reason reason;
539 uint16_t idle_timeout;
540 uint16_t hard_timeout;
545 struct ofpact *ofpacts;
548 /* Used only for NXFME_ABBREV. */
552 int ofputil_decode_flow_update(struct ofputil_flow_update *,
553 struct ofpbuf *msg, struct ofpbuf *ofpacts);
554 void ofputil_start_flow_update(struct list *replies);
555 void ofputil_append_flow_update(const struct ofputil_flow_update *,
556 struct list *replies);
558 /* Abstract nx_flow_monitor_cancel. */
559 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
560 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
562 /* Encoding OpenFlow stats messages. */
563 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
564 const struct ofputil_phy_port *pp,
565 struct list *replies);
567 /* Encoding simple OpenFlow messages. */
568 struct ofpbuf *make_echo_request(enum ofp_version);
569 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
571 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
573 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
574 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
579 /* The type of an action.
581 * For each implemented OFPAT10_* and NXAST_* action type, there is a
582 * corresponding constant prefixed with OFPUTIL_, e.g.:
584 * OFPUTIL_OFPAT10_OUTPUT
585 * OFPUTIL_OFPAT10_SET_VLAN_VID
586 * OFPUTIL_OFPAT10_SET_VLAN_PCP
587 * OFPUTIL_OFPAT10_STRIP_VLAN
588 * OFPUTIL_OFPAT10_SET_DL_SRC
589 * OFPUTIL_OFPAT10_SET_DL_DST
590 * OFPUTIL_OFPAT10_SET_NW_SRC
591 * OFPUTIL_OFPAT10_SET_NW_DST
592 * OFPUTIL_OFPAT10_SET_NW_TOS
593 * OFPUTIL_OFPAT10_SET_TP_SRC
594 * OFPUTIL_OFPAT10_SET_TP_DST
595 * OFPUTIL_OFPAT10_ENQUEUE
596 * OFPUTIL_NXAST_RESUBMIT
597 * OFPUTIL_NXAST_SET_TUNNEL
598 * OFPUTIL_NXAST_SET_METADATA
599 * OFPUTIL_NXAST_SET_QUEUE
600 * OFPUTIL_NXAST_POP_QUEUE
601 * OFPUTIL_NXAST_REG_MOVE
602 * OFPUTIL_NXAST_REG_LOAD
604 * OFPUTIL_NXAST_SET_TUNNEL64
605 * OFPUTIL_NXAST_MULTIPATH
606 * OFPUTIL_NXAST_AUTOPATH
607 * OFPUTIL_NXAST_BUNDLE
608 * OFPUTIL_NXAST_BUNDLE_LOAD
609 * OFPUTIL_NXAST_RESUBMIT_TABLE
610 * OFPUTIL_NXAST_OUTPUT_REG
611 * OFPUTIL_NXAST_LEARN
612 * OFPUTIL_NXAST_DEC_TTL
613 * OFPUTIL_NXAST_FIN_TIMEOUT
615 * (The above list helps developers who want to "grep" for these definitions.)
617 enum OVS_PACKED_ENUM ofputil_action_code {
618 OFPUTIL_ACTION_INVALID,
619 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
620 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
621 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
622 #include "ofp-util.def"
625 /* The number of values of "enum ofputil_action_code". */
627 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
628 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
629 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
630 OFPUTIL_N_ACTIONS = 1
631 #include "ofp-util.def"
634 int ofputil_action_code_from_name(const char *);
636 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
638 /* For each OpenFlow action <ENUM> that has a corresponding action structure
639 * struct <STRUCT>, this defines two functions:
641 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
643 * Initializes the parts of 'action' that identify it as having type <ENUM>
644 * and length 'sizeof *action' and zeros the rest. For actions that have
645 * variable length, the length used and cleared is that of struct <STRUCT>.
647 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
649 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
650 * initializes it with ofputil_init_<ENUM>(), and returns it.
652 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
653 void ofputil_init_##ENUM(struct STRUCT *); \
654 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
655 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
656 void ofputil_init_##ENUM(struct STRUCT *); \
657 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
658 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
659 void ofputil_init_##ENUM(struct STRUCT *); \
660 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
661 #include "ofp-util.def"
663 #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
665 enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
666 const struct flow *, int max_ports);
667 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
669 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
670 union ofp_action **, size_t *);
672 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
673 const union ofp_action *b, size_t n_b);
674 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
676 /* Handy utility for parsing flows and actions. */
677 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
679 struct ofpbuf *ofputlil_dump_ports(enum ofp_version ofp_version, int16_t port);
681 struct ofputil_port_stats {
683 struct netdev_stats stats;
686 struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
688 void ofputil_append_port_stat(struct list *replies,
689 const struct ofputil_port_stats *ops);
690 size_t ofputil_count_port_stats(const struct ofp_header *);
691 int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
692 enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
693 uint16_t *ofp10_port);
695 struct ofputil_queue_stats_request {
696 uint16_t port_no; /* OFPP_ANY means "all ports". */
701 ofputil_decode_queue_stats_request(const struct ofp_header *request,
702 struct ofputil_queue_stats_request *oqsr);
704 ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
705 const struct ofputil_queue_stats_request *oqsr);
707 struct ofputil_queue_stats {
710 struct netdev_queue_stats stats;
713 size_t ofputil_count_queue_stats(const struct ofp_header *);
714 int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
715 void ofputil_append_queue_stat(struct list *replies,
716 const struct ofputil_queue_stats *oqs);
718 #endif /* ofp-util.h */