src: decouple classes from Nlsr object

refs: #1952, #2803, #3960, #4288

Change-Id: Ibe3ac3820f11e8107ee4b13e510d53c27467a6cb
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index a5f935c..67c948f 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2018,  The University of Memphis,
+ * Copyright (c) 2014-2019,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -32,9 +32,17 @@
 const std::string HelloProtocol::INFO_COMPONENT = "INFO";
 const std::string HelloProtocol::NLSR_COMPONENT = "nlsr";
 
-HelloProtocol::HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler)
-  : m_nlsr(nlsr)
-  , m_scheduler(scheduler)
+HelloProtocol::HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain,
+                             ndn::security::SigningInfo& signingInfo,
+                             ConfParameter& confParam, RoutingTable& routingTable,
+                             Lsdb& lsdb)
+  : m_face(face)
+  , m_scheduler(m_face.getIoService())
+  , m_keyChain(keyChain)
+  , m_signingInfo(signingInfo)
+  , m_confParam(confParam)
+  , m_routingTable(routingTable)
+  , m_lsdb(lsdb)
 {
 }
 
@@ -42,46 +50,40 @@
 HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
 {
   NLSR_LOG_DEBUG("Expressing Interest :" << interestName);
-  ndn::Interest i(interestName);
-  i.setInterestLifetime(ndn::time::seconds(seconds));
-  i.setMustBeFresh(true);
-  i.setCanBePrefix(true);
-  m_nlsr.getNlsrFace().expressInterest(i,
-                                       std::bind(&HelloProtocol::onContent, this, _1, _2),
-                                       [this] (const ndn::Interest& interest,
-                                               const ndn::lp::Nack& nack)
-                                       {
-                                         NDN_LOG_TRACE("Received Nack with reason " <<
-                                                        nack.getReason());
-                                         NDN_LOG_TRACE("Treating as timeout");
-                                         processInterestTimedOut(interest);
-                                       },
-                                       std::bind(&HelloProtocol::processInterestTimedOut,
-                                                 this, _1));
+  ndn::Interest interest(interestName);
+  interest.setInterestLifetime(ndn::time::seconds(seconds));
+  interest.setMustBeFresh(true);
+  interest.setCanBePrefix(true);
+  m_face.expressInterest(interest,
+                         std::bind(&HelloProtocol::onContent, this, _1, _2),
+                         [this] (const ndn::Interest& interest, const ndn::lp::Nack& nack)
+                         {
+                           NDN_LOG_TRACE("Received Nack with reason " << nack.getReason());
+                           NDN_LOG_TRACE("Treating as timeout");
+                           processInterestTimedOut(interest);
+                         },
+                         std::bind(&HelloProtocol::processInterestTimedOut, this, _1));
 
   // increment SENT_HELLO_INTEREST
   hpIncrementSignal(Statistics::PacketType::SENT_HELLO_INTEREST);
 }
 
 void
-HelloProtocol::sendScheduledInterest(uint32_t seconds)
+HelloProtocol::sendScheduledInterest()
 {
-  std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
-  for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
-       ++it) {
+  for (const auto& adjacent : m_confParam.getAdjacencyList().getAdjList()) {
     // If this adjacency has a Face, just proceed as usual.
-    if((*it).getFaceId() != 0) {
+    if(adjacent.getFaceId() != 0) {
       // interest name: /<neighbor>/NLSR/INFO/<router>
-      ndn::Name interestName = (*it).getName() ;
+      ndn::Name interestName = adjacent.getName() ;
       interestName.append(NLSR_COMPONENT);
       interestName.append(INFO_COMPONENT);
-      interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
-      expressInterest(interestName,
-                      m_nlsr.getConfParameter().getInterestResendTime());
+      interestName.append(m_confParam.getRouterPrefix().wireEncode());
+      expressInterest(interestName, m_confParam.getInterestResendTime());
       NLSR_LOG_DEBUG("Sending scheduled interest: " << interestName);
     }
   }
-  scheduleInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
+  scheduleInterest(m_confParam.getInfoInterestInterval());
 }
 
 void
@@ -90,7 +92,9 @@
   NLSR_LOG_DEBUG("Scheduling HELLO Interests in " << ndn::time::seconds(seconds));
 
   m_scheduler.scheduleEvent(ndn::time::seconds(seconds),
-                            std::bind(&HelloProtocol::sendScheduledInterest, this, seconds));
+                            [this] {
+                              sendScheduledInterest();
+                            });
 }
 
 void
@@ -113,22 +117,22 @@
   ndn::Name neighbor;
   neighbor.wireDecode(interestName.get(-1).blockFromValue());
   NLSR_LOG_DEBUG("Neighbor: " << neighbor);
-  if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
+  if (m_confParam.getAdjacencyList().isNeighbor(neighbor)) {
     std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
     data->setName(ndn::Name(interest.getName()).appendVersion());
     data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
     data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
-                    INFO_COMPONENT.size());
+                                                      INFO_COMPONENT.size());
 
-    m_nlsr.getKeyChain().sign(*data, m_nlsr.getSigningInfo());
+    m_keyChain.sign(*data, m_signingInfo);
 
     NLSR_LOG_DEBUG("Sending out data for name: " << interest.getName());
 
-    m_nlsr.getNlsrFace().put(*data);
+    m_face.put(*data);
     // increment SENT_HELLO_DATA
     hpIncrementSignal(Statistics::PacketType::SENT_HELLO_DATA);
 
-    auto adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
+    auto adjacent = m_confParam.getAdjacencyList().findAdjacent(neighbor);
     // If this neighbor was previously inactive, send our own hello interest, too
     if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) {
       // We can only do that if the neighbor currently has a face.
@@ -137,9 +141,8 @@
         ndn::Name interestName(neighbor);
         interestName.append(NLSR_COMPONENT);
         interestName.append(INFO_COMPONENT);
-        interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
-        expressInterest(interestName,
-                        m_nlsr.getConfParameter().getInterestResendTime());
+        interestName.append(m_confParam.getRouterPrefix().wireEncode());
+        expressInterest(interestName, m_confParam.getInterestResendTime());
       }
     }
   }
@@ -156,31 +159,30 @@
   }
   ndn::Name neighbor = interestName.getPrefix(-3);
   NLSR_LOG_DEBUG("Neighbor: " << neighbor);
-  m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
+  m_confParam.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
 
-  Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+  Adjacent::Status status = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
 
   uint32_t infoIntTimedOutCount =
-    m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
+    m_confParam.getAdjacencyList().getTimedOutInterestCount(neighbor);
   NLSR_LOG_DEBUG("Status: " << status);
   NLSR_LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount);
-  if (infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber()) {
+  if (infoIntTimedOutCount < m_confParam.getInterestRetryNumber()) {
     // interest name: /<neighbor>/NLSR/INFO/<router>
     ndn::Name interestName(neighbor);
     interestName.append(NLSR_COMPONENT);
     interestName.append(INFO_COMPONENT);
-    interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
+    interestName.append(m_confParam.getRouterPrefix().wireEncode());
     NLSR_LOG_DEBUG("Resending interest: " << interestName);
-    expressInterest(interestName,
-                    m_nlsr.getConfParameter().getInterestResendTime());
+    expressInterest(interestName, m_confParam.getInterestResendTime());
   }
   else if ((status == Adjacent::STATUS_ACTIVE) &&
-           (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
-    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
+           (infoIntTimedOutCount == m_confParam.getInterestRetryNumber())) {
+    m_confParam.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
 
     NLSR_LOG_DEBUG("Neighbor: " << neighbor << " status changed to INACTIVE");
 
-    m_nlsr.getLsdb().scheduleAdjLsaBuild();
+    m_lsdb.scheduleAdjLsaBuild();
   }
 }
 
@@ -196,10 +198,10 @@
       NLSR_LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
     }
   }
-  m_nlsr.getValidator().validate(data,
-                                 std::bind(&HelloProtocol::onContentValidated, this, _1),
-                                 std::bind(&HelloProtocol::onContentValidationFailed,
-                                           this, _1, _2));
+  m_confParam.getValidator().validate(data,
+                                      std::bind(&HelloProtocol::onContentValidated, this, _1),
+                                      std::bind(&HelloProtocol::onContentValidationFailed,
+                                                this, _1, _2));
 }
 
 void
@@ -212,20 +214,20 @@
   if (dataName.get(-3).toUri() == INFO_COMPONENT) {
     ndn::Name neighbor = dataName.getPrefix(-4);
 
-    Adjacent::Status oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
-    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
-    m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
-    Adjacent::Status newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+    Adjacent::Status oldStatus = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
+    m_confParam.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
+    m_confParam.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
+    Adjacent::Status newStatus = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
 
     NLSR_LOG_DEBUG("Neighbor : " << neighbor);
     NLSR_LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus);
     // change in Adjacency list
     if ((oldStatus - newStatus) != 0) {
-      if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-        m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+      if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+        m_routingTable.scheduleRoutingTableCalculation();
       }
       else {
-        m_nlsr.getLsdb().scheduleAdjLsaBuild();
+        m_lsdb.scheduleAdjLsaBuild();
       }
     }
   }