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