blob: 13ae37a74a875e3c5a52a3b1618f1376c627cc84 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 * @brief
17 * A Data-Path Object is an object that represents actions that are
18 * applied to packets are they are switched through VPP.
Dave Barachf8d50682019-05-14 18:01:44 -040019 *
Neale Ranns0bfe5d82016-08-25 15:29:12 +010020 * The DPO is a base class that is specialised by other objects to provide
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -070021 * concrete actions
Neale Ranns0bfe5d82016-08-25 15:29:12 +010022 *
23 * The VLIB graph nodes are graph of types, the DPO graph is a graph of instances.
24 */
25
26#include <vnet/dpo/dpo.h>
27#include <vnet/ip/lookup.h>
28#include <vnet/ip/format.h>
29#include <vnet/adj/adj.h>
30
31#include <vnet/dpo/load_balance.h>
32#include <vnet/dpo/mpls_label_dpo.h>
33#include <vnet/dpo/lookup_dpo.h>
34#include <vnet/dpo/drop_dpo.h>
35#include <vnet/dpo/receive_dpo.h>
36#include <vnet/dpo/punt_dpo.h>
37#include <vnet/dpo/classify_dpo.h>
Neale Ranns948e00f2016-10-20 13:39:34 +010038#include <vnet/dpo/ip_null_dpo.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000039#include <vnet/dpo/replicate_dpo.h>
Neale Ranns43161a82017-08-12 02:12:00 -070040#include <vnet/dpo/interface_rx_dpo.h>
41#include <vnet/dpo/interface_tx_dpo.h>
Neale Ranns0f26c5a2017-03-01 15:12:11 -080042#include <vnet/dpo/mpls_disposition.h>
Neale Rannsf068c3e2018-01-03 04:18:48 -080043#include <vnet/dpo/dvr_dpo.h>
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070044#include <vnet/dpo/l3_proxy_dpo.h>
Neale Ranns53da2212018-02-24 02:11:19 -080045#include <vnet/dpo/ip6_ll_dpo.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010046
47/**
48 * Array of char* names for the DPO types and protos
49 */
50static const char* dpo_type_names[] = DPO_TYPES;
51static const char* dpo_proto_names[] = DPO_PROTOS;
52
53/**
54 * @brief Vector of virtual function tables for the DPO types
55 *
56 * This is a vector so we can dynamically register new DPO types in plugins.
57 */
58static dpo_vft_t *dpo_vfts;
59
60/**
61 * @brief vector of graph node names associated with each DPO type and protocol.
62 *
63 * dpo_nodes[child_type][child_proto][node_X] = node_name;
64 * i.e.
65 * dpo_node[DPO_LOAD_BALANCE][DPO_PROTO_IP4][0] = "ip4-lookup"
66 * dpo_node[DPO_LOAD_BALANCE][DPO_PROTO_IP4][1] = "ip4-load-balance"
67 *
68 * This is a vector so we can dynamically register new DPO types in plugins.
69 */
70static const char* const * const ** dpo_nodes;
71
72/**
73 * @brief Vector of edge indicies from parent DPO nodes to child
74 *
Neale Ranns8fe8cc22016-11-01 10:05:08 +000075 * dpo_edges[child_type][child_proto][parent_type][parent_proto] = edge_index
Neale Ranns0bfe5d82016-08-25 15:29:12 +010076 *
77 * This array is derived at init time from the dpo_nodes above. Note that
78 * the third dimension in dpo_nodes is lost, hence, the edge index from each
79 * node MUST be the same.
Neale Ranns8fe8cc22016-11-01 10:05:08 +000080 * Including both the child and parent protocol is required to support the
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -070081 * case where it changes as the graph is traversed, most notably when an
Neale Ranns8fe8cc22016-11-01 10:05:08 +000082 * MPLS label is popped.
Neale Ranns0bfe5d82016-08-25 15:29:12 +010083 *
84 * Note that this array is child type specific, not child instance specific.
85 */
Neale Ranns8fe8cc22016-11-01 10:05:08 +000086static u32 ****dpo_edges;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010087
88/**
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -070089 * @brief The DPO type value that can be assigned to the next dynamic
Neale Ranns0bfe5d82016-08-25 15:29:12 +010090 * type registration.
91 */
92static dpo_type_t dpo_dynamic = DPO_LAST;
93
Neale Rannsad95b5d2016-11-10 20:35:14 +000094dpo_proto_t
95vnet_link_to_dpo_proto (vnet_link_t linkt)
96{
97 switch (linkt)
98 {
99 case VNET_LINK_IP6:
100 return (DPO_PROTO_IP6);
101 case VNET_LINK_IP4:
102 return (DPO_PROTO_IP4);
103 case VNET_LINK_MPLS:
104 return (DPO_PROTO_MPLS);
105 case VNET_LINK_ETHERNET:
106 return (DPO_PROTO_ETHERNET);
Florin Corasce1b4c72017-01-26 14:25:34 -0800107 case VNET_LINK_NSH:
108 return (DPO_PROTO_NSH);
Neale Rannsad95b5d2016-11-10 20:35:14 +0000109 case VNET_LINK_ARP:
110 break;
111 }
112 ASSERT(0);
113 return (0);
114}
115
Neale Rannsda78f952017-05-24 09:15:43 -0700116vnet_link_t
117dpo_proto_to_link (dpo_proto_t dp)
118{
119 switch (dp)
120 {
121 case DPO_PROTO_IP6:
122 return (VNET_LINK_IP6);
123 case DPO_PROTO_IP4:
124 return (VNET_LINK_IP4);
125 case DPO_PROTO_MPLS:
Neale Rannsd792d9c2017-10-21 10:53:20 -0700126 case DPO_PROTO_BIER:
Neale Rannsda78f952017-05-24 09:15:43 -0700127 return (VNET_LINK_MPLS);
128 case DPO_PROTO_ETHERNET:
129 return (VNET_LINK_ETHERNET);
130 case DPO_PROTO_NSH:
131 return (VNET_LINK_NSH);
132 }
133 return (~0);
134}
135
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136u8 *
137format_dpo_type (u8 * s, va_list * args)
138{
139 dpo_type_t type = va_arg (*args, int);
140
141 s = format(s, "%s", dpo_type_names[type]);
142
143 return (s);
144}
145
146u8 *
147format_dpo_id (u8 * s, va_list * args)
148{
149 dpo_id_t *dpo = va_arg (*args, dpo_id_t*);
150 u32 indent = va_arg (*args, u32);
151
152 s = format(s, "[@%d]: ", dpo->dpoi_next_node);
153
154 if (NULL != dpo_vfts[dpo->dpoi_type].dv_format)
155 {
Neale Ranns2303cb12018-02-21 04:57:17 -0800156 s = format(s, "%U",
157 dpo_vfts[dpo->dpoi_type].dv_format,
158 dpo->dpoi_index,
159 indent);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100160 }
Neale Ranns2303cb12018-02-21 04:57:17 -0800161 else
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100162 {
Neale Ranns2303cb12018-02-21 04:57:17 -0800163 switch (dpo->dpoi_type)
164 {
165 case DPO_FIRST:
166 s = format(s, "unset");
167 break;
168 default:
169 s = format(s, "unknown");
170 break;
171 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100172 }
173 return (s);
174}
175
176u8 *
177format_dpo_proto (u8 * s, va_list * args)
178{
179 dpo_proto_t proto = va_arg (*args, int);
180
181 return (format(s, "%s", dpo_proto_names[proto]));
182}
183
184void
185dpo_set (dpo_id_t *dpo,
186 dpo_type_t type,
187 dpo_proto_t proto,
188 index_t index)
189{
190 dpo_id_t tmp = *dpo;
191
192 dpo->dpoi_type = type;
193 dpo->dpoi_proto = proto,
194 dpo->dpoi_index = index;
195
196 if (DPO_ADJACENCY == type)
197 {
198 /*
199 * set the adj subtype
200 */
201 ip_adjacency_t *adj;
202
203 adj = adj_get(index);
204
205 switch (adj->lookup_next_index)
206 {
207 case IP_LOOKUP_NEXT_ARP:
208 dpo->dpoi_type = DPO_ADJACENCY_INCOMPLETE;
209 break;
210 case IP_LOOKUP_NEXT_MIDCHAIN:
211 dpo->dpoi_type = DPO_ADJACENCY_MIDCHAIN;
212 break;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800213 case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
214 dpo->dpoi_type = DPO_ADJACENCY_MCAST_MIDCHAIN;
215 break;
216 case IP_LOOKUP_NEXT_MCAST:
217 dpo->dpoi_type = DPO_ADJACENCY_MCAST;
Neale Ranns8c4611b2017-05-23 03:43:47 -0700218 break;
219 case IP_LOOKUP_NEXT_GLEAN:
220 dpo->dpoi_type = DPO_ADJACENCY_GLEAN;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800221 break;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100222 default:
223 break;
224 }
225 }
226 dpo_lock(dpo);
227 dpo_unlock(&tmp);
228}
229
230void
231dpo_reset (dpo_id_t *dpo)
232{
Neale Rannsad95b5d2016-11-10 20:35:14 +0000233 dpo_id_t tmp = DPO_INVALID;
234
235 /*
236 * use the atomic copy operation.
237 */
238 dpo_copy(dpo, &tmp);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100239}
240
241/**
242 * \brief
243 * Compare two Data-path objects
244 *
245 * like memcmp, return 0 is matching, !0 otherwise.
246 */
247int
248dpo_cmp (const dpo_id_t *dpo1,
249 const dpo_id_t *dpo2)
250{
251 int res;
252
253 res = dpo1->dpoi_type - dpo2->dpoi_type;
254
255 if (0 != res) return (res);
256
257 return (dpo1->dpoi_index - dpo2->dpoi_index);
258}
259
260void
261dpo_copy (dpo_id_t *dst,
262 const dpo_id_t *src)
263{
264 dpo_id_t tmp = *dst;
265
266 /*
267 * the destination is written in a single u64 write - hence atomically w.r.t
268 * any packets inflight.
269 */
Dave Barachf8d50682019-05-14 18:01:44 -0400270 *((u64*)dst) = *(u64*)src;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100271
272 dpo_lock(dst);
Dave Barachf8d50682019-05-14 18:01:44 -0400273 dpo_unlock(&tmp);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100274}
275
276int
277dpo_is_adj (const dpo_id_t *dpo)
278{
279 return ((dpo->dpoi_type == DPO_ADJACENCY) ||
280 (dpo->dpoi_type == DPO_ADJACENCY_INCOMPLETE) ||
281 (dpo->dpoi_type == DPO_ADJACENCY_MIDCHAIN) ||
282 (dpo->dpoi_type == DPO_ADJACENCY_GLEAN));
283}
284
Neale Ranns43161a82017-08-12 02:12:00 -0700285static u32 *
286dpo_default_get_next_node (const dpo_id_t *dpo)
287{
288 u32 *node_indices = NULL;
289 const char *node_name;
290 u32 ii = 0;
291
292 node_name = dpo_nodes[dpo->dpoi_type][dpo->dpoi_proto][ii];
293 while (NULL != node_name)
294 {
295 vlib_node_t *node;
296
297 node = vlib_get_node_by_name(vlib_get_main(), (u8*) node_name);
298 ASSERT(NULL != node);
299 vec_add1(node_indices, node->index);
300
301 ++ii;
302 node_name = dpo_nodes[dpo->dpoi_type][dpo->dpoi_proto][ii];
303 }
304
305 return (node_indices);
306}
307
Neale Ranns2303cb12018-02-21 04:57:17 -0800308/**
309 * A default variant of the make interpose function that just returns
310 * the original
311 */
312static void
313dpo_default_mk_interpose (const dpo_id_t *original,
314 const dpo_id_t *parent,
315 dpo_id_t *clone)
316{
317 dpo_copy(clone, original);
318}
319
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100320void
321dpo_register (dpo_type_t type,
322 const dpo_vft_t *vft,
323 const char * const * const * nodes)
324{
325 vec_validate(dpo_vfts, type);
326 dpo_vfts[type] = *vft;
Neale Ranns43161a82017-08-12 02:12:00 -0700327 if (NULL == dpo_vfts[type].dv_get_next_node)
328 {
329 dpo_vfts[type].dv_get_next_node = dpo_default_get_next_node;
330 }
Neale Ranns2303cb12018-02-21 04:57:17 -0800331 if (NULL == dpo_vfts[type].dv_mk_interpose)
332 {
333 dpo_vfts[type].dv_mk_interpose = dpo_default_mk_interpose;
334 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100335
336 vec_validate(dpo_nodes, type);
337 dpo_nodes[type] = nodes;
338}
339
340dpo_type_t
341dpo_register_new_type (const dpo_vft_t *vft,
342 const char * const * const * nodes)
343{
344 dpo_type_t type = dpo_dynamic++;
345
346 dpo_register(type, vft, nodes);
347
348 return (type);
349}
350
351void
Neale Ranns2303cb12018-02-21 04:57:17 -0800352dpo_mk_interpose (const dpo_id_t *original,
353 const dpo_id_t *parent,
354 dpo_id_t *clone)
355{
356 if (!dpo_id_is_valid(original))
357 return;
358
359 dpo_vfts[original->dpoi_type].dv_mk_interpose(original, parent, clone);
360}
361
362void
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100363dpo_lock (dpo_id_t *dpo)
364{
365 if (!dpo_id_is_valid(dpo))
366 return;
367
368 dpo_vfts[dpo->dpoi_type].dv_lock(dpo);
369}
370
371void
372dpo_unlock (dpo_id_t *dpo)
373{
374 if (!dpo_id_is_valid(dpo))
375 return;
376
377 dpo_vfts[dpo->dpoi_type].dv_unlock(dpo);
378}
379
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700380u32
381dpo_get_urpf(const dpo_id_t *dpo)
382{
383 if (dpo_id_is_valid(dpo) &&
384 (NULL != dpo_vfts[dpo->dpoi_type].dv_get_urpf))
385 {
386 return (dpo_vfts[dpo->dpoi_type].dv_get_urpf(dpo));
387 }
388
389 return (~0);
390}
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100391
392static u32
393dpo_get_next_node (dpo_type_t child_type,
394 dpo_proto_t child_proto,
395 const dpo_id_t *parent_dpo)
396{
397 dpo_proto_t parent_proto;
398 dpo_type_t parent_type;
399
400 parent_type = parent_dpo->dpoi_type;
401 parent_proto = parent_dpo->dpoi_proto;
402
403 vec_validate(dpo_edges, child_type);
404 vec_validate(dpo_edges[child_type], child_proto);
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000405 vec_validate(dpo_edges[child_type][child_proto], parent_type);
406 vec_validate_init_empty(
407 dpo_edges[child_type][child_proto][parent_type],
408 parent_proto, ~0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100409
410 /*
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700411 * if the edge index has not yet been created for this node to node transition
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100412 */
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000413 if (~0 == dpo_edges[child_type][child_proto][parent_type][parent_proto])
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100414 {
Neale Ranns43161a82017-08-12 02:12:00 -0700415 vlib_node_t *child_node;
416 u32 *parent_indices;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100417 vlib_main_t *vm;
Neale Ranns43161a82017-08-12 02:12:00 -0700418 u32 edge, *pi, cc;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100419
420 vm = vlib_get_main();
421
Neale Ranns43161a82017-08-12 02:12:00 -0700422 ASSERT(NULL != dpo_vfts[parent_type].dv_get_next_node);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100423 ASSERT(NULL != dpo_nodes[child_type]);
424 ASSERT(NULL != dpo_nodes[child_type][child_proto]);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100425
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000426 cc = 0;
Neale Ranns43161a82017-08-12 02:12:00 -0700427 parent_indices = dpo_vfts[parent_type].dv_get_next_node(parent_dpo);
428
429 vlib_worker_thread_barrier_sync(vm);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100430
431 /*
Neale Ranns43161a82017-08-12 02:12:00 -0700432 * create a graph arc from each of the child's registered node types,
433 * to each of the parent's.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100434 */
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000435 while (NULL != dpo_nodes[child_type][child_proto][cc])
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100436 {
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000437 child_node =
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100438 vlib_get_node_by_name(vm,
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000439 (u8*) dpo_nodes[child_type][child_proto][cc]);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100440
Neale Ranns43161a82017-08-12 02:12:00 -0700441 vec_foreach(pi, parent_indices)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100442 {
Neale Ranns43161a82017-08-12 02:12:00 -0700443 edge = vlib_node_add_next(vm, child_node->index, *pi);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100444
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000445 if (~0 == dpo_edges[child_type][child_proto][parent_type][parent_proto])
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100446 {
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000447 dpo_edges[child_type][child_proto][parent_type][parent_proto] = edge;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100448 }
449 else
450 {
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000451 ASSERT(dpo_edges[child_type][child_proto][parent_type][parent_proto] == edge);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100452 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100453 }
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000454 cc++;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100455 }
Neale Rannsbb620d72017-06-29 00:19:08 -0700456
457 vlib_worker_thread_barrier_release(vm);
Neale Ranns43161a82017-08-12 02:12:00 -0700458 vec_free(parent_indices);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100459 }
460
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000461 return (dpo_edges[child_type][child_proto][parent_type][parent_proto]);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100462}
463
464/**
Vijayabhaskar Katamreddyb9ca61b2018-03-14 14:04:27 -0700465 * @brief return already stacked up next node index for a given
466 * child_type/child_proto and parent_type/patent_proto.
467 * The VLIB graph arc used is taken from the parent and child types
468 * passed.
469 */
470u32
471dpo_get_next_node_by_type_and_proto (dpo_type_t child_type,
472 dpo_proto_t child_proto,
473 dpo_type_t parent_type,
474 dpo_proto_t parent_proto)
475{
476 return (dpo_edges[child_type][child_proto][parent_type][parent_proto]);
477}
478
479/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100480 * @brief Stack one DPO object on another, and thus establish a child parent
481 * relationship. The VLIB graph arc used is taken from the parent and child types
482 * passed.
483 */
484static void
485dpo_stack_i (u32 edge,
486 dpo_id_t *dpo,
487 const dpo_id_t *parent)
488{
489 /*
490 * in order to get an atomic update of the parent we create a temporary,
491 * from a copy of the child, and add the next_node. then we copy to the parent
492 */
Neale Ranns948e00f2016-10-20 13:39:34 +0100493 dpo_id_t tmp = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100494 dpo_copy(&tmp, parent);
495
496 /*
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700497 * get the edge index for the parent to child VLIB graph transition
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100498 */
499 tmp.dpoi_next_node = edge;
500
501 /*
502 * this update is atomic.
503 */
504 dpo_copy(dpo, &tmp);
505
506 dpo_reset(&tmp);
507}
508
509/**
510 * @brief Stack one DPO object on another, and thus establish a child-parent
511 * relationship. The VLIB graph arc used is taken from the parent and child types
512 * passed.
513 */
514void
515dpo_stack (dpo_type_t child_type,
516 dpo_proto_t child_proto,
517 dpo_id_t *dpo,
518 const dpo_id_t *parent)
519{
520 dpo_stack_i(dpo_get_next_node(child_type, child_proto, parent), dpo, parent);
521}
522
523/**
524 * @brief Stack one DPO object on another, and thus establish a child parent
525 * relationship. A new VLIB graph arc is created from the child node passed
526 * to the nodes registered by the parent. The VLIB infra will ensure this arc
527 * is added only once.
528 */
529void
530dpo_stack_from_node (u32 child_node_index,
531 dpo_id_t *dpo,
532 const dpo_id_t *parent)
533{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100534 dpo_type_t parent_type;
Neale Ranns43161a82017-08-12 02:12:00 -0700535 u32 *parent_indices;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100536 vlib_main_t *vm;
Neale Ranns43161a82017-08-12 02:12:00 -0700537 u32 edge, *pi;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100538
Neale Ranns43161a82017-08-12 02:12:00 -0700539 edge = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100540 parent_type = parent->dpoi_type;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100541 vm = vlib_get_main();
542
Neale Ranns43161a82017-08-12 02:12:00 -0700543 ASSERT(NULL != dpo_vfts[parent_type].dv_get_next_node);
544 parent_indices = dpo_vfts[parent_type].dv_get_next_node(parent);
545 ASSERT(parent_indices);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100546
Neale Ranns43161a82017-08-12 02:12:00 -0700547 /*
548 * This loop is purposefully written with the worker thread lock in the
549 * inner loop because;
550 * 1) the likelihood that the edge does not exist is smaller
551 * 2) the likelihood there is more than one node is even smaller
552 * so we are optimising for not need to take the lock
553 */
554 vec_foreach(pi, parent_indices)
Neale Rannsbb620d72017-06-29 00:19:08 -0700555 {
Neale Ranns43161a82017-08-12 02:12:00 -0700556 edge = vlib_node_get_next(vm, child_node_index, *pi);
Neale Rannsbb620d72017-06-29 00:19:08 -0700557
Neale Ranns43161a82017-08-12 02:12:00 -0700558 if (~0 == edge)
559 {
560 vlib_worker_thread_barrier_sync(vm);
Neale Rannsbb620d72017-06-29 00:19:08 -0700561
Neale Ranns43161a82017-08-12 02:12:00 -0700562 edge = vlib_node_add_next(vm, child_node_index, *pi);
563
564 vlib_worker_thread_barrier_release(vm);
565 }
Neale Rannsbb620d72017-06-29 00:19:08 -0700566 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100567 dpo_stack_i(edge, dpo, parent);
Kingwel Xiecd4d5b72018-04-24 17:47:56 +0800568
569 /* should free this local vector to avoid memory leak */
570 vec_free(parent_indices);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100571}
572
573static clib_error_t *
574dpo_module_init (vlib_main_t * vm)
575{
576 drop_dpo_module_init();
577 punt_dpo_module_init();
578 receive_dpo_module_init();
579 load_balance_module_init();
580 mpls_label_dpo_module_init();
581 classify_dpo_module_init();
582 lookup_dpo_module_init();
Neale Ranns948e00f2016-10-20 13:39:34 +0100583 ip_null_dpo_module_init();
Neale Ranns53da2212018-02-24 02:11:19 -0800584 ip6_ll_dpo_module_init();
Neale Ranns32e1c012016-11-22 17:07:28 +0000585 replicate_module_init();
Neale Ranns43161a82017-08-12 02:12:00 -0700586 interface_rx_dpo_module_init();
587 interface_tx_dpo_module_init();
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800588 mpls_disp_dpo_module_init();
Neale Rannsf068c3e2018-01-03 04:18:48 -0800589 dvr_dpo_module_init();
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700590 l3_proxy_dpo_module_init();
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100591
592 return (NULL);
593}
594
Dave Barachf8d50682019-05-14 18:01:44 -0400595/* *INDENT-OFF* */
596VLIB_INIT_FUNCTION(dpo_module_init) =
597{
598 .runs_before = VLIB_INITS ("ip_main_init"),
599};
600/* *INDENT-ON* */
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100601
602static clib_error_t *
603dpo_memory_show (vlib_main_t * vm,
604 unformat_input_t * input,
605 vlib_cli_command_t * cmd)
606{
607 dpo_vft_t *vft;
608
609 vlib_cli_output (vm, "DPO memory");
610 vlib_cli_output (vm, "%=30s %=5s %=8s/%=9s totals",
611 "Name","Size", "in-use", "allocated");
612
613 vec_foreach(vft, dpo_vfts)
614 {
615 if (NULL != vft->dv_mem_show)
616 vft->dv_mem_show();
617 }
618
619 return (NULL);
620}
621
622/* *INDENT-OFF* */
623/*?
624 * The '<em>sh dpo memory </em>' command displays the memory usage for each
625 * data-plane object type.
626 *
627 * @cliexpar
628 * @cliexstart{show dpo memory}
629 * DPO memory
630 * Name Size in-use /allocated totals
631 * load-balance 64 12 / 12 768/768
632 * Adjacency 256 1 / 1 256/256
633 * Receive 24 5 / 5 120/120
634 * Lookup 12 0 / 0 0/0
635 * Classify 12 0 / 0 0/0
636 * MPLS label 24 0 / 0 0/0
637 * @cliexend
638?*/
639VLIB_CLI_COMMAND (show_fib_memory, static) = {
640 .path = "show dpo memory",
641 .function = dpo_memory_show,
642 .short_help = "show dpo memory",
643};
644/* *INDENT-ON* */