Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
strategy_dpo_ctx.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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 __HICN_STRATEGY_DPO_CTX_H__
17 #define __HICN_STRATEGY_DPO_CTX_H__
18 
19 #include <vnet/dpo/dpo.h>
20 #include <vnet/fib/fib_table.h>
21 
22 #include "params.h"
23 #include "faces/face.h"
24 
40 // FIB table for hicn. 0 is the default one used by ip
41 #define HICN_FIB_TABLE 10
42 
43 #define NEXT_HOP_INVALID ~0
44 
45 #define INIT_SEQ 0
46 
47 typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s
48 {
49  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
50  /* 4B*10 = 40B */
51  hicn_face_id_t next_hops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX];
52  /* 40B + 4B = 44B */
53  u32 locks;
54  /* 44B + 1B = 45B */
55  u8 entry_count;
56  /* 45B + 1B = 46B */
57  /* Number of TFIB entries (stored at the end of the next_hops array */
58  u8 tfib_entry_count;
59 
60  dpo_type_t dpo_type;
61 
62  /* 46B + 2B = 48B */
63  u8 padding; /* To align to 8B */
64 
65  /* 48 + 4B = 52; last sequence number */
66  u32 seq;
67 
68  /* 52 + 12 = 64 */
69  fib_node_t fib_node;
70 
71  CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
72 
73  fib_node_index_t fib_entry_index;
74 
75  u32 fib_sibling;
76 
77  union
78  {
79  u32 padding_proto;
80  fib_protocol_t proto;
81  };
82 
83  u8 data[CLIB_CACHE_LINE_BYTES - 12];
84 
85 } hicn_dpo_ctx_t;
86 
87 extern hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_pool;
88 
97 always_inline void
98 init_dpo_ctx (hicn_dpo_ctx_t *dpo_ctx, const hicn_face_id_t *next_hop,
99  int nh_len, dpo_type_t dpo_type, dpo_proto_t proto)
100 {
101  hicn_face_id_t invalid = NEXT_HOP_INVALID;
102 
103  dpo_ctx->entry_count = 0;
104  dpo_ctx->locks = 0;
105 
106  dpo_ctx->tfib_entry_count = 0;
107 
108  dpo_ctx->seq = INIT_SEQ;
109  dpo_ctx->dpo_type = dpo_type;
110 
111  dpo_ctx->proto = proto;
112 
113  for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
114  {
115  dpo_ctx->next_hops[i] = next_hop[i];
116  dpo_ctx->entry_count++;
117  }
118 
119  for (int i = nh_len; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
120  {
121  dpo_ctx->next_hops[i] = invalid;
122  }
123 }
124 
130 
134 hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_alloc ();
135 
139 hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_get (index_t index);
140 
144 index_t hicn_strategy_dpo_ctx_get_index (hicn_dpo_ctx_t *cd);
145 
151 void hicn_strategy_dpo_ctx_lock (dpo_id_t *dpo);
152 
158 void hicn_strategy_dpo_ctx_unlock (dpo_id_t *dpo);
159 
172 int hicn_strategy_dpo_ctx_add_nh (hicn_face_id_t nh, hicn_dpo_ctx_t *dpo_ctx,
173  u8 *pos);
174 
183 int hicn_strategy_dpo_ctx_del_nh (hicn_face_id_t face_id,
184  hicn_dpo_ctx_t *dpo_ctx);
185 
186 STATIC_ASSERT (sizeof (hicn_dpo_ctx_t) <= 2 * CLIB_CACHE_LINE_BYTES,
187  "sizeof hicn_dpo_ctx_t is greater than 128B");
188 
189 #endif /* // __HICN_STRATEGY_DPO_CTX_H__ */
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables: eval: (c-set-style "gnu") End:
195  */
hicn_strategy_dpo_ctx_unlock
void hicn_strategy_dpo_ctx_unlock(dpo_id_t *dpo)
Unlock the dpo of a strategy ctx.
hicn_strategy_dpo_ctx_lock
void hicn_strategy_dpo_ctx_lock(dpo_id_t *dpo)
Lock the dpo of a strategy ctx.
face.h
hicn_strategy_dpo_ctx_get_index
index_t hicn_strategy_dpo_ctx_get_index(hicn_dpo_ctx_t *cd)
Retrieve the index of the hICN dpo ctx.
hicn_strategy_dpo_ctx_alloc
hicn_dpo_ctx_t * hicn_strategy_dpo_ctx_alloc()
Allocate a new hICN dpo ctx from the pool.
hicn_strategy_dpo_ctx_add_nh
int hicn_strategy_dpo_ctx_add_nh(hicn_face_id_t nh, hicn_dpo_ctx_t *dpo_ctx, u8 *pos)
Add or update a next hop in the dpo ctx.
hicn_strategy_init_dpo_ctx_pool
void hicn_strategy_init_dpo_ctx_pool(void)
Initialize the pool containing the hICN dpo ctx.
hicn_strategy_dpo_ctx_get
hicn_dpo_ctx_t * hicn_strategy_dpo_ctx_get(index_t index)
Retrieve an existing hICN dpo ctx from the pool.
init_dpo_ctx
always_inline void init_dpo_ctx(hicn_dpo_ctx_t *dpo_ctx, const hicn_face_id_t *next_hop, int nh_len, dpo_type_t dpo_type, dpo_proto_t proto)
Initialize the hICN dpo ctx.
Definition: strategy_dpo_ctx.h:98
params.h
hicn_strategy_dpo_ctx_del_nh
int hicn_strategy_dpo_ctx_del_nh(hicn_face_id_t face_id, hicn_dpo_ctx_t *dpo_ctx)
Delete a next hop in the dpo ctx.