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
32 * Flags for the source data
34 typedef enum mfib_table_attribute_t_ {
36 * Marker. Add new values after this one.
38 MFIB_TABLE_ATTRIBUTE_FIRST,
40 * the table is currently resync-ing
42 MFIB_TABLE_ATTRIBUTE_RESYNC = MFIB_TABLE_ATTRIBUTE_FIRST,
44 * Marker. add new entries before this one.
46 MFIB_TABLE_ATTRIBUTE_LAST = MFIB_TABLE_ATTRIBUTE_RESYNC,
47 } mfib_table_attribute_t;
49 #define MFIB_TABLE_ATTRIBUTE_MAX (MFIB_TABLE_ATTRIBUTE_LAST+1)
51 #define MFIB_TABLE_ATTRIBUTES { \
52 [MFIB_TABLE_ATTRIBUTE_RESYNC] = "resync", \
55 #define FOR_EACH_MFIB_TABLE_ATTRIBUTE(_item) \
56 for (_item = MFIB_TABLE_ATTRIBUTE_FIRST; \
57 _item < MFIB_TABLE_ATTRIBUTE_MAX; \
60 typedef enum mfib_table_flags_t_ {
61 MFIB_TABLE_FLAG_NONE = 0,
62 MFIB_TABLE_FLAG_RESYNC = (1 << MFIB_TABLE_ATTRIBUTE_RESYNC),
63 } __attribute__ ((packed)) mfib_table_flags_t;
65 extern u8* format_mfib_table_flags(u8 *s, va_list *args);
69 * A protocol Independent IP multicast FIB table
71 typedef struct mfib_table_t_
74 * Required for pool_get_aligned
76 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
79 * A union of the protocol specific FIBs that provide the
80 * underlying LPM mechanism.
81 * This element is first in the struct so that it is in the
90 * Which protocol this table serves. Used to switch on the union above.
92 fib_protocol_t mft_proto;
97 mfib_table_flags_t mft_flags;
100 * number of locks on the table
102 u32 mft_locks[MFIB_TABLE_N_LOCKS];
105 * Table ID (hash key) for this FIB.
115 * Index into FIB vector.
117 fib_node_index_t mft_index;
120 * Total route counters
122 u32 mft_total_route_counts;
132 * Format the description/name of the table
134 extern u8* format_mfib_table_name(u8* s, va_list *ap);
138 * Perfom a longest prefix match in the non-forwarding table
141 * The index of the FIB
144 * The prefix to lookup
147 * The index of the fib_entry_t for the best match, which may be the default route
149 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
150 const mfib_prefix_t *prefix);
154 * Perfom an exact match in the non-forwarding table
157 * The index of the FIB
160 * The prefix to lookup
163 * The index of the fib_entry_t for the exact match, or INVALID
164 * is there is no match.
166 extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
167 const mfib_prefix_t *prefix);
171 * Add a new (with no replication) or lock an existing entry
174 * The prefix for the entry to add
177 * the index of the fib_entry_t that is created (or existed already).
179 extern fib_node_index_t mfib_table_entry_update(u32 fib_index,
180 const mfib_prefix_t *prefix,
181 mfib_source_t source,
183 mfib_entry_flags_t flags);
187 * Add n paths to an entry (aka route) in the FIB. If the entry does not
188 * exist, it will be created.
189 * See the documentation for fib_route_path_t for more descirptions of
190 * the path parameters.
193 * The index of the FIB
196 * The prefix for the entry to add
199 * The ID of the client/source adding the entry.
202 * Flags for the entry.
208 * the index of the fib_entry_t that is created (or existed already).
210 extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index,
211 const mfib_prefix_t *prefix,
212 mfib_source_t source,
213 mfib_entry_flags_t entry_flags,
214 const fib_route_path_t *rpath);
215 extern fib_node_index_t mfib_table_entry_paths_update(u32 fib_index,
216 const mfib_prefix_t *prefix,
217 mfib_source_t source,
218 mfib_entry_flags_t entry_flags,
219 const fib_route_path_t *rpath);
223 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
224 * last path, then the entry will be removed, unless it has other sources.
225 * See the documentation for fib_route_path_t for more descirptions of
226 * the path parameters.
229 * The index of the FIB
232 * The prefix for the entry to add
235 * The ID of the client/source adding the entry.
240 extern void mfib_table_entry_path_remove(u32 fib_index,
241 const mfib_prefix_t *prefix,
242 mfib_source_t source,
243 const fib_route_path_t *paths);
244 extern void mfib_table_entry_paths_remove(u32 fib_index,
245 const mfib_prefix_t *prefix,
246 mfib_source_t source,
247 const fib_route_path_t *paths);
253 * Delete a FIB entry. If the entry has no more sources, then it is
254 * removed from the table.
257 * The index of the FIB
260 * The prefix for the entry to remove
263 * The ID of the client/source adding the entry.
265 extern void mfib_table_entry_delete(u32 fib_index,
266 const mfib_prefix_t *prefix,
267 mfib_source_t source);
271 * Delete a FIB entry. If the entry has no more sources, then it is
272 * removed from the table.
275 * The index of the FIB entry
278 * The ID of the client/source adding the entry.
280 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
281 mfib_source_t source);
285 * Add a 'special' entry to the mFIB that links to the DPO passed
286 * A special entry is an entry that the FIB is not expect to resolve
287 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
288 * Instead the client/source provides the index of a replicate DPO to link to.
291 * The index of the FIB
297 * The ID of the client/source adding the entry.
300 * Flags for the entry.
303 * The replicate DPO index to link to.
306 * the index of the fib_entry_t that is created (or existed already).
308 extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index,
309 const mfib_prefix_t *prefix,
310 mfib_source_t source,
311 mfib_entry_flags_t flags,
316 * Flush all entries from a table for the source
319 * The index of the FIB
322 * The protocol of the entries in the table
325 * the source to flush
327 extern void mfib_table_flush(u32 fib_index,
328 fib_protocol_t proto,
329 mfib_source_t source);
333 * Resync all entries from a table for the source
334 * this is the mark part of the mark and sweep algorithm.
335 * All entries in this FIB that are sourced by 'source' are marked
339 * The index of the FIB
342 * The protocol of the entries in the table
345 * the source to flush
347 extern void mfib_table_mark(u32 fib_index,
348 fib_protocol_t proto,
349 mfib_source_t source);
353 * Signal that the table has converged, i.e. all updates are complete.
354 * this is the sweep part of the mark and sweep algorithm.
355 * All entries in this FIB that are sourced by 'source' and marked
356 * as stale are flushed.
359 * The index of the FIB
362 * The protocol of the entries in the table
365 * the source to flush
367 extern void mfib_table_sweep(u32 fib_index,
368 fib_protocol_t proto,
369 mfib_source_t source);
373 * Get the index of the FIB bound to the interface
376 * The protocol of the FIB (and thus the entries therein)
379 * The interface index
382 * The index of the FIB
384 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
389 * Get the Table-ID of the FIB from protocol and index
395 * The protocol of the FIB (and thus the entries therein)
398 * The tableID of the FIB
400 extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
404 * Get the index of the FIB for a Table-ID. This DOES NOT create the
405 * FIB if it does not exist.
408 * The protocol of the FIB (and thus the entries therein)
414 * The index of the FIB, which may be INVALID.
416 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
420 * Get the Table-ID of the FIB from protocol and index
426 * The protocol of the FIB (and thus the entries therein)
429 * The tableID of the FIB
431 extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
435 * Get the index of the FIB for a Table-ID. This DOES create the
436 * FIB if it does not exist.
439 * The protocol of the FIB (and thus the entries therein)
445 * The index of the FIB
448 * The ID of the client/source.
450 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
452 mfib_source_t source);
456 * Get the index of the FIB for a Table-ID. This DOES create the
457 * FIB if it does not exist.
460 * The protocol of the FIB (and thus the entries therein)
466 * The index of the FIB
469 * The ID of the client/source.
472 * The client is choosing the name they want the table to have
474 extern u32 mfib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
476 mfib_source_t source,
482 * Take a reference counting lock on the table
485 * The index of the FIB
488 * The protocol of the FIB (and thus the entries therein)
491 * The ID of the client/source.
493 extern void mfib_table_unlock(u32 fib_index,
494 fib_protocol_t proto,
495 mfib_source_t source);
499 * Release a reference counting lock on the table. When the last lock
500 * has gone. the FIB is deleted.
503 * The index of the FIB
506 * The protocol of the FIB (and thus the entries therein)
509 * The ID of the client/source.
511 extern void mfib_table_lock(u32 fib_index,
512 fib_protocol_t proto,
513 mfib_source_t source);
517 * Return the number of entries in the FIB added by a given source.
520 * The index of the FIB
523 * The protocol of the FIB (and thus the entries therein)
525 * @return number of sourced entries.
527 extern u32 mfib_table_get_num_entries(u32 fib_index,
528 fib_protocol_t proto);
532 * Get the less specific (covering) prefix
535 * The index of the FIB
538 * The prefix to lookup
541 * The index of the less specific fib_entry_t.
543 extern fib_node_index_t mfib_table_get_less_specific(u32 fib_index,
544 const mfib_prefix_t *prefix);
548 * Get a pointer to a FIB table
550 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
551 fib_protocol_t proto);
554 * @brief Call back function when walking entries in a FIB table
556 typedef walk_rc_t (*mfib_table_walk_fn_t)(fib_node_index_t fei,
560 * @brief Walk all entries in a FIB table
561 * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
562 * table and store elements in a vector, then delete the elements
564 extern void mfib_table_walk(u32 fib_index,
565 fib_protocol_t proto,
566 mfib_table_walk_fn_t fn,
569 * @brief format (display) the memory usage for mfibs
571 extern u8 * format_mfib_table_memory(u8 * s, va_list * args);
576 extern u32 mfib_table_get_n_routes(fib_node_index_t index,
577 fib_protocol_t proto);