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:
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.
17 #include <vnet/mpls/mpls.h>
18 #include <vnet/bier/bier_table.h>
19 #include <vnet/bier/bier_entry.h>
20 #include <vnet/bier/bier_fmask.h>
21 #include <vnet/bier/bier_bit_string.h>
22 #include <vnet/bier/bier_imp.h>
23 #include <vnet/bier/bier_disp_table.h>
24 #include <vnet/bier/bier_disp_entry.h>
25 #include <vnet/fib/fib_entry.h>
26 #include <vnet/fib/fib_table.h>
27 #include <vnet/fib/mpls_fib.h>
28 #include <vnet/dpo/load_balance.h>
29 #include <vnet/dpo/drop_dpo.h>
30 #include <vnet/dpo/lookup_dpo.h>
31 #include <vnet/mfib/mfib_table.h>
33 #include <vnet/fib/fib_test.h>
36 * Add debugs for passing tests
38 static int bier_test_do_debug;
40 #define BIER_TEST_I(_cond, _comment, _args...) \
42 int _evald = (_cond); \
44 fformat(stderr, "FAIL:%d: " _comment "\n", \
47 if (bier_test_do_debug) \
48 fformat(stderr, "PASS:%d: " _comment "\n", \
53 #define BIER_TEST(_cond, _comment, _args...) \
55 if (!BIER_TEST_I(_cond, _comment, ##_args)) { \
57 ASSERT(!("FAIL: " _comment)); \
62 * A 'i'm not fussed is this is not efficient' store of test data
64 typedef struct test_main_t_ {
68 u32 hw_if_indicies[4];
72 vnet_hw_interface_t * hw[4];
75 static test_main_t test_main;
77 /* fake ethernet device class, distinct from "fake-ethX" */
78 static u8 * format_test_interface_name (u8 * s, va_list * args)
80 u32 dev_instance = va_arg (*args, u32);
81 return format (s, "test-eth%d", dev_instance);
84 static uword dummy_interface_tx (vlib_main_t * vm,
85 vlib_node_runtime_t * node,
88 clib_warning ("you shouldn't be here, leaking buffers...");
89 return frame->n_vectors;
92 VNET_DEVICE_CLASS (test_interface_device_class,static) = {
93 .name = "Test interface",
94 .format_device_name = format_test_interface_name,
95 .tx_function = dummy_interface_tx,
98 static u8 *hw_address;
101 bier_test_mk_intf (u32 ninterfaces)
103 clib_error_t * error = NULL;
104 test_main_t *tm = &test_main;
108 ASSERT(ninterfaces <= ARRAY_LEN(tm->hw_if_indicies));
113 vec_add1(hw_address, byte);
116 for (i = 0; i < ninterfaces; i++)
120 error = ethernet_register_interface(vnet_get_main(),
121 test_interface_device_class.index,
124 &tm->hw_if_indicies[i],
125 /* flag change */ 0);
127 BIER_TEST((NULL == error), "ADD interface %d", i);
129 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
130 tm->hw_if_indicies[i]);
131 vec_validate (ip4_main.fib_index_by_sw_if_index, tm->hw[i]->sw_if_index);
132 vec_validate (ip6_main.fib_index_by_sw_if_index, tm->hw[i]->sw_if_index);
133 ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
134 ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
135 error = vnet_sw_interface_set_flags(vnet_get_main(),
136 tm->hw[i]->sw_if_index,
137 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
138 BIER_TEST((NULL == error), "UP interface %d", i);
141 * re-eval after the inevitable realloc
143 for (i = 0; i < ninterfaces; i++)
145 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
146 tm->hw_if_indicies[i]);
152 #define BIER_TEST_LB(_cond, _comment, _args...) \
154 if (!BIER_TEST_I(_cond, _comment, ##_args)) { \
160 bier_test_validate_entry (index_t bei,
164 dpo_id_t dpo = DPO_INVALID;
165 const load_balance_t *lb;
169 va_start(ap, n_buckets);
171 bier_entry_contribute_forwarding(bei, &dpo);
173 BIER_TEST_LB((DPO_LOAD_BALANCE == dpo.dpoi_type),
175 format_dpo_type, dpo.dpoi_type);
177 lb = load_balance_get(dpo.dpoi_index);
178 res = fib_test_validate_lb_v(lb, n_buckets, &ap);
188 bier_test_mpls_spf (void)
190 fib_node_index_t lfei, fei, bti;
195 lb_count = pool_elts(load_balance_pool);
197 #define N_BIER_ECMP_TABLES 16
201 * Add the BIER Main table
203 const bier_table_id_t bt_0_0_0_256 = {
206 .bti_hdr_len = BIER_HDR_LEN_256,
207 .bti_type = BIER_TABLE_MPLS_SPF,
208 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
211 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1600);
213 fib_test_lb_bucket_t l_o_bt[N_BIER_ECMP_TABLES];
214 bier_table_id_t bt_ecmp_0_0_0_256 = bt_0_0_0_256;
216 for (ii = 0; ii < N_BIER_ECMP_TABLES; ii++)
218 bt_ecmp_0_0_0_256.bti_ecmp = ii;
220 l_o_bt[ii].type = FT_LB_BIER_TABLE;
221 l_o_bt[ii].bier.table =
222 bier_table_ecmp_create_and_lock(&bt_ecmp_0_0_0_256);
224 const fib_prefix_t pfx_1600_neos = {
226 .fp_proto = FIB_PROTOCOL_MPLS,
228 .fp_eos = MPLS_NON_EOS,
229 .fp_payload_proto = DPO_PROTO_BIER,
231 const fib_prefix_t pfx_1600_eos = {
233 .fp_proto = FIB_PROTOCOL_MPLS,
236 .fp_payload_proto = DPO_PROTO_BIER,
239 mpls_fib_index = fib_table_find(FIB_PROTOCOL_MPLS,
240 MPLS_FIB_DEFAULT_TABLE_ID);
242 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_neos);
243 BIER_TEST(FIB_NODE_INDEX_INVALID == lfei, "1600/0 is not present");
245 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_eos);
246 BIER_TEST(fib_test_validate_entry(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS,
264 "1600/1 LB stacks on BIER table %d", bti);
267 * modify the table's local label - keep the lock count accurate
269 const fib_prefix_t pfx_1601_eos = {
271 .fp_proto = FIB_PROTOCOL_MPLS,
274 .fp_payload_proto = DPO_PROTO_BIER,
276 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1601);
277 bier_table_unlock(&bt_0_0_0_256);
279 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_eos);
280 BIER_TEST(FIB_NODE_INDEX_INVALID == lfei, "1600/1 is deleted");
282 lfei = fib_table_lookup(mpls_fib_index, &pfx_1601_eos);
283 BIER_TEST(fib_test_validate_entry(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS,
301 "1601/1 LB stacks on BIER table %d", bti);
304 * add a route to the table. the via IP route does not exist.
306 const ip46_address_t nh_1_1_1_1 = {
308 .as_u32 = clib_host_to_net_u32(0x01010101),
311 fib_route_path_t *paths_1_1_1_1 = NULL;
312 fib_route_path_t path_1_1_1_1 = {
313 .frp_addr = nh_1_1_1_1,
314 .frp_bier_fib_index = bti,
315 .frp_sw_if_index = ~0,
317 vec_add1(path_1_1_1_1.frp_label_stack, 500);
318 vec_add1(paths_1_1_1_1, path_1_1_1_1);
319 const fib_prefix_t pfx_1_1_1_1_s_32 = {
320 .fp_addr = nh_1_1_1_1,
322 .fp_proto = FIB_PROTOCOL_IP4,
326 bier_table_route_add(&bt_0_0_0_256, 1, paths_1_1_1_1);
327 bei_1 = bier_table_lookup(bier_table_get(bti), 1);
329 BIER_TEST((INDEX_INVALID != bei_1), "BP:1 present");
332 * the newly created fmask should stack on the non-eos chain
333 * of the via-fib-entry
335 dpo_id_t neos_dpo_1_1_1_1 = DPO_INVALID;
336 bier_fmask_t *bfm_1_1_1_1;
337 index_t bfmi_1_1_1_1;
339 fei = fib_table_lookup_exact_match(0, &pfx_1_1_1_1_s_32);
340 fib_entry_contribute_forwarding(fei,
341 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
344 bfmi_1_1_1_1 = bier_fmask_db_find(bti, &path_1_1_1_1);
345 bfm_1_1_1_1 = bier_fmask_get(bfmi_1_1_1_1);
347 BIER_TEST(!dpo_cmp(drop_dpo_get(DPO_PROTO_MPLS),
348 &bfm_1_1_1_1->bfm_dpo),
349 "Fmask via 1.1.1.1 stacks on MPLS drop");
352 * The BIER entry should stack on the forwarding chain of the fmask
354 const fib_test_lb_bucket_t dpo_o_bfm_1_1_1_1 = {
355 .type = FT_LB_BIER_FMASK,
357 .fmask = bfmi_1_1_1_1,
360 dpo_id_t dpo_bei = DPO_INVALID;
361 bier_entry_contribute_forwarding(bei_1, &dpo_bei);
363 BIER_TEST(!dpo_cmp(&dpo_bei, drop_dpo_get(DPO_PROTO_BIER)),
364 "BP:1 stacks on bier drop");
367 * give 1.1.1.1/32 a path and hence a interesting n-eos chain
369 ip46_address_t nh_10_10_10_1 = {
371 .as_u32 = clib_host_to_net_u32(0x0a0a0a01),
374 adj_index_t ai_mpls_10_10_10_1;
375 ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
378 tm->hw[0]->sw_if_index);
380 fib_test_lb_bucket_t bucket_neos_99_via_10_10_10_1 = {
381 .type = FT_LB_LABEL_O_ADJ,
385 .adj = ai_mpls_10_10_10_1,
389 mpls_label_t *out_lbl_99 = NULL;
390 vec_add1(out_lbl_99, 99);
392 fei = fib_table_entry_update_one_path(0,
398 tm->hw[0]->sw_if_index,
399 ~0, // invalid fib index
402 FIB_ROUTE_PATH_FLAG_NONE);
403 fib_entry_contribute_forwarding(fei,
404 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
406 BIER_TEST(fib_test_validate_lb(&neos_dpo_1_1_1_1, 1,
407 &bucket_neos_99_via_10_10_10_1),
408 "1.1.1.1/32 n-eos LB 1 buckets via: 99 + 10.10.10.1");
409 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_1,
410 &bfm_1_1_1_1->bfm_dpo),
411 "Fmask via 1.1.1.1 stacks on updated non-eos of 1.1.1.1/32");
412 bier_entry_contribute_forwarding(bei_1, &dpo_bei);
413 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
414 "BP:1 stacks on fmask 1.1.1.1");
417 * add another path to the via entry.
418 * this makes the via-entry instantiate a new load-balance with
419 * 2 buckets. and the back-walk to the BIER entry will need to
422 ip46_address_t nh_10_10_10_2 = {
424 .as_u32 = clib_host_to_net_u32(0x0a0a0a02),
427 adj_index_t ai_mpls_10_10_10_2;
429 ai_mpls_10_10_10_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
432 tm->hw[0]->sw_if_index);
434 fib_test_lb_bucket_t bucket_neos_100_via_10_10_10_2 = {
435 .type = FT_LB_LABEL_O_ADJ,
439 .adj = ai_mpls_10_10_10_2,
443 mpls_label_t *out_lbl_100 = NULL;
444 vec_add1(out_lbl_100, 100);
446 fei = fib_table_entry_path_add(0,
452 tm->hw[0]->sw_if_index,
453 ~0, // invalid fib index
456 FIB_ROUTE_PATH_FLAG_NONE);
458 fib_entry_contribute_forwarding(fei,
459 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
461 BIER_TEST(fib_test_validate_lb(&neos_dpo_1_1_1_1, 2,
462 &bucket_neos_99_via_10_10_10_1,
463 &bucket_neos_100_via_10_10_10_2),
464 "1.1.1.1/32 n-eos LB 2 buckets "
465 "via: 99 + 10.10.10.1, "
466 "via: 100 + 10.10.10.2");
467 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_1,
468 &bfm_1_1_1_1->bfm_dpo),
469 "Fmask via 1.1.1.1 stacks on updated non-eos of 1.1.1.1/32");
472 * add another bier bit-position via the same next-hop
473 * since its the same next hop, the two bit-positions should link
478 bier_table_route_add(&bt_0_0_0_256, 2, paths_1_1_1_1);
479 bei_2 = bier_table_lookup(bier_table_get(bti), 2);
481 bier_entry_contribute_forwarding(bei_2, &dpo_bei);
482 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
483 "BP:2 stacks on fmask 1.1.1.1");
486 * now add a bit-position via a different next hop and expect to
487 * link via a different fmask
489 const ip46_address_t nh_1_1_1_2 = {
491 .as_u32 = clib_host_to_net_u32(0x01010102),
494 const fib_prefix_t pfx_1_1_1_2_s_32 = {
495 .fp_addr = nh_1_1_1_2,
497 .fp_proto = FIB_PROTOCOL_IP4,
499 fib_route_path_t *paths_1_1_1_2 = NULL, path_1_1_1_2 = {
500 .frp_addr = nh_1_1_1_2,
501 .frp_bier_fib_index = bti,
502 .frp_sw_if_index = ~0,
504 vec_add1(path_1_1_1_2.frp_label_stack, 501);
505 vec_add1(paths_1_1_1_2, path_1_1_1_2);
508 mpls_label_t *out_lbl_101 = NULL;
509 vec_add1(out_lbl_101, 101);
510 fei = fib_table_entry_path_add(0,
516 tm->hw[0]->sw_if_index,
517 ~0, // invalid fib index
520 FIB_ROUTE_PATH_FLAG_NONE);
521 bier_table_route_add(&bt_0_0_0_256, 3, paths_1_1_1_2);
522 bei_3 = bier_table_lookup(bier_table_get(bti), 3);
524 BIER_TEST((INDEX_INVALID != bei_3), "BP:3 present");
527 * the newly created fmask should stack on the non-eos chain
528 * of the via-fib-entry
530 dpo_id_t neos_dpo_1_1_1_2 = DPO_INVALID;
531 bier_fmask_t *bfm_1_1_1_2;
532 index_t bfmi_1_1_1_2;
534 fei = fib_table_lookup_exact_match(0, &pfx_1_1_1_2_s_32);
535 fib_entry_contribute_forwarding(fei,
536 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
539 bfmi_1_1_1_2 = bier_fmask_db_find(bti, &path_1_1_1_2);
540 bfm_1_1_1_2 = bier_fmask_get(bfmi_1_1_1_2);
542 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_2,
543 &bfm_1_1_1_2->bfm_dpo),
544 "Fmask via 1.1.1.2 stacks on non-eos of 1.1.1.2/32");
547 * The BIER entry should stack on the forwarding chain of the fmask
549 const fib_test_lb_bucket_t dpo_o_bfm_1_1_1_2 = {
550 .type = FT_LB_BIER_FMASK,
552 .fmask = bfmi_1_1_1_2,
555 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
556 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_2),
557 "BP:2 stacks on fmask 1.1.1.2");
560 * Load-balance BP:3 over both next-hops
562 paths_1_1_1_1[0] = path_1_1_1_1;
563 bier_table_route_add(&bt_0_0_0_256, 3, paths_1_1_1_1);
565 BIER_TEST(bier_test_validate_entry(bei_3, 2,
568 "BP:3 stacks on fmask 1.1.1.2 & 1.1.1.1");
571 * test that the ECMP choices for BP:3 have been spread over the
574 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
576 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
577 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
579 "fwd lookup for BP:3 ECMP:1 is 1.1.1.2");
582 * Withdraw one of the via FIB and thus bring down the fmask
583 * expect the bier-entry forwarding to remove this from the set
585 fib_table_entry_delete(0, &pfx_1_1_1_2_s_32, FIB_SOURCE_API);
587 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
588 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
589 "BP:3 stacks on fmask 1.1.1.1");
591 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
593 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
594 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
596 "fwd lookup for BP:3 ECMP:1 is 1.1.1.1");
602 vec_add1(out_lbl_101, 101);
603 fei = fib_table_entry_path_add(0,
609 tm->hw[0]->sw_if_index,
610 ~0, // invalid fib index
613 FIB_ROUTE_PATH_FLAG_NONE);
614 /* suspend so the update walk kicks int */
615 vlib_process_suspend(vlib_get_main(), 1e-5);
617 BIER_TEST(bier_test_validate_entry(bei_3, 2,
620 "BP:3 stacks on fmask 1.1.1.2 & 1.1.1.1");
621 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
623 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
624 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
626 "fwd lookup for BP:3 ECMP:1 is 1.1.1.2");
629 * remove the original 1.1.1.2 fmask from BP:3
631 bier_table_route_remove(&bt_0_0_0_256, 3, paths_1_1_1_2);
632 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
633 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
634 "BP:3 stacks on fmask 1.1.1.1");
637 * test that the ECMP choices for BP:3 have been updated
639 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
641 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
642 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
644 "fwd lookup for BP:3 ECMP:1 is 1.1.1.1");
647 * remove the routes added
649 bier_table_route_remove(&bt_0_0_0_256, 2, paths_1_1_1_1);
650 bier_table_route_remove(&bt_0_0_0_256, 3, paths_1_1_1_2);
651 bier_table_route_remove(&bt_0_0_0_256, 3, paths_1_1_1_1);
652 bier_table_route_remove(&bt_0_0_0_256, 1, paths_1_1_1_1);
657 bier_table_unlock(&bt_0_0_0_256);
660 * test resources are freed
663 for (ii = 0; ii < N_BIER_ECMP_TABLES; ii++)
665 bier_table_ecmp_unlock(l_o_bt[ii].bier.table);
667 BIER_TEST(0 == pool_elts(bier_table_pool), "BIER table pool empty");
668 BIER_TEST(0 == pool_elts(bier_fmask_pool), "BIER fmask pool empty");
669 BIER_TEST(0 == pool_elts(bier_entry_pool), "BIER entry pool empty");
671 adj_unlock(ai_mpls_10_10_10_1);
672 adj_unlock(ai_mpls_10_10_10_2);
673 dpo_reset(&neos_dpo_1_1_1_1);
674 dpo_reset(&neos_dpo_1_1_1_2);
675 fib_table_entry_delete(0, &pfx_1_1_1_1_s_32, FIB_SOURCE_API);
676 fib_table_entry_delete(0, &pfx_1_1_1_2_s_32, FIB_SOURCE_API);
678 /* +1 to account for the one time alloc'd drop LB in the MPLS fibs */
679 BIER_TEST(lb_count+1 == pool_elts(load_balance_pool),
680 "Load-balance resources freed ");
681 BIER_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d",
684 vec_free(paths_1_1_1_1);
685 vec_free(paths_1_1_1_2);
691 bier_test_mpls_imp (void)
693 fib_node_index_t bii;
694 /* test_main_t *tm; */
696 /* tm = &test_main; */
699 * Add the BIER Main table
701 const bier_table_id_t bt_0_0_0_256 = {
704 .bti_hdr_len = BIER_HDR_LEN_256,
705 .bti_type = BIER_TABLE_MPLS_SPF,
706 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
709 bier_table_add_or_lock(&bt_0_0_0_256, 1600);
712 * A bit-string for imp 1.
714 bier_bit_string_t bbs_256;
715 u8 buckets[BIER_HDR_BUCKETS_256];
716 memset(buckets, 0x5, BIER_HDR_BUCKETS_256);
718 bier_bit_string_init(&bbs_256, BIER_HDR_LEN_256, buckets);
720 bii = bier_imp_add_or_lock(&bt_0_0_0_256, 1, &bbs_256);
723 * An mfib entry that resolves via the BIER imposition
725 const mfib_prefix_t pfx_1_1_1_1_c_239_1_1_1 = {
727 .fp_proto = FIB_PROTOCOL_IP4,
729 .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
732 .ip4.as_u32 = clib_host_to_net_u32(0x01010101),
735 fib_route_path_t path_via_bier_imp_1 = {
736 .frp_proto = DPO_PROTO_BIER,
739 .frp_flags = FIB_ROUTE_PATH_BIER_IMP,
741 mfib_table_entry_path_update(0, // default table
742 &pfx_1_1_1_1_c_239_1_1_1 ,
744 &path_via_bier_imp_1,
745 MFIB_ITF_FLAG_FORWARD);
746 mfib_table_entry_delete(0,
747 &pfx_1_1_1_1_c_239_1_1_1 ,
750 bier_imp_unlock(bii);
751 bier_table_unlock(&bt_0_0_0_256);
753 BIER_TEST(0 == pool_elts(bier_imp_pool),
754 "BIER imposition resources freed ");
755 BIER_TEST(0 == pool_elts(bier_table_pool),
756 "BIER table resources freed ");
762 bier_test_mpls_disp (void)
765 * Add the BIER Main table
767 const bier_table_id_t bt_0_0_0_256 = {
770 .bti_hdr_len = BIER_HDR_LEN_256,
771 .bti_type = BIER_TABLE_MPLS_SPF,
772 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
776 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1600);
779 * Add a BIER dispoition table
781 const u32 bier_disp_tbl_id = 1;
784 bdti1 = bier_disp_table_add_or_lock(bier_disp_tbl_id);
787 * add a bit-poistion in the table that resolves via
788 * DISP table, i.e. a for-us bit-position
790 fib_route_path_t *paths_via_disp = NULL, path_via_disp = {
791 // .frp_addr = all-zeros
792 .frp_proto = DPO_PROTO_BIER,
793 .frp_bier_fib_index = bdti1,
794 .frp_sw_if_index = ~0,
796 vec_add1(paths_via_disp, path_via_disp);
798 bier_table_route_add(&bt_0_0_0_256, 3, paths_via_disp);
801 * the fmask should stack on the BIER disp table
803 bier_fmask_t *bfm_0_0_0_0;
804 index_t bfmi_0_0_0_0;
805 dpo_id_t dpo_disp_tbl_1 = DPO_INVALID;
807 bier_disp_table_contribute_forwarding(bdti1, &dpo_disp_tbl_1);
809 bfmi_0_0_0_0 = bier_fmask_db_find(bti, &path_via_disp);
810 bfm_0_0_0_0 = bier_fmask_get(bfmi_0_0_0_0);
812 BIER_TEST(!dpo_cmp(&dpo_disp_tbl_1, &bfm_0_0_0_0->bfm_dpo),
813 "Fmask via 0.0.0.0 stacks on BIER disp table 1");
816 * and a deag entry into the disposition table
818 fib_route_path_t *rpaths = NULL, path_via_mfib = {
819 .frp_proto = DPO_PROTO_IP4,
820 .frp_addr = zero_addr,
821 .frp_fib_index = 0, // default MFIB table
822 .frp_rpf_id = 9, // some non-zero value
823 .frp_flags = FIB_ROUTE_PATH_RPF_ID,
825 bier_hdr_src_id_t src = 99;
826 vec_add1(rpaths, path_via_mfib);
827 bier_disp_table_entry_path_add(bier_disp_tbl_id, src,
828 BIER_HDR_PROTO_IPV4, rpaths);
830 /* which should stack on a lookup in the mfib table */
831 const dpo_id_t *dpo_disp_entry_v4;
832 bier_disp_entry_t *bde_99;
835 bdei = bier_disp_table_lookup(bdti1, clib_host_to_net_u16(src));
836 bde_99 = bier_disp_entry_get(bdei);
837 dpo_disp_entry_v4 = &bde_99->bde_fwd[BIER_HDR_PROTO_IPV4].bde_dpo;
839 lookup_dpo_t *lkd = lookup_dpo_get(dpo_disp_entry_v4->dpoi_index);
841 BIER_TEST((bdti1 == lkd->lkd_fib_index),
842 "disp is deag in %d %U",
844 format_dpo_id, dpo_disp_entry_v4, 0);
845 BIER_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input),
846 "disp is destination deag in %d %U",
848 format_dpo_id, dpo_disp_entry_v4, 0);
849 BIER_TEST((LOOKUP_MULTICAST == lkd->lkd_cast),
850 "disp is multicast deag in %d %U",
852 format_dpo_id, dpo_disp_entry_v4, 0);
857 dpo_reset(&dpo_disp_tbl_1);
859 bier_disp_table_entry_path_remove(bier_disp_tbl_id, src,
860 BIER_HDR_PROTO_IPV4, rpaths);
861 bier_table_route_remove(&bt_0_0_0_256, 3, paths_via_disp);
863 bier_disp_table_unlock_w_table_id(bier_disp_tbl_id);
865 bier_table_unlock(&bt_0_0_0_256);
867 BIER_TEST(0 == pool_elts(bier_fmask_pool),
868 "BIER fmask resources freed ");
869 BIER_TEST(0 == pool_elts(bier_table_pool),
870 "BIER table resources freed ");
871 BIER_TEST(0 == pool_elts(bier_disp_table_pool),
872 "BIER Disposition table resources freed ");
873 BIER_TEST(0 == pool_elts(bier_disp_entry_pool),
874 "BIER Disposition entry resources freed ");
876 vec_free(paths_via_disp);
880 static clib_error_t *
881 bier_test (vlib_main_t * vm,
882 unformat_input_t * input,
883 vlib_cli_command_t * cmd_arg)
887 res += bier_test_mk_intf(4);
889 if (unformat (input, "debug"))
891 bier_test_do_debug = 1;
894 if (unformat (input, "mid"))
895 res += bier_test_mpls_spf();
896 else if (unformat (input, "head"))
897 res += bier_test_mpls_imp();
898 else if (unformat (input, "tail"))
899 res += bier_test_mpls_disp();
902 res += bier_test_mpls_spf();
903 res += bier_test_mpls_imp();
904 res += bier_test_mpls_disp();
909 return clib_error_return(0, "BIER Unit Test Failed");
917 VLIB_CLI_COMMAND (test_route_command, static) = {
919 .short_help = "bier unit tests",
920 .function = bier_test,
924 bier_test_init (vlib_main_t *vm)
929 VLIB_INIT_FUNCTION (bier_test_init);