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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vnet_flow_flow_h
17 #define included_vnet_flow_flow_h
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>
26 #define foreach_flow_type \
28 _(ETHERNET, ethernet, "ethernet") \
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") \
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")
48 #define foreach_flow_entry_ethernet \
49 _fe(ethernet_header_t, eth_hdr)
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)
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)
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)
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)
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) \
85 #define foreach_flow_entry_ip4_vxlan \
86 _fe(ip4_address_t, src_addr) \
87 _fe(ip4_address_t, dst_addr) \
91 #define foreach_flow_entry_ip6_vxlan \
92 _fe(ip6_address_t, src_addr) \
93 _fe(ip6_address_t, dst_addr) \
97 #define foreach_flow_entry_ip4_gtpc \
98 foreach_flow_entry_ip4_n_tuple \
101 #define foreach_flow_entry_ip4_gtpu \
102 foreach_flow_entry_ip4_n_tuple \
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)
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)
115 #define foreach_flow_entry_ip6_gtpc \
116 foreach_flow_entry_ip6_n_tuple \
119 #define foreach_flow_entry_ip6_gtpu \
120 foreach_flow_entry_ip6_n_tuple \
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)
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)
133 #define foreach_flow_action \
134 _(0, COUNT, "count") \
136 _(2, BUFFER_ADVANCE, "buffer-advance") \
137 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
138 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
144 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
147 } vnet_flow_action_t;
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")
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") \
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")
185 #define foreach_rss_function \
186 _(DEFAULT, "default") \
187 _(TOEPLITZ, "toeplitz") \
188 _(SIMPLE_XOR, "simple_xor") \
189 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
193 VNET_FLOW_NO_ERROR = 0,
194 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
202 } ip_port_and_mask_t;
206 VNET_FLOW_TYPE_UNKNOWN,
207 #define _(a,b,c) VNET_FLOW_TYPE_##a,
215 #define _(a,b) VNET_RSS_FUNC_##a,
219 } vnet_rss_function_t;
222 * Create typedef struct vnet_flow_XXX_t
224 #define _fe(a, b) a b;
228 foreach_flow_entry_##b \
234 /* main flow struct */
238 vnet_flow_type_t type;
243 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
246 /* flow id for VNET_FLOW_ACTION_MARK */
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;
253 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
256 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
259 /* RSS types, including IPv4/IPv6/TCP/UDP... */
262 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
263 vnet_rss_function_t rss_fun;
267 #define _(a,b,c) vnet_flow_##b##_t b;
272 /* per-interface private data */
276 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
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);
293 /* pool of device flow entries */
294 vnet_flow_t *global_flow_pool;
296 /* flow ids allocated */
299 /* vector of flow ranges */
300 vnet_flow_range_t *ranges;
304 extern vnet_flow_main_t flow_main;
306 format_function_t format_flow_actions;
307 format_function_t format_flow_enabled_hw;
309 #endif /* included_vnet_flow_flow_h */
312 * fd.io coding-style-patch-verification: ON
315 * eval: (c-set-style "gnu")