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