aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/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 /libtransport/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 'libtransport/src')
-rw-r--r--libtransport/src/core/interest.cc31
-rw-r--r--libtransport/src/test/test_interest.cc7
2 files changed, 20 insertions, 18 deletions
diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc
index 0851bfef6..777374b09 100644
--- a/libtransport/src/core/interest.cc
+++ b/libtransport/src/core/interest.cc
@@ -171,7 +171,7 @@ void Interest::encodeSuffixes() {
(interest_manifest_header_t *)(writableData() + headerSize());
int_manifest_header->n_suffixes = (uint32_t)suffix_set_.size();
memset(int_manifest_header->request_bitmap, 0xFFFFFFFF,
- BITMAP_SIZE * sizeof(u32));
+ BITMAP_SIZE * sizeof(hicn_uword));
uint32_t *suffix = (uint32_t *)(int_manifest_header + 1);
for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++, suffix++) {
@@ -181,10 +181,21 @@ void Interest::encodeSuffixes() {
std::size_t additional_length =
sizeof(interest_manifest_header_t) +
int_manifest_header->n_suffixes * sizeof(uint32_t);
+
+ // Serialize interest manifest
+ interest_manifest_serialize(int_manifest_header);
+
append(additional_length);
updateLength();
}
+void Interest::decodeSuffixes() {
+ if (!hasManifest()) return;
+
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
+ interest_manifest_deserialize(header);
+}
+
uint32_t *Interest::firstSuffix() {
if (!hasManifest()) {
return nullptr;
@@ -223,24 +234,8 @@ void Interest::setRequestBitmap(const uint32_t *request_bitmap) {
bool Interest::isValid() {
if (!hasManifest()) return true;
-
auto header = (interest_manifest_header_t *)(writableData() + headerSize());
-
- if (header->n_suffixes == 0 ||
- header->n_suffixes > MAX_SUFFIXES_IN_MANIFEST) {
- std::cerr << "Manifest with invalid number of suffixes "
- << header->n_suffixes;
- return false;
- }
-
- uint32_t empty_bitmap[BITMAP_SIZE];
- memset(empty_bitmap, 0, sizeof(empty_bitmap));
- if (memcmp(empty_bitmap, header->request_bitmap, sizeof(empty_bitmap)) == 0) {
- std::cerr << "Manifest with empty bitmap";
- return false;
- }
-
- return true;
+ return interest_manifest_is_valid(header, payloadSize());
}
} // end namespace core
diff --git a/libtransport/src/test/test_interest.cc b/libtransport/src/test/test_interest.cc
index 8d00a9c6d..ba63b6c93 100644
--- a/libtransport/src/test/test_interest.cc
+++ b/libtransport/src/test/test_interest.cc
@@ -255,7 +255,11 @@ TEST_F(InterestTest, AppendSuffixesEncodeAndIterate) {
// Encode them in wire format
interest.encodeSuffixes();
+ // Decode suffixes from wire format
+ interest.decodeSuffixes();
+
// Iterate over them. They should be in order and without repetitions
+
auto suffix = interest.firstSuffix();
auto n_suffixes = interest.numberOfSuffixes();
@@ -278,6 +282,9 @@ TEST_F(InterestTest, AppendSuffixesWithGaps) {
interest.encodeSuffixes();
EXPECT_TRUE(interest.hasManifest());
+ // Decode suffixes from wire format
+ interest.decodeSuffixes();
+
// Check first suffix correctness
auto suffix = interest.firstSuffix();
EXPECT_NE(suffix, nullptr);