**breaking** Change NLSR to nlsr for various prefixes

src: register router prefix to fix remote requests

refs: #4543

Change-Id: I698484318bf8e641f955ea40e6c51c6865cad8bf
diff --git a/nlsr.conf b/nlsr.conf
index 3f01975..beed576 100644
--- a/nlsr.conf
+++ b/nlsr.conf
@@ -141,7 +141,7 @@
       filter
       {
         type name
-        regex ^[^<NLSR><INFO>]*<NLSR><INFO><><>$
+        regex ^[^<nlsr><INFO>]*<nlsr><INFO><><>$
       }
       checker
       {
@@ -152,10 +152,10 @@
           type name
           hyper-relation
           {
-            k-regex ^([^<KEY><NLSR>]*)<NLSR><KEY><>$
+            k-regex ^([^<KEY><nlsr>]*)<nlsr><KEY><>$
             k-expand \\1
             h-relation equal
-            p-regex ^([^<NLSR><INFO>]*)<NLSR><INFO><><>$
+            p-regex ^([^<nlsr><INFO>]*)<nlsr><INFO><><>$
             p-expand \\1
           }
         }
@@ -169,7 +169,7 @@
       filter
       {
         type name
-        regex ^[^<NLSR><LSA>]*<NLSR><LSA>
+        regex ^[^<nlsr><LSA>]*<nlsr><LSA>
       }
       checker
       {
@@ -180,11 +180,11 @@
           type name
           hyper-relation
           {
-            k-regex ^([^<KEY><NLSR>]*)<NLSR><KEY><>$
+            k-regex ^([^<KEY><nlsr>]*)<nlsr><KEY><>$
             k-expand \\1
             h-relation equal
             ; the last four components in the prefix should be <lsaType><seqNo><version><segmentNo>
-            p-regex ^<localhop>([^<NLSR><LSA>]*)<NLSR><LSA>(<>*)<><><><>$
+            p-regex ^<localhop>([^<nlsr><LSA>]*)<nlsr><LSA>(<>*)<><><><>$
             p-expand \\1\\2
           }
         }
@@ -198,7 +198,7 @@
       filter
       {
         type name
-        regex ^[^<KEY><%C1.Router>]*<%C1.Router>[^<KEY><NLSR>]*<KEY><><><>$
+        regex ^[^<KEY><%C1.Router>]*<%C1.Router>[^<KEY><nlsr>]*<KEY><><><>$
       }
       checker
       {
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 5226ed4..7703505 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -30,7 +30,7 @@
 
 INIT_LOGGER(SyncLogicHandler);
 
-const std::string NLSR_COMPONENT = "NLSR";
+const std::string NLSR_COMPONENT = "nlsr";
 const std::string LSA_COMPONENT = "LSA";
 
 template<class T>
diff --git a/src/conf-parameter.cpp b/src/conf-parameter.cpp
index 5ffca5b..bb61456 100644
--- a/src/conf-parameter.cpp
+++ b/src/conf-parameter.cpp
@@ -29,7 +29,7 @@
 INIT_LOGGER(ConfParameter);
 
 // To be changed when breaking changes are made to sync
-const uint64_t ConfParameter::SYNC_VERSION = 4;
+const uint64_t ConfParameter::SYNC_VERSION = 5;
 
 void
 ConfParameter::writeLog()
@@ -69,13 +69,13 @@
 
   m_chronosyncPrefix.append("localhop");
   m_chronosyncPrefix.append(m_network);
-  m_chronosyncPrefix.append("NLSR");
+  m_chronosyncPrefix.append("nlsr");
   m_chronosyncPrefix.append("sync");
   m_chronosyncPrefix.appendVersion(SYNC_VERSION);
 
   m_lsaPrefix.append("localhop");
   m_lsaPrefix.append(m_network);
-  m_lsaPrefix.append("NLSR");
+  m_lsaPrefix.append("nlsr");
   m_lsaPrefix.append("LSA");
 }
 
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 0c2d2d3..34600a7 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -30,7 +30,7 @@
 INIT_LOGGER(HelloProtocol);
 
 const std::string HelloProtocol::INFO_COMPONENT = "INFO";
-const std::string HelloProtocol::NLSR_COMPONENT = "NLSR";
+const std::string HelloProtocol::NLSR_COMPONENT = "nlsr";
 
 HelloProtocol::HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler)
   : m_nlsr(nlsr)
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 71970ec..3c3fab3 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -97,18 +97,18 @@
 Nlsr::setInfoInterestFilter()
 {
   ndn::Name name(m_confParam.getRouterPrefix());
-  name.append("NLSR");
+  name.append("nlsr");
   name.append("INFO");
 
   NLSR_LOG_DEBUG("Setting interest filter for Hello interest: " << name);
 
-  getNlsrFace().setInterestFilter(name,
-                                  std::bind(&HelloProtocol::processInterest,
-                                            &m_helloProtocol, _1, _2),
-                                  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
-                                  std::bind(&Nlsr::registrationFailed, this, _1),
-                                  m_signingInfo,
-                                  ndn::nfd::ROUTE_FLAG_CAPTURE);
+  m_nlsrFace.setInterestFilter(name,
+                               std::bind(&HelloProtocol::processInterest,
+                                         &m_helloProtocol, _1, _2),
+                               std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+                               std::bind(&Nlsr::registrationFailed, this, _1),
+                               m_signingInfo,
+                               ndn::nfd::ROUTE_FLAG_CAPTURE);
 }
 
 void
@@ -118,13 +118,13 @@
 
   NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name);
 
-  getNlsrFace().setInterestFilter(name,
-                                  std::bind(&Lsdb::processInterest,
-                                            &m_nlsrLsdb, _1, _2),
-                                  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
-                                  std::bind(&Nlsr::registrationFailed, this, _1),
-                                  m_signingInfo,
-                                  ndn::nfd::ROUTE_FLAG_CAPTURE);
+  m_nlsrFace.setInterestFilter(name,
+                               std::bind(&Lsdb::processInterest,
+                                         &m_nlsrLsdb, _1, _2),
+                               std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+                               std::bind(&Nlsr::registrationFailed, this, _1),
+                               m_signingInfo,
+                               ndn::nfd::ROUTE_FLAG_CAPTURE);
 }
 
 
@@ -132,6 +132,7 @@
 Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
 {
   try {
+    // false since we want to have control over the registration process
     m_dispatcher.addTopPrefix(topPrefix, false, m_signingInfo);
   }
   catch (const std::exception& e) {
@@ -277,7 +278,7 @@
   setLsaInterestFilter();
 
   // add top-level prefixes: router and localhost prefix
-  addDispatcherTopPrefix(m_confParam.getRouterPrefix());
+  addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
   addDispatcherTopPrefix(LOCALHOST_PREFIX);
 
   initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
@@ -299,6 +300,7 @@
 
   registerKeyPrefix();
   registerLocalhostPrefix();
+  registerRouterPrefix();
 
   m_helloProtocol.scheduleInterest(m_firstHelloInterval);
 
@@ -319,7 +321,7 @@
   NLSR_LOG_DEBUG("Initializing Key ...");
 
   ndn::Name nlsrInstanceName = m_confParam.getRouterPrefix();
-  nlsrInstanceName.append("NLSR");
+  nlsrInstanceName.append("nlsr");
 
   try {
     m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
@@ -377,7 +379,7 @@
 {
   // Start listening for the interest of this router's NLSR certificate
   ndn::Name nlsrKeyPrefix = getConfParameter().getRouterPrefix();
-  nlsrKeyPrefix.append("NLSR");
+  nlsrKeyPrefix.append("nlsr");
   nlsrKeyPrefix.append("KEY");
 
   m_nlsrFace.setInterestFilter(nlsrKeyPrefix,
@@ -436,6 +438,14 @@
 }
 
 void
+Nlsr::registerRouterPrefix()
+{
+  m_nlsrFace.registerPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"),
+                            std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+                            std::bind(&Nlsr::registrationFailed, this, _1));
+}
+
+void
 Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest)
 {
   NLSR_LOG_DEBUG("Got interest for certificate. Interest: " << interest.getName());
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 018febf..476650f 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -436,6 +436,11 @@
   void
   registerLocalhostPrefix();
 
+  /*! \brief Registers the <router-prefix>/nlsr so that NLSR can respond to status requests from remote routers.
+   */
+  void
+  registerRouterPrefix();
+
   /*! \brief Attempts to satisfy an Interest for a certificate, and send it back.
    */
   void
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 0be5e54..7dbf821 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -119,7 +119,7 @@
 void
 RoutingTableCalculator::writeAdjMatrixLog(const Map& map) const
 {
-  if (!getNdnCxxLogger().isLevelEnabled(ndn::util::LogLevel::DEBUG)) {
+  if (!ndn_cxx_getLogger().isLevelEnabled(ndn::util::LogLevel::DEBUG)) {
     return;
   }
 
@@ -133,7 +133,7 @@
       routerIndex += " ";
       lengthOfDash += "--";
       NLSR_LOG_DEBUG("Router:" + map.getRouterNameByMappingNo(i)->toUri() +
-                     "Index:" + boost::lexical_cast<std::string>(i));
+                     " Index:" + boost::lexical_cast<std::string>(i));
   }
   NLSR_LOG_DEBUG(" |" + routerIndex);
   NLSR_LOG_DEBUG(lengthOfDash);
diff --git a/tests/publisher/publisher-fixture.hpp b/tests/publisher/publisher-fixture.hpp
index dd733fa..05e5a0f 100644
--- a/tests/publisher/publisher-fixture.hpp
+++ b/tests/publisher/publisher-fixture.hpp
@@ -60,6 +60,23 @@
   }
 
   void
+  checkPrefixRegistered(const Name& prefix)
+  {
+    bool registerCommandEmitted = false;
+    for (const auto& interest : face.sentInterests) {
+      if (interest.getName().size() > 4 && interest.getName().get(3) == name::Component("register")) {
+        name::Component test = interest.getName().get(4);
+        ndn::nfd::ControlParameters params(test.blockFromValue());
+        if (params.getName() == prefix) {
+          registerCommandEmitted = true;
+          break;
+        }
+      }
+    }
+    BOOST_CHECK(registerCommandEmitted);
+  }
+
+  void
   addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
   {
     Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
diff --git a/tests/publisher/test-dataset-interest-handler.cpp b/tests/publisher/test-dataset-interest-handler.cpp
index 7cc4a84..bbb37a7 100644
--- a/tests/publisher/test-dataset-interest-handler.cpp
+++ b/tests/publisher/test-dataset-interest-handler.cpp
@@ -57,6 +57,8 @@
 
 BOOST_AUTO_TEST_CASE(Localhost)
 {
+  checkPrefixRegistered(Nlsr::LOCALHOST_PREFIX);
+
   // Install adjacency LSA
   AdjLsa adjLsa;
   adjLsa.setOrigRouter("/RouterA");
@@ -108,6 +110,13 @@
 
 BOOST_AUTO_TEST_CASE(Routername)
 {
+  ndn::Name regRouterPrefix(nlsr.getConfParameter().getRouterPrefix());
+  regRouterPrefix.append("nlsr");
+  // Should already be added to dispatcher
+  BOOST_CHECK_THROW(nlsr.getDispatcher().addTopPrefix(regRouterPrefix), std::out_of_range);
+
+  checkPrefixRegistered(regRouterPrefix);
+
   //Install adjacencies LSA
   AdjLsa adjLsa;
   adjLsa.setOrigRouter("/RouterA");
@@ -129,22 +138,22 @@
   rt1.addNextHop(DEST_ROUTER, nh);
 
   // Request adjacency LSAs
-  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("adjacencies")));
+  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("adjacencies")));
   processDatasetInterest(face,
     [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
 
   // Request coordinate LSAs
-  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("coordinates")));
+  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("coordinates")));
   processDatasetInterest(face,
     [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
 
   // Request Name LSAs
-  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("names")));
+  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("names")));
   processDatasetInterest(face,
     [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
 
   // Request Routing Table
-  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/routing-table")));
+  face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/routing-table")));
   processDatasetInterest(face,
     [] (const ndn::Block& block) {
       return block.type() == ndn::tlv::nlsr::RoutingTable; });
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index a5c8005..14fce9a 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -172,8 +172,8 @@
   BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/");
   BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/");
   BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/");
-  BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), ndn::Name("/localhop/ndn/NLSR/sync").appendVersion(ConfParameter::SYNC_VERSION));
-  BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/NLSR/LSA");
+  BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
+  BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA");
   BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
   BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
   BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
diff --git a/tests/update/test-nfd-rib-command-processor.cpp b/tests/update/test-nfd-rib-command-processor.cpp
index 0709e43..b6645d2 100644
--- a/tests/update/test-nfd-rib-command-processor.cpp
+++ b/tests/update/test-nfd-rib-command-processor.cpp
@@ -73,7 +73,7 @@
     // Need to send an interest now since ChronoSync
     // no longer does face->put(*data) in publishData.
     // Instead it does it in onInterest
-    ndn::Name lsaInterestName("/localhop/ndn/NLSR/LSA/This/router");
+    ndn::Name lsaInterestName("/localhop/ndn/nlsr/LSA/This/router");
     lsaInterestName.append(std::to_string(Lsa::Type::NAME));
 
     lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());