flow: add l2tpv3oip flow
[vpp.git] / src / vnet / flow / flow.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vnet_flow_flow_h
17 #define included_vnet_flow_flow_h
18
19 #include <vppinfra/clib.h>
20 #include <vppinfra/pcap.h>
21 #include <vnet/l3_types.h>
22 #include <vnet/ip/ip4_packet.h>
23 #include <vnet/ip/ip6_packet.h>
24 #include <vnet/ethernet/packet.h>
25
26 #define foreach_flow_type \
27   /* l2 flow*/ \
28   _(ETHERNET, ethernet, "ethernet") \
29   /* l4 flow*/ \
30   _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
31   _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
32   _(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
33   _(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
34   /* IP tunnel flow */ \
35   _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
36   /* L4 tunnel flow*/ \
37   _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
38   _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
39   _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
40   _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
41   _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
42   _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
43   _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
44   _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
45   _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
46   _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
47
48 #define foreach_flow_entry_ethernet \
49   _fe(ethernet_header_t, eth_hdr)
50
51 #define foreach_flow_entry_ip4_n_tuple \
52   _fe(ip4_address_and_mask_t, src_addr) \
53   _fe(ip4_address_and_mask_t, dst_addr) \
54   _fe(ip_port_and_mask_t, src_port) \
55   _fe(ip_port_and_mask_t, dst_port) \
56   _fe(ip_protocol_t, protocol)
57
58 #define foreach_flow_entry_ip6_n_tuple \
59   _fe(ip6_address_and_mask_t, src_addr) \
60   _fe(ip6_address_and_mask_t, dst_addr) \
61   _fe(ip_port_and_mask_t, src_port) \
62   _fe(ip_port_and_mask_t, dst_port) \
63   _fe(ip_protocol_t, protocol)
64
65 #define foreach_flow_entry_ip4_n_tuple_tagged \
66   _fe(ip4_address_and_mask_t, src_addr) \
67   _fe(ip4_address_and_mask_t, dst_addr) \
68   _fe(ip_port_and_mask_t, src_port) \
69   _fe(ip_port_and_mask_t, dst_port) \
70   _fe(ip_protocol_t, protocol)
71
72 #define foreach_flow_entry_ip6_n_tuple_tagged \
73   _fe(ip6_address_and_mask_t, src_addr) \
74   _fe(ip6_address_and_mask_t, dst_addr) \
75   _fe(ip_port_and_mask_t, src_port) \
76   _fe(ip_port_and_mask_t, dst_port) \
77   _fe(ip_protocol_t, protocol)
78
79 #define foreach_flow_entry_ip4_l2tpv3oip \
80   _fe(ip4_address_and_mask_t, src_addr) \
81   _fe(ip4_address_and_mask_t, dst_addr) \
82   _fe(ip_protocol_t, protocol)          \
83   _fe(u32, session_id)
84
85 #define foreach_flow_entry_ip4_vxlan \
86   _fe(ip4_address_t, src_addr) \
87   _fe(ip4_address_t, dst_addr) \
88   _fe(u16, dst_port) \
89   _fe(u16, vni)
90
91 #define foreach_flow_entry_ip6_vxlan \
92   _fe(ip6_address_t, src_addr) \
93   _fe(ip6_address_t, dst_addr) \
94   _fe(u16, dst_port) \
95   _fe(u16, vni)
96
97 #define foreach_flow_entry_ip4_gtpc \
98   foreach_flow_entry_ip4_n_tuple \
99   _fe(u32, teid)
100
101 #define foreach_flow_entry_ip4_gtpu \
102   foreach_flow_entry_ip4_n_tuple \
103   _fe(u32, teid)
104
105 #define foreach_flow_entry_ip4_gtpu_ip4 \
106   foreach_flow_entry_ip4_gtpu \
107   _fe(ip4_address_and_mask_t, inner_src_addr) \
108   _fe(ip4_address_and_mask_t, inner_dst_addr)
109
110 #define foreach_flow_entry_ip4_gtpu_ip6 \
111   foreach_flow_entry_ip4_gtpu \
112   _fe(ip6_address_and_mask_t, inner_src_addr) \
113   _fe(ip6_address_and_mask_t, inner_dst_addr)
114
115 #define foreach_flow_entry_ip6_gtpc \
116   foreach_flow_entry_ip6_n_tuple \
117   _fe(u32, teid)
118
119 #define foreach_flow_entry_ip6_gtpu \
120   foreach_flow_entry_ip6_n_tuple \
121   _fe(u32, teid)
122
123 #define foreach_flow_entry_ip6_gtpu_ip4 \
124   foreach_flow_entry_ip6_gtpu \
125   _fe(ip4_address_and_mask_t, inner_src_addr) \
126   _fe(ip4_address_and_mask_t, inner_dst_addr)
127
128 #define foreach_flow_entry_ip6_gtpu_ip6 \
129   foreach_flow_entry_ip6_gtpu \
130   _fe(ip6_address_and_mask_t, inner_src_addr) \
131   _fe(ip6_address_and_mask_t, inner_dst_addr)
132
133 #define foreach_flow_action \
134   _(0, COUNT, "count") \
135   _(1, MARK, "mark") \
136   _(2, BUFFER_ADVANCE, "buffer-advance") \
137   _(3, REDIRECT_TO_NODE, "redirect-to-node") \
138   _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
139   _(5, RSS, "rss") \
140   _(6, DROP, "drop")
141
142 typedef enum
143 {
144 #define _(v,n,s)  VNET_FLOW_ACTION_##n = (1 << v),
145   foreach_flow_action
146 #undef _
147 } vnet_flow_action_t;
148
149
150 #define foreach_flow_error \
151   _( -1, NOT_SUPPORTED, "not supported")                        \
152   _( -2, ALREADY_DONE, "already done")                          \
153   _( -3, ALREADY_EXISTS, "already exists")                      \
154   _( -4, NO_SUCH_ENTRY, "no such entry")                        \
155   _( -5, NO_SUCH_INTERFACE, "no such interface")                \
156   _( -6, INTERNAL, "internal error")
157
158 #define foreach_flow_rss_types                    \
159   _(0, FRAG_IPV4,          "ipv4-frag")   \
160   _(1, IPV4_TCP,           "ipv4-tcp")    \
161   _(2, IPV4_UDP,           "ipv4-udp")    \
162   _(3, IPV4_SCTP,          "ipv4-sctp")   \
163   _(4, IPV4_OTHER,         "ipv4-other")  \
164   _(5, IPV4,               "ipv4")        \
165   _(6, IPV6_TCP_EX,        "ipv6-tcp-ex") \
166   _(7, IPV6_UDP_EX,        "ipv6-udp-ex") \
167   _(8, FRAG_IPV6,          "ipv6-frag")   \
168   _(9, IPV6_TCP,           "ipv6-tcp")    \
169   _(10, IPV6_UDP,          "ipv6-udp")    \
170   _(11, IPV6_SCTP,         "ipv6-sctp")   \
171   _(12, IPV6_OTHER,        "ipv6-other")  \
172   _(13, IPV6_EX,           "ipv6-ex")     \
173   _(14, IPV6,              "ipv6")        \
174   _(15, L2_PAYLOAD,        "l2-payload")  \
175   _(16, PORT,              "port")        \
176   _(17, VXLAN,             "vxlan")       \
177   _(18, GENEVE,            "geneve")      \
178   _(19, NVGRE,             "nvgre")       \
179   _(20, GTPU,              "gtpu")        \
180   _(60, L4_DST_ONLY,       "l4-dst-only") \
181   _(61, L4_SRC_ONLY,       "l4-src-only") \
182   _(62, L3_DST_ONLY,       "l3-dst-only") \
183   _(63, L3_SRC_ONLY,       "l3-src-only")
184
185 #define foreach_rss_function           \
186   _(DEFAULT, "default")                \
187   _(TOEPLITZ, "toeplitz")              \
188   _(SIMPLE_XOR, "simple_xor")          \
189   _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
190
191 typedef enum
192 {
193   VNET_FLOW_NO_ERROR = 0,
194 #define _(v,n,s)  VNET_FLOW_ERROR_##n = v,
195   foreach_flow_error
196 #undef _
197 } vnet_flow_error_t;
198
199 typedef struct
200 {
201   u16 port, mask;
202 } ip_port_and_mask_t;
203
204 typedef enum
205 {
206   VNET_FLOW_TYPE_UNKNOWN,
207 #define _(a,b,c) VNET_FLOW_TYPE_##a,
208   foreach_flow_type
209 #undef _
210     VNET_FLOW_N_TYPES,
211 } vnet_flow_type_t;
212
213 typedef enum
214 {
215 #define _(a,b) VNET_RSS_FUNC_##a,
216   foreach_rss_function
217 #undef _
218     VNET_RSS_N_TYPES,
219 } vnet_rss_function_t;
220
221 /*
222  * Create typedef struct vnet_flow_XXX_t
223  */
224 #define _fe(a, b) a b;
225 #define _(a,b,c) \
226 typedef struct { \
227 int foo; \
228 foreach_flow_entry_##b \
229 } vnet_flow_##b##_t;
230 foreach_flow_type;
231 #undef _
232 #undef _fe
233
234 /* main flow struct */
235 typedef struct
236 {
237   /* flow type */
238   vnet_flow_type_t type;
239
240   /* flow index */
241   u32 index;
242
243   /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
244   u32 actions;
245
246   /* flow id for VNET_FLOW_ACTION_MARK */
247   u32 mark_flow_id;
248
249   /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
250   u32 redirect_node_index;
251   u32 redirect_device_input_next_index;
252
253   /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
254   u32 redirect_queue;
255
256   /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
257   i32 buffer_advance;
258
259   /* RSS types, including IPv4/IPv6/TCP/UDP... */
260   u64 rss_types;
261
262   /* RSS functions, including IPv4/IPv6/TCP/UDP... */
263   vnet_rss_function_t rss_fun;
264
265   union
266   {
267 #define _(a,b,c) vnet_flow_##b##_t b;
268     foreach_flow_type
269 #undef _
270   };
271
272   /* per-interface private data */
273   uword *private_data;
274 } vnet_flow_t;
275
276 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
277                          u32 * start);
278 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
279 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
280 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
281 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
282 vnet_flow_t *vnet_get_flow (u32 flow_index);
283
284 typedef struct
285 {
286   u32 start;
287   u32 count;
288   u8 *owner;
289 } vnet_flow_range_t;
290
291 typedef struct
292 {
293   /* pool of device flow entries */
294   vnet_flow_t *global_flow_pool;
295
296   /* flow ids allocated */
297   u32 flows_used;
298
299   /* vector of flow ranges */
300   vnet_flow_range_t *ranges;
301
302 } vnet_flow_main_t;
303
304 extern vnet_flow_main_t flow_main;
305
306 format_function_t format_flow_actions;
307 format_function_t format_flow_enabled_hw;
308
309 #endif /* included_vnet_flow_flow_h */
310
311 /*
312  * fd.io coding-style-patch-verification: ON
313  *
314  * Local Variables:
315  * eval: (c-set-style "gnu")
316  * End:
317  */