]>
Commit | Line | Data |
---|---|---|
fa37b408 | 1 | /* |
f4f1ea7e | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. |
fa37b408 BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef OFP_UTIL_H | |
18 | #define OFP_UTIL_H 1 | |
19 | ||
c1c9c9c4 | 20 | #include <stdbool.h> |
fa37b408 BP |
21 | #include <stddef.h> |
22 | #include <stdint.h> | |
d1e2cf21 | 23 | #include "classifier.h" |
f25d0cf3 | 24 | #include "compiler.h" |
fa37b408 | 25 | #include "flow.h" |
81a76618 | 26 | #include "match.h" |
6c038611 | 27 | #include "netdev.h" |
492f7572 | 28 | #include "openflow/nicira-ext.h" |
44381c1b | 29 | #include "openvswitch/types.h" |
5014a89d | 30 | #include "type-props.h" |
fa37b408 BP |
31 | |
32 | struct ofpbuf; | |
e45e72f1 | 33 | union ofp_action; |
fa37b408 | 34 | |
39dc9082 | 35 | /* Port numbers. */ |
4e022ec0 AW |
36 | enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port, |
37 | ofp_port_t *ofp10_port); | |
38 | ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port); | |
7b7503ea | 39 | |
4e022ec0 AW |
40 | enum ofperr ofputil_check_output_port(ofp_port_t ofp_port, |
41 | ofp_port_t max_ports); | |
42 | bool ofputil_port_from_string(const char *, ofp_port_t *portp); | |
43 | void ofputil_format_port(ofp_port_t port, struct ds *); | |
28b11432 BP |
44 | void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN], |
45 | size_t bufsize); | |
d1e2cf21 | 46 | |
7395c052 NZ |
47 | /* Group numbers. */ |
48 | enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) }; | |
49 | bool ofputil_group_from_string(const char *, uint32_t *group_id); | |
50 | void ofputil_format_group(uint32_t group_id, struct ds *); | |
51 | void ofputil_group_to_string(uint32_t group_id, | |
52 | char namebuf[MAX_GROUP_NAME_LEN + 1], | |
53 | size_t bufsize); | |
54 | ||
eec25dc1 BP |
55 | /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts |
56 | * to and from IP bitmasks. */ | |
0596e897 BP |
57 | ovs_be32 ofputil_wcbits_to_netmask(int wcbits); |
58 | int ofputil_netmask_to_wcbits(ovs_be32 netmask); | |
59 | ||
27527aa0 | 60 | /* Protocols. |
85813857 BP |
61 | * |
62 | * A "protocol" is an OpenFlow version plus, for some OpenFlow versions, | |
63 | * a bit extra about the flow match format in use. | |
27527aa0 BP |
64 | * |
65 | * These are arranged from most portable to least portable, or alternatively | |
85813857 BP |
66 | * from least powerful to most powerful. Protocols earlier on the list are |
67 | * more likely to be understood for the purpose of making requests, but | |
68 | * protocol later on the list are more likely to accurately describe a flow | |
69 | * within a switch. | |
27527aa0 BP |
70 | * |
71 | * On any given OpenFlow connection, a single protocol is in effect at any | |
72 | * given time. These values use separate bits only because that makes it easy | |
73 | * to test whether a particular protocol is within a given set of protocols and | |
74 | * to implement set union and intersection. | |
75 | */ | |
76 | enum ofputil_protocol { | |
85813857 BP |
77 | /* OpenFlow 1.0 protocols. |
78 | * | |
79 | * The "STD" protocols use the standard OpenFlow 1.0 flow format. | |
80 | * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format. | |
81 | * | |
82 | * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira | |
83 | * extension has been enabled. The other protocols have it disabled. | |
84 | */ | |
eb12aa89 | 85 | #define OFPUTIL_P_NONE 0 |
85813857 BP |
86 | OFPUTIL_P_OF10_STD = 1 << 0, |
87 | OFPUTIL_P_OF10_STD_TID = 1 << 1, | |
88 | OFPUTIL_P_OF10_NXM = 1 << 2, | |
89 | OFPUTIL_P_OF10_NXM_TID = 1 << 3, | |
90 | #define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID) | |
91 | #define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID) | |
8621547c | 92 | #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY) |
27527aa0 | 93 | |
75fa58f8 BP |
94 | /* OpenFlow 1.1 protocol. |
95 | * | |
96 | * We only support the standard OpenFlow 1.1 flow format. | |
97 | * | |
98 | * OpenFlow 1.1 always operates with an equivalent of the | |
99 | * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID" | |
100 | * variant. */ | |
101 | OFPUTIL_P_OF11_STD = 1 << 4, | |
102 | ||
2e1ae200 | 103 | /* OpenFlow 1.2+ protocols (only one variant each). |
85813857 | 104 | * |
2e1ae200 | 105 | * These use the standard OpenFlow Extensible Match (OXM) flow format. |
85813857 | 106 | * |
2e1ae200 | 107 | * OpenFlow 1.2+ always operates with an equivalent of the |
85813857 BP |
108 | * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID" |
109 | * variant. */ | |
75fa58f8 BP |
110 | OFPUTIL_P_OF12_OXM = 1 << 5, |
111 | OFPUTIL_P_OF13_OXM = 1 << 6, | |
e71bff1b | 112 | #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM) |
44d3732d | 113 | |
db0b6c29 JR |
114 | #define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \ |
115 | OFPUTIL_P_ANY_OXM) | |
116 | ||
117 | #define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM) | |
118 | ||
119 | #define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM) | |
120 | ||
121 | #define OFPUTIL_P_OF12_UP (OFPUTIL_P_ANY_OXM) | |
122 | ||
123 | #define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM) | |
124 | ||
27527aa0 | 125 | /* All protocols. */ |
75fa58f8 | 126 | #define OFPUTIL_P_ANY ((1 << 7) - 1) |
27527aa0 BP |
127 | |
128 | /* Protocols in which a specific table may be specified in flow_mods. */ | |
7cd90356 BP |
129 | #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \ |
130 | OFPUTIL_P_OF10_NXM_TID | \ | |
75fa58f8 | 131 | OFPUTIL_P_OF11_STD | \ |
4f13da56 | 132 | OFPUTIL_P_ANY_OXM) |
27527aa0 BP |
133 | }; |
134 | ||
135 | /* Protocols to use for flow dumps, from most to least preferred. */ | |
136 | extern enum ofputil_protocol ofputil_flow_dump_protocols[]; | |
137 | extern size_t ofputil_n_flow_dump_protocols; | |
138 | ||
6d2c051a | 139 | enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version); |
4f13da56 BP |
140 | enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version); |
141 | enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol); | |
9e1fd49b | 142 | |
27527aa0 BP |
143 | bool ofputil_protocol_is_valid(enum ofputil_protocol); |
144 | enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol, | |
145 | bool enable); | |
146 | enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol); | |
147 | enum ofputil_protocol ofputil_protocol_set_base( | |
148 | enum ofputil_protocol cur, enum ofputil_protocol new_base); | |
149 | ||
150 | const char *ofputil_protocol_to_string(enum ofputil_protocol); | |
151 | char *ofputil_protocols_to_string(enum ofputil_protocol); | |
152 | enum ofputil_protocol ofputil_protocols_from_string(const char *); | |
27527aa0 | 153 | |
03e1125c SH |
154 | void ofputil_format_version(struct ds *, enum ofp_version); |
155 | void ofputil_format_version_name(struct ds *, enum ofp_version); | |
156 | ||
157 | /* A bitmap of version numbers | |
158 | * | |
159 | * Bit offsets correspond to ofp_version numbers which in turn correspond to | |
160 | * wire-protocol numbers for Open Flow versions.. E.g. (1u << OFP11_VERSION) | |
161 | * is the mask for Open Flow 1.1. If the bit for a version is set then it is | |
162 | * allowed, otherwise it is disallowed. */ | |
163 | ||
164 | void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap); | |
165 | void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap); | |
166 | ||
4f13da56 BP |
167 | uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol); |
168 | enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap); | |
169 | ||
03e1125c SH |
170 | /* Bitmap of OpenFlow versions that Open vSwitch supports. */ |
171 | #define OFPUTIL_SUPPORTED_VERSIONS \ | |
2e1ae200 | 172 | ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION)) |
03e1125c SH |
173 | |
174 | /* Bitmap of OpenFlow versions to enable by default (a subset of | |
175 | * OFPUTIL_SUPPORTED_VERSIONS). */ | |
176 | #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION) | |
177 | ||
178 | enum ofputil_protocol ofputil_protocols_from_string(const char *s); | |
179 | ||
180 | const char *ofputil_version_to_string(enum ofp_version ofp_version); | |
181 | uint32_t ofputil_versions_from_string(const char *s); | |
7beaa082 | 182 | uint32_t ofputil_versions_from_strings(char ** const s, size_t count); |
03e1125c | 183 | |
de6c85b0 SH |
184 | bool ofputil_decode_hello(const struct ofp_header *, |
185 | uint32_t *allowed_versions); | |
186 | struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap); | |
187 | ||
27527aa0 BP |
188 | struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current, |
189 | enum ofputil_protocol want, | |
190 | enum ofputil_protocol *next); | |
191 | ||
192 | /* nx_flow_format */ | |
193 | struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format); | |
194 | enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format); | |
195 | bool ofputil_nx_flow_format_is_valid(enum nx_flow_format); | |
196 | const char *ofputil_nx_flow_format_to_string(enum nx_flow_format); | |
197 | ||
eec25dc1 BP |
198 | /* Work with ofp10_match. */ |
199 | void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *); | |
81a76618 BP |
200 | void ofputil_match_from_ofp10_match(const struct ofp10_match *, |
201 | struct match *); | |
202 | void ofputil_normalize_match(struct match *); | |
203 | void ofputil_normalize_match_quiet(struct match *); | |
204 | void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *); | |
d8ae4d67 | 205 | |
410698cf | 206 | /* Work with ofp11_match. */ |
81a76618 | 207 | enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *, |
36a16881 | 208 | uint16_t *padded_match_len); |
81a76618 BP |
209 | enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *, |
210 | struct match *); | |
75fa58f8 BP |
211 | int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *, |
212 | enum ofputil_protocol); | |
81a76618 | 213 | void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *); |
75fa58f8 | 214 | int ofputil_match_typical_len(enum ofputil_protocol); |
410698cf | 215 | |
36956a7d BP |
216 | /* dl_type translation between OpenFlow and 'struct flow' format. */ |
217 | ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type); | |
218 | ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type); | |
219 | ||
54834960 EJ |
220 | /* PACKET_IN. */ |
221 | bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format); | |
222 | int ofputil_packet_in_format_from_string(const char *); | |
223 | const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format); | |
3f4a1939 SH |
224 | struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version, |
225 | enum nx_packet_in_format); | |
54834960 | 226 | |
6c1491fb BP |
227 | /* NXT_FLOW_MOD_TABLE_ID extension. */ |
228 | struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id); | |
229 | ||
0fb88c18 BP |
230 | /* Protocol-independent flow_mod flags. */ |
231 | enum ofputil_flow_mod_flags { | |
3f517bcd DB |
232 | /* Flags that are maintained with a flow as part of its state. |
233 | * | |
234 | * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */ | |
0fb88c18 | 235 | OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */ |
3f517bcd DB |
236 | OFPUTIL_FF_NO_PKT_COUNTS = 1 << 1, /* OpenFlow 1.3+. */ |
237 | OFPUTIL_FF_NO_BYT_COUNTS = 1 << 2, /* OpenFlow 1.3+. */ | |
238 | #define OFPUTIL_FF_STATE (OFPUTIL_FF_SEND_FLOW_REM \ | |
239 | | OFPUTIL_FF_NO_PKT_COUNTS \ | |
240 | | OFPUTIL_FF_NO_BYT_COUNTS) | |
241 | ||
242 | /* Flags that affect flow_mod behavior but are not part of flow state. */ | |
243 | OFPUTIL_FF_CHECK_OVERLAP = 1 << 3, /* All versions. */ | |
244 | OFPUTIL_FF_EMERG = 1 << 4, /* OpenFlow 1.0 only. */ | |
245 | OFPUTIL_FF_RESET_COUNTS = 1 << 5, /* OpenFlow 1.2+. */ | |
0fb88c18 BP |
246 | }; |
247 | ||
623e1caf JP |
248 | /* Protocol-independent flow_mod. |
249 | * | |
250 | * The handling of cookies across multiple versions of OpenFlow is a bit | |
23342857 | 251 | * confusing. See DESIGN for the details. */ |
a9a2da38 | 252 | struct ofputil_flow_mod { |
3d9c5e58 EJ |
253 | struct list list_node; /* For queuing flow_mods. */ |
254 | ||
81a76618 BP |
255 | struct match match; |
256 | unsigned int priority; | |
23342857 BP |
257 | |
258 | /* Cookie matching. The flow_mod affects only flows that have cookies that | |
259 | * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits. | |
260 | * | |
261 | * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */ | |
623e1caf JP |
262 | ovs_be64 cookie; /* Cookie bits to match. */ |
263 | ovs_be64 cookie_mask; /* 1-bit in each 'cookie' bit to match. */ | |
23342857 BP |
264 | |
265 | /* Cookie changes. | |
266 | * | |
267 | * OFPFC_ADD uses 'new_cookie' as the new flow's cookie. 'new_cookie' | |
268 | * should not be UINT64_MAX. | |
269 | * | |
270 | * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases: | |
271 | * | |
272 | * - If one or more matching flows exist and 'modify_cookie' is true, | |
273 | * then the flow_mod changes the existing flows' cookies to | |
274 | * 'new_cookie'. 'new_cookie' should not be UINT64_MAX. | |
275 | * | |
276 | * - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and | |
277 | * 'cookie_mask' is 0, then the flow_mod adds a new flow with | |
278 | * 'new_cookie' as its cookie. | |
279 | */ | |
280 | ovs_be64 new_cookie; /* New cookie to install or UINT64_MAX. */ | |
281 | bool modify_cookie; /* Set cookie of existing flow to 'new_cookie'? */ | |
282 | ||
6c1491fb | 283 | uint8_t table_id; |
2e4f5fcf BP |
284 | uint16_t command; |
285 | uint16_t idle_timeout; | |
286 | uint16_t hard_timeout; | |
287 | uint32_t buffer_id; | |
4e022ec0 | 288 | ofp_port_t out_port; |
7395c052 | 289 | uint32_t out_group; |
0fb88c18 | 290 | enum ofputil_flow_mod_flags flags; |
f25d0cf3 BP |
291 | struct ofpact *ofpacts; /* Series of "struct ofpact"s. */ |
292 | size_t ofpacts_len; /* Length of ofpacts, in bytes. */ | |
2e4f5fcf BP |
293 | }; |
294 | ||
90bf1e07 BP |
295 | enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *, |
296 | const struct ofp_header *, | |
f25d0cf3 BP |
297 | enum ofputil_protocol, |
298 | struct ofpbuf *ofpacts); | |
a9a2da38 | 299 | struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *, |
27527aa0 BP |
300 | enum ofputil_protocol); |
301 | ||
27527aa0 | 302 | /* Flow stats or aggregate stats request, independent of protocol. */ |
81d1ea94 | 303 | struct ofputil_flow_stats_request { |
2e4f5fcf | 304 | bool aggregate; /* Aggregate results? */ |
81a76618 | 305 | struct match match; |
e729e793 JP |
306 | ovs_be64 cookie; |
307 | ovs_be64 cookie_mask; | |
4e022ec0 | 308 | ofp_port_t out_port; |
7395c052 | 309 | uint32_t out_group; |
2e4f5fcf BP |
310 | uint8_t table_id; |
311 | }; | |
312 | ||
90bf1e07 BP |
313 | enum ofperr ofputil_decode_flow_stats_request( |
314 | struct ofputil_flow_stats_request *, const struct ofp_header *); | |
2e4f5fcf | 315 | struct ofpbuf *ofputil_encode_flow_stats_request( |
27527aa0 | 316 | const struct ofputil_flow_stats_request *, enum ofputil_protocol); |
2e4f5fcf | 317 | |
27527aa0 | 318 | /* Flow stats reply, independent of protocol. */ |
4ffd1b43 | 319 | struct ofputil_flow_stats { |
81a76618 | 320 | struct match match; |
4ffd1b43 BP |
321 | ovs_be64 cookie; |
322 | uint8_t table_id; | |
323 | uint32_t duration_sec; | |
324 | uint32_t duration_nsec; | |
81a76618 | 325 | uint16_t priority; |
4ffd1b43 BP |
326 | uint16_t idle_timeout; |
327 | uint16_t hard_timeout; | |
f27f2134 BP |
328 | int idle_age; /* Seconds since last packet, -1 if unknown. */ |
329 | int hard_age; /* Seconds since last change, -1 if unknown. */ | |
5e9d0469 BP |
330 | uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */ |
331 | uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */ | |
f25d0cf3 BP |
332 | struct ofpact *ofpacts; |
333 | size_t ofpacts_len; | |
0fb88c18 | 334 | enum ofputil_flow_mod_flags flags; |
4ffd1b43 BP |
335 | }; |
336 | ||
337 | int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *, | |
f27f2134 | 338 | struct ofpbuf *msg, |
f25d0cf3 BP |
339 | bool flow_age_extension, |
340 | struct ofpbuf *ofpacts); | |
349adfb2 BP |
341 | void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *, |
342 | struct list *replies); | |
4ffd1b43 | 343 | |
27527aa0 | 344 | /* Aggregate stats reply, independent of protocol. */ |
76c93b22 | 345 | struct ofputil_aggregate_stats { |
5e9d0469 BP |
346 | uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */ |
347 | uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */ | |
76c93b22 BP |
348 | uint32_t flow_count; |
349 | }; | |
350 | ||
351 | struct ofpbuf *ofputil_encode_aggregate_stats_reply( | |
352 | const struct ofputil_aggregate_stats *stats, | |
982697a4 BP |
353 | const struct ofp_header *request); |
354 | enum ofperr ofputil_decode_aggregate_stats_reply( | |
355 | struct ofputil_aggregate_stats *, | |
356 | const struct ofp_header *reply); | |
76c93b22 | 357 | |
27527aa0 | 358 | /* Flow removed message, independent of protocol. */ |
9b045a0c | 359 | struct ofputil_flow_removed { |
81a76618 BP |
360 | struct match match; |
361 | uint16_t priority; | |
9b045a0c BP |
362 | ovs_be64 cookie; |
363 | uint8_t reason; /* One of OFPRR_*. */ | |
95216219 | 364 | uint8_t table_id; /* 255 if message didn't include table ID. */ |
9b045a0c BP |
365 | uint32_t duration_sec; |
366 | uint32_t duration_nsec; | |
367 | uint16_t idle_timeout; | |
fa2bad0f | 368 | uint16_t hard_timeout; |
5e9d0469 BP |
369 | uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */ |
370 | uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */ | |
9b045a0c BP |
371 | }; |
372 | ||
90bf1e07 BP |
373 | enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *, |
374 | const struct ofp_header *); | |
588cd7b5 | 375 | struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *, |
27527aa0 | 376 | enum ofputil_protocol); |
9b045a0c | 377 | |
ebb57021 BP |
378 | /* Abstract packet-in message. */ |
379 | struct ofputil_packet_in { | |
22ee3544 BP |
380 | /* Packet data and metadata. |
381 | * | |
382 | * To save bandwidth, in some cases a switch may send only the first | |
383 | * several bytes of a packet, indicated by 'packet_len < total_len'. When | |
384 | * the full packet is included, 'packet_len == total_len'. */ | |
3e3252fa | 385 | const void *packet; |
22ee3544 BP |
386 | size_t packet_len; /* Number of bytes in 'packet'. */ |
387 | size_t total_len; /* Size of packet, pre-truncation. */ | |
388 | struct flow_metadata fmd; | |
ebb57021 | 389 | |
22ee3544 BP |
390 | /* Identifies a buffer in the switch that contains the full packet, to |
391 | * allow the controller to reference it later without having to send the | |
392 | * entire packet back to the switch. | |
393 | * | |
394 | * UINT32_MAX indicates that the packet is not buffered in the switch. A | |
395 | * switch should only use UINT32_MAX when it sends the entire packet. */ | |
ebb57021 | 396 | uint32_t buffer_id; |
5d6c3af0 | 397 | |
22ee3544 BP |
398 | /* Reason that the packet-in is being sent. */ |
399 | enum ofp_packet_in_reason reason; /* One of OFPR_*. */ | |
400 | ||
401 | /* Information about the OpenFlow flow that triggered the packet-in. | |
402 | * | |
403 | * A packet-in triggered by a flow table miss has no associated flow. In | |
d4fa4e79 | 404 | * that case, 'cookie' is UINT64_MAX. */ |
22ee3544 BP |
405 | uint8_t table_id; /* OpenFlow table ID. */ |
406 | ovs_be64 cookie; /* Flow's cookie. */ | |
ebb57021 BP |
407 | }; |
408 | ||
f7cc6bd8 BP |
409 | enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *, |
410 | const struct ofp_header *); | |
54834960 | 411 | struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *, |
d94240ec | 412 | enum ofputil_protocol protocol, |
54834960 | 413 | enum nx_packet_in_format); |
ebb57021 | 414 | |
5014a89d BP |
415 | enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 }; |
416 | const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason, | |
417 | char *reasonbuf, | |
418 | size_t bufsize); | |
7c1a76a4 BP |
419 | bool ofputil_packet_in_reason_from_string(const char *, |
420 | enum ofp_packet_in_reason *); | |
421 | ||
751c7785 BP |
422 | /* Abstract packet-out message. |
423 | * | |
424 | * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port | |
425 | * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */ | |
c6a93eb7 BP |
426 | struct ofputil_packet_out { |
427 | const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */ | |
428 | size_t packet_len; /* Length of packet data in bytes. */ | |
429 | uint32_t buffer_id; /* Buffer id or UINT32_MAX if no buffer. */ | |
4e022ec0 | 430 | ofp_port_t in_port; /* Packet's input port. */ |
f25d0cf3 BP |
431 | struct ofpact *ofpacts; /* Actions. */ |
432 | size_t ofpacts_len; /* Size of ofpacts in bytes. */ | |
c6a93eb7 BP |
433 | }; |
434 | ||
435 | enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *, | |
982697a4 | 436 | const struct ofp_header *, |
f25d0cf3 | 437 | struct ofpbuf *ofpacts); |
de0f3156 SH |
438 | struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *, |
439 | enum ofputil_protocol protocol); | |
c6a93eb7 | 440 | |
9e1fd49b BP |
441 | enum ofputil_port_config { |
442 | /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */ | |
443 | OFPUTIL_PC_PORT_DOWN = 1 << 0, /* Port is administratively down. */ | |
444 | OFPUTIL_PC_NO_RECV = 1 << 2, /* Drop all packets received by port. */ | |
445 | OFPUTIL_PC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */ | |
446 | OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */ | |
447 | /* OpenFlow 1.0 only. */ | |
448 | OFPUTIL_PC_NO_STP = 1 << 1, /* No 802.1D spanning tree for port. */ | |
449 | OFPUTIL_PC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */ | |
450 | OFPUTIL_PC_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */ | |
451 | /* There are no OpenFlow 1.1-only bits. */ | |
452 | }; | |
453 | ||
454 | enum ofputil_port_state { | |
455 | /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */ | |
456 | OFPUTIL_PS_LINK_DOWN = 1 << 0, /* No physical link present. */ | |
457 | /* OpenFlow 1.1 only. */ | |
458 | OFPUTIL_PS_BLOCKED = 1 << 1, /* Port is blocked */ | |
459 | OFPUTIL_PS_LIVE = 1 << 2, /* Live for Fast Failover Group. */ | |
460 | /* OpenFlow 1.0 only. */ | |
461 | OFPUTIL_PS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */ | |
462 | OFPUTIL_PS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */ | |
463 | OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */ | |
464 | OFPUTIL_PS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */ | |
465 | OFPUTIL_PS_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */ | |
466 | }; | |
467 | ||
468 | /* Abstract ofp10_phy_port or ofp11_port. */ | |
469 | struct ofputil_phy_port { | |
4e022ec0 | 470 | ofp_port_t port_no; |
9e1fd49b BP |
471 | uint8_t hw_addr[OFP_ETH_ALEN]; |
472 | char name[OFP_MAX_PORT_NAME_LEN]; | |
473 | enum ofputil_port_config config; | |
474 | enum ofputil_port_state state; | |
475 | ||
476 | /* NETDEV_F_* feature bitmasks. */ | |
477 | enum netdev_features curr; /* Current features. */ | |
478 | enum netdev_features advertised; /* Features advertised by the port. */ | |
479 | enum netdev_features supported; /* Features supported by the port. */ | |
480 | enum netdev_features peer; /* Features advertised by peer. */ | |
481 | ||
482 | /* Speed. */ | |
483 | uint32_t curr_speed; /* Current speed, in kbps. */ | |
484 | uint32_t max_speed; /* Maximum supported speed, in kbps. */ | |
485 | }; | |
486 | ||
487 | enum ofputil_capabilities { | |
2e1ae200 | 488 | /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */ |
9e1fd49b BP |
489 | OFPUTIL_C_FLOW_STATS = 1 << 0, /* Flow statistics. */ |
490 | OFPUTIL_C_TABLE_STATS = 1 << 1, /* Table statistics. */ | |
491 | OFPUTIL_C_PORT_STATS = 1 << 2, /* Port statistics. */ | |
492 | OFPUTIL_C_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */ | |
493 | OFPUTIL_C_QUEUE_STATS = 1 << 6, /* Queue statistics. */ | |
60202987 SH |
494 | |
495 | /* OpenFlow 1.0 and 1.1 share this capability. */ | |
9e1fd49b BP |
496 | OFPUTIL_C_ARP_MATCH_IP = 1 << 7, /* Match IP addresses in ARP pkts. */ |
497 | ||
498 | /* OpenFlow 1.0 only. */ | |
499 | OFPUTIL_C_STP = 1 << 3, /* 802.1d spanning tree. */ | |
500 | ||
2e1ae200 | 501 | /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */ |
9e1fd49b | 502 | OFPUTIL_C_GROUP_STATS = 1 << 4, /* Group statistics. */ |
60202987 | 503 | |
2e1ae200 | 504 | /* OpenFlow 1.2 and 1.3 share this capability */ |
60202987 | 505 | OFPUTIL_C_PORT_BLOCKED = 1 << 8, /* Switch will block looping ports */ |
9e1fd49b BP |
506 | }; |
507 | ||
508 | enum ofputil_action_bitmap { | |
509 | OFPUTIL_A_OUTPUT = 1 << 0, | |
510 | OFPUTIL_A_SET_VLAN_VID = 1 << 1, | |
511 | OFPUTIL_A_SET_VLAN_PCP = 1 << 2, | |
512 | OFPUTIL_A_STRIP_VLAN = 1 << 3, | |
513 | OFPUTIL_A_SET_DL_SRC = 1 << 4, | |
514 | OFPUTIL_A_SET_DL_DST = 1 << 5, | |
515 | OFPUTIL_A_SET_NW_SRC = 1 << 6, | |
516 | OFPUTIL_A_SET_NW_DST = 1 << 7, | |
517 | OFPUTIL_A_SET_NW_ECN = 1 << 8, | |
518 | OFPUTIL_A_SET_NW_TOS = 1 << 9, | |
519 | OFPUTIL_A_SET_TP_SRC = 1 << 10, | |
520 | OFPUTIL_A_SET_TP_DST = 1 << 11, | |
521 | OFPUTIL_A_ENQUEUE = 1 << 12, | |
522 | OFPUTIL_A_COPY_TTL_OUT = 1 << 13, | |
523 | OFPUTIL_A_COPY_TTL_IN = 1 << 14, | |
524 | OFPUTIL_A_SET_MPLS_LABEL = 1 << 15, | |
525 | OFPUTIL_A_SET_MPLS_TC = 1 << 16, | |
526 | OFPUTIL_A_SET_MPLS_TTL = 1 << 17, | |
527 | OFPUTIL_A_DEC_MPLS_TTL = 1 << 18, | |
528 | OFPUTIL_A_PUSH_VLAN = 1 << 19, | |
529 | OFPUTIL_A_POP_VLAN = 1 << 20, | |
530 | OFPUTIL_A_PUSH_MPLS = 1 << 21, | |
531 | OFPUTIL_A_POP_MPLS = 1 << 22, | |
532 | OFPUTIL_A_SET_QUEUE = 1 << 23, | |
533 | OFPUTIL_A_GROUP = 1 << 24, | |
534 | OFPUTIL_A_SET_NW_TTL = 1 << 25, | |
535 | OFPUTIL_A_DEC_NW_TTL = 1 << 26, | |
78a3fff6 | 536 | OFPUTIL_A_SET_FIELD = 1 << 27, |
9e1fd49b BP |
537 | }; |
538 | ||
539 | /* Abstract ofp_switch_features. */ | |
540 | struct ofputil_switch_features { | |
541 | uint64_t datapath_id; /* Datapath unique ID. */ | |
542 | uint32_t n_buffers; /* Max packets buffered at once. */ | |
543 | uint8_t n_tables; /* Number of tables supported by datapath. */ | |
2e1ae200 | 544 | uint8_t auxiliary_id; /* Identify auxiliary connections */ |
9e1fd49b BP |
545 | enum ofputil_capabilities capabilities; |
546 | enum ofputil_action_bitmap actions; | |
547 | }; | |
548 | ||
982697a4 | 549 | enum ofperr ofputil_decode_switch_features(const struct ofp_header *, |
9e1fd49b BP |
550 | struct ofputil_switch_features *, |
551 | struct ofpbuf *); | |
9e1fd49b BP |
552 | |
553 | struct ofpbuf *ofputil_encode_switch_features( | |
554 | const struct ofputil_switch_features *, enum ofputil_protocol, | |
555 | ovs_be32 xid); | |
556 | void ofputil_put_switch_features_port(const struct ofputil_phy_port *, | |
557 | struct ofpbuf *); | |
347b7ac4 | 558 | bool ofputil_switch_features_ports_trunc(struct ofpbuf *b); |
9e1fd49b | 559 | |
2be393ed | 560 | /* phy_port helper functions. */ |
2e3fa633 | 561 | int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *, |
2be393ed JP |
562 | struct ofputil_phy_port *); |
563 | size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *); | |
564 | ||
9e1fd49b BP |
565 | /* Abstract ofp_port_status. */ |
566 | struct ofputil_port_status { | |
567 | enum ofp_port_reason reason; | |
568 | struct ofputil_phy_port desc; | |
569 | }; | |
570 | ||
982697a4 | 571 | enum ofperr ofputil_decode_port_status(const struct ofp_header *, |
9e1fd49b BP |
572 | struct ofputil_port_status *); |
573 | struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *, | |
574 | enum ofputil_protocol); | |
575 | ||
576 | /* Abstract ofp_port_mod. */ | |
577 | struct ofputil_port_mod { | |
4e022ec0 | 578 | ofp_port_t port_no; |
9e1fd49b BP |
579 | uint8_t hw_addr[OFP_ETH_ALEN]; |
580 | enum ofputil_port_config config; | |
581 | enum ofputil_port_config mask; | |
582 | enum netdev_features advertise; | |
583 | }; | |
584 | ||
585 | enum ofperr ofputil_decode_port_mod(const struct ofp_header *, | |
586 | struct ofputil_port_mod *); | |
587 | struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *, | |
588 | enum ofputil_protocol); | |
6c038611 | 589 | |
918f2b82 AZ |
590 | /* Abstract ofp_table_mod. */ |
591 | struct ofputil_table_mod { | |
592 | uint8_t table_id; /* ID of the table, 0xff indicates all tables. */ | |
593 | uint32_t config; | |
594 | }; | |
595 | ||
596 | enum ofperr ofputil_decode_table_mod(const struct ofp_header *, | |
597 | struct ofputil_table_mod *); | |
598 | struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *, | |
599 | enum ofputil_protocol); | |
600 | ||
0445637d | 601 | /* Meter band configuration for all supported band types. */ |
638a19b0 JR |
602 | struct ofputil_meter_band { |
603 | uint16_t type; | |
0445637d | 604 | uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */ |
638a19b0 JR |
605 | uint32_t rate; |
606 | uint32_t burst_size; | |
607 | }; | |
608 | ||
609 | struct ofputil_meter_band_stats { | |
610 | uint64_t packet_count; | |
611 | uint64_t byte_count; | |
612 | }; | |
613 | ||
614 | struct ofputil_meter_config { | |
615 | uint32_t meter_id; | |
616 | uint16_t flags; | |
617 | uint16_t n_bands; | |
618 | struct ofputil_meter_band *bands; | |
619 | }; | |
620 | ||
621 | /* Abstract ofp_meter_mod. */ | |
622 | struct ofputil_meter_mod { | |
623 | uint16_t command; | |
624 | struct ofputil_meter_config meter; | |
625 | }; | |
626 | ||
627 | struct ofputil_meter_stats { | |
628 | uint32_t meter_id; | |
629 | uint32_t flow_count; | |
630 | uint64_t packet_in_count; | |
631 | uint64_t byte_in_count; | |
632 | uint32_t duration_sec; | |
633 | uint32_t duration_nsec; | |
634 | uint16_t n_bands; | |
0445637d | 635 | struct ofputil_meter_band_stats *bands; |
638a19b0 JR |
636 | }; |
637 | ||
638 | struct ofputil_meter_features { | |
0445637d JR |
639 | uint32_t max_meters; /* Maximum number of meters. */ |
640 | uint32_t band_types; /* Can support max 32 band types. */ | |
641 | uint32_t capabilities; /* Supported flags. */ | |
638a19b0 JR |
642 | uint8_t max_bands; |
643 | uint8_t max_color; | |
644 | }; | |
645 | ||
646 | enum ofperr ofputil_decode_meter_mod(const struct ofp_header *, | |
647 | struct ofputil_meter_mod *, | |
0445637d JR |
648 | struct ofpbuf *bands); |
649 | struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version, | |
638a19b0 JR |
650 | const struct ofputil_meter_mod *); |
651 | ||
652 | void ofputil_decode_meter_features(const struct ofp_header *, | |
653 | struct ofputil_meter_features *); | |
654 | struct ofpbuf *ofputil_encode_meter_features_reply(const struct | |
655 | ofputil_meter_features *, | |
656 | const struct ofp_header * | |
657 | request); | |
658 | void ofputil_decode_meter_request(const struct ofp_header *, | |
659 | uint32_t *meter_id); | |
660 | ||
661 | void ofputil_append_meter_config(struct list *replies, | |
0445637d | 662 | const struct ofputil_meter_config *); |
638a19b0 JR |
663 | |
664 | void ofputil_append_meter_stats(struct list *replies, | |
0445637d | 665 | const struct ofputil_meter_stats *); |
638a19b0 JR |
666 | |
667 | enum ofputil_meter_request_type { | |
668 | OFPUTIL_METER_FEATURES, | |
669 | OFPUTIL_METER_CONFIG, | |
670 | OFPUTIL_METER_STATS | |
671 | }; | |
672 | ||
673 | struct ofpbuf *ofputil_encode_meter_request(enum ofp_version, | |
674 | enum ofputil_meter_request_type, | |
675 | uint32_t meter_id); | |
676 | ||
0445637d JR |
677 | int ofputil_decode_meter_stats(struct ofpbuf *, |
678 | struct ofputil_meter_stats *, | |
638a19b0 JR |
679 | struct ofpbuf *bands); |
680 | ||
0445637d JR |
681 | int ofputil_decode_meter_config(struct ofpbuf *, |
682 | struct ofputil_meter_config *, | |
638a19b0 JR |
683 | struct ofpbuf *bands); |
684 | ||
0445637d | 685 | /* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */ |
638a19b0 JR |
686 | typedef struct { uint32_t uint32; } ofproto_meter_id; |
687 | ||
6ea4776b JR |
688 | /* Abstract ofp_role_request and reply. */ |
689 | struct ofputil_role_request { | |
f4f1ea7e | 690 | enum ofp12_controller_role role; |
6ea4776b | 691 | bool have_generation_id; |
6ea4776b JR |
692 | uint64_t generation_id; |
693 | }; | |
694 | ||
00467f73 AC |
695 | struct ofputil_role_status { |
696 | enum ofp12_controller_role role; | |
697 | enum ofp14_controller_role_reason reason; | |
698 | uint64_t generation_id; | |
699 | }; | |
700 | ||
6ea4776b JR |
701 | enum ofperr ofputil_decode_role_message(const struct ofp_header *, |
702 | struct ofputil_role_request *); | |
703 | struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *, | |
f4f1ea7e | 704 | const struct ofputil_role_request *); |
6ea4776b | 705 | |
00467f73 AC |
706 | struct ofpbuf *ofputil_encode_role_status( |
707 | const struct ofputil_role_status *status, | |
708 | enum ofputil_protocol protocol); | |
709 | ||
710 | enum ofperr ofputil_decode_role_status(const struct ofp_header *oh, | |
711 | struct ofputil_role_status *rs); | |
307975da SH |
712 | /* Abstract table stats. |
713 | * | |
714 | * For now we use ofp12_table_stats as a superset of the other protocol | |
715 | * versions' table stats. */ | |
716 | ||
717 | struct ofpbuf *ofputil_encode_table_stats_reply( | |
718 | const struct ofp12_table_stats[], int n, | |
719 | const struct ofp_header *request); | |
720 | ||
e8f9a7bb VG |
721 | /* Queue configuration request. */ |
722 | struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version, | |
723 | ofp_port_t port); | |
724 | enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *, | |
725 | ofp_port_t *port); | |
726 | ||
727 | /* Queue configuration reply. */ | |
728 | struct ofputil_queue_config { | |
729 | uint32_t queue_id; | |
730 | ||
731 | /* Each of these optional values is expressed in tenths of a percent. | |
732 | * Values greater than 1000 indicate that the feature is disabled. | |
733 | * UINT16_MAX indicates that the value is omitted. */ | |
734 | uint16_t min_rate; | |
735 | uint16_t max_rate; | |
736 | }; | |
737 | ||
738 | struct ofpbuf *ofputil_encode_queue_get_config_reply( | |
739 | const struct ofp_header *request); | |
740 | void ofputil_append_queue_get_config_reply( | |
741 | struct ofpbuf *reply, const struct ofputil_queue_config *); | |
742 | ||
743 | enum ofperr ofputil_decode_queue_get_config_reply(struct ofpbuf *reply, | |
744 | ofp_port_t *); | |
745 | int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply, | |
746 | struct ofputil_queue_config *); | |
747 | ||
748 | ||
2b07c8b1 BP |
749 | /* Abstract nx_flow_monitor_request. */ |
750 | struct ofputil_flow_monitor_request { | |
751 | uint32_t id; | |
752 | enum nx_flow_monitor_flags flags; | |
4e022ec0 | 753 | ofp_port_t out_port; |
2b07c8b1 | 754 | uint8_t table_id; |
81a76618 | 755 | struct match match; |
2b07c8b1 BP |
756 | }; |
757 | ||
758 | int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *, | |
759 | struct ofpbuf *msg); | |
760 | void ofputil_append_flow_monitor_request( | |
761 | const struct ofputil_flow_monitor_request *, struct ofpbuf *msg); | |
762 | ||
763 | /* Abstract nx_flow_update. */ | |
764 | struct ofputil_flow_update { | |
765 | enum nx_flow_update_event event; | |
766 | ||
767 | /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */ | |
768 | enum ofp_flow_removed_reason reason; | |
769 | uint16_t idle_timeout; | |
770 | uint16_t hard_timeout; | |
771 | uint8_t table_id; | |
772 | ovs_be64 cookie; | |
81a76618 BP |
773 | struct match *match; |
774 | uint16_t priority; | |
2b07c8b1 BP |
775 | struct ofpact *ofpacts; |
776 | size_t ofpacts_len; | |
777 | ||
778 | /* Used only for NXFME_ABBREV. */ | |
779 | ovs_be32 xid; | |
780 | }; | |
781 | ||
782 | int ofputil_decode_flow_update(struct ofputil_flow_update *, | |
783 | struct ofpbuf *msg, struct ofpbuf *ofpacts); | |
784 | void ofputil_start_flow_update(struct list *replies); | |
785 | void ofputil_append_flow_update(const struct ofputil_flow_update *, | |
786 | struct list *replies); | |
787 | ||
788 | /* Abstract nx_flow_monitor_cancel. */ | |
789 | uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *); | |
790 | struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id); | |
791 | ||
982697a4 | 792 | /* Encoding OpenFlow stats messages. */ |
2e3fa633 | 793 | void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version, |
2be393ed JP |
794 | const struct ofputil_phy_port *pp, |
795 | struct list *replies); | |
796 | ||
982697a4 | 797 | /* Encoding simple OpenFlow messages. */ |
1a126c0c | 798 | struct ofpbuf *make_echo_request(enum ofp_version); |
fa37b408 | 799 | struct ofpbuf *make_echo_reply(const struct ofp_header *rq); |
7257b535 | 800 | |
a0ae0b6e | 801 | struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version); |
efb80167 | 802 | |
7257b535 BP |
803 | const char *ofputil_frag_handling_to_string(enum ofp_config_flags); |
804 | bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *); | |
2be393ed | 805 | |
9aee0764 BP |
806 | \f |
807 | /* Actions. */ | |
808 | ||
e23ae585 BP |
809 | /* The type of an action. |
810 | * | |
08f94c0e | 811 | * For each implemented OFPAT10_* and NXAST_* action type, there is a |
e23ae585 BP |
812 | * corresponding constant prefixed with OFPUTIL_, e.g.: |
813 | * | |
08f94c0e BP |
814 | * OFPUTIL_OFPAT10_OUTPUT |
815 | * OFPUTIL_OFPAT10_SET_VLAN_VID | |
816 | * OFPUTIL_OFPAT10_SET_VLAN_PCP | |
817 | * OFPUTIL_OFPAT10_STRIP_VLAN | |
818 | * OFPUTIL_OFPAT10_SET_DL_SRC | |
819 | * OFPUTIL_OFPAT10_SET_DL_DST | |
820 | * OFPUTIL_OFPAT10_SET_NW_SRC | |
821 | * OFPUTIL_OFPAT10_SET_NW_DST | |
822 | * OFPUTIL_OFPAT10_SET_NW_TOS | |
823 | * OFPUTIL_OFPAT10_SET_TP_SRC | |
824 | * OFPUTIL_OFPAT10_SET_TP_DST | |
825 | * OFPUTIL_OFPAT10_ENQUEUE | |
e23ae585 BP |
826 | * OFPUTIL_NXAST_RESUBMIT |
827 | * OFPUTIL_NXAST_SET_TUNNEL | |
4cceacb9 | 828 | * OFPUTIL_NXAST_SET_METADATA |
e23ae585 BP |
829 | * OFPUTIL_NXAST_SET_QUEUE |
830 | * OFPUTIL_NXAST_POP_QUEUE | |
831 | * OFPUTIL_NXAST_REG_MOVE | |
832 | * OFPUTIL_NXAST_REG_LOAD | |
833 | * OFPUTIL_NXAST_NOTE | |
834 | * OFPUTIL_NXAST_SET_TUNNEL64 | |
835 | * OFPUTIL_NXAST_MULTIPATH | |
e23ae585 BP |
836 | * OFPUTIL_NXAST_BUNDLE |
837 | * OFPUTIL_NXAST_BUNDLE_LOAD | |
838 | * OFPUTIL_NXAST_RESUBMIT_TABLE | |
839 | * OFPUTIL_NXAST_OUTPUT_REG | |
0e553d9c BP |
840 | * OFPUTIL_NXAST_LEARN |
841 | * OFPUTIL_NXAST_DEC_TTL | |
842 | * OFPUTIL_NXAST_FIN_TIMEOUT | |
e23ae585 BP |
843 | * |
844 | * (The above list helps developers who want to "grep" for these definitions.) | |
845 | */ | |
f25d0cf3 | 846 | enum OVS_PACKED_ENUM ofputil_action_code { |
690a61c5 | 847 | OFPUTIL_ACTION_INVALID, |
3ddcaf2d BP |
848 | #define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM, |
849 | #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM, | |
850 | #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM, | |
e23ae585 BP |
851 | #include "ofp-util.def" |
852 | }; | |
853 | ||
854 | /* The number of values of "enum ofputil_action_code". */ | |
855 | enum { | |
3ddcaf2d BP |
856 | #define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1 |
857 | #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 | |
858 | #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 | |
690a61c5 | 859 | OFPUTIL_N_ACTIONS = 1 |
e23ae585 | 860 | #include "ofp-util.def" |
38f2e360 BP |
861 | }; |
862 | ||
e23ae585 BP |
863 | int ofputil_action_code_from_name(const char *); |
864 | ||
93996add BP |
865 | void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf); |
866 | ||
867 | /* For each OpenFlow action <ENUM> that has a corresponding action structure | |
868 | * struct <STRUCT>, this defines two functions: | |
869 | * | |
870 | * void ofputil_init_<ENUM>(struct <STRUCT> *action); | |
871 | * | |
872 | * Initializes the parts of 'action' that identify it as having type <ENUM> | |
873 | * and length 'sizeof *action' and zeros the rest. For actions that have | |
874 | * variable length, the length used and cleared is that of struct <STRUCT>. | |
875 | * | |
876 | * struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf); | |
877 | * | |
878 | * Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf', | |
879 | * initializes it with ofputil_init_<ENUM>(), and returns it. | |
880 | */ | |
08f94c0e | 881 | #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \ |
93996add BP |
882 | void ofputil_init_##ENUM(struct STRUCT *); \ |
883 | struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *); | |
3ddcaf2d | 884 | #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ |
d01c980f BP |
885 | void ofputil_init_##ENUM(struct STRUCT *); \ |
886 | struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *); | |
93996add BP |
887 | #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ |
888 | void ofputil_init_##ENUM(struct STRUCT *); \ | |
889 | struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *); | |
890 | #include "ofp-util.def" | |
891 | ||
9aee0764 | 892 | #define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */ |
fa37b408 | 893 | |
dbba996b | 894 | bool action_outputs_to_port(const union ofp_action *, ovs_be16 port); |
3052b0c5 | 895 | |
90bf1e07 BP |
896 | enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len, |
897 | union ofp_action **, size_t *); | |
18ddadc2 BP |
898 | |
899 | bool ofputil_actions_equal(const union ofp_action *a, size_t n_a, | |
900 | const union ofp_action *b, size_t n_b); | |
901 | union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n); | |
26c112c2 | 902 | |
0ff22822 BP |
903 | /* Handy utility for parsing flows and actions. */ |
904 | bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep); | |
905 | ||
f8e4867e | 906 | struct ofputil_port_stats { |
4e022ec0 | 907 | ofp_port_t port_no; |
f8e4867e | 908 | struct netdev_stats stats; |
65e0be10 BP |
909 | uint32_t duration_sec; /* UINT32_MAX if unknown. */ |
910 | uint32_t duration_nsec; | |
f8e4867e SH |
911 | }; |
912 | ||
913 | struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version, | |
4e022ec0 | 914 | ofp_port_t port); |
f8e4867e SH |
915 | void ofputil_append_port_stat(struct list *replies, |
916 | const struct ofputil_port_stats *ops); | |
917 | size_t ofputil_count_port_stats(const struct ofp_header *); | |
918 | int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg); | |
919 | enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request, | |
4e022ec0 | 920 | ofp_port_t *ofp10_port); |
64626975 SH |
921 | |
922 | struct ofputil_queue_stats_request { | |
4e022ec0 | 923 | ofp_port_t port_no; /* OFPP_ANY means "all ports". */ |
64626975 SH |
924 | uint32_t queue_id; |
925 | }; | |
926 | ||
927 | enum ofperr | |
928 | ofputil_decode_queue_stats_request(const struct ofp_header *request, | |
929 | struct ofputil_queue_stats_request *oqsr); | |
930 | struct ofpbuf * | |
931 | ofputil_encode_queue_stats_request(enum ofp_version ofp_version, | |
932 | const struct ofputil_queue_stats_request *oqsr); | |
933 | ||
934 | struct ofputil_queue_stats { | |
4e022ec0 | 935 | ofp_port_t port_no; |
64626975 | 936 | uint32_t queue_id; |
6dc34a0d BP |
937 | |
938 | /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */ | |
939 | uint64_t tx_bytes; | |
940 | uint64_t tx_packets; | |
941 | uint64_t tx_errors; | |
942 | ||
943 | /* UINT32_MAX if unknown. */ | |
944 | uint32_t duration_sec; | |
945 | uint32_t duration_nsec; | |
64626975 SH |
946 | }; |
947 | ||
948 | size_t ofputil_count_queue_stats(const struct ofp_header *); | |
949 | int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg); | |
950 | void ofputil_append_queue_stat(struct list *replies, | |
951 | const struct ofputil_queue_stats *oqs); | |
952 | ||
7395c052 NZ |
953 | /* Bucket for use in groups. */ |
954 | struct ofputil_bucket { | |
955 | struct list list_node; | |
956 | uint16_t weight; /* Relative weight, for "select" groups. */ | |
957 | ofp_port_t watch_port; /* Port whose state affects whether this bucket | |
958 | * is live. Only required for fast failover | |
959 | * groups. */ | |
960 | uint32_t watch_group; /* Group whose state affects whether this | |
961 | * bucket is live. Only required for fast | |
962 | * failover groups. */ | |
963 | struct ofpact *ofpacts; /* Series of "struct ofpact"s. */ | |
964 | size_t ofpacts_len; /* Length of ofpacts, in bytes. */ | |
965 | }; | |
966 | ||
967 | /* Protocol-independent group_mod. */ | |
968 | struct ofputil_group_mod { | |
969 | uint16_t command; /* One of OFPGC11_*. */ | |
970 | uint8_t type; /* One of OFPGT11_*. */ | |
971 | uint32_t group_id; /* Group identifier. */ | |
972 | struct list buckets; /* Contains "struct ofputil_bucket"s. */ | |
973 | }; | |
974 | ||
975 | struct bucket_counter { | |
976 | uint64_t packet_count; /* Number of packets processed by bucket. */ | |
977 | uint64_t byte_count; /* Number of bytes processed by bucket. */ | |
978 | }; | |
979 | ||
980 | /* Group stats reply, independent of protocol. */ | |
981 | struct ofputil_group_stats { | |
982 | uint32_t group_id; /* Group identifier. */ | |
983 | uint32_t ref_count; | |
984 | uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */ | |
985 | uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */ | |
986 | uint32_t duration_sec; /* UINT32_MAX if unknown. */ | |
987 | uint32_t duration_nsec; | |
988 | uint32_t n_buckets; | |
646b2a9c | 989 | struct bucket_counter *bucket_stats; |
7395c052 NZ |
990 | }; |
991 | ||
992 | /* Group features reply, independent of protocol. */ | |
993 | struct ofputil_group_features { | |
994 | uint32_t types; /* Bitmap of OFPGT_* values supported. */ | |
995 | uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */ | |
996 | uint32_t max_groups[4]; /* Maximum number of groups for each type. */ | |
997 | uint32_t actions[4]; /* Bitmaps of OFPAT_* that are supported. */ | |
998 | }; | |
999 | ||
1000 | /* Group desc reply, independent of protocol. */ | |
1001 | struct ofputil_group_desc { | |
1002 | uint8_t type; /* One of OFPGT_*. */ | |
1003 | uint32_t group_id; /* Group identifier. */ | |
1004 | struct list buckets; /* Contains "struct ofputil_bucket"s. */ | |
1005 | }; | |
1006 | ||
1007 | void ofputil_bucket_list_destroy(struct list *buckets); | |
1008 | ||
1009 | struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version, | |
1010 | uint32_t group_id); | |
1011 | enum ofperr ofputil_decode_group_stats_request( | |
1012 | const struct ofp_header *request, uint32_t *group_id); | |
1013 | void ofputil_append_group_stats(struct list *replies, | |
1014 | const struct ofputil_group_stats *); | |
1015 | struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version); | |
1016 | struct ofpbuf *ofputil_encode_group_features_reply( | |
1017 | const struct ofputil_group_features *, const struct ofp_header *request); | |
1018 | void ofputil_decode_group_features_reply(const struct ofp_header *, | |
1019 | struct ofputil_group_features *); | |
1020 | struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version, | |
1021 | const struct ofputil_group_mod *gm); | |
1022 | ||
1023 | enum ofperr ofputil_decode_group_mod(const struct ofp_header *, | |
1024 | struct ofputil_group_mod *); | |
1025 | ||
1026 | int ofputil_decode_group_stats_reply(struct ofpbuf *, | |
1027 | struct ofputil_group_stats *); | |
1028 | ||
1029 | int ofputil_decode_group_desc_reply(struct ofputil_group_desc *, | |
a7a2d006 | 1030 | struct ofpbuf *, enum ofp_version); |
7395c052 NZ |
1031 | |
1032 | void ofputil_append_group_desc_reply(const struct ofputil_group_desc *, | |
1033 | struct list *buckets, | |
1034 | struct list *replies); | |
1035 | struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version); | |
1036 | ||
fa37b408 | 1037 | #endif /* ofp-util.h */ |