2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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 "openflow/nicira-ext.h"
29 #include "openvswitch/types.h"
30 #include "type-props.h"
34 struct ofpact_set_field;
37 enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
38 ofp_port_t *ofp10_port);
39 ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);
41 bool ofputil_port_from_string(const char *, ofp_port_t *portp);
42 void ofputil_format_port(ofp_port_t port, struct ds *);
43 void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
47 enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) };
48 bool ofputil_group_from_string(const char *, uint32_t *group_id);
49 void ofputil_format_group(uint32_t group_id, struct ds *);
50 void ofputil_group_to_string(uint32_t group_id,
51 char namebuf[MAX_GROUP_NAME_LEN + 1],
54 /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
55 * to and from IP bitmasks. */
56 ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
57 int ofputil_netmask_to_wcbits(ovs_be32 netmask);
61 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
62 * a bit extra about the flow match format in use.
64 * These are arranged from most portable to least portable, or alternatively
65 * from least powerful to most powerful. Protocols earlier on the list are
66 * more likely to be understood for the purpose of making requests, but
67 * protocol later on the list are more likely to accurately describe a flow
70 * On any given OpenFlow connection, a single protocol is in effect at any
71 * given time. These values use separate bits only because that makes it easy
72 * to test whether a particular protocol is within a given set of protocols and
73 * to implement set union and intersection.
75 enum ofputil_protocol {
76 /* OpenFlow 1.0 protocols.
78 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
79 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
81 * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
82 * extension has been enabled. The other protocols have it disabled.
84 #define OFPUTIL_P_NONE 0
85 OFPUTIL_P_OF10_STD = 1 << 0,
86 OFPUTIL_P_OF10_STD_TID = 1 << 1,
87 OFPUTIL_P_OF10_NXM = 1 << 2,
88 OFPUTIL_P_OF10_NXM_TID = 1 << 3,
89 #define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
90 #define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
91 #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY)
93 /* OpenFlow 1.1 protocol.
95 * We only support the standard OpenFlow 1.1 flow format.
97 * OpenFlow 1.1 always operates with an equivalent of the
98 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
100 OFPUTIL_P_OF11_STD = 1 << 4,
102 /* OpenFlow 1.2+ protocols (only one variant each).
104 * These use the standard OpenFlow Extensible Match (OXM) flow format.
106 * OpenFlow 1.2+ always operates with an equivalent of the
107 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
109 OFPUTIL_P_OF12_OXM = 1 << 5,
110 OFPUTIL_P_OF13_OXM = 1 << 6,
111 #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM)
113 #define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
116 #define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
118 #define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
120 #define OFPUTIL_P_OF12_UP (OFPUTIL_P_ANY_OXM)
122 #define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM)
125 #define OFPUTIL_P_ANY ((1 << 7) - 1)
127 /* Protocols in which a specific table may be specified in flow_mods. */
128 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
129 OFPUTIL_P_OF10_NXM_TID | \
130 OFPUTIL_P_OF11_STD | \
134 /* Protocols to use for flow dumps, from most to least preferred. */
135 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
136 extern size_t ofputil_n_flow_dump_protocols;
138 enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
139 enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
140 enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
142 bool ofputil_protocol_is_valid(enum ofputil_protocol);
143 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
145 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
146 enum ofputil_protocol ofputil_protocol_set_base(
147 enum ofputil_protocol cur, enum ofputil_protocol new_base);
149 const char *ofputil_protocol_to_string(enum ofputil_protocol);
150 char *ofputil_protocols_to_string(enum ofputil_protocol);
151 enum ofputil_protocol ofputil_protocols_from_string(const char *);
153 void ofputil_format_version(struct ds *, enum ofp_version);
154 void ofputil_format_version_name(struct ds *, enum ofp_version);
156 /* A bitmap of version numbers
158 * Bit offsets correspond to ofp_version numbers which in turn correspond to
159 * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION)
160 * is the mask for Open Flow 1.1. If the bit for a version is set then it is
161 * allowed, otherwise it is disallowed. */
163 void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
164 void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
166 uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
167 enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
169 /* Bitmap of OpenFlow versions that Open vSwitch supports. */
170 #define OFPUTIL_SUPPORTED_VERSIONS \
171 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
173 /* Bitmap of OpenFlow versions to enable by default (a subset of
174 * OFPUTIL_SUPPORTED_VERSIONS). */
175 #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
177 enum ofputil_protocol ofputil_protocols_from_string(const char *s);
179 const char *ofputil_version_to_string(enum ofp_version ofp_version);
180 uint32_t ofputil_versions_from_string(const char *s);
181 uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
183 bool ofputil_decode_hello(const struct ofp_header *,
184 uint32_t *allowed_versions);
185 struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
187 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
188 enum ofputil_protocol want,
189 enum ofputil_protocol *next);
192 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
193 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
194 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
195 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
197 /* Work with ofp10_match. */
198 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
199 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
201 void ofputil_normalize_match(struct match *);
202 void ofputil_normalize_match_quiet(struct match *);
203 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
205 /* Work with ofp11_match. */
206 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
207 uint16_t *padded_match_len);
208 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
210 int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *,
211 enum ofputil_protocol);
212 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
213 int ofputil_match_typical_len(enum ofputil_protocol);
215 /* dl_type translation between OpenFlow and 'struct flow' format. */
216 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
217 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
220 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
221 int ofputil_packet_in_format_from_string(const char *);
222 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
223 struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
224 enum nx_packet_in_format);
226 /* NXT_FLOW_MOD_TABLE_ID extension. */
227 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
229 /* Protocol-independent flow_mod flags. */
230 enum ofputil_flow_mod_flags {
231 /* Flags that are maintained with a flow as part of its state.
233 * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */
234 OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */
235 OFPUTIL_FF_NO_PKT_COUNTS = 1 << 1, /* OpenFlow 1.3+. */
236 OFPUTIL_FF_NO_BYT_COUNTS = 1 << 2, /* OpenFlow 1.3+. */
237 #define OFPUTIL_FF_STATE (OFPUTIL_FF_SEND_FLOW_REM \
238 | OFPUTIL_FF_NO_PKT_COUNTS \
239 | OFPUTIL_FF_NO_BYT_COUNTS)
241 /* Flags that affect flow_mod behavior but are not part of flow state. */
242 OFPUTIL_FF_CHECK_OVERLAP = 1 << 3, /* All versions. */
243 OFPUTIL_FF_EMERG = 1 << 4, /* OpenFlow 1.0 only. */
244 OFPUTIL_FF_RESET_COUNTS = 1 << 5, /* OpenFlow 1.2+. */
247 /* Protocol-independent flow_mod.
249 * The handling of cookies across multiple versions of OpenFlow is a bit
250 * confusing. See DESIGN for the details. */
251 struct ofputil_flow_mod {
252 struct list list_node; /* For queuing flow_mods. */
255 unsigned int priority;
257 /* Cookie matching. The flow_mod affects only flows that have cookies that
258 * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits.
260 * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
261 ovs_be64 cookie; /* Cookie bits to match. */
262 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
266 * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie'
267 * should not be UINT64_MAX.
269 * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
271 * - If one or more matching flows exist and 'modify_cookie' is true,
272 * then the flow_mod changes the existing flows' cookies to
273 * 'new_cookie'. 'new_cookie' should not be UINT64_MAX.
275 * - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and
276 * 'cookie_mask' is 0, then the flow_mod adds a new flow with
277 * 'new_cookie' as its cookie.
279 ovs_be64 new_cookie; /* New cookie to install or UINT64_MAX. */
280 bool modify_cookie; /* Set cookie of existing flow to 'new_cookie'? */
284 uint16_t idle_timeout;
285 uint16_t hard_timeout;
289 enum ofputil_flow_mod_flags flags;
290 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
291 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
294 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
295 const struct ofp_header *,
296 enum ofputil_protocol,
297 struct ofpbuf *ofpacts,
300 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
301 enum ofputil_protocol);
303 /* Flow stats or aggregate stats request, independent of protocol. */
304 struct ofputil_flow_stats_request {
305 bool aggregate; /* Aggregate results? */
308 ovs_be64 cookie_mask;
314 enum ofperr ofputil_decode_flow_stats_request(
315 struct ofputil_flow_stats_request *, const struct ofp_header *);
316 struct ofpbuf *ofputil_encode_flow_stats_request(
317 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
319 /* Flow stats reply, independent of protocol. */
320 struct ofputil_flow_stats {
325 uint16_t idle_timeout;
326 uint16_t hard_timeout;
327 uint32_t duration_sec;
328 uint32_t duration_nsec;
329 int idle_age; /* Seconds since last packet, -1 if unknown. */
330 int hard_age; /* Seconds since last change, -1 if unknown. */
331 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
332 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
333 struct ofpact *ofpacts;
335 enum ofputil_flow_mod_flags flags;
338 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
340 bool flow_age_extension,
341 struct ofpbuf *ofpacts);
342 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
343 struct list *replies);
345 /* Aggregate stats reply, independent of protocol. */
346 struct ofputil_aggregate_stats {
347 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
348 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
352 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
353 const struct ofputil_aggregate_stats *stats,
354 const struct ofp_header *request);
355 enum ofperr ofputil_decode_aggregate_stats_reply(
356 struct ofputil_aggregate_stats *,
357 const struct ofp_header *reply);
359 /* Flow removed message, independent of protocol. */
360 struct ofputil_flow_removed {
364 uint8_t reason; /* One of OFPRR_*. */
365 uint8_t table_id; /* 255 if message didn't include table ID. */
366 uint32_t duration_sec;
367 uint32_t duration_nsec;
368 uint16_t idle_timeout;
369 uint16_t hard_timeout;
370 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
371 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
374 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
375 const struct ofp_header *);
376 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
377 enum ofputil_protocol);
379 /* Abstract packet-in message. */
380 struct ofputil_packet_in {
381 /* Packet data and metadata.
383 * To save bandwidth, in some cases a switch may send only the first
384 * several bytes of a packet, indicated by 'packet_len < total_len'. When
385 * the full packet is included, 'packet_len == total_len'. */
387 size_t packet_len; /* Number of bytes in 'packet'. */
388 size_t total_len; /* Size of packet, pre-truncation. */
389 struct flow_metadata fmd;
391 /* Identifies a buffer in the switch that contains the full packet, to
392 * allow the controller to reference it later without having to send the
393 * entire packet back to the switch.
395 * UINT32_MAX indicates that the packet is not buffered in the switch. A
396 * switch should only use UINT32_MAX when it sends the entire packet. */
399 /* Reason that the packet-in is being sent. */
400 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
402 /* Information about the OpenFlow flow that triggered the packet-in.
404 * A packet-in triggered by a flow table miss has no associated flow. In
405 * that case, 'cookie' is UINT64_MAX. */
406 uint8_t table_id; /* OpenFlow table ID. */
407 ovs_be64 cookie; /* Flow's cookie. */
410 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
411 const struct ofp_header *);
412 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
413 enum ofputil_protocol protocol,
414 enum nx_packet_in_format);
416 enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
417 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
420 bool ofputil_packet_in_reason_from_string(const char *,
421 enum ofp_packet_in_reason *);
423 /* Abstract packet-out message.
425 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
426 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
427 struct ofputil_packet_out {
428 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
429 size_t packet_len; /* Length of packet data in bytes. */
430 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
431 ofp_port_t in_port; /* Packet's input port. */
432 struct ofpact *ofpacts; /* Actions. */
433 size_t ofpacts_len; /* Size of ofpacts in bytes. */
436 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
437 const struct ofp_header *,
438 struct ofpbuf *ofpacts);
439 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
440 enum ofputil_protocol protocol);
442 enum ofputil_port_config {
443 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
444 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
445 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
446 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
447 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
448 /* OpenFlow 1.0 only. */
449 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
450 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
451 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
452 /* There are no OpenFlow 1.1-only bits. */
455 enum ofputil_port_state {
456 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
457 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
458 /* OpenFlow 1.1 only. */
459 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
460 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
461 /* OpenFlow 1.0 only. */
462 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
463 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
464 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
465 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
466 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
469 /* Abstract ofp10_phy_port or ofp11_port. */
470 struct ofputil_phy_port {
472 uint8_t hw_addr[OFP_ETH_ALEN];
473 char name[OFP_MAX_PORT_NAME_LEN];
474 enum ofputil_port_config config;
475 enum ofputil_port_state state;
477 /* NETDEV_F_* feature bitmasks. */
478 enum netdev_features curr; /* Current features. */
479 enum netdev_features advertised; /* Features advertised by the port. */
480 enum netdev_features supported; /* Features supported by the port. */
481 enum netdev_features peer; /* Features advertised by peer. */
484 uint32_t curr_speed; /* Current speed, in kbps. */
485 uint32_t max_speed; /* Maximum supported speed, in kbps. */
488 enum ofputil_capabilities {
489 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
490 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
491 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
492 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
493 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
494 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
496 /* OpenFlow 1.0 and 1.1 share this capability. */
497 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
499 /* OpenFlow 1.0 only. */
500 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
502 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
503 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
505 /* OpenFlow 1.2 and 1.3 share this capability */
506 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
509 enum ofputil_action_bitmap {
510 OFPUTIL_A_OUTPUT = 1 << 0,
511 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
512 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
513 OFPUTIL_A_STRIP_VLAN = 1 << 3,
514 OFPUTIL_A_SET_DL_SRC = 1 << 4,
515 OFPUTIL_A_SET_DL_DST = 1 << 5,
516 OFPUTIL_A_SET_NW_SRC = 1 << 6,
517 OFPUTIL_A_SET_NW_DST = 1 << 7,
518 OFPUTIL_A_SET_NW_ECN = 1 << 8,
519 OFPUTIL_A_SET_NW_TOS = 1 << 9,
520 OFPUTIL_A_SET_TP_SRC = 1 << 10,
521 OFPUTIL_A_SET_TP_DST = 1 << 11,
522 OFPUTIL_A_ENQUEUE = 1 << 12,
523 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
524 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
525 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
526 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
527 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
528 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
529 OFPUTIL_A_PUSH_VLAN = 1 << 19,
530 OFPUTIL_A_POP_VLAN = 1 << 20,
531 OFPUTIL_A_PUSH_MPLS = 1 << 21,
532 OFPUTIL_A_POP_MPLS = 1 << 22,
533 OFPUTIL_A_SET_QUEUE = 1 << 23,
534 OFPUTIL_A_GROUP = 1 << 24,
535 OFPUTIL_A_SET_NW_TTL = 1 << 25,
536 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
537 OFPUTIL_A_SET_FIELD = 1 << 27,
540 /* Abstract ofp_switch_features. */
541 struct ofputil_switch_features {
542 uint64_t datapath_id; /* Datapath unique ID. */
543 uint32_t n_buffers; /* Max packets buffered at once. */
544 uint8_t n_tables; /* Number of tables supported by datapath. */
545 uint8_t auxiliary_id; /* Identify auxiliary connections */
546 enum ofputil_capabilities capabilities;
547 enum ofputil_action_bitmap actions;
550 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
551 struct ofputil_switch_features *,
554 struct ofpbuf *ofputil_encode_switch_features(
555 const struct ofputil_switch_features *, enum ofputil_protocol,
557 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
559 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
561 /* phy_port helper functions. */
562 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
563 struct ofputil_phy_port *);
564 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
566 /* Abstract ofp_port_status. */
567 struct ofputil_port_status {
568 enum ofp_port_reason reason;
569 struct ofputil_phy_port desc;
572 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
573 struct ofputil_port_status *);
574 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
575 enum ofputil_protocol);
577 /* Abstract ofp_port_mod. */
578 struct ofputil_port_mod {
580 uint8_t hw_addr[OFP_ETH_ALEN];
581 enum ofputil_port_config config;
582 enum ofputil_port_config mask;
583 enum netdev_features advertise;
586 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
587 struct ofputil_port_mod *);
588 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
589 enum ofputil_protocol);
591 /* Abstract ofp_table_mod. */
592 struct ofputil_table_mod {
593 uint8_t table_id; /* ID of the table, 0xff indicates all tables. */
597 enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
598 struct ofputil_table_mod *);
599 struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
600 enum ofputil_protocol);
602 /* Meter band configuration for all supported band types. */
603 struct ofputil_meter_band {
605 uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */
610 struct ofputil_meter_band_stats {
611 uint64_t packet_count;
615 struct ofputil_meter_config {
619 struct ofputil_meter_band *bands;
622 /* Abstract ofp_meter_mod. */
623 struct ofputil_meter_mod {
625 struct ofputil_meter_config meter;
628 struct ofputil_meter_stats {
631 uint64_t packet_in_count;
632 uint64_t byte_in_count;
633 uint32_t duration_sec;
634 uint32_t duration_nsec;
636 struct ofputil_meter_band_stats *bands;
639 struct ofputil_meter_features {
640 uint32_t max_meters; /* Maximum number of meters. */
641 uint32_t band_types; /* Can support max 32 band types. */
642 uint32_t capabilities; /* Supported flags. */
647 enum ofperr ofputil_decode_meter_mod(const struct ofp_header *,
648 struct ofputil_meter_mod *,
649 struct ofpbuf *bands);
650 struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version,
651 const struct ofputil_meter_mod *);
653 void ofputil_decode_meter_features(const struct ofp_header *,
654 struct ofputil_meter_features *);
655 struct ofpbuf *ofputil_encode_meter_features_reply(const struct
656 ofputil_meter_features *,
657 const struct ofp_header *
659 void ofputil_decode_meter_request(const struct ofp_header *,
662 void ofputil_append_meter_config(struct list *replies,
663 const struct ofputil_meter_config *);
665 void ofputil_append_meter_stats(struct list *replies,
666 const struct ofputil_meter_stats *);
668 enum ofputil_meter_request_type {
669 OFPUTIL_METER_FEATURES,
670 OFPUTIL_METER_CONFIG,
674 struct ofpbuf *ofputil_encode_meter_request(enum ofp_version,
675 enum ofputil_meter_request_type,
678 int ofputil_decode_meter_stats(struct ofpbuf *,
679 struct ofputil_meter_stats *,
680 struct ofpbuf *bands);
682 int ofputil_decode_meter_config(struct ofpbuf *,
683 struct ofputil_meter_config *,
684 struct ofpbuf *bands);
686 /* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
687 typedef struct { uint32_t uint32; } ofproto_meter_id;
689 /* Abstract ofp_role_request and reply. */
690 struct ofputil_role_request {
691 enum ofp12_controller_role role;
692 bool have_generation_id;
693 uint64_t generation_id;
696 struct ofputil_role_status {
697 enum ofp12_controller_role role;
698 enum ofp14_controller_role_reason reason;
699 uint64_t generation_id;
702 enum ofperr ofputil_decode_role_message(const struct ofp_header *,
703 struct ofputil_role_request *);
704 struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
705 const struct ofputil_role_request *);
707 struct ofpbuf *ofputil_encode_role_status(
708 const struct ofputil_role_status *status,
709 enum ofputil_protocol protocol);
711 enum ofperr ofputil_decode_role_status(const struct ofp_header *oh,
712 struct ofputil_role_status *rs);
713 /* Abstract table stats.
715 * For now we use ofp12_table_stats as a superset of the other protocol
716 * versions' table stats. */
718 struct ofpbuf *ofputil_encode_table_stats_reply(
719 const struct ofp12_table_stats[], int n,
720 const struct ofp_header *request);
722 /* Queue configuration request. */
723 struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version,
725 enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *,
728 /* Queue configuration reply. */
729 struct ofputil_queue_config {
732 /* Each of these optional values is expressed in tenths of a percent.
733 * Values greater than 1000 indicate that the feature is disabled.
734 * UINT16_MAX indicates that the value is omitted. */
739 struct ofpbuf *ofputil_encode_queue_get_config_reply(
740 const struct ofp_header *request);
741 void ofputil_append_queue_get_config_reply(
742 struct ofpbuf *reply, const struct ofputil_queue_config *);
744 enum ofperr ofputil_decode_queue_get_config_reply(struct ofpbuf *reply,
746 int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply,
747 struct ofputil_queue_config *);
750 /* Abstract nx_flow_monitor_request. */
751 struct ofputil_flow_monitor_request {
753 enum nx_flow_monitor_flags flags;
759 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
761 void ofputil_append_flow_monitor_request(
762 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
764 /* Abstract nx_flow_update. */
765 struct ofputil_flow_update {
766 enum nx_flow_update_event event;
768 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
769 enum ofp_flow_removed_reason reason;
770 uint16_t idle_timeout;
771 uint16_t hard_timeout;
776 struct ofpact *ofpacts;
779 /* Used only for NXFME_ABBREV. */
783 int ofputil_decode_flow_update(struct ofputil_flow_update *,
784 struct ofpbuf *msg, struct ofpbuf *ofpacts);
785 void ofputil_start_flow_update(struct list *replies);
786 void ofputil_append_flow_update(const struct ofputil_flow_update *,
787 struct list *replies);
789 /* Abstract nx_flow_monitor_cancel. */
790 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
791 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
793 /* Encoding OpenFlow stats messages. */
794 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
795 const struct ofputil_phy_port *pp,
796 struct list *replies);
798 /* Encoding simple OpenFlow messages. */
799 struct ofpbuf *make_echo_request(enum ofp_version);
800 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
802 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
804 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
805 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
810 /* The type of an action.
812 * For each implemented OFPAT10_* and NXAST_* action type, there is a
813 * corresponding constant prefixed with OFPUTIL_, e.g.:
815 * OFPUTIL_OFPAT10_OUTPUT
816 * OFPUTIL_OFPAT10_SET_VLAN_VID
817 * OFPUTIL_OFPAT10_SET_VLAN_PCP
818 * OFPUTIL_OFPAT10_STRIP_VLAN
819 * OFPUTIL_OFPAT10_SET_DL_SRC
820 * OFPUTIL_OFPAT10_SET_DL_DST
821 * OFPUTIL_OFPAT10_SET_NW_SRC
822 * OFPUTIL_OFPAT10_SET_NW_DST
823 * OFPUTIL_OFPAT10_SET_NW_TOS
824 * OFPUTIL_OFPAT10_SET_TP_SRC
825 * OFPUTIL_OFPAT10_SET_TP_DST
826 * OFPUTIL_OFPAT10_ENQUEUE
827 * OFPUTIL_NXAST_RESUBMIT
828 * OFPUTIL_NXAST_SET_TUNNEL
829 * OFPUTIL_NXAST_SET_METADATA
830 * OFPUTIL_NXAST_SET_QUEUE
831 * OFPUTIL_NXAST_POP_QUEUE
832 * OFPUTIL_NXAST_REG_MOVE
833 * OFPUTIL_NXAST_REG_LOAD
835 * OFPUTIL_NXAST_SET_TUNNEL64
836 * OFPUTIL_NXAST_MULTIPATH
837 * OFPUTIL_NXAST_BUNDLE
838 * OFPUTIL_NXAST_BUNDLE_LOAD
839 * OFPUTIL_NXAST_RESUBMIT_TABLE
840 * OFPUTIL_NXAST_OUTPUT_REG
841 * OFPUTIL_NXAST_LEARN
842 * OFPUTIL_NXAST_DEC_TTL
843 * OFPUTIL_NXAST_FIN_TIMEOUT
845 * (The above list helps developers who want to "grep" for these definitions.)
847 enum OVS_PACKED_ENUM ofputil_action_code {
848 OFPUTIL_ACTION_INVALID,
849 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
850 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
851 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
852 #include "ofp-util.def"
855 /* The number of values of "enum ofputil_action_code". */
857 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
858 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
859 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
860 OFPUTIL_N_ACTIONS = 1
861 #include "ofp-util.def"
864 int ofputil_action_code_from_name(const char *);
865 const char * ofputil_action_name_from_code(enum ofputil_action_code code);
867 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
869 /* For each OpenFlow action <ENUM> that has a corresponding action structure
870 * struct <STRUCT>, this defines two functions:
872 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
874 * Initializes the parts of 'action' that identify it as having type <ENUM>
875 * and length 'sizeof *action' and zeros the rest. For actions that have
876 * variable length, the length used and cleared is that of struct <STRUCT>.
878 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
880 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
881 * initializes it with ofputil_init_<ENUM>(), and returns it.
883 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
884 void ofputil_init_##ENUM(struct STRUCT *); \
885 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
886 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
887 void ofputil_init_##ENUM(struct STRUCT *); \
888 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
889 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
890 void ofputil_init_##ENUM(struct STRUCT *); \
891 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
892 #include "ofp-util.def"
894 #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
896 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
898 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
899 union ofp_action **, size_t *);
901 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
902 const union ofp_action *b, size_t n_b);
903 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
905 /* Handy utility for parsing flows and actions. */
906 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
908 struct ofputil_port_stats {
910 struct netdev_stats stats;
911 uint32_t duration_sec; /* UINT32_MAX if unknown. */
912 uint32_t duration_nsec;
915 struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
917 void ofputil_append_port_stat(struct list *replies,
918 const struct ofputil_port_stats *ops);
919 size_t ofputil_count_port_stats(const struct ofp_header *);
920 int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
921 enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
922 ofp_port_t *ofp10_port);
924 struct ofputil_queue_stats_request {
925 ofp_port_t port_no; /* OFPP_ANY means "all ports". */
930 ofputil_decode_queue_stats_request(const struct ofp_header *request,
931 struct ofputil_queue_stats_request *oqsr);
933 ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
934 const struct ofputil_queue_stats_request *oqsr);
936 struct ofputil_queue_stats {
940 /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
945 /* UINT32_MAX if unknown. */
946 uint32_t duration_sec;
947 uint32_t duration_nsec;
950 size_t ofputil_count_queue_stats(const struct ofp_header *);
951 int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
952 void ofputil_append_queue_stat(struct list *replies,
953 const struct ofputil_queue_stats *oqs);
955 /* Bucket for use in groups. */
956 struct ofputil_bucket {
957 struct list list_node;
958 uint16_t weight; /* Relative weight, for "select" groups. */
959 ofp_port_t watch_port; /* Port whose state affects whether this bucket
960 * is live. Only required for fast failover
962 uint32_t watch_group; /* Group whose state affects whether this
963 * bucket is live. Only required for fast
964 * failover groups. */
965 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
966 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
969 /* Protocol-independent group_mod. */
970 struct ofputil_group_mod {
971 uint16_t command; /* One of OFPGC11_*. */
972 uint8_t type; /* One of OFPGT11_*. */
973 uint32_t group_id; /* Group identifier. */
974 struct list buckets; /* Contains "struct ofputil_bucket"s. */
977 struct bucket_counter {
978 uint64_t packet_count; /* Number of packets processed by bucket. */
979 uint64_t byte_count; /* Number of bytes processed by bucket. */
982 /* Group stats reply, independent of protocol. */
983 struct ofputil_group_stats {
984 uint32_t group_id; /* Group identifier. */
986 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
987 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
988 uint32_t duration_sec; /* UINT32_MAX if unknown. */
989 uint32_t duration_nsec;
991 struct bucket_counter *bucket_stats;
994 /* Group features reply, independent of protocol.
996 * Only OF1.2 and later support group features replies. */
997 struct ofputil_group_features {
998 uint32_t types; /* Bitmap of OFPGT_* values supported. */
999 uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */
1000 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
1002 /* Bitmaps of OFPAT_* that are supported. OF1.2+ actions only. */
1003 uint32_t actions[4];
1006 /* Group desc reply, independent of protocol. */
1007 struct ofputil_group_desc {
1008 uint8_t type; /* One of OFPGT_*. */
1009 uint32_t group_id; /* Group identifier. */
1010 struct list buckets; /* Contains "struct ofputil_bucket"s. */
1013 void ofputil_bucket_list_destroy(struct list *buckets);
1016 ofputil_bucket_has_liveness(const struct ofputil_bucket *bucket)
1018 return (bucket->watch_port != OFPP_ANY ||
1019 bucket->watch_group != OFPG_ANY);
1022 struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version,
1024 enum ofperr ofputil_decode_group_stats_request(
1025 const struct ofp_header *request, uint32_t *group_id);
1026 void ofputil_append_group_stats(struct list *replies,
1027 const struct ofputil_group_stats *);
1028 struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version);
1029 struct ofpbuf *ofputil_encode_group_features_reply(
1030 const struct ofputil_group_features *, const struct ofp_header *request);
1031 void ofputil_decode_group_features_reply(const struct ofp_header *,
1032 struct ofputil_group_features *);
1033 struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version,
1034 const struct ofputil_group_mod *gm);
1036 enum ofperr ofputil_decode_group_mod(const struct ofp_header *,
1037 struct ofputil_group_mod *);
1039 int ofputil_decode_group_stats_reply(struct ofpbuf *,
1040 struct ofputil_group_stats *);
1042 int ofputil_decode_group_desc_reply(struct ofputil_group_desc *,
1043 struct ofpbuf *, enum ofp_version);
1045 void ofputil_append_group_desc_reply(const struct ofputil_group_desc *,
1046 struct list *buckets,
1047 struct list *replies);
1048 struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version);
1050 #endif /* ofp-util.h */