FD.io VPP  v20.01-48-g3e0dafb74
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;
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  {
81  }
82  else
83  {
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);
97  p = hash_get_mem(bier_fmask_db.bfdb_hash, &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);
116  p = hash_get_mem(bier_fmask_db.bfdb_hash, &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);
126  hash_set_mem(bier_fmask_db.bfdb_hash, bfm->bfm_id, index);
127  }
128  else
129  {
130  index = p[0];
131  bier_fmask_lock(index);
132  }
133 
134  return (index);
135 }
136 
137 void
139 {
140  uword *p;
141 
142  p = hash_get_mem(bier_fmask_db.bfdb_hash, fmid);
143 
144  if (NULL == p) {
145  /*
146  * remove a non-existent entry - oops
147  */
148  ASSERT (!"remove non-existent fmask");
149  } else {
150  hash_unset(bier_fmask_db.bfdb_hash, fmid);
151  }
152 }
153 
154 void
156 {
158  uword *bfmi;
159 
160  hash_foreach(fmid, bfmi, bier_fmask_db.bfdb_hash,
161  ({
162  if (WALK_STOP == fn(*bfmi, ctx))
163  break;
164  }));
165 }
166 
167 clib_error_t *
169 {
170  bier_fmask_db.bfdb_hash = hash_create_mem(0,
171  sizeof(bier_fmask_id_t),
172  sizeof(index_t));
173 
174  return (NULL);
175 }
176 
Global Table of fmask objects The key into this table includes the table&#39;s key and the fmask&#39;s key...
Definition: bier_fmask_db.c:30
walk_rc_t(* bier_fmask_walk_fn_t)(index_t bfmi, void *ctx)
Walk all the BIER fmasks.
Definition: bier_fmask_db.h:99
ip46_address_t frp_addr
The next-hop address.
Definition: fib_types.h:501
#define CLIB_UNUSED(x)
Definition: clib.h:82
#define hash_unset(h, key)
Definition: hash.h:261
void bier_fmask_lock(index_t bfmi)
Definition: bier_fmask.c:269
u32 bier_fmask_db_find_or_create_and_lock(index_t bti, const fib_route_path_t *rpath)
u32 bfmi_id
ID of the next-hop object, e.g.
Definition: bier_fmask_db.h:70
A representation of a path as described by a route producer.
Definition: fib_types.h:485
index_t bier_fmask_create_and_lock(const bier_fmask_id_t *fmid, const fib_route_path_t *rpath)
Definition: bier_fmask.c:284
bier_fmask_id_t * bfm_id
The key to this fmask - used for store/lookup in the DB.
Definition: bier_fmask.h:124
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:177
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
BIER header in non-MPLS networks.
Definition: bier_fmask_db.h:53
static bier_fmask_db_t bier_fmask_db
Single fmask DB.
Definition: bier_fmask_db.c:45
#define hash_set_mem(h, key, value)
Definition: hash.h:275
void bier_fmask_db_walk(bier_fmask_walk_fn_t fn, void *ctx)
clib_error_t * bier_fmask_db_module_init(vlib_main_t *vm)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
uword * bfdb_hash
hash table for underlying storage
Definition: bier_fmask_db.c:34
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
A path via a UDP encap object.
Definition: fib_types.h:367
unsigned int u32
Definition: types.h:88
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
u32 bier_fmask_get_index(const bier_fmask_t *bfm)
Definition: bier_fmask_db.c:49
long ctx[MAX_CONNS]
Definition: main.c:144
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
fib_mpls_label_t * frp_label_stack
The outgoing MPLS label Stack.
Definition: fib_types.h:546
void bier_fmask_db_remove(const bier_fmask_id_t *fmid)
vlib_main_t * vm
Definition: in2out_ed.c:1810
An outgoing BIER mask.
Definition: bier_fmask.h:99
BIER Header in MPLS networks.
Definition: bier_fmask_db.h:33
struct bier_fmask_t_ * bfdb_pool
Pool for memory.
Definition: bier_fmask_db.c:39
BIER header in non-MPLS networks.
Definition: bier_fmask_db.h:38
A key/ID for a BIER forwarding Mas (FMask).
Definition: bier_fmask_db.h:60
#define ASSERT(truth)
fib_route_path_flags_t frp_flags
flags on the path
Definition: fib_types.h:595
bier_hdr_type_t bfmi_hdr_type
Type of BIER header this fmask supports.
Definition: bier_fmask_db.h:80
struct bier_fmask_db_t_ bier_fmask_db_t
Global Table of fmask objects The key into this table includes the table&#39;s key and the fmask&#39;s key...
index_t bfmi_bti
The BIER table this fmask is in.
Definition: bier_fmask_db.h:75
typedef key
Definition: ipsec_types.api:83
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u64 uword
Definition: types.h:112
bier_nh_type_t bfmi_nh_type
Union discriminator.
Definition: bier_fmask_db.h:85
BIER Header in MPLS networks.
Definition: bier_fmask_db.h:48
#define hash_get_mem(h, key)
Definition: hash.h:269
u32 bier_fmask_db_find(index_t bti, const fib_route_path_t *rpath)
Definition: bier_fmask_db.c:90
u32 frp_udp_encap_id
UDP encap ID.
Definition: fib_types.h:565
ip46_address_t bfmi_nh
next-hop of the peer
Definition: bier_fmask_db.h:65