src: change initialization order

Send Hello Interest after route to neighbor is successfully registered
--> First Hello interval is eliminated
--> After Hello Nack, wait exponentially before processing it as a timeout
Register sync route for each neighbor after its Hello Data is validated

refs: #5009

Change-Id: Ice39a591f1e58e474b494d93c913fa45e10f24f2
diff --git a/tests/communication/test-sync-logic-handler.cpp b/tests/communication/test-sync-logic-handler.cpp
index 4dc6346..2352735 100644
--- a/tests/communication/test-sync-logic-handler.cpp
+++ b/tests/communication/test-sync-logic-handler.cpp
@@ -61,12 +61,12 @@
     if (Protocol == SYNC_PROTOCOL_CHRONOSYNC) {
       std::vector<chronosync::MissingDataInfo> updates;
       updates.push_back({ndn::Name(prefix).appendNumber(1), 0, seqNo});
-      sync.m_syncLogic->onChronoSyncUpdate(updates);
+      sync.m_syncLogic.onChronoSyncUpdate(updates);
     }
     else {
       std::vector<psync::MissingDataInfo> updates;
       updates.push_back({ndn::Name(prefix), 0, seqNo});
-      sync.m_syncLogic->onPSyncUpdate(updates);
+      sync.m_syncLogic.onPSyncUpdate(updates);
     }
 
     this->advanceClocks(ndn::time::milliseconds(1), 10);
@@ -246,8 +246,6 @@
   expectedPrefix.append(this->conf.getSiteName());
   expectedPrefix.append(this->conf.getRouterName());
 
-  this->sync.buildUpdatePrefix();
-
   BOOST_CHECK_EQUAL(this->sync.m_nameLsaUserPrefix,
                     ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::NAME)));
   BOOST_CHECK_EQUAL(this->sync.m_adjLsaUserPrefix,
@@ -256,27 +254,6 @@
                     ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::COORDINATE)));
 }
 
-/* Tests that SyncLogicHandler's socket will be created when
-   Nlsr is initialized, preventing use of sync before the
-   socket is created.
-
-   NB: This test is as much an Nlsr class test as a
-   SyncLogicHandler class test, but it rides the line and ends up here.
- */
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(createSyncLogicOnInitialization, T, Protocols,
-                                 SyncLogicFixture<T::value>) // Bug #2649
-{
-  Nlsr nlsr(this->face, this->m_keyChain, this->conf);
-
-  // Make sure an adjacency LSA has not been built yet
-  ndn::Name key = ndn::Name(this->conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
-  AdjLsa* lsa = nlsr.m_lsdb.findAdjLsa(key);
-  BOOST_REQUIRE(lsa == nullptr);
-
-  // Publish a routing update before an Adjacency LSA is built
-  BOOST_CHECK_NO_THROW(nlsr.m_lsdb.m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, 0));
-}
-
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test
diff --git a/tests/publisher/test-dataset-interest-handler.cpp b/tests/publisher/test-dataset-interest-handler.cpp
index ee96ba8..070c06d 100644
--- a/tests/publisher/test-dataset-interest-handler.cpp
+++ b/tests/publisher/test-dataset-interest-handler.cpp
@@ -45,9 +45,7 @@
   parser.parse();
 
   ndn::Block::element_const_iterator it = parser.elements_begin();
-  BOOST_CHECK_EQUAL(isSameType(*it), true);
-  ++it;
-
+  BOOST_CHECK_EQUAL(isSameType(*it++), true);
   BOOST_CHECK(it == parser.elements_end());
 
   face.sentData.clear();
diff --git a/tests/route/test-fib.cpp b/tests/route/test-fib.cpp
index 2e975e8..ae297de 100644
--- a/tests/route/test-fib.cpp
+++ b/tests/route/test-fib.cpp
@@ -53,10 +53,6 @@
 
     fib = std::make_shared<Fib>(*face, m_scheduler, adjacencies, conf, m_keyChain);
     fib->setEntryRefreshTime(1);
-
-    fib->m_faceMap.update(router1FaceUri, router1FaceId);
-    fib->m_faceMap.update(router2FaceUri, router2FaceId);
-    fib->m_faceMap.update(router3FaceUri, router3FaceId);
   }
 
 public:
diff --git a/tests/route/test-name-prefix-table.cpp b/tests/route/test-name-prefix-table.cpp
index 947f8e1..a97520d 100644
--- a/tests/route/test-name-prefix-table.cpp
+++ b/tests/route/test-name-prefix-table.cpp
@@ -56,7 +56,7 @@
   conf.setNetwork("/ndn");
   conf.setSiteName("/router");
   conf.setRouterName("/a");
-  conf.buildRouterPrefix();
+  conf.buildRouterAndSyncUserPrefix();
 
   RoutingTable& routingTable = nlsr.m_routingTable;
   routingTable.setRoutingCalcInterval(0);
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index 9a648a0..878a27d 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -181,10 +181,10 @@
     conf.setNetwork("/ndn");
     conf.setSiteName("/site");
     conf.setRouterName("/%C1.Router/this-router");
-    conf.buildRouterPrefix();
+    conf.buildRouterAndSyncUserPrefix();
 
     conf.setSyncProtocol(protocol);
-    conf.setHyperbolicState(HYPERBOLIC_STATE_OFF);
+    conf.setHyperbolicState(hyperbolicState);
   }
 };
 
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 2d5958d..d00f6ed 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -54,8 +54,7 @@
   "  hello-retries 3\n"
   "  hello-timeout 1\n"
   "  hello-interval  60\n\n"
-  "  adj-lsa-build-interval 3\n"
-  "  first-hello-interval  6\n"
+  "  adj-lsa-build-interval 10\n"
   "  neighbor\n"
   "  {\n"
   "    name /ndn/memphis.edu/cs/castor\n"
@@ -162,7 +161,7 @@
 BOOST_AUTO_TEST_CASE(LinkState)
 {
   processConfigurationString(CONFIG_LINK_STATE);
-  conf.buildRouterPrefix();
+  conf.buildRouterAndSyncUserPrefix();
 
   // General
   BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
@@ -183,8 +182,7 @@
   BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
   BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
 
-  BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3);
-  BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
+  BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10);
 
   BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
   BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
@@ -219,8 +217,7 @@
     "  hello-retries 3\n"
     "  hello-timeout 1\n"
     "  hello-interval  60\n\n"
-    "  adj-lsa-build-interval 3\n"
-    "  first-hello-interval  6\n"
+    "  adj-lsa-build-interval 10\n"
     "  neighbor\n"
     "  {\n"
     "    name /ndn/memphis.edu/cs/castor\n"
@@ -286,8 +283,6 @@
   BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
-  BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
-                    static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
                     static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
 }
diff --git a/tests/test-conf-parameter.cpp b/tests/test-conf-parameter.cpp
index a42d596..7b3b74e 100644
--- a/tests/test-conf-parameter.cpp
+++ b/tests/test-conf-parameter.cpp
@@ -79,10 +79,12 @@
 
   BOOST_CHECK_EQUAL(cp1.getNetwork(), "ATT");
 
-  cp1.buildRouterPrefix();
+  cp1.buildRouterAndSyncUserPrefix();
 
   BOOST_CHECK_EQUAL(cp1.getRouterPrefix(), "/ATT/memphis/router1");
 
+  BOOST_CHECK_EQUAL(cp1.getSyncUserPrefix(), "/localhop/ATT/nlsr/LSA/memphis/router1");
+
   BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), 2);
 
   BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 6e02ffc..2e6a6ff 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -183,14 +183,15 @@
   int nPrefixes = 0;
   while (nameLsa->serialize().size() < ndn::MAX_NDN_PACKET_SIZE) {
     nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
+    break;
   }
   lsdb.installNameLsa(*nameLsa);
 
   // Create another Lsdb and expressInterest
   ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
   face.linkTo(face2);
+
   ConfParameter conf2(face2);
-  Nlsr nlsr2(face2, m_keyChain, conf2);
   std::string config = R"CONF(
               trust-anchor
                 {
@@ -198,19 +199,19 @@
                 }
             )CONF";
   conf2.getValidator().load(config, "config-file-from-string");
+  Nlsr nlsr2(face2, m_keyChain, conf2);
 
   Lsdb& lsdb2(nlsr2.m_lsdb);
 
-  advanceClocks(ndn::time::milliseconds(1), 10);
+  advanceClocks(ndn::time::milliseconds(10), 10);
 
   ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
   interestName.appendNumber(seqNo);
-  // 0 == timeout count
-  lsdb2.expressInterest(interestName, 0);
+  lsdb2.expressInterest(interestName, 0/*= timeout count*/);
 
-  advanceClocks(ndn::time::milliseconds(1), 10);
+  advanceClocks(ndn::time::milliseconds(200), 20);
 
-  BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().front().getNpl());
+  BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().back().getNpl());
 }
 
 BOOST_AUTO_TEST_CASE(SegmentLsaData)
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index 6be31ed..f5ffb8e 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -65,6 +65,7 @@
   AdjacencyList& neighbors;
   uint32_t nSuccessCallbacks;
   uint32_t nFailureCallbacks;
+  ndn::util::signal::ScopedConnection connection;
 };
 
 BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
@@ -121,7 +122,6 @@
 {
   // Simulate loading configuration file
   conf.setAdjLsaBuildInterval(3);
-  conf.setFirstHelloInterval(6);
   conf.setRoutingCalcInterval(9);
 
   Nlsr nlsr2(m_face, m_keyChain, conf);
@@ -130,7 +130,6 @@
   const RoutingTable& rt = nlsr2.m_routingTable;
 
   BOOST_CHECK_EQUAL(lsdb.m_adjLsaBuildInterval, ndn::time::seconds(3));
-  BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
   BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9));
 }
 
@@ -265,6 +264,9 @@
                           10, Adjacent::STATUS_ACTIVE, 0, 256);
   neighbors.insert(otherNeighbor);
 
+  // Set HelloInterest lifetime as 10 seconds so that neighbors are not marked INACTIVE
+  // upon timeout before this test ends
+  conf.setInterestResendTime(10);
   nlsr.initialize();
 
   // Simulate successful HELLO responses
@@ -531,9 +533,6 @@
   conf.setFaceDatasetFetchInterval(fetchInterval);
   conf.setFaceDatasetFetchTries(0);
 
-  nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1),
-                       std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0));
-
   // Elapse the default timeout time of the interest.
   this->advanceClocks(defaultTimeout);
 
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index 5926701..83479c7 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -36,15 +36,12 @@
   StatisticsFixture()
     : face(m_ioService, m_keyChain)
     , conf(face)
+    , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
     , hello(nlsr.m_helloProtocol)
     , collector(nlsr.m_statsCollector)
   {
-    conf.setNetwork("/ndn");
-    conf.setSiteName("/site");
-    conf.setRouterName("/%C1.Router/this-router");
-    conf.buildRouterPrefix();
     // Otherwise code coverage node fails with default 60 seconds lifetime
     conf.setSyncInterestLifetime(1000);
 
@@ -116,6 +113,7 @@
 public:
   ndn::util::DummyClientFace face;
   ConfParameter conf;
+  DummyConfFileProcessor confProcessor;
   Nlsr nlsr;
 
   Lsdb& lsdb;
@@ -254,6 +252,7 @@
   nameLsaKey.append(std::to_string(Lsa::Type::NAME));
 
   NameLsa* nameLsa = lsdb.findNameLsa(nameLsaKey);
+  BOOST_ASSERT(nameLsa != nullptr);
 
   seqNo = nameLsa->getLsSeqNo();