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 <vppinfra/mhash.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/adj/adj.h>
19 #include <vnet/dpo/load_balance.h>
20 #include <vnet/dpo/load_balance_map.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/fib_internal.h>
24 #include <vnet/fib/fib_node_list.h>
25 #include <vnet/fib/fib_walk.h>
29 * A representation of the list/set of path trough which a prefix is reachable
31 typedef struct fib_path_list_t_ {
33 * A path-list is a node in the FIB graph.
38 * Flags on the path-list
40 fib_path_list_flags_t fpl_flags;
43 * The next-hop protocol for the paths in this path list.
44 * Note that fixing the proto here means we don't support a mix of
45 * v4 and v6 paths. ho hum.
47 fib_protocol_t fpl_nh_proto;
50 * Vector of paths indecies for all configured paths.
51 * For shareable path-lists this list MUST not change.
53 fib_node_index_t *fpl_paths;
57 * Array of strings/names for the FIB sources
59 static const char *fib_path_list_attr_names[] = FIB_PATH_LIST_ATTRIBUTES;
62 * The memory pool from which we allocate all the path-lists
64 static fib_path_list_t * fib_path_list_pool;
67 * The data-base of shared path-lists
69 static uword *fib_path_list_db;
75 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...) \
78 _tmp = fib_path_list_format( \
79 fib_path_list_get_index(_pl), _tmp); \
80 clib_warning("pl:[%d:%p:%p:%s]:" _fmt, \
81 fib_path_list_get_index(_pl), \
82 _pl, _pl->fpl_paths, _tmp, \
87 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...)
90 static fib_path_list_t *
91 fib_path_list_get (fib_node_index_t index)
93 return (pool_elt_at_index(fib_path_list_pool, index));
97 fib_path_list_get_node (fib_node_index_t index)
99 return ((fib_node_t*)fib_path_list_get(index));
102 static fib_path_list_t*
103 fib_path_list_from_fib_node (fib_node_t *node)
106 ASSERT(FIB_NODE_TYPE_PATH_LIST == node->fn_type);
108 return ((fib_path_list_t*)node);
111 static fib_node_index_t
112 fib_path_list_get_index (fib_path_list_t *path_list)
114 return (path_list - fib_path_list_pool);
118 format_fib_path_list (u8 * s, va_list * args)
120 fib_path_list_attribute_t attr;
121 fib_node_index_t *path_index;
122 fib_path_list_t *path_list;
124 path_list = va_arg (*args, fib_path_list_t *);
126 s = format (s, " index:%u", fib_path_list_get_index(path_list));
127 s = format (s, " locks:%u", path_list->fpl_node.fn_locks);
128 s = format (s, " proto:%U", format_fib_protocol, path_list->fpl_nh_proto);
130 if (FIB_PATH_LIST_FLAG_NONE != path_list->fpl_flags)
132 s = format (s, " flags:");
133 FOR_EACH_PATH_LIST_ATTRIBUTE(attr)
135 if ((1<<attr) & path_list->fpl_flags)
137 s = format (s, "%s,", fib_path_list_attr_names[attr]);
141 vec_foreach (path_index, path_list->fpl_paths)
143 s = fib_path_format(*path_index, s);
151 fib_path_list_adjs_format (fib_node_index_t path_list_index,
155 fib_path_list_t *path_list;
158 path_list = fib_path_list_get(path_list_index);
160 vec_foreach_index (i, path_list->fpl_paths)
162 s = fib_path_adj_format(path_list->fpl_paths[i],
171 fib_path_list_format (fib_node_index_t path_list_index,
174 fib_path_list_t *path_list;
176 path_list = fib_path_list_get(path_list_index);
178 return (format(s, "%U", format_fib_path_list, path_list));
182 fib_path_list_hash (fib_path_list_t *path_list)
184 uword old_path_list_hash, new_path_list_hash, path_hash;
185 fib_node_index_t *path_index;
189 new_path_list_hash = old_path_list_hash = vec_len(path_list->fpl_paths);
191 vec_foreach (path_index, path_list->fpl_paths)
193 path_hash = fib_path_hash(*path_index);
195 hash_mix64(path_hash, old_path_list_hash, new_path_list_hash);
197 hash_mix32(path_hash, old_path_list_hash, new_path_list_hash);
201 return (new_path_list_hash);
205 fib_path_list_db_hash_key_from_index (uword index)
211 fib_path_list_db_hash_key_is_index (uword key)
217 fib_path_list_db_hash_key_2_index (uword key)
219 ASSERT (fib_path_list_db_hash_key_is_index (key));
223 static fib_path_list_t*
224 fib_path_list_db_get_from_hash_key (uword key)
226 fib_path_list_t *path_list;
228 if (fib_path_list_db_hash_key_is_index (key))
230 fib_node_index_t path_list_index;
232 path_list_index = fib_path_list_db_hash_key_2_index(key);
233 path_list = fib_path_list_get(path_list_index);
237 path_list = uword_to_pointer (key, fib_path_list_t *);
244 fib_path_list_db_hash_key_sum (hash_t * h,
247 fib_path_list_t *path_list;
249 path_list = fib_path_list_db_get_from_hash_key(key);
251 return (fib_path_list_hash(path_list));
255 fib_path_list_db_hash_key_equal (hash_t * h,
259 fib_path_list_t *path_list1, *path_list2;
261 path_list1 = fib_path_list_db_get_from_hash_key(key1);
262 path_list2 = fib_path_list_db_get_from_hash_key(key2);
264 return (fib_path_list_hash(path_list1) ==
265 fib_path_list_hash(path_list2));
268 static fib_node_index_t
269 fib_path_list_db_find (fib_path_list_t *path_list)
273 p = hash_get(fib_path_list_db, path_list);
280 return (FIB_NODE_INDEX_INVALID);
284 fib_path_list_db_insert (fib_node_index_t path_list_index)
286 fib_path_list_t *path_list;
288 path_list = fib_path_list_get(path_list_index);
290 ASSERT(FIB_NODE_INDEX_INVALID == fib_path_list_db_find(path_list));
292 hash_set (fib_path_list_db,
293 fib_path_list_db_hash_key_from_index(path_list_index),
296 FIB_PATH_LIST_DBG(path_list, "DB-inserted");
300 fib_path_list_db_remove (fib_node_index_t path_list_index)
302 fib_path_list_t *path_list;
304 path_list = fib_path_list_get(path_list_index);
306 ASSERT(FIB_NODE_INDEX_INVALID != fib_path_list_db_find(path_list));
308 hash_unset(fib_path_list_db,
309 fib_path_list_db_hash_key_from_index(path_list_index));
311 FIB_PATH_LIST_DBG(path_list, "DB-removed");
315 fib_path_list_destroy (fib_path_list_t *path_list)
317 fib_node_index_t *path_index;
319 FIB_PATH_LIST_DBG(path_list, "destroy");
321 vec_foreach (path_index, path_list->fpl_paths)
323 fib_path_destroy(*path_index);
326 vec_free(path_list->fpl_paths);
328 fib_node_deinit(&path_list->fpl_node);
329 pool_put(fib_path_list_pool, path_list);
333 fib_path_list_last_lock_gone (fib_node_t *node)
335 fib_path_list_t *path_list;
337 path_list = fib_path_list_from_fib_node(node);
339 FIB_PATH_LIST_DBG(path_list, "last-lock");
341 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
343 fib_path_list_db_remove(fib_path_list_get_index(path_list));
345 fib_path_list_destroy(path_list);
351 * update the multipath adj this path-list will contribute to its
352 * children's forwarding.
355 fib_path_list_mk_lb (fib_path_list_t *path_list,
356 fib_forward_chain_type_t type,
359 load_balance_path_t *hash_key;
360 fib_node_index_t *path_index;
365 * We gather the DPOs from resolved paths.
367 vec_foreach (path_index, path_list->fpl_paths)
369 hash_key = fib_path_append_nh_for_multipath_hash(
376 * Path-list load-balances, which if used, would be shared and hence
377 * never need a load-balance map.
379 load_balance_multipath_update(dpo, hash_key, LOAD_BALANCE_FLAG_NONE);
381 FIB_PATH_LIST_DBG(path_list, "mk lb: %d", dpo->dpoi_index);
387 * fib_path_list_back_walk
389 * Called from one of this path-list's paths to progate
393 fib_path_list_back_walk (fib_node_index_t path_list_index,
394 fib_node_back_walk_ctx_t *ctx)
396 fib_path_list_t *path_list;
398 path_list = fib_path_list_get(path_list_index);
401 * propagate the backwalk further
403 if (32 >= fib_node_list_get_size(path_list->fpl_node.fn_children))
406 * only a few children. continue the walk synchronously
408 fib_walk_sync(FIB_NODE_TYPE_PATH_LIST, path_list_index, ctx);
413 * many children. schedule a async walk
415 fib_walk_async(FIB_NODE_TYPE_PATH_LIST,
417 FIB_WALK_PRIORITY_LOW,
423 * fib_path_list_back_walk_notify
425 * A back walk has reach this path-list.
427 static fib_node_back_walk_rc_t
428 fib_path_list_back_walk_notify (fib_node_t *node,
429 fib_node_back_walk_ctx_t *ctx)
432 * the path-list is not a direct child of any other node type
433 * paths, which do not change thier to-list-mapping, save the
434 * list they are a member of, and invoke the BW function directly.
438 return (FIB_NODE_BACK_WALK_CONTINUE);
442 * The FIB path-list's graph node virtual function table
444 static const fib_node_vft_t fib_path_list_vft = {
445 .fnv_get = fib_path_list_get_node,
446 .fnv_last_lock = fib_path_list_last_lock_gone,
447 .fnv_back_walk = fib_path_list_back_walk_notify,
450 static fib_path_list_t *
451 fib_path_list_alloc (fib_node_index_t *path_list_index)
453 fib_path_list_t *path_list;
455 pool_get(fib_path_list_pool, path_list);
456 memset(path_list, 0, sizeof(*path_list));
458 fib_node_init(&path_list->fpl_node,
459 FIB_NODE_TYPE_PATH_LIST);
461 if (NULL != path_list_index)
463 *path_list_index = fib_path_list_get_index(path_list);
466 FIB_PATH_LIST_DBG(path_list, "alloc");
471 static fib_path_list_t *
472 fib_path_list_resolve (fib_path_list_t *path_list)
474 fib_node_index_t *path_index, *paths, path_list_index;
476 ASSERT(!(path_list->fpl_flags & FIB_PATH_LIST_FLAG_RESOLVED));
479 * resolving a path-list is a recursive action. this means more path
480 * lists can be created during this call, and hence this path-list
481 * can be realloc'd. so we work with copies.
482 * this function is called only once per-path list, so its no great overhead.
484 path_list_index = fib_path_list_get_index(path_list);
485 paths = vec_dup(path_list->fpl_paths);
487 vec_foreach (path_index, paths)
489 fib_path_resolve(*path_index);
493 path_list = fib_path_list_get(path_list_index);
495 FIB_PATH_LIST_DBG(path_list, "resovled");
501 fib_path_list_get_resolving_interface (fib_node_index_t path_list_index)
503 fib_node_index_t *path_index;
504 fib_path_list_t *path_list;
507 path_list = fib_path_list_get(path_list_index);
510 vec_foreach (path_index, path_list->fpl_paths)
512 sw_if_index = fib_path_get_resolving_interface(*path_index);
513 if (~0 != sw_if_index)
515 return (sw_if_index);
519 return (sw_if_index);
523 fib_path_list_is_looped (fib_node_index_t path_list_index)
525 fib_path_list_t *path_list;
527 path_list = fib_path_list_get(path_list_index);
529 return (path_list->fpl_flags & FIB_PATH_LIST_FLAG_LOOPED);
532 static fib_path_cfg_flags_t
533 fib_path_list_flags_2_path_flags (fib_path_list_flags_t plf)
535 fib_path_cfg_flags_t pf = FIB_PATH_CFG_FLAG_NONE;
537 if (plf & FIB_PATH_LIST_FLAG_LOCAL)
539 pf |= FIB_PATH_CFG_FLAG_LOCAL;
541 if (plf & FIB_PATH_LIST_FLAG_DROP)
543 pf |= FIB_PATH_CFG_FLAG_DROP;
545 if (plf & FIB_PATH_LIST_FLAG_EXCLUSIVE)
547 pf |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
553 static fib_path_list_flags_t
554 fib_path_list_flags_fixup (fib_path_list_flags_t flags)
557 * we do no share drop nor exclusive path-lists
559 if (flags & FIB_PATH_LIST_FLAG_DROP ||
560 flags & FIB_PATH_LIST_FLAG_EXCLUSIVE)
562 flags &= ~FIB_PATH_LIST_FLAG_SHARED;
569 fib_path_list_create (fib_path_list_flags_t flags,
570 const fib_route_path_t *rpaths)
572 fib_node_index_t path_list_index, old_path_list_index;
573 fib_path_list_t *path_list;
576 flags = fib_path_list_flags_fixup(flags);
577 path_list = fib_path_list_alloc(&path_list_index);
578 path_list->fpl_flags = flags;
580 * we'll assume for now all paths are the same next-hop protocol
582 path_list->fpl_nh_proto = rpaths[0].frp_proto;
584 vec_foreach_index(i, rpaths)
586 vec_add1(path_list->fpl_paths,
587 fib_path_create(path_list_index,
588 path_list->fpl_nh_proto,
589 fib_path_list_flags_2_path_flags(flags),
594 * If a shared path list is requested, consult the DB for a match
596 if (flags & FIB_PATH_LIST_FLAG_SHARED)
599 * check for a matching path-list in the DB.
600 * If we find one then we can return the existing one and destroy the
601 * new one just created.
603 old_path_list_index = fib_path_list_db_find(path_list);
604 if (FIB_NODE_INDEX_INVALID != old_path_list_index)
606 fib_path_list_destroy(path_list);
608 path_list_index = old_path_list_index;
613 * if there was not a matching path-list, then this
614 * new one will need inserting into the DB and resolving.
616 fib_path_list_db_insert(path_list_index);
617 path_list = fib_path_list_resolve(path_list);
623 * no shared path list requested. resolve and use the one
626 path_list = fib_path_list_resolve(path_list);
629 return (path_list_index);
633 fib_path_list_create_special (fib_protocol_t nh_proto,
634 fib_path_list_flags_t flags,
637 fib_node_index_t path_index, path_list_index;
638 fib_path_list_t *path_list;
640 path_list = fib_path_list_alloc(&path_list_index);
641 path_list->fpl_flags = flags;
642 path_list->fpl_nh_proto = nh_proto;
645 fib_path_create_special(path_list_index,
646 path_list->fpl_nh_proto,
647 fib_path_list_flags_2_path_flags(flags),
649 vec_add1(path_list->fpl_paths, path_index);
652 * we don't share path-lists. we can do PIC on them so why bother.
654 path_list = fib_path_list_resolve(path_list);
656 return (path_list_index);
660 * fib_path_list_copy_and_path_add
662 * Create a copy of a path-list and append one more path to it.
663 * The path-list returned could either have been newly created, or
664 * can be a shared path-list from the data-base.
667 fib_path_list_copy_and_path_add (fib_node_index_t orig_path_list_index,
668 fib_path_list_flags_t flags,
669 const fib_route_path_t *rpaths)
671 fib_node_index_t path_index, path_list_index, *orig_path_index;
672 fib_path_list_t *path_list, *orig_path_list;
675 ASSERT(1 == vec_len(rpaths));
678 * alloc the new list before we retrieve the old one, lest
679 * the alloc result in a realloc
681 path_list = fib_path_list_alloc(&path_list_index);
683 orig_path_list = fib_path_list_get(orig_path_list_index);
685 FIB_PATH_LIST_DBG(orig_path_list, "copy-add");
687 flags = fib_path_list_flags_fixup(flags);
688 path_list->fpl_flags = flags;
689 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
690 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths));
693 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
695 path_index = fib_path_copy(*orig_path_index, path_list_index);
696 path_list->fpl_paths[pi++] = path_index;
698 path_index = fib_path_create(path_list_index,
699 path_list->fpl_nh_proto,
700 fib_path_list_flags_2_path_flags(flags),
702 path_list->fpl_paths[pi] = path_index;
705 * we sort the paths since the key for the path-list is
706 * the description of the paths it contains. The paths need to
707 * be sorted else this description will differ.
709 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
711 FIB_PATH_LIST_DBG(path_list, "path-added");
714 * If a shared path list is requested, consult the DB for a match
716 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
718 fib_node_index_t exist_path_list_index;
720 * check for a matching path-list in the DB.
721 * If we find one then we can return the existing one and destroy the
722 * new one just created.
724 exist_path_list_index = fib_path_list_db_find(path_list);
725 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
727 fib_path_list_destroy(path_list);
729 path_list_index = exist_path_list_index;
734 * if there was not a matching path-list, then this
735 * new one will need inserting into the DB and resolving.
737 fib_path_list_db_insert(path_list_index);
739 path_list = fib_path_list_resolve(path_list);
745 * no shared path list requested. resolve and use the one
748 path_list = fib_path_list_resolve(path_list);
751 return (path_list_index);
755 * fib_path_list_copy_and_path_remove
757 * Copy the path-list excluding the path passed.
758 * If the path is the last one, then the index reurned will be invalid.
759 * i.e. the path-list is toast.
762 fib_path_list_copy_and_path_remove (fib_node_index_t orig_path_list_index,
763 fib_path_list_flags_t flags,
764 const fib_route_path_t *rpaths)
766 fib_node_index_t path_index, *orig_path_index, path_list_index, tmp_path_index;
767 fib_path_list_t *path_list, *orig_path_list;
770 ASSERT(1 == vec_len(rpaths));
772 path_list = fib_path_list_alloc(&path_list_index);
774 flags = fib_path_list_flags_fixup(flags);
775 orig_path_list = fib_path_list_get(orig_path_list_index);
777 FIB_PATH_LIST_DBG(orig_path_list, "copy-remove");
779 path_list->fpl_flags = flags;
780 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
782 * allocate as many paths as we might need in one go, rather than
783 * using vec_add to do a few at a time.
785 if (vec_len(orig_path_list->fpl_paths) > 1)
787 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths) - 2);
792 * create a representation of the path to be removed, so it
793 * can be used as a comparison object during the copy.
795 tmp_path_index = fib_path_create(path_list_index,
796 path_list->fpl_nh_proto,
797 fib_path_list_flags_2_path_flags(flags),
800 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
802 if (0 != fib_path_cmp(tmp_path_index, *orig_path_index)) {
803 path_index = fib_path_copy(*orig_path_index, path_list_index);
804 if (pi < vec_len(path_list->fpl_paths))
806 path_list->fpl_paths[pi++] = path_index;
811 * this is the unlikely case that the path being
812 * removed does not match one in the path-list, so
813 * we end up with as many paths as we started with.
814 * the paths vector was sized above with the expectation
815 * that we would have 1 less.
817 vec_add1(path_list->fpl_paths, path_index);
823 * done with the temporary now
825 fib_path_destroy(tmp_path_index);
828 * if there are no paths, then the new path-list is aborted
830 if (0 == vec_len(path_list->fpl_paths)) {
831 FIB_PATH_LIST_DBG(path_list, "last-path-removed");
833 fib_path_list_destroy(path_list);
835 path_list_index = FIB_NODE_INDEX_INVALID;
838 * we sort the paths since the key for the path-list is
839 * the description of the paths it contains. The paths need to
840 * be sorted else this description will differ.
842 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
845 * If a shared path list is requested, consult the DB for a match
847 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
849 fib_node_index_t exist_path_list_index;
852 * check for a matching path-list in the DB.
853 * If we find one then we can return the existing one and destroy the
854 * new one just created.
856 exist_path_list_index = fib_path_list_db_find(path_list);
857 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
859 fib_path_list_destroy(path_list);
861 path_list_index = exist_path_list_index;
866 * if there was not a matching path-list, then this
867 * new one will need inserting into the DB and resolving.
869 fib_path_list_db_insert(path_list_index);
871 path_list = fib_path_list_resolve(path_list);
877 * no shared path list requested. resolve and use the one
880 path_list = fib_path_list_resolve(path_list);
884 return (path_list_index);
888 * fib_path_list_contribute_forwarding
890 * Return the index of a load-balance that user of this path-list should
894 fib_path_list_contribute_forwarding (fib_node_index_t path_list_index,
895 fib_forward_chain_type_t type,
898 fib_path_list_t *path_list;
900 path_list = fib_path_list_get(path_list_index);
902 fib_path_list_mk_lb(path_list, type, dpo);
906 * fib_path_list_get_adj
908 * Return the index of a adjacency for the first path that user of this
909 * path-list should use for forwarding
912 fib_path_list_get_adj (fib_node_index_t path_list_index,
913 fib_forward_chain_type_t type)
915 fib_path_list_t *path_list;
917 path_list = fib_path_list_get(path_list_index);
918 return (fib_path_get_adj(path_list->fpl_paths[0]));
922 fib_path_list_recursive_loop_detect (fib_node_index_t path_list_index,
923 fib_node_index_t **entry_indicies)
925 fib_node_index_t *path_index;
926 int is_looped, list_looped;
927 fib_path_list_t *path_list;
930 path_list = fib_path_list_get(path_list_index);
932 vec_foreach (path_index, path_list->fpl_paths)
934 fib_node_index_t *copy, **copy_ptr;
937 * we need a copy of the nodes visited so that when we add entries
938 * we explore on the nth path and a looped is detected, those entries
939 * are not again searched for n+1 path and so finding a loop that does
942 copy = vec_dup(*entry_indicies);
945 is_looped = fib_path_recursive_loop_detect(*path_index, copy_ptr);
946 list_looped += is_looped;
949 FIB_PATH_LIST_DBG(path_list, "loop-detect: eval:%d", eval);
953 path_list->fpl_flags |= FIB_PATH_LIST_FLAG_LOOPED;
957 path_list->fpl_flags &= ~FIB_PATH_LIST_FLAG_LOOPED;
960 return (list_looped);
964 fib_path_list_child_add (fib_node_index_t path_list_index,
965 fib_node_type_t child_type,
966 fib_node_index_t child_index)
968 return (fib_node_child_add(FIB_NODE_TYPE_PATH_LIST,
975 fib_path_list_child_remove (fib_node_index_t path_list_index,
978 fib_node_child_remove(FIB_NODE_TYPE_PATH_LIST,
984 fib_path_list_lock(fib_node_index_t path_list_index)
986 fib_path_list_t *path_list;
988 if (FIB_NODE_INDEX_INVALID != path_list_index)
990 path_list = fib_path_list_get(path_list_index);
992 fib_node_lock(&path_list->fpl_node);
993 FIB_PATH_LIST_DBG(path_list, "lock");
998 fib_path_list_unlock (fib_node_index_t path_list_index)
1000 fib_path_list_t *path_list;
1002 if (FIB_NODE_INDEX_INVALID != path_list_index)
1004 path_list = fib_path_list_get(path_list_index);
1005 FIB_PATH_LIST_DBG(path_list, "unlock");
1007 fib_node_unlock(&path_list->fpl_node);
1012 fib_path_list_pool_size (void)
1014 return (pool_elts(fib_path_list_pool));
1018 fib_path_list_db_size (void)
1020 return (hash_elts(fib_path_list_db));
1024 fib_path_list_walk (fib_node_index_t path_list_index,
1025 fib_path_list_walk_fn_t func,
1028 fib_node_index_t *path_index;
1029 fib_path_list_t *path_list;
1031 path_list = fib_path_list_get(path_list_index);
1033 vec_foreach(path_index, path_list->fpl_paths)
1035 if (!func(path_list_index, *path_index, ctx))
1042 fib_path_list_module_init (void)
1044 fib_node_register_type (FIB_NODE_TYPE_PATH_LIST, &fib_path_list_vft);
1046 fib_path_list_db = hash_create2 (/* elts */ 0,
1048 /* value_bytes */ sizeof (fib_node_index_t),
1049 fib_path_list_db_hash_key_sum,
1050 fib_path_list_db_hash_key_equal,
1051 /* format pair/arg */
1055 static clib_error_t *
1056 show_fib_path_list_command (vlib_main_t * vm,
1057 unformat_input_t * input,
1058 vlib_cli_command_t * cmd)
1060 fib_path_list_t *path_list;
1061 fib_node_index_t pli;
1063 if (unformat (input, "%d", &pli))
1066 * show one in detail
1068 if (!pool_is_free_index(fib_path_list_pool, pli))
1070 path_list = fib_path_list_get(pli);
1071 u8 *s = fib_path_list_format(pli, NULL);
1072 s = format(s, "children:");
1073 s = fib_node_children_format(path_list->fpl_node.fn_children, s);
1074 vlib_cli_output (vm, "%s", s);
1079 vlib_cli_output (vm, "path list %d invalid", pli);
1087 vlib_cli_output (vm, "FIB Path Lists");
1088 pool_foreach(path_list, fib_path_list_pool,
1090 vlib_cli_output (vm, "%U", format_fib_path_list, path_list);
1096 VLIB_CLI_COMMAND (show_fib_path_list, static) = {
1097 .path = "show fib path list",
1098 .function = show_fib_path_list_command,
1099 .short_help = "show fib path list",