]> git.proxmox.com Git - mirror_ovs.git/blame - lib/ofp-util.h
ofproto: Implement OFPT_QUEUE_GET_CONFIG_REQUEST for OFPP_ANY in OF1.1+.
[mirror_ovs.git] / lib / ofp-util.h
CommitLineData
fa37b408 1/*
7ac27a04 2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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>
5deff5aa 23#include "bitmap.h"
f25d0cf3 24#include "compiler.h"
fa37b408 25#include "flow.h"
13751fd8 26#include "list.h"
81a76618 27#include "match.h"
abadfcb0 28#include "meta-flow.h"
6c038611 29#include "netdev.h"
bc65c25a 30#include "openflow/netronome-ext.h"
492f7572 31#include "openflow/nicira-ext.h"
44381c1b 32#include "openvswitch/types.h"
5014a89d 33#include "type-props.h"
fa37b408
BP
34
35struct ofpbuf;
e45e72f1 36union ofp_action;
b2dd70be 37struct ofpact_set_field;
fa37b408 38
39dc9082 39/* Port numbers. */
4e022ec0
AW
40enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
41 ofp_port_t *ofp10_port);
42ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);
7b7503ea 43
4e022ec0
AW
44bool ofputil_port_from_string(const char *, ofp_port_t *portp);
45void ofputil_format_port(ofp_port_t port, struct ds *);
28b11432
BP
46void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
47 size_t bufsize);
d1e2cf21 48
7395c052
NZ
49/* Group numbers. */
50enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) };
51bool ofputil_group_from_string(const char *, uint32_t *group_id);
52void ofputil_format_group(uint32_t group_id, struct ds *);
53void ofputil_group_to_string(uint32_t group_id,
54 char namebuf[MAX_GROUP_NAME_LEN + 1],
55 size_t bufsize);
56
eec25dc1
BP
57/* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
58 * to and from IP bitmasks. */
0596e897
BP
59ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
60int ofputil_netmask_to_wcbits(ovs_be32 netmask);
61
27527aa0 62/* Protocols.
85813857
BP
63 *
64 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
65 * a bit extra about the flow match format in use.
27527aa0
BP
66 *
67 * These are arranged from most portable to least portable, or alternatively
85813857
BP
68 * from least powerful to most powerful. Protocols earlier on the list are
69 * more likely to be understood for the purpose of making requests, but
70 * protocol later on the list are more likely to accurately describe a flow
71 * within a switch.
27527aa0
BP
72 *
73 * On any given OpenFlow connection, a single protocol is in effect at any
74 * given time. These values use separate bits only because that makes it easy
75 * to test whether a particular protocol is within a given set of protocols and
76 * to implement set union and intersection.
77 */
78enum ofputil_protocol {
85813857
BP
79 /* OpenFlow 1.0 protocols.
80 *
81 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
82 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
83 *
84 * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
85 * extension has been enabled. The other protocols have it disabled.
86 */
eb12aa89 87#define OFPUTIL_P_NONE 0
85813857
BP
88 OFPUTIL_P_OF10_STD = 1 << 0,
89 OFPUTIL_P_OF10_STD_TID = 1 << 1,
90 OFPUTIL_P_OF10_NXM = 1 << 2,
91 OFPUTIL_P_OF10_NXM_TID = 1 << 3,
92#define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
93#define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
8621547c 94#define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY)
27527aa0 95
75fa58f8
BP
96 /* OpenFlow 1.1 protocol.
97 *
98 * We only support the standard OpenFlow 1.1 flow format.
99 *
100 * OpenFlow 1.1 always operates with an equivalent of the
101 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
102 * variant. */
103 OFPUTIL_P_OF11_STD = 1 << 4,
104
2e1ae200 105 /* OpenFlow 1.2+ protocols (only one variant each).
85813857 106 *
2e1ae200 107 * These use the standard OpenFlow Extensible Match (OXM) flow format.
85813857 108 *
2e1ae200 109 * OpenFlow 1.2+ always operates with an equivalent of the
85813857
BP
110 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
111 * variant. */
75fa58f8
BP
112 OFPUTIL_P_OF12_OXM = 1 << 5,
113 OFPUTIL_P_OF13_OXM = 1 << 6,
c37c0382 114 OFPUTIL_P_OF14_OXM = 1 << 7,
42dccab5
BP
115 OFPUTIL_P_OF15_OXM = 1 << 8,
116#define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | \
117 OFPUTIL_P_OF13_OXM | \
118 OFPUTIL_P_OF14_OXM | \
119 OFPUTIL_P_OF15_OXM)
44d3732d 120
db0b6c29
JR
121#define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
122 OFPUTIL_P_ANY_OXM)
123
124#define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
125
126#define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
127
ab12d917
BP
128#define OFPUTIL_P_OF12_UP (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_UP)
129#define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM | OFPUTIL_P_OF14_UP)
42dccab5
BP
130#define OFPUTIL_P_OF14_UP (OFPUTIL_P_OF14_OXM | OFPUTIL_P_OF15_UP)
131#define OFPUTIL_P_OF15_UP OFPUTIL_P_OF15_OXM
c37c0382 132
27527aa0 133 /* All protocols. */
42dccab5 134#define OFPUTIL_P_ANY ((1 << 9) - 1)
27527aa0
BP
135
136 /* Protocols in which a specific table may be specified in flow_mods. */
7cd90356
BP
137#define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
138 OFPUTIL_P_OF10_NXM_TID | \
75fa58f8 139 OFPUTIL_P_OF11_STD | \
4f13da56 140 OFPUTIL_P_ANY_OXM)
27527aa0
BP
141};
142
d18cc1ee
AA
143 /* Valid value of mask for asynchronous messages. */
144#define MAXIMUM_MASK_PACKET_IN ((1 << OFPR_N_REASONS) - 1)
145
146#define MAXIMUM_MASK_FLOW_REMOVED ((1 << OVS_OFPRR_NONE) - 1)
147
148#define MAXIMUM_MASK_PORT_STATUS ((1 << OFPPR_N_REASONS) - 1)
149
150#define MAXIMUM_MASK_ROLE_STATUS ((1 << OFPCRR_N_REASONS) - 1)
151
152#define MINIMUM_MASK_TABLE_STATUS (1 << OFPTR_VACANCY_DOWN)
153
154#define MAXIMUM_MASK_TABLE_STATUS ((1 << OFPTR_N_REASONS) - \
155 MINIMUM_MASK_TABLE_STATUS)
156
157#define MAXIMUM_MASK_REQUESTFORWARD ((1 << OFPRFR_N_REASONS) - 1)
158
27527aa0
BP
159/* Protocols to use for flow dumps, from most to least preferred. */
160extern enum ofputil_protocol ofputil_flow_dump_protocols[];
161extern size_t ofputil_n_flow_dump_protocols;
162
6d2c051a 163enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
4f13da56
BP
164enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
165enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
9e1fd49b 166
27527aa0
BP
167bool ofputil_protocol_is_valid(enum ofputil_protocol);
168enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
169 bool enable);
170enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
171enum ofputil_protocol ofputil_protocol_set_base(
172 enum ofputil_protocol cur, enum ofputil_protocol new_base);
173
174const char *ofputil_protocol_to_string(enum ofputil_protocol);
175char *ofputil_protocols_to_string(enum ofputil_protocol);
176enum ofputil_protocol ofputil_protocols_from_string(const char *);
27527aa0 177
03e1125c
SH
178void ofputil_format_version(struct ds *, enum ofp_version);
179void ofputil_format_version_name(struct ds *, enum ofp_version);
180
181/* A bitmap of version numbers
182 *
183 * Bit offsets correspond to ofp_version numbers which in turn correspond to
0746a84f
BP
184 * wire-protocol numbers for OpenFlow versions, e.g. (1u << OFP11_VERSION)
185 * is the mask for OpenFlow 1.1. If the bit for a version is set then it is
03e1125c
SH
186 * allowed, otherwise it is disallowed. */
187
188void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
189void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
190
9d84066c
BP
191enum ofp_version ofputil_version_from_string(const char *s);
192
4f13da56
BP
193uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
194enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
195
6dc53744
BP
196/* Bitmaps of OpenFlow versions that Open vSwitch supports, and that it enables
197 * by default. When Open vSwitch has experimental or incomplete support for
198 * newer versions of OpenFlow, those versions should not be supported by
199 * default and thus should be omitted from the latter bitmap. */
200#define OFPUTIL_SUPPORTED_VERSIONS ((1u << OFP10_VERSION) | \
201 (1u << OFP11_VERSION) | \
202 (1u << OFP12_VERSION) | \
203 (1u << OFP13_VERSION))
204#define OFPUTIL_DEFAULT_VERSIONS OFPUTIL_SUPPORTED_VERSIONS
03e1125c
SH
205
206enum ofputil_protocol ofputil_protocols_from_string(const char *s);
207
208const char *ofputil_version_to_string(enum ofp_version ofp_version);
209uint32_t ofputil_versions_from_string(const char *s);
7beaa082 210uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
03e1125c 211
de6c85b0
SH
212bool ofputil_decode_hello(const struct ofp_header *,
213 uint32_t *allowed_versions);
214struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
215
27527aa0
BP
216struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
217 enum ofputil_protocol want,
218 enum ofputil_protocol *next);
219
220/* nx_flow_format */
221struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
222enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
223bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
224const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
225
eec25dc1
BP
226/* Work with ofp10_match. */
227void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
81a76618
BP
228void ofputil_match_from_ofp10_match(const struct ofp10_match *,
229 struct match *);
230void ofputil_normalize_match(struct match *);
231void ofputil_normalize_match_quiet(struct match *);
232void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
d8ae4d67 233
410698cf 234/* Work with ofp11_match. */
81a76618 235enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
36a16881 236 uint16_t *padded_match_len);
bc65c25a
SH
237enum ofperr ofputil_pull_ofp11_mask(struct ofpbuf *, struct match *,
238 struct mf_bitmap *bm);
81a76618
BP
239enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
240 struct match *);
75fa58f8
BP
241int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *,
242 enum ofputil_protocol);
81a76618 243void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
75fa58f8 244int ofputil_match_typical_len(enum ofputil_protocol);
410698cf 245
36956a7d
BP
246/* dl_type translation between OpenFlow and 'struct flow' format. */
247ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
248ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
249
54834960
EJ
250/* PACKET_IN. */
251bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
252int ofputil_packet_in_format_from_string(const char *);
253const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
3f4a1939
SH
254struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
255 enum nx_packet_in_format);
54834960 256
6c1491fb
BP
257/* NXT_FLOW_MOD_TABLE_ID extension. */
258struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
259
0fb88c18
BP
260/* Protocol-independent flow_mod flags. */
261enum ofputil_flow_mod_flags {
3f517bcd
DB
262 /* Flags that are maintained with a flow as part of its state.
263 *
264 * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */
0fb88c18 265 OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */
3f517bcd
DB
266 OFPUTIL_FF_NO_PKT_COUNTS = 1 << 1, /* OpenFlow 1.3+. */
267 OFPUTIL_FF_NO_BYT_COUNTS = 1 << 2, /* OpenFlow 1.3+. */
3f517bcd 268
13327b8e
BP
269 /* These flags primarily affects flow_mod behavior. They are not
270 * particularly useful as part of flow state. We include them in flow
271 * state only because OpenFlow implies that they should be. */
3f517bcd 272 OFPUTIL_FF_CHECK_OVERLAP = 1 << 3, /* All versions. */
13327b8e
BP
273 OFPUTIL_FF_RESET_COUNTS = 1 << 4, /* OpenFlow 1.2+. */
274
275 /* Not supported by OVS. */
276 OFPUTIL_FF_EMERG = 1 << 5, /* OpenFlow 1.0 only. */
277
278 /* The set of flags maintained as part of a flow table entry. */
279#define OFPUTIL_FF_STATE (OFPUTIL_FF_SEND_FLOW_REM \
280 | OFPUTIL_FF_NO_PKT_COUNTS \
281 | OFPUTIL_FF_NO_BYT_COUNTS \
282 | OFPUTIL_FF_CHECK_OVERLAP \
283 | OFPUTIL_FF_RESET_COUNTS)
adcf00ba
AZ
284
285 /* Flags that are only set by OVS for its internal use. Cannot be set via
286 * OpenFlow. */
287 OFPUTIL_FF_HIDDEN_FIELDS = 1 << 6, /* Allow hidden match fields to be
288 set or modified. */
289 OFPUTIL_FF_NO_READONLY = 1 << 7, /* Allow rules within read only tables
290 to be modified */
0fb88c18
BP
291};
292
623e1caf
JP
293/* Protocol-independent flow_mod.
294 *
295 * The handling of cookies across multiple versions of OpenFlow is a bit
23342857 296 * confusing. See DESIGN for the details. */
a9a2da38 297struct ofputil_flow_mod {
ca6ba700 298 struct ovs_list list_node; /* For queuing flow_mods. */
3d9c5e58 299
81a76618 300 struct match match;
eb391b76 301 int priority;
23342857
BP
302
303 /* Cookie matching. The flow_mod affects only flows that have cookies that
304 * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits.
305 *
306 * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
623e1caf
JP
307 ovs_be64 cookie; /* Cookie bits to match. */
308 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
23342857
BP
309
310 /* Cookie changes.
311 *
312 * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie'
313 * should not be UINT64_MAX.
314 *
315 * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
316 *
317 * - If one or more matching flows exist and 'modify_cookie' is true,
318 * then the flow_mod changes the existing flows' cookies to
319 * 'new_cookie'. 'new_cookie' should not be UINT64_MAX.
320 *
321 * - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and
322 * 'cookie_mask' is 0, then the flow_mod adds a new flow with
323 * 'new_cookie' as its cookie.
324 */
325 ovs_be64 new_cookie; /* New cookie to install or UINT64_MAX. */
326 bool modify_cookie; /* Set cookie of existing flow to 'new_cookie'? */
327
6c1491fb 328 uint8_t table_id;
2e4f5fcf
BP
329 uint16_t command;
330 uint16_t idle_timeout;
331 uint16_t hard_timeout;
332 uint32_t buffer_id;
4e022ec0 333 ofp_port_t out_port;
7395c052 334 uint32_t out_group;
0fb88c18 335 enum ofputil_flow_mod_flags flags;
ca26eb44 336 uint16_t importance; /* Eviction precedence. */
dc723c44
JR
337 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
338 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
cc40d06b
SH
339
340 /* Reason for delete; ignored for non-delete commands */
341 enum ofp_flow_removed_reason delete_reason;
2e4f5fcf
BP
342};
343
90bf1e07
BP
344enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
345 const struct ofp_header *,
f25d0cf3 346 enum ofputil_protocol,
7e9f8266
BP
347 struct ofpbuf *ofpacts,
348 ofp_port_t max_port,
349 uint8_t max_table);
a9a2da38 350struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
27527aa0
BP
351 enum ofputil_protocol);
352
27527aa0 353/* Flow stats or aggregate stats request, independent of protocol. */
81d1ea94 354struct ofputil_flow_stats_request {
2e4f5fcf 355 bool aggregate; /* Aggregate results? */
81a76618 356 struct match match;
e729e793
JP
357 ovs_be64 cookie;
358 ovs_be64 cookie_mask;
4e022ec0 359 ofp_port_t out_port;
7395c052 360 uint32_t out_group;
2e4f5fcf
BP
361 uint8_t table_id;
362};
363
90bf1e07
BP
364enum ofperr ofputil_decode_flow_stats_request(
365 struct ofputil_flow_stats_request *, const struct ofp_header *);
2e4f5fcf 366struct ofpbuf *ofputil_encode_flow_stats_request(
27527aa0 367 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
2e4f5fcf 368
27527aa0 369/* Flow stats reply, independent of protocol. */
4ffd1b43 370struct ofputil_flow_stats {
81a76618 371 struct match match;
4ffd1b43
BP
372 ovs_be64 cookie;
373 uint8_t table_id;
81a76618 374 uint16_t priority;
4ffd1b43
BP
375 uint16_t idle_timeout;
376 uint16_t hard_timeout;
e0822031
HS
377 uint32_t duration_sec;
378 uint32_t duration_nsec;
f27f2134
BP
379 int idle_age; /* Seconds since last packet, -1 if unknown. */
380 int hard_age; /* Seconds since last change, -1 if unknown. */
5e9d0469
BP
381 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
382 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
dc723c44 383 const struct ofpact *ofpacts;
f25d0cf3 384 size_t ofpacts_len;
0fb88c18 385 enum ofputil_flow_mod_flags flags;
ca26eb44 386 uint16_t importance; /* Eviction precedence. */
4ffd1b43
BP
387};
388
389int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
f27f2134 390 struct ofpbuf *msg,
f25d0cf3
BP
391 bool flow_age_extension,
392 struct ofpbuf *ofpacts);
349adfb2 393void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
ca6ba700 394 struct ovs_list *replies);
4ffd1b43 395
27527aa0 396/* Aggregate stats reply, independent of protocol. */
76c93b22 397struct ofputil_aggregate_stats {
5e9d0469
BP
398 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
399 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
76c93b22
BP
400 uint32_t flow_count;
401};
402
403struct ofpbuf *ofputil_encode_aggregate_stats_reply(
404 const struct ofputil_aggregate_stats *stats,
982697a4
BP
405 const struct ofp_header *request);
406enum ofperr ofputil_decode_aggregate_stats_reply(
407 struct ofputil_aggregate_stats *,
408 const struct ofp_header *reply);
76c93b22 409
27527aa0 410/* Flow removed message, independent of protocol. */
9b045a0c 411struct ofputil_flow_removed {
81a76618 412 struct match match;
9b045a0c 413 ovs_be64 cookie;
e0822031 414 uint16_t priority;
9b045a0c 415 uint8_t reason; /* One of OFPRR_*. */
95216219 416 uint8_t table_id; /* 255 if message didn't include table ID. */
9b045a0c
BP
417 uint32_t duration_sec;
418 uint32_t duration_nsec;
419 uint16_t idle_timeout;
fa2bad0f 420 uint16_t hard_timeout;
5e9d0469
BP
421 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
422 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
9b045a0c
BP
423};
424
90bf1e07
BP
425enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
426 const struct ofp_header *);
588cd7b5 427struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
27527aa0 428 enum ofputil_protocol);
9b045a0c 429
ebb57021
BP
430/* Abstract packet-in message. */
431struct ofputil_packet_in {
22ee3544
BP
432 /* Packet data and metadata.
433 *
434 * To save bandwidth, in some cases a switch may send only the first
435 * several bytes of a packet, indicated by 'packet_len < total_len'. When
436 * the full packet is included, 'packet_len == total_len'. */
3e3252fa 437 const void *packet;
22ee3544
BP
438 size_t packet_len; /* Number of bytes in 'packet'. */
439 size_t total_len; /* Size of packet, pre-truncation. */
50dcbd8e 440 struct match flow_metadata;
ebb57021 441
22ee3544
BP
442 /* Identifies a buffer in the switch that contains the full packet, to
443 * allow the controller to reference it later without having to send the
444 * entire packet back to the switch.
445 *
446 * UINT32_MAX indicates that the packet is not buffered in the switch. A
447 * switch should only use UINT32_MAX when it sends the entire packet. */
ebb57021 448 uint32_t buffer_id;
5d6c3af0 449
22ee3544
BP
450 /* Reason that the packet-in is being sent. */
451 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
452
453 /* Information about the OpenFlow flow that triggered the packet-in.
454 *
455 * A packet-in triggered by a flow table miss has no associated flow. In
d4fa4e79 456 * that case, 'cookie' is UINT64_MAX. */
22ee3544
BP
457 uint8_t table_id; /* OpenFlow table ID. */
458 ovs_be64 cookie; /* Flow's cookie. */
ebb57021
BP
459};
460
f7cc6bd8
BP
461enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
462 const struct ofp_header *);
54834960 463struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
d94240ec 464 enum ofputil_protocol protocol,
54834960 465 enum nx_packet_in_format);
ebb57021 466
5014a89d
BP
467enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
468const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
469 char *reasonbuf,
470 size_t bufsize);
7c1a76a4
BP
471bool ofputil_packet_in_reason_from_string(const char *,
472 enum ofp_packet_in_reason *);
473
751c7785
BP
474/* Abstract packet-out message.
475 *
476 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
477 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
c6a93eb7
BP
478struct ofputil_packet_out {
479 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
480 size_t packet_len; /* Length of packet data in bytes. */
481 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
4e022ec0 482 ofp_port_t in_port; /* Packet's input port. */
f25d0cf3
BP
483 struct ofpact *ofpacts; /* Actions. */
484 size_t ofpacts_len; /* Size of ofpacts in bytes. */
c6a93eb7
BP
485};
486
487enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
982697a4 488 const struct ofp_header *,
f25d0cf3 489 struct ofpbuf *ofpacts);
de0f3156
SH
490struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
491 enum ofputil_protocol protocol);
c6a93eb7 492
9e1fd49b
BP
493enum ofputil_port_config {
494 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
495 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
496 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
497 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
498 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
499 /* OpenFlow 1.0 only. */
500 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
501 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
502 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
503 /* There are no OpenFlow 1.1-only bits. */
504};
505
506enum ofputil_port_state {
507 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
508 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
509 /* OpenFlow 1.1 only. */
510 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
511 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
512 /* OpenFlow 1.0 only. */
513 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
514 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
515 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
516 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
517 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
518};
519
520/* Abstract ofp10_phy_port or ofp11_port. */
521struct ofputil_phy_port {
4e022ec0 522 ofp_port_t port_no;
74ff3298 523 struct eth_addr hw_addr;
9e1fd49b
BP
524 char name[OFP_MAX_PORT_NAME_LEN];
525 enum ofputil_port_config config;
526 enum ofputil_port_state state;
527
528 /* NETDEV_F_* feature bitmasks. */
529 enum netdev_features curr; /* Current features. */
530 enum netdev_features advertised; /* Features advertised by the port. */
531 enum netdev_features supported; /* Features supported by the port. */
532 enum netdev_features peer; /* Features advertised by peer. */
533
534 /* Speed. */
535 uint32_t curr_speed; /* Current speed, in kbps. */
536 uint32_t max_speed; /* Maximum supported speed, in kbps. */
537};
538
539enum ofputil_capabilities {
2e1ae200 540 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
9e1fd49b
BP
541 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
542 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
543 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
544 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
545 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
60202987
SH
546
547 /* OpenFlow 1.0 and 1.1 share this capability. */
9e1fd49b
BP
548 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
549
550 /* OpenFlow 1.0 only. */
551 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
552
2e1ae200 553 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
9e1fd49b 554 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
60202987 555
2e1ae200 556 /* OpenFlow 1.2 and 1.3 share this capability */
60202987 557 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
9e1fd49b
BP
558};
559
9e1fd49b
BP
560/* Abstract ofp_switch_features. */
561struct ofputil_switch_features {
562 uint64_t datapath_id; /* Datapath unique ID. */
563 uint32_t n_buffers; /* Max packets buffered at once. */
564 uint8_t n_tables; /* Number of tables supported by datapath. */
2e1ae200 565 uint8_t auxiliary_id; /* Identify auxiliary connections */
9e1fd49b 566 enum ofputil_capabilities capabilities;
08d1e234 567 uint64_t ofpacts; /* Bitmap of OFPACT_* bits. */
9e1fd49b
BP
568};
569
982697a4 570enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
9e1fd49b
BP
571 struct ofputil_switch_features *,
572 struct ofpbuf *);
9e1fd49b
BP
573
574struct ofpbuf *ofputil_encode_switch_features(
575 const struct ofputil_switch_features *, enum ofputil_protocol,
576 ovs_be32 xid);
577void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
578 struct ofpbuf *);
fca6d553 579bool ofputil_switch_features_has_ports(struct ofpbuf *b);
9e1fd49b 580
2be393ed 581/* phy_port helper functions. */
2e3fa633 582int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
2be393ed 583 struct ofputil_phy_port *);
2be393ed 584
9e1fd49b
BP
585/* Abstract ofp_port_status. */
586struct ofputil_port_status {
587 enum ofp_port_reason reason;
588 struct ofputil_phy_port desc;
589};
590
982697a4 591enum ofperr ofputil_decode_port_status(const struct ofp_header *,
9e1fd49b
BP
592 struct ofputil_port_status *);
593struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
594 enum ofputil_protocol);
595
596/* Abstract ofp_port_mod. */
597struct ofputil_port_mod {
4e022ec0 598 ofp_port_t port_no;
74ff3298 599 struct eth_addr hw_addr;
9e1fd49b
BP
600 enum ofputil_port_config config;
601 enum ofputil_port_config mask;
602 enum netdev_features advertise;
603};
604
605enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
18cc69d9 606 struct ofputil_port_mod *, bool loose);
9e1fd49b
BP
607struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
608 enum ofputil_protocol);
6c038611 609
3c1bb396
BP
610/* Abstract version of OFPTC11_TABLE_MISS_*.
611 *
612 * OpenFlow 1.0 always sends packets that miss to the next flow table, or to
613 * the controller if they miss in the last flow table.
614 *
615 * OpenFlow 1.1 and 1.2 can configure table miss behavior via a "table-mod"
616 * that specifies "send to controller", "miss", or "drop".
617 *
618 * OpenFlow 1.3 and later never sends packets that miss to the controller.
619 */
620enum ofputil_table_miss {
621 /* Protocol-specific default behavior. On OpenFlow 1.0 through 1.2
622 * connections, the packet is sent to the controller, and on OpenFlow 1.3
623 * and later connections, the packet is dropped.
624 *
625 * This is also used as a result of decoding OpenFlow 1.3+ "config" values
626 * in table-mods, to indicate that no table-miss was specified. */
627 OFPUTIL_TABLE_MISS_DEFAULT, /* Protocol default behavior. */
628
629 /* These constants have the same meanings as those in OpenFlow with the
630 * same names. */
631 OFPUTIL_TABLE_MISS_CONTROLLER, /* Send to controller. */
632 OFPUTIL_TABLE_MISS_CONTINUE, /* Go to next table. */
633 OFPUTIL_TABLE_MISS_DROP, /* Drop the packet. */
634};
635
82c22d34
BP
636/* Abstract version of OFPTC14_EVICTION.
637 *
638 * OpenFlow 1.0 through 1.3 don't know anything about eviction, so decoding a
639 * message for one of these protocols always yields
640 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
641enum ofputil_table_eviction {
642 OFPUTIL_TABLE_EVICTION_DEFAULT, /* No value. */
643 OFPUTIL_TABLE_EVICTION_ON, /* Enable eviction. */
644 OFPUTIL_TABLE_EVICTION_OFF /* Disable eviction. */
645};
3c1bb396 646
de7d3c07
SJ
647/* Abstract version of OFPTC14_VACANCY_EVENTS.
648 *
649 * OpenFlow 1.0 through 1.3 don't know anything about vacancy events, so
650 * decoding a message for one of these protocols always yields
651 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
652enum ofputil_table_vacancy {
653 OFPUTIL_TABLE_VACANCY_DEFAULT, /* No value. */
654 OFPUTIL_TABLE_VACANCY_ON, /* Enable vacancy events. */
655 OFPUTIL_TABLE_VACANCY_OFF /* Disable vacancy events. */
656};
657
658/* Abstract version of OFPTMPT_VACANCY.
659 *
660 * Openflow 1.4+ defines vacancy events.
661 * The fields vacancy_down and vacancy_up are the threshold for generating
662 * vacancy events that should be configured on the flow table, expressed as
663 * a percent.
664 * The vacancy field is only used when this property in included in a
665 * OFPMP_TABLE_DESC multipart reply or a OFPT_TABLE_STATUS message and
666 * represent the current vacancy of the table, expressed as a percent. In
667 * OFP_TABLE_MOD requests, this field must be set to 0 */
668struct ofputil_table_mod_prop_vacancy {
669 uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */
670 uint8_t vacancy_up; /* Vacancy threshold when space increases (%). */
671 uint8_t vacancy; /* Current vacancy (%). */
672};
673
918f2b82
AZ
674/* Abstract ofp_table_mod. */
675struct ofputil_table_mod {
676 uint8_t table_id; /* ID of the table, 0xff indicates all tables. */
82c22d34
BP
677
678 /* OpenFlow 1.1 and 1.2 only. For other versions, ignored on encoding,
679 * decoded to OFPUTIL_TABLE_MISS_DEFAULT. */
680 enum ofputil_table_miss miss;
681
682 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
683 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
684 enum ofputil_table_eviction eviction;
685
686 /* OpenFlow 1.4+ only and optional even there; UINT32_MAX indicates
687 * absence. For other versions, ignored on encoding, decoded to
688 * UINT32_MAX.*/
689 uint32_t eviction_flags; /* OFPTMPEF14_*. */
de7d3c07
SJ
690
691 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
692 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
693 enum ofputil_table_vacancy vacancy;
694
695 /* Openflow 1.4+ only. Defines threshold values of vacancy expressed as
696 * percent, value of current vacancy is set to zero for table-mod.
697 * For other versions, ignored on encoding, all values decoded to
698 * zero. */
699 struct ofputil_table_mod_prop_vacancy table_vacancy;
918f2b82
AZ
700};
701
03c72922
BP
702/* Abstract ofp14_table_desc. */
703struct ofputil_table_desc {
704 uint8_t table_id; /* ID of the table. */
705 enum ofputil_table_eviction eviction;
706 uint32_t eviction_flags; /* UINT32_MAX if not present. */
de7d3c07
SJ
707 enum ofputil_table_vacancy vacancy;
708 struct ofputil_table_mod_prop_vacancy table_vacancy;
03c72922
BP
709};
710
918f2b82
AZ
711enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
712 struct ofputil_table_mod *);
713struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
714 enum ofputil_protocol);
715
82c22d34
BP
716/* Abstract ofp_table_features.
717 *
718 * This is used for all versions of OpenFlow, even though ofp_table_features
719 * was only introduced in OpenFlow 1.3, because earlier versions of OpenFlow
720 * include support for a subset of ofp_table_features through OFPST_TABLE (aka
721 * OFPMP_TABLE). */
5deff5aa
AW
722struct ofputil_table_features {
723 uint8_t table_id; /* Identifier of table. Lower numbered tables
724 are consulted first. */
725 char name[OFP_MAX_TABLE_NAME_LEN];
726 ovs_be64 metadata_match; /* Bits of metadata table can match. */
727 ovs_be64 metadata_write; /* Bits of metadata table can write. */
5deff5aa
AW
728 uint32_t max_entries; /* Max number of entries supported. */
729
82c22d34
BP
730 /* Flags.
731 *
732 * 'miss_config' is relevant for OpenFlow 1.1 and 1.2 only, because those
733 * versions include OFPTC_MISS_* flags in OFPST_TABLE. For other versions,
734 * it is decoded to OFPUTIL_TABLE_MISS_DEFAULT and ignored for encoding.
735 *
736 * 'supports_eviction' and 'supports_vacancy_events' are relevant only for
737 * OpenFlow 1.4 and later only. For OF1.4, they are boolean: 1 if
738 * supported, otherwise 0. For other versions, they are decoded as -1 and
739 * ignored for encoding.
740 *
741 * See the section "OFPTC_* Table Configuration" in DESIGN.md for more
742 * details of how OpenFlow has changed in this area.
743 */
744 enum ofputil_table_miss miss_config; /* OF1.1 and 1.2 only. */
745 int supports_eviction; /* OF1.4+ only. */
746 int supports_vacancy_events; /* OF1.4+ only. */
747
5deff5aa
AW
748 /* Table features related to instructions. There are two instances:
749 *
750 * - 'miss' reports features available in the table miss flow.
751 *
752 * - 'nonmiss' reports features available in other flows. */
753 struct ofputil_table_instruction_features {
754 /* Tables that "goto-table" may jump to. */
755 unsigned long int next[BITMAP_N_LONGS(255)];
756
757 /* Bitmap of OVSINST_* for supported instructions. */
758 uint32_t instructions;
759
760 /* Table features related to actions. There are two instances:
761 *
762 * - 'write' reports features available in a "write_actions"
763 * instruction.
764 *
765 * - 'apply' reports features available in an "apply_actions"
766 * instruction. */
767 struct ofputil_table_action_features {
08d1e234 768 uint64_t ofpacts; /* Bitmap of supported OFPACT_*. */
abadfcb0 769 struct mf_bitmap set_fields; /* Fields for "set-field". */
5deff5aa
AW
770 } write, apply;
771 } nonmiss, miss;
772
773 /* MFF_* bitmaps.
774 *
775 * For any given field the following combinations are valid:
776 *
777 * - match=0, wildcard=0, mask=0: Flows in this table cannot match on
778 * this field.
779 *
780 * - match=1, wildcard=0, mask=0: Flows in this table must match on all
781 * the bits in this field.
782 *
783 * - match=1, wildcard=1, mask=0: Flows in this table must either match
784 * on all the bits in the field or wildcard the field entirely.
785 *
786 * - match=1, wildcard=1, mask=1: Flows in this table may arbitrarily
787 * mask this field (as special cases, they may match on all the bits
788 * or wildcard it entirely).
789 *
790 * Other combinations do not make sense.
791 */
abadfcb0
BP
792 struct mf_bitmap match; /* Fields that may be matched. */
793 struct mf_bitmap mask; /* Subset of 'match' that may have masks. */
794 struct mf_bitmap wildcard; /* Subset of 'match' that may be wildcarded. */
5deff5aa
AW
795};
796
797int ofputil_decode_table_features(struct ofpbuf *,
798 struct ofputil_table_features *, bool loose);
03c72922
BP
799
800int ofputil_decode_table_desc(struct ofpbuf *,
801 struct ofputil_table_desc *,
802 enum ofp_version);
803
3c4e10fb
BP
804struct ofpbuf *ofputil_encode_table_features_request(enum ofp_version);
805
03c72922
BP
806struct ofpbuf *ofputil_encode_table_desc_request(enum ofp_version);
807
5deff5aa 808void ofputil_append_table_features_reply(
ca6ba700 809 const struct ofputil_table_features *tf, struct ovs_list *replies);
5deff5aa 810
03c72922
BP
811void ofputil_append_table_desc_reply(const struct ofputil_table_desc *td,
812 struct ovs_list *replies,
813 enum ofp_version);
814
0445637d 815/* Meter band configuration for all supported band types. */
638a19b0
JR
816struct ofputil_meter_band {
817 uint16_t type;
0445637d 818 uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */
638a19b0
JR
819 uint32_t rate;
820 uint32_t burst_size;
821};
822
823struct ofputil_meter_band_stats {
824 uint64_t packet_count;
825 uint64_t byte_count;
826};
827
828struct ofputil_meter_config {
829 uint32_t meter_id;
830 uint16_t flags;
831 uint16_t n_bands;
832 struct ofputil_meter_band *bands;
833};
834
835/* Abstract ofp_meter_mod. */
836struct ofputil_meter_mod {
837 uint16_t command;
838 struct ofputil_meter_config meter;
839};
840
841struct ofputil_meter_stats {
842 uint32_t meter_id;
843 uint32_t flow_count;
844 uint64_t packet_in_count;
845 uint64_t byte_in_count;
846 uint32_t duration_sec;
847 uint32_t duration_nsec;
848 uint16_t n_bands;
0445637d 849 struct ofputil_meter_band_stats *bands;
638a19b0
JR
850};
851
852struct ofputil_meter_features {
0445637d
JR
853 uint32_t max_meters; /* Maximum number of meters. */
854 uint32_t band_types; /* Can support max 32 band types. */
855 uint32_t capabilities; /* Supported flags. */
638a19b0
JR
856 uint8_t max_bands;
857 uint8_t max_color;
858};
859
860enum ofperr ofputil_decode_meter_mod(const struct ofp_header *,
861 struct ofputil_meter_mod *,
0445637d
JR
862 struct ofpbuf *bands);
863struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version,
638a19b0
JR
864 const struct ofputil_meter_mod *);
865
866void ofputil_decode_meter_features(const struct ofp_header *,
867 struct ofputil_meter_features *);
868struct ofpbuf *ofputil_encode_meter_features_reply(const struct
869 ofputil_meter_features *,
870 const struct ofp_header *
871 request);
872void ofputil_decode_meter_request(const struct ofp_header *,
873 uint32_t *meter_id);
874
ca6ba700 875void ofputil_append_meter_config(struct ovs_list *replies,
0445637d 876 const struct ofputil_meter_config *);
638a19b0 877
ca6ba700 878void ofputil_append_meter_stats(struct ovs_list *replies,
0445637d 879 const struct ofputil_meter_stats *);
638a19b0
JR
880
881enum ofputil_meter_request_type {
882 OFPUTIL_METER_FEATURES,
883 OFPUTIL_METER_CONFIG,
884 OFPUTIL_METER_STATS
885};
886
887struct ofpbuf *ofputil_encode_meter_request(enum ofp_version,
888 enum ofputil_meter_request_type,
889 uint32_t meter_id);
890
0445637d
JR
891int ofputil_decode_meter_stats(struct ofpbuf *,
892 struct ofputil_meter_stats *,
638a19b0
JR
893 struct ofpbuf *bands);
894
0445637d
JR
895int ofputil_decode_meter_config(struct ofpbuf *,
896 struct ofputil_meter_config *,
638a19b0
JR
897 struct ofpbuf *bands);
898
0445637d 899/* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
638a19b0
JR
900typedef struct { uint32_t uint32; } ofproto_meter_id;
901
6ea4776b
JR
902/* Abstract ofp_role_request and reply. */
903struct ofputil_role_request {
f4f1ea7e 904 enum ofp12_controller_role role;
6ea4776b 905 bool have_generation_id;
6ea4776b
JR
906 uint64_t generation_id;
907};
908
00467f73
AC
909struct ofputil_role_status {
910 enum ofp12_controller_role role;
911 enum ofp14_controller_role_reason reason;
912 uint64_t generation_id;
913};
914
6ea4776b
JR
915enum ofperr ofputil_decode_role_message(const struct ofp_header *,
916 struct ofputil_role_request *);
917struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
f4f1ea7e 918 const struct ofputil_role_request *);
6ea4776b 919
00467f73
AC
920struct ofpbuf *ofputil_encode_role_status(
921 const struct ofputil_role_status *status,
922 enum ofputil_protocol protocol);
923
924enum ofperr ofputil_decode_role_status(const struct ofp_header *oh,
925 struct ofputil_role_status *rs);
08d1e234 926
3c1bb396
BP
927/* Abstract table stats.
928 *
929 * This corresponds to the OpenFlow 1.3 table statistics structure, which only
930 * includes actual statistics. In earlier versions of OpenFlow, several
931 * members describe table features, so this structure has to be paired with
932 * struct ofputil_table_features to get all information. */
933struct ofputil_table_stats {
934 uint8_t table_id; /* Identifier of table. */
08d1e234
BP
935 uint32_t active_count; /* Number of active entries. */
936 uint64_t lookup_count; /* Number of packets looked up in table. */
937 uint64_t matched_count; /* Number of packets that hit table. */
938};
307975da 939
3c1bb396 940struct ofpbuf *ofputil_encode_table_stats_reply(const struct ofp_header *rq);
03c72922
BP
941
942struct ofpbuf *ofputil_encode_table_desc_reply(const struct ofp_header *rq);
943
3c1bb396
BP
944void ofputil_append_table_stats_reply(struct ofpbuf *reply,
945 const struct ofputil_table_stats *,
946 const struct ofputil_table_features *);
947
948int ofputil_decode_table_stats_reply(struct ofpbuf *reply,
949 struct ofputil_table_stats *,
950 struct ofputil_table_features *);
307975da 951
e8f9a7bb
VG
952/* Queue configuration request. */
953struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version,
954 ofp_port_t port);
955enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *,
956 ofp_port_t *port);
957
958/* Queue configuration reply. */
959struct ofputil_queue_config {
56085be5 960 ofp_port_t port;
e8f9a7bb
VG
961 uint32_t queue_id;
962
963 /* Each of these optional values is expressed in tenths of a percent.
964 * Values greater than 1000 indicate that the feature is disabled.
965 * UINT16_MAX indicates that the value is omitted. */
966 uint16_t min_rate;
967 uint16_t max_rate;
968};
969
970struct ofpbuf *ofputil_encode_queue_get_config_reply(
971 const struct ofp_header *request);
972void ofputil_append_queue_get_config_reply(
973 struct ofpbuf *reply, const struct ofputil_queue_config *);
974
975enum ofperr ofputil_decode_queue_get_config_reply(struct ofpbuf *reply,
976 ofp_port_t *);
977int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply,
978 struct ofputil_queue_config *);
979
980
2b07c8b1
BP
981/* Abstract nx_flow_monitor_request. */
982struct ofputil_flow_monitor_request {
983 uint32_t id;
984 enum nx_flow_monitor_flags flags;
4e022ec0 985 ofp_port_t out_port;
2b07c8b1 986 uint8_t table_id;
81a76618 987 struct match match;
2b07c8b1
BP
988};
989
990int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
991 struct ofpbuf *msg);
992void ofputil_append_flow_monitor_request(
993 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
994
995/* Abstract nx_flow_update. */
996struct ofputil_flow_update {
997 enum nx_flow_update_event event;
998
999 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
1000 enum ofp_flow_removed_reason reason;
1001 uint16_t idle_timeout;
1002 uint16_t hard_timeout;
1003 uint8_t table_id;
e0822031 1004 uint16_t priority;
2b07c8b1 1005 ovs_be64 cookie;
81a76618 1006 struct match *match;
dc723c44 1007 const struct ofpact *ofpacts;
2b07c8b1
BP
1008 size_t ofpacts_len;
1009
1010 /* Used only for NXFME_ABBREV. */
1011 ovs_be32 xid;
1012};
1013
1014int ofputil_decode_flow_update(struct ofputil_flow_update *,
1015 struct ofpbuf *msg, struct ofpbuf *ofpacts);
ca6ba700 1016void ofputil_start_flow_update(struct ovs_list *replies);
2b07c8b1 1017void ofputil_append_flow_update(const struct ofputil_flow_update *,
ca6ba700 1018 struct ovs_list *replies);
2b07c8b1
BP
1019
1020/* Abstract nx_flow_monitor_cancel. */
1021uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
1022struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
1023
70ae4f93
BP
1024/* Port desc stats requests and replies. */
1025enum ofperr ofputil_decode_port_desc_stats_request(const struct ofp_header *,
1026 ofp_port_t *portp);
1027struct ofpbuf *ofputil_encode_port_desc_stats_request(
1028 enum ofp_version ofp_version, ofp_port_t);
1029
e28ac5cf 1030void ofputil_append_port_desc_stats_reply(const struct ofputil_phy_port *pp,
ca6ba700 1031 struct ovs_list *replies);
2be393ed 1032
982697a4 1033/* Encoding simple OpenFlow messages. */
1a126c0c 1034struct ofpbuf *make_echo_request(enum ofp_version);
fa37b408 1035struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
7257b535 1036
a0ae0b6e 1037struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
efb80167 1038
7257b535
BP
1039const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
1040bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
2be393ed 1041
9aee0764
BP
1042\f
1043/* Actions. */
1044
dbba996b 1045bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
3052b0c5 1046
90bf1e07
BP
1047enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
1048 union ofp_action **, size_t *);
18ddadc2
BP
1049
1050bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
1051 const union ofp_action *b, size_t n_b);
1052union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
26c112c2 1053
0ff22822
BP
1054/* Handy utility for parsing flows and actions. */
1055bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
1056
f8e4867e 1057struct ofputil_port_stats {
4e022ec0 1058 ofp_port_t port_no;
f8e4867e 1059 struct netdev_stats stats;
65e0be10
BP
1060 uint32_t duration_sec; /* UINT32_MAX if unknown. */
1061 uint32_t duration_nsec;
f8e4867e
SH
1062};
1063
1064struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
4e022ec0 1065 ofp_port_t port);
ca6ba700 1066void ofputil_append_port_stat(struct ovs_list *replies,
f8e4867e
SH
1067 const struct ofputil_port_stats *ops);
1068size_t ofputil_count_port_stats(const struct ofp_header *);
1069int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
1070enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
4e022ec0 1071 ofp_port_t *ofp10_port);
64626975
SH
1072
1073struct ofputil_queue_stats_request {
4e022ec0 1074 ofp_port_t port_no; /* OFPP_ANY means "all ports". */
64626975
SH
1075 uint32_t queue_id;
1076};
1077
1078enum ofperr
1079ofputil_decode_queue_stats_request(const struct ofp_header *request,
1080 struct ofputil_queue_stats_request *oqsr);
1081struct ofpbuf *
1082ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
1083 const struct ofputil_queue_stats_request *oqsr);
1084
1085struct ofputil_queue_stats {
4e022ec0 1086 ofp_port_t port_no;
64626975 1087 uint32_t queue_id;
6dc34a0d
BP
1088
1089 /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
1090 uint64_t tx_bytes;
1091 uint64_t tx_packets;
1092 uint64_t tx_errors;
1093
1094 /* UINT32_MAX if unknown. */
1095 uint32_t duration_sec;
1096 uint32_t duration_nsec;
64626975
SH
1097};
1098
1099size_t ofputil_count_queue_stats(const struct ofp_header *);
1100int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
ca6ba700 1101void ofputil_append_queue_stat(struct ovs_list *replies,
64626975
SH
1102 const struct ofputil_queue_stats *oqs);
1103
1e684d7d
RW
1104struct bucket_counter {
1105 uint64_t packet_count; /* Number of packets processed by bucket. */
1106 uint64_t byte_count; /* Number of bytes processed by bucket. */
1107};
1108
7395c052
NZ
1109/* Bucket for use in groups. */
1110struct ofputil_bucket {
ca6ba700 1111 struct ovs_list list_node;
7395c052
NZ
1112 uint16_t weight; /* Relative weight, for "select" groups. */
1113 ofp_port_t watch_port; /* Port whose state affects whether this bucket
1114 * is live. Only required for fast failover
1115 * groups. */
1116 uint32_t watch_group; /* Group whose state affects whether this
1117 * bucket is live. Only required for fast
1118 * failover groups. */
18ac06d3 1119 uint32_t bucket_id; /* Bucket Id used to identify bucket*/
7395c052
NZ
1120 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
1121 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
1e684d7d
RW
1122
1123 struct bucket_counter stats;
7395c052
NZ
1124};
1125
bc65c25a
SH
1126/* Protocol-independent group_mod. */
1127struct ofputil_group_props {
1128 /* NTR selection method */
1129 char selection_method[NTR_MAX_SELECTION_METHOD_LEN];
1130 uint64_t selection_method_param;
1131 struct field_array fields;
1132};
1133
7395c052
NZ
1134/* Protocol-independent group_mod. */
1135struct ofputil_group_mod {
18ac06d3 1136 uint16_t command; /* One of OFPGC15_*. */
7395c052
NZ
1137 uint8_t type; /* One of OFPGT11_*. */
1138 uint32_t group_id; /* Group identifier. */
18ac06d3
SH
1139 uint32_t command_bucket_id; /* Bucket Id used as part of
1140 * OFPGC15_INSERT_BUCKET and
1141 * OFPGC15_REMOVE_BUCKET commands
1142 * execution.*/
ca6ba700 1143 struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */
bc65c25a 1144 struct ofputil_group_props props; /* Group properties. */
7395c052
NZ
1145};
1146
7395c052
NZ
1147/* Group stats reply, independent of protocol. */
1148struct ofputil_group_stats {
1149 uint32_t group_id; /* Group identifier. */
1150 uint32_t ref_count;
1151 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
1152 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
1153 uint32_t duration_sec; /* UINT32_MAX if unknown. */
1154 uint32_t duration_nsec;
1155 uint32_t n_buckets;
646b2a9c 1156 struct bucket_counter *bucket_stats;
7395c052
NZ
1157};
1158
f0e7025f
BP
1159/* Group features reply, independent of protocol.
1160 *
1161 * Only OF1.2 and later support group features replies. */
7395c052
NZ
1162struct ofputil_group_features {
1163 uint32_t types; /* Bitmap of OFPGT_* values supported. */
1164 uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */
1165 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
08d1e234 1166 uint64_t ofpacts[4]; /* Bitmaps of supported OFPACT_* */
7395c052
NZ
1167};
1168
1169/* Group desc reply, independent of protocol. */
1170struct ofputil_group_desc {
1171 uint8_t type; /* One of OFPGT_*. */
1172 uint32_t group_id; /* Group identifier. */
ca6ba700 1173 struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */
bc65c25a 1174 struct ofputil_group_props props; /* Group properties. */
7395c052
NZ
1175};
1176
ca6ba700
TG
1177void ofputil_bucket_list_destroy(struct ovs_list *buckets);
1178void ofputil_bucket_clone_list(struct ovs_list *dest,
1179 const struct ovs_list *src,
103b4866 1180 const struct ofputil_bucket *);
ca6ba700 1181struct ofputil_bucket *ofputil_bucket_find(const struct ovs_list *,
103b4866 1182 uint32_t bucket_id);
ca6ba700
TG
1183bool ofputil_bucket_check_duplicate_id(const struct ovs_list *);
1184struct ofputil_bucket *ofputil_bucket_list_front(const struct ovs_list *);
1185struct ofputil_bucket *ofputil_bucket_list_back(const struct ovs_list *);
7395c052 1186
e57681e5
SH
1187static inline bool
1188ofputil_bucket_has_liveness(const struct ofputil_bucket *bucket)
1189{
1190 return (bucket->watch_port != OFPP_ANY ||
1191 bucket->watch_group != OFPG_ANY);
1192}
1193
7395c052
NZ
1194struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version,
1195 uint32_t group_id);
1196enum ofperr ofputil_decode_group_stats_request(
1197 const struct ofp_header *request, uint32_t *group_id);
ca6ba700 1198void ofputil_append_group_stats(struct ovs_list *replies,
7395c052
NZ
1199 const struct ofputil_group_stats *);
1200struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version);
1201struct ofpbuf *ofputil_encode_group_features_reply(
1202 const struct ofputil_group_features *, const struct ofp_header *request);
1203void ofputil_decode_group_features_reply(const struct ofp_header *,
1204 struct ofputil_group_features *);
bc65c25a 1205void ofputil_uninit_group_mod(struct ofputil_group_mod *gm);
7395c052
NZ
1206struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version,
1207 const struct ofputil_group_mod *gm);
1208
1209enum ofperr ofputil_decode_group_mod(const struct ofp_header *,
1210 struct ofputil_group_mod *);
1211
1212int ofputil_decode_group_stats_reply(struct ofpbuf *,
1213 struct ofputil_group_stats *);
1214
bc65c25a 1215void ofputil_uninit_group_desc(struct ofputil_group_desc *gd);
19187a71
BP
1216uint32_t ofputil_decode_group_desc_request(const struct ofp_header *);
1217struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version,
1218 uint32_t group_id);
1219
7395c052 1220int ofputil_decode_group_desc_reply(struct ofputil_group_desc *,
a7a2d006 1221 struct ofpbuf *, enum ofp_version);
7395c052
NZ
1222
1223void ofputil_append_group_desc_reply(const struct ofputil_group_desc *,
1667bb34 1224 const struct ovs_list *buckets,
ca6ba700 1225 struct ovs_list *replies);
7395c052 1226
777af88d
AC
1227struct ofputil_bundle_ctrl_msg {
1228 uint32_t bundle_id;
1229 uint16_t type;
1230 uint16_t flags;
1231};
1232
1233struct ofputil_bundle_add_msg {
1234 uint32_t bundle_id;
1235 uint16_t flags;
1236 const struct ofp_header *msg;
1237};
1238
7ac27a04
JR
1239enum ofptype;
1240
777af88d
AC
1241enum ofperr ofputil_decode_bundle_ctrl(const struct ofp_header *,
1242 struct ofputil_bundle_ctrl_msg *);
1243
db5076ee
JR
1244struct ofpbuf *ofputil_encode_bundle_ctrl_request(enum ofp_version,
1245 struct ofputil_bundle_ctrl_msg *);
777af88d
AC
1246struct ofpbuf *ofputil_encode_bundle_ctrl_reply(const struct ofp_header *,
1247 struct ofputil_bundle_ctrl_msg *);
1248
1249struct ofpbuf *ofputil_encode_bundle_add(enum ofp_version ofp_version,
1250 struct ofputil_bundle_add_msg *msg);
1251
1252enum ofperr ofputil_decode_bundle_add(const struct ofp_header *,
7ac27a04
JR
1253 struct ofputil_bundle_add_msg *,
1254 enum ofptype *type);
6159c531 1255
4e548ad9 1256struct ofputil_tlv_map {
6159c531
JG
1257 struct ovs_list list_node;
1258
1259 uint16_t option_class;
1260 uint8_t option_type;
1261 uint8_t option_len;
1262 uint16_t index;
1263};
1264
4e548ad9 1265struct ofputil_tlv_table_mod {
6159c531 1266 uint16_t command;
4e548ad9 1267 struct ovs_list mappings; /* Contains "struct ofputil_tlv_map"s. */
6159c531
JG
1268};
1269
4e548ad9 1270struct ofputil_tlv_table_reply {
6159c531
JG
1271 uint32_t max_option_space;
1272 uint16_t max_fields;
4e548ad9 1273 struct ovs_list mappings; /* Contains "struct ofputil_tlv_map"s. */
6159c531
JG
1274};
1275
4e548ad9
ML
1276struct ofpbuf *ofputil_encode_tlv_table_mod(enum ofp_version ofp_version,
1277 struct ofputil_tlv_table_mod *);
1278enum ofperr ofputil_decode_tlv_table_mod(const struct ofp_header *,
1279 struct ofputil_tlv_table_mod *);
1280struct ofpbuf *ofputil_encode_tlv_table_reply(const struct ofp_header *,
1281 struct ofputil_tlv_table_reply *);
1282enum ofperr ofputil_decode_tlv_table_reply(const struct ofp_header *,
1283 struct ofputil_tlv_table_reply *);
1284void ofputil_uninit_tlv_table(struct ovs_list *mappings);
6159c531 1285
98090482
NR
1286enum ofputil_async_msg_type {
1287 OAM_PACKET_IN, /* OFPT_PACKET_IN or NXT_PACKET_IN. */
1288 OAM_PORT_STATUS, /* OFPT_PORT_STATUS. */
1289 OAM_FLOW_REMOVED, /* OFPT_FLOW_REMOVED or
1290 * NXT_FLOW_REMOVED. */
1291 OAM_ROLE_STATUS, /* OFPT_ROLE_STATUS. */
1292 OAM_TABLE_STATUS, /* OFPT_TABLE_STATUS. */
1293 OAM_REQUESTFORWARD, /* OFPT_REQUESTFORWARD. */
1294 OAM_N_TYPES
1295};
1296
1297enum ofperr ofputil_decode_set_async_config(const struct ofp_header *,
1298 uint32_t master[OAM_N_TYPES],
1299 uint32_t slave[OAM_N_TYPES],
1300 bool loose);
1301
1302struct ofpbuf *ofputil_encode_get_async_config(const struct ofp_header *,
1303 uint32_t master[OAM_N_TYPES],
1304 uint32_t slave[OAM_N_TYPES]);
1305
3c35db62
NR
1306struct ofputil_requestforward {
1307 ovs_be32 xid;
1308 enum ofp14_requestforward_reason reason;
1309 union {
1310 /* reason == OFPRFR_METER_MOD. */
3c35db62 1311 struct {
eaa0e88b 1312 struct ofputil_meter_mod *meter_mod;
3c35db62
NR
1313 struct ofpbuf bands;
1314 };
eaa0e88b
BP
1315
1316 /* reason == OFPRFR_GROUP_MOD. */
1317 struct ofputil_group_mod *group_mod;
3c35db62
NR
1318 };
1319};
1320
1321struct ofpbuf *ofputil_encode_requestforward(
1322 const struct ofputil_requestforward *, enum ofputil_protocol);
1323enum ofperr ofputil_decode_requestforward(const struct ofp_header *,
1324 struct ofputil_requestforward *);
1325void ofputil_destroy_requestforward(struct ofputil_requestforward *);
1326
fa37b408 1327#endif /* ofp-util.h */