Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * mpls_fib.h: The Label/MPLS FIB |
| 3 | * |
| 4 | * Copyright (c) 2012 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef __MPLS_FIB_TABLE_H__ |
| 19 | #define __MPLS_FIB_TABLE_H__ |
| 20 | |
| 21 | #include <vnet/vnet.h> |
| 22 | #include <vnet/mpls/mpls.h> |
| 23 | #include <vnet/fib/fib_types.h> |
| 24 | #include <vnet/dpo/dpo.h> |
| 25 | #include <vnet/mpls/mpls.h> |
| 26 | #include <vnet/fib/fib_table.h> |
| 27 | |
| 28 | static inline mpls_fib_t* |
| 29 | mpls_fib_get (fib_node_index_t index) |
| 30 | { |
| 31 | if (!pool_is_free_index(mpls_main.fibs, index)) |
| 32 | return (&(pool_elt_at_index(mpls_main.fibs, index)->mpls)); |
| 33 | return (NULL); |
| 34 | } |
| 35 | |
| 36 | extern u32 mpls_fib_table_find_or_create_and_lock(u32 table_id); |
| 37 | extern u32 mpls_fib_table_create_and_lock(void); |
| 38 | // extern mpls_fib_t * mpls_fib_find(u32 table_id); |
| 39 | extern u32 mpls_fib_index_from_table_id(u32 table_id); |
| 40 | |
| 41 | extern u8 *format_mpls_fib_table_name(u8 * s, va_list * args); |
| 42 | |
| 43 | extern fib_node_index_t mpls_fib_table_entry_add_from_ip_fib_entry ( |
| 44 | u32 table_id, |
| 45 | mpls_label_t label, |
| 46 | mpls_eos_bit_t eos, |
| 47 | fib_node_index_t fib_entry_index); |
| 48 | |
| 49 | |
| 50 | extern fib_node_index_t mpls_fib_table_lookup(const mpls_fib_t *mf, |
| 51 | mpls_label_t label, |
| 52 | mpls_eos_bit_t eos); |
| 53 | |
| 54 | extern void mpls_fib_table_entry_remove(mpls_fib_t *mf, |
| 55 | mpls_label_t label, |
| 56 | mpls_eos_bit_t eos); |
| 57 | extern void mpls_fib_table_entry_insert(mpls_fib_t *mf, |
| 58 | mpls_label_t label, |
| 59 | mpls_eos_bit_t eos, |
| 60 | fib_node_index_t fei); |
| 61 | extern void mpls_fib_table_destroy(mpls_fib_t *mf); |
| 62 | |
| 63 | |
| 64 | |
| 65 | extern void mpls_fib_forwarding_table_update(mpls_fib_t *mf, |
| 66 | mpls_label_t label, |
| 67 | mpls_eos_bit_t eos, |
| 68 | const dpo_id_t *dpo); |
| 69 | extern void mpls_fib_forwarding_table_reset(mpls_fib_t *mf, |
| 70 | mpls_label_t label, |
| 71 | mpls_eos_bit_t eos); |
| 72 | |
| 73 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 74 | * @brief Walk all entries in a FIB table |
| 75 | * N.B: This is NOT safe to deletes. If you need to delete walk the whole |
| 76 | * table and store elements in a vector, then delete the elements |
| 77 | */ |
| 78 | extern void mpls_fib_table_walk(mpls_fib_t *fib, |
| 79 | fib_table_walk_fn_t fn, |
| 80 | void *ctx); |
| 81 | |
| 82 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 83 | * @brief |
| 84 | * Lookup a label and EOS bit in the MPLS_FIB table to retrieve the |
| 85 | * load-balance index to be used for packet forwarding. |
| 86 | */ |
| 87 | static inline index_t |
| 88 | mpls_fib_table_forwarding_lookup (u32 mpls_fib_index, |
| 89 | const mpls_unicast_header_t *hdr) |
| 90 | { |
| 91 | mpls_label_t label; |
| 92 | mpls_fib_t *mf; |
| 93 | u32 key; |
| 94 | |
| 95 | label = clib_net_to_host_u32(hdr->label_exp_s_ttl); |
| 96 | key = (vnet_mpls_uc_get_label(label) << 1) | vnet_mpls_uc_get_s(label); |
| 97 | |
| 98 | mf = mpls_fib_get(mpls_fib_index); |
| 99 | |
| 100 | return (mf->mf_lbs[key]); |
| 101 | } |
| 102 | |
| 103 | static inline u32 |
| 104 | mpls_fib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 105 | { |
| 106 | mpls_main_t *mm = &mpls_main; |
| 107 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 108 | ASSERT(vec_len(mm->fib_index_by_sw_if_index) > sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 109 | |
| 110 | return (mm->fib_index_by_sw_if_index[sw_if_index]); |
| 111 | } |
| 112 | |
| 113 | extern flow_hash_config_t mpls_fib_table_get_flow_hash_config(u32 fib_index); |
| 114 | |
| 115 | #endif |