flow: add vlan tagged types for IPv4/IPv6 5-tuple flows
[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   /* L4 tunnel flow*/ \
35   _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
36   _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
37   _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
38   _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
39   _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
40   _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
41   _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
42   _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
43   _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
44   _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
45
46 #define foreach_flow_entry_ethernet \
47   _fe(ethernet_header_t, eth_hdr)
48
49 #define foreach_flow_entry_ip4_n_tuple \
50   _fe(ip4_address_and_mask_t, src_addr) \
51   _fe(ip4_address_and_mask_t, dst_addr) \
52   _fe(ip_port_and_mask_t, src_port) \
53   _fe(ip_port_and_mask_t, dst_port) \
54   _fe(ip_protocol_t, protocol)
55
56 #define foreach_flow_entry_ip6_n_tuple \
57   _fe(ip6_address_and_mask_t, src_addr) \
58   _fe(ip6_address_and_mask_t, dst_addr) \
59   _fe(ip_port_and_mask_t, src_port) \
60   _fe(ip_port_and_mask_t, dst_port) \
61   _fe(ip_protocol_t, protocol)
62
63 #define foreach_flow_entry_ip4_n_tuple_tagged \
64   _fe(ip4_address_and_mask_t, src_addr) \
65   _fe(ip4_address_and_mask_t, dst_addr) \
66   _fe(ip_port_and_mask_t, src_port) \
67   _fe(ip_port_and_mask_t, dst_port) \
68   _fe(ip_protocol_t, protocol)
69
70 #define foreach_flow_entry_ip6_n_tuple_tagged \
71   _fe(ip6_address_and_mask_t, src_addr) \
72   _fe(ip6_address_and_mask_t, dst_addr) \
73   _fe(ip_port_and_mask_t, src_port) \
74   _fe(ip_port_and_mask_t, dst_port) \
75   _fe(ip_protocol_t, protocol)
76
77
78 #define foreach_flow_entry_ip4_vxlan \
79   _fe(ip4_address_t, src_addr) \
80   _fe(ip4_address_t, dst_addr) \
81   _fe(u16, dst_port) \
82   _fe(u16, vni)
83
84 #define foreach_flow_entry_ip6_vxlan \
85   _fe(ip6_address_t, src_addr) \
86   _fe(ip6_address_t, dst_addr) \
87   _fe(u16, dst_port) \
88   _fe(u16, vni)
89
90 #define foreach_flow_entry_ip4_gtpc \
91   foreach_flow_entry_ip4_n_tuple \
92   _fe(u32, teid)
93
94 #define foreach_flow_entry_ip4_gtpu \
95   foreach_flow_entry_ip4_n_tuple \
96   _fe(u32, teid)
97
98 #define foreach_flow_entry_ip4_gtpu_ip4 \
99   foreach_flow_entry_ip4_gtpu \
100   _fe(ip4_address_and_mask_t, inner_src_addr) \
101   _fe(ip4_address_and_mask_t, inner_dst_addr)
102
103 #define foreach_flow_entry_ip4_gtpu_ip6 \
104   foreach_flow_entry_ip4_gtpu \
105   _fe(ip6_address_and_mask_t, inner_src_addr) \
106   _fe(ip6_address_and_mask_t, inner_dst_addr)
107
108 #define foreach_flow_entry_ip6_gtpc \
109   foreach_flow_entry_ip6_n_tuple \
110   _fe(u32, teid)
111
112 #define foreach_flow_entry_ip6_gtpu \
113   foreach_flow_entry_ip6_n_tuple \
114   _fe(u32, teid)
115
116 #define foreach_flow_entry_ip6_gtpu_ip4 \
117   foreach_flow_entry_ip6_gtpu \
118   _fe(ip4_address_and_mask_t, inner_src_addr) \
119   _fe(ip4_address_and_mask_t, inner_dst_addr)
120
121 #define foreach_flow_entry_ip6_gtpu_ip6 \
122   foreach_flow_entry_ip6_gtpu \
123   _fe(ip6_address_and_mask_t, inner_src_addr) \
124   _fe(ip6_address_and_mask_t, inner_dst_addr)
125
126 #define foreach_flow_action \
127   _(0, COUNT, "count") \
128   _(1, MARK, "mark") \
129   _(2, BUFFER_ADVANCE, "buffer-advance") \
130   _(3, REDIRECT_TO_NODE, "redirect-to-node") \
131   _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
132   _(5, DROP, "drop")
133
134 typedef enum
135 {
136 #define _(v,n,s)  VNET_FLOW_ACTION_##n = (1 << v),
137   foreach_flow_action
138 #undef _
139 } vnet_flow_action_t;
140
141
142 #define foreach_flow_error \
143   _( -1, NOT_SUPPORTED, "not supported")                        \
144   _( -2, ALREADY_DONE, "already done")                          \
145   _( -3, ALREADY_EXISTS, "already exists")                      \
146   _( -4, NO_SUCH_ENTRY, "no such entry")                        \
147   _( -5, NO_SUCH_INTERFACE, "no such interface")                \
148   _( -6, INTERNAL, "internal error")
149
150 typedef enum
151 {
152   VNET_FLOW_NO_ERROR = 0,
153 #define _(v,n,s)  VNET_FLOW_ERROR_##n = v,
154   foreach_flow_error
155 #undef _
156 } vnet_flow_error_t;
157
158 typedef struct
159 {
160   u16 port, mask;
161 } ip_port_and_mask_t;
162
163 typedef enum
164 {
165   VNET_FLOW_TYPE_UNKNOWN,
166 #define _(a,b,c) VNET_FLOW_TYPE_##a,
167   foreach_flow_type
168 #undef _
169     VNET_FLOW_N_TYPES,
170 } vnet_flow_type_t;
171
172
173 /*
174  * Create typedef struct vnet_flow_XXX_t
175  */
176 #define _fe(a, b) a b;
177 #define _(a,b,c) \
178 typedef struct { \
179 int foo; \
180 foreach_flow_entry_##b \
181 } vnet_flow_##b##_t;
182 foreach_flow_type;
183 #undef _
184 #undef _fe
185
186 /* main flow struct */
187 typedef struct
188 {
189   /* flow type */
190   vnet_flow_type_t type;
191
192   /* flow index */
193   u32 index;
194
195   /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
196   u32 actions;
197
198   /* flow id for VNET_FLOW_ACTION_MARK */
199   u32 mark_flow_id;
200
201   /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
202   u32 redirect_node_index;
203   u32 redirect_device_input_next_index;
204
205   /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
206   u32 redirect_queue;
207
208   /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
209   i32 buffer_advance;
210
211   union
212   {
213 #define _(a,b,c) vnet_flow_##b##_t b;
214     foreach_flow_type
215 #undef _
216   };
217
218   /* per-interface private data */
219   uword *private_data;
220 } vnet_flow_t;
221
222 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
223                          u32 * start);
224 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
225 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
226 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
227 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
228 vnet_flow_t *vnet_get_flow (u32 flow_index);
229
230 typedef struct
231 {
232   u32 start;
233   u32 count;
234   u8 *owner;
235 } vnet_flow_range_t;
236
237 typedef struct
238 {
239   /* pool of device flow entries */
240   vnet_flow_t *global_flow_pool;
241
242   /* flow ids allocated */
243   u32 flows_used;
244
245   /* vector of flow ranges */
246   vnet_flow_range_t *ranges;
247
248 } vnet_flow_main_t;
249
250 extern vnet_flow_main_t flow_main;
251
252 format_function_t format_flow_actions;
253 format_function_t format_flow_enabled_hw;
254
255 #endif /* included_vnet_flow_flow_h */
256
257 /*
258  * fd.io coding-style-patch-verification: ON
259  *
260  * Local Variables:
261  * eval: (c-set-style "gnu")
262  * End:
263  */