Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 15 | /** |
| 16 | * @file |
| 17 | * @brief Functions for encapsulating VXLAN GPE tunnels |
| 18 | * |
| 19 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #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 Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 25 | #include <vnet/udp/udp_inlines.h> |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 26 | #include <vnet/vxlan-gpe/vxlan_gpe.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 28 | /** Statistics (not really errors) */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 29 | #define foreach_vxlan_gpe_encap_error \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | _(ENCAPSULATED, "good packets encapsulated") |
| 31 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 32 | /** |
| 33 | * @brief VXLAN GPE encap error strings |
| 34 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 35 | static char *vxlan_gpe_encap_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | #define _(sym,string) string, |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 37 | foreach_vxlan_gpe_encap_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | #undef _ |
| 39 | }; |
| 40 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 41 | /** |
| 42 | * @brief Struct for VXLAN GPE errors/counters |
| 43 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 44 | typedef enum |
| 45 | { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 46 | #define _(sym,str) VXLAN_GPE_ENCAP_ERROR_##sym, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 47 | foreach_vxlan_gpe_encap_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | #undef _ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 49 | VXLAN_GPE_ENCAP_N_ERROR, |
| 50 | } vxlan_gpe_encap_error_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 52 | /** |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 53 | * @brief Struct for tracing VXLAN GPE encapsulated packets |
| 54 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 55 | typedef struct |
| 56 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | u32 tunnel_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 58 | } vxlan_gpe_encap_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 60 | /** |
| 61 | * @brief Trace of packets encapsulated in VXLAN GPE |
| 62 | * |
| 63 | * @param *s |
| 64 | * @param *args |
| 65 | * |
| 66 | * @return *s |
| 67 | * |
| 68 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 69 | u8 * |
| 70 | format_vxlan_gpe_encap_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | { |
| 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 reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 74 | vxlan_gpe_encap_trace_t *t = va_arg (*args, vxlan_gpe_encap_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 76 | s = format (s, "VXLAN-GPE-ENCAP: tunnel %d", t->tunnel_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | return s; |
| 78 | } |
| 79 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 80 | /** |
| 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 Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 90 | always_inline void |
| 91 | vxlan_gpe_encap_one_inline (vxlan_gpe_main_t * ngm, vlib_buffer_t * b0, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 92 | vxlan_gpe_tunnel_t * t0, u32 * next0, u8 is_v4) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 93 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 94 | ASSERT (sizeof (ip4_vxlan_gpe_header_t) == 36); |
| 95 | ASSERT (sizeof (ip6_vxlan_gpe_header_t) == 56); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 96 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 97 | ip_udp_encap_one (ngm->vlib_main, b0, t0->rewrite, t0->rewrite_size, is_v4); |
| 98 | next0[0] = t0->encap_next_node; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 99 | } |
| 100 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @brief Instantiates UDP + VXLAN-GPE header then set next node to IP4|6 lookup for two packets |
| 103 | * |
| 104 | * @param *ngm |
| 105 | * @param *b0 Packet0 |
| 106 | * @param *b1 Packet1 |
| 107 | * @param *t0 contains rewrite header for Packet0 |
| 108 | * @param *t1 contains rewrite header for Packet1 |
| 109 | * @param *next0 relative index of next dispatch function (next node) for Packet0 |
| 110 | * @param *next1 relative index of next dispatch function (next node) for Packet1 |
| 111 | * @param is_v4 Is this IPv4? (or IPv6) |
| 112 | * |
| 113 | */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 114 | always_inline void |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 115 | vxlan_gpe_encap_two_inline (vxlan_gpe_main_t * ngm, vlib_buffer_t * b0, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 116 | vlib_buffer_t * b1, vxlan_gpe_tunnel_t * t0, |
| 117 | vxlan_gpe_tunnel_t * t1, u32 * next0, |
| 118 | u32 * next1, u8 is_v4) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 119 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 120 | ASSERT (sizeof (ip4_vxlan_gpe_header_t) == 36); |
| 121 | ASSERT (sizeof (ip6_vxlan_gpe_header_t) == 56); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 122 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 123 | ip_udp_encap_one (ngm->vlib_main, b0, t0->rewrite, t0->rewrite_size, is_v4); |
| 124 | ip_udp_encap_one (ngm->vlib_main, b1, t1->rewrite, t1->rewrite_size, is_v4); |
| 125 | next0[0] = next1[0] = t0->encap_next_node; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 126 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 128 | /** |
| 129 | * @brief Common processing for IPv4 and IPv6 VXLAN GPE encap dispatch functions |
| 130 | * |
| 131 | * It is worth noting that other than trivial UDP forwarding (transit), VXLAN GPE |
| 132 | * tunnels are "establish local". This means that we don't have a TX interface as yet |
| 133 | * as we need to look up where the outer-header dest is. By setting the TX index in the |
| 134 | * buffer metadata to the encap FIB, we can do a lookup to get the adjacency and real TX. |
| 135 | * |
| 136 | * vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index; |
| 137 | * |
| 138 | * @node vxlan-gpe-input |
| 139 | * @param *vm |
| 140 | * @param *node |
| 141 | * @param *from_frame |
| 142 | * |
| 143 | * @return from_frame->n_vectors |
| 144 | * |
| 145 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | static uword |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 147 | vxlan_gpe_encap (vlib_main_t * vm, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 148 | vlib_node_runtime_t * node, vlib_frame_t * from_frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 150 | u32 n_left_from, next_index, *from, *to_next; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 151 | vxlan_gpe_main_t *ngm = &vxlan_gpe_main; |
| 152 | vnet_main_t *vnm = ngm->vnet_main; |
| 153 | vnet_interface_main_t *im = &vnm->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | u32 pkts_encapsulated = 0; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 155 | u32 thread_index = vm->thread_index; |
Hongjun Ni | b2cdd2f | 2016-04-06 16:20:22 -0700 | [diff] [blame] | 156 | u32 stats_sw_if_index, stats_n_packets, stats_n_bytes; |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 157 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | |
| 159 | from = vlib_frame_vector_args (from_frame); |
| 160 | n_left_from = from_frame->n_vectors; |
| 161 | |
| 162 | next_index = node->cached_next_index; |
Hongjun Ni | b2cdd2f | 2016-04-06 16:20:22 -0700 | [diff] [blame] | 163 | stats_sw_if_index = node->runtime_data[0]; |
| 164 | stats_n_packets = stats_n_bytes = 0; |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 165 | vlib_get_buffers (vm, from, bufs, n_left_from); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | |
| 167 | while (n_left_from > 0) |
| 168 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 169 | u32 n_left_to_next; |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 170 | u32 sw_if_index0 = ~0, sw_if_index1 = ~0, len0, len1; |
| 171 | vnet_hw_interface_t *hi0, *hi1; |
| 172 | vxlan_gpe_tunnel_t *t0 = NULL, *t1 = NULL; |
| 173 | u8 is_ip4_0 = 0, is_ip4_1 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 175 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 177 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 178 | { |
| 179 | u32 bi0, bi1; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 180 | u32 next0, next1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 182 | next0 = next1 = VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 184 | /* Prefetch next iteration. */ |
| 185 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 186 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 187 | vlib_prefetch_buffer_header (b[3], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 189 | CLIB_PREFETCH (b[2]->data - CLIB_CACHE_LINE_BYTES, |
| 190 | 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 191 | CLIB_PREFETCH (b[3]->data - CLIB_CACHE_LINE_BYTES, |
| 192 | 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 193 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 194 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 195 | bi0 = from[0]; |
| 196 | bi1 = from[1]; |
| 197 | to_next[0] = bi0; |
| 198 | to_next[1] = bi1; |
| 199 | from += 2; |
| 200 | to_next += 2; |
| 201 | n_left_to_next -= 2; |
| 202 | n_left_from -= 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 204 | /* get the flag "is_ip4" */ |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 205 | if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX]) |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 206 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 207 | sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 208 | hi0 = |
| 209 | vnet_get_sup_hw_interface (vnm, |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 210 | vnet_buffer (b[0])->sw_if_index |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 211 | [VLIB_TX]); |
| 212 | t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance); |
| 213 | is_ip4_0 = (t0->flags & VXLAN_GPE_TUNNEL_IS_IPV4); |
| 214 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 216 | /* get the flag "is_ip4" */ |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 217 | if (sw_if_index1 != vnet_buffer (b[1])->sw_if_index[VLIB_TX]) |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 218 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 219 | if (sw_if_index0 == vnet_buffer (b[1])->sw_if_index[VLIB_TX]) |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 220 | { |
| 221 | sw_if_index1 = sw_if_index0; |
| 222 | hi1 = hi0; |
| 223 | t1 = t0; |
| 224 | is_ip4_1 = is_ip4_0; |
| 225 | } |
| 226 | else |
| 227 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 228 | sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 229 | hi1 = |
| 230 | vnet_get_sup_hw_interface (vnm, |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 231 | vnet_buffer (b[1])->sw_if_index |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 232 | [VLIB_TX]); |
| 233 | t1 = pool_elt_at_index (ngm->tunnels, hi1->dev_instance); |
| 234 | is_ip4_1 = (t1->flags & VXLAN_GPE_TUNNEL_IS_IPV4); |
| 235 | } |
| 236 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 238 | if (PREDICT_TRUE (is_ip4_0 == is_ip4_1)) |
| 239 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 240 | vxlan_gpe_encap_two_inline (ngm, b[0], b[1], t0, t1, &next0, |
| 241 | &next1, is_ip4_0); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 245 | vxlan_gpe_encap_one_inline (ngm, b[0], t0, &next0, is_ip4_0); |
| 246 | vxlan_gpe_encap_one_inline (ngm, b[1], t1, &next1, is_ip4_1); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 247 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 249 | /* Reset to look up tunnel partner in the configured FIB */ |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 250 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = t0->encap_fib_index; |
| 251 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] = t1->encap_fib_index; |
| 252 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0; |
| 253 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = sw_if_index1; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 254 | pkts_encapsulated += 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 256 | len0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 257 | len1 = vlib_buffer_length_in_chain (vm, b[1]); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 258 | stats_n_packets += 2; |
| 259 | stats_n_bytes += len0 + len1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 261 | /* Batch stats increment on the same vxlan tunnel so counter is not |
| 262 | incremented per packet. Note stats are still incremented for deleted |
| 263 | and admin-down tunnel where packets are dropped. It is not worthwhile |
| 264 | to check for this rare case and affect normal path performance. */ |
| 265 | if (PREDICT_FALSE ((sw_if_index0 != stats_sw_if_index) |
| 266 | || (sw_if_index1 != stats_sw_if_index))) |
| 267 | { |
| 268 | stats_n_packets -= 2; |
| 269 | stats_n_bytes -= len0 + len1; |
| 270 | if (sw_if_index0 == sw_if_index1) |
| 271 | { |
| 272 | if (stats_n_packets) |
| 273 | vlib_increment_combined_counter |
| 274 | (im->combined_sw_if_counters + |
| 275 | VNET_INTERFACE_COUNTER_TX, thread_index, |
| 276 | stats_sw_if_index, stats_n_packets, stats_n_bytes); |
| 277 | stats_sw_if_index = sw_if_index0; |
| 278 | stats_n_packets = 2; |
| 279 | stats_n_bytes = len0 + len1; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 284 | + |
| 285 | VNET_INTERFACE_COUNTER_TX, |
| 286 | thread_index, sw_if_index0, |
| 287 | 1, len0); |
| 288 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 289 | + |
| 290 | VNET_INTERFACE_COUNTER_TX, |
| 291 | thread_index, sw_if_index1, |
| 292 | 1, len1); |
| 293 | } |
| 294 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 296 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 297 | { |
| 298 | vxlan_gpe_encap_trace_t *tr = |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 299 | vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 300 | tr->tunnel_index = t0 - ngm->tunnels; |
| 301 | } |
| 302 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 303 | if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 304 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 305 | vxlan_gpe_encap_trace_t *tr = vlib_add_trace (vm, node, b[1], |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 306 | sizeof (*tr)); |
| 307 | tr->tunnel_index = t1 - ngm->tunnels; |
| 308 | } |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 309 | b += 2; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 310 | |
| 311 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 312 | n_left_to_next, bi0, bi1, next0, |
| 313 | next1); |
| 314 | } |
| 315 | |
| 316 | while (n_left_from > 0 && n_left_to_next > 0) |
| 317 | { |
| 318 | u32 bi0; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 319 | u32 next0 = VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 320 | |
| 321 | bi0 = from[0]; |
| 322 | to_next[0] = bi0; |
| 323 | from += 1; |
| 324 | to_next += 1; |
| 325 | n_left_from -= 1; |
| 326 | n_left_to_next -= 1; |
| 327 | |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 328 | /* get the flag "is_ip4" */ |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 329 | if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX]) |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 330 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 331 | sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 332 | hi0 = |
| 333 | vnet_get_sup_hw_interface (vnm, |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 334 | vnet_buffer (b[0])->sw_if_index |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 335 | [VLIB_TX]); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 336 | |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 337 | t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 338 | |
Zhiyong Yang | 6011b5e | 2018-09-04 06:33:18 -0400 | [diff] [blame] | 339 | is_ip4_0 = (t0->flags & VXLAN_GPE_TUNNEL_IS_IPV4); |
| 340 | } |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 341 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 342 | vxlan_gpe_encap_one_inline (ngm, b[0], t0, &next0, is_ip4_0); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 343 | |
| 344 | /* Reset to look up tunnel partner in the configured FIB */ |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 345 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = t0->encap_fib_index; |
| 346 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 347 | pkts_encapsulated++; |
| 348 | |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 349 | len0 = vlib_buffer_length_in_chain (vm, b[0]); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 350 | stats_n_packets += 1; |
| 351 | stats_n_bytes += len0; |
| 352 | |
| 353 | /* Batch stats increment on the same vxlan tunnel so counter is not |
| 354 | * incremented per packet. Note stats are still incremented for deleted |
| 355 | * and admin-down tunnel where packets are dropped. It is not worthwhile |
| 356 | * to check for this rare case and affect normal path performance. */ |
| 357 | if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index)) |
| 358 | { |
| 359 | stats_n_packets -= 1; |
| 360 | stats_n_bytes -= len0; |
| 361 | if (stats_n_packets) |
| 362 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 363 | VNET_INTERFACE_COUNTER_TX, |
| 364 | thread_index, |
| 365 | stats_sw_if_index, |
| 366 | stats_n_packets, |
| 367 | stats_n_bytes); |
| 368 | stats_n_packets = 1; |
| 369 | stats_n_bytes = len0; |
| 370 | stats_sw_if_index = sw_if_index0; |
| 371 | } |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 372 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 373 | { |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 374 | vxlan_gpe_encap_trace_t *tr = vlib_add_trace (vm, node, b[0], |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 375 | sizeof (*tr)); |
| 376 | tr->tunnel_index = t0 - ngm->tunnels; |
| 377 | } |
Zhiyong Yang | 359776a | 2019-05-16 04:03:18 -0400 | [diff] [blame] | 378 | b += 1; |
| 379 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 380 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 381 | n_left_to_next, bi0, next0); |
| 382 | } |
| 383 | |
| 384 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | } |
Hongjun Ni | b2cdd2f | 2016-04-06 16:20:22 -0700 | [diff] [blame] | 386 | vlib_node_increment_counter (vm, node->node_index, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 387 | VXLAN_GPE_ENCAP_ERROR_ENCAPSULATED, |
| 388 | pkts_encapsulated); |
Hongjun Ni | b2cdd2f | 2016-04-06 16:20:22 -0700 | [diff] [blame] | 389 | /* Increment any remaining batch stats */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 390 | if (stats_n_packets) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 391 | { |
| 392 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 393 | VNET_INTERFACE_COUNTER_TX, |
| 394 | thread_index, stats_sw_if_index, |
| 395 | stats_n_packets, stats_n_bytes); |
| 396 | node->runtime_data[0] = stats_sw_if_index; |
| 397 | } |
Hongjun Ni | b2cdd2f | 2016-04-06 16:20:22 -0700 | [diff] [blame] | 398 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | return from_frame->n_vectors; |
| 400 | } |
| 401 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 402 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 403 | VLIB_REGISTER_NODE (vxlan_gpe_encap_node) = { |
| 404 | .function = vxlan_gpe_encap, |
| 405 | .name = "vxlan-gpe-encap", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | .vector_size = sizeof (u32), |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 407 | .format_trace = format_vxlan_gpe_encap_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 408 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 409 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 410 | .n_errors = ARRAY_LEN(vxlan_gpe_encap_error_strings), |
| 411 | .error_strings = vxlan_gpe_encap_error_strings, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 413 | .n_next_nodes = VXLAN_GPE_ENCAP_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
| 415 | .next_nodes = { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 416 | [VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP] = "ip4-lookup", |
Hongjun Ni | beb4bf7 | 2016-11-25 00:03:46 +0800 | [diff] [blame] | 417 | [VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP] = "ip6-lookup", |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 418 | [VXLAN_GPE_ENCAP_NEXT_DROP] = "error-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | }, |
| 420 | }; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 421 | /* *INDENT-ON* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 422 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 423 | |
| 424 | /* |
| 425 | * fd.io coding-style-patch-verification: ON |
| 426 | * |
| 427 | * Local Variables: |
| 428 | * eval: (c-set-style "gnu") |
| 429 | * End: |
| 430 | */ |