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 __FIB_TABLE_H__
17 #define __FIB_TABLE_H__
19 #include <vnet/ip/ip.h>
20 #include <vnet/adj/adj.h>
21 #include <vnet/fib/fib_entry.h>
22 #include <vnet/mpls/mpls.h>
23 #include <vnet/mpls/packet.h>
27 * A protocol Independent FIB table
29 typedef struct fib_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
44 * Which protocol this table serves. Used to switch on the union above.
46 fib_protocol_t ft_proto;
49 * number of locks on the table
54 * Table ID (hash key) for this FIB.
59 * Index into FIB vector.
61 fib_node_index_t ft_index;
64 * flow hash configuration
66 u32 ft_flow_hash_config;
69 * Per-source route counters
71 u32 ft_src_route_counts[FIB_SOURCE_MAX];
74 * Total route counters
76 u32 ft_total_route_counts;
86 * Format the description/name of the table
88 extern u8* format_fib_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 fib_table_lookup(u32 fib_index,
104 const fib_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 fib_table_lookup_exact_match(u32 fib_index,
121 const fib_prefix_t *prefix);
125 * Get the less specific (covering) prefix
128 * The index of the FIB
131 * The prefix to lookup
134 * The index of the less specific fib_entry_t.
136 extern fib_node_index_t fib_table_get_less_specific(u32 fib_index,
137 const fib_prefix_t *prefix);
141 * Add a 'special' entry to the FIB that links to the adj passed
142 * A special entry is an entry that the FIB is not expect to resolve
143 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
144 * Instead the client/source provides the adj to link to.
145 * This add is reference counting per-source. So n 'removes' are required
146 * for n 'adds', if the entry is no longer required.
149 * The index of the FIB
155 * The ID of the client/source adding the entry.
158 * Flags for the entry.
161 * The adjacency to link to.
164 * the index of the fib_entry_t that is created (or exists already).
166 extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
167 const fib_prefix_t *prefix,
169 fib_entry_flag_t flags,
170 adj_index_t adj_index);
174 * Add a 'special' entry to the FIB that links to the DPO passed
175 * A special entry is an entry that the FIB is not expect to resolve
176 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
177 * Instead the client/source provides the DPO to link to.
178 * This add is reference counting per-source. So n 'removes' are required
179 * for n 'adds', if the entry is no longer required.
182 * The index of the FIB
188 * The ID of the client/source adding the entry.
191 * Flags for the entry.
194 * The DPO to link to.
197 * the index of the fib_entry_t that is created (or existed already).
199 extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index,
200 const fib_prefix_t *prefix,
202 fib_entry_flag_t stype,
203 const dpo_id_t *dpo);
207 * Update a 'special' entry to the FIB that links to the DPO passed
208 * A special entry is an entry that the FIB is not expect to resolve
209 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
210 * Instead the client/source provides the DPO to link to.
211 * Special entries are add/remove reference counted per-source. So n
212 * 'removes' are required for n 'adds', if the entry is no longer required.
213 * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add'
214 * is therefore assumed to act on the reference instance of that add.
216 * @param fib_entry_index
217 * The index of the FIB entry to update
220 * The ID of the client/source adding the entry.
223 * Flags for the entry.
226 * The DPO to link to.
229 * the index of the fib_entry_t that is created (or existed already).
231 extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index,
232 const fib_prefix_t *prefix,
234 fib_entry_flag_t stype,
235 const dpo_id_t *dpo);
239 * Remove a 'special' entry from the FIB.
240 * This add is reference counting per-source. So n 'removes' are required
241 * for n 'adds', if the entry is no longer required.
244 * The index of the FIB
247 * The prefix to remove
250 * The ID of the client/source adding the entry.
253 extern void fib_table_entry_special_remove(u32 fib_index,
254 const fib_prefix_t *prefix,
255 fib_source_t source);
259 * Add one path to an entry (aka route) in the FIB. If the entry does not
260 * exist, it will be created.
261 * See the documentation for fib_route_path_t for more descirptions of
262 * the path parameters.
265 * The index of the FIB
268 * The prefix for the entry to add
271 * The ID of the client/source adding the entry.
274 * Flags for the entry.
276 * @paran next_hop_proto
277 * The protocol of the next hop. This cannot be derived in the event that
278 * the next hop is all zeros.
281 * The address of the next-hop.
284 * The index of the interface.
286 * @param next_hop_fib_index,
287 * The fib index of the next-hop for recursive resolution
289 * @param next_hop_weight
290 * [un]equal cost path weight
292 * @param next_hop_label_stack
293 * The path's out-going label stack. NULL is there is none.
299 * the index of the fib_entry_t that is created (or existed already).
301 extern fib_node_index_t fib_table_entry_path_add(u32 fib_index,
302 const fib_prefix_t *prefix,
304 fib_entry_flag_t flags,
305 fib_protocol_t next_hop_proto,
306 const ip46_address_t *next_hop,
307 u32 next_hop_sw_if_index,
308 u32 next_hop_fib_index,
310 mpls_label_t *next_hop_label_stack,
311 fib_route_path_flags_t pf);
314 * Add n paths to an entry (aka route) in the FIB. If the entry does not
315 * exist, it will be created.
316 * See the documentation for fib_route_path_t for more descirptions of
317 * the path parameters.
320 * The index of the FIB
323 * The prefix for the entry to add
326 * The ID of the client/source adding the entry.
329 * Flags for the entry.
332 * A vector of paths. Not const since they may be modified.
335 * the index of the fib_entry_t that is created (or existed already).
337 extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index,
338 const fib_prefix_t *prefix,
340 fib_entry_flag_t flags,
341 fib_route_path_t *rpath);
345 * remove one path to an entry (aka route) in the FIB. If this is the entry's
346 * last path, then the entry will be removed, unless it has other sources.
347 * See the documentation for fib_route_path_t for more descirptions of
348 * the path parameters.
351 * The index of the FIB
354 * The prefix for the entry to add
357 * The ID of the client/source adding the entry.
359 * @paran next_hop_proto
360 * The protocol of the next hop. This cannot be derived in the event that
361 * the next hop is all zeros.
364 * The address of the next-hop.
367 * The index of the interface.
369 * @param next_hop_fib_index,
370 * The fib index of the next-hop for recursive resolution
372 * @param next_hop_weight
373 * [un]equal cost path weight
378 extern void fib_table_entry_path_remove(u32 fib_index,
379 const fib_prefix_t *prefix,
381 fib_protocol_t next_hop_proto,
382 const ip46_address_t *next_hop,
383 u32 next_hop_sw_if_index,
384 u32 next_hop_fib_index,
386 fib_route_path_flags_t pf);
390 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
391 * last path, then the entry will be removed, unless it has other sources.
392 * See the documentation for fib_route_path_t for more descirptions of
393 * the path parameters.
396 * The index of the FIB
399 * The prefix for the entry to add
402 * The ID of the client/source adding the entry.
407 extern void fib_table_entry_path_remove2(u32 fib_index,
408 const fib_prefix_t *prefix,
410 fib_route_path_t *paths);
414 * Update an entry to have a new set of paths. If the entry does not
415 * exist, it will be created.
416 * The difference between an 'path-add' and an update, is that path-add is
417 * an incremental addition of paths, whereas an update is a wholesale swap.
420 * The index of the FIB
423 * The prefix for the entry to add
426 * The ID of the client/source adding the entry.
429 * A vector of paths. Not const since they may be modified.
432 * the index of the fib_entry_t that is created (or existed already).
434 extern fib_node_index_t fib_table_entry_update(u32 fib_index,
435 const fib_prefix_t *prefix,
437 fib_entry_flag_t flags,
438 fib_route_path_t *paths);
442 * Update the entry to have just one path. If the entry does not
443 * exist, it will be created.
444 * See the documentation for fib_route_path_t for more descirptions of
445 * the path parameters.
448 * The index of the FIB
451 * The prefix for the entry to add
454 * The ID of the client/source adding the entry.
457 * Flags for the entry.
459 * @paran next_hop_proto
460 * The protocol of the next hop. This cannot be derived in the event that
461 * the next hop is all zeros.
464 * The address of the next-hop.
467 * The index of the interface.
469 * @param next_hop_fib_index,
470 * The fib index of the next-hop for recursive resolution
472 * @param next_hop_weight
473 * [un]equal cost path weight
475 * @param next_hop_label_stack
476 * The path's out-going label stack. NULL is there is none.
482 * the index of the fib_entry_t that is created (or existed already).
484 extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index,
485 const fib_prefix_t *prefix,
487 fib_entry_flag_t flags,
488 fib_protocol_t next_hop_proto,
489 const ip46_address_t *next_hop,
490 u32 next_hop_sw_if_index,
491 u32 next_hop_fib_index,
493 mpls_label_t *next_hop_label_stack,
494 fib_route_path_flags_t pf);
498 * Add a MPLS local label for the prefix/route. If the entry does not
499 * exist, it will be created. In theory more than one local label can be
500 * added, but this is not yet supported.
503 * The index of the FIB
506 * The prefix for the entry to which to add the label
509 * The MPLS label to add
512 * the index of the fib_entry_t that is created (or existed already).
514 extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index,
515 const fib_prefix_t *prefix,
519 * remove a MPLS local label for the prefix/route.
522 * The index of the FIB
525 * The prefix for the entry to which to add the label
528 * The MPLS label to add
530 extern void fib_table_entry_local_label_remove(u32 fib_index,
531 const fib_prefix_t *prefix,
536 * Delete a FIB entry. If the entry has no more sources, then it is
537 * removed from the table.
540 * The index of the FIB
543 * The prefix for the entry to remove
546 * The ID of the client/source adding the entry.
548 extern void fib_table_entry_delete(u32 fib_index,
549 const fib_prefix_t *prefix,
550 fib_source_t source);
554 * Delete a FIB entry. If the entry has no more sources, then it is
555 * removed from the table.
558 * The index of the FIB entry
561 * The ID of the client/source adding the entry.
563 extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
564 fib_source_t source);
568 * Flush all entries from a table for the source
571 * The index of the FIB
574 * The protocol of the entries in the table
577 * the source to flush
579 extern void fib_table_flush(u32 fib_index,
580 fib_protocol_t proto,
581 fib_source_t source);
585 * Get the index of the FIB bound to the interface
588 * The protocol of the FIB (and thus the entries therein)
591 * The interface index
594 * The index of the FIB
596 extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
601 * Get the Table-ID of the FIB bound to the interface
604 * The protocol of the FIB (and thus the entries therein)
607 * The interface index
610 * The tableID of the FIB
612 extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
617 * Get the index of the FIB for a Table-ID. This DOES NOT create the
618 * FIB if it does not exist.
621 * The protocol of the FIB (and thus the entries therein)
627 * The index of the FIB, which may be INVALID.
629 extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
634 * Get the index of the FIB for a Table-ID. This DOES create the
635 * FIB if it does not exist.
638 * The protocol of the FIB (and thus the entries therein)
644 * The index of the FIB
646 extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
651 * Create a new table with no table ID. This means it does not get
652 * added to the hash-table and so can only be found by using the index returned.
655 * The protocol of the FIB (and thus the entries therein)
658 * A string to describe the table
661 * The index of the FIB
663 extern u32 fib_table_create_and_lock(fib_protocol_t proto,
664 const char *const fmt,
669 * Get the flow hash configured used by the table
672 * The index of the FIB
675 * The protocol of the FIB (and thus the entries therein)
677 * @return The flow hash config
679 extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
680 fib_protocol_t proto);
684 * Take a reference counting lock on the table
687 * The index of the FIB
690 * The protocol of the FIB (and thus the entries therein)
692 extern void fib_table_unlock(u32 fib_index,
693 fib_protocol_t proto);
697 * Release a reference counting lock on the table. When the last lock
698 * has gone. the FIB is deleted.
701 * The index of the FIB
704 * The protocol of the FIB (and thus the entries therein)
706 extern void fib_table_lock(u32 fib_index,
707 fib_protocol_t proto);
711 * Return the number of entries in the FIB added by a given source.
714 * The index of the FIB
717 * The protocol of the FIB (and thus the entries therein)
719 * @return number of sourced entries.
721 extern u32 fib_table_get_num_entries(u32 fib_index,
722 fib_protocol_t proto,
723 fib_source_t source);
727 * Get a pointer to a FIB table
729 extern fib_table_t *fib_table_get(fib_node_index_t index,
730 fib_protocol_t proto);