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