]> git.proxmox.com Git - mirror_ovs.git/blame - lib/ofp-util.h
ofp-util: Enforce OpenFlow 1.1+ table_id requirements in flow_mod messages.
[mirror_ovs.git] / lib / ofp-util.h
CommitLineData
fa37b408 1/*
f4f1ea7e 2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
fa37b408
BP
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef OFP_UTIL_H
18#define OFP_UTIL_H 1
19
c1c9c9c4 20#include <stdbool.h>
fa37b408
BP
21#include <stddef.h>
22#include <stdint.h>
d1e2cf21 23#include "classifier.h"
f25d0cf3 24#include "compiler.h"
fa37b408 25#include "flow.h"
81a76618 26#include "match.h"
6c038611 27#include "netdev.h"
492f7572 28#include "openflow/nicira-ext.h"
44381c1b 29#include "openvswitch/types.h"
5014a89d 30#include "type-props.h"
fa37b408
BP
31
32struct ofpbuf;
e45e72f1 33union ofp_action;
b2dd70be 34struct ofpact_set_field;
fa37b408 35
39dc9082 36/* Port numbers. */
4e022ec0
AW
37enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
38 ofp_port_t *ofp10_port);
39ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);
7b7503ea 40
4e022ec0
AW
41bool ofputil_port_from_string(const char *, ofp_port_t *portp);
42void ofputil_format_port(ofp_port_t port, struct ds *);
28b11432
BP
43void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
44 size_t bufsize);
d1e2cf21 45
7395c052
NZ
46/* Group numbers. */
47enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) };
48bool ofputil_group_from_string(const char *, uint32_t *group_id);
49void ofputil_format_group(uint32_t group_id, struct ds *);
50void ofputil_group_to_string(uint32_t group_id,
51 char namebuf[MAX_GROUP_NAME_LEN + 1],
52 size_t bufsize);
53
eec25dc1
BP
54/* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
55 * to and from IP bitmasks. */
0596e897
BP
56ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
57int ofputil_netmask_to_wcbits(ovs_be32 netmask);
58
27527aa0 59/* Protocols.
85813857
BP
60 *
61 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
62 * a bit extra about the flow match format in use.
27527aa0
BP
63 *
64 * These are arranged from most portable to least portable, or alternatively
85813857
BP
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
68 * within a switch.
27527aa0
BP
69 *
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.
74 */
75enum ofputil_protocol {
85813857
BP
76 /* OpenFlow 1.0 protocols.
77 *
78 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
79 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
80 *
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.
83 */
eb12aa89 84#define OFPUTIL_P_NONE 0
85813857
BP
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)
8621547c 91#define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY)
27527aa0 92
75fa58f8
BP
93 /* OpenFlow 1.1 protocol.
94 *
95 * We only support the standard OpenFlow 1.1 flow format.
96 *
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"
99 * variant. */
100 OFPUTIL_P_OF11_STD = 1 << 4,
101
2e1ae200 102 /* OpenFlow 1.2+ protocols (only one variant each).
85813857 103 *
2e1ae200 104 * These use the standard OpenFlow Extensible Match (OXM) flow format.
85813857 105 *
2e1ae200 106 * OpenFlow 1.2+ always operates with an equivalent of the
85813857
BP
107 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
108 * variant. */
75fa58f8
BP
109 OFPUTIL_P_OF12_OXM = 1 << 5,
110 OFPUTIL_P_OF13_OXM = 1 << 6,
e71bff1b 111#define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM)
44d3732d 112
db0b6c29
JR
113#define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
114 OFPUTIL_P_ANY_OXM)
115
116#define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
117
118#define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
119
120#define OFPUTIL_P_OF12_UP (OFPUTIL_P_ANY_OXM)
121
122#define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM)
123
27527aa0 124 /* All protocols. */
75fa58f8 125#define OFPUTIL_P_ANY ((1 << 7) - 1)
27527aa0
BP
126
127 /* Protocols in which a specific table may be specified in flow_mods. */
7cd90356
BP
128#define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
129 OFPUTIL_P_OF10_NXM_TID | \
75fa58f8 130 OFPUTIL_P_OF11_STD | \
4f13da56 131 OFPUTIL_P_ANY_OXM)
27527aa0
BP
132};
133
134/* Protocols to use for flow dumps, from most to least preferred. */
135extern enum ofputil_protocol ofputil_flow_dump_protocols[];
136extern size_t ofputil_n_flow_dump_protocols;
137
6d2c051a 138enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
4f13da56
BP
139enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
140enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
9e1fd49b 141
27527aa0
BP
142bool ofputil_protocol_is_valid(enum ofputil_protocol);
143enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
144 bool enable);
145enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
146enum ofputil_protocol ofputil_protocol_set_base(
147 enum ofputil_protocol cur, enum ofputil_protocol new_base);
148
149const char *ofputil_protocol_to_string(enum ofputil_protocol);
150char *ofputil_protocols_to_string(enum ofputil_protocol);
151enum ofputil_protocol ofputil_protocols_from_string(const char *);
27527aa0 152
03e1125c
SH
153void ofputil_format_version(struct ds *, enum ofp_version);
154void ofputil_format_version_name(struct ds *, enum ofp_version);
155
156/* A bitmap of version numbers
157 *
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. */
162
163void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
164void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
165
4f13da56
BP
166uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
167enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
168
03e1125c
SH
169/* Bitmap of OpenFlow versions that Open vSwitch supports. */
170#define OFPUTIL_SUPPORTED_VERSIONS \
2e1ae200 171 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
03e1125c
SH
172
173/* Bitmap of OpenFlow versions to enable by default (a subset of
174 * OFPUTIL_SUPPORTED_VERSIONS). */
175#define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
176
177enum ofputil_protocol ofputil_protocols_from_string(const char *s);
178
179const char *ofputil_version_to_string(enum ofp_version ofp_version);
180uint32_t ofputil_versions_from_string(const char *s);
7beaa082 181uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
03e1125c 182
de6c85b0
SH
183bool ofputil_decode_hello(const struct ofp_header *,
184 uint32_t *allowed_versions);
185struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
186
27527aa0
BP
187struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
188 enum ofputil_protocol want,
189 enum ofputil_protocol *next);
190
191/* nx_flow_format */
192struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
193enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
194bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
195const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
196
eec25dc1
BP
197/* Work with ofp10_match. */
198void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
81a76618
BP
199void ofputil_match_from_ofp10_match(const struct ofp10_match *,
200 struct match *);
201void ofputil_normalize_match(struct match *);
202void ofputil_normalize_match_quiet(struct match *);
203void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
d8ae4d67 204
410698cf 205/* Work with ofp11_match. */
81a76618 206enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
36a16881 207 uint16_t *padded_match_len);
81a76618
BP
208enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
209 struct match *);
75fa58f8
BP
210int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *,
211 enum ofputil_protocol);
81a76618 212void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
75fa58f8 213int ofputil_match_typical_len(enum ofputil_protocol);
410698cf 214
36956a7d
BP
215/* dl_type translation between OpenFlow and 'struct flow' format. */
216ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
217ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
218
54834960
EJ
219/* PACKET_IN. */
220bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
221int ofputil_packet_in_format_from_string(const char *);
222const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
3f4a1939
SH
223struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
224 enum nx_packet_in_format);
54834960 225
6c1491fb
BP
226/* NXT_FLOW_MOD_TABLE_ID extension. */
227struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
228
0fb88c18
BP
229/* Protocol-independent flow_mod flags. */
230enum ofputil_flow_mod_flags {
3f517bcd
DB
231 /* Flags that are maintained with a flow as part of its state.
232 *
233 * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */
0fb88c18 234 OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */
3f517bcd
DB
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)
240
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+. */
0fb88c18
BP
245};
246
623e1caf
JP
247/* Protocol-independent flow_mod.
248 *
249 * The handling of cookies across multiple versions of OpenFlow is a bit
23342857 250 * confusing. See DESIGN for the details. */
a9a2da38 251struct ofputil_flow_mod {
3d9c5e58
EJ
252 struct list list_node; /* For queuing flow_mods. */
253
81a76618
BP
254 struct match match;
255 unsigned int priority;
23342857
BP
256
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.
259 *
260 * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
623e1caf
JP
261 ovs_be64 cookie; /* Cookie bits to match. */
262 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
23342857
BP
263
264 /* Cookie changes.
265 *
266 * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie'
267 * should not be UINT64_MAX.
268 *
269 * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
270 *
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.
274 *
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.
278 */
279 ovs_be64 new_cookie; /* New cookie to install or UINT64_MAX. */
280 bool modify_cookie; /* Set cookie of existing flow to 'new_cookie'? */
281
6c1491fb 282 uint8_t table_id;
2e4f5fcf
BP
283 uint16_t command;
284 uint16_t idle_timeout;
285 uint16_t hard_timeout;
286 uint32_t buffer_id;
4e022ec0 287 ofp_port_t out_port;
7395c052 288 uint32_t out_group;
0fb88c18 289 enum ofputil_flow_mod_flags flags;
f25d0cf3
BP
290 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
291 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
2e4f5fcf
BP
292};
293
90bf1e07
BP
294enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
295 const struct ofp_header *,
f25d0cf3
BP
296 enum ofputil_protocol,
297 struct ofpbuf *ofpacts);
a9a2da38 298struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
27527aa0
BP
299 enum ofputil_protocol);
300
27527aa0 301/* Flow stats or aggregate stats request, independent of protocol. */
81d1ea94 302struct ofputil_flow_stats_request {
2e4f5fcf 303 bool aggregate; /* Aggregate results? */
81a76618 304 struct match match;
e729e793
JP
305 ovs_be64 cookie;
306 ovs_be64 cookie_mask;
4e022ec0 307 ofp_port_t out_port;
7395c052 308 uint32_t out_group;
2e4f5fcf
BP
309 uint8_t table_id;
310};
311
90bf1e07
BP
312enum ofperr ofputil_decode_flow_stats_request(
313 struct ofputil_flow_stats_request *, const struct ofp_header *);
2e4f5fcf 314struct ofpbuf *ofputil_encode_flow_stats_request(
27527aa0 315 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
2e4f5fcf 316
27527aa0 317/* Flow stats reply, independent of protocol. */
4ffd1b43 318struct ofputil_flow_stats {
81a76618 319 struct match match;
4ffd1b43
BP
320 ovs_be64 cookie;
321 uint8_t table_id;
322 uint32_t duration_sec;
323 uint32_t duration_nsec;
81a76618 324 uint16_t priority;
4ffd1b43
BP
325 uint16_t idle_timeout;
326 uint16_t hard_timeout;
f27f2134
BP
327 int idle_age; /* Seconds since last packet, -1 if unknown. */
328 int hard_age; /* Seconds since last change, -1 if unknown. */
5e9d0469
BP
329 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
330 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
f25d0cf3
BP
331 struct ofpact *ofpacts;
332 size_t ofpacts_len;
0fb88c18 333 enum ofputil_flow_mod_flags flags;
4ffd1b43
BP
334};
335
336int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
f27f2134 337 struct ofpbuf *msg,
f25d0cf3
BP
338 bool flow_age_extension,
339 struct ofpbuf *ofpacts);
349adfb2
BP
340void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
341 struct list *replies);
4ffd1b43 342
27527aa0 343/* Aggregate stats reply, independent of protocol. */
76c93b22 344struct ofputil_aggregate_stats {
5e9d0469
BP
345 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
346 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
76c93b22
BP
347 uint32_t flow_count;
348};
349
350struct ofpbuf *ofputil_encode_aggregate_stats_reply(
351 const struct ofputil_aggregate_stats *stats,
982697a4
BP
352 const struct ofp_header *request);
353enum ofperr ofputil_decode_aggregate_stats_reply(
354 struct ofputil_aggregate_stats *,
355 const struct ofp_header *reply);
76c93b22 356
27527aa0 357/* Flow removed message, independent of protocol. */
9b045a0c 358struct ofputil_flow_removed {
81a76618
BP
359 struct match match;
360 uint16_t priority;
9b045a0c
BP
361 ovs_be64 cookie;
362 uint8_t reason; /* One of OFPRR_*. */
95216219 363 uint8_t table_id; /* 255 if message didn't include table ID. */
9b045a0c
BP
364 uint32_t duration_sec;
365 uint32_t duration_nsec;
366 uint16_t idle_timeout;
fa2bad0f 367 uint16_t hard_timeout;
5e9d0469
BP
368 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
369 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
9b045a0c
BP
370};
371
90bf1e07
BP
372enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
373 const struct ofp_header *);
588cd7b5 374struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
27527aa0 375 enum ofputil_protocol);
9b045a0c 376
ebb57021
BP
377/* Abstract packet-in message. */
378struct ofputil_packet_in {
22ee3544
BP
379 /* Packet data and metadata.
380 *
381 * To save bandwidth, in some cases a switch may send only the first
382 * several bytes of a packet, indicated by 'packet_len < total_len'. When
383 * the full packet is included, 'packet_len == total_len'. */
3e3252fa 384 const void *packet;
22ee3544
BP
385 size_t packet_len; /* Number of bytes in 'packet'. */
386 size_t total_len; /* Size of packet, pre-truncation. */
387 struct flow_metadata fmd;
ebb57021 388
22ee3544
BP
389 /* Identifies a buffer in the switch that contains the full packet, to
390 * allow the controller to reference it later without having to send the
391 * entire packet back to the switch.
392 *
393 * UINT32_MAX indicates that the packet is not buffered in the switch. A
394 * switch should only use UINT32_MAX when it sends the entire packet. */
ebb57021 395 uint32_t buffer_id;
5d6c3af0 396
22ee3544
BP
397 /* Reason that the packet-in is being sent. */
398 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
399
400 /* Information about the OpenFlow flow that triggered the packet-in.
401 *
402 * A packet-in triggered by a flow table miss has no associated flow. In
d4fa4e79 403 * that case, 'cookie' is UINT64_MAX. */
22ee3544
BP
404 uint8_t table_id; /* OpenFlow table ID. */
405 ovs_be64 cookie; /* Flow's cookie. */
ebb57021
BP
406};
407
f7cc6bd8
BP
408enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
409 const struct ofp_header *);
54834960 410struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
d94240ec 411 enum ofputil_protocol protocol,
54834960 412 enum nx_packet_in_format);
ebb57021 413
5014a89d
BP
414enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
415const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
416 char *reasonbuf,
417 size_t bufsize);
7c1a76a4
BP
418bool ofputil_packet_in_reason_from_string(const char *,
419 enum ofp_packet_in_reason *);
420
751c7785
BP
421/* Abstract packet-out message.
422 *
423 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
424 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
c6a93eb7
BP
425struct ofputil_packet_out {
426 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
427 size_t packet_len; /* Length of packet data in bytes. */
428 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
4e022ec0 429 ofp_port_t in_port; /* Packet's input port. */
f25d0cf3
BP
430 struct ofpact *ofpacts; /* Actions. */
431 size_t ofpacts_len; /* Size of ofpacts in bytes. */
c6a93eb7
BP
432};
433
434enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
982697a4 435 const struct ofp_header *,
f25d0cf3 436 struct ofpbuf *ofpacts);
de0f3156
SH
437struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
438 enum ofputil_protocol protocol);
c6a93eb7 439
9e1fd49b
BP
440enum ofputil_port_config {
441 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
442 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
443 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
444 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
445 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
446 /* OpenFlow 1.0 only. */
447 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
448 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
449 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
450 /* There are no OpenFlow 1.1-only bits. */
451};
452
453enum ofputil_port_state {
454 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
455 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
456 /* OpenFlow 1.1 only. */
457 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
458 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
459 /* OpenFlow 1.0 only. */
460 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
461 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
462 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
463 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
464 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
465};
466
467/* Abstract ofp10_phy_port or ofp11_port. */
468struct ofputil_phy_port {
4e022ec0 469 ofp_port_t port_no;
9e1fd49b
BP
470 uint8_t hw_addr[OFP_ETH_ALEN];
471 char name[OFP_MAX_PORT_NAME_LEN];
472 enum ofputil_port_config config;
473 enum ofputil_port_state state;
474
475 /* NETDEV_F_* feature bitmasks. */
476 enum netdev_features curr; /* Current features. */
477 enum netdev_features advertised; /* Features advertised by the port. */
478 enum netdev_features supported; /* Features supported by the port. */
479 enum netdev_features peer; /* Features advertised by peer. */
480
481 /* Speed. */
482 uint32_t curr_speed; /* Current speed, in kbps. */
483 uint32_t max_speed; /* Maximum supported speed, in kbps. */
484};
485
486enum ofputil_capabilities {
2e1ae200 487 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
9e1fd49b
BP
488 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
489 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
490 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
491 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
492 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
60202987
SH
493
494 /* OpenFlow 1.0 and 1.1 share this capability. */
9e1fd49b
BP
495 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
496
497 /* OpenFlow 1.0 only. */
498 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
499
2e1ae200 500 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
9e1fd49b 501 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
60202987 502
2e1ae200 503 /* OpenFlow 1.2 and 1.3 share this capability */
60202987 504 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
9e1fd49b
BP
505};
506
507enum ofputil_action_bitmap {
508 OFPUTIL_A_OUTPUT = 1 << 0,
509 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
510 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
511 OFPUTIL_A_STRIP_VLAN = 1 << 3,
512 OFPUTIL_A_SET_DL_SRC = 1 << 4,
513 OFPUTIL_A_SET_DL_DST = 1 << 5,
514 OFPUTIL_A_SET_NW_SRC = 1 << 6,
515 OFPUTIL_A_SET_NW_DST = 1 << 7,
516 OFPUTIL_A_SET_NW_ECN = 1 << 8,
517 OFPUTIL_A_SET_NW_TOS = 1 << 9,
518 OFPUTIL_A_SET_TP_SRC = 1 << 10,
519 OFPUTIL_A_SET_TP_DST = 1 << 11,
520 OFPUTIL_A_ENQUEUE = 1 << 12,
521 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
522 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
523 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
524 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
525 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
526 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
527 OFPUTIL_A_PUSH_VLAN = 1 << 19,
528 OFPUTIL_A_POP_VLAN = 1 << 20,
529 OFPUTIL_A_PUSH_MPLS = 1 << 21,
530 OFPUTIL_A_POP_MPLS = 1 << 22,
531 OFPUTIL_A_SET_QUEUE = 1 << 23,
532 OFPUTIL_A_GROUP = 1 << 24,
533 OFPUTIL_A_SET_NW_TTL = 1 << 25,
534 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
78a3fff6 535 OFPUTIL_A_SET_FIELD = 1 << 27,
9e1fd49b
BP
536};
537
538/* Abstract ofp_switch_features. */
539struct ofputil_switch_features {
540 uint64_t datapath_id; /* Datapath unique ID. */
541 uint32_t n_buffers; /* Max packets buffered at once. */
542 uint8_t n_tables; /* Number of tables supported by datapath. */
2e1ae200 543 uint8_t auxiliary_id; /* Identify auxiliary connections */
9e1fd49b
BP
544 enum ofputil_capabilities capabilities;
545 enum ofputil_action_bitmap actions;
546};
547
982697a4 548enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
9e1fd49b
BP
549 struct ofputil_switch_features *,
550 struct ofpbuf *);
9e1fd49b
BP
551
552struct ofpbuf *ofputil_encode_switch_features(
553 const struct ofputil_switch_features *, enum ofputil_protocol,
554 ovs_be32 xid);
555void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
556 struct ofpbuf *);
347b7ac4 557bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
9e1fd49b 558
2be393ed 559/* phy_port helper functions. */
2e3fa633 560int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
2be393ed
JP
561 struct ofputil_phy_port *);
562size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
563
9e1fd49b
BP
564/* Abstract ofp_port_status. */
565struct ofputil_port_status {
566 enum ofp_port_reason reason;
567 struct ofputil_phy_port desc;
568};
569
982697a4 570enum ofperr ofputil_decode_port_status(const struct ofp_header *,
9e1fd49b
BP
571 struct ofputil_port_status *);
572struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
573 enum ofputil_protocol);
574
575/* Abstract ofp_port_mod. */
576struct ofputil_port_mod {
4e022ec0 577 ofp_port_t port_no;
9e1fd49b
BP
578 uint8_t hw_addr[OFP_ETH_ALEN];
579 enum ofputil_port_config config;
580 enum ofputil_port_config mask;
581 enum netdev_features advertise;
582};
583
584enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
585 struct ofputil_port_mod *);
586struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
587 enum ofputil_protocol);
6c038611 588
918f2b82
AZ
589/* Abstract ofp_table_mod. */
590struct ofputil_table_mod {
591 uint8_t table_id; /* ID of the table, 0xff indicates all tables. */
592 uint32_t config;
593};
594
595enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
596 struct ofputil_table_mod *);
597struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
598 enum ofputil_protocol);
599
0445637d 600/* Meter band configuration for all supported band types. */
638a19b0
JR
601struct ofputil_meter_band {
602 uint16_t type;
0445637d 603 uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */
638a19b0
JR
604 uint32_t rate;
605 uint32_t burst_size;
606};
607
608struct ofputil_meter_band_stats {
609 uint64_t packet_count;
610 uint64_t byte_count;
611};
612
613struct ofputil_meter_config {
614 uint32_t meter_id;
615 uint16_t flags;
616 uint16_t n_bands;
617 struct ofputil_meter_band *bands;
618};
619
620/* Abstract ofp_meter_mod. */
621struct ofputil_meter_mod {
622 uint16_t command;
623 struct ofputil_meter_config meter;
624};
625
626struct ofputil_meter_stats {
627 uint32_t meter_id;
628 uint32_t flow_count;
629 uint64_t packet_in_count;
630 uint64_t byte_in_count;
631 uint32_t duration_sec;
632 uint32_t duration_nsec;
633 uint16_t n_bands;
0445637d 634 struct ofputil_meter_band_stats *bands;
638a19b0
JR
635};
636
637struct ofputil_meter_features {
0445637d
JR
638 uint32_t max_meters; /* Maximum number of meters. */
639 uint32_t band_types; /* Can support max 32 band types. */
640 uint32_t capabilities; /* Supported flags. */
638a19b0
JR
641 uint8_t max_bands;
642 uint8_t max_color;
643};
644
645enum ofperr ofputil_decode_meter_mod(const struct ofp_header *,
646 struct ofputil_meter_mod *,
0445637d
JR
647 struct ofpbuf *bands);
648struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version,
638a19b0
JR
649 const struct ofputil_meter_mod *);
650
651void ofputil_decode_meter_features(const struct ofp_header *,
652 struct ofputil_meter_features *);
653struct ofpbuf *ofputil_encode_meter_features_reply(const struct
654 ofputil_meter_features *,
655 const struct ofp_header *
656 request);
657void ofputil_decode_meter_request(const struct ofp_header *,
658 uint32_t *meter_id);
659
660void ofputil_append_meter_config(struct list *replies,
0445637d 661 const struct ofputil_meter_config *);
638a19b0
JR
662
663void ofputil_append_meter_stats(struct list *replies,
0445637d 664 const struct ofputil_meter_stats *);
638a19b0
JR
665
666enum ofputil_meter_request_type {
667 OFPUTIL_METER_FEATURES,
668 OFPUTIL_METER_CONFIG,
669 OFPUTIL_METER_STATS
670};
671
672struct ofpbuf *ofputil_encode_meter_request(enum ofp_version,
673 enum ofputil_meter_request_type,
674 uint32_t meter_id);
675
0445637d
JR
676int ofputil_decode_meter_stats(struct ofpbuf *,
677 struct ofputil_meter_stats *,
638a19b0
JR
678 struct ofpbuf *bands);
679
0445637d
JR
680int ofputil_decode_meter_config(struct ofpbuf *,
681 struct ofputil_meter_config *,
638a19b0
JR
682 struct ofpbuf *bands);
683
0445637d 684/* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
638a19b0
JR
685typedef struct { uint32_t uint32; } ofproto_meter_id;
686
6ea4776b
JR
687/* Abstract ofp_role_request and reply. */
688struct ofputil_role_request {
f4f1ea7e 689 enum ofp12_controller_role role;
6ea4776b 690 bool have_generation_id;
6ea4776b
JR
691 uint64_t generation_id;
692};
693
00467f73
AC
694struct ofputil_role_status {
695 enum ofp12_controller_role role;
696 enum ofp14_controller_role_reason reason;
697 uint64_t generation_id;
698};
699
6ea4776b
JR
700enum ofperr ofputil_decode_role_message(const struct ofp_header *,
701 struct ofputil_role_request *);
702struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
f4f1ea7e 703 const struct ofputil_role_request *);
6ea4776b 704
00467f73
AC
705struct ofpbuf *ofputil_encode_role_status(
706 const struct ofputil_role_status *status,
707 enum ofputil_protocol protocol);
708
709enum ofperr ofputil_decode_role_status(const struct ofp_header *oh,
710 struct ofputil_role_status *rs);
307975da
SH
711/* Abstract table stats.
712 *
713 * For now we use ofp12_table_stats as a superset of the other protocol
714 * versions' table stats. */
715
716struct ofpbuf *ofputil_encode_table_stats_reply(
717 const struct ofp12_table_stats[], int n,
718 const struct ofp_header *request);
719
e8f9a7bb
VG
720/* Queue configuration request. */
721struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version,
722 ofp_port_t port);
723enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *,
724 ofp_port_t *port);
725
726/* Queue configuration reply. */
727struct ofputil_queue_config {
728 uint32_t queue_id;
729
730 /* Each of these optional values is expressed in tenths of a percent.
731 * Values greater than 1000 indicate that the feature is disabled.
732 * UINT16_MAX indicates that the value is omitted. */
733 uint16_t min_rate;
734 uint16_t max_rate;
735};
736
737struct ofpbuf *ofputil_encode_queue_get_config_reply(
738 const struct ofp_header *request);
739void ofputil_append_queue_get_config_reply(
740 struct ofpbuf *reply, const struct ofputil_queue_config *);
741
742enum ofperr ofputil_decode_queue_get_config_reply(struct ofpbuf *reply,
743 ofp_port_t *);
744int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply,
745 struct ofputil_queue_config *);
746
747
2b07c8b1
BP
748/* Abstract nx_flow_monitor_request. */
749struct ofputil_flow_monitor_request {
750 uint32_t id;
751 enum nx_flow_monitor_flags flags;
4e022ec0 752 ofp_port_t out_port;
2b07c8b1 753 uint8_t table_id;
81a76618 754 struct match match;
2b07c8b1
BP
755};
756
757int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
758 struct ofpbuf *msg);
759void ofputil_append_flow_monitor_request(
760 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
761
762/* Abstract nx_flow_update. */
763struct ofputil_flow_update {
764 enum nx_flow_update_event event;
765
766 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
767 enum ofp_flow_removed_reason reason;
768 uint16_t idle_timeout;
769 uint16_t hard_timeout;
770 uint8_t table_id;
771 ovs_be64 cookie;
81a76618
BP
772 struct match *match;
773 uint16_t priority;
2b07c8b1
BP
774 struct ofpact *ofpacts;
775 size_t ofpacts_len;
776
777 /* Used only for NXFME_ABBREV. */
778 ovs_be32 xid;
779};
780
781int ofputil_decode_flow_update(struct ofputil_flow_update *,
782 struct ofpbuf *msg, struct ofpbuf *ofpacts);
783void ofputil_start_flow_update(struct list *replies);
784void ofputil_append_flow_update(const struct ofputil_flow_update *,
785 struct list *replies);
786
787/* Abstract nx_flow_monitor_cancel. */
788uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
789struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
790
982697a4 791/* Encoding OpenFlow stats messages. */
2e3fa633 792void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
2be393ed
JP
793 const struct ofputil_phy_port *pp,
794 struct list *replies);
795
982697a4 796/* Encoding simple OpenFlow messages. */
1a126c0c 797struct ofpbuf *make_echo_request(enum ofp_version);
fa37b408 798struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
7257b535 799
a0ae0b6e 800struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
efb80167 801
7257b535
BP
802const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
803bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
2be393ed 804
9aee0764
BP
805\f
806/* Actions. */
807
e23ae585
BP
808/* The type of an action.
809 *
08f94c0e 810 * For each implemented OFPAT10_* and NXAST_* action type, there is a
e23ae585
BP
811 * corresponding constant prefixed with OFPUTIL_, e.g.:
812 *
08f94c0e
BP
813 * OFPUTIL_OFPAT10_OUTPUT
814 * OFPUTIL_OFPAT10_SET_VLAN_VID
815 * OFPUTIL_OFPAT10_SET_VLAN_PCP
816 * OFPUTIL_OFPAT10_STRIP_VLAN
817 * OFPUTIL_OFPAT10_SET_DL_SRC
818 * OFPUTIL_OFPAT10_SET_DL_DST
819 * OFPUTIL_OFPAT10_SET_NW_SRC
820 * OFPUTIL_OFPAT10_SET_NW_DST
821 * OFPUTIL_OFPAT10_SET_NW_TOS
822 * OFPUTIL_OFPAT10_SET_TP_SRC
823 * OFPUTIL_OFPAT10_SET_TP_DST
824 * OFPUTIL_OFPAT10_ENQUEUE
e23ae585
BP
825 * OFPUTIL_NXAST_RESUBMIT
826 * OFPUTIL_NXAST_SET_TUNNEL
4cceacb9 827 * OFPUTIL_NXAST_SET_METADATA
e23ae585
BP
828 * OFPUTIL_NXAST_SET_QUEUE
829 * OFPUTIL_NXAST_POP_QUEUE
830 * OFPUTIL_NXAST_REG_MOVE
831 * OFPUTIL_NXAST_REG_LOAD
832 * OFPUTIL_NXAST_NOTE
833 * OFPUTIL_NXAST_SET_TUNNEL64
834 * OFPUTIL_NXAST_MULTIPATH
e23ae585
BP
835 * OFPUTIL_NXAST_BUNDLE
836 * OFPUTIL_NXAST_BUNDLE_LOAD
837 * OFPUTIL_NXAST_RESUBMIT_TABLE
838 * OFPUTIL_NXAST_OUTPUT_REG
0e553d9c
BP
839 * OFPUTIL_NXAST_LEARN
840 * OFPUTIL_NXAST_DEC_TTL
841 * OFPUTIL_NXAST_FIN_TIMEOUT
e23ae585
BP
842 *
843 * (The above list helps developers who want to "grep" for these definitions.)
844 */
f25d0cf3 845enum OVS_PACKED_ENUM ofputil_action_code {
690a61c5 846 OFPUTIL_ACTION_INVALID,
3ddcaf2d
BP
847#define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
848#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
849#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
e23ae585
BP
850#include "ofp-util.def"
851};
852
853/* The number of values of "enum ofputil_action_code". */
854enum {
3ddcaf2d
BP
855#define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
856#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
857#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
690a61c5 858 OFPUTIL_N_ACTIONS = 1
e23ae585 859#include "ofp-util.def"
38f2e360
BP
860};
861
e23ae585 862int ofputil_action_code_from_name(const char *);
e3f8f887 863const char * ofputil_action_name_from_code(enum ofputil_action_code code);
e23ae585 864
93996add
BP
865void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
866
867/* For each OpenFlow action <ENUM> that has a corresponding action structure
868 * struct <STRUCT>, this defines two functions:
869 *
870 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
871 *
872 * Initializes the parts of 'action' that identify it as having type <ENUM>
873 * and length 'sizeof *action' and zeros the rest. For actions that have
874 * variable length, the length used and cleared is that of struct <STRUCT>.
875 *
876 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
877 *
878 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
879 * initializes it with ofputil_init_<ENUM>(), and returns it.
880 */
08f94c0e 881#define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
93996add
BP
882 void ofputil_init_##ENUM(struct STRUCT *); \
883 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
3ddcaf2d 884#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
d01c980f
BP
885 void ofputil_init_##ENUM(struct STRUCT *); \
886 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
93996add
BP
887#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
888 void ofputil_init_##ENUM(struct STRUCT *); \
889 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
890#include "ofp-util.def"
891
9aee0764 892#define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
fa37b408 893
dbba996b 894bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
3052b0c5 895
90bf1e07
BP
896enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
897 union ofp_action **, size_t *);
18ddadc2
BP
898
899bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
900 const union ofp_action *b, size_t n_b);
901union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
26c112c2 902
0ff22822
BP
903/* Handy utility for parsing flows and actions. */
904bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
905
f8e4867e 906struct ofputil_port_stats {
4e022ec0 907 ofp_port_t port_no;
f8e4867e 908 struct netdev_stats stats;
65e0be10
BP
909 uint32_t duration_sec; /* UINT32_MAX if unknown. */
910 uint32_t duration_nsec;
f8e4867e
SH
911};
912
913struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
4e022ec0 914 ofp_port_t port);
f8e4867e
SH
915void ofputil_append_port_stat(struct list *replies,
916 const struct ofputil_port_stats *ops);
917size_t ofputil_count_port_stats(const struct ofp_header *);
918int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
919enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
4e022ec0 920 ofp_port_t *ofp10_port);
64626975
SH
921
922struct ofputil_queue_stats_request {
4e022ec0 923 ofp_port_t port_no; /* OFPP_ANY means "all ports". */
64626975
SH
924 uint32_t queue_id;
925};
926
927enum ofperr
928ofputil_decode_queue_stats_request(const struct ofp_header *request,
929 struct ofputil_queue_stats_request *oqsr);
930struct ofpbuf *
931ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
932 const struct ofputil_queue_stats_request *oqsr);
933
934struct ofputil_queue_stats {
4e022ec0 935 ofp_port_t port_no;
64626975 936 uint32_t queue_id;
6dc34a0d
BP
937
938 /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
939 uint64_t tx_bytes;
940 uint64_t tx_packets;
941 uint64_t tx_errors;
942
943 /* UINT32_MAX if unknown. */
944 uint32_t duration_sec;
945 uint32_t duration_nsec;
64626975
SH
946};
947
948size_t ofputil_count_queue_stats(const struct ofp_header *);
949int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
950void ofputil_append_queue_stat(struct list *replies,
951 const struct ofputil_queue_stats *oqs);
952
7395c052
NZ
953/* Bucket for use in groups. */
954struct ofputil_bucket {
955 struct list list_node;
956 uint16_t weight; /* Relative weight, for "select" groups. */
957 ofp_port_t watch_port; /* Port whose state affects whether this bucket
958 * is live. Only required for fast failover
959 * groups. */
960 uint32_t watch_group; /* Group whose state affects whether this
961 * bucket is live. Only required for fast
962 * failover groups. */
963 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
964 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
965};
966
967/* Protocol-independent group_mod. */
968struct ofputil_group_mod {
969 uint16_t command; /* One of OFPGC11_*. */
970 uint8_t type; /* One of OFPGT11_*. */
971 uint32_t group_id; /* Group identifier. */
972 struct list buckets; /* Contains "struct ofputil_bucket"s. */
973};
974
975struct bucket_counter {
976 uint64_t packet_count; /* Number of packets processed by bucket. */
977 uint64_t byte_count; /* Number of bytes processed by bucket. */
978};
979
980/* Group stats reply, independent of protocol. */
981struct ofputil_group_stats {
982 uint32_t group_id; /* Group identifier. */
983 uint32_t ref_count;
984 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
985 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
986 uint32_t duration_sec; /* UINT32_MAX if unknown. */
987 uint32_t duration_nsec;
988 uint32_t n_buckets;
646b2a9c 989 struct bucket_counter *bucket_stats;
7395c052
NZ
990};
991
992/* Group features reply, independent of protocol. */
993struct ofputil_group_features {
994 uint32_t types; /* Bitmap of OFPGT_* values supported. */
995 uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */
996 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
997 uint32_t actions[4]; /* Bitmaps of OFPAT_* that are supported. */
998};
999
1000/* Group desc reply, independent of protocol. */
1001struct ofputil_group_desc {
1002 uint8_t type; /* One of OFPGT_*. */
1003 uint32_t group_id; /* Group identifier. */
1004 struct list buckets; /* Contains "struct ofputil_bucket"s. */
1005};
1006
1007void ofputil_bucket_list_destroy(struct list *buckets);
1008
1009struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version,
1010 uint32_t group_id);
1011enum ofperr ofputil_decode_group_stats_request(
1012 const struct ofp_header *request, uint32_t *group_id);
1013void ofputil_append_group_stats(struct list *replies,
1014 const struct ofputil_group_stats *);
1015struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version);
1016struct ofpbuf *ofputil_encode_group_features_reply(
1017 const struct ofputil_group_features *, const struct ofp_header *request);
1018void ofputil_decode_group_features_reply(const struct ofp_header *,
1019 struct ofputil_group_features *);
1020struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version,
1021 const struct ofputil_group_mod *gm);
1022
1023enum ofperr ofputil_decode_group_mod(const struct ofp_header *,
1024 struct ofputil_group_mod *);
1025
1026int ofputil_decode_group_stats_reply(struct ofpbuf *,
1027 struct ofputil_group_stats *);
1028
1029int ofputil_decode_group_desc_reply(struct ofputil_group_desc *,
a7a2d006 1030 struct ofpbuf *, enum ofp_version);
7395c052
NZ
1031
1032void ofputil_append_group_desc_reply(const struct ofputil_group_desc *,
1033 struct list *buckets,
1034 struct list *replies);
1035struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version);
1036
fa37b408 1037#endif /* ofp-util.h */