2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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.
28 #include "meta-flow.h"
30 #include "openflow/netronome-ext.h"
31 #include "openflow/nicira-ext.h"
32 #include "openvswitch/types.h"
33 #include "type-props.h"
37 struct ofpact_set_field;
41 enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
42 ofp_port_t *ofp10_port);
43 ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);
45 bool ofputil_port_from_string(const char *, ofp_port_t *portp);
46 void ofputil_format_port(ofp_port_t port, struct ds *);
47 void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
51 enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) };
52 bool ofputil_group_from_string(const char *, uint32_t *group_id);
53 void ofputil_format_group(uint32_t group_id, struct ds *);
54 void ofputil_group_to_string(uint32_t group_id,
55 char namebuf[MAX_GROUP_NAME_LEN + 1],
58 /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
59 * to and from IP bitmasks. */
60 ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
61 int ofputil_netmask_to_wcbits(ovs_be32 netmask);
65 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
66 * a bit extra about the flow match format in use.
68 * These are arranged from most portable to least portable, or alternatively
69 * from least powerful to most powerful. Protocols earlier on the list are
70 * more likely to be understood for the purpose of making requests, but
71 * protocol later on the list are more likely to accurately describe a flow
74 * On any given OpenFlow connection, a single protocol is in effect at any
75 * given time. These values use separate bits only because that makes it easy
76 * to test whether a particular protocol is within a given set of protocols and
77 * to implement set union and intersection.
79 enum ofputil_protocol {
80 /* OpenFlow 1.0 protocols.
82 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
83 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
85 * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
86 * extension has been enabled. The other protocols have it disabled.
88 #define OFPUTIL_P_NONE 0
89 OFPUTIL_P_OF10_STD = 1 << 0,
90 OFPUTIL_P_OF10_STD_TID = 1 << 1,
91 OFPUTIL_P_OF10_NXM = 1 << 2,
92 OFPUTIL_P_OF10_NXM_TID = 1 << 3,
93 #define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
94 #define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
95 #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY)
97 /* OpenFlow 1.1 protocol.
99 * We only support the standard OpenFlow 1.1 flow format.
101 * OpenFlow 1.1 always operates with an equivalent of the
102 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
104 OFPUTIL_P_OF11_STD = 1 << 4,
106 /* OpenFlow 1.2+ protocols (only one variant each).
108 * These use the standard OpenFlow Extensible Match (OXM) flow format.
110 * OpenFlow 1.2+ always operates with an equivalent of the
111 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
113 OFPUTIL_P_OF12_OXM = 1 << 5,
114 OFPUTIL_P_OF13_OXM = 1 << 6,
115 OFPUTIL_P_OF14_OXM = 1 << 7,
116 OFPUTIL_P_OF15_OXM = 1 << 8,
117 #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | \
118 OFPUTIL_P_OF13_OXM | \
119 OFPUTIL_P_OF14_OXM | \
122 #define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
125 #define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
127 #define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
129 #define OFPUTIL_P_OF12_UP (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_UP)
130 #define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM | OFPUTIL_P_OF14_UP)
131 #define OFPUTIL_P_OF14_UP (OFPUTIL_P_OF14_OXM | OFPUTIL_P_OF15_UP)
132 #define OFPUTIL_P_OF15_UP OFPUTIL_P_OF15_OXM
135 #define OFPUTIL_P_ANY ((1 << 9) - 1)
137 /* Protocols in which a specific table may be specified in flow_mods. */
138 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
139 OFPUTIL_P_OF10_NXM_TID | \
140 OFPUTIL_P_OF11_STD | \
144 /* Protocols to use for flow dumps, from most to least preferred. */
145 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
146 extern size_t ofputil_n_flow_dump_protocols;
148 enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
149 enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
150 enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
152 bool ofputil_protocol_is_valid(enum ofputil_protocol);
153 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
155 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
156 enum ofputil_protocol ofputil_protocol_set_base(
157 enum ofputil_protocol cur, enum ofputil_protocol new_base);
159 const char *ofputil_protocol_to_string(enum ofputil_protocol);
160 char *ofputil_protocols_to_string(enum ofputil_protocol);
161 enum ofputil_protocol ofputil_protocols_from_string(const char *);
163 void ofputil_format_version(struct ds *, enum ofp_version);
164 void ofputil_format_version_name(struct ds *, enum ofp_version);
166 /* A bitmap of version numbers
168 * Bit offsets correspond to ofp_version numbers which in turn correspond to
169 * wire-protocol numbers for OpenFlow versions, e.g. (1u << OFP11_VERSION)
170 * is the mask for OpenFlow 1.1. If the bit for a version is set then it is
171 * allowed, otherwise it is disallowed. */
173 void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
174 void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
176 enum ofp_version ofputil_version_from_string(const char *s);
178 uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
179 enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
181 /* Bitmaps of OpenFlow versions that Open vSwitch supports, and that it enables
182 * by default. When Open vSwitch has experimental or incomplete support for
183 * newer versions of OpenFlow, those versions should not be supported by
184 * default and thus should be omitted from the latter bitmap. */
185 #define OFPUTIL_SUPPORTED_VERSIONS ((1u << OFP10_VERSION) | \
186 (1u << OFP11_VERSION) | \
187 (1u << OFP12_VERSION) | \
188 (1u << OFP13_VERSION))
189 #define OFPUTIL_DEFAULT_VERSIONS OFPUTIL_SUPPORTED_VERSIONS
191 enum ofputil_protocol ofputil_protocols_from_string(const char *s);
193 const char *ofputil_version_to_string(enum ofp_version ofp_version);
194 uint32_t ofputil_versions_from_string(const char *s);
195 uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
197 bool ofputil_decode_hello(const struct ofp_header *,
198 uint32_t *allowed_versions);
199 struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
201 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
202 enum ofputil_protocol want,
203 enum ofputil_protocol *next);
206 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
207 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
208 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
209 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
211 /* Work with ofp10_match. */
212 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
213 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
215 void ofputil_normalize_match(struct match *);
216 void ofputil_normalize_match_quiet(struct match *);
217 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
219 /* Work with ofp11_match. */
220 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
221 uint16_t *padded_match_len);
222 enum ofperr ofputil_pull_ofp11_mask(struct ofpbuf *, struct match *,
223 struct mf_bitmap *bm);
224 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
226 int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *,
227 enum ofputil_protocol);
228 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
229 int ofputil_match_typical_len(enum ofputil_protocol);
231 /* dl_type translation between OpenFlow and 'struct flow' format. */
232 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
233 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
236 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
237 int ofputil_packet_in_format_from_string(const char *);
238 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
239 struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
240 enum nx_packet_in_format);
242 /* NXT_FLOW_MOD_TABLE_ID extension. */
243 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
245 /* Protocol-independent flow_mod flags. */
246 enum ofputil_flow_mod_flags {
247 /* Flags that are maintained with a flow as part of its state.
249 * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */
250 OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */
251 OFPUTIL_FF_NO_PKT_COUNTS = 1 << 1, /* OpenFlow 1.3+. */
252 OFPUTIL_FF_NO_BYT_COUNTS = 1 << 2, /* OpenFlow 1.3+. */
254 /* These flags primarily affects flow_mod behavior. They are not
255 * particularly useful as part of flow state. We include them in flow
256 * state only because OpenFlow implies that they should be. */
257 OFPUTIL_FF_CHECK_OVERLAP = 1 << 3, /* All versions. */
258 OFPUTIL_FF_RESET_COUNTS = 1 << 4, /* OpenFlow 1.2+. */
260 /* Not supported by OVS. */
261 OFPUTIL_FF_EMERG = 1 << 5, /* OpenFlow 1.0 only. */
263 /* The set of flags maintained as part of a flow table entry. */
264 #define OFPUTIL_FF_STATE (OFPUTIL_FF_SEND_FLOW_REM \
265 | OFPUTIL_FF_NO_PKT_COUNTS \
266 | OFPUTIL_FF_NO_BYT_COUNTS \
267 | OFPUTIL_FF_CHECK_OVERLAP \
268 | OFPUTIL_FF_RESET_COUNTS)
270 /* Flags that are only set by OVS for its internal use. Cannot be set via
272 OFPUTIL_FF_HIDDEN_FIELDS = 1 << 6, /* Allow hidden match fields to be
274 OFPUTIL_FF_NO_READONLY = 1 << 7, /* Allow rules within read only tables
278 /* Protocol-independent flow_mod.
280 * The handling of cookies across multiple versions of OpenFlow is a bit
281 * confusing. See DESIGN for the details. */
282 struct ofputil_flow_mod {
283 struct ovs_list list_node; /* For queuing flow_mods. */
288 /* Cookie matching. The flow_mod affects only flows that have cookies that
289 * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits.
291 * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
292 ovs_be64 cookie; /* Cookie bits to match. */
293 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
297 * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie'
298 * should not be UINT64_MAX.
300 * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
302 * - If one or more matching flows exist and 'modify_cookie' is true,
303 * then the flow_mod changes the existing flows' cookies to
304 * 'new_cookie'. 'new_cookie' should not be UINT64_MAX.
306 * - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and
307 * 'cookie_mask' is 0, then the flow_mod adds a new flow with
308 * 'new_cookie' as its cookie.
310 ovs_be64 new_cookie; /* New cookie to install or UINT64_MAX. */
311 bool modify_cookie; /* Set cookie of existing flow to 'new_cookie'? */
315 uint16_t idle_timeout;
316 uint16_t hard_timeout;
320 enum ofputil_flow_mod_flags flags;
321 uint16_t importance; /* Eviction precedence. */
322 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
323 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
325 /* Reason for delete; ignored for non-delete commands */
326 enum ofp_flow_removed_reason delete_reason;
329 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
330 const struct ofp_header *,
331 enum ofputil_protocol,
332 struct ofpbuf *ofpacts,
335 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
336 enum ofputil_protocol);
338 /* Flow stats or aggregate stats request, independent of protocol. */
339 struct ofputil_flow_stats_request {
340 bool aggregate; /* Aggregate results? */
343 ovs_be64 cookie_mask;
349 enum ofperr ofputil_decode_flow_stats_request(
350 struct ofputil_flow_stats_request *, const struct ofp_header *);
351 struct ofpbuf *ofputil_encode_flow_stats_request(
352 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
354 /* Flow stats reply, independent of protocol. */
355 struct ofputil_flow_stats {
360 uint16_t idle_timeout;
361 uint16_t hard_timeout;
362 uint32_t duration_sec;
363 uint32_t duration_nsec;
364 int idle_age; /* Seconds since last packet, -1 if unknown. */
365 int hard_age; /* Seconds since last change, -1 if unknown. */
366 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
367 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
368 const struct ofpact *ofpacts;
370 enum ofputil_flow_mod_flags flags;
371 uint16_t importance; /* Eviction precedence. */
374 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
376 bool flow_age_extension,
377 struct ofpbuf *ofpacts);
378 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
379 struct ovs_list *replies);
381 /* Aggregate stats reply, independent of protocol. */
382 struct ofputil_aggregate_stats {
383 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
384 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
388 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
389 const struct ofputil_aggregate_stats *stats,
390 const struct ofp_header *request);
391 enum ofperr ofputil_decode_aggregate_stats_reply(
392 struct ofputil_aggregate_stats *,
393 const struct ofp_header *reply);
395 /* Flow removed message, independent of protocol. */
396 struct ofputil_flow_removed {
400 uint8_t reason; /* One of OFPRR_*. */
401 uint8_t table_id; /* 255 if message didn't include table ID. */
402 uint32_t duration_sec;
403 uint32_t duration_nsec;
404 uint16_t idle_timeout;
405 uint16_t hard_timeout;
406 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
407 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
410 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
411 const struct ofp_header *);
412 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
413 enum ofputil_protocol);
415 /* Abstract packet-in message.
417 * This omits the 'total_len' and 'buffer_id' fields, which we handle
418 * differently for encoding and decoding.*/
419 struct ofputil_packet_in {
420 /* Packet data and metadata.
422 * On encoding, the full packet should be supplied, but depending on its
423 * other parameters ofputil_encode_packet_in() might send only the first
424 * part of the packet.
426 * On decoding, the 'len' bytes in 'packet' might only be the first part of
427 * the original packet. ofputil_decode_packet_in() reports the full
428 * original length of the packet using its 'total_len' output parameter. */
429 const void *packet; /* The packet. */
430 size_t len; /* Length of 'packet' in bytes. */
432 /* Input port and other metadata for packet. */
433 struct match flow_metadata;
435 /* Reason that the packet-in is being sent. */
436 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
438 /* Information about the OpenFlow flow that triggered the packet-in.
440 * A packet-in triggered by a flow table miss has no associated flow. In
441 * that case, 'cookie' is UINT64_MAX. */
442 uint8_t table_id; /* OpenFlow table ID. */
443 ovs_be64 cookie; /* Flow's cookie. */
446 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
447 enum ofputil_protocol protocol,
448 enum nx_packet_in_format,
449 uint16_t max_len, struct pktbuf *);
451 enum ofperr ofputil_decode_packet_in(const struct ofp_header *,
452 struct ofputil_packet_in *,
453 size_t *total_len, uint32_t *buffer_id);
455 enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
456 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
459 bool ofputil_packet_in_reason_from_string(const char *,
460 enum ofp_packet_in_reason *);
462 /* Abstract packet-out message.
464 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
465 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
466 struct ofputil_packet_out {
467 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
468 size_t packet_len; /* Length of packet data in bytes. */
469 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
470 ofp_port_t in_port; /* Packet's input port. */
471 struct ofpact *ofpacts; /* Actions. */
472 size_t ofpacts_len; /* Size of ofpacts in bytes. */
475 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
476 const struct ofp_header *,
477 struct ofpbuf *ofpacts);
478 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
479 enum ofputil_protocol protocol);
481 enum ofputil_frag_handling {
482 OFPUTIL_FRAG_NORMAL = OFPC_FRAG_NORMAL, /* No special handling. */
483 OFPUTIL_FRAG_DROP = OFPC_FRAG_DROP, /* Drop fragments. */
484 OFPUTIL_FRAG_REASM = OFPC_FRAG_REASM, /* Reassemble (if supported). */
485 OFPUTIL_FRAG_NX_MATCH = OFPC_FRAG_NX_MATCH /* Match on frag bits. */
488 const char *ofputil_frag_handling_to_string(enum ofputil_frag_handling);
489 bool ofputil_frag_handling_from_string(const char *,
490 enum ofputil_frag_handling *);
492 /* Abstract struct ofp_switch_config. */
493 struct ofputil_switch_config {
494 /* Fragment handling. */
495 enum ofputil_frag_handling frag;
497 /* 0: Do not send packet to controller when decrementing invalid IP TTL.
498 * 1: Do send packet to controller when decrementing invalid IP TTL.
499 * -1: Unspecified (only OpenFlow 1.1 and 1.2 support this setting. */
500 int invalid_ttl_to_controller;
502 /* Maximum bytes of packet to send to controller on miss. */
503 uint16_t miss_send_len;
506 void ofputil_decode_get_config_reply(const struct ofp_header *,
507 struct ofputil_switch_config *);
508 struct ofpbuf *ofputil_encode_get_config_reply(
509 const struct ofp_header *request, const struct ofputil_switch_config *);
511 enum ofperr ofputil_decode_set_config(const struct ofp_header *,
512 struct ofputil_switch_config *);
513 struct ofpbuf *ofputil_encode_set_config(
514 const struct ofputil_switch_config *, enum ofp_version);
516 enum ofputil_port_config {
517 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
518 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
519 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
520 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
521 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
522 /* OpenFlow 1.0 only. */
523 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
524 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
525 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
526 /* There are no OpenFlow 1.1-only bits. */
529 enum ofputil_port_state {
530 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
531 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
532 /* OpenFlow 1.1 only. */
533 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
534 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
535 /* OpenFlow 1.0 only. */
536 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
537 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
538 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
539 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
540 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
543 /* Abstract ofp10_phy_port or ofp11_port. */
544 struct ofputil_phy_port {
546 struct eth_addr hw_addr;
547 char name[OFP_MAX_PORT_NAME_LEN];
548 enum ofputil_port_config config;
549 enum ofputil_port_state state;
551 /* NETDEV_F_* feature bitmasks. */
552 enum netdev_features curr; /* Current features. */
553 enum netdev_features advertised; /* Features advertised by the port. */
554 enum netdev_features supported; /* Features supported by the port. */
555 enum netdev_features peer; /* Features advertised by peer. */
558 uint32_t curr_speed; /* Current speed, in kbps. */
559 uint32_t max_speed; /* Maximum supported speed, in kbps. */
562 enum ofputil_capabilities {
563 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
564 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
565 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
566 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
567 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
568 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
570 /* OpenFlow 1.0 and 1.1 share this capability. */
571 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
573 /* OpenFlow 1.0 only. */
574 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
576 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
577 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
579 /* OpenFlow 1.2 and 1.3 share this capability */
580 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
583 /* Abstract ofp_switch_features. */
584 struct ofputil_switch_features {
585 uint64_t datapath_id; /* Datapath unique ID. */
586 uint32_t n_buffers; /* Max packets buffered at once. */
587 uint8_t n_tables; /* Number of tables supported by datapath. */
588 uint8_t auxiliary_id; /* Identify auxiliary connections */
589 enum ofputil_capabilities capabilities;
590 uint64_t ofpacts; /* Bitmap of OFPACT_* bits. */
593 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
594 struct ofputil_switch_features *,
597 struct ofpbuf *ofputil_encode_switch_features(
598 const struct ofputil_switch_features *, enum ofputil_protocol,
600 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
602 bool ofputil_switch_features_has_ports(struct ofpbuf *b);
604 /* phy_port helper functions. */
605 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
606 struct ofputil_phy_port *);
608 /* Abstract ofp_port_status. */
609 struct ofputil_port_status {
610 enum ofp_port_reason reason;
611 struct ofputil_phy_port desc;
614 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
615 struct ofputil_port_status *);
616 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
617 enum ofputil_protocol);
619 /* Abstract ofp_port_mod. */
620 struct ofputil_port_mod {
622 struct eth_addr hw_addr;
623 enum ofputil_port_config config;
624 enum ofputil_port_config mask;
625 enum netdev_features advertise;
628 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
629 struct ofputil_port_mod *, bool loose);
630 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
631 enum ofputil_protocol);
633 /* Abstract version of OFPTC11_TABLE_MISS_*.
635 * OpenFlow 1.0 always sends packets that miss to the next flow table, or to
636 * the controller if they miss in the last flow table.
638 * OpenFlow 1.1 and 1.2 can configure table miss behavior via a "table-mod"
639 * that specifies "send to controller", "miss", or "drop".
641 * OpenFlow 1.3 and later never sends packets that miss to the controller.
643 enum ofputil_table_miss {
644 /* Protocol-specific default behavior. On OpenFlow 1.0 through 1.2
645 * connections, the packet is sent to the controller, and on OpenFlow 1.3
646 * and later connections, the packet is dropped.
648 * This is also used as a result of decoding OpenFlow 1.3+ "config" values
649 * in table-mods, to indicate that no table-miss was specified. */
650 OFPUTIL_TABLE_MISS_DEFAULT, /* Protocol default behavior. */
652 /* These constants have the same meanings as those in OpenFlow with the
654 OFPUTIL_TABLE_MISS_CONTROLLER, /* Send to controller. */
655 OFPUTIL_TABLE_MISS_CONTINUE, /* Go to next table. */
656 OFPUTIL_TABLE_MISS_DROP, /* Drop the packet. */
659 /* Abstract version of OFPTC14_EVICTION.
661 * OpenFlow 1.0 through 1.3 don't know anything about eviction, so decoding a
662 * message for one of these protocols always yields
663 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
664 enum ofputil_table_eviction {
665 OFPUTIL_TABLE_EVICTION_DEFAULT, /* No value. */
666 OFPUTIL_TABLE_EVICTION_ON, /* Enable eviction. */
667 OFPUTIL_TABLE_EVICTION_OFF /* Disable eviction. */
670 /* Abstract version of OFPTC14_VACANCY_EVENTS.
672 * OpenFlow 1.0 through 1.3 don't know anything about vacancy events, so
673 * decoding a message for one of these protocols always yields
674 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
675 enum ofputil_table_vacancy {
676 OFPUTIL_TABLE_VACANCY_DEFAULT, /* No value. */
677 OFPUTIL_TABLE_VACANCY_ON, /* Enable vacancy events. */
678 OFPUTIL_TABLE_VACANCY_OFF /* Disable vacancy events. */
681 /* Abstract version of OFPTMPT_VACANCY.
683 * Openflow 1.4+ defines vacancy events.
684 * The fields vacancy_down and vacancy_up are the threshold for generating
685 * vacancy events that should be configured on the flow table, expressed as
687 * The vacancy field is only used when this property in included in a
688 * OFPMP_TABLE_DESC multipart reply or a OFPT_TABLE_STATUS message and
689 * represent the current vacancy of the table, expressed as a percent. In
690 * OFP_TABLE_MOD requests, this field must be set to 0 */
691 struct ofputil_table_mod_prop_vacancy {
692 uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */
693 uint8_t vacancy_up; /* Vacancy threshold when space increases (%). */
694 uint8_t vacancy; /* Current vacancy (%). */
697 /* Abstract ofp_table_mod. */
698 struct ofputil_table_mod {
699 uint8_t table_id; /* ID of the table, 0xff indicates all tables. */
701 /* OpenFlow 1.1 and 1.2 only. For other versions, ignored on encoding,
702 * decoded to OFPUTIL_TABLE_MISS_DEFAULT. */
703 enum ofputil_table_miss miss;
705 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
706 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
707 enum ofputil_table_eviction eviction;
709 /* OpenFlow 1.4+ only and optional even there; UINT32_MAX indicates
710 * absence. For other versions, ignored on encoding, decoded to
712 uint32_t eviction_flags; /* OFPTMPEF14_*. */
714 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
715 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
716 enum ofputil_table_vacancy vacancy;
718 /* Openflow 1.4+ only. Defines threshold values of vacancy expressed as
719 * percent, value of current vacancy is set to zero for table-mod.
720 * For other versions, ignored on encoding, all values decoded to
722 struct ofputil_table_mod_prop_vacancy table_vacancy;
725 /* Abstract ofp14_table_desc. */
726 struct ofputil_table_desc {
727 uint8_t table_id; /* ID of the table. */
728 enum ofputil_table_eviction eviction;
729 uint32_t eviction_flags; /* UINT32_MAX if not present. */
730 enum ofputil_table_vacancy vacancy;
731 struct ofputil_table_mod_prop_vacancy table_vacancy;
734 enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
735 struct ofputil_table_mod *);
736 struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
737 enum ofputil_protocol);
739 /* Abstract ofp_table_features.
741 * This is used for all versions of OpenFlow, even though ofp_table_features
742 * was only introduced in OpenFlow 1.3, because earlier versions of OpenFlow
743 * include support for a subset of ofp_table_features through OFPST_TABLE (aka
745 struct ofputil_table_features {
746 uint8_t table_id; /* Identifier of table. Lower numbered tables
747 are consulted first. */
748 char name[OFP_MAX_TABLE_NAME_LEN];
749 ovs_be64 metadata_match; /* Bits of metadata table can match. */
750 ovs_be64 metadata_write; /* Bits of metadata table can write. */
751 uint32_t max_entries; /* Max number of entries supported. */
755 * 'miss_config' is relevant for OpenFlow 1.1 and 1.2 only, because those
756 * versions include OFPTC_MISS_* flags in OFPST_TABLE. For other versions,
757 * it is decoded to OFPUTIL_TABLE_MISS_DEFAULT and ignored for encoding.
759 * 'supports_eviction' and 'supports_vacancy_events' are relevant only for
760 * OpenFlow 1.4 and later only. For OF1.4, they are boolean: 1 if
761 * supported, otherwise 0. For other versions, they are decoded as -1 and
762 * ignored for encoding.
764 * See the section "OFPTC_* Table Configuration" in DESIGN.md for more
765 * details of how OpenFlow has changed in this area.
767 enum ofputil_table_miss miss_config; /* OF1.1 and 1.2 only. */
768 int supports_eviction; /* OF1.4+ only. */
769 int supports_vacancy_events; /* OF1.4+ only. */
771 /* Table features related to instructions. There are two instances:
773 * - 'miss' reports features available in the table miss flow.
775 * - 'nonmiss' reports features available in other flows. */
776 struct ofputil_table_instruction_features {
777 /* Tables that "goto-table" may jump to. */
778 unsigned long int next[BITMAP_N_LONGS(255)];
780 /* Bitmap of OVSINST_* for supported instructions. */
781 uint32_t instructions;
783 /* Table features related to actions. There are two instances:
785 * - 'write' reports features available in a "write_actions"
788 * - 'apply' reports features available in an "apply_actions"
790 struct ofputil_table_action_features {
791 uint64_t ofpacts; /* Bitmap of supported OFPACT_*. */
792 struct mf_bitmap set_fields; /* Fields for "set-field". */
798 * For any given field the following combinations are valid:
800 * - match=0, wildcard=0, mask=0: Flows in this table cannot match on
803 * - match=1, wildcard=0, mask=0: Flows in this table must match on all
804 * the bits in this field.
806 * - match=1, wildcard=1, mask=0: Flows in this table must either match
807 * on all the bits in the field or wildcard the field entirely.
809 * - match=1, wildcard=1, mask=1: Flows in this table may arbitrarily
810 * mask this field (as special cases, they may match on all the bits
811 * or wildcard it entirely).
813 * Other combinations do not make sense.
815 struct mf_bitmap match; /* Fields that may be matched. */
816 struct mf_bitmap mask; /* Subset of 'match' that may have masks. */
817 struct mf_bitmap wildcard; /* Subset of 'match' that may be wildcarded. */
820 int ofputil_decode_table_features(struct ofpbuf *,
821 struct ofputil_table_features *, bool loose);
823 int ofputil_decode_table_desc(struct ofpbuf *,
824 struct ofputil_table_desc *,
827 struct ofpbuf *ofputil_encode_table_features_request(enum ofp_version);
829 struct ofpbuf *ofputil_encode_table_desc_request(enum ofp_version);
831 void ofputil_append_table_features_reply(
832 const struct ofputil_table_features *tf, struct ovs_list *replies);
834 void ofputil_append_table_desc_reply(const struct ofputil_table_desc *td,
835 struct ovs_list *replies,
838 /* Meter band configuration for all supported band types. */
839 struct ofputil_meter_band {
841 uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */
846 struct ofputil_meter_band_stats {
847 uint64_t packet_count;
851 struct ofputil_meter_config {
855 struct ofputil_meter_band *bands;
858 /* Abstract ofp_meter_mod. */
859 struct ofputil_meter_mod {
861 struct ofputil_meter_config meter;
864 struct ofputil_meter_stats {
867 uint64_t packet_in_count;
868 uint64_t byte_in_count;
869 uint32_t duration_sec;
870 uint32_t duration_nsec;
872 struct ofputil_meter_band_stats *bands;
875 struct ofputil_meter_features {
876 uint32_t max_meters; /* Maximum number of meters. */
877 uint32_t band_types; /* Can support max 32 band types. */
878 uint32_t capabilities; /* Supported flags. */
883 enum ofperr ofputil_decode_meter_mod(const struct ofp_header *,
884 struct ofputil_meter_mod *,
885 struct ofpbuf *bands);
886 struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version,
887 const struct ofputil_meter_mod *);
889 void ofputil_decode_meter_features(const struct ofp_header *,
890 struct ofputil_meter_features *);
891 struct ofpbuf *ofputil_encode_meter_features_reply(const struct
892 ofputil_meter_features *,
893 const struct ofp_header *
895 void ofputil_decode_meter_request(const struct ofp_header *,
898 void ofputil_append_meter_config(struct ovs_list *replies,
899 const struct ofputil_meter_config *);
901 void ofputil_append_meter_stats(struct ovs_list *replies,
902 const struct ofputil_meter_stats *);
904 enum ofputil_meter_request_type {
905 OFPUTIL_METER_FEATURES,
906 OFPUTIL_METER_CONFIG,
910 struct ofpbuf *ofputil_encode_meter_request(enum ofp_version,
911 enum ofputil_meter_request_type,
914 int ofputil_decode_meter_stats(struct ofpbuf *,
915 struct ofputil_meter_stats *,
916 struct ofpbuf *bands);
918 int ofputil_decode_meter_config(struct ofpbuf *,
919 struct ofputil_meter_config *,
920 struct ofpbuf *bands);
922 /* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
923 typedef struct { uint32_t uint32; } ofproto_meter_id;
925 /* Abstract ofp_role_request and reply. */
926 struct ofputil_role_request {
927 enum ofp12_controller_role role;
928 bool have_generation_id;
929 uint64_t generation_id;
932 struct ofputil_role_status {
933 enum ofp12_controller_role role;
934 enum ofp14_controller_role_reason reason;
935 uint64_t generation_id;
938 enum ofperr ofputil_decode_role_message(const struct ofp_header *,
939 struct ofputil_role_request *);
940 struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
941 const struct ofputil_role_request *);
943 struct ofpbuf *ofputil_encode_role_status(
944 const struct ofputil_role_status *status,
945 enum ofputil_protocol protocol);
947 enum ofperr ofputil_decode_role_status(const struct ofp_header *oh,
948 struct ofputil_role_status *rs);
950 /* Abstract table stats.
952 * This corresponds to the OpenFlow 1.3 table statistics structure, which only
953 * includes actual statistics. In earlier versions of OpenFlow, several
954 * members describe table features, so this structure has to be paired with
955 * struct ofputil_table_features to get all information. */
956 struct ofputil_table_stats {
957 uint8_t table_id; /* Identifier of table. */
958 uint32_t active_count; /* Number of active entries. */
959 uint64_t lookup_count; /* Number of packets looked up in table. */
960 uint64_t matched_count; /* Number of packets that hit table. */
963 struct ofpbuf *ofputil_encode_table_stats_reply(const struct ofp_header *rq);
965 struct ofpbuf *ofputil_encode_table_desc_reply(const struct ofp_header *rq);
967 void ofputil_append_table_stats_reply(struct ofpbuf *reply,
968 const struct ofputil_table_stats *,
969 const struct ofputil_table_features *);
971 int ofputil_decode_table_stats_reply(struct ofpbuf *reply,
972 struct ofputil_table_stats *,
973 struct ofputil_table_features *);
975 /* Queue configuration request. */
976 struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version,
979 enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *,
983 /* Queue configuration reply. */
984 struct ofputil_queue_config {
988 /* Each of these optional values is expressed in tenths of a percent.
989 * Values greater than 1000 indicate that the feature is disabled.
990 * UINT16_MAX indicates that the value is omitted. */
995 void ofputil_start_queue_get_config_reply(const struct ofp_header *request,
996 struct ovs_list *replies);
997 void ofputil_append_queue_get_config_reply(
998 const struct ofputil_queue_config *, struct ovs_list *replies);
1000 int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply,
1001 struct ofputil_queue_config *);
1004 /* Abstract nx_flow_monitor_request. */
1005 struct ofputil_flow_monitor_request {
1007 enum nx_flow_monitor_flags flags;
1008 ofp_port_t out_port;
1013 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
1014 struct ofpbuf *msg);
1015 void ofputil_append_flow_monitor_request(
1016 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
1018 /* Abstract nx_flow_update. */
1019 struct ofputil_flow_update {
1020 enum nx_flow_update_event event;
1022 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
1023 enum ofp_flow_removed_reason reason;
1024 uint16_t idle_timeout;
1025 uint16_t hard_timeout;
1029 struct match *match;
1030 const struct ofpact *ofpacts;
1033 /* Used only for NXFME_ABBREV. */
1037 int ofputil_decode_flow_update(struct ofputil_flow_update *,
1038 struct ofpbuf *msg, struct ofpbuf *ofpacts);
1039 void ofputil_start_flow_update(struct ovs_list *replies);
1040 void ofputil_append_flow_update(const struct ofputil_flow_update *,
1041 struct ovs_list *replies);
1043 /* Abstract nx_flow_monitor_cancel. */
1044 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
1045 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
1047 /* Port desc stats requests and replies. */
1048 enum ofperr ofputil_decode_port_desc_stats_request(const struct ofp_header *,
1050 struct ofpbuf *ofputil_encode_port_desc_stats_request(
1051 enum ofp_version ofp_version, ofp_port_t);
1053 void ofputil_append_port_desc_stats_reply(const struct ofputil_phy_port *pp,
1054 struct ovs_list *replies);
1056 /* Encoding simple OpenFlow messages. */
1057 struct ofpbuf *make_echo_request(enum ofp_version);
1058 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
1060 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
1064 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
1066 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
1067 union ofp_action **, size_t *);
1069 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
1070 const union ofp_action *b, size_t n_b);
1071 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
1073 /* Handy utility for parsing flows and actions. */
1074 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
1076 struct ofputil_port_stats {
1078 struct netdev_stats stats;
1079 uint32_t duration_sec; /* UINT32_MAX if unknown. */
1080 uint32_t duration_nsec;
1083 struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
1085 void ofputil_append_port_stat(struct ovs_list *replies,
1086 const struct ofputil_port_stats *ops);
1087 size_t ofputil_count_port_stats(const struct ofp_header *);
1088 int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
1089 enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
1090 ofp_port_t *ofp10_port);
1092 struct ofputil_queue_stats_request {
1093 ofp_port_t port_no; /* OFPP_ANY means "all ports". */
1098 ofputil_decode_queue_stats_request(const struct ofp_header *request,
1099 struct ofputil_queue_stats_request *oqsr);
1101 ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
1102 const struct ofputil_queue_stats_request *oqsr);
1104 struct ofputil_queue_stats {
1108 /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
1110 uint64_t tx_packets;
1113 /* UINT32_MAX if unknown. */
1114 uint32_t duration_sec;
1115 uint32_t duration_nsec;
1118 size_t ofputil_count_queue_stats(const struct ofp_header *);
1119 int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
1120 void ofputil_append_queue_stat(struct ovs_list *replies,
1121 const struct ofputil_queue_stats *oqs);
1123 struct bucket_counter {
1124 uint64_t packet_count; /* Number of packets processed by bucket. */
1125 uint64_t byte_count; /* Number of bytes processed by bucket. */
1128 /* Bucket for use in groups. */
1129 struct ofputil_bucket {
1130 struct ovs_list list_node;
1131 uint16_t weight; /* Relative weight, for "select" groups. */
1132 ofp_port_t watch_port; /* Port whose state affects whether this bucket
1133 * is live. Only required for fast failover
1135 uint32_t watch_group; /* Group whose state affects whether this
1136 * bucket is live. Only required for fast
1137 * failover groups. */
1138 uint32_t bucket_id; /* Bucket Id used to identify bucket*/
1139 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
1140 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
1142 struct bucket_counter stats;
1145 /* Protocol-independent group_mod. */
1146 struct ofputil_group_props {
1147 /* NTR selection method */
1148 char selection_method[NTR_MAX_SELECTION_METHOD_LEN];
1149 uint64_t selection_method_param;
1150 struct field_array fields;
1153 /* Protocol-independent group_mod. */
1154 struct ofputil_group_mod {
1155 uint16_t command; /* One of OFPGC15_*. */
1156 uint8_t type; /* One of OFPGT11_*. */
1157 uint32_t group_id; /* Group identifier. */
1158 uint32_t command_bucket_id; /* Bucket Id used as part of
1159 * OFPGC15_INSERT_BUCKET and
1160 * OFPGC15_REMOVE_BUCKET commands
1162 struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */
1163 struct ofputil_group_props props; /* Group properties. */
1166 /* Group stats reply, independent of protocol. */
1167 struct ofputil_group_stats {
1168 uint32_t group_id; /* Group identifier. */
1170 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
1171 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
1172 uint32_t duration_sec; /* UINT32_MAX if unknown. */
1173 uint32_t duration_nsec;
1175 struct bucket_counter *bucket_stats;
1178 /* Group features reply, independent of protocol.
1180 * Only OF1.2 and later support group features replies. */
1181 struct ofputil_group_features {
1182 uint32_t types; /* Bitmap of OFPGT_* values supported. */
1183 uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */
1184 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
1185 uint64_t ofpacts[4]; /* Bitmaps of supported OFPACT_* */
1188 /* Group desc reply, independent of protocol. */
1189 struct ofputil_group_desc {
1190 uint8_t type; /* One of OFPGT_*. */
1191 uint32_t group_id; /* Group identifier. */
1192 struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */
1193 struct ofputil_group_props props; /* Group properties. */
1196 void ofputil_bucket_list_destroy(struct ovs_list *buckets);
1197 void ofputil_bucket_clone_list(struct ovs_list *dest,
1198 const struct ovs_list *src,
1199 const struct ofputil_bucket *);
1200 struct ofputil_bucket *ofputil_bucket_find(const struct ovs_list *,
1201 uint32_t bucket_id);
1202 bool ofputil_bucket_check_duplicate_id(const struct ovs_list *);
1203 struct ofputil_bucket *ofputil_bucket_list_front(const struct ovs_list *);
1204 struct ofputil_bucket *ofputil_bucket_list_back(const struct ovs_list *);
1207 ofputil_bucket_has_liveness(const struct ofputil_bucket *bucket)
1209 return (bucket->watch_port != OFPP_ANY ||
1210 bucket->watch_group != OFPG_ANY);
1213 struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version,
1215 enum ofperr ofputil_decode_group_stats_request(
1216 const struct ofp_header *request, uint32_t *group_id);
1217 void ofputil_append_group_stats(struct ovs_list *replies,
1218 const struct ofputil_group_stats *);
1219 struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version);
1220 struct ofpbuf *ofputil_encode_group_features_reply(
1221 const struct ofputil_group_features *, const struct ofp_header *request);
1222 void ofputil_decode_group_features_reply(const struct ofp_header *,
1223 struct ofputil_group_features *);
1224 void ofputil_uninit_group_mod(struct ofputil_group_mod *gm);
1225 struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version,
1226 const struct ofputil_group_mod *gm);
1228 enum ofperr ofputil_decode_group_mod(const struct ofp_header *,
1229 struct ofputil_group_mod *);
1231 int ofputil_decode_group_stats_reply(struct ofpbuf *,
1232 struct ofputil_group_stats *);
1234 void ofputil_uninit_group_desc(struct ofputil_group_desc *gd);
1235 uint32_t ofputil_decode_group_desc_request(const struct ofp_header *);
1236 struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version,
1239 int ofputil_decode_group_desc_reply(struct ofputil_group_desc *,
1240 struct ofpbuf *, enum ofp_version);
1242 void ofputil_append_group_desc_reply(const struct ofputil_group_desc *,
1243 const struct ovs_list *buckets,
1244 struct ovs_list *replies);
1246 struct ofputil_bundle_ctrl_msg {
1252 struct ofputil_bundle_add_msg {
1255 const struct ofp_header *msg;
1260 enum ofperr ofputil_decode_bundle_ctrl(const struct ofp_header *,
1261 struct ofputil_bundle_ctrl_msg *);
1263 struct ofpbuf *ofputil_encode_bundle_ctrl_request(enum ofp_version,
1264 struct ofputil_bundle_ctrl_msg *);
1265 struct ofpbuf *ofputil_encode_bundle_ctrl_reply(const struct ofp_header *,
1266 struct ofputil_bundle_ctrl_msg *);
1268 struct ofpbuf *ofputil_encode_bundle_add(enum ofp_version ofp_version,
1269 struct ofputil_bundle_add_msg *msg);
1271 enum ofperr ofputil_decode_bundle_add(const struct ofp_header *,
1272 struct ofputil_bundle_add_msg *,
1273 enum ofptype *type);
1275 struct ofputil_tlv_map {
1276 struct ovs_list list_node;
1278 uint16_t option_class;
1279 uint8_t option_type;
1284 struct ofputil_tlv_table_mod {
1286 struct ovs_list mappings; /* Contains "struct ofputil_tlv_map"s. */
1289 struct ofputil_tlv_table_reply {
1290 uint32_t max_option_space;
1291 uint16_t max_fields;
1292 struct ovs_list mappings; /* Contains "struct ofputil_tlv_map"s. */
1295 struct ofpbuf *ofputil_encode_tlv_table_mod(enum ofp_version ofp_version,
1296 struct ofputil_tlv_table_mod *);
1297 enum ofperr ofputil_decode_tlv_table_mod(const struct ofp_header *,
1298 struct ofputil_tlv_table_mod *);
1299 struct ofpbuf *ofputil_encode_tlv_table_reply(const struct ofp_header *,
1300 struct ofputil_tlv_table_reply *);
1301 enum ofperr ofputil_decode_tlv_table_reply(const struct ofp_header *,
1302 struct ofputil_tlv_table_reply *);
1303 void ofputil_uninit_tlv_table(struct ovs_list *mappings);
1305 enum ofputil_async_msg_type {
1306 /* Standard asynchronous messages. */
1307 OAM_PACKET_IN, /* OFPT_PACKET_IN or NXT_PACKET_IN. */
1308 OAM_PORT_STATUS, /* OFPT_PORT_STATUS. */
1309 OAM_FLOW_REMOVED, /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */
1310 OAM_ROLE_STATUS, /* OFPT_ROLE_STATUS. */
1311 OAM_TABLE_STATUS, /* OFPT_TABLE_STATUS. */
1312 OAM_REQUESTFORWARD, /* OFPT_REQUESTFORWARD. */
1314 /* Extension asynchronous messages (none yet--coming soon!). */
1315 #define OAM_EXTENSIONS 0 /* Bitmap of all extensions. */
1319 const char *ofputil_async_msg_type_to_string(enum ofputil_async_msg_type);
1321 struct ofputil_async_cfg {
1322 uint32_t master[OAM_N_TYPES];
1323 uint32_t slave[OAM_N_TYPES];
1325 #define OFPUTIL_ASYNC_CFG_INIT (struct ofputil_async_cfg) { .master[0] = 0 }
1327 enum ofperr ofputil_decode_set_async_config(const struct ofp_header *,
1329 const struct ofputil_async_cfg *,
1330 struct ofputil_async_cfg *);
1332 struct ofpbuf *ofputil_encode_get_async_reply(
1333 const struct ofp_header *, const struct ofputil_async_cfg *);
1334 struct ofpbuf *ofputil_encode_set_async_config(
1335 const struct ofputil_async_cfg *, uint32_t oams, enum ofp_version);
1337 struct ofputil_async_cfg ofputil_async_cfg_default(enum ofp_version);
1339 struct ofputil_requestforward {
1341 enum ofp14_requestforward_reason reason;
1343 /* reason == OFPRFR_METER_MOD. */
1345 struct ofputil_meter_mod *meter_mod;
1346 struct ofpbuf bands;
1349 /* reason == OFPRFR_GROUP_MOD. */
1350 struct ofputil_group_mod *group_mod;
1354 struct ofpbuf *ofputil_encode_requestforward(
1355 const struct ofputil_requestforward *, enum ofputil_protocol);
1356 enum ofperr ofputil_decode_requestforward(const struct ofp_header *,
1357 struct ofputil_requestforward *);
1358 void ofputil_destroy_requestforward(struct ofputil_requestforward *);
1360 #endif /* ofp-util.h */