blob: 824f10f4fb77667955aa3c83a5348fa6a3ea889c [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 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 */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070015/**
16 * @file
17 * @brief Functions for encapsulating VXLAN GPE tunnels
18 *
19*/
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#include <vppinfra/error.h>
21#include <vppinfra/hash.h>
22#include <vnet/vnet.h>
23#include <vnet/ip/ip.h>
24#include <vnet/ethernet/ethernet.h>
Florin Corasb040f982020-10-20 14:59:43 -070025#include <vnet/udp/udp_inlines.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070026#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070028/** Statistics (not really errors) */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070029#define foreach_vxlan_gpe_encap_error \
Ed Warnickecb9cada2015-12-08 15:45:58 -070030_(ENCAPSULATED, "good packets encapsulated")
31
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070032/**
33 * @brief VXLAN GPE encap error strings
34 */
sharath reddy6f8273a2017-12-11 11:31:31 +053035static char *vxlan_gpe_encap_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070036#define _(sym,string) string,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070037 foreach_vxlan_gpe_encap_error
Ed Warnickecb9cada2015-12-08 15:45:58 -070038#undef _
39};
40
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070041/**
42 * @brief Struct for VXLAN GPE errors/counters
43 */
sharath reddy6f8273a2017-12-11 11:31:31 +053044typedef enum
45{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070046#define _(sym,str) VXLAN_GPE_ENCAP_ERROR_##sym,
sharath reddy6f8273a2017-12-11 11:31:31 +053047 foreach_vxlan_gpe_encap_error
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#undef _
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070049 VXLAN_GPE_ENCAP_N_ERROR,
50} vxlan_gpe_encap_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070052/**
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070053 * @brief Struct for tracing VXLAN GPE encapsulated packets
54 */
sharath reddy6f8273a2017-12-11 11:31:31 +053055typedef struct
56{
Ed Warnickecb9cada2015-12-08 15:45:58 -070057 u32 tunnel_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070058} vxlan_gpe_encap_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070060/**
61 * @brief Trace of packets encapsulated in VXLAN GPE
62 *
63 * @param *s
64 * @param *args
65 *
66 * @return *s
67 *
68 */
sharath reddy6f8273a2017-12-11 11:31:31 +053069u8 *
70format_vxlan_gpe_encap_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070071{
72 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
73 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
sharath reddy6f8273a2017-12-11 11:31:31 +053074 vxlan_gpe_encap_trace_t *t = va_arg (*args, vxlan_gpe_encap_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070075
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070076 s = format (s, "VXLAN-GPE-ENCAP: tunnel %d", t->tunnel_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 return s;
78}
79
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070080/**
81 * @brief Instantiates UDP + VXLAN-GPE header then set next node to IP4|6 lookup
82 *
83 * @param *ngm
84 * @param *b0
85 * @param *t0 contains rewrite header
86 * @param *next0 relative index of next dispatch function (next node)
87 * @param is_v4 Is this IPv4? (or IPv6)
88 *
89 */
Hongjun Nidf921cc2016-05-25 01:16:19 +080090always_inline void
Mauro Sardara95396472022-03-22 17:53:46 +000091vxlan_gpe_encap_one_inline (vxlan_gpe_main_t *ngm, vlib_buffer_t *b0,
92 vxlan_gpe_tunnel_t *t0, u32 *next0,
93 ip_address_family_t af)
Hongjun Nidf921cc2016-05-25 01:16:19 +080094{
sharath reddy6f8273a2017-12-11 11:31:31 +053095 ASSERT (sizeof (ip4_vxlan_gpe_header_t) == 36);
96 ASSERT (sizeof (ip6_vxlan_gpe_header_t) == 56);
Hongjun Nidf921cc2016-05-25 01:16:19 +080097
Mauro Sardara95396472022-03-22 17:53:46 +000098 ip_udp_encap_one (ngm->vlib_main, b0, t0->rewrite, t0->rewrite_size, af,
Vladislav Grishenko5c801b32022-06-23 00:45:16 +050099 N_AF, UDP_ENCAP_FIXUP_NONE);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700100 next0[0] = t0->encap_next_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800101}
102
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700103/**
104 * @brief Instantiates UDP + VXLAN-GPE header then set next node to IP4|6 lookup for two packets
105 *
106 * @param *ngm
107 * @param *b0 Packet0
108 * @param *b1 Packet1
109 * @param *t0 contains rewrite header for Packet0
110 * @param *t1 contains rewrite header for Packet1
111 * @param *next0 relative index of next dispatch function (next node) for Packet0
112 * @param *next1 relative index of next dispatch function (next node) for Packet1
113 * @param is_v4 Is this IPv4? (or IPv6)
114 *
115 */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800116always_inline void
Mauro Sardara95396472022-03-22 17:53:46 +0000117vxlan_gpe_encap_two_inline (vxlan_gpe_main_t *ngm, vlib_buffer_t *b0,
118 vlib_buffer_t *b1, vxlan_gpe_tunnel_t *t0,
119 vxlan_gpe_tunnel_t *t1, u32 *next0, u32 *next1,
120 ip_address_family_t af)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800121{
sharath reddy6f8273a2017-12-11 11:31:31 +0530122 ASSERT (sizeof (ip4_vxlan_gpe_header_t) == 36);
123 ASSERT (sizeof (ip6_vxlan_gpe_header_t) == 56);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800124
Mauro Sardara95396472022-03-22 17:53:46 +0000125 ip_udp_encap_one (ngm->vlib_main, b0, t0->rewrite, t0->rewrite_size, af,
Vladislav Grishenko5c801b32022-06-23 00:45:16 +0500126 N_AF, UDP_ENCAP_FIXUP_NONE);
Mauro Sardara95396472022-03-22 17:53:46 +0000127 ip_udp_encap_one (ngm->vlib_main, b1, t1->rewrite, t1->rewrite_size, af,
Vladislav Grishenko5c801b32022-06-23 00:45:16 +0500128 N_AF, UDP_ENCAP_FIXUP_NONE);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700129 next0[0] = next1[0] = t0->encap_next_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800130}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700132/**
133 * @brief Common processing for IPv4 and IPv6 VXLAN GPE encap dispatch functions
134 *
135 * It is worth noting that other than trivial UDP forwarding (transit), VXLAN GPE
136 * tunnels are "establish local". This means that we don't have a TX interface as yet
137 * as we need to look up where the outer-header dest is. By setting the TX index in the
138 * buffer metadata to the encap FIB, we can do a lookup to get the adjacency and real TX.
139 *
140 * vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index;
141 *
142 * @node vxlan-gpe-input
143 * @param *vm
144 * @param *node
145 * @param *from_frame
146 *
147 * @return from_frame->n_vectors
148 *
149 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150static uword
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700151vxlan_gpe_encap (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530152 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153{
Hongjun Nidf921cc2016-05-25 01:16:19 +0800154 u32 n_left_from, next_index, *from, *to_next;
sharath reddy6f8273a2017-12-11 11:31:31 +0530155 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
156 vnet_main_t *vnm = ngm->vnet_main;
157 vnet_interface_main_t *im = &vnm->interface_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 u32 pkts_encapsulated = 0;
Damjan Marion067cd622018-07-11 12:47:43 +0200159 u32 thread_index = vm->thread_index;
Hongjun Nib2cdd2f2016-04-06 16:20:22 -0700160 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
Zhiyong Yang359776a2019-05-16 04:03:18 -0400161 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
163 from = vlib_frame_vector_args (from_frame);
164 n_left_from = from_frame->n_vectors;
165
166 next_index = node->cached_next_index;
Hongjun Nib2cdd2f2016-04-06 16:20:22 -0700167 stats_sw_if_index = node->runtime_data[0];
168 stats_n_packets = stats_n_bytes = 0;
Zhiyong Yang359776a2019-05-16 04:03:18 -0400169 vlib_get_buffers (vm, from, bufs, n_left_from);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
171 while (n_left_from > 0)
172 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530173 u32 n_left_to_next;
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400174 u32 sw_if_index0 = ~0, sw_if_index1 = ~0, len0, len1;
175 vnet_hw_interface_t *hi0, *hi1;
176 vxlan_gpe_tunnel_t *t0 = NULL, *t1 = NULL;
Mauro Sardara95396472022-03-22 17:53:46 +0000177 ip_address_family_t af_0 = AF_IP4, af_1 = AF_IP4;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
sharath reddy6f8273a2017-12-11 11:31:31 +0530179 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180
sharath reddy6f8273a2017-12-11 11:31:31 +0530181 while (n_left_from >= 4 && n_left_to_next >= 2)
182 {
183 u32 bi0, bi1;
sharath reddy6f8273a2017-12-11 11:31:31 +0530184 u32 next0, next1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
sharath reddy6f8273a2017-12-11 11:31:31 +0530186 next0 = next1 = VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700187
sharath reddy6f8273a2017-12-11 11:31:31 +0530188 /* Prefetch next iteration. */
189 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400190 vlib_prefetch_buffer_header (b[2], LOAD);
191 vlib_prefetch_buffer_header (b[3], LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700192
Zhiyong Yang359776a2019-05-16 04:03:18 -0400193 CLIB_PREFETCH (b[2]->data - CLIB_CACHE_LINE_BYTES,
194 2 * CLIB_CACHE_LINE_BYTES, LOAD);
195 CLIB_PREFETCH (b[3]->data - CLIB_CACHE_LINE_BYTES,
196 2 * CLIB_CACHE_LINE_BYTES, LOAD);
sharath reddy6f8273a2017-12-11 11:31:31 +0530197 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700198
sharath reddy6f8273a2017-12-11 11:31:31 +0530199 bi0 = from[0];
200 bi1 = from[1];
201 to_next[0] = bi0;
202 to_next[1] = bi1;
203 from += 2;
204 to_next += 2;
205 n_left_to_next -= 2;
206 n_left_from -= 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207
Mauro Sardara95396472022-03-22 17:53:46 +0000208 /* get "af_0" */
Zhiyong Yang359776a2019-05-16 04:03:18 -0400209 if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX])
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400210 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400211 sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400212 hi0 =
213 vnet_get_sup_hw_interface (vnm,
Zhiyong Yang359776a2019-05-16 04:03:18 -0400214 vnet_buffer (b[0])->sw_if_index
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400215 [VLIB_TX]);
216 t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
Mauro Sardara95396472022-03-22 17:53:46 +0000217 af_0 = (t0->flags & VXLAN_GPE_TUNNEL_IS_IPV4 ? AF_IP4 : AF_IP6);
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400218 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219
Mauro Sardara95396472022-03-22 17:53:46 +0000220 /* get "af_1" */
Zhiyong Yang359776a2019-05-16 04:03:18 -0400221 if (sw_if_index1 != vnet_buffer (b[1])->sw_if_index[VLIB_TX])
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400222 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400223 if (sw_if_index0 == vnet_buffer (b[1])->sw_if_index[VLIB_TX])
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400224 {
225 sw_if_index1 = sw_if_index0;
226 hi1 = hi0;
227 t1 = t0;
Mauro Sardara95396472022-03-22 17:53:46 +0000228 af_1 = af_0;
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400229 }
230 else
231 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400232 sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400233 hi1 =
234 vnet_get_sup_hw_interface (vnm,
Zhiyong Yang359776a2019-05-16 04:03:18 -0400235 vnet_buffer (b[1])->sw_if_index
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400236 [VLIB_TX]);
237 t1 = pool_elt_at_index (ngm->tunnels, hi1->dev_instance);
Mauro Sardara95396472022-03-22 17:53:46 +0000238 af_1 =
239 (t1->flags & VXLAN_GPE_TUNNEL_IS_IPV4 ? AF_IP4 : AF_IP6);
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400240 }
241 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242
Mauro Sardara95396472022-03-22 17:53:46 +0000243 if (PREDICT_TRUE (af_0 == af_1))
sharath reddy6f8273a2017-12-11 11:31:31 +0530244 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400245 vxlan_gpe_encap_two_inline (ngm, b[0], b[1], t0, t1, &next0,
Mauro Sardara95396472022-03-22 17:53:46 +0000246 &next1, af_0);
sharath reddy6f8273a2017-12-11 11:31:31 +0530247 }
248 else
249 {
Mauro Sardara95396472022-03-22 17:53:46 +0000250 vxlan_gpe_encap_one_inline (ngm, b[0], t0, &next0, af_0);
251 vxlan_gpe_encap_one_inline (ngm, b[1], t1, &next1, af_1);
sharath reddy6f8273a2017-12-11 11:31:31 +0530252 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253
sharath reddy6f8273a2017-12-11 11:31:31 +0530254 /* Reset to look up tunnel partner in the configured FIB */
Zhiyong Yang359776a2019-05-16 04:03:18 -0400255 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = t0->encap_fib_index;
256 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = t1->encap_fib_index;
257 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0;
258 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = sw_if_index1;
sharath reddy6f8273a2017-12-11 11:31:31 +0530259 pkts_encapsulated += 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260
Zhiyong Yang359776a2019-05-16 04:03:18 -0400261 len0 = vlib_buffer_length_in_chain (vm, b[0]);
262 len1 = vlib_buffer_length_in_chain (vm, b[1]);
sharath reddy6f8273a2017-12-11 11:31:31 +0530263 stats_n_packets += 2;
264 stats_n_bytes += len0 + len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
sharath reddy6f8273a2017-12-11 11:31:31 +0530266 /* Batch stats increment on the same vxlan tunnel so counter is not
267 incremented per packet. Note stats are still incremented for deleted
268 and admin-down tunnel where packets are dropped. It is not worthwhile
269 to check for this rare case and affect normal path performance. */
270 if (PREDICT_FALSE ((sw_if_index0 != stats_sw_if_index)
271 || (sw_if_index1 != stats_sw_if_index)))
272 {
273 stats_n_packets -= 2;
274 stats_n_bytes -= len0 + len1;
275 if (sw_if_index0 == sw_if_index1)
276 {
277 if (stats_n_packets)
278 vlib_increment_combined_counter
279 (im->combined_sw_if_counters +
280 VNET_INTERFACE_COUNTER_TX, thread_index,
281 stats_sw_if_index, stats_n_packets, stats_n_bytes);
282 stats_sw_if_index = sw_if_index0;
283 stats_n_packets = 2;
284 stats_n_bytes = len0 + len1;
285 }
286 else
287 {
288 vlib_increment_combined_counter (im->combined_sw_if_counters
289 +
290 VNET_INTERFACE_COUNTER_TX,
291 thread_index, sw_if_index0,
292 1, len0);
293 vlib_increment_combined_counter (im->combined_sw_if_counters
294 +
295 VNET_INTERFACE_COUNTER_TX,
296 thread_index, sw_if_index1,
297 1, len1);
298 }
299 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300
Zhiyong Yang359776a2019-05-16 04:03:18 -0400301 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
sharath reddy6f8273a2017-12-11 11:31:31 +0530302 {
303 vxlan_gpe_encap_trace_t *tr =
Zhiyong Yang359776a2019-05-16 04:03:18 -0400304 vlib_add_trace (vm, node, b[0], sizeof (*tr));
sharath reddy6f8273a2017-12-11 11:31:31 +0530305 tr->tunnel_index = t0 - ngm->tunnels;
306 }
307
Zhiyong Yang359776a2019-05-16 04:03:18 -0400308 if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
sharath reddy6f8273a2017-12-11 11:31:31 +0530309 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400310 vxlan_gpe_encap_trace_t *tr = vlib_add_trace (vm, node, b[1],
sharath reddy6f8273a2017-12-11 11:31:31 +0530311 sizeof (*tr));
312 tr->tunnel_index = t1 - ngm->tunnels;
313 }
Zhiyong Yang359776a2019-05-16 04:03:18 -0400314 b += 2;
sharath reddy6f8273a2017-12-11 11:31:31 +0530315
316 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
317 n_left_to_next, bi0, bi1, next0,
318 next1);
319 }
320
321 while (n_left_from > 0 && n_left_to_next > 0)
322 {
323 u32 bi0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530324 u32 next0 = VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP;
sharath reddy6f8273a2017-12-11 11:31:31 +0530325
326 bi0 = from[0];
327 to_next[0] = bi0;
328 from += 1;
329 to_next += 1;
330 n_left_from -= 1;
331 n_left_to_next -= 1;
332
Mauro Sardara95396472022-03-22 17:53:46 +0000333 /* get "af_0" */
Zhiyong Yang359776a2019-05-16 04:03:18 -0400334 if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX])
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400335 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400336 sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400337 hi0 =
338 vnet_get_sup_hw_interface (vnm,
Zhiyong Yang359776a2019-05-16 04:03:18 -0400339 vnet_buffer (b[0])->sw_if_index
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400340 [VLIB_TX]);
sharath reddy6f8273a2017-12-11 11:31:31 +0530341
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400342 t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
sharath reddy6f8273a2017-12-11 11:31:31 +0530343
Mauro Sardara95396472022-03-22 17:53:46 +0000344 af_0 = (t0->flags & VXLAN_GPE_TUNNEL_IS_IPV4 ? AF_IP4 : AF_IP6);
Zhiyong Yang6011b5e2018-09-04 06:33:18 -0400345 }
sharath reddy6f8273a2017-12-11 11:31:31 +0530346
Mauro Sardara95396472022-03-22 17:53:46 +0000347 vxlan_gpe_encap_one_inline (ngm, b[0], t0, &next0, af_0);
sharath reddy6f8273a2017-12-11 11:31:31 +0530348
349 /* Reset to look up tunnel partner in the configured FIB */
Zhiyong Yang359776a2019-05-16 04:03:18 -0400350 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = t0->encap_fib_index;
351 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530352 pkts_encapsulated++;
353
Zhiyong Yang359776a2019-05-16 04:03:18 -0400354 len0 = vlib_buffer_length_in_chain (vm, b[0]);
sharath reddy6f8273a2017-12-11 11:31:31 +0530355 stats_n_packets += 1;
356 stats_n_bytes += len0;
357
358 /* Batch stats increment on the same vxlan tunnel so counter is not
359 * incremented per packet. Note stats are still incremented for deleted
360 * and admin-down tunnel where packets are dropped. It is not worthwhile
361 * to check for this rare case and affect normal path performance. */
362 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
363 {
364 stats_n_packets -= 1;
365 stats_n_bytes -= len0;
366 if (stats_n_packets)
367 vlib_increment_combined_counter (im->combined_sw_if_counters +
368 VNET_INTERFACE_COUNTER_TX,
369 thread_index,
370 stats_sw_if_index,
371 stats_n_packets,
372 stats_n_bytes);
373 stats_n_packets = 1;
374 stats_n_bytes = len0;
375 stats_sw_if_index = sw_if_index0;
376 }
Zhiyong Yang359776a2019-05-16 04:03:18 -0400377 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
sharath reddy6f8273a2017-12-11 11:31:31 +0530378 {
Zhiyong Yang359776a2019-05-16 04:03:18 -0400379 vxlan_gpe_encap_trace_t *tr = vlib_add_trace (vm, node, b[0],
sharath reddy6f8273a2017-12-11 11:31:31 +0530380 sizeof (*tr));
381 tr->tunnel_index = t0 - ngm->tunnels;
382 }
Zhiyong Yang359776a2019-05-16 04:03:18 -0400383 b += 1;
384
sharath reddy6f8273a2017-12-11 11:31:31 +0530385 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
386 n_left_to_next, bi0, next0);
387 }
388
389 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 }
Hongjun Nib2cdd2f2016-04-06 16:20:22 -0700391 vlib_node_increment_counter (vm, node->node_index,
sharath reddy6f8273a2017-12-11 11:31:31 +0530392 VXLAN_GPE_ENCAP_ERROR_ENCAPSULATED,
393 pkts_encapsulated);
Hongjun Nib2cdd2f2016-04-06 16:20:22 -0700394 /* Increment any remaining batch stats */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800395 if (stats_n_packets)
sharath reddy6f8273a2017-12-11 11:31:31 +0530396 {
397 vlib_increment_combined_counter (im->combined_sw_if_counters +
398 VNET_INTERFACE_COUNTER_TX,
399 thread_index, stats_sw_if_index,
400 stats_n_packets, stats_n_bytes);
401 node->runtime_data[0] = stats_sw_if_index;
402 }
Hongjun Nib2cdd2f2016-04-06 16:20:22 -0700403
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404 return from_frame->n_vectors;
405}
406
sharath reddy6f8273a2017-12-11 11:31:31 +0530407/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700408VLIB_REGISTER_NODE (vxlan_gpe_encap_node) = {
409 .function = vxlan_gpe_encap,
410 .name = "vxlan-gpe-encap",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 .vector_size = sizeof (u32),
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700412 .format_trace = format_vxlan_gpe_encap_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700413 .type = VLIB_NODE_TYPE_INTERNAL,
414
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700415 .n_errors = ARRAY_LEN(vxlan_gpe_encap_error_strings),
416 .error_strings = vxlan_gpe_encap_error_strings,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700418 .n_next_nodes = VXLAN_GPE_ENCAP_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419
420 .next_nodes = {
Hongjun Nidf921cc2016-05-25 01:16:19 +0800421 [VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP] = "ip4-lookup",
Hongjun Nibeb4bf72016-11-25 00:03:46 +0800422 [VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
Hongjun Nidf921cc2016-05-25 01:16:19 +0800423 [VXLAN_GPE_ENCAP_NEXT_DROP] = "error-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424 },
425};
sharath reddy6f8273a2017-12-11 11:31:31 +0530426/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700427
sharath reddy6f8273a2017-12-11 11:31:31 +0530428
429/*
430 * fd.io coding-style-patch-verification: ON
431 *
432 * Local Variables:
433 * eval: (c-set-style "gnu")
434 * End:
435 */