FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
bier_imp.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_imposition : The BIER imposition object
17  *
18  * A BIER imposition object is present in the IP mcast output list
19  * and represents the imposition of a BIER bitmask. After BIER header
20  * imposition the packet is forward within the appropriate/specified
21  * BIER table
22  */
23 
24 #include <vnet/bier/bier_imp.h>
25 #include <vnet/bier/bier_table.h>
27 #include <vnet/fib/fib_node.h>
28 #include <vnet/mpls/mpls_types.h>
29 
30 /**
31  * The memory pool of all imp objects
32  */
34 
35 /**
36  * When constructing the BIER imp ID from an index and BSL, shift
37  * the BSL this far
38  */
39 #define BIER_IMP_ID_HLEN_SHIFT 24
40 
41 static void
43 {
44  bi->bi_locks++;
45 }
46 
47 void
49 {
51 }
52 
53 static index_t
55 {
56  return (bi - bier_imp_pool);
57 }
58 
59 index_t
61  bier_bp_t sender,
62  const bier_bit_string_t *bs)
63 {
64  bier_imp_t *bi = NULL;
65  fib_protocol_t fproto;
66  index_t btii;
67 
68  pool_get_aligned(bier_imp_pool, bi, CLIB_CACHE_LINE_BYTES);
69 
70  bi->bi_tbl = *bti;
71  btii = bier_table_lock(bti);
72 
73  /*
74  * init the BIER header we will paint on in the data plane
75  */
76  bier_hdr_init(&bi->bi_hdr,
78  BIER_HDR_PROTO_INVALID, // filled in later
79  bti->bti_hdr_len,
80  0, // entropy
81  sender);
82  bier_hdr_hton(&bi->bi_hdr);
84 
85  bier_imp_lock_i(bi);
86 
87  /*
88  * get and stack on the forwarding info from the table
89  */
91  {
92  /*
93  * initialise to invalid first, lest we pick up garbage
94  * from the pool alloc
95  */
96  dpo_id_t dpo = DPO_INVALID;
97  bi->bi_dpo[fproto] = dpo;
98 
101  &bi->bi_dpo[fproto],
102  &dpo);
103  dpo_reset(&dpo);
104  }
105 
106  return (bier_imp_get_index(bi));
107 }
108 
109 void
111 {
112  fib_protocol_t fproto;
113  bier_imp_t *bi;
114 
115  if (INDEX_INVALID == bii)
116  {
117  return;
118  }
119 
120  bi = bier_imp_get(bii);
121 
122  bi->bi_locks--;
123 
124  if (0 == bi->bi_locks)
125  {
127 
129  {
130  dpo_reset(&bi->bi_dpo[fproto]);
131  }
132  pool_put(bier_imp_pool, bi);
133  }
134 }
135 
136 u8*
137 format_bier_imp (u8* s, va_list *args)
138 {
139  index_t bii = va_arg (*args, index_t);
140  u32 indent = va_arg(*args, u32);
141  bier_show_flags_t flags = va_arg(*args, bier_show_flags_t);
142  bier_imp_t *bi;
143 
144  bi = bier_imp_get(bii);
145 
146  s = format(s, "bier-imp:[%d]: tbl:[%U] hdr:[%U]",
147  bier_imp_get_index(bi),
149  format_bier_hdr, &bi->bi_hdr);
150 
151  if (BIER_SHOW_DETAIL & flags)
152  {
153  bier_bit_string_t bbs;
154  bier_hdr_t copy;
155 
156  copy = bi->bi_hdr;
157  bier_hdr_ntoh(&copy);
159  bier_hdr_get_len_id(&copy),
160  bi->bi_bits);
161 
162  s = format(s, "\n%U%U",
163  format_white_space, indent,
164  format_bier_bit_string, &bbs);
165  s = format(s, "\n%U%U",
166  format_white_space, indent,
167  format_dpo_id, &bi->bi_dpo, indent+2);
168  }
169 
170  return (s);
171 }
172 
173 void
176  dpo_id_t *dpo)
177 {
178  dpo_set(dpo, DPO_BIER_IMP, proto, bii);
179 }
180 
181 const static char* const bier_imp_ip4_nodes[] =
182 {
183  "bier-imp-ip4",
184  NULL,
185 };
186 const static char* const bier_imp_ip6_nodes[] =
187 {
188  "bier-imp-ip6",
189  NULL,
190 };
191 
192 const static char* const * const bier_imp_nodes[DPO_PROTO_NUM] =
193 {
196 };
197 
198 static void
200 {
202 }
203 
204 static void
206 {
208 }
209 
210 static void
212 {
213  fib_show_memory_usage("BIER imposition",
214  pool_elts(bier_imp_pool),
215  pool_len(bier_imp_pool),
216  sizeof(bier_imp_t));
217 }
218 
219 static u8*
220 format_bier_imp_dpo (u8* s, va_list *ap)
221 {
222  index_t index = va_arg(*ap, index_t);
223  u32 indent = va_arg(*ap, u32);
224 
225  s = format(s, "%U", format_bier_imp, index, indent, BIER_SHOW_DETAIL);
226 
227  return (s);
228 }
229 
230 const static dpo_vft_t bier_imp_vft = {
232  .dv_unlock = bier_imp_dpo_unlock,
233  .dv_format = format_bier_imp_dpo,
234  .dv_mem_show = bier_imp_dpo_mem_show,
235 };
236 
237 clib_error_t *
239 {
240  dpo_register(DPO_BIER_IMP, &bier_imp_vft, bier_imp_nodes);
241 
242  return (NULL);
243 }
244 
246 
247 static clib_error_t *
249  unformat_input_t * input,
250  vlib_cli_command_t * cmd)
251 {
252  bier_imp_t *bi;
253  index_t bii;
254 
255  bii = INDEX_INVALID;
256 
257  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
258  if (unformat (input, "%d", &bii))
259  ;
260  else
261  {
262  break;
263  }
264  }
265 
266  if (INDEX_INVALID == bii)
267  {
268  pool_foreach(bi, bier_imp_pool,
269  ({
271  bier_imp_get_index(bi),
272  1,
274  }));
275  }
276  else
277  {
278  if (pool_is_free_index(bier_imp_pool, bii))
279  {
280  vlib_cli_output(vm, "No such BIER imposition: %d", bii);
281  }
282  else
283  {
284  vlib_cli_output(vm, "%U", format_bier_imp, bii, 1,
286  }
287  }
288  return (NULL);
289 }
290 
291 VLIB_CLI_COMMAND (show_bier_imp_node, static) = {
292  .path = "show bier imp",
293  .short_help = "show bier imp [index]",
294  .function = show_bier_imp,
295 };
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:406
u8 * format_bier_bit_string(u8 *string, va_list *args)
u32 flags
Definition: vhost_user.h:141
void bier_imp_contribute_forwarding(index_t bii, dpo_proto_t proto, dpo_id_t *dpo)
Definition: bier_imp.c:174
A virtual function table regisitered for a DPO type.
Definition: dpo.h:401
static bier_hdr_len_id_t bier_hdr_get_len_id(const bier_hdr_t *bier_hdr)
u8 * format_bier_table_id(u8 *s, va_list *ap)
Format a BIER table ID.
Definition: bier_types.c:193
enum bier_show_flags_t_ bier_show_flags_t
Flags to control show output.
u32 bi_locks
number of locks
Definition: bier_imp.h:68
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
static void bier_imp_dpo_lock(dpo_id_t *dpo)
Definition: bier_imp.c:199
void bier_imp_lock(index_t bii)
Definition: bier_imp.c:48
static const char *const bier_imp_ip4_nodes[]
Definition: bier_imp.c:181
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:41
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
clib_error_t * bier_imp_db_module_init(vlib_main_t *vm)
Definition: bier_imp.c:238
The ID of a table.
Definition: bier_types.h:394
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u16 bbs_len
The length of the string in BYTES.
Definition: bier_types.h:282
A Variable length BitString.
Definition: bier_types.h:278
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:322
bier_imposition : The BIER imposition object
Definition: bier_imp.h:34
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
void bier_table_contribute_forwarding(index_t bti, dpo_id_t *dpo)
Definition: bier_table.c:728
static void bier_imp_dpo_unlock(dpo_id_t *dpo)
Definition: bier_imp.c:205
static bier_imp_t * bier_imp_get(index_t bii)
Definition: bier_imp.h:88
bier_hdr_t bi_hdr
The Header to impose.
Definition: bier_imp.h:50
u8 * format_bier_imp(u8 *s, va_list *args)
Definition: bier_imp.c:137
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
unsigned int u32
Definition: types.h:88
static void bier_imp_dpo_mem_show(void)
Definition: bier_imp.c:211
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u32 bier_bp_t
A bit positon as assigned to egress PEs.
Definition: bier_types.h:294
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
static void bier_hdr_hton(bier_hdr_t *bier_hdr)
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
index_t bier_imp_add_or_lock(const bier_table_id_t *bti, bier_bp_t sender, const bier_bit_string_t *bs)
Definition: bier_imp.c:60
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
vlib_main_t * vm
Definition: buffer.c:323
bier_imp_t * bier_imp_pool
bier_imposition : The BIER imposition object
Definition: bier_imp.c:33
static const char *const *const bier_imp_nodes[DPO_PROTO_NUM]
Definition: bier_imp.c:192
static const char *const bier_imp_ip6_nodes[]
Definition: bier_imp.c:186
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
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:186
static void bier_bit_string_init(bier_bit_string_t *bbs, bier_hdr_len_id_t len, bier_bit_mask_bucket_t *buckets)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
void bier_table_unlock(const bier_table_id_t *bti)
Definition: bier_table.c:218
static void bier_imp_lock_i(bier_imp_t *bi)
Definition: bier_imp.c:42
static u8 * format_bier_imp_dpo(u8 *s, va_list *ap)
Definition: bier_imp.c:220
bier_bit_mask_bucket_t * bbs_buckets
The buckets in the string.
Definition: bier_types.h:287
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:247
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:148
static index_t bier_imp_get_index(bier_imp_t *bi)
Definition: bier_imp.c:54
index_t bier_table_lock(const bier_table_id_t *btid)
Definition: bier_table.c:374
static clib_error_t * show_bier_imp(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_imp.c:248
u8 bi_bits[BIER_HDR_BUCKETS_1024]
The bit string.
Definition: bier_imp.h:58
#define DPO_PROTO_NUM
Definition: dpo.h:70
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:186
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:197
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:70
u8 * format_bier_hdr(u8 *s, va_list *ap)
Format a BIER header.
Definition: bier_types.c:205
bier_table_id_t bi_tbl
The BIER table into which to forward the post imposed packet.
Definition: bier_imp.h:63
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:232
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
dpo_id_t bi_dpo[FIB_PROTOCOL_IP_MAX]
The DPO contributed from the resolving BIER table.
Definition: bier_imp.h:45
void bier_imp_unlock(index_t bii)
Definition: bier_imp.c:110
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)
static void bier_hdr_init(bier_hdr_t *bier_hdr, bier_hdr_version_t version, bier_hdr_proto_id_t proto, bier_hdr_len_id_t len, bier_hdr_entropy_t entropy, bier_bp_t src)
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
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:516
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128