FD.io VPP  v18.04-17-g3a0d853
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 polination 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,
57  bier_fmask_id_t *key)
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  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  }
72  else
73  {
74  key->bfmi_sw_if_index = rpath->frp_sw_if_index;
75  memcpy(&key->bfmi_nh, &rpath->frp_addr, sizeof(rpath->frp_addr));
76  }
77  if (NULL == rpath->frp_label_stack)
78  {
80  }
81  else
82  {
84  }
85 }
86 
87 u32
89  const fib_route_path_t *rpath)
90 {
91  bier_fmask_id_t fmid;
92  uword *p;
93 
94  bier_fmask_db_mk_key(bti, rpath, &fmid);
95  p = mhash_get(&bier_fmask_db.bfdb_hash, &fmid);
96 
97  if (NULL != p)
98  {
99  return (p[0]);
100  }
101 
102  return (INDEX_INVALID);
103 }
104 
105 u32
107  const fib_route_path_t *rpath)
108 {
109  bier_fmask_id_t fmid;
110  u32 index;
111  uword *p;
112 
113  bier_fmask_db_mk_key(bti, rpath, &fmid);
114  p = mhash_get(&bier_fmask_db.bfdb_hash, &fmid);
115 
116  if (NULL == p)
117  {
118  bier_fmask_t *bfm;
119  /*
120  * adding a new fmask object
121  */
122  index = bier_fmask_create_and_lock(&fmid, rpath);
123  bfm = bier_fmask_get(index);
124  mhash_set(&bier_fmask_db.bfdb_hash, bfm->bfm_id, index, 0);
125  }
126  else
127  {
128  index = p[0];
129  bier_fmask_lock(index);
130  }
131 
132  return (index);
133 }
134 
135 void
137 {
138  uword *p;
139 
140  p = mhash_get(&bier_fmask_db.bfdb_hash, fmid);
141 
142  if (NULL == p) {
143  /*
144  * remove a non-exitant entry - oops
145  */
146  ASSERT (!"remove non-existant fmask");
147  } else {
148  mhash_unset(&(bier_fmask_db.bfdb_hash), (void*)fmid, 0);
149  }
150 }
151 
152 clib_error_t *
154 {
155  mhash_init(&bier_fmask_db.bfdb_hash,
156  sizeof(index_t),
157  sizeof(bier_fmask_id_t));
158 
159  return (NULL);
160 }
161 
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
Definition: mhash.h:46
mhash_t bfdb_hash
hash table for underlying storage
Definition: bier_fmask_db.c:34
ip46_address_t frp_addr
The next-hop address.
Definition: fib_types.h:471
void bier_fmask_lock(index_t bfmi)
Definition: bier_fmask.c:252
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:65
A representation of a path as described by a route producer.
Definition: fib_types.h:455
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:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:353
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:173
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
static bier_fmask_db_t bier_fmask_db
Single fmask DB.
Definition: bier_fmask_db.c:45
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:490
clib_error_t * bier_fmask_db_module_init(vlib_main_t *vm)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
A path via a UDP encap object.
Definition: fib_types.h:346
index_t bier_fmask_create_and_lock(const bier_fmask_id_t *fmid, const fib_route_path_t *rpaths)
Definition: bier_fmask.c:267
u32 bier_fmask_get_index(const bier_fmask_t *bfm)
Definition: bier_fmask_db.c:49
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:510
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
void bier_fmask_db_remove(const bier_fmask_id_t *fmid)
An outgoing BIER mask.
Definition: bier_fmask.h:99
BIER Header in MPLS networks.
Definition: bier_fmask_db.h:33
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
vlib_main_t * vm
Definition: buffer.c:294
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:45
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
fib_route_path_flags_t frp_flags
flags on the path
Definition: fib_types.h:547
bier_hdr_type_t bfmi_hdr_type
Type of BIER header this fmask supports.
Definition: bier_fmask_db.h:49
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...
u64 uword
Definition: types.h:112
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u32 bfmi_sw_if_index
Software interface index.
Definition: bier_fmask_db.h:71
u32 bier_fmask_db_find(index_t bti, const fib_route_path_t *rpath)
Definition: bier_fmask_db.c:88
u32 frp_udp_encap_id
UDP encap ID.
Definition: fib_types.h:527
ip46_address_t bfmi_nh
next-hop of the peer
Definition: bier_fmask_db.h:60