summaryrefslogtreecommitdiffstats
path: root/lib/src
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-07-08 16:10:13 +0000
committerMauro Sardara <msardara@cisco.com>2022-08-10 11:57:10 +0200
commit8f0a8bf572b9b8123121338a31462440bad65857 (patch)
treeecac67f0ad005b2eb0a1bd25c8f242497ffddea1 /lib/src
parent8d27045832427a0ea345f48bfb2c42f46a357af1 (diff)
feat: add interest manifest serialization/deserialization
Also: add helpers for interest manifest Ref: HICN-738 Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: Ia531605148e00ccbe446da0f4f2d8caae2b098be Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/protocol/ah.c4
-rw-r--r--lib/src/test/test_interest_manifest.cc117
2 files changed, 119 insertions, 2 deletions
diff --git a/lib/src/protocol/ah.c b/lib/src/protocol/ah.c
index 9cc747ac8..645b0482b 100644
--- a/lib/src/protocol/ah.c
+++ b/lib/src/protocol/ah.c
@@ -192,7 +192,7 @@ ah_set_signature_timestamp (const hicn_packet_buffer_t *pkbuf, size_t pos,
{
_ah_header_t *ah = pkbuf_get_ah (pkbuf);
- uint64_t netwok_order_timestamp = htonll (signature_timestamp);
+ uint64_t netwok_order_timestamp = hicn_net_to_host_64 (signature_timestamp);
memcpy (ah->timestamp_as_u8, &netwok_order_timestamp, sizeof (uint64_t));
return HICN_LIB_ERROR_NONE;
}
@@ -204,7 +204,7 @@ ah_get_signature_timestamp (const hicn_packet_buffer_t *pkbuf, size_t pos,
_ah_header_t *ah = pkbuf_get_ah (pkbuf);
memcpy (signature_timestamp, ah->timestamp_as_u8, sizeof (uint64_t));
- *signature_timestamp = ntohll (*signature_timestamp);
+ *signature_timestamp = hicn_host_to_net_64 (*signature_timestamp);
return HICN_LIB_ERROR_NONE;
}
diff --git a/lib/src/test/test_interest_manifest.cc b/lib/src/test/test_interest_manifest.cc
index c912b0bc6..5df06d6bd 100644
--- a/lib/src/test/test_interest_manifest.cc
+++ b/lib/src/test/test_interest_manifest.cc
@@ -14,6 +14,7 @@
*/
#include <gtest/gtest.h>
+#include <gmock/gmock.h>
extern "C"
{
@@ -25,8 +26,17 @@ static constexpr hicn_uword WORD_SIZE = WORD_WIDTH;
class InterestManifestTest : public ::testing::Test
{
protected:
+ static constexpr u32 n_suffixes = 0x00000014;
+ 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,
+ 4, 33, 2, 44, 99, 87, 67,
+ 78, 98, 76, 1, 7, 123 };
InterestManifestTest () {}
virtual ~InterestManifestTest () {}
+
+ uint8_t buffer[512];
+ hicn_uword bitmap_saved[BITMAP_SIZE];
};
TEST_F (InterestManifestTest, OneWordBitmapUpdate)
@@ -83,4 +93,111 @@ TEST_F (InterestManifestTest, TwoWordBitmapUpdate)
EXPECT_EQ (curr_bitmap[1], expected_bitmap[i][1]);
i++;
}
+}
+
+TEST_F (InterestManifestTest, SerializeDeserialize)
+{
+#if hicn_uword_bits == 64
+#define F(x) hicn_host_to_net_64 (x)
+#elif hicn_uword_bits == 32
+#define F(x) hicn_host_to_net_32 (x)
+#else
+#error "Unrecognized architecture"
+#endif
+
+ auto header = reinterpret_cast<interest_manifest_header_t *> (buffer);
+ interest_manifest_init (header);
+
+ for (const auto &v : values)
+ {
+ interest_manifest_add_suffix (header, v);
+ }
+
+ EXPECT_EQ (header->n_suffixes, n_suffixes);
+
+ // Save bitmap
+ memcpy (bitmap_saved, header->request_bitmap, sizeof (bitmap_saved));
+
+ // Serialize manifest
+ interest_manifest_serialize (header);
+
+ // If architecture is little endian, bytes should be now swapped
+ EXPECT_THAT (header->n_suffixes, ::testing::Eq (hicn_host_to_net_32 (
+ n_suffixes) /* 0x14000000 */));
+
+ for (unsigned i = 0; i < BITMAP_SIZE; i++)
+ {
+ EXPECT_THAT (header->request_bitmap[i],
+ ::testing::Eq (F (bitmap_saved[i])));
+ }
+
+ 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])));
+ }
+
+ // Deserialize manifest
+ interest_manifest_deserialize (header);
+
+ // Bytes should now be as before
+ 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++;
+ }
+}
+
+TEST_F (InterestManifestTest, ForEach)
+{
+ 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));
+
+ hicn_name_suffix_t *suffix = (hicn_name_suffix_t *) (header + 1);
+ for (uint32_t i = 0; i < n_suffixes; i++)
+ {
+ *(suffix + i) = values[i];
+ }
+
+ // 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++;
+ }
+
+ std::set<uint32_t> set_values (values.begin (), values.end ());
+
+ // Unset few bitmap positions
+ interest_manifest_del_suffix (header, 5);
+ set_values.erase (values[5]);
+
+ interest_manifest_del_suffix (header, 6);
+ set_values.erase (values[6]);
+
+ interest_manifest_del_suffix (header, 12);
+ set_values.erase (values[12]);
+
+ interest_manifest_del_suffix (header, 17);
+ 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);
+ }
+
+ EXPECT_TRUE (set_values.empty ());
} \ No newline at end of file