]> git.proxmox.com Git - mirror_ovs.git/blob - lib/odp-util.h
datapath: Update comments about 'OVS_KEY_ATTR_8021Q'.
[mirror_ovs.git] / lib / odp-util.h
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
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 ODP_UTIL_H
18 #define ODP_UTIL_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include "flow.h"
25 #include "hash.h"
26 #include "hmap.h"
27 #include "odp-netlink.h"
28 #include "openflow/openflow.h"
29 #include "util.h"
30
31 struct ds;
32 struct nlattr;
33 struct ofpbuf;
34 struct simap;
35 struct pkt_metadata;
36
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") \
43 SPR(SLOW_CONTROLLER, "controller", \
44 "Sends \"packet-in\" messages to the OpenFlow controller") \
45 SPR(SLOW_ACTION, "action", \
46 "Uses action(s) not supported by datapath")
47
48 /* Indexes for slow-path reasons. Client code uses "enum slow_path_reason"
49 * values instead of these, these are just a way to construct those. */
50 enum {
51 #define SPR(ENUM, STRING, EXPLANATION) ENUM##_INDEX,
52 SLOW_PATH_REASONS
53 #undef SPR
54 };
55
56 /* Reasons why a subfacet might not be fast-pathable.
57 *
58 * Each reason is a separate bit to allow reasons to be combined. */
59 enum slow_path_reason {
60 #define SPR(ENUM, STRING, EXPLANATION) ENUM = 1 << ENUM##_INDEX,
61 SLOW_PATH_REASONS
62 #undef SPR
63 };
64
65 const char *slow_path_reason_to_explanation(enum slow_path_reason);
66
67 #define ODPP_LOCAL ODP_PORT_C(OVSP_LOCAL)
68 #define ODPP_NONE ODP_PORT_C(UINT32_MAX)
69
70 void format_odp_actions(struct ds *, const struct nlattr *odp_actions,
71 size_t actions_len);
72 int odp_actions_from_string(const char *, const struct simap *port_names,
73 struct ofpbuf *odp_actions);
74
75 /* A map from odp port number to its name. */
76 struct odp_portno_names {
77 struct hmap_node hmap_node; /* A node in a port number to name hmap. */
78 odp_port_t port_no; /* Port number in the datapath. */
79 char *name; /* Name associated with the above 'port_no'. */
80 };
81
82 void odp_portno_names_set(struct hmap *portno_names, odp_port_t port_no,
83 char *port_name);
84 void odp_portno_names_destroy(struct hmap *portno_names);
85 /* The maximum number of bytes that odp_flow_key_from_flow() appends to a
86 * buffer. This is the upper bound on the length of a nlattr-formatted flow
87 * key that ovs-vswitchd fully understands.
88 *
89 * OVS doesn't insist that ovs-vswitchd and the datapath have exactly the same
90 * idea of a flow, so therefore this value isn't necessarily an upper bound on
91 * the length of a flow key that the datapath can pass to ovs-vswitchd.
92 *
93 * The longest nlattr-formatted flow key appended by odp_flow_key_from_flow()
94 * would be:
95 *
96 * struct pad nl hdr total
97 * ------ --- ------ -----
98 * OVS_KEY_ATTR_PRIORITY 4 -- 4 8
99 * OVS_KEY_ATTR_TUNNEL 0 -- 4 4
100 * - OVS_TUNNEL_KEY_ATTR_ID 8 -- 4 12
101 * - OVS_TUNNEL_KEY_ATTR_IPV4_SRC 4 -- 4 8
102 * - OVS_TUNNEL_KEY_ATTR_IPV4_DST 4 -- 4 8
103 * - OVS_TUNNEL_KEY_ATTR_TOS 1 3 4 8
104 * - OVS_TUNNEL_KEY_ATTR_TTL 1 3 4 8
105 * - OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT 0 -- 4 4
106 * - OVS_TUNNEL_KEY_ATTR_CSUM 0 -- 4 4
107 * - OVS_TUNNEL_KEY_ATTR_OAM 0 -- 4 4
108 * - OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS 256 -- 4 260
109 * OVS_KEY_ATTR_IN_PORT 4 -- 4 8
110 * OVS_KEY_ATTR_SKB_MARK 4 -- 4 8
111 * OVS_KEY_ATTR_DP_HASH 4 -- 4 8
112 * OVS_KEY_ATTR_RECIRC_ID 4 -- 4 8
113 * OVS_KEY_ATTR_ETHERNET 12 -- 4 16
114 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (outer VLAN ethertype)
115 * OVS_KEY_ATTR_VLAN 2 2 4 8
116 * OVS_KEY_ATTR_ENCAP 0 -- 4 4 (VLAN encapsulation)
117 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (inner VLAN ethertype)
118 * OVS_KEY_ATTR_IPV6 40 -- 4 44
119 * OVS_KEY_ATTR_ICMPV6 2 2 4 8
120 * OVS_KEY_ATTR_ND 28 -- 4 32
121 * ----------------------------------------------------------
122 * total 488
123 *
124 * We include some slack space in case the calculation isn't quite right or we
125 * add another field and forget to adjust this value.
126 */
127 #define ODPUTIL_FLOW_KEY_BYTES 512
128 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 27);
129
130 /* A buffer with sufficient size and alignment to hold an nlattr-formatted flow
131 * key. An array of "struct nlattr" might not, in theory, be sufficiently
132 * aligned because it only contains 16-bit types. */
133 struct odputil_keybuf {
134 uint32_t keybuf[DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)];
135 };
136
137 enum odp_key_fitness odp_tun_key_from_attr(const struct nlattr *,
138 struct flow_tnl *);
139
140 void odp_flow_format(const struct nlattr *key, size_t key_len,
141 const struct nlattr *mask, size_t mask_len,
142 const struct hmap *portno_names, struct ds *,
143 bool verbose);
144 void odp_flow_key_format(const struct nlattr *, size_t, struct ds *);
145 int odp_flow_from_string(const char *s,
146 const struct simap *port_names,
147 struct ofpbuf *, struct ofpbuf *);
148
149 void odp_flow_key_from_flow(struct ofpbuf *, const struct flow * flow,
150 const struct flow *mask, odp_port_t odp_in_port,
151 bool recirc);
152 void odp_flow_key_from_mask(struct ofpbuf *, const struct flow *mask,
153 const struct flow *flow, uint32_t odp_in_port,
154 size_t max_mpls_depth, bool recirc);
155
156 uint32_t odp_flow_key_hash(const struct nlattr *, size_t);
157
158 /* Estimated space needed for metadata. */
159 enum { ODP_KEY_METADATA_SIZE = 9 * 8 };
160 void odp_key_from_pkt_metadata(struct ofpbuf *, const struct pkt_metadata *);
161 void odp_key_to_pkt_metadata(const struct nlattr *key, size_t key_len,
162 struct pkt_metadata *md);
163
164 /* How well a kernel-provided flow key (a sequence of OVS_KEY_ATTR_*
165 * attributes) matches OVS userspace expectations.
166 *
167 * These values are arranged so that greater values are "more important" than
168 * lesser ones. In particular, a single flow key can fit the descriptions for
169 * both ODP_FIT_TOO_LITTLE and ODP_FIT_TOO_MUCH. Such a key is treated as
170 * ODP_FIT_TOO_LITTLE. */
171 enum odp_key_fitness {
172 ODP_FIT_PERFECT, /* The key had exactly the fields we expect. */
173 ODP_FIT_TOO_MUCH, /* The key had fields we don't understand. */
174 ODP_FIT_TOO_LITTLE, /* The key lacked fields we expected to see. */
175 ODP_FIT_ERROR, /* The key was invalid. */
176 };
177 enum odp_key_fitness odp_flow_key_to_flow(const struct nlattr *, size_t,
178 struct flow *);
179 enum odp_key_fitness odp_flow_key_to_mask(const struct nlattr *key, size_t len,
180 struct flow *mask,
181 const struct flow *flow);
182 const char *odp_key_fitness_to_string(enum odp_key_fitness);
183
184 void commit_odp_tunnel_action(const struct flow *, struct flow *base,
185 struct ofpbuf *odp_actions);
186 enum slow_path_reason commit_odp_actions(const struct flow *,
187 struct flow *base,
188 struct ofpbuf *odp_actions,
189 struct flow_wildcards *wc);
190 \f
191 /* ofproto-dpif interface.
192 *
193 * The following types and functions are logically part of ofproto-dpif.
194 * ofproto-dpif puts values of these types into the flows that it installs in
195 * the kernel datapath, though, so ovs-dpctl needs to interpret them so that
196 * it can print flows in a more human-readable manner. */
197
198 enum user_action_cookie_type {
199 USER_ACTION_COOKIE_UNSPEC,
200 USER_ACTION_COOKIE_SFLOW, /* Packet for per-bridge sFlow sampling. */
201 USER_ACTION_COOKIE_SLOW_PATH, /* Userspace must process this flow. */
202 USER_ACTION_COOKIE_FLOW_SAMPLE, /* Packet for per-flow sampling. */
203 USER_ACTION_COOKIE_IPFIX, /* Packet for per-bridge IPFIX sampling. */
204 };
205
206 /* user_action_cookie is passed as argument to OVS_ACTION_ATTR_USERSPACE.
207 * Since it is passed to kernel as u64, its size has to be 8 bytes. */
208 union user_action_cookie {
209 uint16_t type; /* enum user_action_cookie_type. */
210
211 struct {
212 uint16_t type; /* USER_ACTION_COOKIE_SFLOW. */
213 ovs_be16 vlan_tci; /* Destination VLAN TCI. */
214 uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */
215 } sflow;
216
217 struct {
218 uint16_t type; /* USER_ACTION_COOKIE_SLOW_PATH. */
219 uint16_t unused;
220 uint32_t reason; /* enum slow_path_reason. */
221 } slow_path;
222
223 struct {
224 uint16_t type; /* USER_ACTION_COOKIE_FLOW_SAMPLE. */
225 uint16_t probability; /* Sampling probability. */
226 uint32_t collector_set_id; /* ID of IPFIX collector set. */
227 uint32_t obs_domain_id; /* Observation Domain ID. */
228 uint32_t obs_point_id; /* Observation Point ID. */
229 } flow_sample;
230
231 struct {
232 uint16_t type; /* USER_ACTION_COOKIE_IPFIX. */
233 } ipfix;
234 };
235 BUILD_ASSERT_DECL(sizeof(union user_action_cookie) == 16);
236
237 size_t odp_put_userspace_action(uint32_t pid,
238 const void *userdata, size_t userdata_size,
239 struct ofpbuf *odp_actions);
240 void odp_put_tunnel_action(const struct flow_tnl *tunnel,
241 struct ofpbuf *odp_actions);
242 void odp_put_pkt_mark_action(const uint32_t pkt_mark,
243 struct ofpbuf *odp_actions);
244
245 #endif /* odp-util.h */