FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
mfib_table.h
Go to the documentation of this file.
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 __MFIB_TABLE_H__
17 #define __MFIB_TABLE_H__
18 
19 #include <vnet/ip/ip.h>
20 #include <vnet/adj/adj.h>
21 #include <vnet/dpo/replicate_dpo.h>
22 
23 #include <vnet/mfib/mfib_types.h>
24 
25 /**
26  * Keep a lock per-source and a total
27  */
28 #define MFIB_TABLE_N_LOCKS (MFIB_N_SOURCES+1)
29 #define MFIB_TABLE_TOTAL_LOCKS MFIB_N_SOURCES
30 
31 /**
32  * @brief
33  * A protocol Independent IP multicast FIB table
34  */
35 typedef struct mfib_table_t_
36 {
37  /**
38  * Required for pool_get_aligned
39  */
40  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
41 
42  /**
43  * A union of the protocol specific FIBs that provide the
44  * underlying LPM mechanism.
45  * This element is first in the struct so that it is in the
46  * first cache line.
47  */
48  union {
51  };
52 
53  /**
54  * Which protocol this table serves. Used to switch on the union above.
55  */
57 
58  /**
59  * number of locks on the table
60  */
62 
63  /**
64  * Table ID (hash key) for this FIB.
65  */
67 
68  /**
69  * Index into FIB vector.
70  */
72 
73  /**
74  * Total route counters
75  */
77 
78  /**
79  * Table description
80  */
82 } mfib_table_t;
83 
84 /**
85  * @brief
86  * Format the description/name of the table
87  */
88 extern u8* format_mfib_table_name(u8* s, va_list *ap);
89 
90 /**
91  * @brief
92  * Perfom a longest prefix match in the non-forwarding table
93  *
94  * @param fib_index
95  * The index of the FIB
96  *
97  * @param prefix
98  * The prefix to lookup
99  *
100  * @return
101  * The index of the fib_entry_t for the best match, which may be the default route
102  */
103 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
104  const mfib_prefix_t *prefix);
105 
106 /**
107  * @brief
108  * Perfom an exact match in the non-forwarding table
109  *
110  * @param fib_index
111  * The index of the FIB
112  *
113  * @param prefix
114  * The prefix to lookup
115  *
116  * @return
117  * The index of the fib_entry_t for the exact match, or INVALID
118  * is there is no match.
119  */
121  const mfib_prefix_t *prefix);
122 
123 /**
124  * @brief
125  * Add a new (with no replication) or lock an existing entry
126  *
127  * @param prefix
128  * The prefix for the entry to add
129  *
130  * @return
131  * the index of the fib_entry_t that is created (or existed already).
132  */
134  const mfib_prefix_t *prefix,
135  mfib_source_t source,
138 
139 /**
140  * @brief
141  * Add n paths to an entry (aka route) in the FIB. If the entry does not
142  * exist, it will be created.
143  * See the documentation for fib_route_path_t for more descirptions of
144  * the path parameters.
145  *
146  * @param fib_index
147  * The index of the FIB
148  *
149  * @param prefix
150  * The prefix for the entry to add
151  *
152  * @param source
153  * The ID of the client/source adding the entry.
154  *
155  * @param flags
156  * Flags for the entry.
157  *
158  * @param rpaths
159  * A vector of paths.
160  *
161  * @return
162  * the index of the fib_entry_t that is created (or existed already).
163  */
165  const mfib_prefix_t *prefix,
166  mfib_source_t source,
167  const fib_route_path_t *rpath);
169  const mfib_prefix_t *prefix,
170  mfib_source_t source,
171  const fib_route_path_t *rpath);
172 
173 /**
174  * @brief
175  * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
176  * last path, then the entry will be removed, unless it has other sources.
177  * See the documentation for fib_route_path_t for more descirptions of
178  * the path parameters.
179  *
180  * @param fib_index
181  * The index of the FIB
182  *
183  * @param prefix
184  * The prefix for the entry to add
185  *
186  * @param source
187  * The ID of the client/source adding the entry.
188  *
189  * @param rpaths
190  * A vector of paths.
191  */
192 extern void mfib_table_entry_path_remove(u32 fib_index,
193  const mfib_prefix_t *prefix,
194  mfib_source_t source,
195  const fib_route_path_t *paths);
196 extern void mfib_table_entry_paths_remove(u32 fib_index,
197  const mfib_prefix_t *prefix,
198  mfib_source_t source,
199  const fib_route_path_t *paths);
200 
201 
202 
203 /**
204  * @brief
205  * Delete a FIB entry. If the entry has no more sources, then it is
206  * removed from the table.
207  *
208  * @param fib_index
209  * The index of the FIB
210  *
211  * @param prefix
212  * The prefix for the entry to remove
213  *
214  * @param source
215  * The ID of the client/source adding the entry.
216  */
217 extern void mfib_table_entry_delete(u32 fib_index,
218  const mfib_prefix_t *prefix,
219  mfib_source_t source);
220 
221 /**
222  * @brief
223  * Delete a FIB entry. If the entry has no more sources, then it is
224  * removed from the table.
225  *
226  * @param entry_index
227  * The index of the FIB entry
228  *
229  * @param source
230  * The ID of the client/source adding the entry.
231  */
232 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
233  mfib_source_t source);
234 
235 /**
236  * @brief
237  * Add a 'special' entry to the mFIB that links to the DPO passed
238  * A special entry is an entry that the FIB is not expect to resolve
239  * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
240  * Instead the client/source provides the index of a replicate DPO to link to.
241  *
242  * @param fib_index
243  * The index of the FIB
244  *
245  * @param prefix
246  * The prefix to add
247  *
248  * @param source
249  * The ID of the client/source adding the entry.
250  *
251  * @param flags
252  * Flags for the entry.
253  *
254  * @param rep_dpo
255  * The replicate DPO index to link to.
256  *
257  * @return
258  * the index of the fib_entry_t that is created (or existed already).
259  */
261  const mfib_prefix_t *prefix,
262  mfib_source_t source,
264  index_t rep_dpo);
265 
266 /**
267  * @brief
268  * Flush all entries from a table for the source
269  *
270  * @param fib_index
271  * The index of the FIB
272  *
273  * @paran proto
274  * The protocol of the entries in the table
275  *
276  * @param source
277  * the source to flush
278  */
279 extern void mfib_table_flush(u32 fib_index,
281  mfib_source_t source);
282 
283 /**
284  * @brief
285  * Get the index of the FIB bound to the interface
286  *
287  * @paran proto
288  * The protocol of the FIB (and thus the entries therein)
289  *
290  * @param sw_if_index
291  * The interface index
292  *
293  * @return fib_index
294  * The index of the FIB
295  */
297  u32 sw_if_index);
298 
299 /**
300  * @brief
301  * Get the Table-ID of the FIB from protocol and index
302  *
303  * @param fib_index
304  * The FIB index
305  *
306  * @paran proto
307  * The protocol of the FIB (and thus the entries therein)
308  *
309  * @return fib_index
310  * The tableID of the FIB
311  */
313 
314 /**
315  * @brief
316  * Get the index of the FIB for a Table-ID. This DOES NOT create the
317  * FIB if it does not exist.
318  *
319  * @paran proto
320  * The protocol of the FIB (and thus the entries therein)
321  *
322  * @param table-id
323  * The Table-ID
324  *
325  * @return fib_index
326  * The index of the FIB, which may be INVALID.
327  */
329 
330 /**
331  * @brief
332  * Get the Table-ID of the FIB from protocol and index
333  *
334  * @param fib_index
335  * The FIB index
336  *
337  * @paran proto
338  * The protocol of the FIB (and thus the entries therein)
339  *
340  * @return fib_index
341  * The tableID of the FIB
342  */
344 
345 /**
346  * @brief
347  * Get the index of the FIB for a Table-ID. This DOES create the
348  * FIB if it does not exist.
349  *
350  * @paran proto
351  * The protocol of the FIB (and thus the entries therein)
352  *
353  * @param table-id
354  * The Table-ID
355  *
356  * @return fib_index
357  * The index of the FIB
358  *
359  * @param source
360  * The ID of the client/source.
361  */
363  u32 table_id,
364  mfib_source_t source);
365 
366 /**
367  * @brief
368  * Get the index of the FIB for a Table-ID. This DOES create the
369  * FIB if it does not exist.
370  *
371  * @paran proto
372  * The protocol of the FIB (and thus the entries therein)
373  *
374  * @param table-id
375  * The Table-ID
376  *
377  * @return fib_index
378  * The index of the FIB
379  *
380  * @param source
381  * The ID of the client/source.
382  *
383  * @param name
384  * The client is choosing the name they want the table to have
385  */
387  u32 table_id,
388  mfib_source_t source,
389  const u8 *name);
390 
391 
392 /**
393  * @brief
394  * Take a reference counting lock on the table
395  *
396  * @param fib_index
397  * The index of the FIB
398  *
399  * @paran proto
400  * The protocol of the FIB (and thus the entries therein)
401  *
402  * @param source
403  * The ID of the client/source.
404  */
405 extern void mfib_table_unlock(u32 fib_index,
407  mfib_source_t source);
408 
409 /**
410  * @brief
411  * Release a reference counting lock on the table. When the last lock
412  * has gone. the FIB is deleted.
413  *
414  * @param fib_index
415  * The index of the FIB
416  *
417  * @paran proto
418  * The protocol of the FIB (and thus the entries therein)
419  *
420  * @param source
421  * The ID of the client/source.
422  */
423 extern void mfib_table_lock(u32 fib_index,
425  mfib_source_t source);
426 
427 /**
428  * @brief
429  * Return the number of entries in the FIB added by a given source.
430  *
431  * @param fib_index
432  * The index of the FIB
433  *
434  * @paran proto
435  * The protocol of the FIB (and thus the entries therein)
436  *
437  * @return number of sourced entries.
438  */
439 extern u32 mfib_table_get_num_entries(u32 fib_index,
441 
442 /**
443  * @brief
444  * Get the less specific (covering) prefix
445  *
446  * @param fib_index
447  * The index of the FIB
448  *
449  * @param prefix
450  * The prefix to lookup
451  *
452  * @return
453  * The index of the less specific fib_entry_t.
454  */
456  const mfib_prefix_t *prefix);
457 
458 /**
459  * @brief
460  * Get a pointer to a FIB table
461  */
464 
465 /**
466  * @brief Call back function when walking entries in a FIB table
467  */
469  void *ctx);
470 
471 /**
472  * @brief Walk all entries in a FIB table
473  * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
474  * table and store elements in a vector, then delete the elements
475  */
476 extern void mfib_table_walk(u32 fib_index,
479  void *ctx);
480 /**
481  * @brief format (display) the memory usage for mfibs
482  */
483 extern u8 * format_mfib_table_memory(u8 * s, va_list * args);
484 
485 /**
486  * To assit UT
487  */
490 
491 
492 #endif
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
Required for pool_get_aligned.
void mfib_table_unlock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Take a reference counting lock on the table.
Definition: mfib_table.c:702
u32 flags
Definition: vhost_user.h:141
u32 mfib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:553
u32 mfib_table_get_num_entries(u32 fib_index, fib_protocol_t proto)
Return the number of entries in the FIB added by a given source.
enum mfib_entry_flags_t_ mfib_entry_flags_t
A representation of a path as described by a route producer.
Definition: fib_types.h:485
ip6_mfib_t v6
Definition: mfib_table.h:50
void mfib_table_entry_paths_remove(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *paths)
Definition: mfib_table.c:393
void mfib_table_entry_path_remove(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *paths)
Remove n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:405
void mfib_table_flush(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Flush all entries from a table for the source.
Definition: mfib_table.c:660
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
u16 mft_locks[MFIB_TABLE_N_LOCKS]
number of locks on the table
Definition: mfib_table.h:61
u32 mft_total_route_counts
Total route counters.
Definition: mfib_table.h:76
u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, mfib_source_t source)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:611
mfib_table_t * mfib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: mfib_table.c:28
vl_api_mprefix_t prefix
Definition: ip.api:456
struct mfib_table_t_ mfib_table_t
A protocol Independent IP multicast FIB table.
fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index, const mfib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: mfib_table.c:96
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
fib_node_index_t mfib_table_lookup(u32 fib_index, const mfib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
Definition: mfib_table.c:67
void mfib_table_lock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Release a reference counting lock on the table.
Definition: mfib_table.c:731
enum mfib_source_t_ mfib_source_t
Possible [control plane] sources of MFIB entries.
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
fib_node_index_t mft_index
Index into FIB vector.
Definition: mfib_table.h:71
fib_node_index_t mfib_table_entry_path_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:323
unsigned int u32
Definition: types.h:88
u32 rpf_id
Definition: fib_types.api:119
void mfib_table_entry_delete(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source)
Delete a FIB entry.
Definition: mfib_table.c:491
long ctx[MAX_CONNS]
Definition: main.c:144
unsigned short u16
Definition: types.h:57
Definition: ip4.h:50
u8 * mft_desc
Table description.
Definition: mfib_table.h:81
u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: mfib_table.c:542
fib_node_index_t mfib_table_entry_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t flags)
Add a new (with no replication) or lock an existing entry.
Definition: mfib_table.c:235
u8 name[64]
Definition: memclnt.api:152
Definition: ip6.h:81
#define MFIB_TABLE_N_LOCKS
Keep a lock per-source and a total.
Definition: mfib_table.h:28
u8 * format_mfib_table_name(u8 *s, va_list *ap)
Format the description/name of the table.
Definition: mfib_table.c:773
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
Aggregate type for a prefix.
Definition: mfib_types.h:24
u32 fib_rpf_id_t
An RPF-ID is numerical value that is used RPF validate.
Definition: fib_types.h:406
u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
Definition: mfib_table.c:525
fib_protocol_t mft_proto
Which protocol this table serves.
Definition: mfib_table.h:56
u32 mft_table_id
Table ID (hash key) for this FIB.
Definition: mfib_table.h:66
u32 mfib_table_get_n_routes(fib_node_index_t index, fib_protocol_t proto)
To assit UT.
Definition: mfib_table.c:743
fib_node_index_t mfib_table_entry_paths_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath)
Definition: mfib_table.c:341
vl_api_mfib_path_t paths[n_paths]
Definition: ip.api:458
void mfib_table_walk(u32 fib_index, fib_protocol_t proto, mfib_table_walk_fn_t fn, void *ctx)
Walk all entries in a FIB table N.B: This is NOT safe to deletes.
Definition: mfib_table.c:754
u8 * format_mfib_table_memory(u8 *s, va_list *args)
format (display) the memory usage for mfibs
Definition: mfib_table.c:787
fib_node_index_t mfib_table_entry_special_add(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, mfib_entry_flags_t flags, index_t rep_dpo)
Add a &#39;special&#39; entry to the mFIB that links to the DPO passed A special entry is an entry that the F...
Definition: mfib_table.c:423
int(* mfib_table_walk_fn_t)(fib_node_index_t fei, void *ctx)
Call back function when walking entries in a FIB table.
Definition: mfib_table.h:468
ip4_mfib_t v4
Definition: mfib_table.h:49
A protocol Independent IP multicast FIB table.
Definition: mfib_table.h:35
fib_node_index_t mfib_table_get_less_specific(u32 fib_index, const mfib_prefix_t *prefix)
Get the less specific (covering) prefix.
Definition: mfib_table.c:127
u32 table_id
Definition: fib_types.api:118
void mfib_table_entry_delete_index(fib_node_index_t entry_index, mfib_source_t source)
Delete a FIB entry.
Definition: mfib_table.c:515
u32 mfib_table_find_or_create_and_lock_w_name(fib_protocol_t proto, u32 table_id, mfib_source_t source, const u8 *name)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:620
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125