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