From 940228d74920fbfd6707e1324711164360cca52d Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Fri, 26 Aug 2022 15:02:12 +0000 Subject: feat(hicn-plugin): interest manifest Ref: HICN-748 Change-Id: Ie403de53a93094dca997cec379db6f5d3ce8e6be Signed-off-by: Mauro Sardara --- lib/includes/hicn/interest_manifest.h | 60 +++++++++++++++++++++++++---------- lib/includes/hicn/util/bitmap.h | 14 ++++---- 2 files changed, 50 insertions(+), 24 deletions(-) (limited to 'lib/includes/hicn') diff --git a/lib/includes/hicn/interest_manifest.h b/lib/includes/hicn/interest_manifest.h index 2b4cd57a2..b6122ce1c 100644 --- a/lib/includes/hicn/interest_manifest.h +++ b/lib/includes/hicn/interest_manifest.h @@ -44,7 +44,7 @@ typedef struct /* This can be 16 bits, but we use 32 bits for alignment */ uint32_t n_suffixes; - /* Align to 64 bits */ + /* First suffix */ uint32_t padding; hicn_uword request_bitmap[BITMAP_SIZE]; @@ -102,7 +102,27 @@ interest_manifest_serialize (interest_manifest_header_t *int_manifest_header) static inline void interest_manifest_deserialize (interest_manifest_header_t *int_manifest_header) { - _interest_manifest_deserialize (int_manifest_header, hicn_uword_bits); + u32 n_suffixes = 0; + + int_manifest_header->n_suffixes = + hicn_net_to_host_32 (int_manifest_header->n_suffixes); + int_manifest_header->padding = + hicn_net_to_host_32 (int_manifest_header->padding); + + for (unsigned i = 0; i < BITMAP_SIZE; i++) + { + int_manifest_header->request_bitmap[i] = + hicn_net_to_host_64 (int_manifest_header->request_bitmap[i]); + } + + hicn_name_suffix_t *suffix = + (hicn_name_suffix_t *) (int_manifest_header + 1); + + n_suffixes = int_manifest_header->n_suffixes; + for (unsigned i = 0; i < n_suffixes; i++) + { + *(suffix + i) = hicn_net_to_host_32 (*(suffix + i)); + } } static inline bool @@ -131,15 +151,6 @@ interest_manifest_is_valid (interest_manifest_header_t *int_manifest_header, return true; } -static inline void -interest_manifest_init (interest_manifest_header_t *int_manifest_header) -{ - int_manifest_header->n_suffixes = 0; - int_manifest_header->padding = 0; - memset (int_manifest_header->request_bitmap, 0, - sizeof (int_manifest_header->request_bitmap)); -} - static inline void interest_manifest_add_suffix (interest_manifest_header_t *int_manifest_header, hicn_name_suffix_t suffix) @@ -151,6 +162,18 @@ interest_manifest_add_suffix (interest_manifest_header_t *int_manifest_header, int_manifest_header->n_suffixes++; } +static inline void +interest_manifest_init (interest_manifest_header_t *int_manifest_header, + u32 fist_suffix) +{ + int_manifest_header->n_suffixes = 0; + int_manifest_header->padding = 0; + memset (int_manifest_header->request_bitmap, 0, + sizeof (int_manifest_header->request_bitmap)); + + interest_manifest_add_suffix (int_manifest_header, fist_suffix); +} + static inline void interest_manifest_del_suffix (interest_manifest_header_t *int_manifest_header, hicn_uword pos) @@ -182,13 +205,16 @@ interest_manifest_update_bitmap (const hicn_uword *initial_bitmap, #define _FIRST(h) (hicn_name_suffix_t *) (h + 1) -#define interest_manifest_foreach_suffix(header, suffix) \ +#define interest_manifest_foreach_suffix(header, suffix, pos) \ for (suffix = _FIRST (header) + bitmap_first_set_no_check ( \ - header->request_bitmap, BITMAP_SIZE); \ + header->request_bitmap, BITMAP_SIZE), \ + pos = 0; \ suffix - _FIRST (header) < header->n_suffixes; \ - suffix = _FIRST (header) + \ - bitmap_next_set_no_check (header->request_bitmap, \ - suffix - _FIRST (header) + 1, \ - BITMAP_SIZE)) + pos = suffix - _FIRST (header) + 1, \ + suffix = _FIRST (header) + \ + bitmap_next_set_no_check (header->request_bitmap, \ + suffix - _FIRST (header) + 1, \ + BITMAP_SIZE), \ + pos = suffix - _FIRST (header)) #endif /* HICNLIGHT_INTEREST_MANIFEST_H */ diff --git a/lib/includes/hicn/util/bitmap.h b/lib/includes/hicn/util/bitmap.h index 68541bc28..d83c838b7 100644 --- a/lib/includes/hicn/util/bitmap.h +++ b/lib/includes/hicn/util/bitmap.h @@ -40,7 +40,7 @@ typedef hicn_uword bitmap_t; #define BITMAP_INVALID_INDEX ((uint32_t) (~0)) static inline int -get_lowest_set_bit_index (hicn_uword w) +hicn_get_lowest_set_bit_index (hicn_uword w) { return hicn_uword_bits > 32 ? __builtin_ctzll (w) : __builtin_ctz (w); } @@ -132,7 +132,7 @@ _bitmap_set_no_check (bitmap_t *bitmap, off_t i) { size_t offset = i / BITMAP_WIDTH (bitmap); size_t pos = i % BITMAP_WIDTH (bitmap); - bitmap[offset] |= (bitmap_t) 1 << pos; + bitmap[offset] |= (hicn_uword) (1) << pos; return 0; } @@ -178,7 +178,7 @@ _bitmap_unset (bitmap_t *bitmap, off_t i, int check) return -1; size_t offset = i / BITMAP_WIDTH (bitmap); size_t pos = i % BITMAP_WIDTH (bitmap); - bitmap[offset] &= ~(1ul << pos); + bitmap[offset] &= ~((hicn_uword) (1) << pos); return 0; } @@ -258,13 +258,13 @@ bitmap_next_set_no_check (const bitmap_t *bitmap, hicn_uword i, size_t length) // This will zeroes all bits < i tmp = bitmap[pos] & mask; if (tmp) - return get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; + return hicn_get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; for (pos += 1; pos < length; pos++) { tmp = bitmap[pos]; if (tmp) - return get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; + return hicn_get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; } } @@ -291,13 +291,13 @@ bitmap_next_unset_no_check (const bitmap_t *bitmap, hicn_uword i, // This will zeroes all bits < i tmp = ~bitmap[pos] & mask; if (tmp) - return get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; + return hicn_get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; for (pos += 1; pos < length; pos++) { tmp = ~bitmap[pos]; if (tmp) - return get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; + return hicn_get_lowest_set_bit_index (tmp) + pos * WORD_WIDTH; } } return BITMAP_INVALID_INDEX; -- cgit 1.2.3-korg