Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 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> |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 21 | #include <vnet/dpo/replicate_dpo.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 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 { |
| 38 | ip4_mfib_t v4; |
| 39 | ip6_mfib_t v6; |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * Which protocol this table serves. Used to switch on the union above. |
| 44 | */ |
| 45 | fib_protocol_t mft_proto; |
| 46 | |
| 47 | /** |
| 48 | * number of locks on the table |
| 49 | */ |
| 50 | u16 mft_locks; |
| 51 | |
| 52 | /** |
| 53 | * Table ID (hash key) for this FIB. |
| 54 | */ |
| 55 | u32 mft_table_id; |
| 56 | |
| 57 | /** |
| 58 | * Index into FIB vector. |
| 59 | */ |
| 60 | fib_node_index_t mft_index; |
| 61 | |
| 62 | /** |
| 63 | * Total route counters |
| 64 | */ |
| 65 | u32 mft_total_route_counts; |
| 66 | |
| 67 | /** |
| 68 | * Table description |
| 69 | */ |
| 70 | u8* mft_desc; |
| 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 | */ |
| 109 | extern fib_node_index_t mfib_table_lookup_exact_match(u32 fib_index, |
| 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 | */ |
| 122 | extern fib_node_index_t mfib_table_entry_update(u32 fib_index, |
| 123 | const mfib_prefix_t *prefix, |
| 124 | mfib_source_t source, |
| 125 | mfib_entry_flags_t flags); |
| 126 | |
| 127 | /** |
| 128 | * @brief |
| 129 | * Add n paths to an entry (aka route) in the FIB. If the entry does not |
| 130 | * exist, it will be created. |
| 131 | * See the documentation for fib_route_path_t for more descirptions of |
| 132 | * the path parameters. |
| 133 | * |
| 134 | * @param fib_index |
| 135 | * The index of the FIB |
| 136 | * |
| 137 | * @param prefix |
| 138 | * The prefix for the entry to add |
| 139 | * |
| 140 | * @param source |
| 141 | * The ID of the client/source adding the entry. |
| 142 | * |
| 143 | * @param flags |
| 144 | * Flags for the entry. |
| 145 | * |
| 146 | * @param rpaths |
| 147 | * A vector of paths. |
| 148 | * |
| 149 | * @return |
| 150 | * the index of the fib_entry_t that is created (or existed already). |
| 151 | */ |
| 152 | extern fib_node_index_t mfib_table_entry_path_update(u32 fib_index, |
| 153 | const mfib_prefix_t *prefix, |
| 154 | mfib_source_t source, |
| 155 | const fib_route_path_t *rpath, |
| 156 | mfib_itf_flags_t flags); |
| 157 | |
| 158 | /** |
| 159 | * @brief |
| 160 | * Remove n paths to an entry (aka route) in the FIB. If this is the entry's |
| 161 | * last path, then the entry will be removed, unless it has other sources. |
| 162 | * See the documentation for fib_route_path_t for more descirptions of |
| 163 | * the path parameters. |
| 164 | * |
| 165 | * @param fib_index |
| 166 | * The index of the FIB |
| 167 | * |
| 168 | * @param prefix |
| 169 | * The prefix for the entry to add |
| 170 | * |
| 171 | * @param source |
| 172 | * The ID of the client/source adding the entry. |
| 173 | * |
| 174 | * @param rpaths |
| 175 | * A vector of paths. |
| 176 | */ |
| 177 | extern void mfib_table_entry_path_remove(u32 fib_index, |
| 178 | const mfib_prefix_t *prefix, |
| 179 | mfib_source_t source, |
| 180 | const fib_route_path_t *paths); |
| 181 | |
| 182 | |
| 183 | |
| 184 | /** |
| 185 | * @brief |
| 186 | * Delete a FIB entry. If the entry has no more sources, then it is |
| 187 | * removed from the table. |
| 188 | * |
| 189 | * @param fib_index |
| 190 | * The index of the FIB |
| 191 | * |
| 192 | * @param prefix |
| 193 | * The prefix for the entry to remove |
| 194 | * |
| 195 | * @param source |
| 196 | * The ID of the client/source adding the entry. |
| 197 | */ |
| 198 | extern void mfib_table_entry_delete(u32 fib_index, |
| 199 | const mfib_prefix_t *prefix, |
| 200 | mfib_source_t source); |
| 201 | |
| 202 | /** |
| 203 | * @brief |
| 204 | * Delete a FIB entry. If the entry has no more sources, then it is |
| 205 | * removed from the table. |
| 206 | * |
| 207 | * @param entry_index |
| 208 | * The index of the FIB entry |
| 209 | * |
| 210 | * @param source |
| 211 | * The ID of the client/source adding the entry. |
| 212 | */ |
| 213 | extern void mfib_table_entry_delete_index(fib_node_index_t entry_index, |
| 214 | mfib_source_t source); |
| 215 | |
| 216 | /** |
| 217 | * @brief |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 218 | * Add a 'special' entry to the mFIB that links to the DPO passed |
| 219 | * A special entry is an entry that the FIB is not expect to resolve |
| 220 | * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). |
| 221 | * Instead the client/source provides the index of a replicate DPO to link to. |
| 222 | * |
| 223 | * @param fib_index |
| 224 | * The index of the FIB |
| 225 | * |
| 226 | * @param prefix |
| 227 | * The prefix to add |
| 228 | * |
| 229 | * @param source |
| 230 | * The ID of the client/source adding the entry. |
| 231 | * |
| 232 | * @param flags |
| 233 | * Flags for the entry. |
| 234 | * |
| 235 | * @param rep_dpo |
| 236 | * The replicate DPO index to link to. |
| 237 | * |
| 238 | * @return |
| 239 | * the index of the fib_entry_t that is created (or existed already). |
| 240 | */ |
| 241 | extern fib_node_index_t mfib_table_entry_special_add(u32 fib_index, |
| 242 | const mfib_prefix_t *prefix, |
| 243 | mfib_source_t source, |
| 244 | mfib_entry_flags_t flags, |
| 245 | index_t rep_dpo); |
| 246 | |
| 247 | /** |
| 248 | * @brief |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 249 | * Flush all entries from a table for the source |
| 250 | * |
| 251 | * @param fib_index |
| 252 | * The index of the FIB |
| 253 | * |
| 254 | * @paran proto |
| 255 | * The protocol of the entries in the table |
| 256 | * |
| 257 | * @param source |
| 258 | * the source to flush |
| 259 | */ |
| 260 | extern void mfib_table_flush(u32 fib_index, |
| 261 | fib_protocol_t proto); |
| 262 | |
| 263 | /** |
| 264 | * @brief |
| 265 | * Get the index of the FIB bound to the interface |
| 266 | * |
| 267 | * @paran proto |
| 268 | * The protocol of the FIB (and thus the entries therein) |
| 269 | * |
| 270 | * @param sw_if_index |
| 271 | * The interface index |
| 272 | * |
| 273 | * @return fib_index |
| 274 | * The index of the FIB |
| 275 | */ |
| 276 | extern u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto, |
| 277 | u32 sw_if_index); |
| 278 | |
| 279 | /** |
| 280 | * @brief |
| 281 | * Get the index of the FIB for a Table-ID. This DOES NOT create the |
| 282 | * FIB if it does not exist. |
| 283 | * |
| 284 | * @paran proto |
| 285 | * The protocol of the FIB (and thus the entries therein) |
| 286 | * |
| 287 | * @param table-id |
| 288 | * The Table-ID |
| 289 | * |
| 290 | * @return fib_index |
| 291 | * The index of the FIB, which may be INVALID. |
| 292 | */ |
| 293 | extern u32 mfib_table_find(fib_protocol_t proto, u32 table_id); |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * @brief |
| 298 | * Get the index of the FIB for a Table-ID. This DOES create the |
| 299 | * FIB if it does not exist. |
| 300 | * |
| 301 | * @paran proto |
| 302 | * The protocol of the FIB (and thus the entries therein) |
| 303 | * |
| 304 | * @param table-id |
| 305 | * The Table-ID |
| 306 | * |
| 307 | * @return fib_index |
| 308 | * The index of the FIB |
| 309 | */ |
| 310 | extern u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto, |
| 311 | u32 table_id); |
| 312 | |
| 313 | |
| 314 | /** |
| 315 | * @brief |
| 316 | * Take a reference counting lock on the table |
| 317 | * |
| 318 | * @param fib_index |
| 319 | * The index of the FIB |
| 320 | * |
| 321 | * @paran proto |
| 322 | * The protocol of the FIB (and thus the entries therein) |
| 323 | */ |
| 324 | extern void mfib_table_unlock(u32 fib_index, |
| 325 | fib_protocol_t proto); |
| 326 | |
| 327 | /** |
| 328 | * @brief |
| 329 | * Release a reference counting lock on the table. When the last lock |
| 330 | * has gone. the FIB is deleted. |
| 331 | * |
| 332 | * @param fib_index |
| 333 | * The index of the FIB |
| 334 | * |
| 335 | * @paran proto |
| 336 | * The protocol of the FIB (and thus the entries therein) |
| 337 | */ |
| 338 | extern void mfib_table_lock(u32 fib_index, |
| 339 | fib_protocol_t proto); |
| 340 | |
| 341 | /** |
| 342 | * @brief |
| 343 | * Return the number of entries in the FIB added by a given source. |
| 344 | * |
| 345 | * @param fib_index |
| 346 | * The index of the FIB |
| 347 | * |
| 348 | * @paran proto |
| 349 | * The protocol of the FIB (and thus the entries therein) |
| 350 | * |
| 351 | * @return number of sourced entries. |
| 352 | */ |
| 353 | extern u32 mfib_table_get_num_entries(u32 fib_index, |
| 354 | fib_protocol_t proto); |
| 355 | |
| 356 | /** |
| 357 | * @brief |
| 358 | * Get a pointer to a FIB table |
| 359 | */ |
| 360 | extern mfib_table_t *mfib_table_get(fib_node_index_t index, |
| 361 | fib_protocol_t proto); |
| 362 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 363 | /** |
| 364 | * @brief Call back function when walking entries in a FIB table |
| 365 | */ |
| 366 | typedef int (*mfib_table_walk_fn_t)(fib_node_index_t fei, |
| 367 | void *ctx); |
| 368 | |
| 369 | /** |
| 370 | * @brief Walk all entries in a FIB table |
| 371 | * N.B: This is NOT safe to deletes. If you need to delete, walk the whole |
| 372 | * table and store elements in a vector, then delete the elements |
| 373 | */ |
| 374 | extern void mfib_table_walk(u32 fib_index, |
| 375 | fib_protocol_t proto, |
| 376 | mfib_table_walk_fn_t fn, |
| 377 | void *ctx); |
| 378 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 379 | #endif |