summaryrefslogtreecommitdiffstats
path: root/src/vnet/bier/bier_fmask_db.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-12-05 13:24:04 -0800
committerFlorin Coras <florin.coras@gmail.com>2017-12-09 20:55:08 +0000
commit9128637ee8f7b0d903551f165a1447d427e8dd19 (patch)
tree244014dd1064643946d64066e352ee1627bf622c /src/vnet/bier/bier_fmask_db.c
parentcef87f1a5eb4d69cf11ce1cd3c5506edcfba74c4 (diff)
BIER in non-MPLS netowrks
as decsribed in section 2.2 ihttps://tools.ietf.org/html/draft-ietf-bier-mpls-encapsulation-10 with BIFT encoding from: https://tools.ietf.org/html/draft-wijnandsxu-bier-non-mpls-bift-encoding-00 changes: 1 - introduce the new BIFT lookup table. BIER tables that have an associated MPLS label are added to the MPLS-FIB. Those that don't are added to the BIER table 2 - BIER routes that have no associated output MPLS label will add a BIFT label. 3 - The BIER FMask has a path-list as a member to resolve via any possible path. Change-Id: I1fd4d9dbd074f0e855c16e9329b81460ebe1efce Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/bier/bier_fmask_db.c')
-rw-r--r--src/vnet/bier/bier_fmask_db.c123
1 files changed, 62 insertions, 61 deletions
diff --git a/src/vnet/bier/bier_fmask_db.c b/src/vnet/bier/bier_fmask_db.c
index 37cbb365897..67d3bd1cf85 100644
--- a/src/vnet/bier/bier_fmask_db.c
+++ b/src/vnet/bier/bier_fmask_db.c
@@ -40,16 +40,6 @@ typedef struct bier_fmask_db_t_ {
} bier_fmask_db_t;
/**
- * The key used in the fmask DB to compare fmask objects.
- * There is one global DB, so we need to use the table's ID and the fmasks ID
- */
-typedef struct bier_fmask_db_key_t_ {
- bier_fmask_id_t bfmdbk_fm_id;
- index_t bfmdbk_tbl_id;
-} bier_fmask_db_key_t;
-// TODO packed?
-
-/**
* Single fmask DB
*/
static bier_fmask_db_t bier_fmask_db;
@@ -61,82 +51,93 @@ bier_fmask_get_index (const bier_fmask_t *bfm)
return (bfm - bier_fmask_db.bfdb_pool);
}
-u32
-bier_fmask_db_find_or_create_and_lock (index_t bti,
- const bier_fmask_id_t *fmid,
- const fib_route_path_t *rpath)
+static void
+bier_fmask_db_mk_key (index_t bti,
+ const fib_route_path_t *rpath,
+ bier_fmask_id_t *key)
{
- bier_fmask_db_key_t key;
- u32 index;
- uword *p;
-
/*
- * there be padding in that thar key, and it's
- * used as a memcmp in the mhash.
+ * Depending on what the ID is there may be padding.
+ * This key will be memcmp'd in the mhash, so make sure it's all 0
*/
- memset(&key, 0, sizeof(key));
- key.bfmdbk_tbl_id = bti;
- key.bfmdbk_fm_id = *fmid;
-
- index = INDEX_INVALID;
- p = mhash_get (&bier_fmask_db.bfdb_hash, &key);
+ memset(key, 0, sizeof(*key));
- if (NULL == p)
+ /*
+ * Pick the attributes from the path that make the FMask unique
+ */
+ if (FIB_ROUTE_PATH_UDP_ENCAP & rpath->frp_flags)
{
- /*
- * adding a new fmask object
- */
- index = bier_fmask_create_and_lock(fmid, bti, rpath);
-
- mhash_set (&bier_fmask_db.bfdb_hash, &key, index, 0 /*old_value*/);
+ key->bfmi_id = rpath->frp_udp_encap_id;
}
else
{
- index = p[0];
- bier_fmask_lock(index);
+ key->bfmi_sw_if_index = rpath->frp_sw_if_index;
+ memcpy(&key->bfmi_nh, &rpath->frp_addr, sizeof(rpath->frp_addr));
+ }
+ if (NULL == rpath->frp_label_stack)
+ {
+ key->bfmi_hdr_type = BIER_HDR_O_OTHER;
+ }
+ else
+ {
+ key->bfmi_hdr_type = BIER_HDR_O_MPLS;
}
-
- return (index);
}
u32
bier_fmask_db_find (index_t bti,
- const bier_fmask_id_t *fmid)
+ const fib_route_path_t *rpath)
{
- bier_fmask_db_key_t key;
- u32 index;
+ bier_fmask_id_t fmid;
uword *p;
- /*
- * there be padding in that thar key, and it's
- * used as a memcmp in the mhash.
- */
- memset(&key, 0, sizeof(key));
- key.bfmdbk_tbl_id = bti;
- key.bfmdbk_fm_id = *fmid;
-
- index = INDEX_INVALID;
- p = mhash_get(&bier_fmask_db.bfdb_hash, &key);
+ bier_fmask_db_mk_key(bti, rpath, &fmid);
+ p = mhash_get(&bier_fmask_db.bfdb_hash, &fmid);
if (NULL != p)
{
+ return (p[0]);
+ }
+
+ return (INDEX_INVALID);
+}
+
+u32
+bier_fmask_db_find_or_create_and_lock (index_t bti,
+ const fib_route_path_t *rpath)
+{
+ bier_fmask_id_t fmid;
+ u32 index;
+ uword *p;
+
+ bier_fmask_db_mk_key(bti, rpath, &fmid);
+ p = mhash_get(&bier_fmask_db.bfdb_hash, &fmid);
+
+ if (NULL == p)
+ {
+ bier_fmask_t *bfm;
+ /*
+ * adding a new fmask object
+ */
+ index = bier_fmask_create_and_lock(&fmid, rpath);
+ bfm = bier_fmask_get(index);
+ mhash_set(&bier_fmask_db.bfdb_hash, bfm->bfm_id, index, 0);
+ }
+ else
+ {
index = p[0];
+ bier_fmask_lock(index);
}
return (index);
}
void
-bier_fmask_db_remove (index_t bti,
- const bier_fmask_id_t *fmid)
+bier_fmask_db_remove (const bier_fmask_id_t *fmid)
{
- bier_fmask_db_key_t key = {
- .bfmdbk_tbl_id = bti,
- .bfmdbk_fm_id = *fmid,
- };
uword *p;
- p = mhash_get (&bier_fmask_db.bfdb_hash, &key);
+ p = mhash_get(&bier_fmask_db.bfdb_hash, fmid);
if (NULL == p) {
/*
@@ -144,16 +145,16 @@ bier_fmask_db_remove (index_t bti,
*/
ASSERT (!"remove non-existant fmask");
} else {
- mhash_unset (&(bier_fmask_db.bfdb_hash), &key, 0);
+ mhash_unset(&(bier_fmask_db.bfdb_hash), (void*)fmid, 0);
}
}
clib_error_t *
bier_fmask_db_module_init (vlib_main_t *vm)
{
- mhash_init (&bier_fmask_db.bfdb_hash,
- sizeof(uword),
- sizeof(bier_fmask_db_key_t));
+ mhash_init(&bier_fmask_db.bfdb_hash,
+ sizeof(index_t),
+ sizeof(bier_fmask_id_t));
return (NULL);
}