Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
face_db.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_FACE_DB_H__
17 #define __HICN_FACE_DB_H__
18 
19 #include <vnet/dpo/dpo.h>
20 #include "faces/face.h"
21 
30 /* Must be power of two */
31 #define HICN_FACE_DB_INLINE_FACES 8
32 
33 #define HICN_PIT_BITMAP_SIZE_BYTE HICN_PARAM_FACES_MAX / 8
34 #define HICN_PIT_N_HOP_BITMAP_SIZE HICN_PARAM_FACES_MAX
35 
36 #define HICN_PIT_N_HOP_BUCKET \
37  (HICN_PARAM_PIT_ENTRY_PHOPS_MAX - HICN_FACE_DB_INLINE_FACES)
38 
39 typedef struct hicn_face_bucket_s
40 {
41  /* Array of indexes of virtual faces */
42  hicn_face_id_t faces[HICN_PIT_N_HOP_BUCKET];
43 
44  /* Used to check if interests are retransmission */
45  u8 bitmap[HICN_PIT_BITMAP_SIZE_BYTE];
46 
48 
49 extern hicn_face_bucket_t *hicn_face_bucket_pool;
50 
51 typedef struct __attribute__ ((packed)) hicn_face_db_s
52 {
53  /* 19B + 1B = 20B */
54  /* Equal to one or zero */
55  u8 is_overflow;
56 
57  /* Number of faces in the last bucket */
58  /* Or next availabe entry for storing a dpo_id_t */
59  /* 20B + 4B = 24B */
60  u32 n_faces;
61 
62  /* 24B + 32B (8*4) = 56B */
63  /* Array of indexes of virtual faces */
64  hicn_face_id_t inline_faces[HICN_FACE_DB_INLINE_FACES];
65 
66  /* 56B + 4B = 60B */
67  u32 next_bucket;
68 
69  /* 60B + 4B = 64B */
70  u32 align;
71  // align back to 64
72 
73 } hicn_face_db_t;
74 
75 always_inline hicn_face_id_t
76 hicn_face_db_get_dpo_face (u32 index, hicn_face_db_t *face_db)
77 {
78  ASSERT (index < face_db->n_faces);
79 
80  return index < HICN_FACE_DB_INLINE_FACES ?
81  (face_db->inline_faces[index]) :
82  (pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket)
83  ->faces[(index - HICN_FACE_DB_INLINE_FACES) &
84  (HICN_PIT_N_HOP_BUCKET - 1)]);
85 }
86 
87 always_inline void
88 hicn_face_db_init (int max_element)
89 {
90  pool_init_fixed (hicn_face_bucket_pool, max_element);
91 }
92 
93 always_inline hicn_face_bucket_t *
94 hicn_face_db_get_bucket (u32 bucket_index)
95 {
96  return pool_elt_at_index (hicn_face_bucket_pool, bucket_index);
97 }
98 
99 always_inline void
100 hicn_face_db_add_face (hicn_face_id_t face_id, hicn_face_db_t *face_db)
101 {
102  // ASSERT (dpo->dpoi_index != ~0);
103 
104  hicn_face_bucket_t *faces_bkt =
105  pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket);
106 
107  hicn_face_id_t *element =
108  face_db->n_faces < HICN_FACE_DB_INLINE_FACES ?
109  &(face_db->inline_faces[face_db->n_faces]) :
110  &(faces_bkt->faces[(face_db->n_faces - HICN_FACE_DB_INLINE_FACES) &
111  (HICN_PIT_N_HOP_BUCKET - 1)]);
112 
113  *element = face_id;
114 
115  u32 bitmap_index = face_id % HICN_PIT_N_HOP_BITMAP_SIZE;
116  u32 position_array = bitmap_index / 8;
117  u8 bit_index = (u8) (bitmap_index - position_array * 8);
118 
119  faces_bkt->bitmap[position_array] |= (0x01 << bit_index);
120  face_db->n_faces++;
121 }
122 
123 always_inline u8
124 hicn_face_search (hicn_face_id_t index, hicn_face_db_t *face_db)
125 {
126  hicn_face_bucket_t *faces_bkt =
127  pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket);
128  u32 bitmap_index = index % HICN_PIT_N_HOP_BITMAP_SIZE;
129 
130  u32 position_array = bitmap_index / 8;
131  u8 bit_index = bitmap_index - position_array * 8;
132 
133  return (faces_bkt->bitmap[position_array] >> bit_index) & 0x01;
134 }
135 
136 always_inline void
137 hicn_faces_flush (hicn_face_db_t *face_db)
138 {
139  hicn_face_bucket_t *faces_bkt =
140  pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket);
141  clib_memset_u8 (&(faces_bkt->bitmap), 0, HICN_PIT_BITMAP_SIZE_BYTE);
142  face_db->n_faces = 0;
143  pool_put_index (hicn_face_bucket_pool, face_db->next_bucket);
144 }
145 
146 #endif /* // __HICN_FACE_DB_H__ */
147 
148 /*
149  * fd.io coding-style-patch-verification: ON
150  *
151  * Local Variables: eval: (c-set-style "gnu") End:
152  */
face.h
hicn_face_bucket_s
Definition: face_db.h:39