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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * bier_imposition : The BIER imposition object
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/specifid
24 #include <vnet/bier/bier_imp.h>
25 #include <vnet/bier/bier_table.h>
26 #include <vnet/bier/bier_hdr_inlines.h>
27 #include <vnet/fib/fib_node.h>
28 #include <vnet/mpls/mpls_types.h>
31 * The memory pool of all imp objects
33 bier_imp_t *bier_imp_pool;
36 * When constructing the BIER imp ID from an index and BSL, shift
39 #define BIER_IMP_ID_HLEN_SHIFT 24
42 bier_imp_lock_i (bier_imp_t *bi)
48 bier_imp_lock (index_t bii)
50 bier_imp_lock_i(bier_imp_get(bii));
54 bier_imp_get_index(bier_imp_t *bi)
56 return (bi - bier_imp_pool);
60 bier_imp_add_or_lock (const bier_table_id_t *bti,
62 const bier_bit_string_t *bs)
64 bier_imp_t *bi = NULL;
65 fib_protocol_t fproto;
68 pool_get_aligned(bier_imp_pool, bi, CLIB_CACHE_LINE_BYTES);
71 btii = bier_table_lock(bti);
74 * init the BIER header we will paint on in the data plane
76 bier_hdr_init(&bi->bi_hdr,
78 BIER_HDR_PROTO_INVALID, // filled in later
82 bier_hdr_hton(&bi->bi_hdr);
83 clib_memcpy(&bi->bi_bits, bs->bbs_buckets, bs->bbs_len);
88 * get and stack on the forwarding info from the table
90 FOR_EACH_FIB_IP_PROTOCOL(fproto)
93 * initialise to invalid first, lest we pick up garbage
96 dpo_id_t dpo = DPO_INVALID;
97 bi->bi_dpo[fproto] = dpo;
99 bier_table_contribute_forwarding(btii, &dpo);
100 dpo_stack(DPO_BIER_IMP, fib_proto_to_dpo(fproto),
106 return (bier_imp_get_index(bi));
110 bier_imp_unlock (index_t bii)
112 fib_protocol_t fproto;
115 if (INDEX_INVALID == bii)
120 bi = bier_imp_get(bii);
124 if (0 == bi->bi_locks)
126 bier_table_unlock(&bi->bi_tbl);
128 FOR_EACH_FIB_IP_PROTOCOL(fproto)
130 dpo_reset(&bi->bi_dpo[fproto]);
132 pool_put(bier_imp_pool, bi);
137 format_bier_imp (u8* s, va_list *args)
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);
144 bi = bier_imp_get(bii);
146 s = format(s, "bier-imp:[%d]: tbl:[%U] hdr:[%U]",
147 bier_imp_get_index(bi),
148 format_bier_table_id, &bi->bi_tbl,
149 format_bier_hdr, &bi->bi_hdr);
151 if (BIER_SHOW_DETAIL & flags)
153 bier_bit_string_t bbs;
157 bier_hdr_ntoh(©);
158 bier_bit_string_init(&bbs,
159 bier_hdr_get_len_id(©),
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);
174 bier_imp_contribute_forwarding (index_t bii,
178 dpo_set(dpo, DPO_BIER_IMP, proto, bii);
181 const static char* const bier_imp_ip4_nodes[] =
186 const static char* const bier_imp_ip6_nodes[] =
192 const static char* const * const bier_imp_nodes[DPO_PROTO_NUM] =
194 [DPO_PROTO_IP4] = bier_imp_ip4_nodes,
195 [DPO_PROTO_IP6] = bier_imp_ip6_nodes,
199 bier_imp_dpo_lock (dpo_id_t *dpo)
201 bier_imp_lock(dpo->dpoi_index);
205 bier_imp_dpo_unlock (dpo_id_t *dpo)
207 bier_imp_unlock(dpo->dpoi_index);
211 bier_imp_dpo_mem_show (void)
213 fib_show_memory_usage("BIER imposition",
214 pool_elts(bier_imp_pool),
215 pool_len(bier_imp_pool),
220 format_bier_imp_dpo (u8* s, va_list *ap)
222 index_t index = va_arg(*ap, index_t);
223 u32 indent = va_arg(*ap, u32);
225 s = format(s, "%U", format_bier_imp, index, indent, BIER_SHOW_DETAIL);
230 const static dpo_vft_t bier_imp_vft = {
231 .dv_lock = bier_imp_dpo_lock,
232 .dv_unlock = bier_imp_dpo_unlock,
233 .dv_format = format_bier_imp_dpo,
234 .dv_mem_show = bier_imp_dpo_mem_show,
238 bier_imp_db_module_init (vlib_main_t *vm)
240 dpo_register(DPO_BIER_IMP, &bier_imp_vft, bier_imp_nodes);
245 VLIB_INIT_FUNCTION (bier_imp_db_module_init);
247 static clib_error_t *
248 show_bier_imp (vlib_main_t * vm,
249 unformat_input_t * input,
250 vlib_cli_command_t * cmd)
257 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
258 if (unformat (input, "%d", &bii))
266 if (INDEX_INVALID == bii)
268 pool_foreach(bi, bier_imp_pool,
270 vlib_cli_output(vm, "%U", format_bier_imp,
271 bier_imp_get_index(bi),
278 if (pool_is_free_index(bier_imp_pool, bii))
280 vlib_cli_output(vm, "No such BIER imposition: %d", bii);
284 vlib_cli_output(vm, "%U", format_bier_imp, bii, 1,
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,