2 * Copyright (c) 2018 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/mfib/mfib_entry_delegate.h>
17 #include <vnet/mfib/mfib_entry.h>
19 static mfib_entry_delegate_t *
20 mfib_entry_delegate_find_i (const mfib_entry_t *mfib_entry,
21 mfib_entry_delegate_type_t type,
24 mfib_entry_delegate_t *delegate;
28 vec_foreach(delegate, mfib_entry->fe_delegates)
30 if (delegate->mfd_type == type)
46 mfib_entry_delegate_t *
47 mfib_entry_delegate_get (const mfib_entry_t *mfib_entry,
48 mfib_entry_delegate_type_t type)
50 return (mfib_entry_delegate_find_i(mfib_entry, type, NULL));
54 mfib_entry_delegate_remove (mfib_entry_t *mfib_entry,
55 mfib_entry_delegate_type_t type)
57 mfib_entry_delegate_t *fed;
60 fed = mfib_entry_delegate_find_i(mfib_entry, type, &index);
64 vec_del1(mfib_entry->fe_delegates, index);
68 mfib_entry_delegate_cmp_for_sort (void * v1,
71 mfib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
73 return (delegate1->mfd_type - delegate2->mfd_type);
77 mfib_entry_delegate_init (mfib_entry_t *mfib_entry,
78 mfib_entry_delegate_type_t type)
81 mfib_entry_delegate_t delegate = {
82 .mfd_entry_index = mfib_entry_get_index(mfib_entry),
86 vec_add1(mfib_entry->fe_delegates, delegate);
87 vec_sort_with_function(mfib_entry->fe_delegates,
88 mfib_entry_delegate_cmp_for_sort);
91 mfib_entry_delegate_t *
92 mfib_entry_delegate_find_or_add (mfib_entry_t *mfib_entry,
93 mfib_entry_delegate_type_t fdt)
95 mfib_entry_delegate_t *delegate;
97 delegate = mfib_entry_delegate_get(mfib_entry, fdt);
101 mfib_entry_delegate_init(mfib_entry, fdt);
104 return (mfib_entry_delegate_get(mfib_entry, fdt));
108 * typedef for printing a delegate
110 typedef u8 * (*mfib_entry_delegate_format_t)(const mfib_entry_delegate_t *fed,
114 * Print a delegate that represents cover tracking
117 mfib_entry_delegate_fmt_covered (const mfib_entry_delegate_t *fed,
120 s = format(s, "covered:[");
121 s = fib_node_children_format(fed->mfd_list, s);
128 * A delegate type to formatter map
130 static mfib_entry_delegate_format_t fed_formatters[] =
132 [MFIB_ENTRY_DELEGATE_COVERED] = mfib_entry_delegate_fmt_covered,
136 format_mfib_entry_deletegate (u8 * s, va_list * args)
138 mfib_entry_delegate_t *fed;
140 fed = va_arg (*args, mfib_entry_delegate_t *);
142 return (fed_formatters[fed->mfd_type](fed, s));