FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
mpls_fib.h
Go to the documentation of this file.
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 #define MPLS_FIB_DEFAULT_TABLE_ID 0
29 
30 /**
31  * Type exposure is to allow the DP fast/inlined access
32  */
33 #define MPLS_FIB_KEY_SIZE 21
34 #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1))
35 
36 /**
37  * There are no options for controlling the MPLS flow hash,
38  * but since it mostly entails using IP data to create one, use that.
39  */
40 #define MPLS_FLOW_HASH_DEFAULT IP_FLOW_HASH_DEFAULT
41 
42 typedef struct mpls_fib_t_
43 {
44  /**
45  * Required for pool_get_aligned
46  */
47  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
48 
49  /**
50  * A hash table of entries. 21 bit key
51  * Hash table for reduced memory footprint
52  */
54 
55  /**
56  * The load-balance indices keyed by 21 bit label+eos bit.
57  * A flat array for maximum lookup performace.
58  */
60 } mpls_fib_t;
61 
62 static inline mpls_fib_t*
64 {
66 }
67 
71 // extern mpls_fib_t * mpls_fib_find(u32 table_id);
73 
74 extern u8 *format_mpls_fib_table_name(u8 * s, va_list * args);
75 
77  u32 table_id,
79  mpls_eos_bit_t eos,
80  fib_node_index_t fib_entry_index);
81 
82 
85  mpls_eos_bit_t eos);
86 
89  mpls_eos_bit_t eos);
92  mpls_eos_bit_t eos,
93  fib_node_index_t fei);
94 extern void mpls_fib_table_destroy(u32 fib_index);
95 
96 
99  mpls_eos_bit_t eos,
100  const dpo_id_t *dpo);
103  mpls_eos_bit_t eos);
104 
105 /**
106  * @brief Walk all entries in a FIB table
107  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
108  * table and store elements in a vector, then delete the elements
109  */
110 extern void mpls_fib_table_walk(mpls_fib_t *fib,
112  void *ctx);
113 
114 extern u8 *format_mpls_fib_table_memory(u8 * s, va_list * args);
115 
116 /**
117  * @brief
118  * Lookup a label and EOS bit in the MPLS_FIB table to retrieve the
119  * load-balance index to be used for packet forwarding.
120  */
121 static inline index_t
123  const mpls_unicast_header_t *hdr)
124 {
126  mpls_fib_t *mf;
127  u32 key;
128 
129  label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
131 
132  mf = mpls_fib_get(mpls_fib_index);
133 
134  return (mf->mf_lbs[key]);
135 }
136 
137 static inline u32
139 {
140  mpls_main_t *mm = &mpls_main;
141 
143 
145 }
146 
147 #endif
mpls_fib_forwarding_table_reset
void mpls_fib_forwarding_table_reset(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos)
Definition: mpls_fib.c:338
label
u32 label
Definition: fib_types.api:25
vnet_mpls_uc_get_s
static u32 vnet_mpls_uc_get_s(mpls_label_t label_exp_s_ttl)
Definition: packet.h:115
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
mpls_main
mpls_main_t mpls_main
Definition: mpls.c:25
mpls_fib_forwarding_table_update
void mpls_fib_forwarding_table_update(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos, const dpo_id_t *dpo)
Definition: mpls_fib.c:316
mpls_fib_t_
Definition: mpls_fib.h:42
fib_table.h
mpls_unicast_header_t
Definition: packet.h:28
vnet_mpls_uc_get_label
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
Definition: packet.h:105
mpls.h
MPLS_FIB_DB_SIZE
#define MPLS_FIB_DB_SIZE
Definition: mpls_fib.h:34
mpls_fib_table_lookup
fib_node_index_t mpls_fib_table_lookup(const mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos)
Definition: mpls_fib.c:284
key
typedef key
Definition: ipsec_types.api:91
mpls_fib_table_entry_add_from_ip_fib_entry
fib_node_index_t mpls_fib_table_entry_add_from_ip_fib_entry(u32 table_id, mpls_label_t label, mpls_eos_bit_t eos, fib_node_index_t fib_entry_index)
format_mpls_fib_table_memory
u8 * format_mpls_fib_table_memory(u8 *s, va_list *args)
Definition: mpls_fib.c:364
mpls_fib_t_::CLIB_CACHE_LINE_ALIGN_MARK
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
Required for pool_get_aligned.
mpls_fib_table_get_index_for_sw_if_index
static u32 mpls_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: mpls_fib.h:138
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
dpo.h
mpls_fib_table_entry_insert
void mpls_fib_table_entry_insert(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos, fib_node_index_t fei)
Definition: mpls_fib.c:299
mpls_fib_index_from_table_id
u32 mpls_fib_index_from_table_id(u32 table_id)
Definition: mpls_fib.c:73
fib_types.h
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
uword
u64 uword
Definition: types.h:112
mpls_fib_t_::mf_lbs
index_t mf_lbs[MPLS_FIB_DB_SIZE]
The load-balance indices keyed by 21 bit label+eos bit.
Definition: mpls_fib.h:59
src
vl_api_address_t src
Definition: gre.api:54
fib_table_walk_fn_t
fib_table_walk_rc_t(* fib_table_walk_fn_t)(fib_node_index_t fei, void *ctx)
Call back function when walking entries in a FIB table.
Definition: fib_table.h:930
mpls_fib_table_find_or_create_and_lock
u32 mpls_fib_table_find_or_create_and_lock(u32 table_id, fib_source_t src)
Definition: mpls_fib.c:224
index
u32 index
Definition: flow_types.api:221
mpls_fib_get
static mpls_fib_t * mpls_fib_get(fib_node_index_t index)
Definition: mpls_fib.h:63
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
format_mpls_fib_table_name
u8 * format_mpls_fib_table_name(u8 *s, va_list *args)
table_id
u32 table_id
Definition: wireguard.api:102
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
mpls_fib_table_create_and_lock
u32 mpls_fib_table_create_and_lock(fib_source_t src)
Definition: mpls_fib.c:238
mpls_fib_t
struct mpls_fib_t_ mpls_fib_t
mpls_fib_table_walk
void mpls_fib_table_walk(mpls_fib_t *fib, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a FIB table N.B: This is NOT safe to deletes.
Definition: mpls_fib.c:350
mpls_unicast_header_t::label_exp_s_ttl
mpls_label_t label_exp_s_ttl
Definition: packet.h:33
mpls_fib_table_forwarding_lookup
static index_t mpls_fib_table_forwarding_lookup(u32 mpls_fib_index, const mpls_unicast_header_t *hdr)
Lookup a label and EOS bit in the MPLS_FIB table to retrieve the load-balance index to be used for pa...
Definition: mpls_fib.h:122
u8
unsigned char u8
Definition: types.h:56
mpls_main_t
Definition: mpls.h:41
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
fib_source_t
enum fib_source_t_ fib_source_t
The different sources that can create a route.
mpls_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: mpls.h:44
mpls_label_t
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:26
mpls_fib_table_entry_remove
void mpls_fib_table_entry_remove(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos)
Definition: mpls_fib.c:308
vnet.h
mpls_eos_bit_t
enum mpls_eos_bit_t_ mpls_eos_bit_t
mpls_fib_t_::mf_entries
uword * mf_entries
A hash table of entries.
Definition: mpls_fib.h:53
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
mpls_fib_table_destroy
void mpls_fib_table_destroy(u32 fib_index)
Definition: mpls_fib.c:244
mpls_main_t::mpls_fibs
struct mpls_fib_t_ * mpls_fibs
A pool of all the MPLS FIBs.
Definition: mpls.h:50