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