lsdb: Segment LSAs larger than max segment size
refs: #2965
Change-Id: I5dd091b663db2cc5e2d925144e57ee55a486b3cd
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 7111620..05a71ea 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, The University of Memphis,
+ * Copyright (c) 2014-2016, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -28,6 +28,7 @@
#include <boost/test/unit_test.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/util/segment-fetcher.hpp>
namespace nlsr {
namespace test {
@@ -38,7 +39,7 @@
{
public:
LsdbFixture()
- : face(make_shared<ndn::util::DummyClientFace>())
+ : face(make_shared<ndn::util::DummyClientFace>(g_ioService))
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
, sync(*face, nlsr.getLsdb(), nlsr.getConfParameter(), nlsr.getSequencingManager())
, lsdb(nlsr.getLsdb())
@@ -122,10 +123,11 @@
interests.clear();
steady_clock::TimePoint deadline = steady_clock::now() +
- ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
+ ndn::time::seconds(LSA_REFRESH_TIME_MAX);
// Simulate an LSA interest timeout
- lsdb.processInterestTimedOut(oldInterestName, 0, deadline, interestName, oldSeqNo);
+ lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
+ oldInterestName, 0, deadline, interestName, oldSeqNo);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE(interests.size() > 0);
@@ -149,13 +151,81 @@
interests.clear();
// Simulate an LSA interest timeout where the sequence number is outdated
- lsdb.processInterestTimedOut(oldInterestName, 0, deadline, interestName, oldSeqNo);
+ lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
+ oldInterestName, 0, deadline, interestName, oldSeqNo);
face->processEvents(ndn::time::milliseconds(1));
// Interest should not be expressed for outdated sequence number
BOOST_CHECK_EQUAL(interests.size(), 0);
}
+BOOST_AUTO_TEST_CASE(SegmentLsaData)
+{
+ ndn::Name router("/ndn/cs/%C1.Router/router1");
+ uint64_t seqNo = 12;
+ NamePrefixList prefixList;
+
+ NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
+
+ ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
+
+ int nPrefixes = 0;
+ while (lsa.getData().size() < ndn::MAX_NDN_PACKET_SIZE) {
+ lsa.addName(ndn::Name(prefix).appendNumber(++nPrefixes));
+ }
+
+ std::string expectedDataContent = lsa.getData();
+ lsdb.installNameLsa(lsa);
+
+ ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
+ interestName.appendNumber(seqNo);
+
+ ndn::Interest interest(interestName);
+
+ lsdb.processInterest(ndn::Name(), interest);
+ face->processEvents(ndn::time::milliseconds(1));
+
+ std::vector<ndn::Data> data = face->sentData;
+ std::string recvDataContent;
+ for (unsigned int i = 0; i < data.size(); ++i)
+ {
+ const ndn::Block& nameBlock = data[i].getContent();
+
+ std::string nameBlockContent(reinterpret_cast<char const*>(nameBlock.value()),
+ nameBlock.value_size());
+ recvDataContent += nameBlockContent;
+ }
+
+ BOOST_CHECK_EQUAL(expectedDataContent, recvDataContent);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
+{
+ ndn::Name router("/ndn/cs/%C1.Router/router1");
+ uint64_t seqNo = 12;
+ NamePrefixList prefixList;
+
+ NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
+
+ ndn::Name prefix("/prefix/");
+
+ for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
+ lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
+ }
+
+ ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
+ interestName.appendNumber(seqNo);
+
+ const ndn::ConstBufferPtr bufferPtr = make_shared<ndn::Buffer>(lsa.getData().c_str(),
+ lsa.getData().size());
+ lsdb.afterFetchLsa(bufferPtr, interestName);
+
+ NameLsa* foundLsa = lsdb.findNameLsa(lsa.getKey());
+ BOOST_REQUIRE(foundLsa != nullptr);
+
+ BOOST_CHECK_EQUAL(foundLsa->getData(), lsa.getData());
+}
+
BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
{
ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();