FD.io VPP  v17.07.01-10-g3be13f0
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  * @brief
27  * A protocol Independent IP multicast FIB table
28  */
29 typedef struct mfib_table_t_
30 {
31  /**
32  * A union of the protocol specific FIBs that provide the
33  * underlying LPM mechanism.
34  * This element is first in the struct so that it is in the
35  * first cache line.
36  */
37  union {
40  };
41 
42  /**
43  * Which protocol this table serves. Used to switch on the union above.
44  */
46 
47  /**
48  * number of locks on the table
49  */
51 
52  /**
53  * Table ID (hash key) for this FIB.
54  */
56 
57  /**
58  * Index into FIB vector.
59  */
61 
62  /**
63  * Total route counters
64  */
66 
67  /**
68  * Table description
69  */
71 } mfib_table_t;
72 
73 /**
74  * @brief
75  * Format the description/name of the table
76  */
77 extern u8* format_mfib_table_name(u8* s, va_list ap);
78 
79 /**
80  * @brief
81  * Perfom a longest prefix match in the non-forwarding table
82  *
83  * @param fib_index
84  * The index of the FIB
85  *
86  * @param prefix
87  * The prefix to lookup
88  *
89  * @return
90  * The index of the fib_entry_t for the best match, which may be the default route
91  */
92 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
93  const mfib_prefix_t *prefix);
94 
95 /**
96  * @brief
97  * Perfom an exact match in the non-forwarding table
98  *
99  * @param fib_index
100  * The index of the FIB
101  *
102  * @param prefix
103  * The prefix to lookup
104  *
105  * @return
106  * The index of the fib_entry_t for the exact match, or INVALID
107  * is there is no match.
108  */
110  const mfib_prefix_t *prefix);
111 
112 /**
113  * @brief
114  * Add a new (with no replication) or lock an existing entry
115  *
116  * @param prefix
117  * The prefix for the entry to add
118  *
119  * @return
120  * the index of the fib_entry_t that is created (or existed already).
121  */
123  const mfib_prefix_t *prefix,
124  mfib_source_t source,
125  fib_rpf_id_t rpf_id,
127 
128 /**
129  * @brief
130  * Add n paths to an entry (aka route) in the FIB. If the entry does not
131  * exist, it will be created.
132  * See the documentation for fib_route_path_t for more descirptions of
133  * the path parameters.
134  *
135  * @param fib_index
136  * The index of the FIB
137  *
138  * @param prefix
139  * The prefix for the entry to add
140  *
141  * @param source
142  * The ID of the client/source adding the entry.
143  *
144  * @param flags
145  * Flags for the entry.
146  *
147  * @param rpaths
148  * A vector of paths.
149  *
150  * @return
151  * the index of the fib_entry_t that is created (or existed already).
152  */
154  const mfib_prefix_t *prefix,
155  mfib_source_t source,
156  const fib_route_path_t *rpath,
158 
159 /**
160  * @brief
161  * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
162  * last path, then the entry will be removed, unless it has other sources.
163  * See the documentation for fib_route_path_t for more descirptions of
164  * the path parameters.
165  *
166  * @param fib_index
167  * The index of the FIB
168  *
169  * @param prefix
170  * The prefix for the entry to add
171  *
172  * @param source
173  * The ID of the client/source adding the entry.
174  *
175  * @param rpaths
176  * A vector of paths.
177  */
178 extern void mfib_table_entry_path_remove(u32 fib_index,
179  const mfib_prefix_t *prefix,
180  mfib_source_t source,
181  const fib_route_path_t *paths);
182 
183 
184 
185 /**
186  * @brief
187  * Delete a FIB entry. If the entry has no more sources, then it is
188  * removed from the table.
189  *
190  * @param fib_index
191  * The index of the FIB
192  *
193  * @param prefix
194  * The prefix for the entry to remove
195  *
196  * @param source
197  * The ID of the client/source adding the entry.
198  */
199 extern void mfib_table_entry_delete(u32 fib_index,
200  const mfib_prefix_t *prefix,
201  mfib_source_t source);
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 entry_index
209  * The index of the FIB entry
210  *
211  * @param source
212  * The ID of the client/source adding the entry.
213  */
214 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
215  mfib_source_t source);
216 
217 /**
218  * @brief
219  * Add a 'special' entry to the mFIB that links to the DPO passed
220  * A special entry is an entry that the FIB is not expect to resolve
221  * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
222  * Instead the client/source provides the index of a replicate DPO to link to.
223  *
224  * @param fib_index
225  * The index of the FIB
226  *
227  * @param prefix
228  * The prefix to add
229  *
230  * @param source
231  * The ID of the client/source adding the entry.
232  *
233  * @param flags
234  * Flags for the entry.
235  *
236  * @param rep_dpo
237  * The replicate DPO index to link to.
238  *
239  * @return
240  * the index of the fib_entry_t that is created (or existed already).
241  */
243  const mfib_prefix_t *prefix,
244  mfib_source_t source,
246  index_t rep_dpo);
247 
248 /**
249  * @brief
250  * Flush all entries from a table for the source
251  *
252  * @param fib_index
253  * The index of the FIB
254  *
255  * @paran proto
256  * The protocol of the entries in the table
257  *
258  * @param source
259  * the source to flush
260  */
261 extern void mfib_table_flush(u32 fib_index,
262  fib_protocol_t proto);
263 
264 /**
265  * @brief
266  * Get the index of the FIB bound to the interface
267  *
268  * @paran proto
269  * The protocol of the FIB (and thus the entries therein)
270  *
271  * @param sw_if_index
272  * The interface index
273  *
274  * @return fib_index
275  * The index of the FIB
276  */
278  u32 sw_if_index);
279 
280 /**
281  * @brief
282  * Get the index of the FIB for a Table-ID. This DOES NOT create the
283  * FIB if it does not exist.
284  *
285  * @paran proto
286  * The protocol of the FIB (and thus the entries therein)
287  *
288  * @param table-id
289  * The Table-ID
290  *
291  * @return fib_index
292  * The index of the FIB, which may be INVALID.
293  */
294 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
295 
296 
297 /**
298  * @brief
299  * Get the index of the FIB for a Table-ID. This DOES create the
300  * FIB if it does not exist.
301  *
302  * @paran proto
303  * The protocol of the FIB (and thus the entries therein)
304  *
305  * @param table-id
306  * The Table-ID
307  *
308  * @return fib_index
309  * The index of the FIB
310  */
312  u32 table_id);
313 
314 
315 /**
316  * @brief
317  * Take a reference counting lock on the table
318  *
319  * @param fib_index
320  * The index of the FIB
321  *
322  * @paran proto
323  * The protocol of the FIB (and thus the entries therein)
324  */
325 extern void mfib_table_unlock(u32 fib_index,
326  fib_protocol_t proto);
327 
328 /**
329  * @brief
330  * Release a reference counting lock on the table. When the last lock
331  * has gone. the FIB is deleted.
332  *
333  * @param fib_index
334  * The index of the FIB
335  *
336  * @paran proto
337  * The protocol of the FIB (and thus the entries therein)
338  */
339 extern void mfib_table_lock(u32 fib_index,
340  fib_protocol_t proto);
341 
342 /**
343  * @brief
344  * Return the number of entries in the FIB added by a given source.
345  *
346  * @param fib_index
347  * The index of the FIB
348  *
349  * @paran proto
350  * The protocol of the FIB (and thus the entries therein)
351  *
352  * @return number of sourced entries.
353  */
354 extern u32 mfib_table_get_num_entries(u32 fib_index,
355  fib_protocol_t proto);
356 
357 /**
358  * @brief
359  * Get a pointer to a FIB table
360  */
362  fib_protocol_t proto);
363 
364 /**
365  * @brief Call back function when walking entries in a FIB table
366  */
368  void *ctx);
369 
370 /**
371  * @brief Walk all entries in a FIB table
372  * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
373  * table and store elements in a vector, then delete the elements
374  */
375 extern void mfib_table_walk(u32 fib_index,
376  fib_protocol_t proto,
378  void *ctx);
379 
380 #endif
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:409
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:336
ip6_mfib_t v6
Definition: mfib_table.h:39
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:251
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
u32 mft_total_route_counts
Total route counters.
Definition: mfib_table.h:65
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:26
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:94
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
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, mfib_itf_flags_t flags)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:219
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:65
enum mfib_source_t_ mfib_source_t
Possible [control plane] sources of MFIB entries.
fib_node_index_t mft_index
Index into FIB vector.
Definition: mfib_table.h:60
u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:426
void mfib_table_lock(u32 fib_index, fib_protocol_t proto)
Release a reference counting lock on the table.
Definition: mfib_table.c:489
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:356
Definition: ip4.h:47
u8 * mft_desc
Table description.
Definition: mfib_table.h:70
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:165
Definition: ip6.h:76
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
Aggregrate 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:315
unsigned int u32
Definition: types.h:88
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:392
void mfib_table_unlock(u32 fib_index, fib_protocol_t proto)
Take a reference counting lock on the table.
Definition: mfib_table.c:474
fib_protocol_t mft_proto
Which protocol this table serves.
Definition: mfib_table.h:45
u32 mft_table_id
Table ID (hash key) for this FIB.
Definition: mfib_table.h:55
u8 * format_mfib_table_name(u8 *s, va_list ap)
Format the description/name of the table.
Definition: mfib_table.c:518
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:499
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
u16 mft_locks
number of locks on the table
Definition: mfib_table.h:50
enum mfib_itf_flags_t_ mfib_itf_flags_t
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:294
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:367
ip4_mfib_t v4
Definition: mfib_table.h:38
A protocol Independent IP multicast FIB table.
Definition: mfib_table.h:29
void mfib_table_flush(u32 fib_index, fib_protocol_t proto)
Flush all entries from a table for the source.
u32 flags
Definition: vhost-user.h:76
void mfib_table_entry_delete_index(fib_node_index_t entry_index, mfib_source_t source)
Delete a FIB entry.
Definition: mfib_table.c:380