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