FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
ioam_encap.c
Go to the documentation of this file.
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  */
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>
24 
25 /* Statistics (not really errors) */
26 #define foreach_vxlan_gpe_encap_ioam_v4_error \
27 _(ENCAPSULATED, "good packets encapsulated")
28 
30 #define _(sym,string) string,
32 #undef _
33 };
34 
35 typedef enum
36 {
37 #define _(sym,str) VXLAN_GPE_ENCAP_IOAM_V4_ERROR_##sym,
39 #undef _
42 
43 typedef enum
44 {
49 
50 
51 always_inline void
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)
57 {
59  vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node, b0, next0,
61  0 /* use_adj */ );
62  vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node, b1, next1,
64  0 /* use_adj */ );
65 }
66 
67 
68 static uword
70  vlib_node_runtime_t * node,
71  vlib_frame_t * from_frame)
72 {
73  u32 n_left_from, next_index, *from, *to_next;
75 
76  from = vlib_frame_vector_args (from_frame);
77  n_left_from = from_frame->n_vectors;
78 
79  next_index = node->cached_next_index;
80 
81  while (n_left_from > 0)
82  {
83  u32 n_left_to_next;
84 
85  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
86 
87  while (n_left_from >= 4 && n_left_to_next >= 2)
88  {
89  u32 bi0, bi1;
90  vlib_buffer_t *b0, *b1;
91  u32 next0, next1;
92 
94 
95  /* Prefetch next iteration. */
96  {
97  vlib_buffer_t *p2, *p3;
98 
99  p2 = vlib_get_buffer (vm, from[2]);
100  p3 = vlib_get_buffer (vm, from[3]);
101 
102  vlib_prefetch_buffer_header (p2, LOAD);
103  vlib_prefetch_buffer_header (p3, LOAD);
104 
105  CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
106  CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
107  }
108 
109  bi0 = from[0];
110  bi1 = from[1];
111  to_next[0] = bi0;
112  to_next[1] = bi1;
113  from += 2;
114  to_next += 2;
115  n_left_to_next -= 2;
116  n_left_from -= 2;
117 
118  b0 = vlib_get_buffer (vm, bi0);
119  b1 = vlib_get_buffer (vm, bi1);
120 
121  vxlan_gpe_encap_ioam_v4_two_inline (vm, node, ngm, b0, b1,
122  &next0, &next1);
123 
124 
125  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
126  n_left_to_next, bi0, bi1, next0,
127  next1);
128  }
129 
130  while (n_left_from > 0 && n_left_to_next > 0)
131  {
132  u32 bi0;
133  vlib_buffer_t *b0;
135 
136  bi0 = from[0];
137  to_next[0] = bi0;
138  from += 1;
139  to_next += 1;
140  n_left_from -= 1;
141  n_left_to_next -= 1;
142 
143  b0 = vlib_get_buffer (vm, bi0);
144 
146  &next0,
148  0 /* use_adj */ );
149 
150  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
151  {
152  vxlan_gpe_ioam_v4_trace_t *tr = vlib_add_trace (vm, node, b0,
153  sizeof (*tr));
154  }
155  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
156  n_left_to_next, bi0, next0);
157  }
158 
159  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
160  }
161 
162  return from_frame->n_vectors;
163 }
164 
165 
166 
167 /* *INDENT-OFF* */
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,
174 
176  .error_strings = vxlan_gpe_encap_ioam_v4_error_strings,
177 
178  .n_next_nodes = VXLAN_GPE_ENCAP_IOAM_V4_N_NEXT,
179 
180  .next_nodes = {
182  [VXLAN_GPE_ENCAP_IOAM_V4_NEXT_DROP] = "error-drop",
183  },
184 };
185 /* *INDENT-ON* */
186 
187 
188 /*
189  * fd.io coding-style-patch-verification: ON
190  *
191  * Local Variables:
192  * eval: (c-set-style "gnu")
193  * End:
194  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
VXLAN GPE definitions.
vlib_node_registration_t vxlan_gpe_encap_ioam_v4_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_encap_ioam_v4_node)
Definition: ioam_encap.c:168
vxlan_gpe_encap_ioam_v4_error_t
Definition: ioam_encap.c:35
#define always_inline
Definition: clib.h:99
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vxlan_gpe_main_t vxlan_gpe_main
Definition: vxlan_gpe.c:46
#define PREDICT_FALSE(x)
Definition: clib.h:112
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
static uword vxlan_gpe_encap_ioam_v4(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: ioam_encap.c:69
static u8 * format_vxlan_gpe_ioam_v4_trace(u8 *s, va_list *args)
static void vxlan_gpe_encap_decap_ioam_v4_one_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0, u32 *next0, u32 drop_node_val, u8 use_adj)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:397
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:323
u8 data[]
Packet data.
Definition: buffer.h:181
#define ARRAY_LEN(x)
Definition: clib.h:63
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:456
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
Struct for VXLAN GPE node state.
Definition: vxlan_gpe.h:196
#define foreach_vxlan_gpe_encap_ioam_v4_error
Definition: ioam_encap.c:26
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
vxlan_gpe_encap_ioam_v4_next_t
Definition: ioam_encap.c:43
static char * vxlan_gpe_encap_ioam_v4_error_strings[]
Definition: ioam_encap.c:29
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static void vxlan_gpe_encap_ioam_v4_two_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vxlan_gpe_main_t *ngm, vlib_buffer_t *b0, vlib_buffer_t *b1, u32 *next0, u32 *next1)
Definition: ioam_encap.c:52