publisher: set router-name command prefix correctly
refs: #3651
Change-Id: Ic3771de5161fc482f76df78035dcb9f5325e1a9d
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 2409956..a6039e4 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -60,7 +60,6 @@
, m_helloProtocol(*this, scheduler)
, m_lsdbDatasetHandler(m_nlsrLsdb,
m_nlsrFace,
- m_confParam.getRouterPrefix(),
m_keyChain)
, m_certificateCache(new ndn::CertificateCacheTtl(ioService))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache, m_certStore)
@@ -179,6 +178,7 @@
{
_LOG_DEBUG("Initializing Nlsr");
m_confParam.buildRouterPrefix();
+ m_lsdbDatasetHandler.setRouterNameCommandPrefix(m_confParam.getRouterPrefix());
m_nlsrLsdb.setLsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()));
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 3f9fa24..4e9cc23 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -226,6 +226,12 @@
return m_syncLogicHandler;
}
+ LsdbDatasetInterestHandler&
+ getLsdbDatasetHandler()
+ {
+ return m_lsdbDatasetHandler;
+ }
+
void
initialize();
diff --git a/src/publisher/lsdb-dataset-interest-handler.cpp b/src/publisher/lsdb-dataset-interest-handler.cpp
index 11ddc69..4ea6454 100644
--- a/src/publisher/lsdb-dataset-interest-handler.cpp
+++ b/src/publisher/lsdb-dataset-interest-handler.cpp
@@ -37,10 +37,8 @@
LsdbDatasetInterestHandler::LsdbDatasetInterestHandler(Lsdb& lsdb,
ndn::Face& face,
- const ndn::Name& routerName,
ndn::KeyChain& keyChain)
: LOCALHOST_COMMAND_PREFIX(ndn::Name(Nlsr::LOCALHOST_PREFIX).append(Lsdb::NAME_COMPONENT))
- , ROUTER_NAME_COMMAND_PREFIX(ndn::Name(routerName).append(Lsdb::NAME_COMPONENT))
, m_face(face)
, m_keyChain(keyChain)
, m_adjacencyLsaPublisher(lsdb, face, keyChain)
@@ -66,10 +64,10 @@
void
LsdbDatasetInterestHandler::startListeningOnRouterPrefix()
{
- _LOG_DEBUG("Setting interest filter for: " << ROUTER_NAME_COMMAND_PREFIX);
- m_face.setInterestFilter(ROUTER_NAME_COMMAND_PREFIX,
+ _LOG_DEBUG("Setting interest filter for: " << m_routerNameCommandPrefix);
+ m_face.setInterestFilter(m_routerNameCommandPrefix,
std::bind(&LsdbDatasetInterestHandler::onInterest, this, _2,
- std::cref(ROUTER_NAME_COMMAND_PREFIX)));
+ std::cref(m_routerNameCommandPrefix)));
}
void
diff --git a/src/publisher/lsdb-dataset-interest-handler.hpp b/src/publisher/lsdb-dataset-interest-handler.hpp
index c56c638..4285803 100644
--- a/src/publisher/lsdb-dataset-interest-handler.hpp
+++ b/src/publisher/lsdb-dataset-interest-handler.hpp
@@ -48,7 +48,6 @@
LsdbDatasetInterestHandler(Lsdb& lsdb,
ndn::Face& face,
- const ndn::Name& routerName,
ndn::KeyChain& keyChain);
void
@@ -63,10 +62,16 @@
return LOCALHOST_COMMAND_PREFIX;
}
- const ndn::Name&
+ ndn::Name&
getRouterNameCommandPrefix()
{
- return ROUTER_NAME_COMMAND_PREFIX;
+ return m_routerNameCommandPrefix;
+ }
+
+ void
+ setRouterNameCommandPrefix(const ndn::Name& routerName) {
+ m_routerNameCommandPrefix = routerName;
+ m_routerNameCommandPrefix.append(Lsdb::NAME_COMPONENT);
}
private:
@@ -84,7 +89,7 @@
private:
const ndn::Name LOCALHOST_COMMAND_PREFIX;
- const ndn::Name ROUTER_NAME_COMMAND_PREFIX;
+ ndn::Name m_routerNameCommandPrefix;
ndn::Face& m_face;
ndn::KeyChain& m_keyChain;
diff --git a/tests/publisher/test-lsdb-dataset-interest-handler.cpp b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
index a574df1..80c83ce 100644
--- a/tests/publisher/test-lsdb-dataset-interest-handler.cpp
+++ b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
@@ -81,7 +81,9 @@
lsdb.installNameLsa(nameLsa);
ndn::Name thisRouter("/This/Router");
- LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
+ LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
+ publisher.setRouterNameCommandPrefix(thisRouter);
+
publisher.startListeningOnLocalhost();
face->processEvents(ndn::time::milliseconds(10));
@@ -136,7 +138,8 @@
BOOST_AUTO_TEST_CASE(InvalidCommand)
{
ndn::Name thisRouter("/This/Router");
- LsdbDatasetInterestHandler publisher(lsdb, *face, thisRouter, keyChain);
+ LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
+ publisher.setRouterNameCommandPrefix(thisRouter);
// Localhost prefix
publisher.startListeningOnLocalhost();
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index c0dfc47..d24e512 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -357,6 +357,23 @@
BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
}
+BOOST_FIXTURE_TEST_CASE(SetRouterCommandPrefix, UnitTestTimeFixture)
+{
+ shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>(g_ioService);
+ Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
+
+ // Simulate loading configuration file
+ ConfParameter& conf = nlsr.getConfParameter();
+ conf.setNetwork("/ndn");
+ conf.setSiteName("/site");
+ conf.setRouterName("/%C1.router/this-router");
+
+ nlsr.initialize();
+
+ BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(),
+ ndn::Name("/ndn/site/%C1.router/this-router/lsdb"));
+}
+
BOOST_AUTO_TEST_SUITE_END()
} //namespace test