FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
ip4_fib.h
Go to the documentation of this file.
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  * @brief The IPv4 FIB
17  *
18  * FIBs are composed of two prefix data-bases (akak tables). The non-forwarding
19  * table contains all the routes that the control plane has programmed, the
20  * forwarding table contains the sub-set of those routes that can be used to
21  * forward packets.
22  * In the IPv4 FIB the non-forwarding table is an array of hash tables indexed
23  * by mask length, the forwarding table is an mtrie
24  *
25  * This IPv4 FIB is used by the protocol independent FIB. So directly using
26  * this APIs in client code is not encouraged. However, this IPv4 FIB can be
27  * used if all the client wants is an IPv4 prefix data-base
28  */
29 
30 #ifndef __IP4_FIB_H__
31 #define __IP4_FIB_H__
32 
33 #include <vlib/vlib.h>
34 #include <vnet/ip/ip.h>
35 #include <vnet/fib/fib_entry.h>
36 #include <vnet/fib/fib_table.h>
37 
39  const ip4_address_t *addr,
40  u32 len);
42  const ip4_address_t *addr,
43  u32 len);
44 
45 extern void ip4_fib_table_entry_remove(ip4_fib_t *fib,
46  const ip4_address_t *addr,
47  u32 len);
48 
49 extern void ip4_fib_table_entry_insert(ip4_fib_t *fib,
50  const ip4_address_t *addr,
51  u32 len,
52  fib_node_index_t fib_entry_index);
53 extern void ip4_fib_table_destroy(ip4_fib_t *fib);
54 
56  const ip4_address_t *addr,
57  u32 len,
58  const dpo_id_t *dpo);
59 
61  const ip4_address_t *addr,
62  u32 len,
63  const dpo_id_t *dpo);
65  const ip4_address_t * dst);
66 
67 /**
68  * @brief Get the FIB at the given index
69  */
70 static inline ip4_fib_t *
72 {
73  return (&(pool_elt_at_index(ip4_main.fibs, index)->v4));
74 }
75 
77 ip4_fib_lookup (ip4_main_t * im, u32 sw_if_index, ip4_address_t * dst)
78 {
80  ip4_fib_get(vec_elt (im->fib_index_by_sw_if_index, sw_if_index)),
81  dst));
82 }
83 
84 /**
85  * @brief Get or create an IPv4 fib.
86  *
87  * Get or create an IPv4 fib with the provided table ID.
88  *
89  * @param table_id
90  * When set to \c ~0, an arbitrary and unused fib ID is picked
91  * and can be retrieved with \c ret->table_id.
92  * Otherwise, the fib ID to be used to retrieve or create the desired fib.
93  * @returns A pointer to the retrieved or created fib.
94  *
95  */
98 
99 
100 static inline
102 {
103  ip4_main_t * im = &ip4_main;
104  uword * p;
105 
106  p = hash_get (im->fib_index_by_table_id, table_id);
107  if (!p)
108  return ~0;
109 
110  return p[0];
111 }
112 
114 
116 
117 
120  const ip4_address_t * addr)
121 {
123  ip4_fib_mtrie_t * mtrie;
124 
125  mtrie = &ip4_fib_get(fib_index)->mtrie;
126 
128  leaf = ip4_fib_mtrie_lookup_step (mtrie, leaf, addr, 0);
129  leaf = ip4_fib_mtrie_lookup_step (mtrie, leaf, addr, 1);
130  leaf = ip4_fib_mtrie_lookup_step (mtrie, leaf, addr, 2);
131  leaf = ip4_fib_mtrie_lookup_step (mtrie, leaf, addr, 3);
132 
133  /* Handle default route. */
134  leaf = (leaf == IP4_FIB_MTRIE_LEAF_EMPTY ? mtrie->default_leaf : leaf);
135 
136  return (ip4_fib_mtrie_leaf_get_adj_index(leaf));
137 }
138 
139 
140 #endif
141 
static u32 ip4_fib_lookup(ip4_main_t *im, u32 sw_if_index, ip4_address_t *dst)
Definition: ip4_fib.h:77
u32 ip4_fib_table_lookup_lb(ip4_fib_t *fib, const ip4_address_t *dst)
Definition: ip4_fib.c:261
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
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:105
u32 ip4_fib_table_find_or_create_and_lock(u32 table_id)
Get or create an IPv4 fib.
Definition: ip4_fib.c:192
#define IP4_FIB_MTRIE_LEAF_EMPTY
Definition: ip4_mtrie.h:54
static ip4_fib_mtrie_leaf_t ip4_fib_mtrie_lookup_step(ip4_fib_mtrie_t *m, ip4_fib_mtrie_leaf_t current_leaf, const ip4_address_t *dst_address, u32 dst_address_byte_index)
Definition: ip4_mtrie.h:164
#define always_inline
Definition: clib.h:84
void ip4_fib_table_entry_insert(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, fib_node_index_t fib_entry_index)
Definition: ip4_fib.c:308
flow_hash_config_t ip4_fib_table_get_flow_hash_config(u32 fib_index)
Definition: ip4_fib.c:226
u32 ip4_fib_mtrie_leaf_t
Definition: ip4_mtrie.h:52
static u32 ip4_fib_mtrie_leaf_get_adj_index(ip4_fib_mtrie_leaf_t n)
Definition: ip4_mtrie.h:76
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
#define hash_get(h, key)
Definition: hash.h:248
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:112
void ip4_fib_table_entry_remove(ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:338
void ip4_fib_table_fwding_dpo_update(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, const dpo_id_t *dpo)
Definition: ip4_fib.c:364
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
Definition: ip4_fib.h:71
Definition: ip4.h:48
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:101
#define IP4_FIB_MTRIE_LEAF_ROOT
Definition: ip4_mtrie.h:55
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
The IPv4 FIB.
Definition: ip4_fib.c:285
unsigned int u32
Definition: types.h:88
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip4_fib.c:212
IPv4 main type.
Definition: ip4.h:95
static index_t ip4_fib_forwarding_lookup(u32 fib_index, const ip4_address_t *addr)
Definition: ip4_fib.h:119
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:160
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
ip4_fib_mtrie_t mtrie
Definition: ip4.h:54
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1099
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:100
u32 ip4_fib_table_create_and_lock(void)
Definition: ip4_fib.c:206
fib_node_index_t ip4_fib_table_lookup_exact_match(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:237
vhost_vring_addr_t addr
Definition: vhost-user.h:81
void ip4_fib_table_fwding_dpo_remove(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, const dpo_id_t *dpo)
Definition: ip4_fib.c:373
void ip4_fib_table_destroy(ip4_fib_t *fib)
Definition: ip4_fib.c:154
ip4_fib_mtrie_leaf_t default_leaf
Definition: ip4_mtrie.h:145