FD.io VPP  v21.06
Vector Packet Processing
lcp_adj.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 #ifndef __LCP_ADJ_DELEGATE_H__
17 #define __LCP_ADJ_DELEGATE_H__
18 
19 #include <vppinfra/bihash_32_8.h>
20 
21 typedef struct lcp_adj_key_t_
22 {
24  u8 rewrite[28];
26 
27 STATIC_ASSERT (sizeof (lcp_adj_key_t) == 32, "LCP ADJ Key size changed");
28 
29 typedef struct lcp_adj_kv_t_
30 {
31  union
32  {
33  BVT (clib_bihash_kv) kv;
34  struct
35  {
37  u64 v;
38  };
39  };
40 } lcp_adj_kv_t;
41 
42 STATIC_ASSERT (sizeof (lcp_adj_kv_t) == sizeof (BVT (clib_bihash_kv)),
43  "LCP ADJ Key size changed");
44 
45 /**
46  * The table of adjacencies indexed by the rewrite string
47  */
48 extern BVT (clib_bihash) lcp_adj_tbl;
49 
52 {
53  /*
54  * Construct the key from the provided rewrite, then pad with zeros
55  * to ensure the key does not have garbage bytes
56  */
57  ASSERT (len <= sizeof (key->rewrite));
58  clib_memcpy_fast (key->rewrite, rewrite, len);
59  clib_memset (key->rewrite + len, 0, sizeof (key->rewrite) - len);
60  key->sw_if_index = sw_if_index;
61 }
62 
65 {
66  lcp_adj_kv_t kv;
67 
68  lcp_adj_mk_key (rewrite, len, sw_if_index, &kv.k);
69 
70  if (!BV (clib_bihash_search_inline) (&lcp_adj_tbl, &kv.kv))
71  return (kv.v);
72 
73  return (ADJ_INDEX_INVALID);
74 }
75 
76 /*
77  * fd.io coding-style-patch-verification: ON
78  *
79  * Local Variables:
80  * eval: (c-set-style "gnu")
81  * End:
82  */
83 
84 #endif
struct lcp_adj_kv_t_ lcp_adj_kv_t
u8 rewrite[28]
Definition: lcp_adj.h:24
STATIC_ASSERT(sizeof(lcp_adj_key_t)==32, "LCP ADJ Key size changed")
unsigned long u64
Definition: types.h:89
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
#define static_always_inline
Definition: clib.h:112
static_always_inline void lcp_adj_mk_key(const u8 *rewrite, u8 len, u32 sw_if_index, lcp_adj_key_t *key)
Definition: lcp_adj.h:51
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
int clib_bihash_search_inline(clib_bihash *h, clib_bihash_kv *in_out_kv)
Search a bi-hash table.
u8 len
Definition: ip_types.api:103
static_always_inline adj_index_t lcp_adj_lkup(const u8 *rewrite, u8 len, u32 sw_if_index)
Definition: lcp_adj.h:64
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
lcp_adj_key_t k
Definition: lcp_adj.h:36
#define ASSERT(truth)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
typedef key
Definition: ipsec_types.api:88
struct lcp_adj_key_t_ lcp_adj_key_t
BVT(clib_bihash) lcp_adj_tbl
The table of adjacencies indexed by the rewrite string.
Definition: l2_fib.c:1069
u32 sw_if_index
Definition: lcp_adj.h:23