publisher: Serve LSDB dataset on localhost prefix
refs: #2737
Change-Id: I4cc9bd1d07dea583937676dd491ab5c68fd821ea
diff --git a/tests/publisher/test-lsa-publisher.cpp b/tests/publisher/test-lsa-publisher.cpp
index aa7922c..4ea6544 100644
--- a/tests/publisher/test-lsa-publisher.cpp
+++ b/tests/publisher/test-lsa-publisher.cpp
@@ -34,9 +34,11 @@
BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic)
{
+ ndn::Name thisRouter("/RouterA");
+
// Adjacency LSA for RouterA
AdjLsa routerALsa;
- routerALsa.setOrigRouter("/RouterA");
+ routerALsa.setOrigRouter(thisRouter);
addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10);
lsdb.installAdjLsa(routerALsa);
@@ -49,9 +51,12 @@
addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30);
lsdb.installAdjLsa(routerBLsa);
- AdjacencyLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain);
+ AdjacencyLsaPublisher publisher(lsdb, *face, keyChain);
- publisher.publish();
+ ndn::Name publishingPrefix = ndn::Name(thisRouter);
+ publishingPrefix.append(Lsdb::NAME_COMPONENT).append(AdjacencyLsaPublisher::DATASET_COMPONENT);
+
+ publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
@@ -69,7 +74,9 @@
BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
{
- CoordinateLsa routerALsa = createCoordinateLsa("/RouterA", 10.0, 20.0);
+ ndn::Name thisRouter("/RouterA");
+
+ CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, 20.0);
lsdb.installCoordinateLsa(routerALsa);
CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, 543.21);
@@ -78,9 +85,12 @@
CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, 0.02);
lsdb.installCoordinateLsa(routerCLsa);
- CoordinateLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain);
+ CoordinateLsaPublisher publisher(lsdb, *face, keyChain);
- publisher.publish();
+ ndn::Name publishingPrefix = ndn::Name(thisRouter);
+ publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT);
+
+ publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
@@ -102,10 +112,12 @@
BOOST_AUTO_TEST_CASE(NameLsaBasic)
{
+ ndn::Name thisRouter("/RouterA");
+
// Name LSA for RouterA
NameLsa routerALsa;
- routerALsa.setOrigRouter("/RouterA");
- routerALsa.addName("/RouterA/name1");
+ routerALsa.setOrigRouter(thisRouter.toUri());
+ routerALsa.addName(ndn::Name(thisRouter).append("name1"));
lsdb.installNameLsa(routerALsa);
// Name LSA for RouterB
@@ -116,9 +128,12 @@
routerBLsa.addName("/RouterB/name3");
lsdb.installNameLsa(routerBLsa);
- NameLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain);
+ NameLsaPublisher publisher(lsdb, *face, keyChain);
- publisher.publish();
+ ndn::Name publishingPrefix = ndn::Name(thisRouter);
+ publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT);
+
+ publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
diff --git a/tests/publisher/test-lsdb-dataset-interest-handler.cpp b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
index 22b2819..15c6eea 100644
--- a/tests/publisher/test-lsdb-dataset-interest-handler.cpp
+++ b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
@@ -82,30 +82,53 @@
ndn::Name thisRouter("/This/Router");
LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
+ publisher.startListeningOnLocalhost();
face->processEvents(ndn::time::milliseconds(10));
- ndn::Name commandPrefix(thisRouter);
- commandPrefix.append("lsdb");
+ // Localhost prefix
+ ndn::Name localhostCommandPrefix = publisher.getLocalhostCommandPrefix();
// Request adjacency LSAs
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("adjacencies")));
-
+ face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("adjacencies")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
// Request coordinate LSAs
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("coordinates")));
+ face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("coordinates")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
// Request Name LSAs
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("names")));
+ face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("names")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
// Request LSDB Status
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("list")));
+ face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("list")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
+
+ // Router name prefix
+ ndn::Name routerCommandPrefix = publisher.getLocalhostCommandPrefix();
+
+ // Request adjacency LSAs
+ face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("adjacencies")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
+
+ // Request coordinate LSAs
+ face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("coordinates")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
+
+ // Request Name LSAs
+ face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("names")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
+
+ // Request LSDB Status
+ face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("list")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
}
@@ -115,22 +138,42 @@
ndn::Name thisRouter("/This/Router");
LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
+ // Localhost prefix
+ publisher.startListeningOnLocalhost();
face->processEvents(ndn::time::milliseconds(10));
- ndn::Name commandPrefix(thisRouter);
- commandPrefix.append("lsdb");
+ ndn::Name localhostCommandPrefix = publisher.getLocalhostCommandPrefix();
// Unsupported command
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("unsupported")));
+ face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("unsupported")));
face->processEvents(ndn::time::milliseconds(1));
- checkErrorResponse(face, 501);
+ checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND);
// Long malformed command
- face->receive(ndn::Interest(ndn::Name(commandPrefix).append("extra").append("malformed")));
+ face->receive(
+ ndn::Interest(ndn::Name(localhostCommandPrefix).append("extra").append("malformed")));
face->processEvents(ndn::time::milliseconds(1));
- checkErrorResponse(face, 400);
+ checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_MALFORMED_COMMAND);
+
+ // Router name prefix
+ publisher.startListeningOnRouterPrefix();
+ face->processEvents(ndn::time::milliseconds(10));
+
+ ndn::Name remoteCommandPrefix = publisher.getRouterNameCommandPrefix();
+
+ // Unsupported command
+ face->receive(ndn::Interest(ndn::Name(remoteCommandPrefix).append("unsupported")));
+ face->processEvents(ndn::time::milliseconds(1));
+
+ checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND);
+
+ // Long malformed command
+ face->receive(ndn::Interest(ndn::Name(remoteCommandPrefix).append("extra").append("malformed")));
+ face->processEvents(ndn::time::milliseconds(1));
+
+ checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_MALFORMED_COMMAND);
// Short malformed command
face->receive(ndn::Interest(ndn::Name(thisRouter).append("malformed")));
diff --git a/tests/publisher/test-lsdb-status-publisher.cpp b/tests/publisher/test-lsdb-status-publisher.cpp
index 50d48da..58c4eff 100644
--- a/tests/publisher/test-lsdb-status-publisher.cpp
+++ b/tests/publisher/test-lsdb-status-publisher.cpp
@@ -75,16 +75,19 @@
lsdb.installNameLsa(routerBNameLsa);
ndn::Name thisRouter("/This/Router");
- AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, thisRouter, keyChain);
- CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, thisRouter, keyChain);
- NameLsaPublisher nameLsaPublisher(lsdb, *face, thisRouter, keyChain);
+ AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, keyChain);
+ CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, keyChain);
+ NameLsaPublisher nameLsaPublisher(lsdb, *face, keyChain);
- LsdbStatusPublisher publisher(lsdb, *face, thisRouter, keyChain,
+ LsdbStatusPublisher publisher(lsdb, *face, keyChain,
adjacencyLsaPublisher,
coordinateLsaPublisher,
nameLsaPublisher);
- publisher.publish();
+ ndn::Name publishingPrefix = ndn::Name(thisRouter);
+ publishingPrefix.append(Lsdb::NAME_COMPONENT).append(LsdbStatusPublisher::DATASET_COMPONENT);
+
+ publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
diff --git a/tests/publisher/test-segment-publisher.cpp b/tests/publisher/test-segment-publisher.cpp
index 8cc8dde..0855466 100644
--- a/tests/publisher/test-segment-publisher.cpp
+++ b/tests/publisher/test-segment-publisher.cpp
@@ -41,10 +41,9 @@
{
public:
TestSegmentPublisher(ndn::util::DummyClientFace& face,
- const ndn::Name& prefix,
ndn::KeyChain& keyChain,
const ndn::time::milliseconds freshnessPeriod)
- : SegmentPublisher(face, prefix, keyChain, freshnessPeriod)
+ : SegmentPublisher(face, keyChain, freshnessPeriod)
, m_totalPayloadLength(0)
{
@@ -92,8 +91,8 @@
SegmentPublisherFixture()
: m_face(ndn::util::makeDummyClientFace())
, m_expectedFreshnessPeriod(ndn::time::milliseconds(111))
- , m_publisher(*m_face, "/localhost/nfd/SegmentPublisherFixture",
- m_keyChain, m_expectedFreshnessPeriod)
+ , m_publisher(*m_face, m_keyChain, m_expectedFreshnessPeriod)
+ , m_publishingPrefix("/localhost/nfd/SegmentPublisherFixture")
{
}
@@ -140,6 +139,7 @@
TestSegmentPublisher<N> m_publisher;
ndn::EncodingBuffer m_buffer;
ndn::KeyChain m_keyChain;
+ const ndn::Name m_publishingPrefix;
};
using boost::mpl::int_;
@@ -149,7 +149,7 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Generate, T, DatasetSizes, SegmentPublisherFixture<T::value>)
{
- this->m_publisher.publish();
+ this->m_publisher.publish(this->m_publishingPrefix);
this->m_face->processEvents();
size_t nSegments = this->m_publisher.getTotalPayloadLength() /