src: decouple classes from Nlsr object

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

Change-Id: Ibe3ac3820f11e8107ee4b13e510d53c27467a6cb
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 18108b7..bdf39a1 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -20,7 +20,6 @@
  **/
 
 #include "conf-file-processor.hpp"
-#include "conf-parameter.hpp"
 #include "adjacent.hpp"
 #include "utility/name-helper.hpp"
 #include "update/prefix-update-processor.hpp"
@@ -134,6 +133,12 @@
   bool m_isRequired;
 };
 
+ConfFileProcessor::ConfFileProcessor(ConfParameter& confParam)
+  : m_confFileName(confParam.getConfFileName())
+  , m_confParam(confParam)
+{
+}
+
 bool
 ConfFileProcessor::processConfFile()
 {
@@ -220,7 +225,7 @@
     std::string router = section.get<std::string>("router");
     ndn::Name networkName(network);
     if (!networkName.empty()) {
-      m_nlsr.getConfParameter().setNetwork(networkName);
+      m_confParam.setNetwork(networkName);
     }
     else {
       std::cerr << " Network can not be null or empty or in bad URI format :(!" << std::endl;
@@ -228,7 +233,7 @@
     }
     ndn::Name siteName(site);
     if (!siteName.empty()) {
-      m_nlsr.getConfParameter().setSiteName(siteName);
+      m_confParam.setSiteName(siteName);
     }
     else {
       std::cerr << "Site can not be null or empty or in bad URI format:( !" << std::endl;
@@ -236,7 +241,7 @@
     }
     ndn::Name routerName(router);
     if (!routerName.empty()) {
-      m_nlsr.getConfParameter().setRouterName(routerName);
+      m_confParam.setRouterName(routerName);
     }
     else {
       std::cerr << " Router name can not be null or empty or in bad URI format:( !" << std::endl;
@@ -252,7 +257,7 @@
   uint32_t lsaRefreshTime = section.get<uint32_t>("lsa-refresh-time", LSA_REFRESH_TIME_DEFAULT);
 
   if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
-    m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
+    m_confParam.setLsaRefreshTime(lsaRefreshTime);
   }
   else {
     std::cerr << "Wrong value for lsa-refresh-time ";
@@ -265,8 +270,8 @@
   // router-dead-interval
   uint32_t routerDeadInterval = section.get<uint32_t>("router-dead-interval", (2*lsaRefreshTime));
 
-  if (routerDeadInterval > m_nlsr.getConfParameter().getLsaRefreshTime()) {
-    m_nlsr.getConfParameter().setRouterDeadInterval(routerDeadInterval);
+  if (routerDeadInterval > m_confParam.getLsaRefreshTime()) {
+    m_confParam.setRouterDeadInterval(routerDeadInterval);
   }
   else {
     std::cerr << "Value of router-dead-interval must be larger than lsa-refresh-time" << std::endl;
@@ -277,7 +282,7 @@
   int lifetime = section.get<int>("lsa-interest-lifetime", LSA_INTEREST_LIFETIME_DEFAULT);
 
   if (lifetime >= LSA_INTEREST_LIFETIME_MIN && lifetime <= LSA_INTEREST_LIFETIME_MAX) {
-    m_nlsr.getConfParameter().setLsaInterestLifetime(ndn::time::seconds(lifetime));
+    m_confParam.setLsaInterestLifetime(ndn::time::seconds(lifetime));
   }
   else {
     std::cerr << "Wrong value for lsa-interest-timeout. "
@@ -290,10 +295,10 @@
   // sync-protocol
   std::string syncProtocol = section.get<std::string>("sync-protocol", "chronosync");
   if (syncProtocol == "chronosync") {
-    m_nlsr.getConfParameter().setSyncProtocol(SYNC_PROTOCOL_CHRONOSYNC);
+    m_confParam.setSyncProtocol(SYNC_PROTOCOL_CHRONOSYNC);
   }
   else if (syncProtocol == "psync") {
-    m_nlsr.getConfParameter().setSyncProtocol(SYNC_PROTOCOL_PSYNC);
+    m_confParam.setSyncProtocol(SYNC_PROTOCOL_PSYNC);
   }
   else {
     std::cerr << "Sync protocol " << syncProtocol << " is not supported!"
@@ -302,10 +307,11 @@
   }
 
   // sync-interest-lifetime
-  uint32_t syncInterestLifetime = section.get<uint32_t>("sync-interest-lifetime", SYNC_INTEREST_LIFETIME_DEFAULT);
+  uint32_t syncInterestLifetime = section.get<uint32_t>("sync-interest-lifetime",
+                                                        SYNC_INTEREST_LIFETIME_DEFAULT);
   if (syncInterestLifetime >= SYNC_INTEREST_LIFETIME_MIN &&
       syncInterestLifetime <= SYNC_INTEREST_LIFETIME_MAX) {
-    m_nlsr.getConfParameter().setSyncInterestLifetime(syncInterestLifetime);
+    m_confParam.setSyncInterestLifetime(syncInterestLifetime);
   }
   else {
     std::cerr << "Wrong value for sync-interest-lifetime. "
@@ -323,7 +329,7 @@
         std::ofstream testOutFile;
         testOutFile.open(testFileName.c_str());
         if (testOutFile.is_open() && testOutFile.good()) {
-          m_nlsr.getConfParameter().setSeqFileDir(seqDir);
+          m_confParam.setSeqFileDir(seqDir);
         }
         else {
           std::cerr << "User does not have read and write permission on the directory";
@@ -359,7 +365,7 @@
   int retrials = section.get<int>("hello-retries", HELLO_RETRIES_DEFAULT);
 
   if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
-    m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
+    m_confParam.setInterestRetryNumber(retrials);
   }
   else {
     std::cerr << "Wrong value for hello-retries." << std::endl;
@@ -373,7 +379,7 @@
   uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
 
   if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
-    m_nlsr.getConfParameter().setInterestResendTime(timeOut);
+    m_confParam.setInterestResendTime(timeOut);
   }
   else {
     std::cerr << "Wrong value for hello-timeout. ";
@@ -387,7 +393,7 @@
   uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT);
 
   if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
-    m_nlsr.getConfParameter().setInfoInterestInterval(interval);
+    m_confParam.setInfoInterestInterval(interval);
   }
   else {
     std::cerr << "Wrong value for hello-interval. ";
@@ -401,7 +407,7 @@
   // adj-lsa-build-interval
   ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval",
                                                       std::bind(&ConfParameter::setAdjLsaBuildInterval,
-                                                      &m_nlsr.getConfParameter(), _1));
+                                                      &m_confParam, _1));
   adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX);
   adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT);
 
@@ -411,7 +417,7 @@
   // Set the retry count for fetching the FaceStatus dataset
   ConfigurationVariable<uint32_t> faceDatasetFetchTries("face-dataset-fetch-tries",
                                                         std::bind(&ConfParameter::setFaceDatasetFetchTries,
-                                                                  &m_nlsr.getConfParameter(),
+                                                                  &m_confParam,
                                                                   _1));
 
   faceDatasetFetchTries.setMinAndMaxValue(FACE_DATASET_FETCH_TRIES_MIN,
@@ -425,7 +431,7 @@
   // Set the interval between FaceStatus dataset fetch attempts.
   ConfigurationVariable<uint32_t> faceDatasetFetchInterval("face-dataset-fetch-interval",
                                                            bind(&ConfParameter::setFaceDatasetFetchInterval,
-                                                                &m_nlsr.getConfParameter(),
+                                                                &m_confParam,
                                                                 _1));
 
   faceDatasetFetchInterval.setMinAndMaxValue(FACE_DATASET_FETCH_INTERVAL_MIN,
@@ -439,7 +445,7 @@
   // first-hello-interval
   ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
                                                      std::bind(&ConfParameter::setFirstHelloInterval,
-                                                     &m_nlsr.getConfParameter(), _1));
+                                                     &m_confParam, _1));
   firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
   firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
 
@@ -484,7 +490,7 @@
         ndn::Name neighborName(name);
         if (!neighborName.empty()) {
           Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
-          m_nlsr.getAdjacencyList().insert(adj);
+          m_confParam.getAdjacencyList().insert(adj);
         }
         else {
           std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
@@ -507,13 +513,13 @@
   std::string state = section.get<std::string>("state", "off");
 
   if (boost::iequals(state, "off")) {
-    m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
+    m_confParam.setHyperbolicState(HYPERBOLIC_STATE_OFF);
   }
   else if (boost::iequals(state, "on")) {
-    m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
+    m_confParam.setHyperbolicState(HYPERBOLIC_STATE_ON);
   }
   else if (state == "dry-run") {
-    m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
+    m_confParam.setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
   }
   else {
     std::cerr << "Wrong format for hyperbolic state." << std::endl;
@@ -542,10 +548,10 @@
       }
     }
 
-    if (!m_nlsr.getConfParameter().setCorR(radius)) {
+    if (!m_confParam.setCorR(radius)) {
       return false;
     }
-    m_nlsr.getConfParameter().setCorTheta(angles);
+    m_confParam.setCorTheta(angles);
   }
   catch (const std::exception& ex) {
     std::cerr << ex.what() << std::endl;
@@ -566,7 +572,7 @@
   if (maxFacesPerPrefix >= MAX_FACES_PER_PREFIX_MIN &&
       maxFacesPerPrefix <= MAX_FACES_PER_PREFIX_MAX)
   {
-    m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefix);
+    m_confParam.setMaxFacesPerPrefix(maxFacesPerPrefix);
   }
   else {
     std::cerr << "Wrong value for max-faces-per-prefix. ";
@@ -578,7 +584,7 @@
   // routing-calc-interval
   ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval",
                                                       std::bind(&ConfParameter::setRoutingCalcInterval,
-                                                      &m_nlsr.getConfParameter(), _1));
+                                                      &m_confParam, _1));
   routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX);
   routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT);
 
@@ -599,7 +605,7 @@
        std::string prefix = tn->second.data();
        ndn::Name namePrefix(prefix);
        if (!namePrefix.empty()) {
-         m_nlsr.getNamePrefixList().insert(namePrefix);
+         m_confParam.getNamePrefixList().insert(namePrefix);
        }
        else {
          std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
@@ -625,11 +631,11 @@
     return false;
   }
 
-  m_nlsr.loadValidator(it->second, m_confFileName);
+  m_confParam.getValidator().load(it->second, m_confFileName);
 
   it++;
   if (it != section.end() && it->first == "prefix-update-validator") {
-    m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
+    m_confParam.getPrefixUpdateValidator().load(it->second, m_confFileName);
 
     it++;
     for (; it != section.end(); it++) {
@@ -650,7 +656,11 @@
         return false;
       }
 
-      m_nlsr.loadCertToPublish(*idCert);
+      m_confParam.getCertStore().insert(*idCert);
+      m_confParam.getValidator().loadAnchor("Authoritative-Certificate",
+                                            ndn::security::v2::Certificate(*idCert));
+      m_confParam.getPrefixUpdateValidator().loadAnchor("Authoritative-Certificate",
+                                                        ndn::security::v2::Certificate(*idCert));
     }
   }