FD.io VPP  v17.04.2-2-ga8f93f8
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 static inline mpls_fib_t*
30 {
31  return (&(pool_elt_at_index(mpls_main.fibs, index)->mpls));
32 }
33 
36 // extern mpls_fib_t * mpls_fib_find(u32 table_id);
37 extern u32 mpls_fib_index_from_table_id(u32 table_id);
38 
39 extern u8 *format_mpls_fib_table_name(u8 * s, va_list * args);
40 
42  u32 table_id,
43  mpls_label_t label,
44  mpls_eos_bit_t eos,
45  fib_node_index_t fib_entry_index);
46 
47 
49  mpls_label_t label,
50  mpls_eos_bit_t eos);
51 
53  mpls_label_t label,
54  mpls_eos_bit_t eos);
56  mpls_label_t label,
57  mpls_eos_bit_t eos,
58  fib_node_index_t fei);
59 extern void mpls_fib_table_destroy(mpls_fib_t *mf);
60 
61 
62 
64  mpls_label_t label,
65  mpls_eos_bit_t eos,
66  const dpo_id_t *dpo);
68  mpls_label_t label,
69  mpls_eos_bit_t eos);
70 
71 /**
72  * @brief Walk all entries in a FIB table
73  * N.B: This is NOT safe to deletes. If you need to delete walk the whole
74  * table and store elements in a vector, then delete the elements
75  */
76 extern void mpls_fib_table_walk(mpls_fib_t *fib,
78  void *ctx);
79 
80 /**
81  * @brief
82  * Lookup a label and EOS bit in the MPLS_FIB table to retrieve the
83  * load-balance index to be used for packet forwarding.
84  */
85 static inline index_t
87  const mpls_unicast_header_t *hdr)
88 {
89  mpls_label_t label;
90  mpls_fib_t *mf;
91  u32 key;
92 
93  label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
94  key = (vnet_mpls_uc_get_label(label) << 1) | vnet_mpls_uc_get_s(label);
95 
96  mf = mpls_fib_get(mpls_fib_index);
97 
98  return (mf->mf_lbs[key]);
99 }
100 
101 static inline u32
103 {
104  mpls_main_t *mm = &mpls_main;
105 
106  ASSERT(vec_len(mm->fib_index_by_sw_if_index) > sw_if_index);
107 
108  return (mm->fib_index_by_sw_if_index[sw_if_index]);
109 }
110 
112 
113 #endif
int(* 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:733
u32 * fib_index_by_sw_if_index
Definition: mpls.h:65
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
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:41
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:313
u32 mpls_fib_index_from_table_id(u32 table_id)
Definition: mpls_fib.c:78
void mpls_fib_table_destroy(mpls_fib_t *mf)
Definition: mpls_fib.c:244
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)
static u32 mpls_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: mpls_fib.h:102
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:146
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:281
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
Definition: packet.h:77
flow_hash_config_t mpls_fib_table_get_flow_hash_config(u32 fib_index)
Definition: mpls_fib.c:340
struct fib_table_t_ * fibs
A pool of all the MPLS FIBs.
Definition: mpls.h:68
u8 * format_mpls_fib_table_name(u8 *s, va_list *args)
mpls_main_t mpls_main
Definition: mpls.c:25
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
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:296
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static mpls_fib_t * mpls_fib_get(fib_node_index_t index)
Definition: mpls_fib.h:29
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:347
void mpls_fib_table_entry_remove(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos)
Definition: mpls_fib.c:305
mpls_label_t label_exp_s_ttl
Definition: packet.h:31
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:165
u32 mpls_fib_table_create_and_lock(void)
Definition: mpls_fib.c:238
void mpls_fib_forwarding_table_reset(mpls_fib_t *mf, mpls_label_t label, mpls_eos_bit_t eos)
Definition: mpls_fib.c:328
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u32 vnet_mpls_uc_get_s(mpls_label_t label_exp_s_ttl)
Definition: packet.h:87
unsigned char u8
Definition: types.h:56
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:86
index_t mf_lbs[MPLS_FIB_DB_SIZE]
The load-balance indeices keyed by 21 bit label+eos bit.
Definition: mpls.h:53
u32 mpls_fib_table_find_or_create_and_lock(u32 table_id)
Definition: mpls_fib.c:225
enum mpls_eos_bit_t_ mpls_eos_bit_t