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