]> git.proxmox.com Git - ovs.git/blame - lib/ofp-util.h
ofproto-dpif: Print slow-path actions instead of "drop" in dump-flows.
[ovs.git] / lib / ofp-util.h
CommitLineData
fa37b408 1/*
f4f1ea7e 2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
fa37b408
BP
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OFP_UTIL_H
18#define OFP_UTIL_H 1
19
c1c9c9c4 20#include <stdbool.h>
fa37b408
BP
21#include <stddef.h>
22#include <stdint.h>
d1e2cf21 23#include "classifier.h"
f25d0cf3 24#include "compiler.h"
fa37b408 25#include "flow.h"
81a76618 26#include "match.h"
6c038611 27#include "netdev.h"
492f7572 28#include "openflow/nicira-ext.h"
44381c1b 29#include "openvswitch/types.h"
fa37b408
BP
30
31struct ofpbuf;
fa37b408 32
39dc9082 33/* Port numbers. */
7b7503ea
BP
34enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port, uint16_t *ofp10_port);
35ovs_be32 ofputil_port_to_ofp11(uint16_t ofp10_port);
36
90bf1e07 37enum ofperr ofputil_check_output_port(uint16_t ofp_port, int max_ports);
8010100b 38bool ofputil_port_from_string(const char *, uint16_t *portp);
39dc9082 39void ofputil_format_port(uint16_t port, struct ds *);
d1e2cf21 40
eec25dc1
BP
41/* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
42 * to and from IP bitmasks. */
0596e897
BP
43ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
44int ofputil_netmask_to_wcbits(ovs_be32 netmask);
45
27527aa0 46/* Protocols.
85813857
BP
47 *
48 * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
49 * a bit extra about the flow match format in use.
27527aa0
BP
50 *
51 * These are arranged from most portable to least portable, or alternatively
85813857
BP
52 * from least powerful to most powerful. Protocols earlier on the list are
53 * more likely to be understood for the purpose of making requests, but
54 * protocol later on the list are more likely to accurately describe a flow
55 * within a switch.
27527aa0
BP
56 *
57 * On any given OpenFlow connection, a single protocol is in effect at any
58 * given time. These values use separate bits only because that makes it easy
59 * to test whether a particular protocol is within a given set of protocols and
60 * to implement set union and intersection.
61 */
62enum ofputil_protocol {
85813857
BP
63 /* OpenFlow 1.0 protocols.
64 *
65 * The "STD" protocols use the standard OpenFlow 1.0 flow format.
66 * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
67 *
68 * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
69 * extension has been enabled. The other protocols have it disabled.
70 */
eb12aa89 71#define OFPUTIL_P_NONE 0
85813857
BP
72 OFPUTIL_P_OF10_STD = 1 << 0,
73 OFPUTIL_P_OF10_STD_TID = 1 << 1,
74 OFPUTIL_P_OF10_NXM = 1 << 2,
75 OFPUTIL_P_OF10_NXM_TID = 1 << 3,
76#define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
77#define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
27527aa0 78
2e1ae200 79 /* OpenFlow 1.2+ protocols (only one variant each).
85813857 80 *
2e1ae200 81 * These use the standard OpenFlow Extensible Match (OXM) flow format.
85813857 82 *
2e1ae200 83 * OpenFlow 1.2+ always operates with an equivalent of the
85813857
BP
84 * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
85 * variant. */
86 OFPUTIL_P_OF12_OXM = 1 << 4,
2e1ae200 87 OFPUTIL_P_OF13_OXM = 1 << 5,
e71bff1b 88#define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM)
44d3732d 89
27527aa0 90 /* All protocols. */
2e1ae200 91#define OFPUTIL_P_ANY ((1 << 6) - 1)
27527aa0
BP
92
93 /* Protocols in which a specific table may be specified in flow_mods. */
7cd90356
BP
94#define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
95 OFPUTIL_P_OF10_NXM_TID | \
4f13da56 96 OFPUTIL_P_ANY_OXM)
27527aa0
BP
97};
98
99/* Protocols to use for flow dumps, from most to least preferred. */
100extern enum ofputil_protocol ofputil_flow_dump_protocols[];
101extern size_t ofputil_n_flow_dump_protocols;
102
6d2c051a 103enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
4f13da56
BP
104enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
105enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
9e1fd49b 106
27527aa0
BP
107bool ofputil_protocol_is_valid(enum ofputil_protocol);
108enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
109 bool enable);
110enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
111enum ofputil_protocol ofputil_protocol_set_base(
112 enum ofputil_protocol cur, enum ofputil_protocol new_base);
113
114const char *ofputil_protocol_to_string(enum ofputil_protocol);
115char *ofputil_protocols_to_string(enum ofputil_protocol);
116enum ofputil_protocol ofputil_protocols_from_string(const char *);
81a76618 117enum ofputil_protocol ofputil_usable_protocols(const struct match *);
27527aa0 118
03e1125c
SH
119void ofputil_format_version(struct ds *, enum ofp_version);
120void ofputil_format_version_name(struct ds *, enum ofp_version);
121
122/* A bitmap of version numbers
123 *
124 * Bit offsets correspond to ofp_version numbers which in turn correspond to
125 * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION)
126 * is the mask for Open Flow 1.1. If the bit for a version is set then it is
127 * allowed, otherwise it is disallowed. */
128
129void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
130void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
131
4f13da56
BP
132uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
133enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
134
03e1125c
SH
135/* Bitmap of OpenFlow versions that Open vSwitch supports. */
136#define OFPUTIL_SUPPORTED_VERSIONS \
2e1ae200 137 ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
03e1125c
SH
138
139/* Bitmap of OpenFlow versions to enable by default (a subset of
140 * OFPUTIL_SUPPORTED_VERSIONS). */
141#define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
142
143enum ofputil_protocol ofputil_protocols_from_string(const char *s);
144
145const char *ofputil_version_to_string(enum ofp_version ofp_version);
146uint32_t ofputil_versions_from_string(const char *s);
7beaa082 147uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
03e1125c 148
de6c85b0
SH
149bool ofputil_decode_hello(const struct ofp_header *,
150 uint32_t *allowed_versions);
151struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
152
27527aa0
BP
153struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
154 enum ofputil_protocol want,
155 enum ofputil_protocol *next);
156
157/* nx_flow_format */
158struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
159enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
160bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
161const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
162
eec25dc1
BP
163/* Work with ofp10_match. */
164void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
81a76618
BP
165void ofputil_match_from_ofp10_match(const struct ofp10_match *,
166 struct match *);
167void ofputil_normalize_match(struct match *);
168void ofputil_normalize_match_quiet(struct match *);
169void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
d8ae4d67 170
410698cf 171/* Work with ofp11_match. */
81a76618 172enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
36a16881 173 uint16_t *padded_match_len);
81a76618
BP
174enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
175 struct match *);
176void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
410698cf 177
36956a7d
BP
178/* dl_type translation between OpenFlow and 'struct flow' format. */
179ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
180ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
181
54834960
EJ
182/* PACKET_IN. */
183bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
184int ofputil_packet_in_format_from_string(const char *);
185const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
3f4a1939
SH
186struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
187 enum nx_packet_in_format);
54834960 188
6c1491fb
BP
189/* NXT_FLOW_MOD_TABLE_ID extension. */
190struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
191
623e1caf
JP
192/* Protocol-independent flow_mod.
193 *
194 * The handling of cookies across multiple versions of OpenFlow is a bit
195 * confusing. A full description of Open vSwitch's cookie handling is
196 * in the DESIGN file. The following table shows the expected values of
197 * the cookie-related fields for the different flow_mod commands in
198 * OpenFlow 1.0 ("OF10") and NXM. "<used>" and "-" indicate a value
199 * that may be populated and an ignored field, respectively.
200 *
201 * cookie cookie_mask new_cookie
202 * ====== =========== ==========
203 * OF10 Add - 0 <used>
204 * OF10 Modify - 0 <used>
205 * OF10 Delete - 0 -
206 * NXM Add - 0 <used>
207 * NXM Modify <used> <used> <used>
208 * NXM Delete <used> <used> -
209 */
a9a2da38 210struct ofputil_flow_mod {
81a76618
BP
211 struct match match;
212 unsigned int priority;
623e1caf
JP
213 ovs_be64 cookie; /* Cookie bits to match. */
214 ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */
215 ovs_be64 new_cookie; /* New cookie to install or -1. */
6c1491fb 216 uint8_t table_id;
2e4f5fcf
BP
217 uint16_t command;
218 uint16_t idle_timeout;
219 uint16_t hard_timeout;
220 uint32_t buffer_id;
221 uint16_t out_port;
222 uint16_t flags;
f25d0cf3
BP
223 struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
224 size_t ofpacts_len; /* Length of ofpacts, in bytes. */
2e4f5fcf
BP
225};
226
90bf1e07
BP
227enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
228 const struct ofp_header *,
f25d0cf3
BP
229 enum ofputil_protocol,
230 struct ofpbuf *ofpacts);
a9a2da38 231struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
27527aa0
BP
232 enum ofputil_protocol);
233
234enum ofputil_protocol ofputil_flow_mod_usable_protocols(
235 const struct ofputil_flow_mod *fms, size_t n_fms);
2e4f5fcf 236
27527aa0 237/* Flow stats or aggregate stats request, independent of protocol. */
81d1ea94 238struct ofputil_flow_stats_request {
2e4f5fcf 239 bool aggregate; /* Aggregate results? */
81a76618 240 struct match match;
e729e793
JP
241 ovs_be64 cookie;
242 ovs_be64 cookie_mask;
2e4f5fcf
BP
243 uint16_t out_port;
244 uint8_t table_id;
245};
246
90bf1e07
BP
247enum ofperr ofputil_decode_flow_stats_request(
248 struct ofputil_flow_stats_request *, const struct ofp_header *);
2e4f5fcf 249struct ofpbuf *ofputil_encode_flow_stats_request(
27527aa0
BP
250 const struct ofputil_flow_stats_request *, enum ofputil_protocol);
251enum ofputil_protocol ofputil_flow_stats_request_usable_protocols(
252 const struct ofputil_flow_stats_request *);
2e4f5fcf 253
27527aa0 254/* Flow stats reply, independent of protocol. */
4ffd1b43 255struct ofputil_flow_stats {
81a76618 256 struct match match;
4ffd1b43
BP
257 ovs_be64 cookie;
258 uint8_t table_id;
259 uint32_t duration_sec;
260 uint32_t duration_nsec;
81a76618 261 uint16_t priority;
4ffd1b43
BP
262 uint16_t idle_timeout;
263 uint16_t hard_timeout;
f27f2134
BP
264 int idle_age; /* Seconds since last packet, -1 if unknown. */
265 int hard_age; /* Seconds since last change, -1 if unknown. */
5e9d0469
BP
266 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
267 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
f25d0cf3
BP
268 struct ofpact *ofpacts;
269 size_t ofpacts_len;
2e1ae200 270 uint16_t flags; /* Added for OF 1.3 */
4ffd1b43
BP
271};
272
273int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
f27f2134 274 struct ofpbuf *msg,
f25d0cf3
BP
275 bool flow_age_extension,
276 struct ofpbuf *ofpacts);
349adfb2
BP
277void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
278 struct list *replies);
4ffd1b43 279
27527aa0 280/* Aggregate stats reply, independent of protocol. */
76c93b22 281struct ofputil_aggregate_stats {
5e9d0469
BP
282 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
283 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
76c93b22
BP
284 uint32_t flow_count;
285};
286
287struct ofpbuf *ofputil_encode_aggregate_stats_reply(
288 const struct ofputil_aggregate_stats *stats,
982697a4
BP
289 const struct ofp_header *request);
290enum ofperr ofputil_decode_aggregate_stats_reply(
291 struct ofputil_aggregate_stats *,
292 const struct ofp_header *reply);
76c93b22 293
27527aa0 294/* Flow removed message, independent of protocol. */
9b045a0c 295struct ofputil_flow_removed {
81a76618
BP
296 struct match match;
297 uint16_t priority;
9b045a0c
BP
298 ovs_be64 cookie;
299 uint8_t reason; /* One of OFPRR_*. */
95216219 300 uint8_t table_id; /* 255 if message didn't include table ID. */
9b045a0c
BP
301 uint32_t duration_sec;
302 uint32_t duration_nsec;
303 uint16_t idle_timeout;
fa2bad0f 304 uint16_t hard_timeout;
5e9d0469
BP
305 uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */
306 uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */
9b045a0c
BP
307};
308
90bf1e07
BP
309enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
310 const struct ofp_header *);
588cd7b5 311struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
27527aa0 312 enum ofputil_protocol);
9b045a0c 313
ebb57021
BP
314/* Abstract packet-in message. */
315struct ofputil_packet_in {
3e3252fa
EJ
316 const void *packet;
317 size_t packet_len;
318
2a6dab2f 319 enum ofp_packet_in_reason reason; /* One of OFPR_*. */
a7349929 320 uint16_t controller_id; /* Controller ID to send to. */
54834960
EJ
321 uint8_t table_id;
322 ovs_be64 cookie;
ebb57021
BP
323
324 uint32_t buffer_id;
325 int send_len;
65120a8a 326 uint16_t total_len; /* Full length of frame. */
5d6c3af0
EJ
327
328 struct flow_metadata fmd; /* Metadata at creation time. */
ebb57021
BP
329};
330
f7cc6bd8
BP
331enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
332 const struct ofp_header *);
54834960 333struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
d94240ec 334 enum ofputil_protocol protocol,
54834960 335 enum nx_packet_in_format);
ebb57021 336
7c1a76a4
BP
337const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
338bool ofputil_packet_in_reason_from_string(const char *,
339 enum ofp_packet_in_reason *);
340
751c7785
BP
341/* Abstract packet-out message.
342 *
343 * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
344 * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
c6a93eb7
BP
345struct ofputil_packet_out {
346 const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */
347 size_t packet_len; /* Length of packet data in bytes. */
348 uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */
751c7785 349 uint16_t in_port; /* Packet's input port. */
f25d0cf3
BP
350 struct ofpact *ofpacts; /* Actions. */
351 size_t ofpacts_len; /* Size of ofpacts in bytes. */
c6a93eb7
BP
352};
353
354enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
982697a4 355 const struct ofp_header *,
f25d0cf3 356 struct ofpbuf *ofpacts);
de0f3156
SH
357struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
358 enum ofputil_protocol protocol);
c6a93eb7 359
9e1fd49b
BP
360enum ofputil_port_config {
361 /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
362 OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
363 OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
364 OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
365 OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
366 /* OpenFlow 1.0 only. */
367 OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */
368 OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
369 OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
370 /* There are no OpenFlow 1.1-only bits. */
371};
372
373enum ofputil_port_state {
374 /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
375 OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */
376 /* OpenFlow 1.1 only. */
377 OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */
378 OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
379 /* OpenFlow 1.0 only. */
380 OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
381 OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
382 OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
383 OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
384 OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
385};
386
387/* Abstract ofp10_phy_port or ofp11_port. */
388struct ofputil_phy_port {
389 uint16_t port_no;
390 uint8_t hw_addr[OFP_ETH_ALEN];
391 char name[OFP_MAX_PORT_NAME_LEN];
392 enum ofputil_port_config config;
393 enum ofputil_port_state state;
394
395 /* NETDEV_F_* feature bitmasks. */
396 enum netdev_features curr; /* Current features. */
397 enum netdev_features advertised; /* Features advertised by the port. */
398 enum netdev_features supported; /* Features supported by the port. */
399 enum netdev_features peer; /* Features advertised by peer. */
400
401 /* Speed. */
402 uint32_t curr_speed; /* Current speed, in kbps. */
403 uint32_t max_speed; /* Maximum supported speed, in kbps. */
404};
405
406enum ofputil_capabilities {
2e1ae200 407 /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
9e1fd49b
BP
408 OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */
409 OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */
410 OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */
411 OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
412 OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */
60202987
SH
413
414 /* OpenFlow 1.0 and 1.1 share this capability. */
9e1fd49b
BP
415 OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */
416
417 /* OpenFlow 1.0 only. */
418 OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */
419
2e1ae200 420 /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
9e1fd49b 421 OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */
60202987 422
2e1ae200 423 /* OpenFlow 1.2 and 1.3 share this capability */
60202987 424 OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */
9e1fd49b
BP
425};
426
427enum ofputil_action_bitmap {
428 OFPUTIL_A_OUTPUT = 1 << 0,
429 OFPUTIL_A_SET_VLAN_VID = 1 << 1,
430 OFPUTIL_A_SET_VLAN_PCP = 1 << 2,
431 OFPUTIL_A_STRIP_VLAN = 1 << 3,
432 OFPUTIL_A_SET_DL_SRC = 1 << 4,
433 OFPUTIL_A_SET_DL_DST = 1 << 5,
434 OFPUTIL_A_SET_NW_SRC = 1 << 6,
435 OFPUTIL_A_SET_NW_DST = 1 << 7,
436 OFPUTIL_A_SET_NW_ECN = 1 << 8,
437 OFPUTIL_A_SET_NW_TOS = 1 << 9,
438 OFPUTIL_A_SET_TP_SRC = 1 << 10,
439 OFPUTIL_A_SET_TP_DST = 1 << 11,
440 OFPUTIL_A_ENQUEUE = 1 << 12,
441 OFPUTIL_A_COPY_TTL_OUT = 1 << 13,
442 OFPUTIL_A_COPY_TTL_IN = 1 << 14,
443 OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
444 OFPUTIL_A_SET_MPLS_TC = 1 << 16,
445 OFPUTIL_A_SET_MPLS_TTL = 1 << 17,
446 OFPUTIL_A_DEC_MPLS_TTL = 1 << 18,
447 OFPUTIL_A_PUSH_VLAN = 1 << 19,
448 OFPUTIL_A_POP_VLAN = 1 << 20,
449 OFPUTIL_A_PUSH_MPLS = 1 << 21,
450 OFPUTIL_A_POP_MPLS = 1 << 22,
451 OFPUTIL_A_SET_QUEUE = 1 << 23,
452 OFPUTIL_A_GROUP = 1 << 24,
453 OFPUTIL_A_SET_NW_TTL = 1 << 25,
454 OFPUTIL_A_DEC_NW_TTL = 1 << 26,
78a3fff6 455 OFPUTIL_A_SET_FIELD = 1 << 27,
9e1fd49b
BP
456};
457
458/* Abstract ofp_switch_features. */
459struct ofputil_switch_features {
460 uint64_t datapath_id; /* Datapath unique ID. */
461 uint32_t n_buffers; /* Max packets buffered at once. */
462 uint8_t n_tables; /* Number of tables supported by datapath. */
2e1ae200 463 uint8_t auxiliary_id; /* Identify auxiliary connections */
9e1fd49b
BP
464 enum ofputil_capabilities capabilities;
465 enum ofputil_action_bitmap actions;
466};
467
982697a4 468enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
9e1fd49b
BP
469 struct ofputil_switch_features *,
470 struct ofpbuf *);
9e1fd49b
BP
471
472struct ofpbuf *ofputil_encode_switch_features(
473 const struct ofputil_switch_features *, enum ofputil_protocol,
474 ovs_be32 xid);
475void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
476 struct ofpbuf *);
347b7ac4 477bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
9e1fd49b 478
2be393ed 479/* phy_port helper functions. */
2e3fa633 480int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
2be393ed
JP
481 struct ofputil_phy_port *);
482size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
483
9e1fd49b
BP
484/* Abstract ofp_port_status. */
485struct ofputil_port_status {
486 enum ofp_port_reason reason;
487 struct ofputil_phy_port desc;
488};
489
982697a4 490enum ofperr ofputil_decode_port_status(const struct ofp_header *,
9e1fd49b
BP
491 struct ofputil_port_status *);
492struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
493 enum ofputil_protocol);
494
495/* Abstract ofp_port_mod. */
496struct ofputil_port_mod {
497 uint16_t port_no;
498 uint8_t hw_addr[OFP_ETH_ALEN];
499 enum ofputil_port_config config;
500 enum ofputil_port_config mask;
501 enum netdev_features advertise;
502};
503
504enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
505 struct ofputil_port_mod *);
506struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
507 enum ofputil_protocol);
6c038611 508
6ea4776b
JR
509/* Abstract ofp_role_request and reply. */
510struct ofputil_role_request {
f4f1ea7e 511 enum ofp12_controller_role role;
6ea4776b 512 bool have_generation_id;
6ea4776b
JR
513 uint64_t generation_id;
514};
515
516enum ofperr ofputil_decode_role_message(const struct ofp_header *,
517 struct ofputil_role_request *);
518struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
f4f1ea7e 519 const struct ofputil_role_request *);
6ea4776b 520
307975da
SH
521/* Abstract table stats.
522 *
523 * For now we use ofp12_table_stats as a superset of the other protocol
524 * versions' table stats. */
525
526struct ofpbuf *ofputil_encode_table_stats_reply(
527 const struct ofp12_table_stats[], int n,
528 const struct ofp_header *request);
529
2b07c8b1
BP
530/* Abstract nx_flow_monitor_request. */
531struct ofputil_flow_monitor_request {
532 uint32_t id;
533 enum nx_flow_monitor_flags flags;
534 uint16_t out_port;
535 uint8_t table_id;
81a76618 536 struct match match;
2b07c8b1
BP
537};
538
539int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
540 struct ofpbuf *msg);
541void ofputil_append_flow_monitor_request(
542 const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
543
544/* Abstract nx_flow_update. */
545struct ofputil_flow_update {
546 enum nx_flow_update_event event;
547
548 /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
549 enum ofp_flow_removed_reason reason;
550 uint16_t idle_timeout;
551 uint16_t hard_timeout;
552 uint8_t table_id;
553 ovs_be64 cookie;
81a76618
BP
554 struct match *match;
555 uint16_t priority;
2b07c8b1
BP
556 struct ofpact *ofpacts;
557 size_t ofpacts_len;
558
559 /* Used only for NXFME_ABBREV. */
560 ovs_be32 xid;
561};
562
563int ofputil_decode_flow_update(struct ofputil_flow_update *,
564 struct ofpbuf *msg, struct ofpbuf *ofpacts);
565void ofputil_start_flow_update(struct list *replies);
566void ofputil_append_flow_update(const struct ofputil_flow_update *,
567 struct list *replies);
568
569/* Abstract nx_flow_monitor_cancel. */
570uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
571struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
572
982697a4 573/* Encoding OpenFlow stats messages. */
2e3fa633 574void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
2be393ed
JP
575 const struct ofputil_phy_port *pp,
576 struct list *replies);
577
982697a4 578/* Encoding simple OpenFlow messages. */
1a126c0c 579struct ofpbuf *make_echo_request(enum ofp_version);
fa37b408 580struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
7257b535 581
a0ae0b6e 582struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
efb80167 583
7257b535
BP
584const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
585bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
2be393ed 586
9aee0764
BP
587\f
588/* Actions. */
589
e23ae585
BP
590/* The type of an action.
591 *
08f94c0e 592 * For each implemented OFPAT10_* and NXAST_* action type, there is a
e23ae585
BP
593 * corresponding constant prefixed with OFPUTIL_, e.g.:
594 *
08f94c0e
BP
595 * OFPUTIL_OFPAT10_OUTPUT
596 * OFPUTIL_OFPAT10_SET_VLAN_VID
597 * OFPUTIL_OFPAT10_SET_VLAN_PCP
598 * OFPUTIL_OFPAT10_STRIP_VLAN
599 * OFPUTIL_OFPAT10_SET_DL_SRC
600 * OFPUTIL_OFPAT10_SET_DL_DST
601 * OFPUTIL_OFPAT10_SET_NW_SRC
602 * OFPUTIL_OFPAT10_SET_NW_DST
603 * OFPUTIL_OFPAT10_SET_NW_TOS
604 * OFPUTIL_OFPAT10_SET_TP_SRC
605 * OFPUTIL_OFPAT10_SET_TP_DST
606 * OFPUTIL_OFPAT10_ENQUEUE
e23ae585
BP
607 * OFPUTIL_NXAST_RESUBMIT
608 * OFPUTIL_NXAST_SET_TUNNEL
4cceacb9 609 * OFPUTIL_NXAST_SET_METADATA
e23ae585
BP
610 * OFPUTIL_NXAST_SET_QUEUE
611 * OFPUTIL_NXAST_POP_QUEUE
612 * OFPUTIL_NXAST_REG_MOVE
613 * OFPUTIL_NXAST_REG_LOAD
614 * OFPUTIL_NXAST_NOTE
615 * OFPUTIL_NXAST_SET_TUNNEL64
616 * OFPUTIL_NXAST_MULTIPATH
e23ae585
BP
617 * OFPUTIL_NXAST_BUNDLE
618 * OFPUTIL_NXAST_BUNDLE_LOAD
619 * OFPUTIL_NXAST_RESUBMIT_TABLE
620 * OFPUTIL_NXAST_OUTPUT_REG
0e553d9c
BP
621 * OFPUTIL_NXAST_LEARN
622 * OFPUTIL_NXAST_DEC_TTL
623 * OFPUTIL_NXAST_FIN_TIMEOUT
e23ae585
BP
624 *
625 * (The above list helps developers who want to "grep" for these definitions.)
626 */
f25d0cf3 627enum OVS_PACKED_ENUM ofputil_action_code {
690a61c5 628 OFPUTIL_ACTION_INVALID,
3ddcaf2d
BP
629#define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
630#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
631#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
e23ae585
BP
632#include "ofp-util.def"
633};
634
635/* The number of values of "enum ofputil_action_code". */
636enum {
3ddcaf2d
BP
637#define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1
638#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
639#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
690a61c5 640 OFPUTIL_N_ACTIONS = 1
e23ae585 641#include "ofp-util.def"
38f2e360
BP
642};
643
e23ae585
BP
644int ofputil_action_code_from_name(const char *);
645
93996add
BP
646void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
647
648/* For each OpenFlow action <ENUM> that has a corresponding action structure
649 * struct <STRUCT>, this defines two functions:
650 *
651 * void ofputil_init_<ENUM>(struct <STRUCT> *action);
652 *
653 * Initializes the parts of 'action' that identify it as having type <ENUM>
654 * and length 'sizeof *action' and zeros the rest. For actions that have
655 * variable length, the length used and cleared is that of struct <STRUCT>.
656 *
657 * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
658 *
659 * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
660 * initializes it with ofputil_init_<ENUM>(), and returns it.
661 */
08f94c0e 662#define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
93996add
BP
663 void ofputil_init_##ENUM(struct STRUCT *); \
664 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
3ddcaf2d 665#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
d01c980f
BP
666 void ofputil_init_##ENUM(struct STRUCT *); \
667 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
93996add
BP
668#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
669 void ofputil_init_##ENUM(struct STRUCT *); \
670 struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
671#include "ofp-util.def"
672
9aee0764 673#define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
fa37b408 674
90bf1e07
BP
675enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
676 const struct flow *, int max_ports);
dbba996b 677bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
3052b0c5 678
90bf1e07
BP
679enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
680 union ofp_action **, size_t *);
18ddadc2
BP
681
682bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
683 const union ofp_action *b, size_t n_b);
684union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
26c112c2 685
0ff22822
BP
686/* Handy utility for parsing flows and actions. */
687bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
688
f8e4867e
SH
689struct ofputil_port_stats {
690 uint16_t port_no;
691 struct netdev_stats stats;
692};
693
694struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
695 int16_t port);
696void ofputil_append_port_stat(struct list *replies,
697 const struct ofputil_port_stats *ops);
698size_t ofputil_count_port_stats(const struct ofp_header *);
699int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
700enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
701 uint16_t *ofp10_port);
64626975
SH
702
703struct ofputil_queue_stats_request {
7f05e7ab 704 uint16_t port_no; /* OFPP_ANY means "all ports". */
64626975
SH
705 uint32_t queue_id;
706};
707
708enum ofperr
709ofputil_decode_queue_stats_request(const struct ofp_header *request,
710 struct ofputil_queue_stats_request *oqsr);
711struct ofpbuf *
712ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
713 const struct ofputil_queue_stats_request *oqsr);
714
715struct ofputil_queue_stats {
716 uint16_t port_no;
717 uint32_t queue_id;
718 struct netdev_queue_stats stats;
719};
720
721size_t ofputil_count_queue_stats(const struct ofp_header *);
722int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
723void ofputil_append_queue_stat(struct list *replies,
724 const struct ofputil_queue_stats *oqs);
725
fa37b408 726#endif /* ofp-util.h */