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