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 #ifndef __MFIB_TABLE_H__
17 #define __MFIB_TABLE_H__
19 #include <vnet/ip/ip.h>
20 #include <vnet/adj/adj.h>
21 #include <vnet/dpo/replicate_dpo.h>
23 #include <vnet/mfib/mfib_types.h>
27 * A protocol Independent IP multicast FIB table
29 typedef struct mfib_table_t_
32 * A union of the protocol specific FIBs that provide the
33 * underlying LPM mechanism.
34 * This element is first in the struct so that it is in the
43 * Which protocol this table serves. Used to switch on the union above.
45 fib_protocol_t mft_proto;
48 * number of locks on the table
53 * Table ID (hash key) for this FIB.
58 * Index into FIB vector.
60 fib_node_index_t mft_index;
63 * Total route counters
65 u32 mft_total_route_counts;
75 * Format the description/name of the table
77 extern u8* format_mfib_table_name(u8* s, va_list ap);
81 * Perfom a longest prefix match in the non-forwarding table
84 * The index of the FIB
87 * The prefix to lookup
90 * The index of the fib_entry_t for the best match, which may be the default route
92 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
93 const mfib_prefix_t *prefix);
97 * Perfom an exact match in the non-forwarding table
100 * The index of the FIB
103 * The prefix to lookup
106 * The index of the fib_entry_t for the exact match, or INVALID
107 * is there is no match.
109 extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
110 const mfib_prefix_t *prefix);
114 * Add a new (with no replication) or lock an existing entry
117 * The prefix for the entry to add
120 * the index of the fib_entry_t that is created (or existed already).
122 extern fib_node_index_t mfib_table_entry_update(u32 fib_index,
123 const mfib_prefix_t *prefix,
124 mfib_source_t source,
126 mfib_entry_flags_t flags);
130 * Add n paths to an entry (aka route) in the FIB. If the entry does not
131 * exist, it will be created.
132 * See the documentation for fib_route_path_t for more descirptions of
133 * the path parameters.
136 * The index of the FIB
139 * The prefix for the entry to add
142 * The ID of the client/source adding the entry.
145 * Flags for the entry.
151 * the index of the fib_entry_t that is created (or existed already).
153 extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index,
154 const mfib_prefix_t *prefix,
155 mfib_source_t source,
156 const fib_route_path_t *rpath,
157 mfib_itf_flags_t flags);
161 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
162 * last path, then the entry will be removed, unless it has other sources.
163 * See the documentation for fib_route_path_t for more descirptions of
164 * the path parameters.
167 * The index of the FIB
170 * The prefix for the entry to add
173 * The ID of the client/source adding the entry.
178 extern void mfib_table_entry_path_remove(u32 fib_index,
179 const mfib_prefix_t *prefix,
180 mfib_source_t source,
181 const fib_route_path_t *paths);
187 * Delete a FIB entry. If the entry has no more sources, then it is
188 * removed from the table.
191 * The index of the FIB
194 * The prefix for the entry to remove
197 * The ID of the client/source adding the entry.
199 extern void mfib_table_entry_delete(u32 fib_index,
200 const mfib_prefix_t *prefix,
201 mfib_source_t source);
205 * Delete a FIB entry. If the entry has no more sources, then it is
206 * removed from the table.
209 * The index of the FIB entry
212 * The ID of the client/source adding the entry.
214 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
215 mfib_source_t source);
219 * Add a 'special' entry to the mFIB that links to the DPO passed
220 * A special entry is an entry that the FIB is not expect to resolve
221 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
222 * Instead the client/source provides the index of a replicate DPO to link to.
225 * The index of the FIB
231 * The ID of the client/source adding the entry.
234 * Flags for the entry.
237 * The replicate DPO index to link to.
240 * the index of the fib_entry_t that is created (or existed already).
242 extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index,
243 const mfib_prefix_t *prefix,
244 mfib_source_t source,
245 mfib_entry_flags_t flags,
250 * Flush all entries from a table for the source
253 * The index of the FIB
256 * The protocol of the entries in the table
259 * the source to flush
261 extern void mfib_table_flush(u32 fib_index,
262 fib_protocol_t proto);
266 * Get the index of the FIB bound to the interface
269 * The protocol of the FIB (and thus the entries therein)
272 * The interface index
275 * The index of the FIB
277 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
282 * Get the index of the FIB for a Table-ID. This DOES NOT create the
283 * FIB if it does not exist.
286 * The protocol of the FIB (and thus the entries therein)
292 * The index of the FIB, which may be INVALID.
294 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
299 * Get the index of the FIB for a Table-ID. This DOES create the
300 * FIB if it does not exist.
303 * The protocol of the FIB (and thus the entries therein)
309 * The index of the FIB
311 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
317 * Take a reference counting lock on the table
320 * The index of the FIB
323 * The protocol of the FIB (and thus the entries therein)
325 extern void mfib_table_unlock(u32 fib_index,
326 fib_protocol_t proto);
330 * Release a reference counting lock on the table. When the last lock
331 * has gone. the FIB is deleted.
334 * The index of the FIB
337 * The protocol of the FIB (and thus the entries therein)
339 extern void mfib_table_lock(u32 fib_index,
340 fib_protocol_t proto);
344 * Return the number of entries in the FIB added by a given source.
347 * The index of the FIB
350 * The protocol of the FIB (and thus the entries therein)
352 * @return number of sourced entries.
354 extern u32 mfib_table_get_num_entries(u32 fib_index,
355 fib_protocol_t proto);
359 * Get a pointer to a FIB table
361 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
362 fib_protocol_t proto);
365 * @brief Call back function when walking entries in a FIB table
367 typedef int (*mfib_table_walk_fn_t)(fib_node_index_t fei,
371 * @brief Walk all entries in a FIB table
372 * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
373 * table and store elements in a vector, then delete the elements
375 extern void mfib_table_walk(u32 fib_index,
376 fib_protocol_t proto,
377 mfib_table_walk_fn_t fn,