aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/core/interest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/core/interest.cc')
-rw-r--r--libtransport/src/core/interest.cc143
1 files changed, 100 insertions, 43 deletions
diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc
index 9d868ced0..c3eb7c379 100644
--- a/libtransport/src/core/interest.cc
+++ b/libtransport/src/core/interest.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -21,7 +21,9 @@ extern "C" {
#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
#endif
+#include <hicn/base.h>
#include <hicn/hicn.h>
+#include <hicn/interest_manifest.h>
}
#include <cstring>
@@ -33,29 +35,30 @@ namespace core {
Interest::Interest(const Name &interest_name, Packet::Format format,
std::size_t additional_header_size)
- : Packet(format, additional_header_size) {
- if (hicn_interest_set_name(format_, packet_start_,
- interest_name.getConstStructReference()) < 0) {
+ : Packet(HICN_PACKET_TYPE_INTEREST, format, additional_header_size) {
+ if (hicn_interest_set_name(&pkbuf_,
+ &interest_name.getConstStructReference()) < 0) {
throw errors::MalformedPacketException();
}
- if (hicn_interest_get_name(format_, packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
+Interest::Interest(hicn_packet_format_t format,
+ std::size_t additional_header_size)
+ : Interest(
#ifdef __ANDROID__
-Interest::Interest(hicn_format_t format, std::size_t additional_header_size)
- : Interest(Name("0::0|0"), format, additional_header_size) {}
+ Name("0::0|0"),
#else
-Interest::Interest(hicn_format_t format, std::size_t additional_header_size)
- : Interest(base_name, format, additional_header_size) {}
+ base_name,
#endif
+ format, additional_header_size) {
+}
Interest::Interest(MemBuf &&buffer) : Packet(std::move(buffer)) {
- if (hicn_interest_get_name(format_, packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -73,15 +76,13 @@ Interest &Interest::operator=(const Interest &other) {
return (Interest &)Packet::operator=(other);
}
-Interest::~Interest() {}
+Interest::~Interest() = default;
const Name &Interest::getName() const {
- if (!name_) {
- if (hicn_interest_get_name(format_, packet_start_,
- (hicn_name_t *)name_.getConstStructReference()) <
- 0) {
- throw errors::MalformedPacketException();
- }
+ if (!name_ &&
+ hicn_interest_get_name(
+ &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) {
+ throw errors::MalformedPacketException();
}
return name_;
@@ -90,29 +91,27 @@ const Name &Interest::getName() const {
Name &Interest::getWritableName() { return const_cast<Name &>(getName()); }
void Interest::setName(const Name &name) {
- if (hicn_interest_set_name(format_, packet_start_,
- name.getConstStructReference()) < 0) {
+ if (hicn_interest_set_name(&pkbuf_, &name.getConstStructReference()) < 0) {
throw errors::RuntimeException("Error setting interest name.");
}
- if (hicn_interest_get_name(format_, packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
-void Interest::setLocator(const ip_address_t &ip_address) {
- if (hicn_interest_set_locator(format_, packet_start_, &ip_address) < 0) {
+void Interest::setLocator(const hicn_ip_address_t &ip_address) {
+ if (hicn_interest_set_locator(&pkbuf_, &ip_address) < 0) {
throw errors::RuntimeException("Error setting interest locator.");
}
return;
}
-ip_address_t Interest::getLocator() const {
- ip_address_t ip;
+hicn_ip_address_t Interest::getLocator() const {
+ hicn_ip_address_t ip;
- if (hicn_interest_get_locator(format_, packet_start_, &ip) < 0) {
+ if (hicn_interest_get_locator(&pkbuf_, &ip) < 0) {
throw errors::RuntimeException("Error getting interest locator.");
}
@@ -120,7 +119,7 @@ ip_address_t Interest::getLocator() const {
}
void Interest::setLifetime(uint32_t lifetime) {
- if (hicn_interest_set_lifetime(packet_start_, lifetime) < 0) {
+ if (hicn_interest_set_lifetime(&pkbuf_, lifetime) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -128,7 +127,7 @@ void Interest::setLifetime(uint32_t lifetime) {
uint32_t Interest::getLifetime() const {
uint32_t lifetime = 0;
- if (hicn_interest_get_lifetime(packet_start_, &lifetime) < 0) {
+ if (hicn_interest_get_lifetime(&pkbuf_, &lifetime) < 0) {
throw errors::MalformedPacketException();
}
@@ -136,14 +135,20 @@ uint32_t Interest::getLifetime() const {
}
void Interest::resetForHash() {
- if (hicn_interest_reset_for_hash(
- format_, reinterpret_cast<hicn_header_t *>(packet_start_)) < 0) {
+ if (hicn_interest_reset_for_hash(&pkbuf_) < 0) {
throw errors::RuntimeException(
"Error resetting interest fields for hash computation.");
}
+
+ // Reset request bitmap in manifest
+ if (hasManifest()) {
+ auto int_manifest_header =
+ (interest_manifest_header_t *)(writableData() + headerSize());
+ memset(int_manifest_header->request_bitmap, 0, BITMAP_SIZE * sizeof(u32));
+ }
}
-bool Interest::hasManifest() {
+bool Interest::hasManifest() const {
return (getPayloadType() == PayloadType::MANIFEST);
}
@@ -162,19 +167,43 @@ void Interest::encodeSuffixes() {
// We assume interest does not hold signature for the moment.
auto int_manifest_header =
- (InterestManifestHeader *)(writableData() + headerSize());
- int_manifest_header->n_suffixes = suffix_set_.size();
+ (interest_manifest_header_t *)(writableData() + headerSize());
+
+ interest_manifest_init(int_manifest_header, name_.getSuffix());
+ for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++) {
+ interest_manifest_add_suffix(int_manifest_header, *it);
+ }
+
std::size_t additional_length =
- sizeof(InterestManifestHeader) +
+ sizeof(interest_manifest_header_t) +
int_manifest_header->n_suffixes * sizeof(uint32_t);
- uint32_t *suffix = (uint32_t *)(int_manifest_header + 1);
- for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++, suffix++) {
- *suffix = *it;
+ append(additional_length);
+ updateLength();
+}
+
+void Interest::serializeSuffixes() {
+ if (!hasManifest()) {
+ return;
}
- append(additional_length);
- updateLength(additional_length);
+ // We assume interest does not hold signature for the moment.
+ auto int_manifest_header =
+ (interest_manifest_header_t *)(writableData() + headerSize());
+ // Serialize interest manifest
+ interest_manifest_serialize(int_manifest_header);
+}
+
+void Interest::deserializeSuffixes() {
+ if (!hasManifest()) {
+ return;
+ }
+
+ // We assume interest does not hold signature for the moment.
+ auto int_manifest_header =
+ (interest_manifest_header_t *)(writableData() + headerSize());
+ // Serialize interest manifest
+ interest_manifest_deserialize(int_manifest_header);
}
uint32_t *Interest::firstSuffix() {
@@ -182,7 +211,7 @@ uint32_t *Interest::firstSuffix() {
return nullptr;
}
- auto ret = (InterestManifestHeader *)(writableData() + headerSize());
+ auto ret = (interest_manifest_header_t *)(writableData() + headerSize());
ret += 1;
return (uint32_t *)ret;
@@ -193,11 +222,39 @@ uint32_t Interest::numberOfSuffixes() {
return 0;
}
- auto header = (InterestManifestHeader *)(writableData() + headerSize());
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
return header->n_suffixes;
}
+hicn_uword *Interest::getRequestBitmap() {
+ if (!hasManifest()) return nullptr;
+
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
+ return header->request_bitmap;
+}
+
+interest_manifest_header_t *Interest::getIntManifestHeader() {
+ if (!hasManifest()) return nullptr;
+
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
+ return header;
+};
+
+void Interest::setRequestBitmap(const uint32_t *request_bitmap) {
+ if (!hasManifest()) return;
+
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
+ memcpy(header->request_bitmap, request_bitmap,
+ BITMAP_SIZE * sizeof(uint32_t));
+}
+
+bool Interest::isValid() {
+ if (!hasManifest()) return true;
+ auto header = (interest_manifest_header_t *)(writableData() + headerSize());
+ return interest_manifest_is_valid(header, payloadSize());
+}
+
} // end namespace core
} // end namespace transport