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") \
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")
46 #define foreach_flow_entry_ethernet \
47 _fe(ethernet_header_t, eth_hdr)
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)
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)
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)
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)
78 #define foreach_flow_entry_ip4_vxlan \
79 _fe(ip4_address_t, src_addr) \
80 _fe(ip4_address_t, dst_addr) \
84 #define foreach_flow_entry_ip6_vxlan \
85 _fe(ip6_address_t, src_addr) \
86 _fe(ip6_address_t, dst_addr) \
90 #define foreach_flow_entry_ip4_gtpc \
91 foreach_flow_entry_ip4_n_tuple \
94 #define foreach_flow_entry_ip4_gtpu \
95 foreach_flow_entry_ip4_n_tuple \
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)
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)
108 #define foreach_flow_entry_ip6_gtpc \
109 foreach_flow_entry_ip6_n_tuple \
112 #define foreach_flow_entry_ip6_gtpu \
113 foreach_flow_entry_ip6_n_tuple \
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)
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)
126 #define foreach_flow_action \
127 _(0, COUNT, "count") \
129 _(2, BUFFER_ADVANCE, "buffer-advance") \
130 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
131 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
137 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
140 } vnet_flow_action_t;
143 #define foreach_flow_error \
144 _( -1, NOT_SUPPORTED, "not supported") \
145 _( -2, ALREADY_DONE, "already done") \
146 _( -3, ALREADY_EXISTS, "already exists") \
147 _( -4, NO_SUCH_ENTRY, "no such entry") \
148 _( -5, NO_SUCH_INTERFACE, "no such interface") \
149 _( -6, INTERNAL, "internal error")
151 #define foreach_flow_rss_types \
152 _(0, FRAG_IPV4, "ipv4-frag") \
153 _(1, IPV4_TCP, "ipv4-tcp") \
154 _(2, IPV4_UDP, "ipv4-udp") \
155 _(3, IPV4_SCTP, "ipv4-sctp") \
156 _(4, IPV4_OTHER, "ipv4-other") \
158 _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
159 _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
160 _(8, FRAG_IPV6, "ipv6-frag") \
161 _(9, IPV6_TCP, "ipv6-tcp") \
162 _(10, IPV6_UDP, "ipv6-udp") \
163 _(11, IPV6_SCTP, "ipv6-sctp") \
164 _(12, IPV6_OTHER, "ipv6-other") \
165 _(13, IPV6_EX, "ipv6-ex") \
166 _(14, IPV6, "ipv6") \
167 _(15, L2_PAYLOAD, "l2-payload") \
168 _(16, PORT, "port") \
169 _(17, VXLAN, "vxlan") \
170 _(18, GENEVE, "geneve") \
171 _(19, NVGRE, "nvgre") \
172 _(20, GTPU, "gtpu") \
173 _(60, L4_DST_ONLY, "l4-dst-only") \
174 _(61, L4_SRC_ONLY, "l4-src-only") \
175 _(62, L3_DST_ONLY, "l3-dst-only") \
176 _(63, L3_SRC_ONLY, "l3-src-only")
178 #define foreach_rss_function \
179 _(DEFAULT, "default") \
180 _(TOEPLITZ, "toeplitz") \
181 _(SIMPLE_XOR, "simple_xor") \
182 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
186 VNET_FLOW_NO_ERROR = 0,
187 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
195 } ip_port_and_mask_t;
199 VNET_FLOW_TYPE_UNKNOWN,
200 #define _(a,b,c) VNET_FLOW_TYPE_##a,
208 #define _(a,b) VNET_RSS_FUNC_##a,
212 } vnet_rss_function_t;
215 * Create typedef struct vnet_flow_XXX_t
217 #define _fe(a, b) a b;
221 foreach_flow_entry_##b \
227 /* main flow struct */
231 vnet_flow_type_t type;
236 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
239 /* flow id for VNET_FLOW_ACTION_MARK */
242 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
243 u32 redirect_node_index;
244 u32 redirect_device_input_next_index;
246 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
249 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
252 /* RSS types, including IPv4/IPv6/TCP/UDP... */
255 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
256 vnet_rss_function_t rss_fun;
260 #define _(a,b,c) vnet_flow_##b##_t b;
265 /* per-interface private data */
269 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
271 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
272 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
273 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
274 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
275 vnet_flow_t *vnet_get_flow (u32 flow_index);
286 /* pool of device flow entries */
287 vnet_flow_t *global_flow_pool;
289 /* flow ids allocated */
292 /* vector of flow ranges */
293 vnet_flow_range_t *ranges;
297 extern vnet_flow_main_t flow_main;
299 format_function_t format_flow_actions;
300 format_function_t format_flow_enabled_hw;
302 #endif /* included_vnet_flow_flow_h */
305 * fd.io coding-style-patch-verification: ON
308 * eval: (c-set-style "gnu")