FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bier_fmask_db.c
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 
17 #include <vnet/bier/bier_fmask.h>
18 
19 /**
20  * Global Table of fmask objects
21  * The key into this table includes the table's key and the fmask's key,
22  * so there could be a DB per-table. But it is more efficient
23  * at forwarding time to extract the fmask from a single global table
24  * which is hot in dcache.
25  *
26  * The table's key is part of this DB key, since the fmasks therein build up
27  * their forwarding mask based on the routes that resolve through
28  * it, so cross pollination would be bad.
29  */
30 typedef struct bier_fmask_db_t_ {
31  /**
32  * hash table for underlying storage
33  */
35 
36  /**
37  * Pool for memory
38  */
41 
42 /**
43  * Single fmask DB
44  */
46 
47 
48 u32
50 {
51  return (bfm - bier_fmask_db.bfdb_pool);
52 }
53 
54 static void
56  const fib_route_path_t *rpath,
58 {
59  /*
60  * Depending on what the ID is there may be padding.
61  * This key will be memcmp'd in the mhash, so make sure it's all 0
62  */
63  clib_memset(key, 0, sizeof(*key));
64 
65  /*
66  * Pick the attributes from the path that make the FMask unique
67  */
69  {
70  key->bfmi_id = rpath->frp_udp_encap_id;
71  key->bfmi_nh_type = BIER_NH_UDP;
72  }
73  else
74  {
75  memcpy(&key->bfmi_nh, &rpath->frp_addr, sizeof(rpath->frp_addr));
76  key->bfmi_nh_type = BIER_NH_IP;
77  }
78  if (NULL == rpath->frp_label_stack)
79  {
80  key->bfmi_hdr_type = BIER_HDR_O_OTHER;
81  }
82  else
83  {
84  key->bfmi_hdr_type = BIER_HDR_O_MPLS;
85  }
86  key->bfmi_bti = bti;
87 }
88 
89 u32
91  const fib_route_path_t *rpath)
92 {
93  bier_fmask_id_t fmid;
94  uword *p;
95 
96  bier_fmask_db_mk_key(bti, rpath, &fmid);
98 
99  if (NULL != p)
100  {
101  return (p[0]);
102  }
103 
104  return (INDEX_INVALID);
105 }
106 
107 u32
109  const fib_route_path_t *rpath)
110 {
111  bier_fmask_id_t fmid;
112  u32 index;
113  uword *p;
114 
115  bier_fmask_db_mk_key(bti, rpath, &fmid);
117 
118  if (NULL == p)
119  {
120  bier_fmask_t *bfm;
121  /*
122  * adding a new fmask object
123  */
124  index = bier_fmask_create_and_lock(&fmid, rpath);
125  bfm = bier_fmask_get(index);
127  }
128  else
129  {
130  index = p[0];
132  }
133 
134  return (index);
135 }
136 
137 void
139 {
140  uword *p;
141 
143 
144  if (NULL == p) {
145  /*
146  * remove a non-existent entry - oops
147  */
148  ASSERT (!"remove non-existent fmask");
149  } else {
151  }
152 }
153 
154 void
156 {
158  uword *bfmi;
159 
161  ({
162  if (WALK_STOP == fn(*bfmi, ctx))
163  break;
164  }));
165 }
166 
167 clib_error_t *
169 {
171  sizeof(bier_fmask_id_t),
172  sizeof(index_t));
173 
174  return (NULL);
175 }
176 
bier_fmask_db_find
u32 bier_fmask_db_find(index_t bti, const fib_route_path_t *rpath)
Definition: bier_fmask_db.c:90
BIER_HDR_O_MPLS
@ BIER_HDR_O_MPLS
BIER Header in MPLS networks.
Definition: bier_fmask_db.h:33
fib_route_path_t_::frp_addr
ip46_address_t frp_addr
The next-hop address.
Definition: fib_types.h:516
bier_fmask_db_find_or_create_and_lock
u32 bier_fmask_db_find_or_create_and_lock(index_t bti, const fib_route_path_t *rpath)
Definition: bier_fmask_db.c:108
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
bier_fmask_db
static bier_fmask_db_t bier_fmask_db
Single fmask DB.
Definition: bier_fmask_db.c:45
bier_fmask_db_walk
void bier_fmask_db_walk(bier_fmask_walk_fn_t fn, void *ctx)
Definition: bier_fmask_db.c:155
bier_fmask_db_t_
Global Table of fmask objects The key into this table includes the table's key and the fmask's key,...
Definition: bier_fmask_db.c:30
key
typedef key
Definition: ipsec_types.api:88
fib_route_path_t_::frp_label_stack
fib_mpls_label_t * frp_label_stack
The outgoing MPLS label Stack.
Definition: fib_types.h:560
bier_fmask_db_mk_key
static void bier_fmask_db_mk_key(index_t bti, const fib_route_path_t *rpath, bier_fmask_id_t *key)
Definition: bier_fmask_db.c:55
BIER_HDR_O_OTHER
@ BIER_HDR_O_OTHER
BIER header in non-MPLS networks.
Definition: bier_fmask_db.h:38
bier_fmask_db_remove
void bier_fmask_db_remove(const bier_fmask_id_t *fmid)
Definition: bier_fmask_db.c:138
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
bier_fmask_db_module_init
clib_error_t * bier_fmask_db_module_init(vlib_main_t *vm)
Definition: bier_fmask_db.c:168
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
bier_fmask_lock
void bier_fmask_lock(index_t bfmi)
Definition: bier_fmask.c:269
uword
u64 uword
Definition: types.h:112
hash_create_mem
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:660
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
hash_foreach
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:441
bier_fmask_create_and_lock
index_t bier_fmask_create_and_lock(const bier_fmask_id_t *fmid, const fib_route_path_t *rpath)
Definition: bier_fmask.c:284
FIB_ROUTE_PATH_UDP_ENCAP
@ FIB_ROUTE_PATH_UDP_ENCAP
A path via a UDP encap object.
Definition: fib_types.h:373
BIER_NH_UDP
@ BIER_NH_UDP
BIER header in non-MPLS networks.
Definition: bier_fmask_db.h:53
bier_fmask_db_t
struct bier_fmask_db_t_ bier_fmask_db_t
Global Table of fmask objects The key into this table includes the table's key and the fmask's key,...
bier_fmask_walk_fn_t
walk_rc_t(* bier_fmask_walk_fn_t)(index_t bfmi, void *ctx)
Walk all the BIER fmasks.
Definition: bier_fmask_db.h:99
bier_fmask_t_::bfm_id
bier_fmask_id_t * bfm_id
The key to this fmask - used for store/lookup in the DB.
Definition: bier_fmask.h:124
bier_fmask_get_index
u32 bier_fmask_get_index(const bier_fmask_t *bfm)
Definition: bier_fmask_db.c:49
index
u32 index
Definition: flow_types.api:221
fib_route_path_t_::frp_flags
fib_route_path_flags_t frp_flags
flags on the path
Definition: fib_types.h:609
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
bier_fmask_db_t_::bfdb_pool
struct bier_fmask_t_ * bfdb_pool
Pool for memory.
Definition: bier_fmask_db.c:39
bier_fmask.h
BIER_NH_IP
@ BIER_NH_IP
BIER Header in MPLS networks.
Definition: bier_fmask_db.h:48
bier_fmask_db_t_::bfdb_hash
uword * bfdb_hash
hash table for underlying storage
Definition: bier_fmask_db.c:34
fib_route_path_t_::frp_udp_encap_id
u32 frp_udp_encap_id
UDP encap ID.
Definition: fib_types.h:579
bier_fmask_t_
An outgoing BIER mask.
Definition: bier_fmask.h:99
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
bier_fmask_db.h
bier_fmask_id_t_
A key/ID for a BIER forwarding Mas (FMask).
Definition: bier_fmask_db.h:60
bier_fmask_get
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:177