16 #ifndef __HICN_FACE_DB_H__
17 #define __HICN_FACE_DB_H__
19 #include <vnet/dpo/dpo.h>
31 #define HICN_FACE_DB_INLINE_FACES 8
33 #define HICN_PIT_BITMAP_SIZE_BYTE HICN_PARAM_FACES_MAX / 8
34 #define HICN_PIT_N_HOP_BITMAP_SIZE HICN_PARAM_FACES_MAX
36 #define HICN_PIT_N_HOP_BUCKET \
37 (HICN_PARAM_PIT_ENTRY_PHOPS_MAX - HICN_FACE_DB_INLINE_FACES)
42 hicn_face_id_t faces[HICN_PIT_N_HOP_BUCKET];
45 u8 bitmap[HICN_PIT_BITMAP_SIZE_BYTE];
51 typedef struct __attribute__ ((packed)) hicn_face_db_s
64 hicn_face_id_t inline_faces[HICN_FACE_DB_INLINE_FACES];
75 always_inline hicn_face_id_t
76 hicn_face_db_get_dpo_face (u32 index, hicn_face_db_t *face_db)
78 ASSERT (index < face_db->n_faces);
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)]);
88 hicn_face_db_init (
int max_element)
90 pool_init_fixed (hicn_face_bucket_pool, max_element);
94 hicn_face_db_get_bucket (u32 bucket_index)
96 return pool_elt_at_index (hicn_face_bucket_pool, bucket_index);
100 hicn_face_db_add_face (hicn_face_id_t face_id, hicn_face_db_t *face_db)
105 pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket);
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)]);
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);
119 faces_bkt->bitmap[position_array] |= (0x01 << bit_index);
124 hicn_face_search (hicn_face_id_t index, hicn_face_db_t *face_db)
127 pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket);
128 u32 bitmap_index = index % HICN_PIT_N_HOP_BITMAP_SIZE;
130 u32 position_array = bitmap_index / 8;
131 u8 bit_index = bitmap_index - position_array * 8;
133 return (faces_bkt->bitmap[position_array] >> bit_index) & 0x01;
137 hicn_faces_flush (hicn_face_db_t *face_db)
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);