blob: 6be4f798cd7b33a7f0a74663abb76cf8d07ba900 [file] [log] [blame]
Neale Ranns32e1c012016-11-22 17:07:28 +00001/*
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>
Neale Rannsa9374df2017-02-02 02:18:18 -080021#include <vnet/dpo/replicate_dpo.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000022
23#include <vnet/mfib/mfib_types.h>
24
25/**
Neale Ranns15002542017-09-10 04:39:11 -070026 * 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/**
Neale Ranns32e1c012016-11-22 17:07:28 +000032 * @brief
33 * A protocol Independent IP multicast FIB table
34 */
35typedef struct mfib_table_t_
36{
37 /**
Dave Baracheb987d32018-05-03 08:26:39 -040038 * Required for pool_get_aligned
39 */
40 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
41
42 /**
Neale Ranns32e1c012016-11-22 17:07:28 +000043 * 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 {
49 ip4_mfib_t v4;
50 ip6_mfib_t v6;
51 };
52
53 /**
54 * Which protocol this table serves. Used to switch on the union above.
55 */
56 fib_protocol_t mft_proto;
57
58 /**
59 * number of locks on the table
60 */
Neale Ranns15002542017-09-10 04:39:11 -070061 u16 mft_locks[MFIB_TABLE_N_LOCKS];
Neale Ranns32e1c012016-11-22 17:07:28 +000062
63 /**
64 * Table ID (hash key) for this FIB.
65 */
66 u32 mft_table_id;
67
68 /**
69 * Index into FIB vector.
70 */
71 fib_node_index_t mft_index;
72
73 /**
74 * Total route counters
75 */
76 u32 mft_total_route_counts;
77
78 /**
79 * Table description
80 */
81 u8* mft_desc;
82} mfib_table_t;
83
84/**
85 * @brief
86 * Format the description/name of the table
87 */
Christophe Fontained3c008d2017-10-02 18:10:54 +020088extern u8* format_mfib_table_name(u8* s, va_list *ap);
Neale Ranns32e1c012016-11-22 17:07:28 +000089
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 */
103extern 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 */
120extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
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 */
133extern fib_node_index_t mfib_table_entry_update(u32 fib_index,
134 const mfib_prefix_t *prefix,
135 mfib_source_t source,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800136 fib_rpf_id_t rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000137 mfib_entry_flags_t flags);
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 */
164extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index,
165 const mfib_prefix_t *prefix,
166 mfib_source_t source,
167 const fib_route_path_t *rpath,
168 mfib_itf_flags_t flags);
169
170/**
171 * @brief
172 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
173 * last path, then the entry will be removed, unless it has other sources.
174 * See the documentation for fib_route_path_t for more descirptions of
175 * the path parameters.
176 *
177 * @param fib_index
178 * The index of the FIB
179 *
180 * @param prefix
181 * The prefix for the entry to add
182 *
183 * @param source
184 * The ID of the client/source adding the entry.
185 *
186 * @param rpaths
187 * A vector of paths.
188 */
189extern void mfib_table_entry_path_remove(u32 fib_index,
190 const mfib_prefix_t *prefix,
191 mfib_source_t source,
192 const fib_route_path_t *paths);
193
194
195
196/**
197 * @brief
198 * Delete a FIB entry. If the entry has no more sources, then it is
199 * removed from the table.
200 *
201 * @param fib_index
202 * The index of the FIB
203 *
204 * @param prefix
205 * The prefix for the entry to remove
206 *
207 * @param source
208 * The ID of the client/source adding the entry.
209 */
210extern void mfib_table_entry_delete(u32 fib_index,
211 const mfib_prefix_t *prefix,
212 mfib_source_t source);
213
214/**
215 * @brief
216 * Delete a FIB entry. If the entry has no more sources, then it is
217 * removed from the table.
218 *
219 * @param entry_index
220 * The index of the FIB entry
221 *
222 * @param source
223 * The ID of the client/source adding the entry.
224 */
225extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
226 mfib_source_t source);
227
228/**
229 * @brief
Neale Rannsa9374df2017-02-02 02:18:18 -0800230 * Add a 'special' entry to the mFIB that links to the DPO passed
231 * A special entry is an entry that the FIB is not expect to resolve
232 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
233 * Instead the client/source provides the index of a replicate DPO to link to.
234 *
235 * @param fib_index
236 * The index of the FIB
237 *
238 * @param prefix
239 * The prefix to add
240 *
241 * @param source
242 * The ID of the client/source adding the entry.
243 *
244 * @param flags
245 * Flags for the entry.
246 *
247 * @param rep_dpo
248 * The replicate DPO index to link to.
249 *
250 * @return
251 * the index of the fib_entry_t that is created (or existed already).
252 */
253extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index,
254 const mfib_prefix_t *prefix,
255 mfib_source_t source,
256 mfib_entry_flags_t flags,
257 index_t rep_dpo);
258
259/**
260 * @brief
Neale Ranns32e1c012016-11-22 17:07:28 +0000261 * Flush all entries from a table for the source
262 *
263 * @param fib_index
264 * The index of the FIB
265 *
266 * @paran proto
267 * The protocol of the entries in the table
268 *
269 * @param source
270 * the source to flush
271 */
272extern void mfib_table_flush(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700273 fib_protocol_t proto,
274 mfib_source_t source);
Neale Ranns32e1c012016-11-22 17:07:28 +0000275
276/**
277 * @brief
278 * Get the index of the FIB bound to the interface
279 *
280 * @paran proto
281 * The protocol of the FIB (and thus the entries therein)
282 *
283 * @param sw_if_index
284 * The interface index
285 *
286 * @return fib_index
287 * The index of the FIB
288 */
289extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
290 u32 sw_if_index);
291
292/**
293 * @brief
Neale Ranns775f73c2018-12-20 03:01:49 -0800294 * Get the Table-ID of the FIB from protocol and index
295 *
296 * @param fib_index
297 * The FIB index
298 *
299 * @paran proto
300 * The protocol of the FIB (and thus the entries therein)
301 *
302 * @return fib_index
303 * The tableID of the FIB
304 */
305extern u32 mfib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
306
307/**
308 * @brief
Neale Ranns32e1c012016-11-22 17:07:28 +0000309 * Get the index of the FIB for a Table-ID. This DOES NOT create the
310 * FIB if it does not exist.
311 *
312 * @paran proto
313 * The protocol of the FIB (and thus the entries therein)
314 *
315 * @param table-id
316 * The Table-ID
317 *
318 * @return fib_index
319 * The index of the FIB, which may be INVALID.
320 */
321extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
322
323
324/**
325 * @brief
326 * Get the index of the FIB for a Table-ID. This DOES create the
327 * FIB if it does not exist.
328 *
329 * @paran proto
330 * The protocol of the FIB (and thus the entries therein)
331 *
332 * @param table-id
333 * The Table-ID
334 *
335 * @return fib_index
336 * The index of the FIB
Neale Ranns15002542017-09-10 04:39:11 -0700337 *
338 * @param source
339 * The ID of the client/source.
Neale Ranns32e1c012016-11-22 17:07:28 +0000340 */
341extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
Neale Ranns15002542017-09-10 04:39:11 -0700342 u32 table_id,
343 mfib_source_t source);
Neale Ranns32e1c012016-11-22 17:07:28 +0000344
Neale Ranns2297af02017-09-12 09:45:04 -0700345/**
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 *
362 * @param name
363 * The client is choosing the name they want the table to have
364 */
365extern u32 mfib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
366 u32 table_id,
367 mfib_source_t source,
368 const u8 *name);
369
Florin Corasd0a59722017-10-15 17:41:21 +0000370
Neale Ranns32e1c012016-11-22 17:07:28 +0000371/**
372 * @brief
373 * Take a reference counting lock on the table
374 *
375 * @param fib_index
376 * The index of the FIB
377 *
378 * @paran proto
379 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700380 *
381 * @param source
382 * The ID of the client/source.
Neale Ranns32e1c012016-11-22 17:07:28 +0000383 */
384extern void mfib_table_unlock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700385 fib_protocol_t proto,
386 mfib_source_t source);
Neale Ranns32e1c012016-11-22 17:07:28 +0000387
388/**
389 * @brief
390 * Release a reference counting lock on the table. When the last lock
391 * has gone. the FIB is deleted.
392 *
393 * @param fib_index
394 * The index of the FIB
395 *
396 * @paran proto
397 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700398 *
399 * @param source
400 * The ID of the client/source.
Neale Ranns32e1c012016-11-22 17:07:28 +0000401 */
402extern void mfib_table_lock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700403 fib_protocol_t proto,
404 mfib_source_t source);
Neale Ranns32e1c012016-11-22 17:07:28 +0000405
406/**
407 * @brief
408 * Return the number of entries in the FIB added by a given source.
409 *
410 * @param fib_index
411 * The index of the FIB
412 *
413 * @paran proto
414 * The protocol of the FIB (and thus the entries therein)
415 *
416 * @return number of sourced entries.
417 */
418extern u32 mfib_table_get_num_entries(u32 fib_index,
419 fib_protocol_t proto);
420
421/**
422 * @brief
Neale Ranns9e829a82018-12-17 05:50:32 -0800423 * Get the less specific (covering) prefix
424 *
425 * @param fib_index
426 * The index of the FIB
427 *
428 * @param prefix
429 * The prefix to lookup
430 *
431 * @return
432 * The index of the less specific fib_entry_t.
433 */
434extern fib_node_index_t mfib_table_get_less_specific(u32 fib_index,
435 const mfib_prefix_t *prefix);
436
437/**
438 * @brief
Neale Ranns32e1c012016-11-22 17:07:28 +0000439 * Get a pointer to a FIB table
440 */
441extern mfib_table_t *mfib_table_get(fib_node_index_t index,
442 fib_protocol_t proto);
443
Neale Ranns5a8123b2017-01-26 01:18:23 -0800444/**
445 * @brief Call back function when walking entries in a FIB table
446 */
447typedef int (*mfib_table_walk_fn_t)(fib_node_index_t fei,
448 void *ctx);
449
450/**
451 * @brief Walk all entries in a FIB table
452 * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
453 * table and store elements in a vector, then delete the elements
454 */
455extern void mfib_table_walk(u32 fib_index,
456 fib_protocol_t proto,
457 mfib_table_walk_fn_t fn,
458 void *ctx);
Neale Rannsc87aafa2017-11-29 00:59:31 -0800459/**
460 * @brief format (display) the memory usage for mfibs
461 */
462extern u8 * format_mfib_table_memory(u8 * s, va_list * args);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800463
Neale Ranns9e829a82018-12-17 05:50:32 -0800464/**
465 * To assit UT
466 */
467extern u32 mfib_table_get_n_routes(fib_node_index_t index,
468 fib_protocol_t proto);
469
470
Neale Ranns32e1c012016-11-22 17:07:28 +0000471#endif