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 u16 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 const fib_route_path_t *rpath);
214 extern fib_node_index_t mfib_table_entry_paths_update(u32 fib_index,
215 const mfib_prefix_t *prefix,
216 mfib_source_t source,
217 const fib_route_path_t *rpath);
221 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
222 * last path, then the entry will be removed, unless it has other sources.
223 * See the documentation for fib_route_path_t for more descirptions of
224 * the path parameters.
227 * The index of the FIB
230 * The prefix for the entry to add
233 * The ID of the client/source adding the entry.
238 extern void mfib_table_entry_path_remove(u32 fib_index,
239 const mfib_prefix_t *prefix,
240 mfib_source_t source,
241 const fib_route_path_t *paths);
242 extern void mfib_table_entry_paths_remove(u32 fib_index,
243 const mfib_prefix_t *prefix,
244 mfib_source_t source,
245 const fib_route_path_t *paths);
251 * Delete a FIB entry. If the entry has no more sources, then it is
252 * removed from the table.
255 * The index of the FIB
258 * The prefix for the entry to remove
261 * The ID of the client/source adding the entry.
263 extern void mfib_table_entry_delete(u32 fib_index,
264 const mfib_prefix_t *prefix,
265 mfib_source_t source);
269 * Delete a FIB entry. If the entry has no more sources, then it is
270 * removed from the table.
273 * The index of the FIB entry
276 * The ID of the client/source adding the entry.
278 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
279 mfib_source_t source);
283 * Add a 'special' entry to the mFIB that links to the DPO passed
284 * A special entry is an entry that the FIB is not expect to resolve
285 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
286 * Instead the client/source provides the index of a replicate DPO to link to.
289 * The index of the FIB
295 * The ID of the client/source adding the entry.
298 * Flags for the entry.
301 * The replicate DPO index to link to.
304 * the index of the fib_entry_t that is created (or existed already).
306 extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index,
307 const mfib_prefix_t *prefix,
308 mfib_source_t source,
309 mfib_entry_flags_t flags,
314 * Flush all entries from a table for the source
317 * The index of the FIB
320 * The protocol of the entries in the table
323 * the source to flush
325 extern void mfib_table_flush(u32 fib_index,
326 fib_protocol_t proto,
327 mfib_source_t source);
331 * Resync all entries from a table for the source
332 * this is the mark part of the mark and sweep algorithm.
333 * All entries in this FIB that are sourced by 'source' are marked
337 * The index of the FIB
340 * The protocol of the entries in the table
343 * the source to flush
345 extern void mfib_table_mark(u32 fib_index,
346 fib_protocol_t proto,
347 mfib_source_t source);
351 * Signal that the table has converged, i.e. all updates are complete.
352 * this is the sweep part of the mark and sweep algorithm.
353 * All entries in this FIB that are sourced by 'source' and marked
354 * as stale are flushed.
357 * The index of the FIB
360 * The protocol of the entries in the table
363 * the source to flush
365 extern void mfib_table_sweep(u32 fib_index,
366 fib_protocol_t proto,
367 mfib_source_t source);
371 * Get the index of the FIB bound to the interface
374 * The protocol of the FIB (and thus the entries therein)
377 * The interface index
380 * The index of the FIB
382 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
387 * Get the Table-ID of the FIB from protocol and index
393 * The protocol of the FIB (and thus the entries therein)
396 * The tableID of the FIB
398 extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
402 * Get the index of the FIB for a Table-ID. This DOES NOT create the
403 * FIB if it does not exist.
406 * The protocol of the FIB (and thus the entries therein)
412 * The index of the FIB, which may be INVALID.
414 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
418 * Get the Table-ID of the FIB from protocol and index
424 * The protocol of the FIB (and thus the entries therein)
427 * The tableID of the FIB
429 extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
433 * Get the index of the FIB for a Table-ID. This DOES create the
434 * FIB if it does not exist.
437 * The protocol of the FIB (and thus the entries therein)
443 * The index of the FIB
446 * The ID of the client/source.
448 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
450 mfib_source_t source);
454 * Get the index of the FIB for a Table-ID. This DOES create the
455 * FIB if it does not exist.
458 * The protocol of the FIB (and thus the entries therein)
464 * The index of the FIB
467 * The ID of the client/source.
470 * The client is choosing the name they want the table to have
472 extern u32 mfib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
474 mfib_source_t source,
480 * Take a reference counting lock on the table
483 * The index of the FIB
486 * The protocol of the FIB (and thus the entries therein)
489 * The ID of the client/source.
491 extern void mfib_table_unlock(u32 fib_index,
492 fib_protocol_t proto,
493 mfib_source_t source);
497 * Release a reference counting lock on the table. When the last lock
498 * has gone. the FIB is deleted.
501 * The index of the FIB
504 * The protocol of the FIB (and thus the entries therein)
507 * The ID of the client/source.
509 extern void mfib_table_lock(u32 fib_index,
510 fib_protocol_t proto,
511 mfib_source_t source);
515 * Return the number of entries in the FIB added by a given source.
518 * The index of the FIB
521 * The protocol of the FIB (and thus the entries therein)
523 * @return number of sourced entries.
525 extern u32 mfib_table_get_num_entries(u32 fib_index,
526 fib_protocol_t proto);
530 * Get the less specific (covering) prefix
533 * The index of the FIB
536 * The prefix to lookup
539 * The index of the less specific fib_entry_t.
541 extern fib_node_index_t mfib_table_get_less_specific(u32 fib_index,
542 const mfib_prefix_t *prefix);
546 * Get a pointer to a FIB table
548 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
549 fib_protocol_t proto);
552 * @brief Call back function when walking entries in a FIB table
554 typedef walk_rc_t (*mfib_table_walk_fn_t)(fib_node_index_t fei,
558 * @brief Walk all entries in a FIB table
559 * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
560 * table and store elements in a vector, then delete the elements
562 extern void mfib_table_walk(u32 fib_index,
563 fib_protocol_t proto,
564 mfib_table_walk_fn_t fn,
567 * @brief format (display) the memory usage for mfibs
569 extern u8 * format_mfib_table_memory(u8 * s, va_list * args);
574 extern u32 mfib_table_get_n_routes(fib_node_index_t index,
575 fib_protocol_t proto);