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