FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bier_disp_entry.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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  * bier_disposition : The BIER disposition object
17  *
18  * A BIER disposition object is present in the IP mcast output list
19  * and represents the disposition of a BIER bitmask. After BIER header
20  * disposition the packet is forward within the appropriate/specified
21  * BIER table
22  */
23 
26 #include <vnet/fib/fib_path_list.h>
27 #include <vnet/dpo/drop_dpo.h>
28 
29 /**
30  * The memory pool of all imp objects
31  */
33 
34 /**
35  * When constructing the BIER imp ID from an index and BSL, shift
36  * the BSL this far
37  */
38 #define BIER_DISP_ENTRY_ID_HLEN_SHIFT 24
39 
40 static void
42 {
43  bde->bde_locks++;
44 }
45 
46 void
48 {
50 }
51 
52 static index_t
54 {
55  return (bde - bier_disp_entry_pool);
56 }
57 
58 index_t
60 {
61  dpo_id_t invalid = DPO_INVALID;
62  bier_hdr_proto_id_t pproto;
63  bier_disp_entry_t *bde;
64 
66 
67  bde->bde_locks = 0;
68 
70  {
71  bde->bde_fwd[pproto].bde_dpo = invalid;
72  bde->bde_fwd[pproto].bde_rpf_id = ~0;
73  bde->bde_pl[pproto] = FIB_NODE_INDEX_INVALID;
74  }
75 
77  return (bier_disp_entry_get_index(bde));
78 }
79 
80 void
82 {
83  bier_disp_entry_t *bde;
84 
85  if (INDEX_INVALID == bdei)
86  {
87  return;
88  }
89 
90  bde = bier_disp_entry_get(bdei);
91 
92  bde->bde_locks--;
93 
94  if (0 == bde->bde_locks)
95  {
96  bier_hdr_proto_id_t pproto;
97 
99  {
100  dpo_unlock(&bde->bde_fwd[pproto].bde_dpo);
101  bde->bde_fwd[pproto].bde_rpf_id = ~0;
102  fib_path_list_unlock(bde->bde_pl[pproto]);
103  }
105  }
106 }
107 
109 {
112 
115  fib_node_index_t path_index,
116  void *arg)
117 {
119 
120  ctx->bdew_rpf_id = fib_path_get_rpf_id(path_index);
121 
122  if (~0 != ctx->bdew_rpf_id)
123  {
124  return (FIB_PATH_LIST_WALK_STOP);
125  }
127 }
128 
129 static void
131  bier_hdr_proto_id_t pproto)
132 {
133  dpo_id_t via_dpo = DPO_INVALID;
134  fib_node_index_t pli;
135 
136  pli = bde->bde_pl[pproto];
137 
138  if (FIB_NODE_INDEX_INVALID == pli)
139  {
140  dpo_copy(&via_dpo,
142  }
143  else
144  {
147  bier_hdr_proto_to_dpo(pproto)),
149  &via_dpo);
150 
152  .bdew_rpf_id = ~0,
153  };
154 
156  bde->bde_fwd[pproto].bde_rpf_id = ctx.bdew_rpf_id;
157  }
158 
161  &bde->bde_fwd[pproto].bde_dpo,
162  &via_dpo);
163 }
164 
165 void
167  bier_hdr_proto_id_t pproto,
168  const fib_route_path_t *rpaths)
169 {
170  fib_node_index_t *pli, old_pli;
171  bier_disp_entry_t *bde;
172 
173  bde = bier_disp_entry_get(bdei);
174  pli = &bde->bde_pl[pproto];
175  old_pli = *pli;
176 
177  /*
178  * create a new or update the existing path-list for this
179  * payload protocol
180  */
181  if (FIB_NODE_INDEX_INVALID == *pli)
182  {
185  rpaths);
186  }
187  else
188  {
189  *pli = fib_path_list_copy_and_path_add(old_pli,
192  rpaths);
193  }
194 
195  fib_path_list_lock(*pli);
196  fib_path_list_unlock(old_pli);
197 
198  bier_disp_entry_restack(bde, pproto);
199 }
200 
201 int
203  bier_hdr_proto_id_t pproto,
204  const fib_route_path_t *rpaths)
205 {
206  fib_node_index_t *pli, old_pli;
207  bier_disp_entry_t *bde;
208 
209  bde = bier_disp_entry_get(bdei);
210  pli = &bde->bde_pl[pproto];
211  old_pli = *pli;
212 
213  /*
214  * update the existing path-list for this payload protocol
215  */
216  if (FIB_NODE_INDEX_INVALID != *pli)
217  {
218  *pli = fib_path_list_copy_and_path_remove(old_pli,
221  rpaths);
222 
223  fib_path_list_lock(*pli);
224  fib_path_list_unlock(old_pli);
225 
226  bier_disp_entry_restack(bde, pproto);
227  }
228 
229  /*
230  * if there are no path-list defined for any payload protocol
231  * then this entry is OK for removal
232  */
233  int remove = 1;
234 
236  {
237  if (FIB_NODE_INDEX_INVALID != bde->bde_pl[pproto])
238  {
239  remove = 0;
240  break;
241  }
242  }
243 
244  return (remove);
245 }
246 
247 u8*
248 format_bier_disp_entry (u8* s, va_list *args)
249 {
250  index_t bdei = va_arg (*args, index_t);
251  u32 indent = va_arg(*args, u32);
252  bier_show_flags_t flags = va_arg(*args, bier_show_flags_t);
253  bier_hdr_proto_id_t pproto;
254  bier_disp_entry_t *bde;
255 
256  bde = bier_disp_entry_get(bdei);
257 
258  s = format(s, "%Ubier-disp:[%d]", format_white_space, indent, bdei);
259 
261  {
262  if (INDEX_INVALID != bde->bde_pl[pproto])
263  {
264  s = format(s, "\n%U%U\n",
265  format_white_space, indent+2,
266  format_bier_hdr_proto, pproto);
267  s = format(s, "%U", format_fib_path_list, bde->bde_pl[pproto], indent+4);
268 
269  if (flags & BIER_SHOW_DETAIL)
270  {
271  s = format(s, "\n%UForwarding:",
272  format_white_space, indent+4);
273  s = format(s, "\n%Urpf-id:%d",
274  format_white_space, indent+6,
275  bde->bde_fwd[pproto].bde_rpf_id);
276  s = format(s, "\n%U%U",
277  format_white_space, indent+6,
278  format_dpo_id, &bde->bde_fwd[pproto].bde_dpo, indent+2);
279  }
280  }
281  }
282  return (s);
283 }
284 
285 void
287  dpo_id_t *dpo)
288 {
290 }
291 
292 const static char* const bier_disp_entry_bier_nodes[] =
293 {
294  "bier-disp-dispatch",
295  NULL,
296 };
297 
298 const static char* const * const bier_disp_entry_nodes[DPO_PROTO_NUM] =
299 {
301 };
302 
303 static void
305 {
307 }
308 
309 static void
311 {
313 }
314 
315 static void
317 {
318  fib_show_memory_usage("BIER disposition",
321  sizeof(bier_disp_entry_t));
322 }
323 
324 static u8*
326 {
327  index_t index = va_arg(*ap, index_t);
328  u32 indent = va_arg(*ap, u32);
329 
330  s = format(s, "%U", format_bier_disp_entry, index, indent, BIER_SHOW_DETAIL);
331 
332  return (s);
333 }
334 
337  .dv_unlock = bier_disp_entry_dpo_unlock,
338  .dv_format = format_bier_disp_entry_dpo,
339  .dv_mem_show = bier_disp_entry_dpo_mem_show,
340 };
341 
342 clib_error_t *
344 {
348 
349  return (NULL);
350 }
351 
353 
354 static clib_error_t *
356  unformat_input_t * input,
357  vlib_cli_command_t * cmd)
358 {
359  index_t bdei;
360 
361  bdei = INDEX_INVALID;
362 
363  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
364  if (unformat (input, "%d", &bdei))
365  ;
366  else
367  {
368  break;
369  }
370  }
371 
372  if (INDEX_INVALID == bdei)
373  {
374  return (NULL);
375  }
376  else
377  {
379  {
380  vlib_cli_output(vm, "No such BIER disp entry: %d", bdei);
381  }
382  else
383  {
384  vlib_cli_output(vm, "%U", format_bier_disp_entry, bdei, 1,
386  }
387  }
388  return (NULL);
389 }
390 
392  .path = "show bier disp entry",
393  .short_help = "show bier disp entry index",
394  .function = show_bier_disp_entry,
395 };
FOR_EACH_BIER_HDR_PROTO
#define FOR_EACH_BIER_HDR_PROTO(_proto)
Definition: bier_types.h:206
bier_disp_entry_t_::bde_pl
fib_node_index_t bde_pl[BIER_HDR_N_PROTO]
The path-lists used by per-payload protocol parents.
Definition: bier_disp_entry.h:59
bier_disp_entry_unlock
void bier_disp_entry_unlock(index_t bdei)
Definition: bier_disp_entry.c:81
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
DPO_INVALID
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:204
DPO_BIER_DISP_ENTRY
@ DPO_BIER_DISP_ENTRY
Definition: dpo.h:127
bier_disp_entry_path_list_walk_ctx_t
struct bier_disp_entry_path_list_walk_ctx_t_ bier_disp_entry_path_list_walk_ctx_t
bier_disp_entry_path_list_walk_ctx_t_
Definition: bier_disp_entry.c:108
bier_disp_entry_t_::bde_rpf_id
u32 bde_rpf_id
Definition: bier_disp_entry.h:45
bier_disp_entry_path_list_walk_ctx_t_::bdew_rpf_id
u32 bdew_rpf_id
Definition: bier_disp_entry.c:110
bier_disp_entry.h
bier_disp_entry_pool
bier_disp_entry_t * bier_disp_entry_pool
bier_disposition : The BIER disposition object
Definition: bier_disp_entry.c:32
pool_get_aligned
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:249
vlib_cli_command_t::path
char * path
Definition: cli.h:96
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_path_list_walk_rc_t
enum fib_path_list_walk_rc_t_ fib_path_list_walk_rc_t
return code to control pat-hlist walk
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
bier_hdr_inlines.h
DPO_PROTO_BIER
@ DPO_PROTO_BIER
Definition: dpo.h:68
format_bier_disp_entry_dpo
static u8 * format_bier_disp_entry_dpo(u8 *s, va_list *ap)
Definition: bier_disp_entry.c:325
format_bier_hdr_proto
u8 * format_bier_hdr_proto(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:104
bier_disp_entry_restack
static void bier_disp_entry_restack(bier_disp_entry_t *bde, bier_hdr_proto_id_t pproto)
Definition: bier_disp_entry.c:130
unformat_input_t
struct _unformat_input_t unformat_input_t
fib_path_get_rpf_id
u32 fib_path_get_rpf_id(fib_node_index_t path_index)
Definition: fib_path.c:2264
drop_dpo.h
bier_disp_entry_t_::bde_fwd
struct bier_disp_entry_t_::@152 bde_fwd[BIER_HDR_N_PROTO]
The DPO contributed from the per-payload protocol parents on cacheline 1.
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
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
fib_path_list_unlock
void fib_path_list_unlock(fib_node_index_t path_list_index)
Definition: fib_path_list.c:1357
bier_disp_entry_path_list_walk
static fib_path_list_walk_rc_t bier_disp_entry_path_list_walk(fib_node_index_t pl_index, fib_node_index_t path_index, void *arg)
Definition: bier_disp_entry.c:114
bier_disp_entry_t_
bier_disposition : The BIER disposition object
Definition: bier_disp_entry.h:32
bier_disp_entry_dpo_unlock
static void bier_disp_entry_dpo_unlock(dpo_id_t *dpo)
Definition: bier_disp_entry.c:310
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
bier_disp_entry_get_index
static index_t bier_disp_entry_get_index(bier_disp_entry_t *bde)
Definition: bier_disp_entry.c:53
format_fib_path_list
u8 * format_fib_path_list(u8 *s, va_list *args)
Definition: fib_path_list.c:125
FIB_PATH_LIST_FLAG_SHARED
@ FIB_PATH_LIST_FLAG_SHARED
Definition: fib_path_list.h:81
bier_disp_entry_contribute_forwarding
void bier_disp_entry_contribute_forwarding(index_t bdei, dpo_id_t *dpo)
Definition: bier_disp_entry.c:286
bier_disp_entry_nodes
const static char *const *const bier_disp_entry_nodes[DPO_PROTO_NUM]
Definition: bier_disp_entry.c:298
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
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_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
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
bier_disp_entry_path_add
void bier_disp_entry_path_add(index_t bdei, bier_hdr_proto_id_t pproto, const fib_route_path_t *rpaths)
Definition: bier_disp_entry.c:166
bier_show_flags_t
enum bier_show_flags_t_ bier_show_flags_t
Flags to control show output.
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
bier_disp_entry_t_::bde_dpo
dpo_id_t bde_dpo
Definition: bier_disp_entry.h:44
fib_path_list_contribute_forwarding
void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index, fib_forward_chain_type_t fct, fib_path_list_fwd_flags_t flags, dpo_id_t *dpo)
Definition: fib_path_list.c:1211
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
FIB_PATH_LIST_WALK_STOP
@ FIB_PATH_LIST_WALK_STOP
Definition: fib_types.h:632
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
bier_disp_entry_bier_nodes
const static char *const bier_disp_entry_bier_nodes[]
Definition: bier_disp_entry.c:292
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
FIB_PATH_LIST_WALK_CONTINUE
@ FIB_PATH_LIST_WALK_CONTINUE
Definition: fib_types.h:633
bier_disp_entry_dpo_lock
static void bier_disp_entry_dpo_lock(dpo_id_t *dpo)
Definition: bier_disp_entry.c:304
bier_hdr_proto_id_t
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
pool_len
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:139
index
u32 index
Definition: flow_types.api:221
show_bier_disp_entry
static clib_error_t * show_bier_disp_entry(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_disp_entry.c:355
dpo_copy
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:264
fib_path_list.h
fib_path_list_copy_and_path_remove
fib_node_index_t fib_path_list_copy_and_path_remove(fib_node_index_t orig_path_list_index, fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
Definition: fib_path_list.c:1086
bier_disp_entry_lock
void bier_disp_entry_lock(index_t bdei)
Definition: bier_disp_entry.c:47
format
description fragment has unexpected format
Definition: map.api:433
fib_path_list_walk
void fib_path_list_walk(fib_node_index_t path_list_index, fib_path_list_walk_fn_t func, void *ctx)
Definition: fib_path_list.c:1382
fib_forw_chain_type_from_dpo_proto
fib_forward_chain_type_t fib_forw_chain_type_from_dpo_proto(dpo_proto_t proto)
Convert from a payload-protocol to a chain type.
Definition: fib_types.c:427
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
format_bier_disp_entry
u8 * format_bier_disp_entry(u8 *s, va_list *args)
Definition: bier_disp_entry.c:248
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
show_bier_disp_entry_node
static vlib_cli_command_t show_bier_disp_entry_node
(constructor) VLIB_CLI_COMMAND (show_bier_disp_entry_node)
Definition: bier_disp_entry.c:391
dpo_unlock
void dpo_unlock(dpo_id_t *dpo)
Release a reference counting lock on the DPO.
Definition: dpo.c:380
fib_path_list_lock
void fib_path_list_lock(fib_node_index_t path_list_index)
Definition: fib_path_list.c:1344
vlib_main_t
Definition: main.h:102
drop_dpo_get
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
bier_disp_entry_dpo_mem_show
static void bier_disp_entry_dpo_mem_show(void)
Definition: bier_disp_entry.c:316
bier_disp_entry_db_module_init
clib_error_t * bier_disp_entry_db_module_init(vlib_main_t *vm)
Definition: bier_disp_entry.c:343
FIB_PATH_LIST_FLAG_NO_URPF
@ FIB_PATH_LIST_FLAG_NO_URPF
Definition: fib_path_list.h:88
BIER_SHOW_DETAIL
@ BIER_SHOW_DETAIL
Definition: bier_types.h:27
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
bier_disp_entry_get
static bier_disp_entry_t * bier_disp_entry_get(index_t bdi)
Definition: bier_disp_entry.h:81
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
bier_disp_entry_add_or_lock
index_t bier_disp_entry_add_or_lock(void)
Definition: bier_disp_entry.c:59
vlib_cli_command_t
Definition: cli.h:92
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
fib_path_list_copy_and_path_add
fib_node_index_t fib_path_list_copy_and_path_add(fib_node_index_t orig_path_list_index, fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
Definition: fib_path_list.c:907
fib_path_list_create
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
Definition: fib_path_list.c:682
bier_disp_entry_path_remove
int bier_disp_entry_path_remove(index_t bdei, bier_hdr_proto_id_t pproto, const fib_route_path_t *rpaths)
Definition: bier_disp_entry.c:202
bier_disp_entry_lock_i
static void bier_disp_entry_lock_i(bier_disp_entry_t *bde)
Definition: bier_disp_entry.c:41
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
bier_hdr_proto_to_dpo
dpo_proto_t bier_hdr_proto_to_dpo(bier_hdr_proto_id_t bproto)
Convert from BIER next-hop proto to DPO proto.
Definition: bier_types.c:139
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
FIB_PATH_LIST_FWD_FLAG_COLLAPSE
@ FIB_PATH_LIST_FWD_FLAG_COLLAPSE
Definition: fib_path_list.h:143
bier_disp_entry_t_::bde_locks
u32 bde_locks
number of locks
Definition: bier_disp_entry.h:51
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
bier_disp_entry_vft
const static dpo_vft_t bier_disp_entry_vft
Definition: bier_disp_entry.c:335
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105