diff options
author | Mauro Sardara <msardara@cisco.com> | 2022-08-26 15:02:12 +0000 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-09-01 13:20:29 +0000 |
commit | 940228d74920fbfd6707e1324711164360cca52d (patch) | |
tree | 1810371558a8f3efd5e9eb2e5ac042c98e354d50 /libtransport | |
parent | 8d7d5327ca86871cdf1d2ce404ca88bb2a58630f (diff) |
feat(hicn-plugin): interest manifest
Ref: HICN-748
Change-Id: Ie403de53a93094dca997cec379db6f5d3ce8e6be
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport')
-rw-r--r-- | libtransport/includes/hicn/transport/core/interest.h | 6 | ||||
-rw-r--r-- | libtransport/src/core/interest.cc | 33 | ||||
-rw-r--r-- | libtransport/src/core/packet.cc | 2 | ||||
-rw-r--r-- | libtransport/src/core/pending_interest.h | 26 | ||||
-rw-r--r-- | libtransport/src/core/portal.h | 24 | ||||
-rw-r--r-- | libtransport/src/protocols/transport_protocol.cc | 1 | ||||
-rw-r--r-- | libtransport/src/test/test_interest.cc | 12 |
7 files changed, 63 insertions, 41 deletions
diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h index 716ac6b0a..428829697 100644 --- a/libtransport/includes/hicn/transport/core/interest.h +++ b/libtransport/includes/hicn/transport/core/interest.h @@ -92,10 +92,12 @@ class Interest void appendSuffix(std::uint32_t suffix); - void decodeSuffixes(); - void encodeSuffixes(); + void serializeSuffixes(); + + void deserializeSuffixes(); + uint32_t *firstSuffix(); uint32_t numberOfSuffixes(); diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc index 777374b09..10e1a6dfa 100644 --- a/libtransport/src/core/interest.cc +++ b/libtransport/src/core/interest.cc @@ -169,31 +169,46 @@ void Interest::encodeSuffixes() { // We assume interest does not hold signature for the moment. auto int_manifest_header = (interest_manifest_header_t *)(writableData() + headerSize()); - int_manifest_header->n_suffixes = (uint32_t)suffix_set_.size(); + + interest_manifest_init(int_manifest_header, name_.getSuffix()); memset(int_manifest_header->request_bitmap, 0xFFFFFFFF, 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++) { - *suffix = *it; + interest_manifest_add_suffix(int_manifest_header, *it); } 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; +void Interest::serializeSuffixes() { + if (!hasManifest()) { + return; + } - auto header = (interest_manifest_header_t *)(writableData() + headerSize()); - interest_manifest_deserialize(header); + // 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() { diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 73134ce3d..e670ecb54 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -368,7 +368,7 @@ uint8_t Packet::getTTL() const { return hops; } -bool Packet::hasAH() const { return _is_ah(hicn_packet_get_format(&pkbuf_)); } +bool Packet::hasAH() const { return _is_ah(getFormat()); } utils::MemBuf::Ptr Packet::getSignature() const { if (!hasAH()) { diff --git a/libtransport/src/core/pending_interest.h b/libtransport/src/core/pending_interest.h index fb10405d3..b901e7d97 100644 --- a/libtransport/src/core/pending_interest.h +++ b/libtransport/src/core/pending_interest.h @@ -57,38 +57,32 @@ class PendingInterest { ~PendingInterest() = default; template <typename Handler> - TRANSPORT_ALWAYS_INLINE void startCountdown(uint32_t lifetime, Handler &&cb) { + void startCountdown(uint32_t lifetime, Handler &&cb) { timer_.expires_from_now(std::chrono::milliseconds(lifetime)); timer_.async_wait(std::forward<Handler>(cb)); } - TRANSPORT_ALWAYS_INLINE void cancelTimer() { timer_.cancel(); } + void cancelTimer() { timer_.cancel(); } - TRANSPORT_ALWAYS_INLINE Interest::Ptr &&getInterest() { - return std::move(interest_); - } + Interest::Ptr &&getInterest() { return std::move(interest_); } - TRANSPORT_ALWAYS_INLINE void setInterest(const Interest::Ptr &interest) { - interest_ = interest; - } + const Interest::Ptr &getInterestReference() const { return interest_; } + + void setInterest(const Interest::Ptr &interest) { interest_ = interest; } - TRANSPORT_ALWAYS_INLINE const OnContentObjectCallback &getOnDataCallback() - const { + const OnContentObjectCallback &getOnDataCallback() const { return on_content_object_callback_; } - TRANSPORT_ALWAYS_INLINE void setOnContentObjectCallback( - OnContentObjectCallback &&on_content_object) { + void setOnContentObjectCallback(OnContentObjectCallback &&on_content_object) { PendingInterest::on_content_object_callback_ = std::move(on_content_object); } - TRANSPORT_ALWAYS_INLINE const OnInterestTimeoutCallback & - getOnTimeoutCallback() const { + const OnInterestTimeoutCallback &getOnTimeoutCallback() const { return on_interest_timeout_callback_; } - TRANSPORT_ALWAYS_INLINE void setOnTimeoutCallback( - OnInterestTimeoutCallback &&on_interest_timeout) { + void setOnTimeoutCallback(OnInterestTimeoutCallback &&on_interest_timeout) { PendingInterest::on_interest_timeout_callback_ = std::move(on_interest_timeout); } diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h index f2380347b..d4fbb3442 100644 --- a/libtransport/src/core/portal.h +++ b/libtransport/src/core/portal.h @@ -319,8 +319,8 @@ class Portal : public ::utils::NonCopyable, uint32_t initial_hash = interest->getName().getHash32(false); auto hash = initial_hash + interest->getName().getSuffix(); uint32_t seq = interest->getName().getSuffix(); - const uint32_t *suffix = interest->firstSuffix(); - auto n_suffixes = interest->numberOfSuffixes(); + const uint32_t *suffix = interest->firstSuffix() + 1; + auto n_suffixes = interest->numberOfSuffixes() - 1; uint32_t counter = 0; // Set timers do { @@ -412,9 +412,10 @@ class Portal : public ::utils::NonCopyable, UNSET_CALLBACK) { DCHECK(std::this_thread::get_id() == worker_.getThreadId()); - io_module_->send(*interest); addInterestToPIT(interest, lifetime, std::move(on_content_object_callback), std::move(on_interest_timeout_callback)); + interest->serializeSuffixes(); + io_module_->send(*interest); } /** @@ -541,6 +542,22 @@ class Portal : public ::utils::NonCopyable, pending_interest_hash_table_.clear(); } + void dumpPIT() { + std::vector<Name> sorted_elements; + for (const auto &[key, value] : pending_interest_hash_table_) { + sorted_elements.push_back(value.getInterestReference()->getName()); + } + + std::sort(sorted_elements.begin(), sorted_elements.end(), + [](const Name &a, const Name &b) { + return a.getSuffix() < b.getSuffix(); + }); + + for (auto &elt : sorted_elements) { + LOG(INFO) << elt; + } + } + /** * Callback called by the underlying connector upon reception of a packet * from the local forwarder. @@ -620,6 +637,7 @@ class Portal : public ::utils::NonCopyable, DLOG_IF(INFO, VLOG_IS_ON(3)) << "processInterest " << interest.getName(); // Save interest in PIT + interest.deserializeSuffixes(); addInterestToPIT(interest.shared_from_this(), interest.getLifetime()); if (TRANSPORT_EXPECT_TRUE(transport_callback_ != nullptr)) { transport_callback_->onInterest(interest); diff --git a/libtransport/src/protocols/transport_protocol.cc b/libtransport/src/protocols/transport_protocol.cc index b1803709b..5b262e4e7 100644 --- a/libtransport/src/protocols/transport_protocol.cc +++ b/libtransport/src/protocols/transport_protocol.cc @@ -159,7 +159,6 @@ void TransportProtocol::sendInterest( for (uint32_t i = 0; i < len; i++) { interest->appendSuffix(additional_suffixes->at(i)); } - interest->encodeSuffixes(); uint32_t lifetime = default_values::interest_lifetime; socket_->getSocketOption(GeneralTransportOptions::INTEREST_LIFETIME, diff --git a/libtransport/src/test/test_interest.cc b/libtransport/src/test/test_interest.cc index ba63b6c93..22dc01455 100644 --- a/libtransport/src/test/test_interest.cc +++ b/libtransport/src/test/test_interest.cc @@ -255,16 +255,13 @@ 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(); for (uint32_t i = 0; i < n_suffixes; i++) { - EXPECT_EQ(*(suffix + i), (i + 1)); + EXPECT_EQ(*(suffix + i), i); } } @@ -282,16 +279,13 @@ 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); - EXPECT_EQ(*suffix, 1U); + EXPECT_EQ(*suffix, 0U); // Iterate over them. They should be in order and without repetitions - std::vector<uint32_t> expected = {1, 2, 5, 6}; + std::vector<uint32_t> expected = {interest.getName().getSuffix(), 1, 2, 5, 6}; EXPECT_EQ(interest.numberOfSuffixes(), expected.size()); for (uint32_t seq : expected) { |