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.
16 #include <vnet/mpls/mpls_types.h>
18 #include <vnet/mfib/mfib_table.h>
19 #include <vnet/mfib/mfib_entry.h>
20 #include <vnet/mfib/mfib_signal.h>
21 #include <vnet/mfib/ip6_mfib.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/fib_test.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vnet/fib/mpls_fib.h>
27 #include <vnet/dpo/replicate_dpo.h>
28 #include <vnet/adj/adj_mcast.h>
30 #define MFIB_TEST_I(_cond, _comment, _args...) \
32 int _evald = (_cond); \
34 fformat(stderr, "FAIL:%d: " _comment "\n", \
38 fformat(stderr, "PASS:%d: " _comment "\n", \
43 #define MFIB_TEST(_cond, _comment, _args...) \
45 if (MFIB_TEST_I(_cond, _comment, ##_args)) { \
47 ASSERT(!("FAIL: " _comment)); \
50 #define MFIB_TEST_NS(_cond) \
52 if (MFIB_TEST_I(_cond, "")) { \
54 ASSERT(!("FAIL: ")); \
59 * A 'i'm not fussed is this is not efficient' store of test data
61 typedef struct test_main_t_ {
65 u32 hw_if_indicies[4];
69 vnet_hw_interface_t * hw[4];
72 static test_main_t test_main;
74 /* fake ethernet device class, distinct from "fake-ethX" */
75 static u8 * format_test_interface_name (u8 * s, va_list * args)
77 u32 dev_instance = va_arg (*args, u32);
78 return format (s, "test-eth%d", dev_instance);
81 static uword dummy_interface_tx (vlib_main_t * vm,
82 vlib_node_runtime_t * node,
85 clib_warning ("you shouldn't be here, leaking buffers...");
86 return frame->n_vectors;
90 test_interface_admin_up_down (vnet_main_t * vnm,
94 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
95 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
96 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
100 VNET_DEVICE_CLASS (test_interface_device_class,static) = {
101 .name = "Test interface",
102 .format_device_name = format_test_interface_name,
103 .tx_function = dummy_interface_tx,
104 .admin_up_down_function = test_interface_admin_up_down,
107 static u8 *hw_address;
110 mfib_test_mk_intf (u32 ninterfaces)
112 clib_error_t * error = NULL;
113 test_main_t *tm = &test_main;
119 ASSERT(ninterfaces <= ARRAY_LEN(tm->hw_if_indicies));
124 vec_add1(hw_address, byte);
127 for (i = 0; i < ninterfaces; i++)
131 error = ethernet_register_interface(vnet_get_main(),
132 test_interface_device_class.index,
135 &tm->hw_if_indicies[i],
136 /* flag change */ 0);
138 MFIB_TEST((NULL == error), "ADD interface %d", i);
140 error = vnet_hw_interface_set_flags(vnet_get_main(),
141 tm->hw_if_indicies[i],
142 VNET_HW_INTERFACE_FLAG_LINK_UP);
143 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
144 tm->hw_if_indicies[i]);
145 vec_validate (ip4_main.fib_index_by_sw_if_index,
146 tm->hw[i]->sw_if_index);
147 vec_validate (ip6_main.fib_index_by_sw_if_index,
148 tm->hw[i]->sw_if_index);
149 ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
150 ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
152 vec_validate (ip4_main.mfib_index_by_sw_if_index,
153 tm->hw[i]->sw_if_index);
154 vec_validate (ip6_main.mfib_index_by_sw_if_index,
155 tm->hw[i]->sw_if_index);
156 ip4_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
157 ip6_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
159 error = vnet_sw_interface_set_flags(vnet_get_main(),
160 tm->hw[i]->sw_if_index,
161 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
162 MFIB_TEST((NULL == error), "UP interface %d", i);
165 * re-eval after the inevitable realloc
167 for (i = 0; i < ninterfaces; i++)
169 tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
170 tm->hw_if_indicies[i]);
176 #define MFIB_TEST_REP(_cond, _comment, _args...) \
178 if (MFIB_TEST_I(_cond, _comment, ##_args)) { \
184 mfib_test_validate_rep_v (const replicate_t *rep,
195 MFIB_TEST_REP((n_buckets == rep->rep_n_buckets),
196 "n_buckets = %d", rep->rep_n_buckets);
198 for (bucket = 0; bucket < n_buckets; bucket++)
200 dt = va_arg(*ap, int); // type promotion
201 ai = va_arg(*ap, adj_index_t);
202 dpo = replicate_get_bucket_i(rep, bucket);
204 MFIB_TEST_REP((dt == dpo->dpoi_type),
205 "bucket %d stacks on %U",
207 format_dpo_type, dpo->dpoi_type);
209 if (DPO_RECEIVE != dt)
211 MFIB_TEST_REP((ai == dpo->dpoi_index),
212 "bucket %d [exp:%d] stacks on %U",
214 format_dpo_id, dpo, 0);
220 static fib_forward_chain_type_t
221 fib_forw_chain_type_from_fib_proto (fib_protocol_t proto)
225 case FIB_PROTOCOL_IP4:
226 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
227 case FIB_PROTOCOL_IP6:
228 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
238 mfib_test_entry (fib_node_index_t fei,
239 mfib_entry_flags_t eflags,
243 const mfib_entry_t *mfe;
244 const replicate_t *rep;
249 va_start(ap, n_buckets);
252 mfe = mfib_entry_get(fei);
253 mfib_entry_get_prefix(fei, &pfx);
255 MFIB_TEST_REP((eflags == mfe->mfe_flags),
256 "%U has %U expect %U",
257 format_mfib_prefix, &pfx,
258 format_mfib_entry_flags, mfe->mfe_flags,
259 format_mfib_entry_flags, eflags);
263 MFIB_TEST_REP((DPO_DROP == mfe->mfe_rep.dpoi_type),
265 format_mfib_prefix, &pfx,
266 format_dpo_id, &mfe->mfe_rep, 0);
270 dpo_id_t tmp = DPO_INVALID;
272 mfib_entry_contribute_forwarding(
274 fib_forw_chain_type_from_fib_proto(pfx.fp_proto),
276 rep = replicate_get(tmp.dpoi_index);
278 MFIB_TEST_REP((DPO_REPLICATE == tmp.dpoi_type),
280 format_mfib_prefix, &pfx,
281 format_dpo_type, tmp.dpoi_type);
283 res = mfib_test_validate_rep_v(rep, n_buckets, &ap);
294 mfib_test_entry_itf (fib_node_index_t fei,
296 mfib_itf_flags_t flags)
298 const mfib_entry_t *mfe;
299 const mfib_itf_t *mfi;
304 mfe = mfib_entry_get(fei);
305 mfi = mfib_entry_get_itf(mfe, sw_if_index);
306 mfib_entry_get_prefix(fei, &pfx);
308 MFIB_TEST_REP((NULL != mfi),
309 "%U has interface %d",
310 format_mfib_prefix, &pfx, sw_if_index);
312 MFIB_TEST_REP((flags == mfi->mfi_flags),
313 "%U interface %d has flags %U expect %U",
314 format_mfib_prefix, &pfx, sw_if_index,
315 format_mfib_itf_flags, flags,
316 format_mfib_itf_flags, mfi->mfi_flags);
322 mfib_test_entry_no_itf (fib_node_index_t fei,
325 const mfib_entry_t *mfe;
326 const mfib_itf_t *mfi;
331 mfe = mfib_entry_get(fei);
332 mfi = mfib_entry_get_itf(mfe, sw_if_index);
333 mfib_entry_get_prefix(fei, &pfx);
335 MFIB_TEST_REP((NULL == mfi),
336 "%U has no interface %d",
337 format_mfib_prefix, &pfx, sw_if_index);
343 mfib_test_i (fib_protocol_t PROTO,
345 const mfib_prefix_t *pfx_no_forward,
346 const mfib_prefix_t *pfx_s_g,
347 const mfib_prefix_t *pfx_star_g_1,
348 const mfib_prefix_t *pfx_star_g_2,
349 const mfib_prefix_t *pfx_star_g_3,
350 const mfib_prefix_t *pfx_star_g_slash_m)
352 fib_node_index_t mfei, mfei_dflt, mfei_no_f, mfei_s_g, mfei_g_1, mfei_g_2, mfei_g_3, mfei_g_m;
353 u32 fib_index, n_entries, n_itfs, n_reps, n_pls;
354 fib_node_index_t ai_1, ai_2, ai_3;
358 mfib_prefix_t all_1s;
359 memset(&all_1s, 0xfd, sizeof(all_1s));
362 n_entries = pool_elts(mfib_entry_pool);
363 n_itfs = pool_elts(mfib_itf_pool);
364 n_reps = pool_elts(replicate_pool);
365 n_pls = fib_path_list_pool_size();
368 ai_1 = adj_mcast_add_or_lock(PROTO,
370 tm->hw[1]->sw_if_index);
371 ai_2 = adj_mcast_add_or_lock(PROTO,
373 tm->hw[2]->sw_if_index);
374 ai_3 = adj_mcast_add_or_lock(PROTO,
376 tm->hw[3]->sw_if_index);
378 MFIB_TEST(3 == adj_mcast_db_size(), "3 MCAST adjs");
380 /* Find or create FIB table 11 */
381 fib_index = mfib_table_find_or_create_and_lock(PROTO, 11, MFIB_SOURCE_API);
383 mfib_prefix_t pfx_dft = {
387 mfei_dflt = mfib_table_lookup_exact_match(fib_index, &pfx_dft);
388 MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet");
389 MFIB_TEST(!mfib_test_entry(mfei_dflt,
390 MFIB_ENTRY_FLAG_DROP,
392 "(*,*) no replcaitions");
394 MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_dflt, "(*,*) presnet");
395 MFIB_TEST(!mfib_test_entry(mfei_dflt,
396 MFIB_ENTRY_FLAG_DROP,
398 "(*,*) no replcaitions");
401 fib_route_path_t path_via_if0 = {
402 .frp_proto = fib_proto_to_dpo(PROTO),
403 .frp_addr = zero_addr,
404 .frp_sw_if_index = tm->hw[0]->sw_if_index,
410 mfib_table_entry_path_update(fib_index,
414 MFIB_ITF_FLAG_ACCEPT);
416 mfei_no_f = mfib_table_lookup_exact_match(fib_index, pfx_no_forward);
417 MFIB_TEST(!mfib_test_entry(mfei_no_f,
418 MFIB_ENTRY_FLAG_NONE,
420 "%U no replcaitions",
421 format_mfib_prefix, pfx_no_forward);
422 MFIB_TEST_NS(!mfib_test_entry_itf(mfei_no_f, tm->hw[0]->sw_if_index,
423 MFIB_ITF_FLAG_ACCEPT));
425 fib_route_path_t path_via_if1 = {
426 .frp_proto = fib_proto_to_dpo(PROTO),
427 .frp_addr = zero_addr,
428 .frp_sw_if_index = tm->hw[1]->sw_if_index,
433 fib_route_path_t path_via_if2 = {
434 .frp_proto = fib_proto_to_dpo(PROTO),
435 .frp_addr = zero_addr,
436 .frp_sw_if_index = tm->hw[2]->sw_if_index,
441 fib_route_path_t path_via_if3 = {
442 .frp_proto = fib_proto_to_dpo(PROTO),
443 .frp_addr = zero_addr,
444 .frp_sw_if_index = tm->hw[3]->sw_if_index,
449 fib_route_path_t path_for_us = {
450 .frp_proto = fib_proto_to_dpo(PROTO),
451 .frp_addr = zero_addr,
452 .frp_sw_if_index = 0xffffffff,
455 .frp_flags = FIB_ROUTE_PATH_LOCAL,
459 * An (S,G) with 1 accepting and 3 forwarding paths
461 mfib_table_entry_path_update(fib_index,
465 MFIB_ITF_FLAG_ACCEPT);
466 mfib_table_entry_path_update(fib_index,
470 MFIB_ITF_FLAG_FORWARD);
471 mfib_table_entry_path_update(fib_index,
475 MFIB_ITF_FLAG_FORWARD);
476 mfib_table_entry_path_update(fib_index,
480 (MFIB_ITF_FLAG_FORWARD |
481 MFIB_ITF_FLAG_NEGATE_SIGNAL));
483 mfei_s_g = mfib_table_lookup_exact_match(fib_index, pfx_s_g);
485 MFIB_TEST(FIB_NODE_INDEX_INVALID != mfei_s_g,
487 format_mfib_prefix, pfx_s_g);
488 MFIB_TEST(!mfib_test_entry(mfei_s_g,
489 MFIB_ENTRY_FLAG_NONE,
491 DPO_ADJACENCY_MCAST, ai_1,
492 DPO_ADJACENCY_MCAST, ai_2,
493 DPO_ADJACENCY_MCAST, ai_3),
495 format_mfib_prefix, pfx_s_g);
496 MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[0]->sw_if_index,
497 MFIB_ITF_FLAG_ACCEPT));
498 MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[1]->sw_if_index,
499 MFIB_ITF_FLAG_FORWARD));
500 MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[2]->sw_if_index,
501 MFIB_ITF_FLAG_FORWARD));
502 MFIB_TEST_NS(!mfib_test_entry_itf(mfei_s_g, tm->hw[3]->sw_if_index,
503 (MFIB_ITF_FLAG_FORWARD |
504 MFIB_ITF_FLAG_NEGATE_SIGNAL)));
507 * A (*,G), which the same G as the (S,G).
508 * different paths. test our LPM.
510 mfei_g_1 = mfib_table_entry_path_update(fib_index,
514 MFIB_ITF_FLAG_ACCEPT);
515 mfib_table_entry_path_update(fib_index,
519 MFIB_ITF_FLAG_FORWARD);
522 * test we find the *,G and S,G via LPM and exact matches
524 mfei = mfib_table_lookup_exact_match(fib_index,
526 MFIB_TEST(mfei == mfei_g_1,
527 "%U found via exact match",
528 format_mfib_prefix, pfx_star_g_1);
529 MFIB_TEST(!mfib_test_entry(mfei,
530 MFIB_ENTRY_FLAG_NONE,
532 DPO_ADJACENCY_MCAST, ai_1),
534 format_mfib_prefix, pfx_star_g_1);
536 mfei = mfib_table_lookup(fib_index,
538 MFIB_TEST(mfei == mfei_g_1,
539 "%U found via LP match",
540 format_mfib_prefix, pfx_star_g_1);
542 MFIB_TEST(!mfib_test_entry(mfei,
543 MFIB_ENTRY_FLAG_NONE,
545 DPO_ADJACENCY_MCAST, ai_1),
547 format_mfib_prefix, pfx_star_g_1);
549 mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g);
550 MFIB_TEST(mfei == mfei_s_g,
551 "%U found via exact match",
552 format_mfib_prefix, pfx_s_g);
554 MFIB_TEST(!mfib_test_entry(mfei,
555 MFIB_ENTRY_FLAG_NONE,
557 DPO_ADJACENCY_MCAST, ai_1,
558 DPO_ADJACENCY_MCAST, ai_2,
559 DPO_ADJACENCY_MCAST, ai_3),
561 format_mfib_prefix, pfx_s_g);
562 mfei = mfib_table_lookup(fib_index, pfx_s_g);
563 MFIB_TEST(mfei == mfei_s_g,
564 "%U found via LP match",
565 format_mfib_prefix, pfx_s_g);
567 MFIB_TEST(!mfib_test_entry(mfei,
568 MFIB_ENTRY_FLAG_NONE,
570 DPO_ADJACENCY_MCAST, ai_1,
571 DPO_ADJACENCY_MCAST, ai_2,
572 DPO_ADJACENCY_MCAST, ai_3),
574 format_mfib_prefix, pfx_s_g);
577 * A (*,G/m), which the same root G as the (*,G).
578 * different paths. test our LPM.
580 mfei_g_m = mfib_table_entry_path_update(fib_index,
584 MFIB_ITF_FLAG_ACCEPT);
585 mfib_table_entry_path_update(fib_index,
589 MFIB_ITF_FLAG_FORWARD);
592 * test we find the (*,G/m), (*,G) and (S,G) via LPM and exact matches
594 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1);
595 MFIB_TEST((mfei_g_1 == mfei),
596 "%U found via DP LPM: %d",
597 format_mfib_prefix, pfx_star_g_1, mfei);
599 MFIB_TEST(!mfib_test_entry(mfei,
600 MFIB_ENTRY_FLAG_NONE,
602 DPO_ADJACENCY_MCAST, ai_1),
604 format_mfib_prefix, pfx_star_g_1);
606 mfei = mfib_table_lookup(fib_index, pfx_star_g_1);
608 MFIB_TEST(!mfib_test_entry(mfei,
609 MFIB_ENTRY_FLAG_NONE,
611 DPO_ADJACENCY_MCAST, ai_1),
613 format_mfib_prefix, pfx_star_g_1);
615 mfei = mfib_table_lookup_exact_match(fib_index, pfx_s_g);
617 MFIB_TEST(!mfib_test_entry(mfei,
618 MFIB_ENTRY_FLAG_NONE,
620 DPO_ADJACENCY_MCAST, ai_1,
621 DPO_ADJACENCY_MCAST, ai_2,
622 DPO_ADJACENCY_MCAST, ai_3),
624 format_mfib_prefix, pfx_s_g);
625 mfei = mfib_table_lookup(fib_index, pfx_s_g);
627 MFIB_TEST(!mfib_test_entry(mfei,
628 MFIB_ENTRY_FLAG_NONE,
630 DPO_ADJACENCY_MCAST, ai_1,
631 DPO_ADJACENCY_MCAST, ai_2,
632 DPO_ADJACENCY_MCAST, ai_3),
634 format_mfib_prefix, pfx_s_g);
636 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m);
637 MFIB_TEST(mfei = mfei_g_m,
638 "%U Found via exact match",
639 format_mfib_prefix, pfx_star_g_slash_m);
640 MFIB_TEST(!mfib_test_entry(mfei,
641 MFIB_ENTRY_FLAG_NONE,
643 DPO_ADJACENCY_MCAST, ai_3),
645 format_mfib_prefix, pfx_star_g_slash_m);
646 MFIB_TEST(mfei_g_m == mfib_table_lookup(fib_index, pfx_star_g_slash_m),
648 format_mfib_prefix, pfx_star_g_slash_m);
653 mfei = mfib_table_entry_path_update(fib_index,
657 MFIB_ITF_FLAG_FORWARD);
659 MFIB_TEST(!mfib_test_entry(mfei,
660 MFIB_ENTRY_FLAG_NONE,
662 DPO_ADJACENCY_MCAST, ai_1,
663 DPO_ADJACENCY_MCAST, ai_2,
664 DPO_ADJACENCY_MCAST, ai_3,
667 format_mfib_prefix, pfx_s_g);
670 * remove a for-us path
672 mfib_table_entry_path_remove(fib_index,
677 MFIB_TEST(!mfib_test_entry(mfei,
678 MFIB_ENTRY_FLAG_NONE,
680 DPO_ADJACENCY_MCAST, ai_1,
681 DPO_ADJACENCY_MCAST, ai_2,
682 DPO_ADJACENCY_MCAST, ai_3),
684 format_mfib_prefix, pfx_s_g);
687 * update an existing forwarding path to be only accepting
688 * - expect it to be removed from the replication set.
690 mfib_table_entry_path_update(fib_index,
694 MFIB_ITF_FLAG_ACCEPT);
696 MFIB_TEST(!mfib_test_entry(mfei,
697 MFIB_ENTRY_FLAG_NONE,
699 DPO_ADJACENCY_MCAST, ai_1,
700 DPO_ADJACENCY_MCAST, ai_2),
702 format_mfib_prefix, pfx_s_g);
703 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
704 MFIB_ITF_FLAG_ACCEPT));
705 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
706 MFIB_ITF_FLAG_FORWARD));
707 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
708 MFIB_ITF_FLAG_FORWARD));
709 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index,
710 MFIB_ITF_FLAG_ACCEPT));
712 * Make the path forwarding again
713 * - expect it to be added back to the replication set
715 mfib_table_entry_path_update(fib_index,
719 (MFIB_ITF_FLAG_FORWARD |
720 MFIB_ITF_FLAG_ACCEPT |
721 MFIB_ITF_FLAG_NEGATE_SIGNAL));
723 mfei = mfib_table_lookup_exact_match(fib_index,
726 MFIB_TEST(!mfib_test_entry(mfei,
727 MFIB_ENTRY_FLAG_NONE,
729 DPO_ADJACENCY_MCAST, ai_1,
730 DPO_ADJACENCY_MCAST, ai_2,
731 DPO_ADJACENCY_MCAST, ai_3),
733 format_mfib_prefix, pfx_s_g);
734 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
735 MFIB_ITF_FLAG_ACCEPT));
736 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
737 MFIB_ITF_FLAG_FORWARD));
738 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
739 MFIB_ITF_FLAG_FORWARD));
740 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[3]->sw_if_index,
741 (MFIB_ITF_FLAG_FORWARD |
742 MFIB_ITF_FLAG_ACCEPT |
743 MFIB_ITF_FLAG_NEGATE_SIGNAL)));
746 * update flags on the entry
748 mfib_table_entry_update(fib_index,
752 MFIB_ENTRY_FLAG_SIGNAL);
753 MFIB_TEST(!mfib_test_entry(mfei,
754 MFIB_ENTRY_FLAG_SIGNAL,
756 DPO_ADJACENCY_MCAST, ai_1,
757 DPO_ADJACENCY_MCAST, ai_2,
758 DPO_ADJACENCY_MCAST, ai_3),
760 format_mfib_prefix, pfx_s_g);
765 mfib_table_entry_path_remove(fib_index,
770 MFIB_TEST(!mfib_test_entry(mfei,
771 MFIB_ENTRY_FLAG_SIGNAL,
773 DPO_ADJACENCY_MCAST, ai_1,
774 DPO_ADJACENCY_MCAST, ai_2),
776 format_mfib_prefix, pfx_s_g);
777 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
778 MFIB_ITF_FLAG_ACCEPT));
779 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[1]->sw_if_index,
780 MFIB_ITF_FLAG_FORWARD));
781 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
782 MFIB_ITF_FLAG_FORWARD));
783 MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));
785 mfib_table_entry_path_remove(fib_index,
790 MFIB_TEST(!mfib_test_entry(mfei,
791 MFIB_ENTRY_FLAG_SIGNAL,
793 DPO_ADJACENCY_MCAST, ai_2),
795 format_mfib_prefix, pfx_s_g);
796 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[0]->sw_if_index,
797 MFIB_ITF_FLAG_ACCEPT));
798 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
799 MFIB_ITF_FLAG_FORWARD));
800 MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));
803 * remove the accpeting only interface
805 mfib_table_entry_path_remove(fib_index,
810 MFIB_TEST(!mfib_test_entry(mfei,
811 MFIB_ENTRY_FLAG_SIGNAL,
813 DPO_ADJACENCY_MCAST, ai_2),
815 format_mfib_prefix, pfx_s_g);
816 MFIB_TEST_NS(!mfib_test_entry_itf(mfei, tm->hw[2]->sw_if_index,
817 MFIB_ITF_FLAG_FORWARD));
818 MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[0]->sw_if_index));
819 MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[1]->sw_if_index));
820 MFIB_TEST_NS(!mfib_test_entry_no_itf(mfei, tm->hw[3]->sw_if_index));
823 * remove the last path, the entry still has flags so it remains
825 mfib_table_entry_path_remove(fib_index,
830 MFIB_TEST(!mfib_test_entry(mfei,
831 MFIB_ENTRY_FLAG_SIGNAL,
833 "%U no replications",
834 format_mfib_prefix, pfx_s_g);
837 * update flags on the entry
839 mfib_table_entry_update(fib_index,
843 (MFIB_ENTRY_FLAG_SIGNAL |
844 MFIB_ENTRY_FLAG_CONNECTED));
845 MFIB_TEST(!mfib_test_entry(mfei,
846 (MFIB_ENTRY_FLAG_SIGNAL |
847 MFIB_ENTRY_FLAG_CONNECTED),
849 "%U no replications",
850 format_mfib_prefix, pfx_s_g);
853 * An entry with a NS interface
855 mfei_g_2 = mfib_table_entry_path_update(fib_index,
859 (MFIB_ITF_FLAG_ACCEPT |
860 MFIB_ITF_FLAG_NEGATE_SIGNAL));
861 MFIB_TEST(!mfib_test_entry(mfei_g_2,
862 MFIB_ENTRY_FLAG_NONE,
864 "%U No replications",
865 format_mfib_prefix, pfx_star_g_2);
868 * Simulate a signal from the data-plane
874 mfe = mfib_entry_get(mfei_g_2);
875 mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index);
877 mfib_signal_push(mfe, mfi, NULL);
881 * An entry with a NS interface
883 mfei_g_3 = mfib_table_entry_path_update(fib_index,
887 (MFIB_ITF_FLAG_ACCEPT |
888 MFIB_ITF_NEGATE_SIGNAL));
889 MFIB_TEST(!mfib_test_entry(mfei_g_3,
890 MFIB_ENTRY_FLAG_NONE,
892 "%U No replications",
893 format_mfib_prefix, pfx_star_g_3);
896 * Simulate a signal from the data-plane
902 mfe = mfib_entry_get(mfei_g_3);
903 mfi = mfib_entry_get_itf(mfe, path_via_if0.frp_sw_if_index);
905 mfib_signal_push(mfe, mfi, NULL);
908 if (FIB_PROTOCOL_IP6 == PROTO)
911 * All the entries are present. let's ensure we can find them all
912 * via exact and longest prefix matches.
915 * A source address we will never match
917 ip6_address_t src = {
918 .as_u64[0] = clib_host_to_net_u64(0x3001000000000000),
919 .as_u64[1] = clib_host_to_net_u64(0xffffffffffffffff),
925 MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2(
926 ip6_mfib_get(fib_index),
928 &pfx_star_g_slash_m->fp_grp_addr.ip6)),
929 "%U found via DP LPM grp=%U",
930 format_mfib_prefix, pfx_star_g_slash_m,
931 format_ip6_address, &pfx_star_g_slash_m->fp_grp_addr.ip6);
933 ip6_address_t tmp = pfx_star_g_slash_m->fp_grp_addr.ip6;
934 tmp.as_u8[15] = 0xff;
936 MFIB_TEST((mfei_g_m == ip6_mfib_table_lookup2(
937 ip6_mfib_get(fib_index),
938 &pfx_s_g->fp_src_addr.ip6,
940 "%U found via DP LPM grp=%U",
941 format_mfib_prefix, pfx_star_g_slash_m,
942 format_ip6_address, &tmp);
947 mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
948 &pfx_s_g->fp_src_addr.ip6,
949 &pfx_s_g->fp_grp_addr.ip6);
950 MFIB_TEST((mfei_s_g == mfei),
951 "%U found via DP LPM: %d",
952 format_mfib_prefix, pfx_s_g, mfei);
957 mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
959 &pfx_star_g_1->fp_grp_addr.ip6);
960 MFIB_TEST((mfei_g_1 == mfei),
961 "%U found via DP LPM: %d",
962 format_mfib_prefix, pfx_star_g_1, mfei);
963 mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
965 &pfx_star_g_2->fp_grp_addr.ip6);
966 MFIB_TEST((mfei_g_2 == mfei),
967 "%U found via DP LPM: %d",
968 format_mfib_prefix, pfx_star_g_2, mfei);
969 mfei = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index),
971 &pfx_star_g_3->fp_grp_addr.ip6);
972 MFIB_TEST((mfei_g_3 == mfei),
973 "%U found via DP LPM: %d",
974 format_mfib_prefix, pfx_star_g_3, mfei);
978 * remove flags on the entry. This is the last of the
979 * state associated with the entry, so now it goes.
981 mfib_table_entry_update(fib_index,
985 MFIB_ENTRY_FLAG_NONE);
986 mfei = mfib_table_lookup_exact_match(fib_index,
988 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
990 format_mfib_prefix, pfx_s_g);
993 * remove the last path on the no forward entry - the last entry
995 mfib_table_entry_path_remove(fib_index,
1000 mfei = mfib_table_lookup_exact_match(fib_index, pfx_no_forward);
1001 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
1003 format_mfib_prefix, pfx_no_forward);
1006 * hard delete the (*,232.1.1.1)
1008 mfib_table_entry_delete(fib_index,
1012 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_1);
1013 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
1015 format_mfib_prefix, pfx_star_g_1);
1017 * remove the entry whilst the signal is pending
1019 mfib_table_entry_delete(fib_index,
1023 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_2);
1024 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
1026 format_mfib_prefix, pfx_star_g_2);
1027 mfib_table_entry_delete(fib_index,
1031 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_3);
1032 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
1034 format_mfib_prefix, pfx_star_g_3);
1036 mfib_table_entry_delete(fib_index,
1040 mfei = mfib_table_lookup_exact_match(fib_index, pfx_star_g_slash_m);
1041 MFIB_TEST(FIB_NODE_INDEX_INVALID == mfei,
1043 format_mfib_prefix, pfx_star_g_slash_m);
1046 * Add a prefix as a special/exclusive route
1048 dpo_id_t td = DPO_INVALID;
1049 index_t repi = replicate_create(1, fib_proto_to_dpo(PROTO));
1051 dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_2);
1052 replicate_set_bucket(repi, 0, &td);
1054 mfei = mfib_table_entry_special_add(fib_index,
1057 MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF,
1059 MFIB_TEST(!mfib_test_entry(mfei,
1060 (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF |
1061 MFIB_ENTRY_FLAG_EXCLUSIVE),
1063 DPO_ADJACENCY_MCAST, ai_2),
1064 "%U exclusive replicate OK",
1065 format_mfib_prefix, pfx_star_g_3);
1068 * update a special/exclusive route
1070 index_t repi2 = replicate_create(1, fib_proto_to_dpo(PROTO));
1072 dpo_set(&td, DPO_ADJACENCY_MCAST, fib_proto_to_dpo(PROTO), ai_1);
1073 replicate_set_bucket(repi2, 0, &td);
1075 mfei = mfib_table_entry_special_add(fib_index,
1078 MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF,
1080 MFIB_TEST(!mfib_test_entry(mfei,
1081 (MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF |
1082 MFIB_ENTRY_FLAG_EXCLUSIVE),
1084 DPO_ADJACENCY_MCAST, ai_1),
1085 "%U exclusive update replicate OK",
1086 format_mfib_prefix, pfx_star_g_3);
1088 mfib_table_entry_delete(fib_index,
1094 * A Multicast LSP. This a mLDP head-end
1096 fib_node_index_t ai_mpls_10_10_10_1, lfei;
1097 ip46_address_t nh_10_10_10_1 = {
1099 .as_u32 = clib_host_to_net_u32(0x0a0a0a01),
1102 ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4,
1105 tm->hw[0]->sw_if_index);
1107 fib_prefix_t pfx_3500 = {
1109 .fp_proto = FIB_PROTOCOL_MPLS,
1112 .fp_payload_proto = DPO_PROTO_IP4,
1114 fib_test_rep_bucket_t mc_0 = {
1115 .type = FT_REP_LABEL_O_ADJ,
1117 .adj = ai_mpls_10_10_10_1,
1122 fib_mpls_label_t *l3300 = NULL, fml3300 = {
1125 vec_add1(l3300, fml3300);
1128 * MPLS enable an interface so we get the MPLS table created
1130 mpls_table_create(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API, NULL);
1131 mpls_sw_interface_enable_disable(&mpls_main,
1132 tm->hw[0]->sw_if_index,
1135 lfei = fib_table_entry_update_one_path(0, // default MPLS Table
1138 FIB_ENTRY_FLAG_MULTICAST,
1141 tm->hw[0]->sw_if_index,
1142 ~0, // invalid fib index
1145 FIB_ROUTE_PATH_FLAG_NONE);
1146 MFIB_TEST(!fib_test_validate_entry(lfei,
1147 FIB_FORW_CHAIN_TYPE_MPLS_EOS,
1150 "3500 via replicate over 10.10.10.1");
1153 * An (S,G) that resolves via the mLDP head-end
1155 fib_route_path_t path_via_mldp = {
1156 .frp_proto = DPO_PROTO_MPLS,
1157 .frp_local_label = pfx_3500.fp_label,
1158 .frp_eos = MPLS_EOS,
1159 .frp_sw_if_index = 0xffffffff,
1162 .frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
1164 dpo_id_t mldp_dpo = DPO_INVALID;
1166 fib_entry_contribute_forwarding(lfei,
1167 FIB_FORW_CHAIN_TYPE_MPLS_EOS,
1170 mfei = mfib_table_entry_path_update(fib_index,
1174 MFIB_ITF_FLAG_FORWARD);
1176 MFIB_TEST(!mfib_test_entry(mfei,
1177 MFIB_ENTRY_FLAG_NONE,
1179 DPO_REPLICATE, mldp_dpo.dpoi_index),
1180 "%U over-mLDP replicate OK",
1181 format_mfib_prefix, pfx_s_g);
1184 * add a for-us path. this tests two types of non-attached paths on one entry
1186 mfei = mfib_table_entry_path_update(fib_index,
1190 MFIB_ITF_FLAG_FORWARD);
1191 MFIB_TEST(!mfib_test_entry(mfei,
1192 MFIB_ENTRY_FLAG_NONE,
1194 DPO_REPLICATE, mldp_dpo.dpoi_index,
1196 "%U mLDP+for-us replicate OK",
1197 format_mfib_prefix, pfx_s_g);
1199 mfib_table_entry_delete(fib_index,
1202 fib_table_entry_delete(0,
1205 dpo_reset(&mldp_dpo);
1208 * Unlock the table - it's the last lock so should be gone thereafter
1210 mfib_table_unlock(fib_index, PROTO, MFIB_SOURCE_API);
1212 MFIB_TEST((FIB_NODE_INDEX_INVALID ==
1213 mfib_table_find(PROTO, fib_index)),
1214 "MFIB table %d gone", fib_index);
1221 * MPLS disable the interface
1223 mpls_sw_interface_enable_disable(&mpls_main,
1224 tm->hw[0]->sw_if_index,
1226 mpls_table_delete(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API);
1229 * test we've leaked no resources
1231 MFIB_TEST(0 == adj_mcast_db_size(), "%d MCAST adjs", adj_mcast_db_size());
1232 MFIB_TEST(n_pls == fib_path_list_pool_size(), "%d=%d path-lists",
1233 n_pls, fib_path_list_pool_size());
1234 MFIB_TEST(n_reps == pool_elts(replicate_pool), "%d=%d replicates",
1235 n_reps, pool_elts(replicate_pool));
1236 MFIB_TEST(n_entries == pool_elts(mfib_entry_pool),
1237 " No more entries %d!=%d",
1238 n_entries, pool_elts(mfib_entry_pool));
1239 MFIB_TEST(n_itfs == pool_elts(mfib_itf_pool),
1240 " No more Interfaces %d!=%d",
1241 n_itfs, pool_elts(mfib_itf_pool));
1249 const mfib_prefix_t pfx_224_s_8 = {
1251 .fp_proto = FIB_PROTOCOL_IP4,
1253 .ip4.as_u32 = clib_host_to_net_u32(0xe0000000),
1256 const mfib_prefix_t pfx_1_1_1_1_c_239_1_1_1 = {
1258 .fp_proto = FIB_PROTOCOL_IP4,
1260 .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
1263 .ip4.as_u32 = clib_host_to_net_u32(0x01010101),
1266 const mfib_prefix_t pfx_239_1_1_1 = {
1268 .fp_proto = FIB_PROTOCOL_IP4,
1270 .ip4.as_u32 = clib_host_to_net_u32(0xef010101),
1276 const mfib_prefix_t pfx_239_1_1_2 = {
1278 .fp_proto = FIB_PROTOCOL_IP4,
1280 .ip4.as_u32 = clib_host_to_net_u32(0xef010102),
1286 const mfib_prefix_t pfx_239_1_1_3 = {
1288 .fp_proto = FIB_PROTOCOL_IP4,
1290 .ip4.as_u32 = clib_host_to_net_u32(0xef010103),
1296 const mfib_prefix_t pfx_239 = {
1298 .fp_proto = FIB_PROTOCOL_IP4,
1300 .ip4.as_u32 = clib_host_to_net_u32(0xef000000),
1307 return (mfib_test_i(FIB_PROTOCOL_IP4,
1310 &pfx_1_1_1_1_c_239_1_1_1,
1320 const mfib_prefix_t pfx_ffd_s_12 = {
1322 .fp_proto = FIB_PROTOCOL_IP6,
1324 .ip6.as_u64[0] = clib_host_to_net_u64(0xffd0000000000000),
1327 const mfib_prefix_t pfx_2001_1_c_ff_1 = {
1329 .fp_proto = FIB_PROTOCOL_IP6,
1331 .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
1332 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
1335 .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000),
1336 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
1339 const mfib_prefix_t pfx_ff_1 = {
1341 .fp_proto = FIB_PROTOCOL_IP6,
1343 .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
1344 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000001),
1347 const mfib_prefix_t pfx_ff_2 = {
1349 .fp_proto = FIB_PROTOCOL_IP6,
1351 .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
1352 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002),
1355 const mfib_prefix_t pfx_ff_3 = {
1357 * this is the ALL DHCP routers address
1360 .fp_proto = FIB_PROTOCOL_IP6,
1362 .ip6.as_u64[0] = clib_host_to_net_u64(0xff02000100000000),
1363 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000002),
1366 const mfib_prefix_t pfx_ff = {
1368 .fp_proto = FIB_PROTOCOL_IP6,
1370 .ip6.as_u64[0] = clib_host_to_net_u64(0xff01000000000000),
1371 .ip6.as_u64[1] = clib_host_to_net_u64(0x0000000000000000),
1375 return (mfib_test_i(FIB_PROTOCOL_IP6,
1385 static clib_error_t *
1386 mfib_test (vlib_main_t * vm,
1387 unformat_input_t * input,
1388 vlib_cli_command_t * cmd_arg)
1392 res += mfib_test_mk_intf(4);
1393 res += mfib_test_v4();
1394 res += mfib_test_v6();
1398 return clib_error_return(0, "MFIB Unit Test Failed");
1406 VLIB_CLI_COMMAND (test_fib_command, static) = {
1407 .path = "test mfib",
1408 .short_help = "mfib unit tests - DO NOT RUN ON A LIVE SYSTEM",
1409 .function = mfib_test,
1413 mfib_test_init (vlib_main_t *vm)
1418 VLIB_INIT_FUNCTION (mfib_test_init);