summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-08-26 15:02:12 +0000
committerMauro Sardara <msardara@cisco.com>2022-09-01 13:20:29 +0000
commit940228d74920fbfd6707e1324711164360cca52d (patch)
tree1810371558a8f3efd5e9eb2e5ac042c98e354d50 /lib
parent8d7d5327ca86871cdf1d2ce404ca88bb2a58630f (diff)
feat(hicn-plugin): interest manifest
Ref: HICN-748 Change-Id: Ie403de53a93094dca997cec379db6f5d3ce8e6be Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/.clang-format10
-rw-r--r--lib/includes/hicn/interest_manifest.h60
-rw-r--r--lib/includes/hicn/util/bitmap.h14
-rw-r--r--lib/src/packet.c5
-rw-r--r--lib/src/test/test_interest_manifest.cc89
5 files changed, 110 insertions, 68 deletions
diff --git a/lib/.clang-format b/lib/.clang-format
index 351a70e20..b4846b63a 100644
--- a/lib/.clang-format
+++ b/lib/.clang-format
@@ -10,11 +10,5 @@ BreakBeforeBinaryOperators: None
ContinuationIndentWidth: 2
ForEachMacros:
- - 'clib_bitmap_foreach'
- - 'pool_foreach'
- - 'pool_foreach_index'
- - 'vec_foreach'
- - 'vec_foreach_backwards'
- - 'vec_foreach_index'
- - 'vec_foreach_index_backwards'
- - 'vlib_foreach_rx_tx'
+ - 'interest_manifest_foreach_suffix'
+
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
@@ -132,15 +152,6 @@ interest_manifest_is_valid (interest_manifest_header_t *int_manifest_header,
}
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)
{
@@ -152,6 +163,18 @@ interest_manifest_add_suffix (interest_manifest_header_t *int_manifest_header,
}
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;
diff --git a/lib/src/packet.c b/lib/src/packet.c
index ad86afb66..f020e099c 100644
--- a/lib/src/packet.c
+++ b/lib/src/packet.c
@@ -324,11 +324,12 @@ int
hicn_packet_get_payload (const hicn_packet_buffer_t *pkbuf, u8 **payload,
size_t *payload_size, bool hard_copy)
{
- size_t payload_len = hicn_packet_get_len (pkbuf) - pkbuf->payload;
+ *payload_size = hicn_packet_get_len (pkbuf) - pkbuf->payload;
if (hard_copy)
{
- memcpy (payload, pkbuf_get_header (pkbuf) + pkbuf->payload, payload_len);
+ memcpy (payload, pkbuf_get_header (pkbuf) + pkbuf->payload,
+ *payload_size);
}
else
{
diff --git a/lib/src/test/test_interest_manifest.cc b/lib/src/test/test_interest_manifest.cc
index 5df06d6bd..da7531fd3 100644
--- a/lib/src/test/test_interest_manifest.cc
+++ b/lib/src/test/test_interest_manifest.cc
@@ -26,7 +26,7 @@ static constexpr hicn_uword WORD_SIZE = WORD_WIDTH;
class InterestManifestTest : public ::testing::Test
{
protected:
- static constexpr u32 n_suffixes = 0x00000014;
+ static constexpr u32 n_suffixes = 0x00000014 + 1;
static constexpr u32 padding = 0x21232425;
static constexpr hicn_uword bitmap_word = ~0ULL;
static inline std::vector<uint32_t> values = { 10, 22, 23, 43, 54, 65, 66,
@@ -106,7 +106,7 @@ TEST_F (InterestManifestTest, SerializeDeserialize)
#endif
auto header = reinterpret_cast<interest_manifest_header_t *> (buffer);
- interest_manifest_init (header);
+ interest_manifest_init (header, 0);
for (const auto &v : values)
{
@@ -134,8 +134,15 @@ TEST_F (InterestManifestTest, SerializeDeserialize)
hicn_name_suffix_t *suffix = (hicn_name_suffix_t *) (header + 1);
for (unsigned i = 0; i < n_suffixes; i++)
{
- EXPECT_THAT (*(suffix + i),
- ::testing::Eq (hicn_host_to_net_32 (values[i])));
+ if (i == 0)
+ {
+ EXPECT_THAT (*(suffix + i), ::testing::Eq (hicn_name_suffix_t (0)));
+ }
+ else
+ {
+ EXPECT_THAT (*(suffix + i),
+ ::testing::Eq (hicn_host_to_net_32 (values[i - 1])));
+ }
}
// Deserialize manifest
@@ -145,59 +152,73 @@ TEST_F (InterestManifestTest, SerializeDeserialize)
EXPECT_THAT (header->n_suffixes, ::testing::Eq (n_suffixes));
int i = 0;
- interest_manifest_foreach_suffix (header, suffix)
- {
- EXPECT_THAT (*suffix, ::testing::Eq (values[i]));
- i++;
- }
+ int pos;
+ interest_manifest_foreach_suffix (header, suffix, pos)
+ {
+ if (pos == 0)
+ {
+ EXPECT_THAT (*suffix, ::testing::Eq (hicn_name_suffix_t (0)));
+ }
+ else
+ {
+ EXPECT_THAT (*suffix, ::testing::Eq (values[i]));
+ i++;
+ }
+ }
}
TEST_F (InterestManifestTest, ForEach)
{
+ int pos;
+ hicn_name_suffix_t *suffix = nullptr;
auto header = reinterpret_cast<interest_manifest_header_t *> (buffer);
- header->n_suffixes = n_suffixes;
- header->padding = padding;
- memset (header->request_bitmap, 0xff, BITMAP_SIZE * sizeof (hicn_uword));
+ interest_manifest_init (header, 0);
- hicn_name_suffix_t *suffix = (hicn_name_suffix_t *) (header + 1);
- for (uint32_t i = 0; i < n_suffixes; i++)
+ for (const auto &v : values)
{
- *(suffix + i) = values[i];
+ interest_manifest_add_suffix (header, v);
}
- // Iterate over interest manifest. As bitmap is all 1, we should be able to
- // iterate over all suffixes.
- unsigned i = 0;
- interest_manifest_foreach_suffix (header, suffix)
- {
- EXPECT_EQ (*suffix, values[i]);
- i++;
- }
+ // Iterate over interest manifest. bBbitmap should be all 1, we should be
+ // able to iterate over all suffixes.
+ interest_manifest_foreach_suffix (header, suffix, pos)
+ {
+ if (pos == 0)
+ {
+ EXPECT_EQ (*suffix, hicn_name_suffix_t (0));
+ }
+ else
+ {
+ EXPECT_EQ (*suffix, values[pos - 1]);
+ }
+ }
std::set<uint32_t> set_values (values.begin (), values.end ());
// Unset few bitmap positions
- interest_manifest_del_suffix (header, 5);
+ interest_manifest_del_suffix (header, 5 + 1);
set_values.erase (values[5]);
- interest_manifest_del_suffix (header, 6);
+ interest_manifest_del_suffix (header, 6 + 1);
set_values.erase (values[6]);
- interest_manifest_del_suffix (header, 12);
+ interest_manifest_del_suffix (header, 12 + 1);
set_values.erase (values[12]);
- interest_manifest_del_suffix (header, 17);
+ interest_manifest_del_suffix (header, 17 + 1);
set_values.erase (values[17]);
// Iterate over interest manifest and remove elements in manifest from set.
// The set should be empty at the end.
- interest_manifest_foreach_suffix (header, suffix)
- {
- std::cout << suffix - _FIRST (header) << std::endl;
- EXPECT_TRUE (set_values.find (*suffix) != set_values.end ())
- << "The value was " << *suffix;
- set_values.erase (*suffix);
- }
+ interest_manifest_foreach_suffix (header, suffix, pos)
+ {
+ if (pos > 0)
+ {
+ EXPECT_TRUE (set_values.find (*suffix) != set_values.end ())
+ << "The value was " << *suffix;
+ set_values.erase (*suffix);
+ }
+ }
EXPECT_TRUE (set_values.empty ());
} \ No newline at end of file