FD.io VPP  v21.06-3-gbb25fbf28
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 
65 {
66  u32 n_left_from, *from, *to_next;
68 
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  }
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  }
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 
208  vlib_node_increment_counter (vm, node->node_index,
209  L2_UU_FWD_ERROR_L2_UU_FWD, frame->n_vectors);
210 
211  return frame->n_vectors;
212 }
213 
214 /* *INDENT-OFF* */
216  .name = "l2-uu-fwd",
217  .vector_size = sizeof (u32),
218  .format_trace = format_l2_uu_fwd_trace,
220 
221  .n_errors = ARRAY_LEN(l2_uu_fwd_error_strings),
222  .error_strings = l2_uu_fwd_error_strings,
223 
224  .n_next_nodes = L2_UU_FWD_N_NEXT,
225 
226  .next_nodes = {
227  [L2_UU_FWD_NEXT_DROP] = "error-drop",
228  [L2_UU_FWD_NEXT_L2_OUTPUT] = "l2-output",
229  },
230 };
231 /* *INDENT-ON* */
232 
233 /*
234  * fd.io coding-style-patch-verification: ON
235  *
236  * Local Variables:
237  * eval: (c-set-style "gnu")
238  * End:
239  */
L2_UU_FWD_N_NEXT
@ L2_UU_FWD_N_NEXT
Definition: l2_uu_fwd.c:42
l2_bridge_domain_t
Definition: l2_bd.h:63
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
l2input_main
l2input_main_t l2input_main
Definition: l2_input_node.c:78
l2_uu_fwd_error_strings
static char * l2_uu_fwd_error_strings[]
Definition: l2_uu_fwd.c:32
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
l2_uu_fwd_node
vlib_node_registration_t l2_uu_fwd_node
(constructor) VLIB_REGISTER_NODE (l2_uu_fwd_node)
Definition: l2_uu_fwd.c:215
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vlib_validate_buffer_enqueue_x4
#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:140
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_frame_t
Definition: node.h:372
l2_uu_fwd_error_t
l2_uu_fwd_error_t
Definition: l2_uu_fwd.c:24
L2_UU_FWD_N_ERROR
@ L2_UU_FWD_N_ERROR
Definition: l2_uu_fwd.c:29
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
l2_bridge_domain_t::uu_fwd_sw_if_index
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:80
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
l2_uu_fwd_next_t
l2_uu_fwd_next_t
Definition: l2_uu_fwd.c:38
l2_uu_fwd_trace_t
Definition: l2_uu_fwd.c:45
foreach_l2_uu_fwd_error
#define foreach_l2_uu_fwd_error
Definition: l2_uu_fwd.c:21
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
l2_input.h
vlib_validate_buffer_enqueue_x1
#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:224
l2_uu_fwd_trace_t::sw_if_index
u32 sw_if_index
Definition: l2_uu_fwd.c:47
L2_UU_FWD_NEXT_DROP
@ L2_UU_FWD_NEXT_DROP
Definition: l2_uu_fwd.c:40
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
format_l2_uu_fwd_trace
static u8 * format_l2_uu_fwd_trace(u8 *s, va_list *args)
Definition: l2_uu_fwd.c:52
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
L2_UU_FWD_NEXT_L2_OUTPUT
@ L2_UU_FWD_NEXT_L2_OUTPUT
Definition: l2_uu_fwd.c:41
vlib_get_next_frame
#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:395
l2_bd.h
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
l2input_main_t::bd_configs
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:93
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169