]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
18080541 | 2 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
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: | |
064af421 | 7 | * |
a14bc59f BP |
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. | |
064af421 BP |
15 | */ |
16 | ||
17 | #ifndef ODP_UTIL_H | |
18 | #define ODP_UTIL_H 1 | |
19 | ||
20 | #include <stdbool.h> | |
3762274e | 21 | #include <stddef.h> |
064af421 | 22 | #include <stdint.h> |
14608a15 | 23 | #include <string.h> |
94f4d447 | 24 | #include "flow.h" |
14608a15 | 25 | #include "hash.h" |
0a37839c | 26 | #include "hmap.h" |
837eefc7 | 27 | #include "odp-netlink.h" |
064af421 | 28 | #include "openflow/openflow.h" |
9026bf34 | 29 | #include "util.h" |
064af421 BP |
30 | |
31 | struct ds; | |
5fa27009 | 32 | struct nlattr; |
36956a7d | 33 | struct ofpbuf; |
44bac24b | 34 | struct simap; |
758c456d | 35 | struct pkt_metadata; |
064af421 | 36 | |
7fd91025 BP |
37 | #define SLOW_PATH_REASONS \ |
38 | /* These reasons are mutually exclusive. */ \ | |
39 | SPR(SLOW_CFM, "cfm", "Consists of CFM packets") \ | |
40 | SPR(SLOW_BFD, "bfd", "Consists of BFD packets") \ | |
41 | SPR(SLOW_LACP, "lacp", "Consists of LACP packets") \ | |
42 | SPR(SLOW_STP, "stp", "Consists of STP packets") \ | |
0477baa9 | 43 | SPR(SLOW_LLDP, "lldp", "Consists of LLDP packets") \ |
7fd91025 BP |
44 | SPR(SLOW_CONTROLLER, "controller", \ |
45 | "Sends \"packet-in\" messages to the OpenFlow controller") \ | |
46 | SPR(SLOW_ACTION, "action", \ | |
47 | "Uses action(s) not supported by datapath") | |
48 | ||
49 | /* Indexes for slow-path reasons. Client code uses "enum slow_path_reason" | |
50 | * values instead of these, these are just a way to construct those. */ | |
51 | enum { | |
52 | #define SPR(ENUM, STRING, EXPLANATION) ENUM##_INDEX, | |
53 | SLOW_PATH_REASONS | |
54 | #undef SPR | |
55 | }; | |
56 | ||
57 | /* Reasons why a subfacet might not be fast-pathable. | |
58 | * | |
59 | * Each reason is a separate bit to allow reasons to be combined. */ | |
60 | enum slow_path_reason { | |
61 | #define SPR(ENUM, STRING, EXPLANATION) ENUM = 1 << ENUM##_INDEX, | |
62 | SLOW_PATH_REASONS | |
63 | #undef SPR | |
64 | }; | |
65 | ||
ea2735d3 JR |
66 | /* Mask of all slow_path_reasons. */ |
67 | enum { | |
68 | SLOW_PATH_REASON_MASK = 0 | |
69 | #define SPR(ENUM, STRING, EXPLANATION) | 1 << ENUM##_INDEX | |
70 | SLOW_PATH_REASONS | |
71 | #undef SPR | |
72 | }; | |
73 | ||
7fd91025 BP |
74 | const char *slow_path_reason_to_explanation(enum slow_path_reason); |
75 | ||
4e022ec0 AW |
76 | #define ODPP_LOCAL ODP_PORT_C(OVSP_LOCAL) |
77 | #define ODPP_NONE ODP_PORT_C(UINT32_MAX) | |
c75d4dcf | 78 | |
cdee00fd BP |
79 | void format_odp_actions(struct ds *, const struct nlattr *odp_actions, |
80 | size_t actions_len); | |
44bac24b | 81 | int odp_actions_from_string(const char *, const struct simap *port_names, |
7202cbe5 | 82 | struct ofpbuf *odp_actions); |
064af421 | 83 | |
0a37839c GS |
84 | /* A map from odp port number to its name. */ |
85 | struct odp_portno_names { | |
86 | struct hmap_node hmap_node; /* A node in a port number to name hmap. */ | |
87 | odp_port_t port_no; /* Port number in the datapath. */ | |
88 | char *name; /* Name associated with the above 'port_no'. */ | |
89 | }; | |
90 | ||
91 | void odp_portno_names_set(struct hmap *portno_names, odp_port_t port_no, | |
92 | char *port_name); | |
93 | void odp_portno_names_destroy(struct hmap *portno_names); | |
2508ac16 BP |
94 | /* The maximum number of bytes that odp_flow_key_from_flow() appends to a |
95 | * buffer. This is the upper bound on the length of a nlattr-formatted flow | |
96 | * key that ovs-vswitchd fully understands. | |
97 | * | |
98 | * OVS doesn't insist that ovs-vswitchd and the datapath have exactly the same | |
99 | * idea of a flow, so therefore this value isn't necessarily an upper bound on | |
100 | * the length of a flow key that the datapath can pass to ovs-vswitchd. | |
101 | * | |
102 | * The longest nlattr-formatted flow key appended by odp_flow_key_from_flow() | |
103 | * would be: | |
36956a7d | 104 | * |
354d4c98 PS |
105 | * struct pad nl hdr total |
106 | * ------ --- ------ ----- | |
107 | * OVS_KEY_ATTR_PRIORITY 4 -- 4 8 | |
354d4c98 PS |
108 | * OVS_KEY_ATTR_TUNNEL 0 -- 4 4 |
109 | * - OVS_TUNNEL_KEY_ATTR_ID 8 -- 4 12 | |
110 | * - OVS_TUNNEL_KEY_ATTR_IPV4_SRC 4 -- 4 8 | |
111 | * - OVS_TUNNEL_KEY_ATTR_IPV4_DST 4 -- 4 8 | |
ffe4c74f JB |
112 | * - OVS_TUNNEL_KEY_ATTR_IPV6_SRC 16 -- 4 20 |
113 | * - OVS_TUNNEL_KEY_ATTR_IPV6_DST 16 -- 4 20 | |
354d4c98 PS |
114 | * - OVS_TUNNEL_KEY_ATTR_TOS 1 3 4 8 |
115 | * - OVS_TUNNEL_KEY_ATTR_TTL 1 3 4 8 | |
116 | * - OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT 0 -- 4 4 | |
117 | * - OVS_TUNNEL_KEY_ATTR_CSUM 0 -- 4 4 | |
94872594 | 118 | * - OVS_TUNNEL_KEY_ATTR_OAM 0 -- 4 4 |
c1fc1411 | 119 | * - OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS 256 -- 4 260 |
ac6073e3 | 120 | * - OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS - -- - - (shared with _GENEVE_OPTS) |
354d4c98 PS |
121 | * OVS_KEY_ATTR_IN_PORT 4 -- 4 8 |
122 | * OVS_KEY_ATTR_SKB_MARK 4 -- 4 8 | |
b96986ed AZ |
123 | * OVS_KEY_ATTR_DP_HASH 4 -- 4 8 |
124 | * OVS_KEY_ATTR_RECIRC_ID 4 -- 4 8 | |
07659514 JS |
125 | * OVS_KEY_ATTR_CT_STATE 4 -- 4 8 |
126 | * OVS_KEY_ATTR_CT_ZONE 2 2 4 8 | |
8e53fe8c | 127 | * OVS_KEY_ATTR_CT_MARK 4 -- 4 8 |
9daf2348 | 128 | * OVS_KEY_ATTR_CT_LABEL 16 -- 4 20 |
354d4c98 PS |
129 | * OVS_KEY_ATTR_ETHERNET 12 -- 4 16 |
130 | * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (outer VLAN ethertype) | |
a445095f | 131 | * OVS_KEY_ATTR_VLAN 2 2 4 8 |
354d4c98 PS |
132 | * OVS_KEY_ATTR_ENCAP 0 -- 4 4 (VLAN encapsulation) |
133 | * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (inner VLAN ethertype) | |
134 | * OVS_KEY_ATTR_IPV6 40 -- 4 44 | |
135 | * OVS_KEY_ATTR_ICMPV6 2 2 4 8 | |
136 | * OVS_KEY_ATTR_ND 28 -- 4 32 | |
137 | * ---------------------------------------------------------- | |
ffe4c74f | 138 | * total 572 |
2508ac16 BP |
139 | * |
140 | * We include some slack space in case the calculation isn't quite right or we | |
141 | * add another field and forget to adjust this value. | |
18c43631 | 142 | */ |
ffe4c74f JB |
143 | #define ODPUTIL_FLOW_KEY_BYTES 640 |
144 | BUILD_ASSERT_DECL(FLOW_WC_SEQ == 35); | |
18c43631 | 145 | |
19cf4069 BP |
146 | /* A buffer with sufficient size and alignment to hold an nlattr-formatted flow |
147 | * key. An array of "struct nlattr" might not, in theory, be sufficiently | |
148 | * aligned because it only contains 16-bit types. */ | |
149 | struct odputil_keybuf { | |
150 | uint32_t keybuf[DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)]; | |
151 | }; | |
14608a15 | 152 | |
6728d578 | 153 | enum odp_key_fitness odp_tun_key_from_attr(const struct nlattr *, bool udpif, |
617e10e7 SH |
154 | struct flow_tnl *); |
155 | ||
534a19b9 | 156 | int odp_ufid_from_string(const char *s_, ovs_u128 *ufid); |
70e5ed6f | 157 | void odp_format_ufid(const ovs_u128 *ufid, struct ds *); |
e6cc0bab AZ |
158 | void odp_flow_format(const struct nlattr *key, size_t key_len, |
159 | const struct nlattr *mask, size_t mask_len, | |
0a37839c GS |
160 | const struct hmap *portno_names, struct ds *, |
161 | bool verbose); | |
36956a7d | 162 | void odp_flow_key_format(const struct nlattr *, size_t, struct ds *); |
e6cc0bab AZ |
163 | int odp_flow_from_string(const char *s, |
164 | const struct simap *port_names, | |
165 | struct ofpbuf *, struct ofpbuf *); | |
14608a15 | 166 | |
2494ccd7 JS |
167 | /* Indicates support for various fields. This defines how flows will be |
168 | * serialised. */ | |
169 | struct odp_support { | |
170 | /* Maximum number of MPLS label stack entries to serialise in a mask. */ | |
171 | size_t max_mpls_depth; | |
172 | ||
173 | /* If this is true, then recirculation fields will always be serialised. */ | |
174 | bool recirc; | |
07659514 JS |
175 | |
176 | /* If true, serialise the corresponding OVS_KEY_ATTR_CONN_* field. */ | |
177 | bool ct_state; | |
178 | bool ct_zone; | |
8e53fe8c | 179 | bool ct_mark; |
9daf2348 | 180 | bool ct_label; |
7b27258c DDP |
181 | |
182 | /* If true, it means that the datapath supports the NAT bits in | |
183 | * 'ct_state'. The above 'ct_state' member must be true for this | |
184 | * to make sense */ | |
185 | bool ct_state_nat; | |
2494ccd7 JS |
186 | }; |
187 | ||
5262eea1 JG |
188 | struct odp_flow_key_parms { |
189 | /* The flow and mask to be serialized. In the case of masks, 'flow' | |
190 | * is used as a template to determine how to interpret 'mask'. For | |
191 | * example, the 'dl_type' of 'mask' describes the mask, but it doesn't | |
192 | * indicate whether the other fields should be interpreted as ARP, IPv4, | |
193 | * IPv6, etc. */ | |
194 | const struct flow *flow; | |
195 | const struct flow *mask; | |
196 | ||
2494ccd7 JS |
197 | /* Indicates support for various fields. If the datapath supports a field, |
198 | * then it will always be serialised. */ | |
199 | struct odp_support support; | |
ec1f6f32 JG |
200 | |
201 | /* The netlink formatted version of the flow. It is used in cases where | |
202 | * the mask cannot be constructed from the OVS internal representation | |
203 | * and needs to see the original form. */ | |
204 | const struct ofpbuf *key_buf; | |
5262eea1 JG |
205 | }; |
206 | ||
207 | void odp_flow_key_from_flow(const struct odp_flow_key_parms *, struct ofpbuf *); | |
208 | void odp_flow_key_from_mask(const struct odp_flow_key_parms *, struct ofpbuf *); | |
b0f7b9b5 BP |
209 | |
210 | uint32_t odp_flow_key_hash(const struct nlattr *, size_t); | |
211 | ||
758c456d JR |
212 | /* Estimated space needed for metadata. */ |
213 | enum { ODP_KEY_METADATA_SIZE = 9 * 8 }; | |
214 | void odp_key_from_pkt_metadata(struct ofpbuf *, const struct pkt_metadata *); | |
215 | void odp_key_to_pkt_metadata(const struct nlattr *key, size_t key_len, | |
216 | struct pkt_metadata *md); | |
217 | ||
b0f7b9b5 BP |
218 | /* How well a kernel-provided flow key (a sequence of OVS_KEY_ATTR_* |
219 | * attributes) matches OVS userspace expectations. | |
220 | * | |
221 | * These values are arranged so that greater values are "more important" than | |
222 | * lesser ones. In particular, a single flow key can fit the descriptions for | |
223 | * both ODP_FIT_TOO_LITTLE and ODP_FIT_TOO_MUCH. Such a key is treated as | |
224 | * ODP_FIT_TOO_LITTLE. */ | |
225 | enum odp_key_fitness { | |
226 | ODP_FIT_PERFECT, /* The key had exactly the fields we expect. */ | |
227 | ODP_FIT_TOO_MUCH, /* The key had fields we don't understand. */ | |
228 | ODP_FIT_TOO_LITTLE, /* The key lacked fields we expected to see. */ | |
229 | ODP_FIT_ERROR, /* The key was invalid. */ | |
230 | }; | |
231 | enum odp_key_fitness odp_flow_key_to_flow(const struct nlattr *, size_t, | |
232 | struct flow *); | |
ec1f6f32 JG |
233 | enum odp_key_fitness odp_flow_key_to_mask(const struct nlattr *mask_key, |
234 | size_t mask_key_len, | |
235 | const struct nlattr *flow_key, | |
236 | size_t flow_key_len, | |
ca8d3442 | 237 | struct flow_wildcards *mask, |
4a221615 | 238 | const struct flow *flow); |
6728d578 JG |
239 | |
240 | enum odp_key_fitness odp_flow_key_to_flow_udpif(const struct nlattr *, size_t, | |
241 | struct flow *); | |
242 | enum odp_key_fitness odp_flow_key_to_mask_udpif(const struct nlattr *mask_key, | |
243 | size_t mask_key_len, | |
244 | const struct nlattr *flow_key, | |
245 | size_t flow_key_len, | |
ca8d3442 | 246 | struct flow_wildcards *mask, |
6728d578 JG |
247 | const struct flow *flow); |
248 | ||
6814e51f | 249 | const char *odp_key_fitness_to_string(enum odp_key_fitness); |
14608a15 | 250 | |
b9ad7294 EJ |
251 | void commit_odp_tunnel_action(const struct flow *, struct flow *base, |
252 | struct ofpbuf *odp_actions); | |
6d670e7f JR |
253 | void commit_masked_set_action(struct ofpbuf *odp_actions, |
254 | enum ovs_key_attr key_type, const void *key, | |
255 | const void *mask, size_t key_size); | |
7fd91025 BP |
256 | enum slow_path_reason commit_odp_actions(const struct flow *, |
257 | struct flow *base, | |
258 | struct ofpbuf *odp_actions, | |
d23df9a8 JR |
259 | struct flow_wildcards *wc, |
260 | bool use_masked); | |
6a7e895f BP |
261 | \f |
262 | /* ofproto-dpif interface. | |
263 | * | |
264 | * The following types and functions are logically part of ofproto-dpif. | |
265 | * ofproto-dpif puts values of these types into the flows that it installs in | |
266 | * the kernel datapath, though, so ovs-dpctl needs to interpret them so that | |
267 | * it can print flows in a more human-readable manner. */ | |
268 | ||
6ff686f2 PS |
269 | enum user_action_cookie_type { |
270 | USER_ACTION_COOKIE_UNSPEC, | |
29089a54 RL |
271 | USER_ACTION_COOKIE_SFLOW, /* Packet for per-bridge sFlow sampling. */ |
272 | USER_ACTION_COOKIE_SLOW_PATH, /* Userspace must process this flow. */ | |
273 | USER_ACTION_COOKIE_FLOW_SAMPLE, /* Packet for per-flow sampling. */ | |
274 | USER_ACTION_COOKIE_IPFIX, /* Packet for per-bridge IPFIX sampling. */ | |
6ff686f2 PS |
275 | }; |
276 | ||
277 | /* user_action_cookie is passed as argument to OVS_ACTION_ATTR_USERSPACE. | |
0a18743a | 278 | * Since it is passed to kernel as u64, its size has to be 8 bytes. */ |
1673e0e4 | 279 | union user_action_cookie { |
36fc5f18 BP |
280 | uint16_t type; /* enum user_action_cookie_type. */ |
281 | ||
1673e0e4 BP |
282 | struct { |
283 | uint16_t type; /* USER_ACTION_COOKIE_SFLOW. */ | |
284 | ovs_be16 vlan_tci; /* Destination VLAN TCI. */ | |
285 | uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */ | |
286 | } sflow; | |
6ff686f2 | 287 | |
6a7e895f BP |
288 | struct { |
289 | uint16_t type; /* USER_ACTION_COOKIE_SLOW_PATH. */ | |
290 | uint16_t unused; | |
291 | uint32_t reason; /* enum slow_path_reason. */ | |
292 | } slow_path; | |
29089a54 RL |
293 | |
294 | struct { | |
295 | uint16_t type; /* USER_ACTION_COOKIE_FLOW_SAMPLE. */ | |
296 | uint16_t probability; /* Sampling probability. */ | |
297 | uint32_t collector_set_id; /* ID of IPFIX collector set. */ | |
298 | uint32_t obs_domain_id; /* Observation Domain ID. */ | |
299 | uint32_t obs_point_id; /* Observation Point ID. */ | |
f69f713b | 300 | odp_port_t output_odp_port; /* The output odp port. */ |
29089a54 RL |
301 | } flow_sample; |
302 | ||
303 | struct { | |
8b7ea2d4 WZ |
304 | uint16_t type; /* USER_ACTION_COOKIE_IPFIX. */ |
305 | odp_port_t output_odp_port; /* The output odp port. */ | |
29089a54 | 306 | } ipfix; |
6a7e895f | 307 | }; |
f69f713b | 308 | BUILD_ASSERT_DECL(sizeof(union user_action_cookie) == 20); |
6ff686f2 | 309 | |
39db78a0 | 310 | size_t odp_put_userspace_action(uint32_t pid, |
e995e3df | 311 | const void *userdata, size_t userdata_size, |
8b7ea2d4 | 312 | odp_port_t tunnel_out_port, |
7321bda3 | 313 | bool include_actions, |
39db78a0 | 314 | struct ofpbuf *odp_actions); |
b9ad7294 EJ |
315 | void odp_put_tunnel_action(const struct flow_tnl *tunnel, |
316 | struct ofpbuf *odp_actions); | |
5bbda0aa | 317 | |
a36de779 PS |
318 | void odp_put_tnl_push_action(struct ofpbuf *odp_actions, |
319 | struct ovs_action_push_tnl *data); | |
064af421 | 320 | #endif /* odp-util.h */ |