blob: 8b86f8d6dd965879d818d833677bfdc6984080b4 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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/**
Neale Ranns15002542017-09-10 04:39:11 -070026 * 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/**
Neale Ranns53da2212018-02-24 02:11:19 -080032 * Flags for the source data
33 */
34typedef 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
60typedef 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/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010066 * @brief
67 * A protocol Independent FIB table
68 */
69typedef struct fib_table_t_
70{
71 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010072 * Which protocol this table serves. Used to switch on the union above.
73 */
74 fib_protocol_t ft_proto;
75
76 /**
Neale Ranns53da2212018-02-24 02:11:19 -080077 * Table flags
78 */
79 fib_table_flags_t ft_flags;
80
81 /**
Neale Ranns15002542017-09-10 04:39:11 -070082 * per-source number of locks on the table
Neale Ranns0bfe5d82016-08-25 15:29:12 +010083 */
Neale Ranns15002542017-09-10 04:39:11 -070084 u16 ft_locks[FIB_TABLE_N_LOCKS];
Neale Ranns0bfe5d82016-08-25 15:29:12 +010085
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 */
Christophe Fontained3c008d2017-10-02 18:10:54 +0200121extern u8* format_fib_table_name(u8* s, va_list *ap);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100122
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 */
136extern 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 */
153extern 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 */
169extern fib_node_index_t fib_table_get_less_specific(u32 fib_index,
170 const fib_prefix_t *prefix);
171
172/**
173 * @brief
Neale Rannsa0558302017-04-13 00:44:52 -0700174 * Add a 'special' entry to the FIB.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100175 * 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).
Neale Rannsa0558302017-04-13 00:44:52 -0700177 * Instead the will link to a DPO valid for the source and/or the flags.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100178 * This add is reference counting per-source. So n 'removes' are required
179 * for n 'adds', if the entry is no longer required.
Neale Rannsa0558302017-04-13 00:44:52 -0700180 * If the source needs to provide non-default forwarding use:
181 * fib_table_entry_special_dpo_add()
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100182 *
Neale Rannsa0558302017-04-13 00:44:52 -0700183 * @param fib_index
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100184 * 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 *
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100195 * @return
196 * the index of the fib_entry_t that is created (or exists already).
197 */
198extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
199 const fib_prefix_t *prefix,
200 fib_source_t source,
Neale Rannsa0558302017-04-13 00:44:52 -0700201 fib_entry_flag_t flags);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100202
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 */
230extern 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.
Neale Ranns948e00f2016-10-20 13:39:34 +0100244 * 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.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100246 *
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 */
Neale Ranns948e00f2016-10-20 13:39:34 +0100262extern 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);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100267
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 */
284extern 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 *
Neale Rannsad422ed2016-11-02 14:20:04 +0000323 * @param next_hop_label_stack
324 * The path's out-going label stack. NULL is there is none.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100325 *
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 */
332extern 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,
Neale Rannsda78f952017-05-24 09:15:43 -0700336 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100337 const ip46_address_t *next_hop,
338 u32 next_hop_sw_if_index,
339 u32 next_hop_fib_index,
340 u32 next_hop_weight,
Neale Ranns31ed7442018-02-23 05:29:09 -0800341 fib_mpls_label_t *next_hop_label_stack,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100342 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
Neale Rannsad422ed2016-11-02 14:20:04 +0000363 * A vector of paths. Not const since they may be modified.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100364 *
365 * @return
366 * the index of the fib_entry_t that is created (or existed already).
367 */
368extern 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,
Neale Rannsad422ed2016-11-02 14:20:04 +0000372 fib_route_path_t *rpath);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100373
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 */
409extern void fib_table_entry_path_remove(u32 fib_index,
410 const fib_prefix_t *prefix,
411 fib_source_t source,
Neale Rannsda78f952017-05-24 09:15:43 -0700412 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100413 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 */
438extern void fib_table_entry_path_remove2(u32 fib_index,
439 const fib_prefix_t *prefix,
440 fib_source_t source,
Neale Rannsad422ed2016-11-02 14:20:04 +0000441 fib_route_path_t *paths);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100442
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
Neale Rannsad422ed2016-11-02 14:20:04 +0000460 * A vector of paths. Not const since they may be modified.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100461 *
462 * @return
463 * the index of the fib_entry_t that is created (or existed already).
464 */
465extern 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,
Neale Rannsad422ed2016-11-02 14:20:04 +0000469 fib_route_path_t *paths);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100470
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 *
Neale Rannsad422ed2016-11-02 14:20:04 +0000506 * @param next_hop_label_stack
507 * The path's out-going label stack. NULL is there is none.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100508 *
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 */
515extern 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,
Neale Rannsda78f952017-05-24 09:15:43 -0700519 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100520 const ip46_address_t *next_hop,
521 u32 next_hop_sw_if_index,
522 u32 next_hop_fib_index,
523 u32 next_hop_weight,
Neale Ranns31ed7442018-02-23 05:29:09 -0800524 fib_mpls_label_t *next_hop_label_stack,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100525 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 */
545extern 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 */
561extern 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 */
579extern 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 */
594extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
595 fib_source_t source);
596
597/**
598 * @brief
599 * Flush all entries from a table for the source
600 *
601 * @param fib_index
602 * The index of the FIB
603 *
604 * @paran proto
605 * The protocol of the entries in the table
606 *
607 * @param source
608 * the source to flush
609 */
610extern void fib_table_flush(u32 fib_index,
611 fib_protocol_t proto,
612 fib_source_t source);
613
614/**
615 * @brief
616 * Get the index of the FIB bound to the interface
617 *
618 * @paran proto
619 * The protocol of the FIB (and thus the entries therein)
620 *
621 * @param sw_if_index
622 * The interface index
623 *
624 * @return fib_index
625 * The index of the FIB
626 */
627extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
628 u32 sw_if_index);
629
630/**
631 * @brief
632 * Get the Table-ID of the FIB bound to the interface
633 *
634 * @paran proto
635 * The protocol of the FIB (and thus the entries therein)
636 *
637 * @param sw_if_index
638 * The interface index
639 *
640 * @return fib_index
641 * The tableID of the FIB
642 */
643extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
644 u32 sw_if_index);
645
646/**
647 * @brief
Neale Ranns25b04942018-04-04 09:34:50 -0700648 * Get the Table-ID of the FIB from protocol and index
649 *
650 * @param fib_index
651 * The FIB index
652 *
653 * @paran proto
654 * The protocol of the FIB (and thus the entries therein)
655 *
656 * @return fib_index
657 * The tableID of the FIB
658 */
659extern u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
660
661/**
662 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100663 * Get the index of the FIB for a Table-ID. This DOES NOT create the
664 * FIB if it does not exist.
665 *
666 * @paran proto
667 * The protocol of the FIB (and thus the entries therein)
668 *
669 * @param table-id
670 * The Table-ID
671 *
672 * @return fib_index
673 * The index of the FIB, which may be INVALID.
674 */
675extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
676
677
678/**
679 * @brief
680 * Get the index of the FIB for a Table-ID. This DOES create the
681 * FIB if it does not exist.
682 *
683 * @paran proto
684 * The protocol of the FIB (and thus the entries therein)
685 *
686 * @param table-id
687 * The Table-ID
688 *
689 * @return fib_index
690 * The index of the FIB
Neale Ranns15002542017-09-10 04:39:11 -0700691 *
692 * @param source
693 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100694 */
695extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
Neale Ranns15002542017-09-10 04:39:11 -0700696 u32 table_id,
697 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100698
699/**
700 * @brief
Neale Ranns2297af02017-09-12 09:45:04 -0700701 * Get the index of the FIB for a Table-ID. This DOES create the
702 * FIB if it does not exist.
703 *
704 * @paran proto
705 * The protocol of the FIB (and thus the entries therein)
706 *
707 * @param table-id
708 * The Table-ID
709 *
710 * @return fib_index
711 * The index of the FIB
712 *
713 * @param source
714 * The ID of the client/source.
715 *
716 * @param name
717 * The client is choosing the name they want the table to have
718 */
719extern u32 fib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
720 u32 table_id,
721 fib_source_t source,
722 const u8 *name);
723
724/**
725 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100726 * Create a new table with no table ID. This means it does not get
727 * added to the hash-table and so can only be found by using the index returned.
728 *
729 * @paran proto
730 * The protocol of the FIB (and thus the entries therein)
731 *
732 * @param fmt
733 * A string to describe the table
734 *
Neale Ranns15002542017-09-10 04:39:11 -0700735 * @param source
736 * The ID of the client/source.
737 *
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100738 * @return fib_index
739 * The index of the FIB
740 */
741extern u32 fib_table_create_and_lock(fib_protocol_t proto,
Neale Ranns15002542017-09-10 04:39:11 -0700742 fib_source_t source,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100743 const char *const fmt,
744 ...);
745
746/**
747 * @brief
748 * Get the flow hash configured used by the table
749 *
750 * @param fib_index
751 * The index of the FIB
752 *
753 * @paran proto
Neale Rannsd792d9c2017-10-21 10:53:20 -0700754 * The protocol the packets the flow hash will be calculated for.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100755 *
756 * @return The flow hash config
757 */
758extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
759 fib_protocol_t proto);
760
761/**
762 * @brief
Neale Ranns41da54f2017-05-02 10:15:19 -0700763 * Get the flow hash configured used by the protocol
764 *
765 * @paran proto
766 * The protocol of the FIB (and thus the entries therein)
767 *
768 * @return The flow hash config
769 */
770extern flow_hash_config_t fib_table_get_default_flow_hash_config(fib_protocol_t proto);
771
772/**
773 * @brief
Neale Ranns227038a2017-04-21 01:07:59 -0700774 * Set the flow hash configured used by the table
775 *
776 * @param fib_index
777 * The index of the FIB
778 *
779 * @paran proto
780 * The protocol of the FIB (and thus the entries therein)
781 *
782 * @param hash_config
783 * The flow-hash config to set
784 *
785 * @return none
786 */
787extern void fib_table_set_flow_hash_config(u32 fib_index,
788 fib_protocol_t proto,
789 flow_hash_config_t hash_config);
790
791/**
792 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100793 * Take a reference counting lock on the table
794 *
795 * @param fib_index
796 * The index of the FIB
797 *
798 * @paran proto
799 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700800 *
801 * @param source
802 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100803 */
804extern void fib_table_unlock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700805 fib_protocol_t proto,
806 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100807
808/**
809 * @brief
810 * Release a reference counting lock on the table. When the last lock
811 * has gone. the FIB is deleted.
812 *
813 * @param fib_index
814 * The index of the FIB
815 *
816 * @paran proto
817 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700818 *
819 * @param source
820 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100821 */
822extern void fib_table_lock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700823 fib_protocol_t proto,
824 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100825
826/**
827 * @brief
828 * Return the number of entries in the FIB added by a given source.
829 *
830 * @param fib_index
831 * The index of the FIB
832 *
833 * @paran proto
834 * The protocol of the FIB (and thus the entries therein)
835 *
836 * @return number of sourced entries.
837 */
838extern u32 fib_table_get_num_entries(u32 fib_index,
839 fib_protocol_t proto,
840 fib_source_t source);
841
842/**
843 * @brief
844 * Get a pointer to a FIB table
845 */
846extern fib_table_t *fib_table_get(fib_node_index_t index,
847 fib_protocol_t proto);
848
Neale Ranns32e1c012016-11-22 17:07:28 +0000849/**
Neale Ranns89541992017-04-06 04:41:02 -0700850 * @brief return code controlling how a table walk proceeds
851 */
852typedef enum fib_table_walk_rc_t_
853{
854 /**
855 * Continue on to the next entry
856 */
857 FIB_TABLE_WALK_CONTINUE,
858 /**
859 * Do no traverse down this sub-tree
860 */
861 FIB_TABLE_WALK_SUB_TREE_STOP,
862 /**
863 * Stop the walk completely
864 */
865 FIB_TABLE_WALK_STOP,
866} fib_table_walk_rc_t;
867
868/**
Neale Ranns32e1c012016-11-22 17:07:28 +0000869 * @brief Call back function when walking entries in a FIB table
870 */
Neale Ranns89541992017-04-06 04:41:02 -0700871typedef fib_table_walk_rc_t (*fib_table_walk_fn_t)(fib_node_index_t fei,
872 void *ctx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000873
874/**
875 * @brief Walk all entries in a FIB table
876 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
877 * table and store elements in a vector, then delete the elements
878 */
879extern void fib_table_walk(u32 fib_index,
880 fib_protocol_t proto,
881 fib_table_walk_fn_t fn,
882 void *ctx);
883
Neale Rannsc87aafa2017-11-29 00:59:31 -0800884/**
Neale Ranns89541992017-04-06 04:41:02 -0700885 * @brief Walk all entries in a sub-tree FIB table. The 'root' paraneter
886 * is the prefix at the root of the sub-tree.
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 */
890extern void fib_table_sub_tree_walk(u32 fib_index,
891 fib_protocol_t proto,
892 const fib_prefix_t *root,
893 fib_table_walk_fn_t fn,
894 void *ctx);
895
896/**
Neale Rannsc87aafa2017-11-29 00:59:31 -0800897 * @brief format (display) the memory used by the FIB tables
898 */
899extern u8 *format_fib_table_memory(u8 *s, va_list *args);
900
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100901#endif