fib: Table Replace
[vpp.git] / src / vnet / fib / fib_table.h
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #ifndef __FIB_TABLE_H__
17 #define __FIB_TABLE_H__
18
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>
24
25 /**
26  * Keep a lock per-source and a total
27  */
28 #define FIB_TABLE_N_LOCKS (FIB_SOURCE_MAX+1)
29 #define FIB_TABLE_TOTAL_LOCKS FIB_SOURCE_MAX
30
31 /**
32  * Flags for the source data
33  */
34 typedef enum fib_table_attribute_t_ {
35     /**
36      * Marker. Add new values after this one.
37      */
38     FIB_TABLE_ATTRIBUTE_FIRST,
39     /**
40      * the table is for IP6 link local addresses
41      */
42     FIB_TABLE_ATTRIBUTE_IP6_LL = FIB_TABLE_ATTRIBUTE_FIRST,
43     /**
44      * the table is currently resync-ing
45      */
46     FIB_TABLE_ATTRIBUTE_RESYNC,
47     /**
48      * Marker. add new entries before this one.
49      */
50     FIB_TABLE_ATTRIBUTE_LAST = FIB_TABLE_ATTRIBUTE_RESYNC,
51 } fib_table_attribute_t;
52
53 #define FIB_TABLE_ATTRIBUTE_MAX (FIB_TABLE_ATTRIBUTE_LAST+1)
54
55 #define FIB_TABLE_ATTRIBUTES {                   \
56     [FIB_TABLE_ATTRIBUTE_IP6_LL]  = "ip6-ll",    \
57     [FIB_TABLE_ATTRIBUTE_RESYNC]  = "resync",    \
58 }
59
60 #define FOR_EACH_FIB_TABLE_ATTRIBUTE(_item)             \
61     for (_item = FIB_TABLE_ATTRIBUTE_FIRST;             \
62          _item < FIB_TABLE_ATTRIBUTE_MAX;               \
63          _item++)
64
65 typedef enum fib_table_flags_t_ {
66     FIB_TABLE_FLAG_NONE   = 0,
67     FIB_TABLE_FLAG_IP6_LL  = (1 << FIB_TABLE_ATTRIBUTE_IP6_LL),
68     FIB_TABLE_FLAG_RESYNC  = (1 << FIB_TABLE_ATTRIBUTE_RESYNC),
69 } __attribute__ ((packed)) fib_table_flags_t;
70
71 extern u8* format_fib_table_flags(u8 *s, va_list *args);
72
73 /**
74  * @brief 
75  *   A protocol Independent FIB table
76  */
77 typedef struct fib_table_t_
78 {
79     /**
80      * Which protocol this table serves. Used to switch on the union above.
81      */
82     fib_protocol_t ft_proto;
83
84     /**
85      * Table flags
86      */
87     fib_table_flags_t ft_flags;
88
89     /**
90      * per-source number of locks on the table
91      */
92     u16 ft_locks[FIB_TABLE_N_LOCKS];
93
94     /**
95      * Table ID (hash key) for this FIB.
96      */
97     u32 ft_table_id;
98
99     /**
100      * Index into FIB vector.
101      */
102     fib_node_index_t ft_index;
103
104     /**
105      * flow hash configuration
106      */
107     u32 ft_flow_hash_config;
108
109     /**
110      * Per-source route counters
111      */
112     u32 ft_src_route_counts[FIB_SOURCE_MAX];
113
114     /**
115      * Total route counters
116      */
117     u32 ft_total_route_counts;
118
119     /**
120      * Epoch - number of resyncs performed
121      */
122     u32 ft_epoch;
123
124     /**
125      * Table description
126      */
127     u8* ft_desc;
128 } fib_table_t;
129
130 /**
131  * @brief
132  *  Format the description/name of the table
133  */
134 extern u8* format_fib_table_name(u8* s, va_list *ap);
135
136 /**
137  * @brief
138  *  Perfom a longest prefix match in the non-forwarding table
139  *
140  * @param fib_index
141  *  The index of the FIB
142  *
143  * @param prefix
144  *  The prefix to lookup
145  *
146  * @return
147  *  The index of the fib_entry_t for the best match, which may be the default route
148  */
149 extern fib_node_index_t fib_table_lookup(u32 fib_index,
150                                          const fib_prefix_t *prefix);
151
152 /**
153  * @brief
154  *  Perfom an exact match in the non-forwarding table
155  *
156  * @param fib_index
157  *  The index of the FIB
158  *
159  * @param prefix
160  *  The prefix to lookup
161  *
162  * @return
163  *  The index of the fib_entry_t for the exact match, or INVALID
164  *  is there is no match.
165  */
166 extern fib_node_index_t fib_table_lookup_exact_match(u32 fib_index,
167                                                      const fib_prefix_t *prefix);
168
169 /**
170  * @brief
171  *  Get the less specific (covering) prefix
172  *
173  * @param fib_index
174  *  The index of the FIB
175  *
176  * @param prefix
177  *  The prefix to lookup
178  *
179  * @return
180  *  The index of the less specific fib_entry_t.
181  */
182 extern fib_node_index_t fib_table_get_less_specific(u32 fib_index,
183                                                     const fib_prefix_t *prefix);
184
185 /**
186  * @brief
187  *  Add a 'special' entry to the FIB.
188  *  A special entry is an entry that the FIB is not expect to resolve
189  *  via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
190  *  Instead the will link to a DPO valid for the source and/or the flags.
191  *  This add is reference counting per-source. So n 'removes' are required
192  *  for n 'adds', if the entry is no longer required.
193  *  If the source needs to provide non-default forwarding use:
194  *  fib_table_entry_special_dpo_add()
195  *
196  * @param fib_index
197  *  The index of the FIB
198  *
199  * @param prefix
200  *  The prefix to add
201  *
202  * @param source
203  *  The ID of the client/source adding the entry.
204  *
205  * @param flags
206  *  Flags for the entry.
207  *
208  * @return
209  *  the index of the fib_entry_t that is created (or exists already).
210  */
211 extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
212                                                     const fib_prefix_t *prefix,
213                                                     fib_source_t source,
214                                                     fib_entry_flag_t flags);
215
216 /**
217  * @brief
218  *  Add a 'special' entry to the FIB that links to the DPO passed
219  *  A special entry is an entry that the FIB is not expect to resolve
220  *  via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
221  *  Instead the client/source provides the DPO to link to.
222  *  This add is reference counting per-source. So n 'removes' are required
223  *  for n 'adds', if the entry is no longer required.
224  *
225   * @param fib_index
226  *  The index of the FIB
227  *
228  * @param prefix
229  *  The prefix to add
230  *
231  * @param source
232  *  The ID of the client/source adding the entry.
233  *
234  * @param flags
235  *  Flags for the entry.
236  *
237  * @param dpo
238  *  The DPO to link to.
239  *
240  * @return
241  *  the index of the fib_entry_t that is created (or existed already).
242  */
243 extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index,
244                                                         const fib_prefix_t *prefix,
245                                                         fib_source_t source,
246                                                         fib_entry_flag_t stype,
247                                                         const dpo_id_t *dpo);
248
249 /**
250  * @brief
251  *  Update a 'special' entry to the FIB that links to the DPO passed
252  *  A special entry is an entry that the FIB is not expect to resolve
253  *  via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
254  *  Instead the client/source provides the DPO to link to.
255  *  Special entries are add/remove reference counted per-source. So n
256  * 'removes' are required for n 'adds', if the entry is no longer required.
257  *  An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add'
258  * is therefore assumed to act on the reference instance of that add.
259  *
260  * @param fib_entry_index
261  *  The index of the FIB entry to update
262  *
263  * @param source
264  *  The ID of the client/source adding the entry.
265  *
266  * @param flags
267  *  Flags for the entry.
268  *
269  * @param dpo
270  *  The DPO to link to.
271  *
272  * @return
273  *  the index of the fib_entry_t that is created (or existed already).
274  */
275 extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index,
276                                                             const fib_prefix_t *prefix,
277                                                             fib_source_t source,
278                                                             fib_entry_flag_t stype,
279                                                             const dpo_id_t *dpo);
280
281 /**
282  * @brief
283  *  Remove a 'special' entry from the FIB.
284  *  This add is reference counting per-source. So n 'removes' are required
285  *  for n 'adds', if the entry is no longer required.
286  *
287  * @param fib_index
288  *  The index of the FIB
289  *
290  * @param prefix
291  *  The prefix to remove
292  *
293  * @param source
294  *  The ID of the client/source adding the entry.
295  *
296  */
297 extern void fib_table_entry_special_remove(u32 fib_index,
298                                            const fib_prefix_t *prefix,
299                                            fib_source_t source);
300
301 /**
302  * @brief
303  *  Add one path to an entry (aka route) in the FIB. If the entry does not
304  *  exist, it will be created.
305  * See the documentation for fib_route_path_t for more descirptions of
306  * the path parameters.
307  *
308  * @param fib_index
309  *  The index of the FIB
310  *
311  * @param prefix
312  *  The prefix for the entry to add
313  *
314  * @param source
315  *  The ID of the client/source adding the entry.
316  *
317  * @param flags
318  *  Flags for the entry.
319  *
320  * @paran next_hop_proto
321  *  The protocol of the next hop. This cannot be derived in the event that
322  * the next hop is all zeros.
323  *
324  * @param next_hop
325  *  The address of the next-hop.
326  *
327  * @param sw_if_index
328  *  The index of the interface.
329  *
330  * @param next_hop_fib_index,
331  *  The fib index of the next-hop for recursive resolution
332  *
333  * @param next_hop_weight
334  *  [un]equal cost path weight
335  *
336  * @param  next_hop_label_stack
337  *  The path's out-going label stack. NULL is there is none.
338  *
339  * @param  pf
340  *  Flags for the path
341  *
342  * @return
343  *  the index of the fib_entry_t that is created (or existed already).
344  */
345 extern fib_node_index_t fib_table_entry_path_add(u32 fib_index,
346                                                  const fib_prefix_t *prefix,
347                                                  fib_source_t source,
348                                                  fib_entry_flag_t flags,
349                                                  dpo_proto_t next_hop_proto,
350                                                  const ip46_address_t *next_hop,
351                                                  u32 next_hop_sw_if_index,
352                                                  u32 next_hop_fib_index,
353                                                  u32 next_hop_weight,
354                                                  fib_mpls_label_t *next_hop_label_stack,
355                                                  fib_route_path_flags_t pf);
356 /**
357  * @brief
358  *  Add n paths to an entry (aka route) in the FIB. If the entry does not
359  *  exist, it will be created.
360  * See the documentation for fib_route_path_t for more descirptions of
361  * the path parameters.
362  *
363  * @param fib_index
364  *  The index of the FIB
365  *
366  * @param prefix
367  *  The prefix for the entry to add
368  *
369  * @param source
370  *  The ID of the client/source adding the entry.
371  *
372  * @param flags
373  *  Flags for the entry.
374  *
375  * @param rpaths
376  *  A vector of paths. Not const since they may be modified.
377  *
378  * @return
379  *  the index of the fib_entry_t that is created (or existed already).
380  */
381 extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index,
382                                                   const fib_prefix_t *prefix,
383                                                   fib_source_t source,
384                                                   fib_entry_flag_t flags,
385                                                   fib_route_path_t *rpath);
386
387 /**
388  * @brief
389  * remove one path to an entry (aka route) in the FIB. If this is the entry's
390  * last path, then the entry will be removed, unless it has other sources.
391  * See the documentation for fib_route_path_t for more descirptions of
392  * the path parameters.
393  *
394  * @param fib_index
395  *  The index of the FIB
396  *
397  * @param prefix
398  *  The prefix for the entry to add
399  *
400  * @param source
401  *  The ID of the client/source adding the entry.
402  *
403  * @paran next_hop_proto
404  *  The protocol of the next hop. This cannot be derived in the event that
405  * the next hop is all zeros.
406  *
407  * @param next_hop
408  *  The address of the next-hop.
409  *
410  * @param sw_if_index
411  *  The index of the interface.
412  *
413  * @param next_hop_fib_index,
414  *  The fib index of the next-hop for recursive resolution
415  *
416  * @param next_hop_weight
417  *  [un]equal cost path weight
418  *
419  * @param  pf
420  *  Flags for the path
421  */
422 extern void fib_table_entry_path_remove(u32 fib_index,
423                                         const fib_prefix_t *prefix,
424                                         fib_source_t source,
425                                         dpo_proto_t next_hop_proto,
426                                         const ip46_address_t *next_hop,
427                                         u32 next_hop_sw_if_index,
428                                         u32 next_hop_fib_index,
429                                         u32 next_hop_weight,
430                                         fib_route_path_flags_t pf);
431
432 /**
433  * @brief
434  * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
435  * last path, then the entry will be removed, unless it has other sources.
436  * See the documentation for fib_route_path_t for more descirptions of
437  * the path parameters.
438  *
439  * @param fib_index
440  *  The index of the FIB
441  *
442  * @param prefix
443  *  The prefix for the entry to add
444  *
445  * @param source
446  *  The ID of the client/source adding the entry.
447  *
448  * @param rpaths
449  *  A vector of paths.
450  */
451 extern void fib_table_entry_path_remove2(u32 fib_index,
452                                          const fib_prefix_t *prefix,
453                                          fib_source_t source,
454                                          fib_route_path_t *paths);
455
456 /**
457  * @brief
458  *  Update an entry to have a new set of paths. If the entry does not
459  *  exist, it will be created.
460  * The difference between an 'path-add' and an update, is that path-add is
461  * an incremental addition of paths, whereas an update is a wholesale swap.
462  *
463  * @param fib_index
464  *  The index of the FIB
465  *
466  * @param prefix
467  *  The prefix for the entry to add
468  *
469  * @param source
470  *  The ID of the client/source adding the entry.
471  *
472  * @param rpaths
473  *  A vector of paths. Not const since they may be modified.
474  *
475  * @return
476  *  the index of the fib_entry_t that is created (or existed already).
477  */
478 extern fib_node_index_t fib_table_entry_update(u32 fib_index,
479                                                const fib_prefix_t *prefix,
480                                                fib_source_t source,
481                                                fib_entry_flag_t flags,
482                                                fib_route_path_t *paths);
483
484 /**
485  * @brief
486  *  Update the entry to have just one path. If the entry does not
487  *  exist, it will be created.
488  * See the documentation for fib_route_path_t for more descirptions of
489  * the path parameters.
490  *
491  * @param fib_index
492  *  The index of the FIB
493  *
494  * @param prefix
495  *  The prefix for the entry to add
496  *
497  * @param source
498  *  The ID of the client/source adding the entry.
499  *
500  * @param flags
501  *  Flags for the entry.
502  *
503  * @paran next_hop_proto
504  *  The protocol of the next hop. This cannot be derived in the event that
505  * the next hop is all zeros.
506  *
507  * @param next_hop
508  *  The address of the next-hop.
509  *
510  * @param sw_if_index
511  *  The index of the interface.
512  *
513  * @param next_hop_fib_index,
514  *  The fib index of the next-hop for recursive resolution
515  *
516  * @param next_hop_weight
517  *  [un]equal cost path weight
518  *
519  * @param  next_hop_label_stack
520  *  The path's out-going label stack. NULL is there is none.
521  *
522  * @param  pf
523  *  Flags for the path
524  *
525  * @return
526  *  the index of the fib_entry_t that is created (or existed already).
527  */
528 extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index,
529                                                         const fib_prefix_t *prefix,
530                                                         fib_source_t source,
531                                                         fib_entry_flag_t flags,
532                                                         dpo_proto_t next_hop_proto,
533                                                         const ip46_address_t *next_hop,
534                                                         u32 next_hop_sw_if_index,
535                                                         u32 next_hop_fib_index,
536                                                         u32 next_hop_weight,
537                                                         fib_mpls_label_t *next_hop_label_stack,
538                                                         fib_route_path_flags_t pf);
539
540 /**
541  * @brief
542  *  Add a MPLS local label for the prefix/route. If the entry does not
543  *  exist, it will be created. In theory more than one local label can be
544  *  added, but this is not yet supported.
545  *
546  * @param fib_index
547  *  The index of the FIB
548  *
549  * @param prefix
550  *  The prefix for the entry to which to add the label
551  *
552  * @param label
553  *  The MPLS label to add
554  *
555  * @return
556  *  the index of the fib_entry_t that is created (or existed already).
557  */
558 extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index,
559                                                         const fib_prefix_t *prefix,
560                                                         mpls_label_t label);
561 /**
562  * @brief
563  *  remove a MPLS local label for the prefix/route.
564  *
565  * @param fib_index
566  *  The index of the FIB
567  *
568  * @param prefix
569  *  The prefix for the entry to which to add the label
570  *
571  * @param label
572  *  The MPLS label to add
573  */
574 extern void fib_table_entry_local_label_remove(u32 fib_index,
575                                                const fib_prefix_t *prefix,
576                                                mpls_label_t label);
577
578 /**
579  * @brief
580  *  Delete a FIB entry. If the entry has no more sources, then it is
581  * removed from the table.
582  *
583  * @param fib_index
584  *  The index of the FIB
585  *
586  * @param prefix
587  *  The prefix for the entry to remove
588  *
589  * @param source
590  *  The ID of the client/source adding the entry.
591  */
592 extern void fib_table_entry_delete(u32 fib_index,
593                                    const fib_prefix_t *prefix,
594                                    fib_source_t source);
595
596 /**
597  * @brief
598  *  Delete a FIB entry. If the entry has no more sources, then it is
599  * removed from the table.
600  *
601  * @param entry_index
602  *  The index of the FIB entry
603  *
604  * @param source
605  *  The ID of the client/source adding the entry.
606  */
607 extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
608                                          fib_source_t source);
609
610 /**
611  * @brief
612  *  Return the stats index for a FIB entry
613  * @param fib_index
614  *  The table's FIB index
615  * @param prefix
616  *  The entry's prefix's
617  */
618 extern u32 fib_table_entry_get_stats_index(u32 fib_index,
619                                            const fib_prefix_t *prefix);
620
621 /**
622  * @brief
623  *  Flush all entries from a table for the source
624  *
625  * @param fib_index
626  *  The index of the FIB
627  *
628  * @paran proto
629  *  The protocol of the entries in the table
630  *
631  * @param source
632  *  the source to flush
633  */
634 extern void fib_table_flush(u32 fib_index,
635                             fib_protocol_t proto,
636                             fib_source_t source);
637
638 /**
639  * @brief
640  *  Resync all entries from a table for the source
641  *  this is the mark part of the mark and sweep algorithm.
642  *  All entries in this FIB that are sourced by 'source' are marked
643  *  as stale.
644  *
645  * @param fib_index
646  *  The index of the FIB
647  *
648  * @paran proto
649  *  The protocol of the entries in the table
650  *
651  * @param source
652  *  the source to flush
653  */
654 extern void fib_table_mark(u32 fib_index,
655                            fib_protocol_t proto,
656                            fib_source_t source);
657
658 /**
659  * @brief
660  *  Signal that the table has converged, i.e. all updates are complete.
661  *  this is the sweep part of the mark and sweep algorithm.
662  *  All entries in this FIB that are sourced by 'source' and marked
663  *  as stale are flushed.
664  *
665  * @param fib_index
666  *  The index of the FIB
667  *
668  * @paran proto
669  *  The protocol of the entries in the table
670  *
671  * @param source
672  *  the source to flush
673  */
674 extern void fib_table_sweep(u32 fib_index,
675                             fib_protocol_t proto,
676                             fib_source_t source);
677
678 /**
679  * @brief
680  *  Get the index of the FIB bound to the interface
681  *
682  * @paran proto
683  *  The protocol of the FIB (and thus the entries therein)
684  *
685  * @param sw_if_index
686  *  The interface index
687  *
688  * @return fib_index
689  *  The index of the FIB
690  */
691 extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
692                                                u32 sw_if_index);
693
694 /**
695  * @brief
696  *  Get the Table-ID of the FIB bound to the interface
697  *
698  * @paran proto
699  *  The protocol of the FIB (and thus the entries therein)
700  *
701  * @param sw_if_index
702  *  The interface index
703  *
704  * @return fib_index
705  *  The tableID of the FIB
706  */
707 extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
708                                                   u32 sw_if_index);
709
710 /**
711  * @brief
712  *  Get the Table-ID of the FIB from protocol and index
713  *
714  * @param fib_index
715  *  The FIB index
716  *
717  * @paran proto
718  *  The protocol of the FIB (and thus the entries therein)
719  *
720  * @return fib_index
721  *  The tableID of the FIB
722  */
723 extern u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
724
725 /**
726  * @brief
727  *  Get the index of the FIB for a Table-ID. This DOES NOT create the
728  * FIB if it does not exist.
729  *
730  * @paran proto
731  *  The protocol of the FIB (and thus the entries therein)
732  *
733  * @param table-id
734  *  The Table-ID
735  *
736  * @return fib_index
737  *  The index of the FIB, which may be INVALID.
738  */
739 extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
740
741
742 /**
743  * @brief
744  *  Get the index of the FIB for a Table-ID. This DOES create the
745  * FIB if it does not exist.
746  *
747  * @paran proto
748  *  The protocol of the FIB (and thus the entries therein)
749  *
750  * @param table-id
751  *  The Table-ID
752  *
753  * @return fib_index
754  *  The index of the FIB
755  *
756  * @param source
757  *  The ID of the client/source.
758  */
759 extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
760                                              u32 table_id,
761                                              fib_source_t source);
762
763 /**
764  * @brief
765  *  Get the index of the FIB for a Table-ID. This DOES create the
766  * FIB if it does not exist.
767  *
768  * @paran proto
769  *  The protocol of the FIB (and thus the entries therein)
770  *
771  * @param table-id
772  *  The Table-ID
773  *
774  * @return fib_index
775  *  The index of the FIB
776  *
777  * @param source
778  *  The ID of the client/source.
779  *
780  * @param name
781  *  The client is choosing the name they want the table to have
782  */
783 extern u32 fib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
784                                                     u32 table_id,
785                                                     fib_source_t source,
786                                                     const u8 *name);
787
788 /**
789  * @brief
790  *  Create a new table with no table ID. This means it does not get
791  * added to the hash-table and so can only be found by using the index returned.
792  *
793  * @paran proto
794  *  The protocol of the FIB (and thus the entries therein)
795  *
796  * @param fmt
797  *  A string to describe the table
798  *
799  * @param source
800  *  The ID of the client/source.
801  *
802  * @return fib_index
803  *  The index of the FIB
804  */
805 extern u32 fib_table_create_and_lock(fib_protocol_t proto,
806                                      fib_source_t source,
807                                      const char *const fmt,
808                                      ...);
809
810 /**
811  * @brief
812  *  Get the flow hash configured used by the table
813  *
814  * @param fib_index
815  *  The index of the FIB
816  *
817  * @paran proto
818  *  The protocol the packets the flow hash will be calculated for.
819  *
820  * @return The flow hash config
821  */
822 extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
823                                                          fib_protocol_t proto);
824
825 /**
826  * @brief
827  *  Get the flow hash configured used by the protocol
828  *
829  * @paran proto
830  *  The protocol of the FIB (and thus the entries therein)
831  *
832  * @return The flow hash config
833  */
834 extern flow_hash_config_t fib_table_get_default_flow_hash_config(fib_protocol_t proto);
835
836 /**
837  * @brief
838  *  Set the flow hash configured used by the table
839  *
840  * @param fib_index
841  *  The index of the FIB
842  *
843  * @paran proto
844  *  The protocol of the FIB (and thus the entries therein)
845  *
846  * @param hash_config
847  *  The flow-hash config to set
848  *
849  * @return none
850  */
851 extern void fib_table_set_flow_hash_config(u32 fib_index,
852                                            fib_protocol_t proto,
853                                            flow_hash_config_t hash_config);
854
855 /**
856  * @brief
857  * Take a reference counting lock on the table
858  *
859  * @param fib_index
860  *  The index of the FIB
861  *
862  * @paran proto
863  *  The protocol of the FIB (and thus the entries therein)
864  *
865  * @param source
866  *  The ID of the client/source.
867  */ 
868 extern void fib_table_unlock(u32 fib_index,
869                              fib_protocol_t proto,
870                              fib_source_t source);
871
872 /**
873  * @brief
874  * Release a reference counting lock on the table. When the last lock
875  * has gone. the FIB is deleted.
876  *
877  * @param fib_index
878  *  The index of the FIB
879  *
880  * @paran proto
881  *  The protocol of the FIB (and thus the entries therein)
882  *
883  * @param source
884  *  The ID of the client/source.
885  */ 
886 extern void fib_table_lock(u32 fib_index,
887                            fib_protocol_t proto,
888                            fib_source_t source);
889
890 /**
891  * @brief
892  * Return the number of entries in the FIB added by a given source.
893  *
894  * @param fib_index
895  *  The index of the FIB
896  *
897  * @paran proto
898  *  The protocol of the FIB (and thus the entries therein)
899  *
900  * @return number of sourced entries.
901  */ 
902 extern u32 fib_table_get_num_entries(u32 fib_index,
903                                      fib_protocol_t proto,
904                                      fib_source_t source);
905
906 /**
907  * @brief
908  * Get a pointer to a FIB table
909  */
910 extern fib_table_t *fib_table_get(fib_node_index_t index,
911                                   fib_protocol_t proto);
912
913 /**
914  * @brief return code controlling how a table walk proceeds
915  */
916 typedef enum fib_table_walk_rc_t_
917 {
918     /**
919      * Continue on to the next entry
920      */
921     FIB_TABLE_WALK_CONTINUE,
922     /**
923      * Do no traverse down this sub-tree
924      */
925     FIB_TABLE_WALK_SUB_TREE_STOP,
926     /**
927      * Stop the walk completely
928      */
929     FIB_TABLE_WALK_STOP,
930 } fib_table_walk_rc_t;
931
932 /**
933  * @brief Call back function when walking entries in a FIB table
934  */
935 typedef fib_table_walk_rc_t (*fib_table_walk_fn_t)(fib_node_index_t fei,
936                                                    void *ctx);
937
938 /**
939  * @brief Walk all entries in a FIB table
940  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
941  * table and store elements in a vector, then delete the elements
942  */
943 extern void fib_table_walk(u32 fib_index,
944                            fib_protocol_t proto,
945                            fib_table_walk_fn_t fn,
946                            void *ctx);
947
948 /**
949  * @brief Walk all entries in a sub-tree FIB table. The 'root' paraneter
950  * is the prefix at the root of the sub-tree.
951  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
952  * table and store elements in a vector, then delete the elements
953  */
954 extern void fib_table_sub_tree_walk(u32 fib_index,
955                                     fib_protocol_t proto,
956                                     const fib_prefix_t *root,
957                                     fib_table_walk_fn_t fn,
958                                     void *ctx);
959
960 /**
961  * @brief format (display) the memory used by the FIB tables
962  */
963 extern u8 *format_fib_table_memory(u8 *s, va_list *args);
964
965 #endif