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>
26 * Keep a lock per-source and a total
28 #define MFIB_TABLE_N_LOCKS (MFIB_N_SOURCES+1)
29 #define MFIB_TABLE_TOTAL_LOCKS MFIB_N_SOURCES
33 * A protocol Independent IP multicast FIB table
35 typedef struct mfib_table_t_
38 * Required for pool_get_aligned
40 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
43 * A union of the protocol specific FIBs that provide the
44 * underlying LPM mechanism.
45 * This element is first in the struct so that it is in the
54 * Which protocol this table serves. Used to switch on the union above.
56 fib_protocol_t mft_proto;
59 * number of locks on the table
61 u16 mft_locks[MFIB_TABLE_N_LOCKS];
64 * Table ID (hash key) for this FIB.
69 * Index into FIB vector.
71 fib_node_index_t mft_index;
74 * Total route counters
76 u32 mft_total_route_counts;
86 * Format the description/name of the table
88 extern u8* format_mfib_table_name(u8* s, va_list *ap);
92 * Perfom a longest prefix match in the non-forwarding table
95 * The index of the FIB
98 * The prefix to lookup
101 * The index of the fib_entry_t for the best match, which may be the default route
103 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
104 const mfib_prefix_t *prefix);
108 * Perfom an exact match in the non-forwarding table
111 * The index of the FIB
114 * The prefix to lookup
117 * The index of the fib_entry_t for the exact match, or INVALID
118 * is there is no match.
120 extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
121 const mfib_prefix_t *prefix);
125 * Add a new (with no replication) or lock an existing entry
128 * The prefix for the entry to add
131 * the index of the fib_entry_t that is created (or existed already).
133 extern fib_node_index_t mfib_table_entry_update(u32 fib_index,
134 const mfib_prefix_t *prefix,
135 mfib_source_t source,
137 mfib_entry_flags_t flags);
141 * Add n paths to an entry (aka route) in the FIB. If the entry does not
142 * exist, it will be created.
143 * See the documentation for fib_route_path_t for more descirptions of
144 * the path parameters.
147 * The index of the FIB
150 * The prefix for the entry to add
153 * The ID of the client/source adding the entry.
156 * Flags for the entry.
162 * the index of the fib_entry_t that is created (or existed already).
164 extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index,
165 const mfib_prefix_t *prefix,
166 mfib_source_t source,
167 const fib_route_path_t *rpath,
168 mfib_itf_flags_t flags);
172 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
173 * last path, then the entry will be removed, unless it has other sources.
174 * See the documentation for fib_route_path_t for more descirptions of
175 * the path parameters.
178 * The index of the FIB
181 * The prefix for the entry to add
184 * The ID of the client/source adding the entry.
189 extern void mfib_table_entry_path_remove(u32 fib_index,
190 const mfib_prefix_t *prefix,
191 mfib_source_t source,
192 const fib_route_path_t *paths);
198 * Delete a FIB entry. If the entry has no more sources, then it is
199 * removed from the table.
202 * The index of the FIB
205 * The prefix for the entry to remove
208 * The ID of the client/source adding the entry.
210 extern void mfib_table_entry_delete(u32 fib_index,
211 const mfib_prefix_t *prefix,
212 mfib_source_t source);
216 * Delete a FIB entry. If the entry has no more sources, then it is
217 * removed from the table.
220 * The index of the FIB entry
223 * The ID of the client/source adding the entry.
225 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
226 mfib_source_t source);
230 * Add a 'special' entry to the mFIB that links to the DPO passed
231 * A special entry is an entry that the FIB is not expect to resolve
232 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
233 * Instead the client/source provides the index of a replicate DPO to link to.
236 * The index of the FIB
242 * The ID of the client/source adding the entry.
245 * Flags for the entry.
248 * The replicate DPO index to link to.
251 * the index of the fib_entry_t that is created (or existed already).
253 extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index,
254 const mfib_prefix_t *prefix,
255 mfib_source_t source,
256 mfib_entry_flags_t flags,
261 * Flush all entries from a table for the source
264 * The index of the FIB
267 * The protocol of the entries in the table
270 * the source to flush
272 extern void mfib_table_flush(u32 fib_index,
273 fib_protocol_t proto,
274 mfib_source_t source);
278 * Get the index of the FIB bound to the interface
281 * The protocol of the FIB (and thus the entries therein)
284 * The interface index
287 * The index of the FIB
289 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
294 * Get the Table-ID of the FIB from protocol and index
300 * The protocol of the FIB (and thus the entries therein)
303 * The tableID of the FIB
305 extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
309 * Get the index of the FIB for a Table-ID. This DOES NOT create the
310 * FIB if it does not exist.
313 * The protocol of the FIB (and thus the entries therein)
319 * The index of the FIB, which may be INVALID.
321 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
326 * Get the index of the FIB for a Table-ID. This DOES create the
327 * FIB if it does not exist.
330 * The protocol of the FIB (and thus the entries therein)
336 * The index of the FIB
339 * The ID of the client/source.
341 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
343 mfib_source_t source);
347 * Get the index of the FIB for a Table-ID. This DOES create the
348 * FIB if it does not exist.
351 * The protocol of the FIB (and thus the entries therein)
357 * The index of the FIB
360 * The ID of the client/source.
363 * The client is choosing the name they want the table to have
365 extern u32 mfib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
367 mfib_source_t source,
373 * Take a reference counting lock on the table
376 * The index of the FIB
379 * The protocol of the FIB (and thus the entries therein)
382 * The ID of the client/source.
384 extern void mfib_table_unlock(u32 fib_index,
385 fib_protocol_t proto,
386 mfib_source_t source);
390 * Release a reference counting lock on the table. When the last lock
391 * has gone. the FIB is deleted.
394 * The index of the FIB
397 * The protocol of the FIB (and thus the entries therein)
400 * The ID of the client/source.
402 extern void mfib_table_lock(u32 fib_index,
403 fib_protocol_t proto,
404 mfib_source_t source);
408 * Return the number of entries in the FIB added by a given source.
411 * The index of the FIB
414 * The protocol of the FIB (and thus the entries therein)
416 * @return number of sourced entries.
418 extern u32 mfib_table_get_num_entries(u32 fib_index,
419 fib_protocol_t proto);
423 * Get the less specific (covering) prefix
426 * The index of the FIB
429 * The prefix to lookup
432 * The index of the less specific fib_entry_t.
434 extern fib_node_index_t mfib_table_get_less_specific(u32 fib_index,
435 const mfib_prefix_t *prefix);
439 * Get a pointer to a FIB table
441 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
442 fib_protocol_t proto);
445 * @brief Call back function when walking entries in a FIB table
447 typedef int (*mfib_table_walk_fn_t)(fib_node_index_t fei,
451 * @brief Walk all entries in a FIB table
452 * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
453 * table and store elements in a vector, then delete the elements
455 extern void mfib_table_walk(u32 fib_index,
456 fib_protocol_t proto,
457 mfib_table_walk_fn_t fn,
460 * @brief format (display) the memory usage for mfibs
462 extern u8 * format_mfib_table_memory(u8 * s, va_list * args);
467 extern u32 mfib_table_get_n_routes(fib_node_index_t index,
468 fib_protocol_t proto);