src: use psync::SegmentPublisher and fix proccessing of interests w/ segments
refs: #4784, #4760
Change-Id: Ia017a6f340e1cd35991068453c9da595c453ca1f
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);