]> git.proxmox.com Git - mirror_ovs.git/blame - lib/odp-util.h
dpctl: Add the option 'pmd' for dump-flows.
[mirror_ovs.git] / lib / odp-util.h
CommitLineData
064af421 1/*
4930ea56 2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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"
ee89ea7b 26#include "openvswitch/hmap.h"
4930ea56 27#include "openvswitch/ofp-actions.h"
fcb9579b 28#include "openvswitch/uuid.h"
837eefc7 29#include "odp-netlink.h"
064af421 30#include "openflow/openflow.h"
9026bf34 31#include "util.h"
064af421
BP
32
33struct ds;
5fa27009 34struct nlattr;
36956a7d 35struct ofpbuf;
44bac24b 36struct simap;
758c456d 37struct pkt_metadata;
064af421 38
7fd91025 39#define SLOW_PATH_REASONS \
7fd91025
BP
40 SPR(SLOW_CFM, "cfm", "Consists of CFM packets") \
41 SPR(SLOW_BFD, "bfd", "Consists of BFD packets") \
42 SPR(SLOW_LACP, "lacp", "Consists of LACP packets") \
43 SPR(SLOW_STP, "stp", "Consists of STP packets") \
d39ec23d 44 SPR(SLOW_LLDP, "lldp", "Consists of LLDP packets") \
7fd91025 45 SPR(SLOW_ACTION, "action", \
687bafbb
BP
46 "Uses action(s) not supported by datapath") \
47 SPR(SLOW_MATCH, "match", \
48 "Datapath can't match specifically enough")
7fd91025
BP
49
50/* Indexes for slow-path reasons. Client code uses "enum slow_path_reason"
51 * values instead of these, these are just a way to construct those. */
52enum {
53#define SPR(ENUM, STRING, EXPLANATION) ENUM##_INDEX,
54 SLOW_PATH_REASONS
55#undef SPR
56};
57
48999827 58/* Reasons why a flow might not be fast-pathable.
7fd91025
BP
59 *
60 * Each reason is a separate bit to allow reasons to be combined. */
61enum slow_path_reason {
62#define SPR(ENUM, STRING, EXPLANATION) ENUM = 1 << ENUM##_INDEX,
63 SLOW_PATH_REASONS
64#undef SPR
65};
66
ea2735d3
JR
67/* Mask of all slow_path_reasons. */
68enum {
69 SLOW_PATH_REASON_MASK = 0
70#define SPR(ENUM, STRING, EXPLANATION) | 1 << ENUM##_INDEX
71 SLOW_PATH_REASONS
72#undef SPR
73};
74
7fd91025
BP
75const char *slow_path_reason_to_explanation(enum slow_path_reason);
76
4e022ec0
AW
77#define ODPP_LOCAL ODP_PORT_C(OVSP_LOCAL)
78#define ODPP_NONE ODP_PORT_C(UINT32_MAX)
c75d4dcf 79
cdee00fd 80void format_odp_actions(struct ds *, const struct nlattr *odp_actions,
0722f341 81 size_t actions_len, const struct hmap *portno_names);
44bac24b 82int odp_actions_from_string(const char *, const struct simap *port_names,
7202cbe5 83 struct ofpbuf *odp_actions);
064af421 84
0a37839c
GS
85/* A map from odp port number to its name. */
86struct odp_portno_names {
87 struct hmap_node hmap_node; /* A node in a port number to name hmap. */
88 odp_port_t port_no; /* Port number in the datapath. */
89 char *name; /* Name associated with the above 'port_no'. */
90};
91
92void odp_portno_names_set(struct hmap *portno_names, odp_port_t port_no,
93 char *port_name);
94void odp_portno_names_destroy(struct hmap *portno_names);
0722f341
BP
95void odp_portno_name_format(const struct hmap *portno_names,
96 odp_port_t, struct ds *);
97
2508ac16
BP
98/* The maximum number of bytes that odp_flow_key_from_flow() appends to a
99 * buffer. This is the upper bound on the length of a nlattr-formatted flow
100 * key that ovs-vswitchd fully understands.
101 *
102 * OVS doesn't insist that ovs-vswitchd and the datapath have exactly the same
103 * idea of a flow, so therefore this value isn't necessarily an upper bound on
104 * the length of a flow key that the datapath can pass to ovs-vswitchd.
105 *
106 * The longest nlattr-formatted flow key appended by odp_flow_key_from_flow()
107 * would be:
36956a7d 108 *
354d4c98
PS
109 * struct pad nl hdr total
110 * ------ --- ------ -----
111 * OVS_KEY_ATTR_PRIORITY 4 -- 4 8
354d4c98
PS
112 * OVS_KEY_ATTR_TUNNEL 0 -- 4 4
113 * - OVS_TUNNEL_KEY_ATTR_ID 8 -- 4 12
114 * - OVS_TUNNEL_KEY_ATTR_IPV4_SRC 4 -- 4 8
115 * - OVS_TUNNEL_KEY_ATTR_IPV4_DST 4 -- 4 8
ffe4c74f
JB
116 * - OVS_TUNNEL_KEY_ATTR_IPV6_SRC 16 -- 4 20
117 * - OVS_TUNNEL_KEY_ATTR_IPV6_DST 16 -- 4 20
354d4c98
PS
118 * - OVS_TUNNEL_KEY_ATTR_TOS 1 3 4 8
119 * - OVS_TUNNEL_KEY_ATTR_TTL 1 3 4 8
120 * - OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT 0 -- 4 4
121 * - OVS_TUNNEL_KEY_ATTR_CSUM 0 -- 4 4
94872594 122 * - OVS_TUNNEL_KEY_ATTR_OAM 0 -- 4 4
c1fc1411 123 * - OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS 256 -- 4 260
ac6073e3 124 * - OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS - -- - - (shared with _GENEVE_OPTS)
354d4c98
PS
125 * OVS_KEY_ATTR_IN_PORT 4 -- 4 8
126 * OVS_KEY_ATTR_SKB_MARK 4 -- 4 8
b96986ed
AZ
127 * OVS_KEY_ATTR_DP_HASH 4 -- 4 8
128 * OVS_KEY_ATTR_RECIRC_ID 4 -- 4 8
07659514
JS
129 * OVS_KEY_ATTR_CT_STATE 4 -- 4 8
130 * OVS_KEY_ATTR_CT_ZONE 2 2 4 8
8e53fe8c 131 * OVS_KEY_ATTR_CT_MARK 4 -- 4 8
9daf2348 132 * OVS_KEY_ATTR_CT_LABEL 16 -- 4 20
daf4d3c1 133 * OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6 40 -- 4 44
060609be 134 * OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4 - -- - - (exclusive of_CT_ORIG_TUPLE_IPV6)
354d4c98
PS
135 * OVS_KEY_ATTR_ETHERNET 12 -- 4 16
136 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (outer VLAN ethertype)
a445095f 137 * OVS_KEY_ATTR_VLAN 2 2 4 8
354d4c98
PS
138 * OVS_KEY_ATTR_ENCAP 0 -- 4 4 (VLAN encapsulation)
139 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (inner VLAN ethertype)
140 * OVS_KEY_ATTR_IPV6 40 -- 4 44
141 * OVS_KEY_ATTR_ICMPV6 2 2 4 8
142 * OVS_KEY_ATTR_ND 28 -- 4 32
143 * ----------------------------------------------------------
daf4d3c1 144 * total 616
2508ac16
BP
145 *
146 * We include some slack space in case the calculation isn't quite right or we
147 * add another field and forget to adjust this value.
18c43631 148 */
ffe4c74f 149#define ODPUTIL_FLOW_KEY_BYTES 640
3c6d05a0 150BUILD_ASSERT_DECL(FLOW_WC_SEQ == 42);
18c43631 151
19cf4069
BP
152/* A buffer with sufficient size and alignment to hold an nlattr-formatted flow
153 * key. An array of "struct nlattr" might not, in theory, be sufficiently
154 * aligned because it only contains 16-bit types. */
155struct odputil_keybuf {
156 uint32_t keybuf[DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)];
157};
14608a15 158
8d8ab6c2 159enum odp_key_fitness odp_tun_key_from_attr(const struct nlattr *,
d40533fc 160 struct flow_tnl *, char **errorp);
f59cb331 161enum odp_key_fitness odp_nsh_key_from_attr(const struct nlattr *,
81fdabb9 162 struct ovs_key_nsh *,
d40533fc
BP
163 struct ovs_key_nsh *,
164 char **errorp);
f59cb331 165enum odp_key_fitness odp_nsh_hdr_from_attr(const struct nlattr *,
81fdabb9 166 struct nsh_hdr *, size_t);
617e10e7 167
534a19b9 168int odp_ufid_from_string(const char *s_, ovs_u128 *ufid);
70e5ed6f 169void odp_format_ufid(const ovs_u128 *ufid, struct ds *);
8d8ab6c2 170
e6cc0bab
AZ
171void odp_flow_format(const struct nlattr *key, size_t key_len,
172 const struct nlattr *mask, size_t mask_len,
0a37839c
GS
173 const struct hmap *portno_names, struct ds *,
174 bool verbose);
36956a7d 175void odp_flow_key_format(const struct nlattr *, size_t, struct ds *);
d40533fc
BP
176int odp_flow_from_string(const char *s, const struct simap *port_names,
177 struct ofpbuf *, struct ofpbuf *, char **errorp);
14608a15 178
1c2f091b
AZ
179/* ODP_SUPPORT_FIELD(TYPE, FIELD_NAME, FIELD_DESCRIPTION)
180 *
181 * Each 'ODP_SUPPORT_FIELD' defines a member in 'struct odp_support',
182 * and represents support for related OVS_KEY_ATTR_* fields.
183 * They are defined as macros to keep 'dpif_show_support()' in sync
184 * as new fields are added. */
185#define ODP_SUPPORT_FIELDS \
186 /* Maximum number of 802.1q VLAN headers to serialize in a mask. */ \
187 ODP_SUPPORT_FIELD(size_t, max_vlan_headers, "Max VLAN headers") \
188 /* Maximum number of MPLS label stack entries to serialise in a mask. */ \
189 ODP_SUPPORT_FIELD(size_t, max_mpls_depth, "Max MPLS depth") \
190 /* If this is true, then recirculation fields will always be \
191 * serialised. */ \
192 ODP_SUPPORT_FIELD(bool, recirc, "Recirc") \
193 /* If true, serialise the corresponding OVS_KEY_ATTR_CONN_* field. */ \
194 ODP_SUPPORT_FIELD(bool, ct_state, "CT state") \
195 ODP_SUPPORT_FIELD(bool, ct_zone, "CT zone") \
196 ODP_SUPPORT_FIELD(bool, ct_mark, "CT mark") \
197 ODP_SUPPORT_FIELD(bool, ct_label, "CT label") \
198 \
199 /* If true, it means that the datapath supports the NAT bits in \
200 * 'ct_state'. The above 'ct_state' member must be true for this \
201 * to make sense */ \
202 ODP_SUPPORT_FIELD(bool, ct_state_nat, "CT state NAT") \
203 \
204 /* Conntrack original direction tuple matching * supported. */ \
7b5bbe5d 205 ODP_SUPPORT_FIELD(bool, ct_orig_tuple, "CT orig tuple") \
d0d57149
FL
206 ODP_SUPPORT_FIELD(bool, ct_orig_tuple6, "CT orig tuple for IPv6") \
207 \
208 /* If true, it means that the datapath supports the IPv6 Neigh \
209 * Discovery Extension bits. */ \
210 ODP_SUPPORT_FIELD(bool, nd_ext, "IPv6 ND Extension")
1c2f091b 211
2494ccd7
JS
212/* Indicates support for various fields. This defines how flows will be
213 * serialised. */
214struct odp_support {
1c2f091b
AZ
215#define ODP_SUPPORT_FIELD(TYPE, NAME, TITLE) TYPE NAME;
216 ODP_SUPPORT_FIELDS
217#undef ODP_SUPPORT_FIELD
2494ccd7
JS
218};
219
5262eea1
JG
220struct odp_flow_key_parms {
221 /* The flow and mask to be serialized. In the case of masks, 'flow'
222 * is used as a template to determine how to interpret 'mask'. For
223 * example, the 'dl_type' of 'mask' describes the mask, but it doesn't
224 * indicate whether the other fields should be interpreted as ARP, IPv4,
225 * IPv6, etc. */
226 const struct flow *flow;
227 const struct flow *mask;
228
2494ccd7
JS
229 /* Indicates support for various fields. If the datapath supports a field,
230 * then it will always be serialised. */
231 struct odp_support support;
ec1f6f32 232
f0fb825a
EG
233 /* Indicates if we are probing datapath capability. If true, ignore the
234 * configured flow limits. */
235 bool probe;
236
ec1f6f32
JG
237 /* The netlink formatted version of the flow. It is used in cases where
238 * the mask cannot be constructed from the OVS internal representation
239 * and needs to see the original form. */
240 const struct ofpbuf *key_buf;
5262eea1
JG
241};
242
243void odp_flow_key_from_flow(const struct odp_flow_key_parms *, struct ofpbuf *);
244void odp_flow_key_from_mask(const struct odp_flow_key_parms *, struct ofpbuf *);
b0f7b9b5 245
7a5e0ee7 246void odp_flow_key_hash(const void *key, size_t key_len, ovs_u128 *hash);
b0f7b9b5 247
758c456d
JR
248/* Estimated space needed for metadata. */
249enum { ODP_KEY_METADATA_SIZE = 9 * 8 };
beb75a40
JS
250void odp_key_from_dp_packet(struct ofpbuf *, const struct dp_packet *);
251void odp_key_to_dp_packet(const struct nlattr *key, size_t key_len,
252 struct dp_packet *md);
758c456d 253
b0f7b9b5
BP
254/* How well a kernel-provided flow key (a sequence of OVS_KEY_ATTR_*
255 * attributes) matches OVS userspace expectations.
256 *
257 * These values are arranged so that greater values are "more important" than
258 * lesser ones. In particular, a single flow key can fit the descriptions for
259 * both ODP_FIT_TOO_LITTLE and ODP_FIT_TOO_MUCH. Such a key is treated as
260 * ODP_FIT_TOO_LITTLE. */
261enum odp_key_fitness {
262 ODP_FIT_PERFECT, /* The key had exactly the fields we expect. */
263 ODP_FIT_TOO_MUCH, /* The key had fields we don't understand. */
264 ODP_FIT_TOO_LITTLE, /* The key lacked fields we expected to see. */
265 ODP_FIT_ERROR, /* The key was invalid. */
266};
267enum odp_key_fitness odp_flow_key_to_flow(const struct nlattr *, size_t,
d40533fc 268 struct flow *, char **errorp);
ec1f6f32
JG
269enum odp_key_fitness odp_flow_key_to_mask(const struct nlattr *mask_key,
270 size_t mask_key_len,
ca8d3442 271 struct flow_wildcards *mask,
d40533fc
BP
272 const struct flow *flow,
273 char **errorp);
8b668ee3
PB
274int parse_key_and_mask_to_match(const struct nlattr *key, size_t key_len,
275 const struct nlattr *mask, size_t mask_len,
276 struct match *match);
6728d578 277
6814e51f 278const char *odp_key_fitness_to_string(enum odp_key_fitness);
14608a15 279
b9ad7294 280void commit_odp_tunnel_action(const struct flow *, struct flow *base,
c6d87201
WT
281 struct ofpbuf *odp_actions,
282 const char *tnl_type);
6d670e7f
JR
283void commit_masked_set_action(struct ofpbuf *odp_actions,
284 enum ovs_key_attr key_type, const void *key,
285 const void *mask, size_t key_size);
7fd91025
BP
286enum slow_path_reason commit_odp_actions(const struct flow *,
287 struct flow *base,
288 struct ofpbuf *odp_actions,
d23df9a8 289 struct flow_wildcards *wc,
f839892a 290 bool use_masked,
1fc11c59 291 bool pending_encap,
88ec1e0a 292 bool pending_decap,
1fc11c59 293 struct ofpbuf *encap_data);
6a7e895f
BP
294\f
295/* ofproto-dpif interface.
296 *
297 * The following types and functions are logically part of ofproto-dpif.
298 * ofproto-dpif puts values of these types into the flows that it installs in
299 * the kernel datapath, though, so ovs-dpctl needs to interpret them so that
300 * it can print flows in a more human-readable manner. */
301
6ff686f2
PS
302enum user_action_cookie_type {
303 USER_ACTION_COOKIE_UNSPEC,
29089a54
RL
304 USER_ACTION_COOKIE_SFLOW, /* Packet for per-bridge sFlow sampling. */
305 USER_ACTION_COOKIE_SLOW_PATH, /* Userspace must process this flow. */
306 USER_ACTION_COOKIE_FLOW_SAMPLE, /* Packet for per-flow sampling. */
307 USER_ACTION_COOKIE_IPFIX, /* Packet for per-bridge IPFIX sampling. */
d39ec23d 308 USER_ACTION_COOKIE_CONTROLLER, /* Forward packet to controller. */
6ff686f2
PS
309};
310
d8ec8318 311/* user_action_cookie is passed as argument to OVS_ACTION_ATTR_USERSPACE. */
8de6ff3e 312struct user_action_cookie {
36fc5f18 313 uint16_t type; /* enum user_action_cookie_type. */
fcb9579b
JP
314 ofp_port_t ofp_in_port; /* OpenFlow in port, or OFPP_NONE. */
315 struct uuid ofproto_uuid; /* UUID of ofproto-dpif. */
36fc5f18 316
8de6ff3e
JP
317 union {
318 struct {
319 /* USER_ACTION_COOKIE_SFLOW. */
320 ovs_be16 vlan_tci; /* Destination VLAN TCI. */
321 uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */
322 } sflow;
323
324 struct {
325 /* USER_ACTION_COOKIE_SLOW_PATH. */
326 uint16_t unused;
327 uint32_t reason; /* enum slow_path_reason. */
328 } slow_path;
329
330 struct {
331 /* USER_ACTION_COOKIE_FLOW_SAMPLE. */
332 uint16_t probability; /* Sampling probability. */
333 uint32_t collector_set_id; /* ID of IPFIX collector set. */
334 uint32_t obs_domain_id; /* Observation Domain ID. */
335 uint32_t obs_point_id; /* Observation Point ID. */
336 odp_port_t output_odp_port; /* The output odp port. */
337 enum nx_action_sample_direction direction;
338 } flow_sample;
339
340 struct {
341 /* USER_ACTION_COOKIE_IPFIX. */
342 odp_port_t output_odp_port; /* The output odp port. */
343 } ipfix;
d39ec23d
JP
344
345 struct {
346 /* USER_ACTION_COOKIE_CONTROLLER. */
abaf6dcf
YS
347 uint8_t dont_send; /* Don't send the packet to controller. */
348 uint8_t continuation; /* Send packet-in as a continuation. */
d39ec23d
JP
349 uint16_t reason;
350 uint32_t recirc_id;
351 ovs_32aligned_be64 rule_cookie;
352 uint16_t controller_id;
353 uint16_t max_len;
354 } controller;
8de6ff3e 355 };
6a7e895f 356};
fcb9579b 357BUILD_ASSERT_DECL(sizeof(struct user_action_cookie) == 48);
6ff686f2 358
39db78a0 359size_t odp_put_userspace_action(uint32_t pid,
e995e3df 360 const void *userdata, size_t userdata_size,
8b7ea2d4 361 odp_port_t tunnel_out_port,
7321bda3 362 bool include_actions,
39db78a0 363 struct ofpbuf *odp_actions);
b9ad7294 364void odp_put_tunnel_action(const struct flow_tnl *tunnel,
c6d87201
WT
365 struct ofpbuf *odp_actions,
366 const char *tnl_type);
5bbda0aa 367
a36de779
PS
368void odp_put_tnl_push_action(struct ofpbuf *odp_actions,
369 struct ovs_action_push_tnl *data);
88fc5281
JS
370
371void odp_put_pop_eth_action(struct ofpbuf *odp_actions);
372void odp_put_push_eth_action(struct ofpbuf *odp_actions,
373 const struct eth_addr *eth_src,
374 const struct eth_addr *eth_dst);
375
0aee3827
PB
376struct attr_len_tbl {
377 int len;
378 const struct attr_len_tbl *next;
379 int next_max;
380};
381
382#define ATTR_LEN_INVALID -1
383#define ATTR_LEN_VARIABLE -2
384#define ATTR_LEN_NESTED -3
385
386extern const struct attr_len_tbl ovs_flow_key_attr_lens[OVS_KEY_ATTR_MAX + 1];
064af421 387#endif /* odp-util.h */