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:
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.
15 #include <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/vxlan-gpe/vxlan_gpe.h>
21 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
22 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
23 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_util.h>
25 /* Statistics (not really errors) */
26 #define foreach_vxlan_gpe_encap_ioam_v4_error \
27 _(ENCAPSULATED, "good packets encapsulated")
29 static char *vxlan_gpe_encap_ioam_v4_error_strings[] = {
30 #define _(sym,string) string,
31 foreach_vxlan_gpe_encap_ioam_v4_error
37 #define _(sym,str) VXLAN_GPE_ENCAP_IOAM_V4_ERROR_##sym,
38 foreach_vxlan_gpe_encap_ioam_v4_error
40 VXLAN_GPE_ENCAP_IOAM_V4_N_ERROR,
41 } vxlan_gpe_encap_ioam_v4_error_t;
45 VXLAN_GPE_ENCAP_IOAM_V4_NEXT_IP4_LOOKUP,
46 VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP,
47 VXLAN_GPE_ENCAP_IOAM_V4_N_NEXT
48 } vxlan_gpe_encap_ioam_v4_next_t;
52 vxlan_gpe_encap_ioam_v4_two_inline (vlib_main_t * vm,
53 vlib_node_runtime_t * node,
54 vxlan_gpe_main_t * ngm,
55 vlib_buffer_t * b0, vlib_buffer_t * b1,
56 u32 * next0, u32 * next1)
58 next0[0] = next1[0] = VXLAN_GPE_ENCAP_IOAM_V4_NEXT_IP4_LOOKUP;
59 vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node, b0, next0,
60 VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP,
62 vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node, b1, next1,
63 VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP,
69 vxlan_gpe_encap_ioam_v4 (vlib_main_t * vm,
70 vlib_node_runtime_t * node,
71 vlib_frame_t * from_frame)
73 u32 n_left_from, next_index, *from, *to_next;
74 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
76 from = vlib_frame_vector_args (from_frame);
77 n_left_from = from_frame->n_vectors;
79 next_index = node->cached_next_index;
81 while (n_left_from > 0)
85 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
87 while (n_left_from >= 4 && n_left_to_next >= 2)
90 vlib_buffer_t *b0, *b1;
93 next0 = next1 = VXLAN_GPE_ENCAP_IOAM_V4_NEXT_IP4_LOOKUP;
95 /* Prefetch next iteration. */
97 vlib_buffer_t *p2, *p3;
99 p2 = vlib_get_buffer (vm, from[2]);
100 p3 = vlib_get_buffer (vm, from[3]);
102 vlib_prefetch_buffer_header (p2, LOAD);
103 vlib_prefetch_buffer_header (p3, LOAD);
105 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
106 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
118 b0 = vlib_get_buffer (vm, bi0);
119 b1 = vlib_get_buffer (vm, bi1);
121 vxlan_gpe_encap_ioam_v4_two_inline (vm, node, ngm, b0, b1,
125 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
126 n_left_to_next, bi0, bi1, next0,
130 while (n_left_from > 0 && n_left_to_next > 0)
134 u32 next0 = VXLAN_GPE_ENCAP_IOAM_V4_NEXT_IP4_LOOKUP;
143 b0 = vlib_get_buffer (vm, bi0);
145 vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node, b0,
147 VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP,
150 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
152 vxlan_gpe_ioam_v4_trace_t *tr = vlib_add_trace (vm, node, b0,
155 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
156 n_left_to_next, bi0, next0);
159 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
162 return from_frame->n_vectors;
168 VLIB_REGISTER_NODE (vxlan_gpe_encap_ioam_v4_node) = {
169 .function = vxlan_gpe_encap_ioam_v4,
170 .name = "vxlan-gpe-encap-ioam-v4",
171 .vector_size = sizeof (u32),
172 .format_trace = format_vxlan_gpe_ioam_v4_trace,
173 .type = VLIB_NODE_TYPE_INTERNAL,
175 .n_errors = ARRAY_LEN(vxlan_gpe_encap_ioam_v4_error_strings),
176 .error_strings = vxlan_gpe_encap_ioam_v4_error_strings,
178 .n_next_nodes = VXLAN_GPE_ENCAP_IOAM_V4_N_NEXT,
181 [VXLAN_GPE_ENCAP_IOAM_V4_NEXT_IP4_LOOKUP] = "ip4-lookup",
182 [VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP] = "error-drop",
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "gnu")