FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
p2p_ethernet_input.c
Go to the documentation of this file.
1 /*
2  * node.c: p2p ethernet vpp node
3  *
4  * Copyright (c) 2016 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 <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vppinfra/error.h>
21 
23 
24 #include <vppinfra/error.h>
25 #include <vppinfra/elog.h>
26 
28 
29 /* packet trace format function */
30 static u8 *
31 format_p2p_ethernet_trace (u8 * s, va_list * args)
32 {
33  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
34  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
35  p2p_ethernet_trace_t *t = va_arg (*args, p2p_ethernet_trace_t *);
36 
37  vnet_main_t *vnm = &vnet_main;
38  s = format (s, "P2P ethernet: %U -> %U",
41 
42  return s;
43 }
44 
45 #define foreach_p2p_ethernet_error \
46 _(HITS, "P2P ethernet incoming packets processed")
47 
48 typedef enum
49 {
50 #define _(sym,str) P2PE_ERROR_##sym,
52 #undef _
55 
56 static char *p2p_ethernet_error_strings[] = {
57 #define _(sym,string) string,
59 #undef _
60 };
61 
65 {
67  u32 n_trace = vlib_get_trace_count (vm, node);
68  u32 n_left_from, *from, *to_next;
70  u32 n_p2p_ethernet_packets = 0;
73 
75  n_left_from = frame->n_vectors;
76  next_index = node->cached_next_index;
77 
78  while (n_left_from > 0)
79  {
80  u32 n_left_to_next;
81 
82  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
83 
84  while (n_left_from >= 4 && n_left_to_next >= 2)
85  {
86  u32 bi0, bi1;
87  vlib_buffer_t *b0, *b1;
88  u32 next0 = 0, next1 = 0;
89  u32 sw_if_index0, sw_if_index1;
90  ethernet_header_t *en0, *en1;
91  u32 rx0, rx1;
92 
93  bi0 = from[0];
94  bi1 = from[1];
95  to_next[0] = bi0;
96  to_next[1] = bi1;
97  from += 2;
98  to_next += 2;
99  n_left_to_next -= 2;
100  n_left_from -= 2;
101 
102  b0 = vlib_get_buffer (vm, bi0);
103  b1 = vlib_get_buffer (vm, bi1);
104 
105  en0 = vlib_buffer_get_current (b0);
106  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
107  en1 = vlib_buffer_get_current (b1);
108  sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
109 
110  vnet_feature_next (&next0, b0);
111  vnet_feature_next (&next1, b1);
112 
113  rx0 = p2p_ethernet_lookup (sw_if_index0, en0->src_address);
114  rx1 = p2p_ethernet_lookup (sw_if_index1, en1->src_address);
115 
116  if (rx0 != ~0)
117  {
118  /* Send pkt to p2p_ethernet RX interface */
119  vnet_buffer (b0)->sw_if_index[VLIB_RX] = rx0;
120  n_p2p_ethernet_packets += 1;
121 
122  if (PREDICT_FALSE
123  (n_trace > 0
125  1 /* follow_chain */ )))
126  {
128  vlib_set_trace_count (vm, node, --n_trace);
129  t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
130  t0->sw_if_index = sw_if_index0;
131  t0->p2pe_sw_if_index = rx0;
132  }
133 
136  (vm, b0));
137  }
138  if (rx1 != ~0)
139  {
140  /* Send pkt to p2p_ethernet RX interface */
141  vnet_buffer (b1)->sw_if_index[VLIB_RX] = rx1;
142  n_p2p_ethernet_packets += 1;
143 
144  if (PREDICT_FALSE
145  (n_trace > 0
147  1 /* follow_chain */ )))
148  {
150  vlib_set_trace_count (vm, node, --n_trace);
151  t1 = vlib_add_trace (vm, node, b1, sizeof (*t1));
152  t1->sw_if_index = sw_if_index1;
153  t1->p2pe_sw_if_index = rx1;
154  }
155 
158  (vm, b1));
159  }
160 
161  /* verify speculative enqueue, maybe switch current next frame */
163  to_next, n_left_to_next,
164  bi0, next0);
166  to_next, n_left_to_next,
167  bi1, next1);
168  }
169 
170  while (n_left_from > 0 && n_left_to_next > 0)
171  {
172  u32 bi0;
173  vlib_buffer_t *b0;
174  u32 next0 = 0;
175  u32 sw_if_index0;
176  ethernet_header_t *en0;
177  u32 rx0;
178 
179  bi0 = from[0];
180  to_next[0] = bi0;
181  from += 1;
182  to_next += 1;
183  n_left_from -= 1;
184  n_left_to_next -= 1;
185 
186  b0 = vlib_get_buffer (vm, bi0);
187 
188  en0 = vlib_buffer_get_current (b0);
189  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
190 
191  vnet_feature_next (&next0, b0);
192 
193  rx0 = p2p_ethernet_lookup (sw_if_index0, en0->src_address);
194  if (rx0 != ~0)
195  {
196  /* Send pkt to p2p_ethernet RX interface */
197  vnet_buffer (b0)->sw_if_index[VLIB_RX] = rx0;
198  n_p2p_ethernet_packets += 1;
199 
200  if (PREDICT_FALSE
201  (n_trace > 0
203  1 /* follow_chain */ )))
204  {
206  vlib_set_trace_count (vm, node, --n_trace);
207  t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
208  t0->sw_if_index = sw_if_index0;
209  t0->p2pe_sw_if_index = rx0;
210  }
211 
214  (vm, b0));
215  }
216  else
217  {
218  if (PREDICT_FALSE (n_trace > 0))
219  {
220  node->flags |= VLIB_NODE_FLAG_TRACE;
221  }
222  }
223 
224  /* verify speculative enqueue, maybe switch current next frame */
226  to_next, n_left_to_next,
227  bi0, next0);
228  }
229  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
230  }
231 
233  P2PE_ERROR_HITS, n_p2p_ethernet_packets);
234 
235  return frame->n_vectors;
236 }
237 
238 /* *INDENT-OFF* */
240  .name = "p2p-ethernet-input",
241  .vector_size = sizeof (u32),
242  .format_trace = format_p2p_ethernet_trace,
245 
247  .error_strings = p2p_ethernet_error_strings,
248 
249  .n_next_nodes = 1,
250 
251  /* edit / add dispositions here */
252  .next_nodes = {
253  [0] = "error-drop",
254  },
255 };
256 /* *INDENT-ON* */
257 
258 /*
259  * fd.io coding-style-patch-verification: ON
260  *
261  * Local Variables:
262  * eval: (c-set-style "gnu")
263  * End:
264  */
vlib.h
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
elog.h
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
ethernet_header_t::src_address
u8 src_address[6]
Definition: packet.h:56
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
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
vlib_get_trace_count
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:212
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
format_p2p_ethernet_trace
static u8 * format_p2p_ethernet_trace(u8 *s, va_list *args)
Definition: p2p_ethernet_input.c:31
error.h
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vnet_feature_next
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
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
p2p_ethernet_input_node
vlib_node_registration_t p2p_ethernet_input_node
(constructor) VLIB_REGISTER_NODE (p2p_ethernet_input_node)
Definition: p2p_ethernet_input.c:239
ethernet_header_t
Definition: packet.h:52
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:215
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
P2PE_N_ERROR
@ P2PE_N_ERROR
Definition: p2p_ethernet_input.c:53
VLIB_NODE_FLAG_TRACE_SUPPORTED
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
Definition: node.h:295
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
p2p_ethernet_trace_t::p2pe_sw_if_index
u32 p2pe_sw_if_index
Definition: p2p_ethernet.h:45
vlib_set_trace_count
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
Definition: trace_funcs.h:226
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vnet_interface_main_t::combined_sw_if_counters
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:1024
p2p_ethernet.h
vnet_main_t
Definition: vnet.h:76
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
p2p_ethernet_trace_t
Definition: p2p_ethernet.h:42
p2p_ethernet_trace_t::sw_if_index
u32 sw_if_index
Definition: p2p_ethernet.h:44
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
format
description fragment has unexpected format
Definition: map.api:433
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
p2p_ethernet_lookup
u32 p2p_ethernet_lookup(u32 parent_if_index, u8 *client_mac)
Definition: p2p_ethernet.c:35
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
p2p_ethernet_error_strings
static char * p2p_ethernet_error_strings[]
Definition: p2p_ethernet_input.c:56
foreach_p2p_ethernet_error
#define foreach_p2p_ethernet_error
Definition: p2p_ethernet_input.c:45
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
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_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vnet.h
vlib_node_runtime_t
Definition: node.h:454
vlib_trace_buffer
static __clib_warn_unused_result int vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:153
from
from
Definition: nat44_ei_hairpinning.c:415
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
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
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
p2p_ethernet_error_t
p2p_ethernet_error_t
Definition: p2p_ethernet_input.c:48
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105