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