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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __MFIB_TABLE_H__
17 #define __MFIB_TABLE_H__
19 #include <vnet/ip/ip.h>
20 #include <vnet/adj/adj.h>
22 #include <vnet/mfib/mfib_types.h>
26 * A protocol Independent IP multicast FIB table
28 typedef struct mfib_table_t_
31 * A union of the protocol specific FIBs that provide the
32 * underlying LPM mechanism.
33 * This element is first in the struct so that it is in the
42 * Which protocol this table serves. Used to switch on the union above.
44 fib_protocol_t mft_proto;
47 * number of locks on the table
52 * Table ID (hash key) for this FIB.
57 * Index into FIB vector.
59 fib_node_index_t mft_index;
62 * Total route counters
64 u32 mft_total_route_counts;
74 * Format the description/name of the table
76 extern u8* format_mfib_table_name(u8* s, va_list ap);
80 * Perfom a longest prefix match in the non-forwarding table
83 * The index of the FIB
86 * The prefix to lookup
89 * The index of the fib_entry_t for the best match, which may be the default route
91 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
92 const mfib_prefix_t *prefix);
96 * Perfom an exact match in the non-forwarding table
99 * The index of the FIB
102 * The prefix to lookup
105 * The index of the fib_entry_t for the exact match, or INVALID
106 * is there is no match.
108 extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
109 const mfib_prefix_t *prefix);
113 * Add a new (with no replication) or lock an existing entry
116 * The prefix for the entry to add
119 * the index of the fib_entry_t that is created (or existed already).
121 extern fib_node_index_t mfib_table_entry_update(u32 fib_index,
122 const mfib_prefix_t *prefix,
123 mfib_source_t source,
124 mfib_entry_flags_t flags);
128 * Add n paths to an entry (aka route) in the FIB. If the entry does not
129 * exist, it will be created.
130 * See the documentation for fib_route_path_t for more descirptions of
131 * the path parameters.
134 * The index of the FIB
137 * The prefix for the entry to add
140 * The ID of the client/source adding the entry.
143 * Flags for the entry.
149 * the index of the fib_entry_t that is created (or existed already).
151 extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index,
152 const mfib_prefix_t *prefix,
153 mfib_source_t source,
154 const fib_route_path_t *rpath,
155 mfib_itf_flags_t flags);
159 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
160 * last path, then the entry will be removed, unless it has other sources.
161 * See the documentation for fib_route_path_t for more descirptions of
162 * the path parameters.
165 * The index of the FIB
168 * The prefix for the entry to add
171 * The ID of the client/source adding the entry.
176 extern void mfib_table_entry_path_remove(u32 fib_index,
177 const mfib_prefix_t *prefix,
178 mfib_source_t source,
179 const fib_route_path_t *paths);
185 * Delete a FIB entry. If the entry has no more sources, then it is
186 * removed from the table.
189 * The index of the FIB
192 * The prefix for the entry to remove
195 * The ID of the client/source adding the entry.
197 extern void mfib_table_entry_delete(u32 fib_index,
198 const mfib_prefix_t *prefix,
199 mfib_source_t source);
203 * Delete a FIB entry. If the entry has no more sources, then it is
204 * removed from the table.
207 * The index of the FIB entry
210 * The ID of the client/source adding the entry.
212 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
213 mfib_source_t source);
217 * Flush all entries from a table for the source
220 * The index of the FIB
223 * The protocol of the entries in the table
226 * the source to flush
228 extern void mfib_table_flush(u32 fib_index,
229 fib_protocol_t proto);
233 * Get the index of the FIB bound to the interface
236 * The protocol of the FIB (and thus the entries therein)
239 * The interface index
242 * The index of the FIB
244 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
249 * Get the index of the FIB for a Table-ID. This DOES NOT create the
250 * FIB if it does not exist.
253 * The protocol of the FIB (and thus the entries therein)
259 * The index of the FIB, which may be INVALID.
261 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
266 * Get the index of the FIB for a Table-ID. This DOES create the
267 * FIB if it does not exist.
270 * The protocol of the FIB (and thus the entries therein)
276 * The index of the FIB
278 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
284 * Take a reference counting lock on the table
287 * The index of the FIB
290 * The protocol of the FIB (and thus the entries therein)
292 extern void mfib_table_unlock(u32 fib_index,
293 fib_protocol_t proto);
297 * Release a reference counting lock on the table. When the last lock
298 * has gone. the FIB is deleted.
301 * The index of the FIB
304 * The protocol of the FIB (and thus the entries therein)
306 extern void mfib_table_lock(u32 fib_index,
307 fib_protocol_t proto);
311 * Return the number of entries in the FIB added by a given source.
314 * The index of the FIB
317 * The protocol of the FIB (and thus the entries therein)
319 * @return number of sourced entries.
321 extern u32 mfib_table_get_num_entries(u32 fib_index,
322 fib_protocol_t proto);
326 * Get a pointer to a FIB table
328 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
329 fib_protocol_t proto);