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", \
48 if (bier_test_do_debug) \
49 fformat(stderr, "PASS:%d: " _comment "\n", \
54 #define BIER_TEST(_cond, _comment, _args...) \
56 if (BIER_TEST_I(_cond, _comment, ##_args)) { \
58 ASSERT(!("FAIL: " _comment)); \
63 * A 'i'm not fussed is this is not efficient' store of test data
65 typedef struct test_main_t_ {
69 u32 hw_if_indicies[4];
73 vnet_hw_interface_t * hw[4];
76 static test_main_t test_main;
78 /* fake ethernet device class, distinct from "fake-ethX" */
79 static u8 * format_test_interface_name (u8 * s, va_list * args)
81 u32 dev_instance = va_arg (*args, u32);
82 return format (s, "test-eth%d", dev_instance);
85 static uword placeholder_interface_tx (vlib_main_t * vm,
86 vlib_node_runtime_t * node,
89 clib_warning ("you shouldn't be here, leaking buffers...");
90 return frame->n_vectors;
93 VNET_DEVICE_CLASS (test_interface_device_class,static) = {
94 .name = "Test interface",
95 .format_device_name = format_test_interface_name,
96 .tx_function = placeholder_interface_tx,
99 static u8 *hw_address;
102 bier_test_mk_intf (u32 ninterfaces)
104 clib_error_t * error = NULL;
105 test_main_t *tm = &test_main;
111 ASSERT(ninterfaces <= ARRAY_LEN(tm->hw_if_indicies));
116 vec_add1(hw_address, byte);
119 for (i = 0; i < ninterfaces; i++)
123 error = ethernet_register_interface(vnet_get_main(),
124 test_interface_device_class.index,
127 &tm->hw_if_indicies[i],
128 /* flag change */ 0);
130 error = vnet_hw_interface_set_flags(vnet_get_main(),
131 tm->hw_if_indicies[i],
132 VNET_HW_INTERFACE_FLAG_LINK_UP);
133 BIER_TEST((NULL == error), "ADD interface %d", i);
135 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
136 tm->hw_if_indicies[i]);
137 ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
138 ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
139 error = vnet_sw_interface_set_flags(vnet_get_main(),
140 tm->hw[i]->sw_if_index,
141 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
142 BIER_TEST((NULL == error), "UP interface %d", i);
145 * re-eval after the inevitable realloc
147 for (i = 0; i < ninterfaces; i++)
149 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
150 tm->hw_if_indicies[i]);
156 #define BIER_TEST_LB(_cond, _comment, _args...) \
158 if (BIER_TEST_I(_cond, _comment, ##_args)) { \
164 bier_test_validate_entry (index_t bei,
168 dpo_id_t dpo = DPO_INVALID;
169 const load_balance_t *lb;
173 va_start(ap, n_buckets);
176 bier_entry_contribute_forwarding(bei, &dpo);
178 res = BIER_TEST_I((DPO_LOAD_BALANCE == dpo.dpoi_type),
180 format_dpo_type, dpo.dpoi_type);
184 lb = load_balance_get(dpo.dpoi_index);
185 res = fib_test_validate_lb_v(lb, n_buckets, &ap);
195 bier_test_mpls_spf (void)
197 fib_node_index_t lfei, fei, bti;
204 lb_count = pool_elts(load_balance_pool);
206 #define N_BIER_ECMP_TABLES 16
210 * Add the BIER Main table
212 const bier_table_id_t bt_0_0_0_256 = {
215 .bti_hdr_len = BIER_HDR_LEN_256,
216 .bti_type = BIER_TABLE_MPLS_SPF,
217 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
220 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1600);
222 fib_test_lb_bucket_t l_o_bt[N_BIER_ECMP_TABLES];
223 bier_table_id_t bt_ecmp_0_0_0_256 = bt_0_0_0_256;
225 for (ii = 0; ii < N_BIER_ECMP_TABLES; ii++)
227 bt_ecmp_0_0_0_256.bti_ecmp = ii;
229 l_o_bt[ii].type = FT_LB_BIER_TABLE;
230 l_o_bt[ii].bier.table =
231 bier_table_ecmp_create_and_lock(&bt_ecmp_0_0_0_256);
233 const fib_prefix_t pfx_1600_neos = {
235 .fp_proto = FIB_PROTOCOL_MPLS,
237 .fp_eos = MPLS_NON_EOS,
238 .fp_payload_proto = DPO_PROTO_BIER,
240 const fib_prefix_t pfx_1600_eos = {
242 .fp_proto = FIB_PROTOCOL_MPLS,
245 .fp_payload_proto = DPO_PROTO_BIER,
248 mpls_fib_index = fib_table_find(FIB_PROTOCOL_MPLS,
249 MPLS_FIB_DEFAULT_TABLE_ID);
251 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_neos);
252 BIER_TEST(FIB_NODE_INDEX_INVALID == lfei, "1600/0 is not present");
254 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_eos);
255 BIER_TEST(!fib_test_validate_entry(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS,
273 "1600/1 LB stacks on BIER table %d", bti);
276 * modify the table's local label - keep the lock count accurate
278 const fib_prefix_t pfx_1601_eos = {
280 .fp_proto = FIB_PROTOCOL_MPLS,
283 .fp_payload_proto = DPO_PROTO_BIER,
285 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1601);
286 bier_table_unlock(&bt_0_0_0_256);
288 lfei = fib_table_lookup(mpls_fib_index, &pfx_1600_eos);
289 BIER_TEST(FIB_NODE_INDEX_INVALID == lfei, "1600/1 is deleted");
291 lfei = fib_table_lookup(mpls_fib_index, &pfx_1601_eos);
292 BIER_TEST(!fib_test_validate_entry(lfei, FIB_FORW_CHAIN_TYPE_MPLS_EOS,
310 "1601/1 LB stacks on BIER table %d", bti);
313 * add a route to the table. the via IP route does not exist.
315 const ip46_address_t nh_1_1_1_1 = {
317 .as_u32 = clib_host_to_net_u32(0x01010101),
320 fib_route_path_t *paths_1_1_1_1 = NULL, *input_paths_1_1_1_1;
321 fib_route_path_t path_1_1_1_1 = {
322 .frp_addr = nh_1_1_1_1,
323 .frp_sw_if_index = ~0,
325 fib_mpls_label_t fml_500 = {
328 vec_add1(path_1_1_1_1.frp_label_stack, fml_500);
329 vec_add1(paths_1_1_1_1, path_1_1_1_1);
330 const fib_prefix_t pfx_1_1_1_1_s_32 = {
331 .fp_addr = nh_1_1_1_1,
333 .fp_proto = FIB_PROTOCOL_IP4,
337 input_paths_1_1_1_1 = vec_dup(paths_1_1_1_1);
338 bier_table_route_path_add(&bt_0_0_0_256, 1, input_paths_1_1_1_1);
339 bei_1 = bier_table_lookup(bier_table_get(bti), 1);
341 BIER_TEST((INDEX_INVALID != bei_1), "BP:1 present");
344 * the newly created fmask should stack on the non-eos chain
345 * of the via-fib-entry
347 dpo_id_t neos_dpo_1_1_1_1 = DPO_INVALID;
348 bier_fmask_t *bfm_1_1_1_1;
349 index_t bfmi_1_1_1_1;
351 fei = fib_table_lookup_exact_match(0, &pfx_1_1_1_1_s_32);
352 fib_entry_contribute_forwarding(fei,
353 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
356 bfmi_1_1_1_1 = bier_fmask_db_find(bti, &path_1_1_1_1);
357 bfm_1_1_1_1 = bier_fmask_get(bfmi_1_1_1_1);
359 BIER_TEST(!dpo_cmp(drop_dpo_get(DPO_PROTO_MPLS),
360 &bfm_1_1_1_1->bfm_dpo),
361 "Fmask via 1.1.1.1 stacks on MPLS drop");
364 * The BIER entry should stack on the forwarding chain of the fmask
366 const fib_test_lb_bucket_t dpo_o_bfm_1_1_1_1 = {
367 .type = FT_LB_BIER_FMASK,
369 .fmask = bfmi_1_1_1_1,
372 dpo_id_t dpo_bei = DPO_INVALID;
373 bier_entry_contribute_forwarding(bei_1, &dpo_bei);
375 BIER_TEST(!dpo_cmp(&dpo_bei, drop_dpo_get(DPO_PROTO_BIER)),
376 "BP:1 stacks on bier drop");
379 * give 1.1.1.1/32 a path and hence a interesting n-eos chain
381 ip46_address_t nh_10_10_10_1 = {
383 .as_u32 = clib_host_to_net_u32(0x0a0a0a01),
386 adj_index_t ai_mpls_10_10_10_1;
387 ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
390 tm->hw[0]->sw_if_index);
392 fib_test_lb_bucket_t bucket_neos_99_via_10_10_10_1 = {
393 .type = FT_LB_LABEL_O_ADJ,
397 .adj = ai_mpls_10_10_10_1,
401 fib_mpls_label_t *out_lbl_99 = NULL, fml_99 = {
404 vec_add1(out_lbl_99, fml_99);
406 fei = fib_table_entry_update_one_path(0,
412 tm->hw[0]->sw_if_index,
413 ~0, // invalid fib index
416 FIB_ROUTE_PATH_FLAG_NONE);
417 fib_entry_contribute_forwarding(fei,
418 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
420 BIER_TEST(!fib_test_validate_lb(&neos_dpo_1_1_1_1, 1,
421 &bucket_neos_99_via_10_10_10_1),
422 "1.1.1.1/32 n-eos LB 1 buckets via: 99 + 10.10.10.1");
423 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_1,
424 &bfm_1_1_1_1->bfm_dpo),
425 "Fmask via 1.1.1.1 stacks on updated non-eos of 1.1.1.1/32");
426 bier_entry_contribute_forwarding(bei_1, &dpo_bei);
427 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
428 "BP:1 stacks on fmask 1.1.1.1");
431 * add another path to the via entry.
432 * this makes the via-entry instantiate a new load-balance with
433 * 2 buckets. and the back-walk to the BIER entry will need to
436 ip46_address_t nh_10_10_10_2 = {
438 .as_u32 = clib_host_to_net_u32(0x0a0a0a02),
441 adj_index_t ai_mpls_10_10_10_2;
443 ai_mpls_10_10_10_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
446 tm->hw[0]->sw_if_index);
448 fib_test_lb_bucket_t bucket_neos_100_via_10_10_10_2 = {
449 .type = FT_LB_LABEL_O_ADJ,
453 .adj = ai_mpls_10_10_10_2,
457 fib_mpls_label_t *out_lbl_100 = NULL, fml_100 = {
460 vec_add1(out_lbl_100, fml_100);
462 fei = fib_table_entry_path_add(0,
468 tm->hw[0]->sw_if_index,
469 ~0, // invalid fib index
472 FIB_ROUTE_PATH_FLAG_NONE);
474 fib_entry_contribute_forwarding(fei,
475 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
477 BIER_TEST(!fib_test_validate_lb(&neos_dpo_1_1_1_1, 2,
478 &bucket_neos_99_via_10_10_10_1,
479 &bucket_neos_100_via_10_10_10_2),
480 "1.1.1.1/32 n-eos LB 2 buckets "
481 "via: 99 + 10.10.10.1, "
482 "via: 100 + 10.10.10.2");
483 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_1,
484 &bfm_1_1_1_1->bfm_dpo),
485 "Fmask via 1.1.1.1 stacks on updated non-eos of 1.1.1.1/32");
488 * add another bier bit-position via the same next-hop
489 * since its the same next hop, the two bit-positions should link
494 input_paths_1_1_1_1 = vec_dup(paths_1_1_1_1);
495 bier_table_route_path_add(&bt_0_0_0_256, 2, input_paths_1_1_1_1);
496 bei_2 = bier_table_lookup(bier_table_get(bti), 2);
498 bier_entry_contribute_forwarding(bei_2, &dpo_bei);
499 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
500 "BP:2 stacks on fmask 1.1.1.1");
503 * now add a bit-position via a different next hop and expect to
504 * link via a different fmask
506 const ip46_address_t nh_1_1_1_2 = {
508 .as_u32 = clib_host_to_net_u32(0x01010102),
511 const fib_prefix_t pfx_1_1_1_2_s_32 = {
512 .fp_addr = nh_1_1_1_2,
514 .fp_proto = FIB_PROTOCOL_IP4,
516 fib_route_path_t *paths_1_1_1_2 = NULL, *input_paths_1_1_1_2, path_1_1_1_2 = {
517 .frp_addr = nh_1_1_1_2,
518 .frp_sw_if_index = ~0,
520 fib_mpls_label_t fml_501 = {
523 vec_add1(path_1_1_1_2.frp_label_stack, fml_501);
524 vec_add1(paths_1_1_1_2, path_1_1_1_2);
525 input_paths_1_1_1_2 = vec_dup(paths_1_1_1_2);
528 fib_mpls_label_t *out_lbl_101 = NULL, fml_101 = {
531 vec_add1(out_lbl_101, fml_101);
532 fei = fib_table_entry_path_add(0,
538 tm->hw[0]->sw_if_index,
539 ~0, // invalid fib index
542 FIB_ROUTE_PATH_FLAG_NONE);
543 bier_table_route_path_update(&bt_0_0_0_256, 3, input_paths_1_1_1_2);
544 bei_3 = bier_table_lookup(bier_table_get(bti), 3);
546 BIER_TEST((INDEX_INVALID != bei_3), "BP:3 present");
549 * the newly created fmask should stack on the non-eos chain
550 * of the via-fib-entry
552 dpo_id_t neos_dpo_1_1_1_2 = DPO_INVALID;
553 bier_fmask_t *bfm_1_1_1_2;
554 index_t bfmi_1_1_1_2;
556 fei = fib_table_lookup_exact_match(0, &pfx_1_1_1_2_s_32);
557 fib_entry_contribute_forwarding(fei,
558 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
561 bfmi_1_1_1_2 = bier_fmask_db_find(bti, &path_1_1_1_2);
562 bfm_1_1_1_2 = bier_fmask_get(bfmi_1_1_1_2);
564 BIER_TEST(!dpo_cmp(&neos_dpo_1_1_1_2,
565 &bfm_1_1_1_2->bfm_dpo),
566 "Fmask via 1.1.1.2 stacks on non-eos of 1.1.1.2/32");
569 * The BIER entry should stack on the forwarding chain of the fmask
571 const fib_test_lb_bucket_t dpo_o_bfm_1_1_1_2 = {
572 .type = FT_LB_BIER_FMASK,
574 .fmask = bfmi_1_1_1_2,
577 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
578 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_2),
579 "BP:2 stacks on fmask 1.1.1.2");
582 * Load-balance BP:3 over both next-hops
584 paths_1_1_1_1[0] = path_1_1_1_1;
585 input_paths_1_1_1_1 = vec_dup(paths_1_1_1_1);
586 bier_table_route_path_add(&bt_0_0_0_256, 3, input_paths_1_1_1_1);
588 BIER_TEST(!bier_test_validate_entry(bei_3, 2,
591 "BP:3 stacks on fmask 1.1.1.2 & 1.1.1.1");
594 * test that the ECMP choices for BP:3 have been spread over the
597 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
599 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
600 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
602 "fwd lookup for BP:3 ECMP:1 is 1.1.1.2");
605 * Withdraw one of the via FIB and thus bring down the fmask
606 * expect the bier-entry forwarding to remove this from the set
608 fib_table_entry_delete(0, &pfx_1_1_1_2_s_32, FIB_SOURCE_API);
610 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
611 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
612 "BP:3 stacks on fmask 1.1.1.1");
614 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
616 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
617 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
619 "fwd lookup for BP:3 ECMP:1 is 1.1.1.1");
625 vec_add1(out_lbl_101, fml_101);
626 fei = fib_table_entry_path_add(0,
632 tm->hw[0]->sw_if_index,
633 ~0, // invalid fib index
636 FIB_ROUTE_PATH_FLAG_NONE);
637 /* suspend so the update walk kicks int */
638 vlib_process_suspend(vlib_get_main(), 1e-5);
640 BIER_TEST(!bier_test_validate_entry(bei_3, 2,
643 "BP:3 stacks on fmask 1.1.1.2 & 1.1.1.1");
644 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
646 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
647 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
649 "fwd lookup for BP:3 ECMP:1 is 1.1.1.2");
652 * remove the original 1.1.1.2 fmask from BP:3
654 input_paths_1_1_1_2 = vec_dup(paths_1_1_1_2);
655 bier_table_route_path_remove(&bt_0_0_0_256, 3, input_paths_1_1_1_2);
656 bier_entry_contribute_forwarding(bei_3, &dpo_bei);
657 BIER_TEST((dpo_bei.dpoi_index == bfmi_1_1_1_1),
658 "BP:3 stacks on fmask 1.1.1.1");
661 * test that the ECMP choices for BP:3 have been updated
663 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[0].bier.table), 3) ==
665 "fwd lookup for BP:3 ECMP:0 is 1.1.1.1");
666 BIER_TEST((bier_table_fwd_lookup(bier_table_get(l_o_bt[1].bier.table), 3) ==
668 "fwd lookup for BP:3 ECMP:1 is 1.1.1.1");
671 * remove the routes added
673 input_paths_1_1_1_1 = vec_dup(paths_1_1_1_1);
674 bier_table_route_path_remove(&bt_0_0_0_256, 2, input_paths_1_1_1_1);
675 input_paths_1_1_1_2 = vec_dup(paths_1_1_1_2);
676 bier_table_route_path_remove(&bt_0_0_0_256, 3, input_paths_1_1_1_2);
677 input_paths_1_1_1_1 = vec_dup(paths_1_1_1_1);
678 bier_table_route_path_remove(&bt_0_0_0_256, 3, input_paths_1_1_1_1);
680 bier_table_route_delete(&bt_0_0_0_256, 1);
685 bier_table_unlock(&bt_0_0_0_256);
688 * test resources are freed
691 for (ii = 0; ii < N_BIER_ECMP_TABLES; ii++)
693 bier_table_ecmp_unlock(l_o_bt[ii].bier.table);
695 BIER_TEST(0 == pool_elts(bier_table_pool), "BIER table pool empty");
696 BIER_TEST(0 == pool_elts(bier_fmask_pool), "BIER fmask pool empty");
697 BIER_TEST(0 == pool_elts(bier_entry_pool), "BIER entry pool empty");
699 adj_unlock(ai_mpls_10_10_10_1);
700 adj_unlock(ai_mpls_10_10_10_2);
701 dpo_reset(&neos_dpo_1_1_1_1);
702 dpo_reset(&neos_dpo_1_1_1_2);
703 fib_table_entry_delete(0, &pfx_1_1_1_1_s_32, FIB_SOURCE_API);
704 fib_table_entry_delete(0, &pfx_1_1_1_2_s_32, FIB_SOURCE_API);
706 /* +1 to account for the one time alloc'd drop LB in the MPLS fibs */
707 BIER_TEST(lb_count+1 == pool_elts(load_balance_pool),
708 "Load-balance resources freed ");
709 BIER_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d",
712 vec_free(paths_1_1_1_1);
713 vec_free(paths_1_1_1_2);
714 vec_free(input_paths_1_1_1_1);
715 vec_free(input_paths_1_1_1_2);
721 bier_test_mpls_imp (void)
723 fib_node_index_t bii;
727 * Add the BIER Main table
729 const bier_table_id_t bt_0_0_0_256 = {
732 .bti_hdr_len = BIER_HDR_LEN_256,
733 .bti_type = BIER_TABLE_MPLS_SPF,
734 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
737 bier_table_add_or_lock(&bt_0_0_0_256, 1600);
740 * A bit-string for imp 1.
742 bier_bit_string_t bbs_256;
743 u8 buckets[BIER_HDR_BUCKETS_256];
744 clib_memset(buckets, 0x5, BIER_HDR_BUCKETS_256);
747 bier_bit_string_init(&bbs_256, BIER_HDR_LEN_256, buckets);
749 bii = bier_imp_add_or_lock(&bt_0_0_0_256, 1, &bbs_256);
752 * An mfib entry that resolves via the BIER imposition
754 const mfib_prefix_t pfx_1_1_1_1_c_239_1_1_1 = {
756 .fp_proto = FIB_PROTOCOL_IP4,
758 .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
761 .ip4.as_u32 = clib_host_to_net_u32(0x01010101),
764 fib_route_path_t path_via_bier_imp_1 = {
765 .frp_proto = DPO_PROTO_BIER,
768 .frp_flags = FIB_ROUTE_PATH_BIER_IMP,
769 .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
771 mfib_table_entry_path_update(0, // default table
772 &pfx_1_1_1_1_c_239_1_1_1 ,
774 &path_via_bier_imp_1);
775 mfib_table_entry_delete(0,
776 &pfx_1_1_1_1_c_239_1_1_1 ,
779 bier_imp_unlock(bii);
780 bier_table_unlock(&bt_0_0_0_256);
782 BIER_TEST(0 == pool_elts(bier_imp_pool),
783 "BIER imposition resources freed ");
784 BIER_TEST(0 == pool_elts(bier_table_pool),
785 "BIER table resources freed ");
791 bier_test_mpls_disp (void)
794 * Add the BIER Main table
796 const bier_table_id_t bt_0_0_0_256 = {
799 .bti_hdr_len = BIER_HDR_LEN_256,
800 .bti_type = BIER_TABLE_MPLS_SPF,
801 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
807 bti = bier_table_add_or_lock(&bt_0_0_0_256, 1600);
810 * Add a BIER disposition table
812 const u32 bier_disp_tbl_id = 1;
815 bdti1 = bier_disp_table_add_or_lock(bier_disp_tbl_id);
818 * add a bit-position in the table that resolves via
819 * DISP table, i.e. a for-us bit-position
821 fib_route_path_t *paths_via_disp = NULL, path_via_disp = {
822 // .frp_addr = all-zeros
823 .frp_proto = DPO_PROTO_BIER,
824 .frp_sw_if_index = ~0,
826 vec_add1(paths_via_disp, path_via_disp);
828 bier_table_route_path_add(&bt_0_0_0_256, 3, paths_via_disp);
831 * the fmask should stack on the BIER disp table
833 bier_fmask_t *bfm_0_0_0_0;
834 index_t bfmi_0_0_0_0;
835 dpo_id_t dpo_disp_tbl_1 = DPO_INVALID;
837 bier_disp_table_contribute_forwarding(bdti1, &dpo_disp_tbl_1);
839 bfmi_0_0_0_0 = bier_fmask_db_find(bti, &path_via_disp);
840 bfm_0_0_0_0 = bier_fmask_get(bfmi_0_0_0_0);
842 BIER_TEST(!dpo_cmp(&dpo_disp_tbl_1, &bfm_0_0_0_0->bfm_dpo),
843 "Fmask via 0.0.0.0 stacks on BIER disp table 1");
846 * and a deag entry into the disposition table
848 fib_route_path_t *rpaths = NULL, path_via_mfib = {
849 .frp_proto = DPO_PROTO_IP4,
850 .frp_addr = zero_addr,
851 .frp_fib_index = 0, // default MFIB table
852 .frp_rpf_id = 9, // some non-zero value
853 .frp_flags = FIB_ROUTE_PATH_RPF_ID,
855 bier_hdr_src_id_t src = 99;
856 vec_add1(rpaths, path_via_mfib);
857 bier_disp_table_entry_path_add(bier_disp_tbl_id, src,
858 BIER_HDR_PROTO_IPV4, rpaths);
860 /* which should stack on a lookup in the mfib table */
861 const dpo_id_t *dpo_disp_entry_v4;
862 bier_disp_entry_t *bde_99;
865 bdei = bier_disp_table_lookup(bdti1, clib_host_to_net_u16(src));
866 bde_99 = bier_disp_entry_get(bdei);
867 dpo_disp_entry_v4 = &bde_99->bde_fwd[BIER_HDR_PROTO_IPV4].bde_dpo;
869 lookup_dpo_t *lkd = lookup_dpo_get(dpo_disp_entry_v4->dpoi_index);
871 BIER_TEST((bdti1 == lkd->lkd_fib_index),
872 "disp is deag in %d %U",
874 format_dpo_id, dpo_disp_entry_v4, 0);
875 BIER_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input),
876 "disp is destination deag in %d %U",
878 format_dpo_id, dpo_disp_entry_v4, 0);
879 BIER_TEST((LOOKUP_MULTICAST == lkd->lkd_cast),
880 "disp is multicast deag in %d %U",
882 format_dpo_id, dpo_disp_entry_v4, 0);
887 dpo_reset(&dpo_disp_tbl_1);
889 bier_disp_table_entry_path_remove(bier_disp_tbl_id, src,
890 BIER_HDR_PROTO_IPV4, rpaths);
891 bier_table_route_path_remove(&bt_0_0_0_256, 3, paths_via_disp);
893 bier_disp_table_unlock_w_table_id(bier_disp_tbl_id);
895 bier_table_unlock(&bt_0_0_0_256);
897 BIER_TEST(0 == pool_elts(bier_fmask_pool),
898 "BIER fmask resources freed ");
899 BIER_TEST(0 == pool_elts(bier_table_pool),
900 "BIER table resources freed ");
901 BIER_TEST(0 == pool_elts(bier_disp_table_pool),
902 "BIER Disposition table resources freed ");
903 BIER_TEST(0 == pool_elts(bier_disp_entry_pool),
904 "BIER Disposition entry resources freed ");
906 vec_free(paths_via_disp);
910 static clib_error_t *
911 bier_test (vlib_main_t * vm,
912 unformat_input_t * input,
913 vlib_cli_command_t * cmd_arg)
917 res += bier_test_mk_intf(4);
919 if (unformat (input, "debug"))
921 bier_test_do_debug = 1;
924 if (unformat (input, "mid"))
925 res += bier_test_mpls_spf();
926 else if (unformat (input, "head"))
927 res += bier_test_mpls_imp();
928 else if (unformat (input, "tail"))
929 res += bier_test_mpls_disp();
932 res += bier_test_mpls_spf();
933 res += bier_test_mpls_imp();
934 res += bier_test_mpls_disp();
939 return clib_error_return(0, "BIER Unit Test Failed");
947 VLIB_CLI_COMMAND (test_route_command, static) = {
949 .short_help = "bier unit tests",
950 .function = bier_test,
954 bier_test_init (vlib_main_t *vm)
959 VLIB_INIT_FUNCTION (bier_test_init);