2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include "odp-netlink.h"
28 #include "openflow/openflow.h"
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")
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. */
51 #define SPR(ENUM, STRING, EXPLANATION) ENUM##_INDEX,
56 /* Reasons why a subfacet might not be fast-pathable.
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,
65 /* Mask of all slow_path_reasons. */
67 SLOW_PATH_REASON_MASK = 0
68 #define SPR(ENUM, STRING, EXPLANATION) | 1 << ENUM##_INDEX
73 const char *slow_path_reason_to_explanation(enum slow_path_reason);
75 #define ODPP_LOCAL ODP_PORT_C(OVSP_LOCAL)
76 #define ODPP_NONE ODP_PORT_C(UINT32_MAX)
78 void format_odp_actions(struct ds *, const struct nlattr *odp_actions,
80 int odp_actions_from_string(const char *, const struct simap *port_names,
81 struct ofpbuf *odp_actions);
83 /* A map from odp port number to its name. */
84 struct odp_portno_names {
85 struct hmap_node hmap_node; /* A node in a port number to name hmap. */
86 odp_port_t port_no; /* Port number in the datapath. */
87 char *name; /* Name associated with the above 'port_no'. */
90 void odp_portno_names_set(struct hmap *portno_names, odp_port_t port_no,
92 void odp_portno_names_destroy(struct hmap *portno_names);
93 /* The maximum number of bytes that odp_flow_key_from_flow() appends to a
94 * buffer. This is the upper bound on the length of a nlattr-formatted flow
95 * key that ovs-vswitchd fully understands.
97 * OVS doesn't insist that ovs-vswitchd and the datapath have exactly the same
98 * idea of a flow, so therefore this value isn't necessarily an upper bound on
99 * the length of a flow key that the datapath can pass to ovs-vswitchd.
101 * The longest nlattr-formatted flow key appended by odp_flow_key_from_flow()
104 * struct pad nl hdr total
105 * ------ --- ------ -----
106 * OVS_KEY_ATTR_PRIORITY 4 -- 4 8
107 * OVS_KEY_ATTR_TUNNEL 0 -- 4 4
108 * - OVS_TUNNEL_KEY_ATTR_ID 8 -- 4 12
109 * - OVS_TUNNEL_KEY_ATTR_IPV4_SRC 4 -- 4 8
110 * - OVS_TUNNEL_KEY_ATTR_IPV4_DST 4 -- 4 8
111 * - OVS_TUNNEL_KEY_ATTR_TOS 1 3 4 8
112 * - OVS_TUNNEL_KEY_ATTR_TTL 1 3 4 8
113 * - OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT 0 -- 4 4
114 * - OVS_TUNNEL_KEY_ATTR_CSUM 0 -- 4 4
115 * - OVS_TUNNEL_KEY_ATTR_OAM 0 -- 4 4
116 * - OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS 256 -- 4 260
117 * OVS_KEY_ATTR_IN_PORT 4 -- 4 8
118 * OVS_KEY_ATTR_SKB_MARK 4 -- 4 8
119 * OVS_KEY_ATTR_DP_HASH 4 -- 4 8
120 * OVS_KEY_ATTR_RECIRC_ID 4 -- 4 8
121 * OVS_KEY_ATTR_ETHERNET 12 -- 4 16
122 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (outer VLAN ethertype)
123 * OVS_KEY_ATTR_VLAN 2 2 4 8
124 * OVS_KEY_ATTR_ENCAP 0 -- 4 4 (VLAN encapsulation)
125 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (inner VLAN ethertype)
126 * OVS_KEY_ATTR_IPV6 40 -- 4 44
127 * OVS_KEY_ATTR_ICMPV6 2 2 4 8
128 * OVS_KEY_ATTR_ND 28 -- 4 32
129 * ----------------------------------------------------------
132 * We include some slack space in case the calculation isn't quite right or we
133 * add another field and forget to adjust this value.
135 #define ODPUTIL_FLOW_KEY_BYTES 512
136 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 27);
138 /* A buffer with sufficient size and alignment to hold an nlattr-formatted flow
139 * key. An array of "struct nlattr" might not, in theory, be sufficiently
140 * aligned because it only contains 16-bit types. */
141 struct odputil_keybuf {
142 uint32_t keybuf[DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)];
145 enum odp_key_fitness odp_tun_key_from_attr(const struct nlattr *,
148 void odp_flow_format(const struct nlattr *key, size_t key_len,
149 const struct nlattr *mask, size_t mask_len,
150 const struct hmap *portno_names, struct ds *,
152 void odp_flow_key_format(const struct nlattr *, size_t, struct ds *);
153 int odp_flow_from_string(const char *s,
154 const struct simap *port_names,
155 struct ofpbuf *, struct ofpbuf *);
157 void odp_flow_key_from_flow(struct ofpbuf *, const struct flow * flow,
158 const struct flow *mask, odp_port_t odp_in_port,
160 void odp_flow_key_from_mask(struct ofpbuf *, const struct flow *mask,
161 const struct flow *flow, uint32_t odp_in_port,
162 size_t max_mpls_depth, bool recirc);
164 uint32_t odp_flow_key_hash(const struct nlattr *, size_t);
166 /* Estimated space needed for metadata. */
167 enum { ODP_KEY_METADATA_SIZE = 9 * 8 };
168 void odp_key_from_pkt_metadata(struct ofpbuf *, const struct pkt_metadata *);
169 void odp_key_to_pkt_metadata(const struct nlattr *key, size_t key_len,
170 struct pkt_metadata *md);
172 /* How well a kernel-provided flow key (a sequence of OVS_KEY_ATTR_*
173 * attributes) matches OVS userspace expectations.
175 * These values are arranged so that greater values are "more important" than
176 * lesser ones. In particular, a single flow key can fit the descriptions for
177 * both ODP_FIT_TOO_LITTLE and ODP_FIT_TOO_MUCH. Such a key is treated as
178 * ODP_FIT_TOO_LITTLE. */
179 enum odp_key_fitness {
180 ODP_FIT_PERFECT, /* The key had exactly the fields we expect. */
181 ODP_FIT_TOO_MUCH, /* The key had fields we don't understand. */
182 ODP_FIT_TOO_LITTLE, /* The key lacked fields we expected to see. */
183 ODP_FIT_ERROR, /* The key was invalid. */
185 enum odp_key_fitness odp_flow_key_to_flow(const struct nlattr *, size_t,
187 enum odp_key_fitness odp_flow_key_to_mask(const struct nlattr *key, size_t len,
189 const struct flow *flow);
190 const char *odp_key_fitness_to_string(enum odp_key_fitness);
192 void commit_odp_tunnel_action(const struct flow *, struct flow *base,
193 struct ofpbuf *odp_actions);
194 void commit_masked_set_action(struct ofpbuf *odp_actions,
195 enum ovs_key_attr key_type, const void *key,
196 const void *mask, size_t key_size);
197 enum slow_path_reason commit_odp_actions(const struct flow *,
199 struct ofpbuf *odp_actions,
200 struct flow_wildcards *wc,
203 /* ofproto-dpif interface.
205 * The following types and functions are logically part of ofproto-dpif.
206 * ofproto-dpif puts values of these types into the flows that it installs in
207 * the kernel datapath, though, so ovs-dpctl needs to interpret them so that
208 * it can print flows in a more human-readable manner. */
210 enum user_action_cookie_type {
211 USER_ACTION_COOKIE_UNSPEC,
212 USER_ACTION_COOKIE_SFLOW, /* Packet for per-bridge sFlow sampling. */
213 USER_ACTION_COOKIE_SLOW_PATH, /* Userspace must process this flow. */
214 USER_ACTION_COOKIE_FLOW_SAMPLE, /* Packet for per-flow sampling. */
215 USER_ACTION_COOKIE_IPFIX, /* Packet for per-bridge IPFIX sampling. */
218 /* user_action_cookie is passed as argument to OVS_ACTION_ATTR_USERSPACE.
219 * Since it is passed to kernel as u64, its size has to be 8 bytes. */
220 union user_action_cookie {
221 uint16_t type; /* enum user_action_cookie_type. */
224 uint16_t type; /* USER_ACTION_COOKIE_SFLOW. */
225 ovs_be16 vlan_tci; /* Destination VLAN TCI. */
226 uint32_t output; /* SFL_FLOW_SAMPLE_TYPE 'output' value. */
230 uint16_t type; /* USER_ACTION_COOKIE_SLOW_PATH. */
232 uint32_t reason; /* enum slow_path_reason. */
236 uint16_t type; /* USER_ACTION_COOKIE_FLOW_SAMPLE. */
237 uint16_t probability; /* Sampling probability. */
238 uint32_t collector_set_id; /* ID of IPFIX collector set. */
239 uint32_t obs_domain_id; /* Observation Domain ID. */
240 uint32_t obs_point_id; /* Observation Point ID. */
244 uint16_t type; /* USER_ACTION_COOKIE_IPFIX. */
245 odp_port_t output_odp_port; /* The output odp port. */
248 BUILD_ASSERT_DECL(sizeof(union user_action_cookie) == 16);
250 size_t odp_put_userspace_action(uint32_t pid,
251 const void *userdata, size_t userdata_size,
252 odp_port_t tunnel_out_port,
253 struct ofpbuf *odp_actions);
254 void odp_put_tunnel_action(const struct flow_tnl *tunnel,
255 struct ofpbuf *odp_actions);
257 #endif /* odp-util.h */