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