IP Multicast FIB (mfib)
[vpp.git] / src / vnet / mfib / mfib_table.h
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
22 #include <vnet/mfib/mfib_types.h>
23
24 /**
25  * @brief
26  *   A protocol Independent IP multicast FIB table
27  */
28 typedef struct mfib_table_t_
29 {
30     /**
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
34      * first cache line.
35      */
36     union {
37         ip4_mfib_t v4;
38         ip6_mfib_t v6;
39     };
40
41     /**
42      * Which protocol this table serves. Used to switch on the union above.
43      */
44     fib_protocol_t mft_proto;
45
46     /**
47      * number of locks on the table
48      */
49     u16 mft_locks;
50
51     /**
52      * Table ID (hash key) for this FIB.
53      */
54     u32 mft_table_id;
55
56     /**
57      * Index into FIB vector.
58      */
59     fib_node_index_t mft_index;
60
61     /**
62      * Total route counters
63      */
64     u32 mft_total_route_counts;
65
66     /**
67      * Table description
68      */
69     u8* mft_desc;
70 } mfib_table_t;
71
72 /**
73  * @brief
74  *  Format the description/name of the table
75  */
76 extern u8* format_mfib_table_name(u8* s, va_list ap);
77
78 /**
79  * @brief
80  *  Perfom a longest prefix match in the non-forwarding table
81  *
82  * @param fib_index
83  *  The index of the FIB
84  *
85  * @param prefix
86  *  The prefix to lookup
87  *
88  * @return
89  *  The index of the fib_entry_t for the best match, which may be the default route
90  */
91 extern fib_node_index_t mfib_table_lookup(u32 fib_index,
92                                          const mfib_prefix_t *prefix);
93
94 /**
95  * @brief
96  *  Perfom an exact match in the non-forwarding table
97  *
98  * @param fib_index
99  *  The index of the FIB
100  *
101  * @param prefix
102  *  The prefix to lookup
103  *
104  * @return
105  *  The index of the fib_entry_t for the exact match, or INVALID
106  *  is there is no match.
107  */
108 extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index,
109                                                       const mfib_prefix_t *prefix);
110
111 /**
112  * @brief
113  * Add a new (with no replication) or lock an existing entry
114  *
115  * @param prefix
116  *  The prefix for the entry to add
117  *
118  * @return
119  *  the index of the fib_entry_t that is created (or existed already).
120  */
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);
125
126 /**
127  * @brief
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.
132  *
133  * @param fib_index
134  *  The index of the FIB
135  *
136  * @param prefix
137  *  The prefix for the entry to add
138  *
139  * @param source
140  *  The ID of the client/source adding the entry.
141  *
142  * @param flags
143  *  Flags for the entry.
144  *
145  * @param rpaths
146  *  A vector of paths.
147  *
148  * @return
149  *  the index of the fib_entry_t that is created (or existed already).
150  */
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);
156
157 /**
158  * @brief
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.
163  *
164  * @param fib_index
165  *  The index of the FIB
166  *
167  * @param prefix
168  *  The prefix for the entry to add
169  *
170  * @param source
171  *  The ID of the client/source adding the entry.
172  *
173  * @param rpaths
174  *  A vector of paths.
175  */
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);
180
181
182
183 /**
184  * @brief
185  *  Delete a FIB entry. If the entry has no more sources, then it is
186  * removed from the table.
187  *
188  * @param fib_index
189  *  The index of the FIB
190  *
191  * @param prefix
192  *  The prefix for the entry to remove
193  *
194  * @param source
195  *  The ID of the client/source adding the entry.
196  */
197 extern void mfib_table_entry_delete(u32 fib_index,
198                                     const mfib_prefix_t *prefix,
199                                     mfib_source_t source);
200
201 /**
202  * @brief
203  *  Delete a FIB entry. If the entry has no more sources, then it is
204  * removed from the table.
205  *
206  * @param entry_index
207  *  The index of the FIB entry
208  *
209  * @param source
210  *  The ID of the client/source adding the entry.
211  */
212 extern void mfib_table_entry_delete_index(fib_node_index_t entry_index,
213                                           mfib_source_t source);
214
215 /**
216  * @brief
217  *  Flush all entries from a table for the source
218  *
219  * @param fib_index
220  *  The index of the FIB
221  *
222  * @paran proto
223  *  The protocol of the entries in the table
224  *
225  * @param source
226  *  the source to flush
227  */
228 extern void mfib_table_flush(u32 fib_index,
229                              fib_protocol_t proto);
230
231 /**
232  * @brief
233  *  Get the index of the FIB bound to the interface
234  *
235  * @paran proto
236  *  The protocol of the FIB (and thus the entries therein)
237  *
238  * @param sw_if_index
239  *  The interface index
240  *
241  * @return fib_index
242  *  The index of the FIB
243  */
244 extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto,
245                                                 u32 sw_if_index);
246
247 /**
248  * @brief
249  *  Get the index of the FIB for a Table-ID. This DOES NOT create the
250  * FIB if it does not exist.
251  *
252  * @paran proto
253  *  The protocol of the FIB (and thus the entries therein)
254  *
255  * @param table-id
256  *  The Table-ID
257  *
258  * @return fib_index
259  *  The index of the FIB, which may be INVALID.
260  */
261 extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id);
262
263
264 /**
265  * @brief
266  *  Get the index of the FIB for a Table-ID. This DOES create the
267  * FIB if it does not exist.
268  *
269  * @paran proto
270  *  The protocol of the FIB (and thus the entries therein)
271  *
272  * @param table-id
273  *  The Table-ID
274  *
275  * @return fib_index
276  *  The index of the FIB
277  */
278 extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto,
279                                               u32 table_id);
280
281
282 /**
283  * @brief
284  * Take a reference counting lock on the table
285  *
286  * @param fib_index
287  *  The index of the FIB
288  *
289  * @paran proto
290  *  The protocol of the FIB (and thus the entries therein)
291  */
292 extern void mfib_table_unlock(u32 fib_index,
293                               fib_protocol_t proto);
294
295 /**
296  * @brief
297  * Release a reference counting lock on the table. When the last lock
298  * has gone. the FIB is deleted.
299  *
300  * @param fib_index
301  *  The index of the FIB
302  *
303  * @paran proto
304  *  The protocol of the FIB (and thus the entries therein)
305  */
306 extern void mfib_table_lock(u32 fib_index,
307                             fib_protocol_t proto);
308
309 /**
310  * @brief
311  * Return the number of entries in the FIB added by a given source.
312  *
313  * @param fib_index
314  *  The index of the FIB
315  *
316  * @paran proto
317  *  The protocol of the FIB (and thus the entries therein)
318  *
319  * @return number of sourced entries.
320  */
321 extern u32 mfib_table_get_num_entries(u32 fib_index,
322                                       fib_protocol_t proto);
323
324 /**
325  * @brief
326  * Get a pointer to a FIB table
327  */
328 extern mfib_table_t *mfib_table_get(fib_node_index_t index,
329                                     fib_protocol_t proto);
330
331 #endif