src: use psync::SegmentPublisher and fix proccessing of interests w/ segments
refs: #4784, #4760
Change-Id: Ia017a6f340e1cd35991068453c9da595c453ca1f
diff --git a/src/common.hpp b/src/common.hpp
index 3337520..cd6dc18 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@@ -27,7 +27,6 @@
#ifndef NLSR_COMMON_HPP
#define NLSR_COMMON_HPP
-#include <ndn-cxx/common.hpp>
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/name.hpp>
diff --git a/src/lsa-segment-storage.cpp b/src/lsa-segment-storage.cpp
index dfe92d7..830906d 100644
--- a/src/lsa-segment-storage.cpp
+++ b/src/lsa-segment-storage.cpp
@@ -97,21 +97,8 @@
NLSR_LOG_TRACE("The received segment is already in the storage.");
}
- std::string content(reinterpret_cast<const char*>(lsaSegment.getContent().value()),
- lsaSegment.getContent().value_size());
-
ndn::time::seconds expirationTime(LSA_REFRESH_TIME_DEFAULT);
- std::vector<std::string> options;
- boost::split(options, content, boost::is_any_of("|"));
-
- try {
- expirationTime = ndn::time::duration_cast<ndn::time::seconds>
- (ndn::time::fromIsoString(options.at(3)) - ndn::time::system_clock::now());
- } catch (const std::exception& e) {
- NLSR_LOG_ERROR("Cannot extract expiration time from LSA content: " << e.what());
- }
-
// schedule the segment deletion
scheduleLsaSegmentDeletion(lsaSegmentsKey, expirationTime);
}
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index b8cda8e..1507a08 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -24,7 +24,6 @@
#include "logger.hpp"
#include "lsa-segment-storage.hpp"
#include "nlsr.hpp"
-#include "publisher/segment-publisher.hpp"
#include "utility/name-helper.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
@@ -33,31 +32,6 @@
INIT_LOGGER(Lsdb);
-class LsaContentPublisher : public SegmentPublisher<ndn::Face>
-{
-public:
- LsaContentPublisher(ndn::Face& face,
- ndn::KeyChain& keyChain,
- const ndn::security::SigningInfo& signingInfo,
- const ndn::time::milliseconds& freshnessPeriod,
- const std::string& content)
- : SegmentPublisher(face, keyChain, signingInfo, freshnessPeriod)
- , m_content(content)
- {
- }
-
- virtual size_t
- generate(ndn::EncodingBuffer& outBuffer) {
- size_t totalLength = 0;
- totalLength += outBuffer.prependByteArray(reinterpret_cast<const uint8_t*>(m_content.c_str()),
- m_content.size());
- return totalLength;
- }
-
-private:
- const std::string m_content;
-};
-
const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
const ndn::time::steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE =
@@ -76,11 +50,12 @@
, m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
, m_sequencingManager()
, m_onNewLsaConnection(m_sync.onNewLsa->connect(
- [this] (const ndn::Name& updateName, const uint64_t& sequenceNumber) {
+ [this] (const ndn::Name& updateName, uint64_t sequenceNumber) {
ndn::Name lsaInterest{updateName};
lsaInterest.appendNumber(sequenceNumber);
expressInterest(lsaInterest, 0);
}))
+ , m_segmentPublisher(m_nlsr.getNlsrFace(), m_nlsr.getKeyChain())
{
}
@@ -127,7 +102,7 @@
Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& interestName)
{
std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(ndn::Name(interestName));
- data->setContent(bufferPtr);
+ data->setContent(ndn::Block(bufferPtr));
NLSR_LOG_DEBUG("Received data for LSA(name): " << data->getName());
@@ -1050,48 +1025,53 @@
void
Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
{
+ ndn::Name interestName(interest.getName());
+ NLSR_LOG_DEBUG("Interest received for LSA: " << interestName);
+
+ if (interestName[-2].isVersion()) {
+ // Interest for particular segment
+ if (m_segmentPublisher.replyFromStore(interestName)) {
+ NLSR_LOG_TRACE("Reply from SegmentPublisher storage");
+ return;
+ }
+ // Remove version and segment
+ interestName = interestName.getSubName(0, interestName.size() - 2);
+ NLSR_LOG_TRACE("Interest w/o segment and version: " << interestName);
+ }
+
// increment RCV_LSA_INTEREST
lsaIncrementSignal(Statistics::PacketType::RCV_LSA_INTEREST);
- const ndn::Name& interestName(interest.getName());
- NLSR_LOG_DEBUG("Interest received for LSA: " << interestName);
-
std::string chkString("LSA");
- int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
+ int32_t lsaPosition = util::getNameComponentPosition(interestName, chkString);
// Forms the name of the router that the Interest packet came from.
ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
originRouter.append(interestName.getSubName(lsaPosition + 1,
- interest.getName().size() - lsaPosition - 3));
+ interestName.size() - lsaPosition - 3));
// if the interest is for this router's LSA
- if (originRouter == m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (originRouter == m_nlsr.getConfParameter().getRouterPrefix() && lsaPosition >= 0) {
+ uint64_t seqNo = interestName[-1].toNumber();
+ NLSR_LOG_DEBUG("LSA sequence number from interest: " << seqNo);
- if (lsaPosition >= 0) {
+ std::string lsaType = interestName[-2].toUri();
+ Lsa::Type interestedLsType;
+ std::istringstream(lsaType) >> interestedLsType;
- uint64_t seqNo = interestName[-1].toNumber();
- NLSR_LOG_DEBUG("LSA sequence number from interest: " << seqNo);
-
- Lsa::Type interestedLsType;
- std::istringstream(interestName[-2].toUri()) >> interestedLsType;
-
- if (interestedLsType == Lsa::Type::NAME) {
- processInterestForNameLsa(interest, originRouter.append(std::to_string(interestedLsType)),
- seqNo);
- }
- else if (interestedLsType == Lsa::Type::ADJACENCY) {
- processInterestForAdjacencyLsa(interest, originRouter.append(std::to_string(interestedLsType)),
- seqNo);
- }
- else if (interestedLsType == Lsa::Type::COORDINATE) {
- processInterestForCoordinateLsa(interest, originRouter.append(std::to_string(interestedLsType)),
- seqNo);
- }
- else {
- NLSR_LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
- }
- lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA);
+ if (interestedLsType == Lsa::Type::NAME) {
+ processInterestForNameLsa(interest, originRouter.append(lsaType), seqNo);
}
+ else if (interestedLsType == Lsa::Type::ADJACENCY) {
+ processInterestForAdjacencyLsa(interest, originRouter.append(lsaType), seqNo);
+ }
+ else if (interestedLsType == Lsa::Type::COORDINATE) {
+ processInterestForCoordinateLsa(interest, originRouter.append(lsaType), seqNo);
+ }
+ else {
+ NLSR_LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
+ }
+ lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA);
}
else { // else the interest is for other router's lsa, serve from LsaSegmentStorage
const ndn::Data* lsaSegment = m_lsaStorage.getLsaSegment(interest);
@@ -1100,27 +1080,11 @@
m_nlsr.getNlsrFace().put(*lsaSegment);
}
else {
- NLSR_LOG_TRACE(interest << " was not found in this lsa storage.");
+ NLSR_LOG_TRACE(interest << " was not found in this lsa storage.");
}
}
}
- // \brief Sends LSA data.
- // \param interest The Interest that warranted the data.
- // \param content The data that the Interest was seeking.
-void
-Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
-{
- LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
- m_nlsr.getKeyChain(),
- m_nlsr.getSigningInfo(),
- m_lsaRefreshTime,
- content);
- NLSR_LOG_DEBUG("Sending requested data ( " << content << ") for interest (" << interest
- << ") to be published and added to face.");
- publisher.publish(interest.getName());
-}
-
// \brief Finds and sends a requested name LSA.
// \param interest The interest that seeks the name LSA.
// \param lsaKey The LSA that the Interest is seeking.
@@ -1134,17 +1098,15 @@
// increment RCV_NAME_LSA_INTEREST
lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST);
NLSR_LOG_DEBUG("nameLsa interest " << interest << " received");
- NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
+ NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
if (nameLsa != nullptr) {
NLSR_LOG_TRACE("Verifying SeqNo for NameLsa is same as requested.");
if (nameLsa->getLsSeqNo() == seqNo) {
- // if requested lsa belongs to this router then sign it and serve it
std::string content = nameLsa->serialize();
- putLsaData(interest,content);
- // else the requested belongs to neighboring routers, so serve the
- // original data packet corresponding to the lsa
+ m_segmentPublisher.publish(interest.getName(), interest.getName(),
+ ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
+ m_lsaRefreshTime, m_nlsr.getSigningInfo());
- // increment SENT_NAME_LSA_DATA
lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA);
}
else {
@@ -1170,7 +1132,6 @@
NLSR_LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled");
}
- // increment RCV_ADJ_LSA_INTEREST
lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST);
NLSR_LOG_DEBUG("AdjLsa interest " << interest << " received");
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
@@ -1178,8 +1139,10 @@
NLSR_LOG_TRACE("Verifying SeqNo for AdjLsa is same as requested.");
if (adjLsa->getLsSeqNo() == seqNo) {
std::string content = adjLsa->serialize();
- putLsaData(interest,content);
- // increment SENT_ADJ_LSA_DATA
+ m_segmentPublisher.publish(interest.getName(), interest.getName(),
+ ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
+ m_lsaRefreshTime, m_nlsr.getSigningInfo());
+
lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA);
}
else {
@@ -1205,7 +1168,6 @@
NLSR_LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled");
}
- // increment RCV_COORD_LSA_INTEREST
lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST);
NLSR_LOG_DEBUG("CoordinateLsa interest " << interest << " received");
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
@@ -1213,8 +1175,10 @@
NLSR_LOG_TRACE("Verifying SeqNo for CoordinateLsa is same as requested.");
if (corLsa->getLsSeqNo() == seqNo) {
std::string content = corLsa->serialize();
- putLsaData(interest,content);
- // increment SENT_COORD_LSA_DATA
+ m_segmentPublisher.publish(interest.getName(), interest.getName(),
+ ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
+ m_lsaRefreshTime, m_nlsr.getSigningInfo());
+
lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA);
}
else {
@@ -1264,7 +1228,6 @@
NLSR_LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
}
- // increment RCV_LSA_DATA
lsaIncrementSignal(Statistics::PacketType::RCV_LSA_DATA);
}
}
@@ -1273,7 +1236,6 @@
Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
uint64_t lsSeqNo, std::string& dataContent)
{
- // increment RCV_NAME_LSA_DATA
lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_DATA);
if (isNameLsaNew(lsaKey, lsSeqNo)) {
NameLsa nameLsa;
@@ -1290,7 +1252,6 @@
Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
uint64_t lsSeqNo, std::string& dataContent)
{
- // increment RCV_ADJ_LSA_DATA
lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_DATA);
if (isAdjLsaNew(lsaKey, lsSeqNo)) {
AdjLsa adjLsa;
@@ -1307,7 +1268,6 @@
Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
uint64_t lsSeqNo, std::string& dataContent)
{
- // increment RCV_COORD_LSA_DATA
lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_DATA);
if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
CoordinateLsa corLsa;
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 2ebb952..183f3dc 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -35,6 +35,8 @@
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/util/segment-fetcher.hpp>
+#include <PSync/segment-publisher.hpp>
+
#include <utility>
#include <boost/cstdint.hpp>
@@ -219,6 +221,12 @@
expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
+ /* \brief Process interest which can be either:
+ * 1) Discovery interest from segment fetcher:
+ * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
+ * 2) Interest containing segment number:
+ * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo>
+ */
void
processInterest(const ndn::Name& name, const ndn::Interest& interest);
@@ -311,9 +319,6 @@
private:
void
- putLsaData(const ndn::Interest& interest, const std::string& content);
-
- void
processInterestForNameLsa(const ndn::Interest& interest,
const ndn::Name& lsaKey,
uint64_t seqNo);
@@ -417,6 +422,7 @@
ndn::util::signal::ScopedConnection m_onNewLsaConnection;
std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
+ psync::SegmentPublisher m_segmentPublisher;
};
} // namespace nlsr
diff --git a/src/publisher/segment-publisher.hpp b/src/publisher/segment-publisher.hpp
deleted file mode 100644
index d80c90e..0000000
--- a/src/publisher/segment-publisher.hpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP
-#define NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP
-
-#include <ndn-cxx/encoding/encoding-buffer.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-
-namespace nlsr {
-
-/*! \brief provides a publisher of Status Dataset or other segmented octet stream
- \sa https://redmine.named-data.net/projects/nfd/wiki/StatusDataset
- */
-template <class FaceBase>
-class SegmentPublisher : boost::noncopyable
-{
-public:
- SegmentPublisher(FaceBase& face,
- ndn::KeyChain& keyChain,
- const ndn::security::SigningInfo& signingInfo,
- const ndn::time::milliseconds& freshnessPeriod = getDefaultFreshness())
- : m_face(face)
- , m_keyChain(keyChain)
- , m_signingInfo(signingInfo)
- , m_freshnessPeriod(freshnessPeriod)
- {
- }
-
- virtual
- ~SegmentPublisher()
- {
- }
-
- /*! \brief Define the max segment size as half the max NDN packet size.
- */
- static size_t
- getMaxSegmentSize()
- {
- static const size_t MAX_SEGMENT_SIZE = ndn::MAX_NDN_PACKET_SIZE >> 1;
- return MAX_SEGMENT_SIZE;
- }
-
- static constexpr ndn::time::milliseconds
- getDefaultFreshness()
- {
- return ndn::time::milliseconds(1000);
- }
-
- /*! \brief Publish data under the provided prefix
- *
- * Processes whatever is provided from SegmentPublisher::generate,
- * by breaking it into segments of MAX_SEGMENT_SIZE and sending each
- * one individually. The last segment is distinguished by having the
- * final block ID set to a timestamp.
- */
- void
- publish(const ndn::Name& prefix)
- {
- ndn::EncodingBuffer buffer;
- generate(buffer);
-
- const uint8_t* rawBuffer = buffer.buf();
- const uint8_t* segmentBegin = rawBuffer;
- const uint8_t* end = rawBuffer + buffer.size();
-
- ndn::Name segmentPrefix(prefix);
- segmentPrefix.appendVersion();
-
- uint64_t segmentNo = 0;
- do {
- const uint8_t* segmentEnd = segmentBegin + getMaxSegmentSize();
- if (segmentEnd > end) {
- segmentEnd = end;
- }
-
- ndn::Name segmentName(segmentPrefix);
- segmentName.appendSegment(segmentNo);
-
- std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(segmentName);
- data->setContent(segmentBegin, segmentEnd - segmentBegin);
- data->setFreshnessPeriod(m_freshnessPeriod);
-
- segmentBegin = segmentEnd;
- if (segmentBegin >= end) {
- data->setFinalBlock(segmentName[-1]);
- }
-
- publishSegment(data);
- ++segmentNo;
- } while (segmentBegin < end);
- }
-
-protected:
- /*! \brief In a derived class, write the octets into outBuffer.
- */
- virtual size_t
- generate(ndn::EncodingBuffer& outBuffer) = 0;
-
-private:
- /*! \brief Helper function to sign and put data on a Face.
- */
- void
- publishSegment(std::shared_ptr<ndn::Data>& data)
- {
- m_keyChain.sign(*data, m_signingInfo);
- m_face.put(*data);
- }
-
-private:
- FaceBase& m_face;
- ndn::KeyChain& m_keyChain;
- const ndn::security::SigningInfo& m_signingInfo;
- const ndn::time::milliseconds m_freshnessPeriod;
-};
-
-} // namespace nlsr
-
-#endif // NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP
diff --git a/tests/publisher/test-segment-publisher.cpp b/tests/publisher/test-segment-publisher.cpp
deleted file mode 100644
index a70e57f..0000000
--- a/tests/publisher/test-segment-publisher.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "publisher/segment-publisher.hpp"
-
-#include "../boost-test.hpp"
-#include "../test-common.hpp"
-
-#include <ndn-cxx/encoding/tlv.hpp>
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
-#include <boost/mpl/int.hpp>
-#include <boost/mpl/vector.hpp>
-
-namespace nlsr {
-namespace tests {
-
-using namespace nlsr::test;
-
-template<int64_t N=10000>
-class TestSegmentPublisher : public SegmentPublisher<ndn::util::DummyClientFace>
-{
-public:
- TestSegmentPublisher(ndn::util::DummyClientFace& face,
- ndn::KeyChain& keyChain,
- ndn::security::SigningInfo& signingInfo,
- const ndn::time::milliseconds freshnessPeriod)
- : SegmentPublisher(face, keyChain, signingInfo, freshnessPeriod)
- , m_totalPayloadLength(0)
- {
-
- }
-
- virtual
- ~TestSegmentPublisher()
- {
- }
-
- uint16_t
- getLimit() const
- {
- return N;
- }
-
- size_t
- getTotalPayloadLength() const
- {
- return m_totalPayloadLength;
- }
-
-protected:
-
- virtual size_t
- generate(ndn::EncodingBuffer& outBuffer)
- {
- size_t totalLength = 0;
- for (int64_t i = 0; i < N; i++) {
- totalLength += prependNonNegativeIntegerBlock(outBuffer, ndn::tlv::Content, i);
- }
-
- m_totalPayloadLength += totalLength;
- return totalLength;
- }
-
-protected:
- size_t m_totalPayloadLength;
-};
-
-template<int64_t N>
-class SegmentPublisherFixture : public BaseFixture
-{
-public:
- SegmentPublisherFixture()
- : m_face(std::make_shared<ndn::util::DummyClientFace>(m_ioService, m_keyChain))
- , m_expectedFreshnessPeriod(ndn::time::milliseconds(111))
- , m_publisher(*m_face, m_keyChain, m_signingInfo, m_expectedFreshnessPeriod)
- , m_publishingPrefix("/localhost/nfd/SegmentPublisherFixture")
- {
- }
-
- void
- validate(const ndn::Data& data)
- {
- BOOST_CHECK_EQUAL(data.getFreshnessPeriod(), m_expectedFreshnessPeriod);
-
- ndn::Block payload = data.getContent();
-
- m_buffer.appendByteArray(payload.value(), payload.value_size());
-
- // uint64_t segmentNo = data.getName()[-1].toSegment();
- if (data.getFinalBlock().value_or(ndn::name::Component("")) != data.getName()[-1]) {
- return;
- }
-
- // wrap data in a single Content TLV for easy parsing
- m_buffer.prependVarNumber(m_buffer.size());
- m_buffer.prependVarNumber(ndn::tlv::Content);
-
- BOOST_TEST_CHECKPOINT("creating parser");
- ndn::Block parser(m_buffer.buf(), m_buffer.size());
- BOOST_TEST_CHECKPOINT("parsing aggregated response");
- parser.parse();
-
- BOOST_REQUIRE_EQUAL(parser.elements_size(), m_publisher.getLimit());
-
- uint64_t expectedNo = m_publisher.getLimit() - 1;
- for (ndn::Block::element_const_iterator i = parser.elements_begin();
- i != parser.elements_end();
- ++i)
- {
- uint64_t number = readNonNegativeInteger(*i);
- BOOST_REQUIRE_EQUAL(number, expectedNo);
- --expectedNo;
- }
- }
-
-protected:
- std::shared_ptr<ndn::util::DummyClientFace> m_face;
- const ndn::time::milliseconds m_expectedFreshnessPeriod;
- TestSegmentPublisher<N> m_publisher;
- ndn::EncodingBuffer m_buffer;
- ndn::security::SigningInfo m_signingInfo;
- const ndn::Name m_publishingPrefix;
-};
-
-using boost::mpl::int_;
-typedef boost::mpl::vector<int_<10000>, int_<100>, int_<10>, int_<0> > DatasetSizes;
-
-BOOST_AUTO_TEST_SUITE(PublisherTestSegmentPublisher)
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Generate, T, DatasetSizes, SegmentPublisherFixture<T::value>)
-{
- this->m_publisher.publish(this->m_publishingPrefix);
- this->m_face->processEvents();
-
- size_t nSegments = this->m_publisher.getTotalPayloadLength() /
- this->m_publisher.getMaxSegmentSize();
- if (this->m_publisher.getTotalPayloadLength() % this->m_publisher.getMaxSegmentSize() != 0 ||
- nSegments == 0)
- ++nSegments;
-
- BOOST_CHECK_EQUAL(this->m_face->sentData.size(), nSegments);
- for (const ndn::Data& data : this->m_face->sentData) {
- this->validate(data);
- }
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace nlsr
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 8a36113..2f9fefc 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -41,7 +41,7 @@
{
public:
LsdbFixture()
- : face(m_ioService, m_keyChain)
+ : face(m_ioService, m_keyChain, {true, true})
, nlsr(m_ioService, m_scheduler, face, m_keyChain)
, lsdb(nlsr.getLsdb())
, conf(nlsr.getConfParameter())
@@ -172,6 +172,48 @@
BOOST_CHECK_EQUAL(interests.size(), 0);
}
+BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
+{
+ // Add a lot of NameLSAs to exceed max packet size
+ ndn::Name lsaKey("/ndn/site/%C1.Router/this-router/NAME");
+
+ NameLsa* nameLsa = lsdb.findNameLsa(lsaKey);
+ uint64_t seqNo = nameLsa->getLsSeqNo();
+
+ ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
+
+ int nPrefixes = 0;
+ while (nameLsa->serialize().size() < ndn::MAX_NDN_PACKET_SIZE) {
+ nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
+ }
+ lsdb.installNameLsa(*nameLsa);
+
+ // Create another Lsdb and expressInterest
+ ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
+ face.linkTo(face2);
+ Nlsr nlsr2(m_ioService, m_scheduler, face2, m_keyChain);
+ std::string config = R"CONF(
+ trust-anchor
+ {
+ type any
+ }
+ )CONF";
+ nlsr2.getValidator().load(config, "config-file-from-string");
+
+ Lsdb& lsdb2(nlsr2.getLsdb());
+
+ advanceClocks(ndn::time::milliseconds(1), 10);
+
+ ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
+ interestName.appendNumber(seqNo);
+ // 0 == timeout count
+ lsdb2.expressInterest(interestName, 0);
+
+ advanceClocks(ndn::time::milliseconds(1), 10);
+
+ BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().front().getNpl());
+}
+
BOOST_AUTO_TEST_CASE(SegmentLsaData)
{
ndn::Name lsaKey("/ndn/site/%C1.Router/this-router/NAME");
@@ -189,29 +231,21 @@
std::string expectedDataContent = lsa->serialize();
- ndn::Name interestName("/ndn/NLSR/LSA/site/%C1.Router/this-router/NAME/");
+ ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
interestName.appendNumber(seqNo);
- ndn::Interest interest(interestName);
- lsdb.processInterest(ndn::Name(), interest);
- advanceClocks(ndn::time::milliseconds(1), 10);
- face.sentData.clear();
+ ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
+ face.linkTo(face2);
- lsdb.processInterest(ndn::Name(), interest);
+ auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName),
+ ndn::security::v2::getAcceptAllValidator());
+ fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
+ ndn::Block block(bufferPtr);
+ BOOST_CHECK_EQUAL(expectedDataContent, readString(block));
+ });
- advanceClocks(ndn::time::milliseconds(1), 10);
-
- std::string recvDataContent;
- for (const ndn::Data& data : face.sentData)
- {
- const ndn::Block& nameBlock = data.getContent();
- std::string nameBlockContent(reinterpret_cast<char const*>(nameBlock.value()),
- nameBlock.value_size());
-
- recvDataContent += nameBlockContent;
- }
-
- BOOST_CHECK_EQUAL(expectedDataContent, recvDataContent);
+ advanceClocks(ndn::time::milliseconds(1), 100);
+ fetcher->stop();
}
BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
@@ -228,12 +262,11 @@
lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
}
- ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/");
+ ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
interestName.appendNumber(seqNo);
- const ndn::ConstBufferPtr bufferPtr = std::make_shared<ndn::Buffer>(lsa.serialize().c_str(),
- lsa.serialize().size());
- lsdb.afterFetchLsa(bufferPtr, interestName);
+ ndn::Block block = ndn::encoding::makeStringBlock(ndn::tlv::Content, lsa.serialize());
+ lsdb.afterFetchLsa(block.getBuffer(), interestName);
NameLsa* foundLsa = lsdb.findNameLsa(lsa.getKey());
BOOST_REQUIRE(foundLsa != nullptr);
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index 51797e5..3e46c80 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -196,7 +196,7 @@
*/
BOOST_AUTO_TEST_CASE(LsdbSendLsaInterest)
{
- const std::string interestPrefix("/ndn/NLSR/LSA/site/%C1.Router/router/");
+ const std::string interestPrefix("/localhop/ndn/nlsr/LSA/site/%C1.Router/router/");
uint32_t seqNo = 1;
// Adjacency LSA
@@ -240,7 +240,7 @@
lsdb.installAdjLsa(*adjLsa);
- const std::string interestPrefix("/ndn/NLSR/LSA/site/%C1.Router/this-router/");
+ const std::string interestPrefix("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/");
// Receive Adjacency LSA Interest
receiveInterestAndCheckSentStats(interestPrefix,
@@ -302,37 +302,37 @@
ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
// adjacency lsa
- ndn::Name adjInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/ADJACENCY/");
+ ndn::Name adjInterest("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/ADJACENCY/");
adjInterest.appendNumber(seqNo);
AdjLsa aLsa(routerName, seqNo, MAX_TIME, 1, nlsr.getAdjacencyList());
lsdb.installAdjLsa(aLsa);
- const ndn::ConstBufferPtr aBuffer = std::make_shared<ndn::Buffer>(aLsa.serialize().c_str(),
- aLsa.serialize().size());
- lsdb.afterFetchLsa(aBuffer, adjInterest);
+ ndn::Block block = ndn::encoding::makeStringBlock(ndn::tlv::Content, aLsa.serialize());
+
+ lsdb.afterFetchLsa(block.getBuffer(), adjInterest);
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_ADJ_LSA_DATA), 1);
// coordinate lsa
- ndn::Name coordInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/COORDINATE/");
+ ndn::Name coordInterest("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/COORDINATE/");
coordInterest.appendNumber(seqNo);
std::vector<double> angles = {20.0, 30.0};
CoordinateLsa cLsa(routerName, seqNo, MAX_TIME, 2.5, angles);
lsdb.installCoordinateLsa(cLsa);
- const ndn::ConstBufferPtr cBuffer = std::make_shared<ndn::Buffer>(cLsa.serialize().c_str(),
- cLsa.serialize().size());
- lsdb.afterFetchLsa(cBuffer, coordInterest);
+ block = ndn::encoding::makeStringBlock(ndn::tlv::Content, cLsa.serialize());
+
+ lsdb.afterFetchLsa(block.getBuffer(), coordInterest);
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_COORD_LSA_DATA), 1);
// name lsa
- ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/");
+ ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
interestName.appendNumber(seqNo);
NameLsa nLsa(routerName, seqNo, MAX_TIME, nlsr.getNamePrefixList());
lsdb.installNameLsa(nLsa);
- const ndn::ConstBufferPtr nBuffer = std::make_shared<ndn::Buffer>(nLsa.serialize().c_str(),
- nLsa.serialize().size());
- lsdb.afterFetchLsa(nBuffer, interestName);
+ block = ndn::encoding::makeStringBlock(ndn::tlv::Content, nLsa.serialize());
+
+ lsdb.afterFetchLsa(block.getBuffer(), interestName);
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_NAME_LSA_DATA), 1);
// 3 lsa data types should be received