FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
adj_midchain_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 
16 #include <vnet/adj/adj_internal.h>
17 #include <vnet/adj/adj_midchain.h>
18 
19 /**
20  * @brief Trace data for packets traversing the midchain tx node
21  */
23 {
24  /**
25  * @brief the midchain adj we are traversing
26  */
29 
34  int interface_count)
35 {
39  vnet_main_t *vnm = vnet_get_main ();
41 
43  n_left = frame->n_vectors;
45 
47 
48  next = nexts;
49  b = bufs;
50 
51  while (n_left > 8)
52  {
53  u32 adj_index0, adj_index1, adj_index2, adj_index3;
54  const ip_adjacency_t *adj0, *adj1, *adj2, *adj3;
55  const dpo_id_t *dpo0, *dpo1, *dpo2, *dpo3;
56 
57  /* Prefetch next iteration. */
58  {
59  vlib_prefetch_buffer_header (b[4], LOAD);
60  vlib_prefetch_buffer_header (b[5], LOAD);
61  vlib_prefetch_buffer_header (b[6], LOAD);
62  vlib_prefetch_buffer_header (b[7], LOAD);
63  }
64 
65  /* Follow the DPO on which the midchain is stacked */
66  adj_index0 = vnet_buffer(b[0])->ip.adj_index[VLIB_TX];
67  adj_index1 = vnet_buffer(b[1])->ip.adj_index[VLIB_TX];
68  adj_index2 = vnet_buffer(b[2])->ip.adj_index[VLIB_TX];
69  adj_index3 = vnet_buffer(b[3])->ip.adj_index[VLIB_TX];
70 
71  adj0 = adj_get(adj_index0);
72  adj1 = adj_get(adj_index1);
73  adj2 = adj_get(adj_index2);
74  adj3 = adj_get(adj_index3);
75 
76  dpo0 = &adj0->sub_type.midchain.next_dpo;
77  dpo1 = &adj1->sub_type.midchain.next_dpo;
78  dpo2 = &adj2->sub_type.midchain.next_dpo;
79  dpo3 = &adj3->sub_type.midchain.next_dpo;
80 
81  next[0] = dpo0->dpoi_next_node;
82  next[1] = dpo1->dpoi_next_node;
83  next[2] = dpo2->dpoi_next_node;
84  next[3] = dpo3->dpoi_next_node;
85 
86  vnet_buffer(b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
87  vnet_buffer(b[1])->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
88  vnet_buffer(b[2])->ip.adj_index[VLIB_TX] = dpo2->dpoi_index;
89  vnet_buffer(b[3])->ip.adj_index[VLIB_TX] = dpo3->dpoi_index;
90 
91  if (interface_count)
92  {
96  adj0->rewrite_header.sw_if_index,
97  1,
101  thread_index,
102  adj1->rewrite_header.sw_if_index,
103  1,
107  thread_index,
108  adj2->rewrite_header.sw_if_index,
109  1,
113  thread_index,
114  adj3->rewrite_header.sw_if_index,
115  1,
117  }
118 
120  {
121  if (PREDICT_FALSE(b[0]->flags & VLIB_BUFFER_IS_TRACED))
122  {
124  b[0], sizeof (*tr));
125  tr->ai = adj_index0;
126  }
127  if (PREDICT_FALSE(b[1]->flags & VLIB_BUFFER_IS_TRACED))
128  {
130  b[1], sizeof (*tr));
131  tr->ai = adj_index1;
132  }
133  if (PREDICT_FALSE(b[2]->flags & VLIB_BUFFER_IS_TRACED))
134  {
136  b[2], sizeof (*tr));
137  tr->ai = adj_index2;
138  }
139  if (PREDICT_FALSE(b[3]->flags & VLIB_BUFFER_IS_TRACED))
140  {
142  b[3], sizeof (*tr));
143  tr->ai = adj_index3;
144  }
145  }
146  n_left -= 4;
147  b += 4;
148  next += 4;
149  }
150 
151  while (n_left)
152  {
153  const ip_adjacency_t * adj0;
154  const dpo_id_t *dpo0;
155  u32 adj_index0;
156 
157  /* Follow the DPO on which the midchain is stacked */
158  adj_index0 = vnet_buffer(b[0])->ip.adj_index[VLIB_TX];
159  adj0 = adj_get(adj_index0);
160  dpo0 = &adj0->sub_type.midchain.next_dpo;
161  next[0] = dpo0->dpoi_next_node;
162  vnet_buffer(b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
163 
164  if (interface_count)
165  {
168  thread_index,
169  adj0->rewrite_header.sw_if_index,
170  1,
172  }
173 
174  if (PREDICT_FALSE(b[0]->flags & VLIB_BUFFER_IS_TRACED))
175  {
177  b[0], sizeof (*tr));
178  tr->ai = adj_index0;
179  }
180 
181  n_left -= 1;
182  b += 1;
183  next += 1;
184  }
185 
187 
188  return frame->n_vectors;
189 }
190 
191 static u8 *
192 format_adj_midchain_tx_trace (u8 * s, va_list * args)
193 {
194  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
195  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
196  adj_midchain_tx_trace_t *tr = va_arg (*args, adj_midchain_tx_trace_t*);
197 
198  s = format(s, "adj-midchain:[%d]:%U", tr->ai,
199  format_ip_adjacency, tr->ai,
201 
202  return (s);
203 }
204 
205 static uword
209 {
210  return (adj_midchain_tx_inline(vm, node, frame, 1));
211 }
212 
214  .function = adj_midchain_tx,
215  .name = "adj-midchain-tx",
216  .vector_size = sizeof (u32),
217 
218  .format_trace = format_adj_midchain_tx_trace,
219 
220  .n_next_nodes = 1,
221  .next_nodes = {
222  [0] = "error-drop",
223  },
224 };
225 
226 static uword
230 {
231  return (adj_midchain_tx_inline(vm, node, frame, 0));
232 }
233 
235  .function = adj_midchain_tx_no_count,
236  .name = "adj-midchain-tx-no-count",
237  .vector_size = sizeof (u32),
238 
239  .format_trace = format_adj_midchain_tx_trace,
240  .sibling_of = "adj-midchain-tx",
241 };
adj_midchain_tx_inline
static uword adj_midchain_tx_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int interface_count)
Definition: adj_midchain_node.c:31
adj_midchain_tx_node
vlib_node_registration_t adj_midchain_tx_node
(constructor) VLIB_REGISTER_NODE (adj_midchain_tx_node)
Definition: adj_midchain_node.c:213
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
im
vnet_interface_main_t * im
Definition: interface_output.c:395
adj_midchain.h
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
bufs
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:717
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
VNET_INTERFACE_COUNTER_TX
@ VNET_INTERFACE_COUNTER_TX
Definition: interface.h:918
format_ip_adjacency
format_function_t format_ip_adjacency
Definition: format.h:58
vlib_get_buffers
vlib_get_buffers(vm, from, b, n_left_from)
next
u16 * next
Definition: nat44_ei_out2in.c:718
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
FORMAT_IP_ADJACENCY_NONE
@ FORMAT_IP_ADJACENCY_NONE
Definition: format.h:53
vnet_interface_main_t
Definition: interface.h:989
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_buffer_enqueue_to_next
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
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
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
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
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
adj_midchain_tx_no_count_node
vlib_node_registration_t adj_midchain_tx_no_count_node
(constructor) VLIB_REGISTER_NODE (adj_midchain_tx_no_count_node)
Definition: adj_midchain_node.c:234
uword
u64 uword
Definition: types.h:112
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
adj_midchain_tx_trace_t_::ai
adj_index_t ai
the midchain adj we are traversing
Definition: adj_midchain_node.c:27
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
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:1023
vnet_main_t
Definition: vnet.h:76
ip_adjacency_t_::sub_type
union ip_adjacency_t_::@144 sub_type
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
adj_midchain_tx_trace_t_
Trace data for packets traversing the midchain tx node.
Definition: adj_midchain_node.c:22
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
adj_internal.h
n_left
u32 n_left
Definition: interface_output.c:1078
adj_midchain_tx_trace_t
struct adj_midchain_tx_trace_t_ adj_midchain_tx_trace_t
Trace data for packets traversing the midchain tx node.
adj_index_t
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
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
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
nexts
u16 nexts[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:718
adj_midchain_tx
static uword adj_midchain_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: adj_midchain_node.c:206
vlib_node_runtime_t
Definition: node.h:454
format_adj_midchain_tx_trace
static u8 * format_adj_midchain_tx_trace(u8 *s, va_list *args)
Definition: adj_midchain_node.c:192
from
from
Definition: nat44_ei_hairpinning.c:415
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
adj_get
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:470
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)
adj_midchain_tx_no_count
static uword adj_midchain_tx_no_count(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: adj_midchain_node.c:227
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
ip_adjacency_t_::midchain
struct ip_adjacency_t_::@144::@146 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105