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