FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
l2_uu_fwd.c
Go to the documentation of this file.
1 /*
2  * l2_uu_fwd.c : Foward unknown unicast packets to BD's configured interface
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/l2/l2_bd.h>
19 #include <vnet/l2/l2_input.h>
20 
21 #define foreach_l2_uu_fwd_error \
22 _(L2_UU_FWD, "L2 UU fwd")
23 
24 typedef enum
25 {
26 #define _(sym,str) L2_UU_FWD_ERROR_##sym,
28 #undef _
31 
32 static char *l2_uu_fwd_error_strings[] = {
33 #define _(sym,string) string,
35 #undef _
36 };
37 
38 typedef enum
39 {
44 
45 typedef struct
46 {
49 
50 /* packet trace format function */
51 static u8 *
52 format_l2_uu_fwd_trace (u8 * s, va_list * args)
53 {
54  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
55  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
56  l2_uu_fwd_trace_t *t = va_arg (*args, l2_uu_fwd_trace_t *);
57 
58  s = format (s, "l2-uu-fwd: sw_if_index %d", t->sw_if_index);
59  return s;
60 }
61 
62 static uword
64  vlib_node_runtime_t * node, vlib_frame_t * frame)
65 {
66  u32 n_left_from, *from, *to_next;
67  l2_uu_fwd_next_t next_index;
68 
69  from = vlib_frame_vector_args (frame);
70  n_left_from = frame->n_vectors;
71  next_index = node->cached_next_index;
72 
73  while (n_left_from > 0)
74  {
75  u32 n_left_to_next;
76 
77  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
78 
79  while (n_left_from >= 8 && n_left_to_next >= 4)
80  {
81  const l2_bridge_domain_t *bdc0, *bdc1, *bdc2, *bdc3;
82  l2_uu_fwd_next_t next0, next1, next2, next3;
83  vlib_buffer_t *b0, *b1, *b2, *b3;
84  u32 bi0, bi1, bi2, bi3;
85 
86  {
87  vlib_buffer_t *b4, *b5, *b6, *b7;
88 
89  b4 = vlib_get_buffer (vm, from[4]);
90  b5 = vlib_get_buffer (vm, from[5]);
91  b6 = vlib_get_buffer (vm, from[6]);
92  b7 = vlib_get_buffer (vm, from[7]);
93 
94  vlib_prefetch_buffer_header (b4, STORE);
95  vlib_prefetch_buffer_header (b5, STORE);
96  vlib_prefetch_buffer_header (b6, STORE);
97  vlib_prefetch_buffer_header (b7, STORE);
98  }
99  bi0 = to_next[0] = from[0];
100  bi1 = to_next[1] = from[1];
101  bi2 = to_next[2] = from[2];
102  bi3 = to_next[3] = from[3];
103 
104  from += 4;
105  to_next += 4;
106  n_left_from -= 4;
107  n_left_to_next -= 4;
108 
109  next3 = next2 = next1 = next0 = L2_UU_FWD_NEXT_L2_OUTPUT;
110 
111  b0 = vlib_get_buffer (vm, bi0);
112  b1 = vlib_get_buffer (vm, bi1);
113  b2 = vlib_get_buffer (vm, bi2);
114  b3 = vlib_get_buffer (vm, bi3);
115 
117  vnet_buffer (b0)->l2.bd_index);
119  vnet_buffer (b1)->l2.bd_index);
121  vnet_buffer (b2)->l2.bd_index);
123  vnet_buffer (b3)->l2.bd_index);
124 
125  ASSERT (~0 != bdc0->uu_fwd_sw_if_index);
126 
127  vnet_buffer (b0)->sw_if_index[VLIB_TX] = bdc0->uu_fwd_sw_if_index;
128  vnet_buffer (b1)->sw_if_index[VLIB_TX] = bdc1->uu_fwd_sw_if_index;
129  vnet_buffer (b2)->sw_if_index[VLIB_TX] = bdc2->uu_fwd_sw_if_index;
130  vnet_buffer (b3)->sw_if_index[VLIB_TX] = bdc3->uu_fwd_sw_if_index;
131 
132  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
133  (b0->flags & VLIB_BUFFER_IS_TRACED)))
134  {
136 
137  t = vlib_add_trace (vm, node, b0, sizeof (*t));
138  t->sw_if_index = bdc0->uu_fwd_sw_if_index;
139  }
140  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
141  (b1->flags & VLIB_BUFFER_IS_TRACED)))
142  {
144 
145  t = vlib_add_trace (vm, node, b1, sizeof (*t));
146  t->sw_if_index = bdc1->uu_fwd_sw_if_index;
147  }
148  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
149  (b1->flags & VLIB_BUFFER_IS_TRACED)))
150  {
152 
153  t = vlib_add_trace (vm, node, b2, sizeof (*t));
154  t->sw_if_index = bdc2->uu_fwd_sw_if_index;
155  }
156  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
157  (b1->flags & VLIB_BUFFER_IS_TRACED)))
158  {
160 
161  t = vlib_add_trace (vm, node, b3, sizeof (*t));
162  t->sw_if_index = bdc3->uu_fwd_sw_if_index;
163  }
164  vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
165  to_next, n_left_to_next,
166  bi0, bi1, bi2, bi3,
167  next0, next1, next2, next3);
168  }
169 
170  while (n_left_from > 0 && n_left_to_next > 0)
171  {
172  const l2_bridge_domain_t *bdc0;
173  l2_uu_fwd_next_t next0;
174  vlib_buffer_t *b0;
175  u32 bi0;
176 
177  bi0 = from[0];
178  to_next[0] = bi0;
179  from += 1;
180  to_next += 1;
181  n_left_from -= 1;
182  n_left_to_next -= 1;
183  next0 = L2_UU_FWD_NEXT_L2_OUTPUT;
184  b0 = vlib_get_buffer (vm, bi0);
185 
187  vnet_buffer (b0)->l2.bd_index);
188  ASSERT (~0 != bdc0->uu_fwd_sw_if_index);
189 
190  vnet_buffer (b0)->sw_if_index[VLIB_TX] = bdc0->uu_fwd_sw_if_index;
191 
192  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
193  (b0->flags & VLIB_BUFFER_IS_TRACED)))
194  {
196 
197  t = vlib_add_trace (vm, node, b0, sizeof (*t));
198  t->sw_if_index = bdc0->uu_fwd_sw_if_index;
199  }
200  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
201  to_next, n_left_to_next,
202  bi0, next0);
203  }
204 
205  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
206  }
207 
209  L2_UU_FWD_ERROR_L2_UU_FWD, frame->n_vectors);
210 
211  return frame->n_vectors;
212 }
213 
214 /* *INDENT-OFF* */
216  .function = l2_uu_fwd_node_fn,
217  .name = "l2-uu-fwd",
218  .vector_size = sizeof (u32),
219  .format_trace = format_l2_uu_fwd_trace,
220  .type = VLIB_NODE_TYPE_INTERNAL,
221 
222  .n_errors = ARRAY_LEN(l2_uu_fwd_error_strings),
223  .error_strings = l2_uu_fwd_error_strings,
224 
225  .n_next_nodes = L2_UU_FWD_N_NEXT,
226 
227  .next_nodes = {
228  [L2_UU_FWD_NEXT_DROP] = "error-drop",
229  [L2_UU_FWD_NEXT_L2_OUTPUT] = "l2-output",
230  },
231 };
232 
234 /* *INDENT-ON* */
235 
236 /*
237  * fd.io coding-style-patch-verification: ON
238  *
239  * Local Variables:
240  * eval: (c-set-style "gnu")
241  * End:
242  */
l2_uu_fwd_next_t
Definition: l2_uu_fwd.c:38
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:80
#define CLIB_UNUSED(x)
Definition: clib.h:82
#define foreach_l2_uu_fwd_error
Definition: l2_uu_fwd.c:21
#define vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3)
Finish enqueueing four buffers forward in the graph.
Definition: buffer_node.h:138
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
l2_uu_fwd_error_t
Definition: l2_uu_fwd.c:24
unsigned char u8
Definition: types.h:56
static uword l2_uu_fwd_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: l2_uu_fwd.c:63
static char * l2_uu_fwd_error_strings[]
Definition: l2_uu_fwd.c:32
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:188
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned int u32
Definition: types.h:88
static vlib_node_registration_t l2_uu_fwd_node
(constructor) VLIB_REGISTER_NODE (l2_uu_fwd_node)
Definition: l2_uu_fwd.c:215
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
Definition: node.h:223
#define PREDICT_FALSE(x)
Definition: clib.h:111
u32 node_index
Node index.
Definition: node.h:518
#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 void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:420
vlib_main_t * vm
Definition: buffer.c:301
#define ARRAY_LEN(x)
Definition: clib.h:62
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:452
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:537
#define ASSERT(truth)
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:57
Definition: defs.h:47
l2input_main_t l2input_main
Definition: l2_input.c:122
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
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:64
#define vnet_buffer(b)
Definition: buffer.h:368
u16 flags
Copy of main node flags.
Definition: node.h:531
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:326
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:117
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
static u8 * format_l2_uu_fwd_trace(u8 *s, va_list *args)
Definition: l2_uu_fwd.c:52