FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pw_cw.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/dpo/pw_cw.h>
17 #include <vnet/fib/fib_node.h>
18 
19 #ifndef CLIB_MARCH_VARIANT
20 
21 /*
22  * pool of all MPLS Label DPOs
23  */
25 
26 static pw_cw_dpo_t *
28 {
29  pw_cw_dpo_t *pwcw;
30 
32 
33  return (pwcw);
34 }
35 
36 static index_t
38 {
39  return (pwcw - pw_cw_dpo_pool);
40 }
41 
42 void
43 pw_cw_dpo_create (const dpo_id_t *parent,
44  dpo_id_t *dpo)
45 {
46  pw_cw_dpo_t *pwcw;
47 
48  pwcw = pw_cw_dpo_alloc();
49 
50  /*
51  * stack this disposition object on the parent given
52  */
54  parent->dpoi_proto,
55  &pwcw->pwcw_parent,
56  parent);
57 
58  /*
59  * set up the return DPO to refer to this object
60  */
61  dpo_set(dpo,
62  DPO_PW_CW,
63  parent->dpoi_proto,
64  pw_cw_dpo_get_index(pwcw));
65 }
66 
67 u8*
68 format_pw_cw_dpo (u8 *s, va_list *args)
69 {
70  index_t pwcwi = va_arg (*args, index_t);
71  u32 indent = va_arg (*args, u32);
72  pw_cw_dpo_t *pwcw;
73 
75  {
76  /*
77  * the packet trace can be printed after the DPO has been deleted
78  */
79  return (format(s, "pw-cw[???,%d]:", pwcwi));
80  }
81 
82  pwcw = pw_cw_dpo_get(pwcwi);
83  s = format(s, "pw-cw[%d]:", pwcwi);
84 
85  s = format(s, "\n%U", format_white_space, indent);
86  s = format(s, "%U", format_dpo_id, &pwcw->pwcw_parent, indent+2);
87 
88  return (s);
89 }
90 
91 static void
93 {
94  pw_cw_dpo_t *pwcw;
95 
96  pwcw = pw_cw_dpo_get(dpo->dpoi_index);
97 
98  pwcw->pwcw_locks++;
99 }
100 
101 static void
103 {
104  pw_cw_dpo_t *pwcw;
105 
106  pwcw = pw_cw_dpo_get(dpo->dpoi_index);
107 
108  pwcw->pwcw_locks--;
109 
110  if (0 == pwcw->pwcw_locks)
111  {
112  dpo_reset(&pwcw->pwcw_parent);
113  pool_put(pw_cw_dpo_pool, pwcw);
114  }
115 }
116 #endif /* CLIB_MARCH_VARIANT */
117 
118 /**
119  * @brief A struct to hold tracing information for the MPLS label imposition
120  * node.
121  */
122 typedef struct pw_cw_trace_t_
123 {
124  /**
125  * The CW popped
126  */
128 } pw_cw_trace_t;
129 
134 {
135  u32 n_left_from, next_index, * from, * to_next;
136 
138  n_left_from = from_frame->n_vectors;
139  next_index = node->cached_next_index;
140 
141  while (n_left_from > 0)
142  {
143  u32 n_left_to_next;
144 
145  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
146 
147  while (n_left_from >= 4 && n_left_to_next >= 2)
148  {
149  pw_cw_dpo_t *pwcw0, *pwcw1;
150  u32 bi0, pwcwi0, bi1, pwcwi1;
151  vlib_buffer_t * b0, *b1;
152  u32 next0, next1;
153 
154  bi0 = to_next[0] = from[0];
155  bi1 = to_next[1] = from[1];
156 
157  /* Prefetch next iteration. */
158  {
159  vlib_buffer_t * p2, * p3;
160 
161  p2 = vlib_get_buffer(vm, from[2]);
162  p3 = vlib_get_buffer(vm, from[3]);
163 
164  vlib_prefetch_buffer_header(p2, STORE);
165  vlib_prefetch_buffer_header(p3, STORE);
166 
167  CLIB_PREFETCH(p2->data, sizeof(pw_cw_t), STORE);
168  CLIB_PREFETCH(p3->data, sizeof(pw_cw_t), STORE);
169  }
170 
171  from += 2;
172  to_next += 2;
173  n_left_from -= 2;
174  n_left_to_next -= 2;
175 
176  b0 = vlib_get_buffer(vm, bi0);
177  b1 = vlib_get_buffer(vm, bi1);
178 
179  /* get the next parent DPO for the next pop */
180  pwcwi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
181  pwcwi1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX];
182  pwcw0 = pw_cw_dpo_get(pwcwi0);
183  pwcw1 = pw_cw_dpo_get(pwcwi1);
184 
185  next0 = pwcw0->pwcw_parent.dpoi_next_node;
186  next1 = pwcw1->pwcw_parent.dpoi_next_node;
187 
188  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = pwcw0->pwcw_parent.dpoi_index;
189  vnet_buffer(b1)->ip.adj_index[VLIB_TX] = pwcw1->pwcw_parent.dpoi_index;
190 
191  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
192  {
193  pw_cw_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr));
194 
195  tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b0));
196  }
197  if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
198  {
199  pw_cw_trace_t *tr = vlib_add_trace(vm, node, b1, sizeof(*tr));
200 
201  tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b1));
202  }
203 
204  /* pop the PW CW */
205  vlib_buffer_advance (b0, sizeof(pw_cw_t));
206  vlib_buffer_advance (b1, sizeof(pw_cw_t));
207 
209  n_left_to_next,
210  bi0, bi1, next0, next1);
211  }
212 
213  while (n_left_from > 0 && n_left_to_next > 0)
214  {
215  pw_cw_dpo_t *pwcw0;
216  vlib_buffer_t * b0;
217  u32 bi0, pwcwi0;
218  u32 next0;
219 
220  bi0 = from[0];
221  to_next[0] = bi0;
222  from += 1;
223  to_next += 1;
224  n_left_from -= 1;
225  n_left_to_next -= 1;
226 
227  b0 = vlib_get_buffer(vm, bi0);
228 
229  pwcwi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
230  pwcw0 = pw_cw_dpo_get(pwcwi0);
231  next0 = pwcw0->pwcw_parent.dpoi_next_node;
232  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = pwcw0->pwcw_parent.dpoi_index;
233 
234  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
235  {
236  pw_cw_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr));
237 
238  tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b0));
239  }
240 
241  vlib_buffer_advance (b0, sizeof(pw_cw_t));
242 
244  n_left_to_next, bi0, next0);
245  }
246  vlib_put_next_frame(vm, node, next_index, n_left_to_next);
247  }
248  return from_frame->n_vectors;
249 }
250 
251 static u8 *
252 format_pw_cw_trace (u8 * s, va_list * args)
253 {
254  CLIB_UNUSED(vlib_main_t * vm) = va_arg(*args, vlib_main_t *);
255  CLIB_UNUSED(vlib_node_t * node) = va_arg(*args, vlib_node_t *);
257 
258  t = va_arg(*args, pw_cw_trace_t *);
259 
260  s = format(s, "cw:0x%x", t->cw);
261 
262  return (s);
263 }
264 
268 {
269  return (pw_cw_pop_inline(vm, node, frame));
270 }
271 
273  .name = "pw-cw-pop",
274  .vector_size = sizeof(u32),
275  .format_trace = format_pw_cw_trace,
276 };
277 
278 #ifndef CLIB_MARCH_VARIANT
279 static void
281 {
282  fib_show_memory_usage("PW-CW",
285  sizeof(pw_cw_dpo_t));
286 }
287 
288 const static dpo_vft_t pwcw_vft = {
290  .dv_unlock = pw_cw_dpo_unlock,
291  .dv_format = format_pw_cw_dpo,
292  .dv_mem_show = pw_cw_dpo_mem_show,
293 };
294 
295 const static char* const pw_cw_proto_nodes[] =
296 {
297  "pw-cw-pop",
298  NULL,
299 };
300 
301 const static char* const * const pw_cw_nodes[DPO_PROTO_NUM] =
302 {
307 };
308 
309 void
311 {
313 }
314 
315 #endif /* CLIB_MARCH_VARIANT */
pw_cw_dpo_pool
pw_cw_dpo_t * pw_cw_dpo_pool
Definition: pw_cw.c:24
pwcw_vft
const static dpo_vft_t pwcw_vft
Definition: pw_cw.c:288
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
pw_cw_proto_nodes
const static char *const pw_cw_proto_nodes[]
Definition: pw_cw.c:295
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
pool_get_aligned_zero
#define pool_get_aligned_zero(P, E, A)
Allocate an object E from a pool P with alignment A and zero it.
Definition: pool.h:252
pw_cw_t
u32 pw_cw_t
A Psuedo Wire Control Word is 4 bytes.
Definition: pw_cw.h:26
pw_cw_dpo_mem_show
static void pw_cw_dpo_mem_show(void)
Definition: pw_cw.c:280
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
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
pw_cw_dpo_t::pwcw_parent
dpo_id_t pwcw_parent
Next DPO in the graph.
Definition: pw_cw.h:36
pw_cw_trace_t
struct pw_cw_trace_t_ pw_cw_trace_t
A struct to hold tracing information for the MPLS label imposition node.
pw_cw_dpo_get_index
static index_t pw_cw_dpo_get_index(pw_cw_dpo_t *pwcw)
Definition: pw_cw.c:37
pw_cw_trace_t_::cw
u32 cw
The CW popped.
Definition: pw_cw.c:127
DPO_PW_CW
@ DPO_PW_CW
Definition: dpo.h:129
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
pw_cw_nodes
const static char *const *const pw_cw_nodes[DPO_PROTO_NUM]
Definition: pw_cw.c:301
fib_node.h
vlib_frame_t
Definition: node.h:372
pw_cw_dpo_lock
static void pw_cw_dpo_lock(dpo_id_t *dpo)
Definition: pw_cw.c:92
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
pw_cw_dpo_t
A representation of a Psuedo Wire Control Word pop DPO.
Definition: pw_cw.h:31
pw_cw.h
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
dpo_stack
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child-parent relationship.
Definition: dpo.c:535
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
pw_cw_node
vlib_node_registration_t pw_cw_node
(constructor) VLIB_REGISTER_NODE (pw_cw_node)
Definition: pw_cw.c:272
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
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
fib_show_memory_usage
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
Definition: fib_node.c:220
uword
u64 uword
Definition: types.h:112
pw_cw_dpo_unlock
static void pw_cw_dpo_unlock(dpo_id_t *dpo)
Definition: pw_cw.c:102
format_pw_cw_trace
static u8 * format_pw_cw_trace(u8 *s, va_list *args)
Definition: pw_cw.c:252
pw_cw_dpo_create
void pw_cw_dpo_create(const dpo_id_t *parent, dpo_id_t *dpo)
Create an PW CW pop.
Definition: pw_cw.c:43
pw_cw_dpo_t::pwcw_locks
u16 pwcw_locks
Number of locks/users of the label.
Definition: pw_cw.h:41
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
pw_cw_dpo_alloc
static pw_cw_dpo_t * pw_cw_dpo_alloc(void)
Definition: pw_cw.c:27
dpo_id_t_::dpoi_proto
dpo_proto_t dpoi_proto
the data-path protocol of the type.
Definition: dpo.h:182
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
pool_len
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:139
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
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
format
description fragment has unexpected format
Definition: map.api:433
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
DPO_PROTO_MPLS
@ DPO_PROTO_MPLS
Definition: dpo.h:66
u32
unsigned int u32
Definition: types.h:88
pw_cw_dpo_module_init
void pw_cw_dpo_module_init(void)
Definition: pw_cw.c:310
pw_cw_dpo_get
static pw_cw_dpo_t * pw_cw_dpo_get(index_t index)
Definition: pw_cw.h:73
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
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
pw_cw_pop_inline
static uword pw_cw_pop_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: pw_cw.c:131
u8
unsigned char u8
Definition: types.h:56
format_pw_cw_dpo
u8 * format_pw_cw_dpo(u8 *s, va_list *args)
Definition: pw_cw.c:68
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
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
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
vlib_validate_buffer_enqueue_x2
#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
DPO_PROTO_ETHERNET
@ DPO_PROTO_ETHERNET
Definition: dpo.h:67
dpo_set
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:188
vlib_node_runtime_t
Definition: node.h:454
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
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
pw_cw_trace_t_
A struct to hold tracing information for the MPLS label imposition node.
Definition: pw_cw.c:122
dpo_reset
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:234
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
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
dpo_register
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:329
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169