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