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.
23 #include "classifier.h"
28 #include "openflow/nicira-ext.h"
29 #include "openvswitch/types.h"
30 #include "type-props.h"
35 enum ofperr
ofputil_port_from_ofp11(ovs_be32 ofp11_port
,
36 ofp_port_t
*ofp10_port
);
37 ovs_be32
ofputil_port_to_ofp11(ofp_port_t ofp10_port
);
39 enum ofperr
ofputil_check_output_port(ofp_port_t ofp_port
,
40 ofp_port_t max_ports
);
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)
92 /* OpenFlow 1.1 protocol.
94 * We only support the standard OpenFlow 1.1 flow format.
96 * OpenFlow 1.1 always operates with an equivalent of the
97 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
99 OFPUTIL_P_OF11_STD
= 1 << 4,
101 /* OpenFlow 1.2+ protocols (only one variant each).
103 * These use the standard OpenFlow Extensible Match (OXM) flow format.
105 * OpenFlow 1.2+ always operates with an equivalent of the
106 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
108 OFPUTIL_P_OF12_OXM
= 1 << 5,
109 OFPUTIL_P_OF13_OXM
= 1 << 6,
110 #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM)
112 #define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
115 #define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
117 #define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
119 #define OFPUTIL_P_OF12_UP (OFPUTIL_P_ANY_OXM)
121 #define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM)
124 #define OFPUTIL_P_ANY ((1 << 7) - 1)
126 /* Protocols in which a specific table may be specified in flow_mods. */
127 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
128 OFPUTIL_P_OF10_NXM_TID | \
129 OFPUTIL_P_OF11_STD | \
133 /* Protocols to use for flow dumps, from most to least preferred. */
134 extern enum ofputil_protocol ofputil_flow_dump_protocols
[];
135 extern size_t ofputil_n_flow_dump_protocols
;
137 enum ofputil_protocol
ofputil_protocol_from_ofp_version(enum ofp_version
);
138 enum ofputil_protocol
ofputil_protocols_from_ofp_version(enum ofp_version
);
139 enum ofp_version
ofputil_protocol_to_ofp_version(enum ofputil_protocol
);
141 bool ofputil_protocol_is_valid(enum ofputil_protocol
);
142 enum ofputil_protocol
ofputil_protocol_set_tid(enum ofputil_protocol
,
144 enum ofputil_protocol
ofputil_protocol_to_base(enum ofputil_protocol
);
145 enum ofputil_protocol
ofputil_protocol_set_base(
146 enum ofputil_protocol cur
, enum ofputil_protocol new_base
);
148 const char *ofputil_protocol_to_string(enum ofputil_protocol
);
149 char *ofputil_protocols_to_string(enum ofputil_protocol
);
150 enum ofputil_protocol
ofputil_protocols_from_string(const char *);
152 void ofputil_format_version(struct ds
*, enum ofp_version
);
153 void ofputil_format_version_name(struct ds
*, enum ofp_version
);
155 /* A bitmap of version numbers
157 * Bit offsets correspond to ofp_version numbers which in turn correspond to
158 * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION)
159 * is the mask for Open Flow 1.1. If the bit for a version is set then it is
160 * allowed, otherwise it is disallowed. */
162 void ofputil_format_version_bitmap(struct ds
*msg
, uint32_t bitmap
);
163 void ofputil_format_version_bitmap_names(struct ds
*msg
, uint32_t bitmap
);
165 uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol
);
166 enum ofputil_protocol
ofputil_protocols_from_version_bitmap(uint32_t bitmap
);
168 /* Bitmap of OpenFlow versions that Open vSwitch supports. */
169 #define OFPUTIL_SUPPORTED_VERSIONS \
170 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
172 /* Bitmap of OpenFlow versions to enable by default (a subset of
173 * OFPUTIL_SUPPORTED_VERSIONS). */
174 #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
176 enum ofputil_protocol
ofputil_protocols_from_string(const char *s
);
178 const char *ofputil_version_to_string(enum ofp_version ofp_version
);
179 uint32_t ofputil_versions_from_string(const char *s
);
180 uint32_t ofputil_versions_from_strings(char ** const s
, size_t count
);
182 bool ofputil_decode_hello(const struct ofp_header
*,
183 uint32_t *allowed_versions
);
184 struct ofpbuf
*ofputil_encode_hello(uint32_t version_bitmap
);
186 struct ofpbuf
*ofputil_encode_set_protocol(enum ofputil_protocol current
,
187 enum ofputil_protocol want
,
188 enum ofputil_protocol
*next
);
191 struct ofpbuf
*ofputil_encode_nx_set_flow_format(enum nx_flow_format
);
192 enum ofputil_protocol
ofputil_nx_flow_format_to_protocol(enum nx_flow_format
);
193 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format
);
194 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format
);
196 /* Work with ofp10_match. */
197 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw
, struct flow_wildcards
*);
198 void ofputil_match_from_ofp10_match(const struct ofp10_match
*,
200 void ofputil_normalize_match(struct match
*);
201 void ofputil_normalize_match_quiet(struct match
*);
202 void ofputil_match_to_ofp10_match(const struct match
*, struct ofp10_match
*);
204 /* Work with ofp11_match. */
205 enum ofperr
ofputil_pull_ofp11_match(struct ofpbuf
*, struct match
*,
206 uint16_t *padded_match_len
);
207 enum ofperr
ofputil_match_from_ofp11_match(const struct ofp11_match
*,
209 int ofputil_put_ofp11_match(struct ofpbuf
*, const struct match
*,
210 enum ofputil_protocol
);
211 void ofputil_match_to_ofp11_match(const struct match
*, struct ofp11_match
*);
212 int ofputil_match_typical_len(enum ofputil_protocol
);
214 /* dl_type translation between OpenFlow and 'struct flow' format. */
215 ovs_be16
ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type
);
216 ovs_be16
ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type
);
219 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format
);
220 int ofputil_packet_in_format_from_string(const char *);
221 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format
);
222 struct ofpbuf
*ofputil_make_set_packet_in_format(enum ofp_version
,
223 enum nx_packet_in_format
);
225 /* NXT_FLOW_MOD_TABLE_ID extension. */
226 struct ofpbuf
*ofputil_make_flow_mod_table_id(bool flow_mod_table_id
);
228 /* Protocol-independent flow_mod flags. */
229 enum ofputil_flow_mod_flags
{
230 OFPUTIL_FF_SEND_FLOW_REM
= 1 << 0, /* All versions. */
231 OFPUTIL_FF_CHECK_OVERLAP
= 1 << 1, /* All versions. */
232 OFPUTIL_FF_EMERG
= 1 << 2, /* OpenFlow 1.0 only. */
233 OFPUTIL_FF_RESET_COUNTS
= 1 << 3, /* OpenFlow 1.2+. */
234 OFPUTIL_FF_NO_PKT_COUNTS
= 1 << 4, /* OpenFlow 1.3+. */
235 OFPUTIL_FF_NO_BYT_COUNTS
= 1 << 5 /* OpenFlow 1.3+. */
238 /* Protocol-independent flow_mod.
240 * The handling of cookies across multiple versions of OpenFlow is a bit
241 * confusing. See DESIGN for the details. */
242 struct ofputil_flow_mod
{
243 struct list list_node
; /* For queuing flow_mods. */
246 unsigned int priority
;
248 /* Cookie matching. The flow_mod affects only flows that have cookies that
249 * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits.
251 * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
252 ovs_be64 cookie
; /* Cookie bits to match. */
253 ovs_be64 cookie_mask
; /* 1-bit in each 'cookie' bit to match. */
257 * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie'
258 * should not be UINT64_MAX.
260 * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
262 * - If one or more matching flows exist and 'modify_cookie' is true,
263 * then the flow_mod changes the existing flows' cookies to
264 * 'new_cookie'. 'new_cookie' should not be UINT64_MAX.
266 * - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and
267 * 'cookie_mask' is 0, then the flow_mod adds a new flow with
268 * 'new_cookie' as its cookie.
270 ovs_be64 new_cookie
; /* New cookie to install or UINT64_MAX. */
271 bool modify_cookie
; /* Set cookie of existing flow to 'new_cookie'? */
275 uint16_t idle_timeout
;
276 uint16_t hard_timeout
;
280 enum ofputil_flow_mod_flags flags
;
281 struct ofpact
*ofpacts
; /* Series of "struct ofpact"s. */
282 size_t ofpacts_len
; /* Length of ofpacts, in bytes. */
285 enum ofperr
ofputil_decode_flow_mod(struct ofputil_flow_mod
*,
286 const struct ofp_header
*,
287 enum ofputil_protocol
,
288 struct ofpbuf
*ofpacts
);
289 struct ofpbuf
*ofputil_encode_flow_mod(const struct ofputil_flow_mod
*,
290 enum ofputil_protocol
);
292 /* Flow stats or aggregate stats request, independent of protocol. */
293 struct ofputil_flow_stats_request
{
294 bool aggregate
; /* Aggregate results? */
297 ovs_be64 cookie_mask
;
303 enum ofperr
ofputil_decode_flow_stats_request(
304 struct ofputil_flow_stats_request
*, const struct ofp_header
*);
305 struct ofpbuf
*ofputil_encode_flow_stats_request(
306 const struct ofputil_flow_stats_request
*, enum ofputil_protocol
);
308 /* Flow stats reply, independent of protocol. */
309 struct ofputil_flow_stats
{
313 uint32_t duration_sec
;
314 uint32_t duration_nsec
;
316 uint16_t idle_timeout
;
317 uint16_t hard_timeout
;
318 int idle_age
; /* Seconds since last packet, -1 if unknown. */
319 int hard_age
; /* Seconds since last change, -1 if unknown. */
320 uint64_t packet_count
; /* Packet count, UINT64_MAX if unknown. */
321 uint64_t byte_count
; /* Byte count, UINT64_MAX if unknown. */
322 struct ofpact
*ofpacts
;
324 enum ofputil_flow_mod_flags flags
;
327 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats
*,
329 bool flow_age_extension
,
330 struct ofpbuf
*ofpacts
);
331 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats
*,
332 struct list
*replies
);
334 /* Aggregate stats reply, independent of protocol. */
335 struct ofputil_aggregate_stats
{
336 uint64_t packet_count
; /* Packet count, UINT64_MAX if unknown. */
337 uint64_t byte_count
; /* Byte count, UINT64_MAX if unknown. */
341 struct ofpbuf
*ofputil_encode_aggregate_stats_reply(
342 const struct ofputil_aggregate_stats
*stats
,
343 const struct ofp_header
*request
);
344 enum ofperr
ofputil_decode_aggregate_stats_reply(
345 struct ofputil_aggregate_stats
*,
346 const struct ofp_header
*reply
);
348 /* Flow removed message, independent of protocol. */
349 struct ofputil_flow_removed
{
353 uint8_t reason
; /* One of OFPRR_*. */
354 uint8_t table_id
; /* 255 if message didn't include table ID. */
355 uint32_t duration_sec
;
356 uint32_t duration_nsec
;
357 uint16_t idle_timeout
;
358 uint16_t hard_timeout
;
359 uint64_t packet_count
; /* Packet count, UINT64_MAX if unknown. */
360 uint64_t byte_count
; /* Byte count, UINT64_MAX if unknown. */
363 enum ofperr
ofputil_decode_flow_removed(struct ofputil_flow_removed
*,
364 const struct ofp_header
*);
365 struct ofpbuf
*ofputil_encode_flow_removed(const struct ofputil_flow_removed
*,
366 enum ofputil_protocol
);
368 /* Abstract packet-in message. */
369 struct ofputil_packet_in
{
370 struct list list_node
; /* For queueing packet_ins. */
375 enum ofp_packet_in_reason reason
; /* One of OFPR_*. */
376 uint16_t controller_id
; /* Controller ID to send to. */
382 uint16_t total_len
; /* Full length of frame. */
384 struct flow_metadata fmd
; /* Metadata at creation time. */
387 enum ofperr
ofputil_decode_packet_in(struct ofputil_packet_in
*,
388 const struct ofp_header
*);
389 struct ofpbuf
*ofputil_encode_packet_in(const struct ofputil_packet_in
*,
390 enum ofputil_protocol protocol
,
391 enum nx_packet_in_format
);
393 enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE
= INT_STRLEN(int) + 1 };
394 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason
,
397 bool ofputil_packet_in_reason_from_string(const char *,
398 enum ofp_packet_in_reason
*);
400 /* Abstract packet-out message.
402 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
403 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
404 struct ofputil_packet_out
{
405 const void *packet
; /* Packet data, if buffer_id == UINT32_MAX. */
406 size_t packet_len
; /* Length of packet data in bytes. */
407 uint32_t buffer_id
; /* Buffer id or UINT32_MAX if no buffer. */
408 ofp_port_t in_port
; /* Packet's input port. */
409 struct ofpact
*ofpacts
; /* Actions. */
410 size_t ofpacts_len
; /* Size of ofpacts in bytes. */
413 enum ofperr
ofputil_decode_packet_out(struct ofputil_packet_out
*,
414 const struct ofp_header
*,
415 struct ofpbuf
*ofpacts
);
416 struct ofpbuf
*ofputil_encode_packet_out(const struct ofputil_packet_out
*,
417 enum ofputil_protocol protocol
);
419 enum ofputil_port_config
{
420 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
421 OFPUTIL_PC_PORT_DOWN
= 1 << 0, /* Port is administratively down. */
422 OFPUTIL_PC_NO_RECV
= 1 << 2, /* Drop all packets received by port. */
423 OFPUTIL_PC_NO_FWD
= 1 << 5, /* Drop packets forwarded to port. */
424 OFPUTIL_PC_NO_PACKET_IN
= 1 << 6, /* No send packet-in msgs for port. */
425 /* OpenFlow 1.0 only. */
426 OFPUTIL_PC_NO_STP
= 1 << 1, /* No 802.1D spanning tree for port. */
427 OFPUTIL_PC_NO_RECV_STP
= 1 << 3, /* Drop received 802.1D STP packets. */
428 OFPUTIL_PC_NO_FLOOD
= 1 << 4, /* Do not include port when flooding. */
429 /* There are no OpenFlow 1.1-only bits. */
432 enum ofputil_port_state
{
433 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
434 OFPUTIL_PS_LINK_DOWN
= 1 << 0, /* No physical link present. */
435 /* OpenFlow 1.1 only. */
436 OFPUTIL_PS_BLOCKED
= 1 << 1, /* Port is blocked */
437 OFPUTIL_PS_LIVE
= 1 << 2, /* Live for Fast Failover Group. */
438 /* OpenFlow 1.0 only. */
439 OFPUTIL_PS_STP_LISTEN
= 0 << 8, /* Not learning or relaying frames. */
440 OFPUTIL_PS_STP_LEARN
= 1 << 8, /* Learning but not relaying frames. */
441 OFPUTIL_PS_STP_FORWARD
= 2 << 8, /* Learning and relaying frames. */
442 OFPUTIL_PS_STP_BLOCK
= 3 << 8, /* Not part of spanning tree. */
443 OFPUTIL_PS_STP_MASK
= 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
446 /* Abstract ofp10_phy_port or ofp11_port. */
447 struct ofputil_phy_port
{
449 uint8_t hw_addr
[OFP_ETH_ALEN
];
450 char name
[OFP_MAX_PORT_NAME_LEN
];
451 enum ofputil_port_config config
;
452 enum ofputil_port_state state
;
454 /* NETDEV_F_* feature bitmasks. */
455 enum netdev_features curr
; /* Current features. */
456 enum netdev_features advertised
; /* Features advertised by the port. */
457 enum netdev_features supported
; /* Features supported by the port. */
458 enum netdev_features peer
; /* Features advertised by peer. */
461 uint32_t curr_speed
; /* Current speed, in kbps. */
462 uint32_t max_speed
; /* Maximum supported speed, in kbps. */
465 enum ofputil_capabilities
{
466 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
467 OFPUTIL_C_FLOW_STATS
= 1 << 0, /* Flow statistics. */
468 OFPUTIL_C_TABLE_STATS
= 1 << 1, /* Table statistics. */
469 OFPUTIL_C_PORT_STATS
= 1 << 2, /* Port statistics. */
470 OFPUTIL_C_IP_REASM
= 1 << 5, /* Can reassemble IP fragments. */
471 OFPUTIL_C_QUEUE_STATS
= 1 << 6, /* Queue statistics. */
473 /* OpenFlow 1.0 and 1.1 share this capability. */
474 OFPUTIL_C_ARP_MATCH_IP
= 1 << 7, /* Match IP addresses in ARP pkts. */
476 /* OpenFlow 1.0 only. */
477 OFPUTIL_C_STP
= 1 << 3, /* 802.1d spanning tree. */
479 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
480 OFPUTIL_C_GROUP_STATS
= 1 << 4, /* Group statistics. */
482 /* OpenFlow 1.2 and 1.3 share this capability */
483 OFPUTIL_C_PORT_BLOCKED
= 1 << 8, /* Switch will block looping ports */
486 enum ofputil_action_bitmap
{
487 OFPUTIL_A_OUTPUT
= 1 << 0,
488 OFPUTIL_A_SET_VLAN_VID
= 1 << 1,
489 OFPUTIL_A_SET_VLAN_PCP
= 1 << 2,
490 OFPUTIL_A_STRIP_VLAN
= 1 << 3,
491 OFPUTIL_A_SET_DL_SRC
= 1 << 4,
492 OFPUTIL_A_SET_DL_DST
= 1 << 5,
493 OFPUTIL_A_SET_NW_SRC
= 1 << 6,
494 OFPUTIL_A_SET_NW_DST
= 1 << 7,
495 OFPUTIL_A_SET_NW_ECN
= 1 << 8,
496 OFPUTIL_A_SET_NW_TOS
= 1 << 9,
497 OFPUTIL_A_SET_TP_SRC
= 1 << 10,
498 OFPUTIL_A_SET_TP_DST
= 1 << 11,
499 OFPUTIL_A_ENQUEUE
= 1 << 12,
500 OFPUTIL_A_COPY_TTL_OUT
= 1 << 13,
501 OFPUTIL_A_COPY_TTL_IN
= 1 << 14,
502 OFPUTIL_A_SET_MPLS_LABEL
= 1 << 15,
503 OFPUTIL_A_SET_MPLS_TC
= 1 << 16,
504 OFPUTIL_A_SET_MPLS_TTL
= 1 << 17,
505 OFPUTIL_A_DEC_MPLS_TTL
= 1 << 18,
506 OFPUTIL_A_PUSH_VLAN
= 1 << 19,
507 OFPUTIL_A_POP_VLAN
= 1 << 20,
508 OFPUTIL_A_PUSH_MPLS
= 1 << 21,
509 OFPUTIL_A_POP_MPLS
= 1 << 22,
510 OFPUTIL_A_SET_QUEUE
= 1 << 23,
511 OFPUTIL_A_GROUP
= 1 << 24,
512 OFPUTIL_A_SET_NW_TTL
= 1 << 25,
513 OFPUTIL_A_DEC_NW_TTL
= 1 << 26,
514 OFPUTIL_A_SET_FIELD
= 1 << 27,
517 /* Abstract ofp_switch_features. */
518 struct ofputil_switch_features
{
519 uint64_t datapath_id
; /* Datapath unique ID. */
520 uint32_t n_buffers
; /* Max packets buffered at once. */
521 uint8_t n_tables
; /* Number of tables supported by datapath. */
522 uint8_t auxiliary_id
; /* Identify auxiliary connections */
523 enum ofputil_capabilities capabilities
;
524 enum ofputil_action_bitmap actions
;
527 enum ofperr
ofputil_decode_switch_features(const struct ofp_header
*,
528 struct ofputil_switch_features
*,
531 struct ofpbuf
*ofputil_encode_switch_features(
532 const struct ofputil_switch_features
*, enum ofputil_protocol
,
534 void ofputil_put_switch_features_port(const struct ofputil_phy_port
*,
536 bool ofputil_switch_features_ports_trunc(struct ofpbuf
*b
);
538 /* phy_port helper functions. */
539 int ofputil_pull_phy_port(enum ofp_version ofp_version
, struct ofpbuf
*,
540 struct ofputil_phy_port
*);
541 size_t ofputil_count_phy_ports(uint8_t ofp_version
, struct ofpbuf
*);
543 /* Abstract ofp_port_status. */
544 struct ofputil_port_status
{
545 enum ofp_port_reason reason
;
546 struct ofputil_phy_port desc
;
549 enum ofperr
ofputil_decode_port_status(const struct ofp_header
*,
550 struct ofputil_port_status
*);
551 struct ofpbuf
*ofputil_encode_port_status(const struct ofputil_port_status
*,
552 enum ofputil_protocol
);
554 /* Abstract ofp_port_mod. */
555 struct ofputil_port_mod
{
557 uint8_t hw_addr
[OFP_ETH_ALEN
];
558 enum ofputil_port_config config
;
559 enum ofputil_port_config mask
;
560 enum netdev_features advertise
;
563 enum ofperr
ofputil_decode_port_mod(const struct ofp_header
*,
564 struct ofputil_port_mod
*);
565 struct ofpbuf
*ofputil_encode_port_mod(const struct ofputil_port_mod
*,
566 enum ofputil_protocol
);
568 /* Abstract ofp_table_mod. */
569 struct ofputil_table_mod
{
570 uint8_t table_id
; /* ID of the table, 0xff indicates all tables. */
574 enum ofperr
ofputil_decode_table_mod(const struct ofp_header
*,
575 struct ofputil_table_mod
*);
576 struct ofpbuf
*ofputil_encode_table_mod(const struct ofputil_table_mod
*,
577 enum ofputil_protocol
);
579 /* Meter band configuration for all supported band types. */
580 struct ofputil_meter_band
{
582 uint8_t prec_level
; /* Non-zero if type == OFPMBT_DSCP_REMARK. */
587 struct ofputil_meter_band_stats
{
588 uint64_t packet_count
;
592 struct ofputil_meter_config
{
596 struct ofputil_meter_band
*bands
;
599 /* Abstract ofp_meter_mod. */
600 struct ofputil_meter_mod
{
602 struct ofputil_meter_config meter
;
605 struct ofputil_meter_stats
{
608 uint64_t packet_in_count
;
609 uint64_t byte_in_count
;
610 uint32_t duration_sec
;
611 uint32_t duration_nsec
;
613 struct ofputil_meter_band_stats
*bands
;
616 struct ofputil_meter_features
{
617 uint32_t max_meters
; /* Maximum number of meters. */
618 uint32_t band_types
; /* Can support max 32 band types. */
619 uint32_t capabilities
; /* Supported flags. */
624 enum ofperr
ofputil_decode_meter_mod(const struct ofp_header
*,
625 struct ofputil_meter_mod
*,
626 struct ofpbuf
*bands
);
627 struct ofpbuf
*ofputil_encode_meter_mod(enum ofp_version
,
628 const struct ofputil_meter_mod
*);
630 void ofputil_decode_meter_features(const struct ofp_header
*,
631 struct ofputil_meter_features
*);
632 struct ofpbuf
*ofputil_encode_meter_features_reply(const struct
633 ofputil_meter_features
*,
634 const struct ofp_header
*
636 void ofputil_decode_meter_request(const struct ofp_header
*,
639 void ofputil_append_meter_config(struct list
*replies
,
640 const struct ofputil_meter_config
*);
642 void ofputil_append_meter_stats(struct list
*replies
,
643 const struct ofputil_meter_stats
*);
645 enum ofputil_meter_request_type
{
646 OFPUTIL_METER_FEATURES
,
647 OFPUTIL_METER_CONFIG
,
651 struct ofpbuf
*ofputil_encode_meter_request(enum ofp_version
,
652 enum ofputil_meter_request_type
,
655 int ofputil_decode_meter_stats(struct ofpbuf
*,
656 struct ofputil_meter_stats
*,
657 struct ofpbuf
*bands
);
659 int ofputil_decode_meter_config(struct ofpbuf
*,
660 struct ofputil_meter_config
*,
661 struct ofpbuf
*bands
);
663 /* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
664 typedef struct { uint32_t uint32
; } ofproto_meter_id
;
666 /* Abstract ofp_role_request and reply. */
667 struct ofputil_role_request
{
668 enum ofp12_controller_role role
;
669 bool have_generation_id
;
670 uint64_t generation_id
;
673 enum ofperr
ofputil_decode_role_message(const struct ofp_header
*,
674 struct ofputil_role_request
*);
675 struct ofpbuf
*ofputil_encode_role_reply(const struct ofp_header
*,
676 const struct ofputil_role_request
*);
678 /* Abstract table stats.
680 * For now we use ofp12_table_stats as a superset of the other protocol
681 * versions' table stats. */
683 struct ofpbuf
*ofputil_encode_table_stats_reply(
684 const struct ofp12_table_stats
[], int n
,
685 const struct ofp_header
*request
);
687 /* Abstract nx_flow_monitor_request. */
688 struct ofputil_flow_monitor_request
{
690 enum nx_flow_monitor_flags flags
;
696 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request
*,
698 void ofputil_append_flow_monitor_request(
699 const struct ofputil_flow_monitor_request
*, struct ofpbuf
*msg
);
701 /* Abstract nx_flow_update. */
702 struct ofputil_flow_update
{
703 enum nx_flow_update_event event
;
705 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
706 enum ofp_flow_removed_reason reason
;
707 uint16_t idle_timeout
;
708 uint16_t hard_timeout
;
713 struct ofpact
*ofpacts
;
716 /* Used only for NXFME_ABBREV. */
720 int ofputil_decode_flow_update(struct ofputil_flow_update
*,
721 struct ofpbuf
*msg
, struct ofpbuf
*ofpacts
);
722 void ofputil_start_flow_update(struct list
*replies
);
723 void ofputil_append_flow_update(const struct ofputil_flow_update
*,
724 struct list
*replies
);
726 /* Abstract nx_flow_monitor_cancel. */
727 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header
*);
728 struct ofpbuf
*ofputil_encode_flow_monitor_cancel(uint32_t id
);
730 /* Encoding OpenFlow stats messages. */
731 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version
,
732 const struct ofputil_phy_port
*pp
,
733 struct list
*replies
);
735 /* Encoding simple OpenFlow messages. */
736 struct ofpbuf
*make_echo_request(enum ofp_version
);
737 struct ofpbuf
*make_echo_reply(const struct ofp_header
*rq
);
739 struct ofpbuf
*ofputil_encode_barrier_request(enum ofp_version
);
741 const char *ofputil_frag_handling_to_string(enum ofp_config_flags
);
742 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags
*);
747 /* The type of an action.
749 * For each implemented OFPAT10_* and NXAST_* action type, there is a
750 * corresponding constant prefixed with OFPUTIL_, e.g.:
752 * OFPUTIL_OFPAT10_OUTPUT
753 * OFPUTIL_OFPAT10_SET_VLAN_VID
754 * OFPUTIL_OFPAT10_SET_VLAN_PCP
755 * OFPUTIL_OFPAT10_STRIP_VLAN
756 * OFPUTIL_OFPAT10_SET_DL_SRC
757 * OFPUTIL_OFPAT10_SET_DL_DST
758 * OFPUTIL_OFPAT10_SET_NW_SRC
759 * OFPUTIL_OFPAT10_SET_NW_DST
760 * OFPUTIL_OFPAT10_SET_NW_TOS
761 * OFPUTIL_OFPAT10_SET_TP_SRC
762 * OFPUTIL_OFPAT10_SET_TP_DST
763 * OFPUTIL_OFPAT10_ENQUEUE
764 * OFPUTIL_NXAST_RESUBMIT
765 * OFPUTIL_NXAST_SET_TUNNEL
766 * OFPUTIL_NXAST_SET_METADATA
767 * OFPUTIL_NXAST_SET_QUEUE
768 * OFPUTIL_NXAST_POP_QUEUE
769 * OFPUTIL_NXAST_REG_MOVE
770 * OFPUTIL_NXAST_REG_LOAD
772 * OFPUTIL_NXAST_SET_TUNNEL64
773 * OFPUTIL_NXAST_MULTIPATH
774 * OFPUTIL_NXAST_BUNDLE
775 * OFPUTIL_NXAST_BUNDLE_LOAD
776 * OFPUTIL_NXAST_RESUBMIT_TABLE
777 * OFPUTIL_NXAST_OUTPUT_REG
778 * OFPUTIL_NXAST_LEARN
779 * OFPUTIL_NXAST_DEC_TTL
780 * OFPUTIL_NXAST_FIN_TIMEOUT
782 * (The above list helps developers who want to "grep" for these definitions.)
784 enum OVS_PACKED_ENUM ofputil_action_code
{
785 OFPUTIL_ACTION_INVALID
,
786 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
787 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
788 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
789 #include "ofp-util.def"
792 /* The number of values of "enum ofputil_action_code". */
794 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
795 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
796 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
797 OFPUTIL_N_ACTIONS
= 1
798 #include "ofp-util.def"
801 int ofputil_action_code_from_name(const char *);
803 void *ofputil_put_action(enum ofputil_action_code
, struct ofpbuf
*buf
);
805 /* For each OpenFlow action <ENUM> that has a corresponding action structure
806 * struct <STRUCT>, this defines two functions:
808 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
810 * Initializes the parts of 'action' that identify it as having type <ENUM>
811 * and length 'sizeof *action' and zeros the rest. For actions that have
812 * variable length, the length used and cleared is that of struct <STRUCT>.
814 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
816 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
817 * initializes it with ofputil_init_<ENUM>(), and returns it.
819 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
820 void ofputil_init_##ENUM(struct STRUCT *); \
821 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
822 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
823 void ofputil_init_##ENUM(struct STRUCT *); \
824 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
825 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
826 void ofputil_init_##ENUM(struct STRUCT *); \
827 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
828 #include "ofp-util.def"
830 #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
832 bool action_outputs_to_port(const union ofp_action
*, ovs_be16 port
);
834 enum ofperr
ofputil_pull_actions(struct ofpbuf
*, unsigned int actions_len
,
835 union ofp_action
**, size_t *);
837 bool ofputil_actions_equal(const union ofp_action
*a
, size_t n_a
,
838 const union ofp_action
*b
, size_t n_b
);
839 union ofp_action
*ofputil_actions_clone(const union ofp_action
*, size_t n
);
841 /* Handy utility for parsing flows and actions. */
842 bool ofputil_parse_key_value(char **stringp
, char **keyp
, char **valuep
);
844 struct ofputil_port_stats
{
846 struct netdev_stats stats
;
847 uint32_t duration_sec
; /* UINT32_MAX if unknown. */
848 uint32_t duration_nsec
;
851 struct ofpbuf
*ofputil_encode_dump_ports_request(enum ofp_version ofp_version
,
853 void ofputil_append_port_stat(struct list
*replies
,
854 const struct ofputil_port_stats
*ops
);
855 size_t ofputil_count_port_stats(const struct ofp_header
*);
856 int ofputil_decode_port_stats(struct ofputil_port_stats
*, struct ofpbuf
*msg
);
857 enum ofperr
ofputil_decode_port_stats_request(const struct ofp_header
*request
,
858 ofp_port_t
*ofp10_port
);
860 struct ofputil_queue_stats_request
{
861 ofp_port_t port_no
; /* OFPP_ANY means "all ports". */
866 ofputil_decode_queue_stats_request(const struct ofp_header
*request
,
867 struct ofputil_queue_stats_request
*oqsr
);
869 ofputil_encode_queue_stats_request(enum ofp_version ofp_version
,
870 const struct ofputil_queue_stats_request
*oqsr
);
872 struct ofputil_queue_stats
{
876 /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
881 /* UINT32_MAX if unknown. */
882 uint32_t duration_sec
;
883 uint32_t duration_nsec
;
886 size_t ofputil_count_queue_stats(const struct ofp_header
*);
887 int ofputil_decode_queue_stats(struct ofputil_queue_stats
*qs
, struct ofpbuf
*msg
);
888 void ofputil_append_queue_stat(struct list
*replies
,
889 const struct ofputil_queue_stats
*oqs
);
891 /* Bucket for use in groups. */
892 struct ofputil_bucket
{
893 struct list list_node
;
894 uint16_t weight
; /* Relative weight, for "select" groups. */
895 ofp_port_t watch_port
; /* Port whose state affects whether this bucket
896 * is live. Only required for fast failover
898 uint32_t watch_group
; /* Group whose state affects whether this
899 * bucket is live. Only required for fast
900 * failover groups. */
901 struct ofpact
*ofpacts
; /* Series of "struct ofpact"s. */
902 size_t ofpacts_len
; /* Length of ofpacts, in bytes. */
905 /* Protocol-independent group_mod. */
906 struct ofputil_group_mod
{
907 uint16_t command
; /* One of OFPGC11_*. */
908 uint8_t type
; /* One of OFPGT11_*. */
909 uint32_t group_id
; /* Group identifier. */
910 struct list buckets
; /* Contains "struct ofputil_bucket"s. */
913 struct bucket_counter
{
914 uint64_t packet_count
; /* Number of packets processed by bucket. */
915 uint64_t byte_count
; /* Number of bytes processed by bucket. */
918 /* Group stats reply, independent of protocol. */
919 struct ofputil_group_stats
{
920 uint32_t group_id
; /* Group identifier. */
922 uint64_t packet_count
; /* Packet count, UINT64_MAX if unknown. */
923 uint64_t byte_count
; /* Byte count, UINT64_MAX if unknown. */
924 uint32_t duration_sec
; /* UINT32_MAX if unknown. */
925 uint32_t duration_nsec
;
927 struct bucket_counter
*bucket_stats
;
930 /* Group features reply, independent of protocol. */
931 struct ofputil_group_features
{
932 uint32_t types
; /* Bitmap of OFPGT_* values supported. */
933 uint32_t capabilities
; /* Bitmap of OFPGFC12_* capability supported. */
934 uint32_t max_groups
[4]; /* Maximum number of groups for each type. */
935 uint32_t actions
[4]; /* Bitmaps of OFPAT_* that are supported. */
938 /* Group desc reply, independent of protocol. */
939 struct ofputil_group_desc
{
940 uint8_t type
; /* One of OFPGT_*. */
941 uint32_t group_id
; /* Group identifier. */
942 struct list buckets
; /* Contains "struct ofputil_bucket"s. */
945 void ofputil_bucket_list_destroy(struct list
*buckets
);
947 struct ofpbuf
*ofputil_encode_group_stats_request(enum ofp_version
,
949 enum ofperr
ofputil_decode_group_stats_request(
950 const struct ofp_header
*request
, uint32_t *group_id
);
951 void ofputil_append_group_stats(struct list
*replies
,
952 const struct ofputil_group_stats
*);
953 struct ofpbuf
*ofputil_encode_group_features_request(enum ofp_version
);
954 struct ofpbuf
*ofputil_encode_group_features_reply(
955 const struct ofputil_group_features
*, const struct ofp_header
*request
);
956 void ofputil_decode_group_features_reply(const struct ofp_header
*,
957 struct ofputil_group_features
*);
958 struct ofpbuf
*ofputil_encode_group_mod(enum ofp_version ofp_version
,
959 const struct ofputil_group_mod
*gm
);
961 enum ofperr
ofputil_decode_group_mod(const struct ofp_header
*,
962 struct ofputil_group_mod
*);
964 int ofputil_decode_group_stats_reply(struct ofpbuf
*,
965 struct ofputil_group_stats
*);
967 int ofputil_decode_group_desc_reply(struct ofputil_group_desc
*,
970 void ofputil_append_group_desc_reply(const struct ofputil_group_desc
*,
971 struct list
*buckets
,
972 struct list
*replies
);
973 struct ofpbuf
*ofputil_encode_group_desc_request(enum ofp_version
);
975 #endif /* ofp-util.h */