src: decouple classes from Nlsr object
refs: #1952, #2803, #3960, #4288
Change-Id: Ibe3ac3820f11e8107ee4b13e510d53c27467a6cb
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 13f2e8e..78547e2 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.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,
* Arizona Board of Regents.
*
@@ -50,6 +50,7 @@
, m_isLsaNew(isLsaNew)
, m_confParam(conf)
{
+ createSyncLogic(conf.getSyncPrefix());
}
void
@@ -122,21 +123,21 @@
Lsa::Type lsaType;
std::istringstream(updateName.get(updateName.size()-1).toUri()) >> lsaType;
- NLSR_LOG_DEBUG("Received sync update with higher " << lsaType
- << " sequence number than entry in LSDB");
+ NLSR_LOG_DEBUG("Received sync update with higher " << lsaType <<
+ " sequence number than entry in LSDB");
if (m_isLsaNew(originRouter, lsaType, seqNo)) {
if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
- NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
- << " is enabled. Not going to fetch.");
+ NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing " <<
+ "is enabled. Not going to fetch.");
return;
}
if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
- NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state"
- << " is enabled. Not going to fetch.");
+ NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state " <<
+ "is enabled. Not going to fetch.");
return;
}
(*onNewLsa)(updateName, seqNo);
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index ae72fb8..b9461c2 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -76,11 +76,13 @@
void
publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
- /*! \brief Create and configure a Logic object to enable ChronoSync for this NLSR.
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ /*! \brief Create and configure a Logic object to enable Sync for this NLSR.
*
* In a typical situation this only needs to be called once, when NLSR starts.
- * \param syncPrefix The sync prefix you want this ChronoSync to use
- * \param syncInterestLifetime ChronoSync sends a periodic sync interest every \p syncInterestLifetime / 2 ms
+ * \param syncPrefix The sync prefix you want this Sync to use
+ * \param syncInterestLifetime ChronoSync/PSync sends a periodic sync interest every
+ * \p syncInterestLifetime / 2 ms
* \sa Nlsr::initialize
*/
void
@@ -88,10 +90,15 @@
const ndn::time::milliseconds& syncInterestLifetime =
ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
+ /*! \brief Callback from Sync protocol
+ *
+ * In a typical situation this only needs to be called once, when NLSR starts.
+ * \param updateName The prefix for which sync reports an update
+ * \param highSeq The latest sequence number of the update
+ */
void
processUpdate(const ndn::Name& updateName, uint64_t highSeq);
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Simple function to glue Name components together
*/
void
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));
}
}
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index 0bcb7e8..65b9a16 100644
--- a/src/conf-file-processor.hpp
+++ b/src/conf-file-processor.hpp
@@ -22,7 +22,7 @@
#define NLSR_CONF_FILE_PROCESSOR_HPP
#include "common.hpp"
-#include "nlsr.hpp"
+#include "conf-parameter.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/info_parser.hpp>
@@ -46,11 +46,7 @@
class ConfFileProcessor
{
public:
- ConfFileProcessor(Nlsr& nlsr, const std::string& cfile)
- : m_confFileName(cfile)
- , m_nlsr(nlsr)
- {
- }
+ ConfFileProcessor(ConfParameter& confParam);
/*! \brief Load and parse the configuration file, then populate NLSR.
*
@@ -125,8 +121,8 @@
private:
/*! m_confFileName The full path of the configuration file to parse. */
std::string m_confFileName;
- /*! m_nlsr The NLSR object to configure upon successful parsing. */
- Nlsr& m_nlsr;
+ /*! m_confParam The ConfFileProcessor object to configure as parsing is done. */
+ ConfParameter& m_confParam;
/*! m_io For canonization of faceUri. */
boost::asio::io_service m_io;
};
diff --git a/src/conf-parameter.cpp b/src/conf-parameter.cpp
index eaaf76e..2d50838 100644
--- a/src/conf-parameter.cpp
+++ b/src/conf-parameter.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).
@@ -31,6 +31,30 @@
// To be changed when breaking changes are made to sync
const uint64_t ConfParameter::SYNC_VERSION = 6;
+ConfParameter::ConfParameter(ndn::Face& face, const std::string& confFileName)
+ : m_confFileName(confFileName)
+ , m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
+ , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
+ , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
+ , m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT)
+ , m_faceDatasetFetchInterval(ndn::time::seconds(static_cast<int>(FACE_DATASET_FETCH_INTERVAL_DEFAULT)))
+ , m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT)))
+ , m_routerDeadInterval(2 * LSA_REFRESH_TIME_DEFAULT)
+ , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
+ , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
+ , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
+ , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
+ , m_corR(0)
+ , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
+ , m_syncInterestLifetime(ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT))
+ , m_syncProtocol(SYNC_PROTOCOL_CHRONOSYNC)
+ , m_adjl()
+ , m_npl()
+ , m_validator(std::make_unique<ndn::security::v2::CertificateFetcherDirectFetch>(face))
+ , m_prefixUpdateValidator(std::make_unique<ndn::security::v2::CertificateFetcherDirectFetch>(face))
+ {
+ }
+
void
ConfParameter::writeLog()
{
@@ -38,8 +62,8 @@
NLSR_LOG_INFO("Site Name: " << m_siteName);
NLSR_LOG_INFO("Network: " << m_network);
NLSR_LOG_INFO("Router Prefix: " << m_routerPrefix);
- NLSR_LOG_INFO("ChronoSync sync Prefix: " << m_chronosyncPrefix);
- NLSR_LOG_INFO("ChronoSync LSA prefix: " << m_lsaPrefix);
+ NLSR_LOG_INFO("Sync Prefix: " << m_syncPrefix);
+ NLSR_LOG_INFO("Sync LSA prefix: " << m_lsaPrefix);
NLSR_LOG_INFO("Hello Interest retry number: " << m_interestRetryNumber);
NLSR_LOG_INFO("Hello Interest resend second: " << m_interestResendTime);
NLSR_LOG_INFO("Info Interest interval: " << m_infoInterestInterval);
@@ -67,11 +91,11 @@
{
m_network = networkName;
- m_chronosyncPrefix.append("localhop");
- m_chronosyncPrefix.append(m_network);
- m_chronosyncPrefix.append("nlsr");
- m_chronosyncPrefix.append("sync");
- m_chronosyncPrefix.appendVersion(SYNC_VERSION);
+ m_syncPrefix.append("localhop");
+ m_syncPrefix.append(m_network);
+ m_syncPrefix.append("nlsr");
+ m_syncPrefix.append("sync");
+ m_syncPrefix.appendVersion(SYNC_VERSION);
m_lsaPrefix.append("localhop");
m_lsaPrefix.append(m_network);
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index df90cda..c1f6073 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -25,10 +25,15 @@
#include "common.hpp"
#include "logger.hpp"
#include "test-access-control.hpp"
+#include "adjacency-list.hpp"
+#include "name-prefix-list.hpp"
+#include "security/certificate-store.hpp"
#include <iostream>
#include <boost/cstdint.hpp>
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
+#include <ndn-cxx/security/v2/certificate-fetcher-direct-fetch.hpp>
#include <ndn-cxx/util/time.hpp>
namespace nlsr {
@@ -133,23 +138,12 @@
{
public:
- ConfParameter()
- : m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
- , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
- , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
- , m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT)
- , m_faceDatasetFetchInterval(ndn::time::seconds(static_cast<int>(FACE_DATASET_FETCH_INTERVAL_DEFAULT)))
- , m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT)))
- , m_routerDeadInterval(2 * LSA_REFRESH_TIME_DEFAULT)
- , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
- , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
- , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
- , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
- , m_corR(0)
- , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
- , m_syncInterestLifetime(ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT))
- , m_syncProtocol(SYNC_PROTOCOL_CHRONOSYNC)
+ ConfParameter(ndn::Face& face, const std::string& confFileName = "nlsr.conf");
+
+ const std::string&
+ getConfFileName()
{
+ return m_confFileName;
}
void
@@ -199,11 +193,10 @@
return m_routerPrefix;
}
-
const ndn::Name&
- getChronosyncPrefix() const
+ getSyncPrefix() const
{
- return m_chronosyncPrefix;
+ return m_syncPrefix;
}
const ndn::Name&
@@ -434,10 +427,43 @@
return m_syncInterestLifetime;
}
+ AdjacencyList&
+ getAdjacencyList()
+ {
+ return m_adjl;
+ }
+
+ NamePrefixList&
+ getNamePrefixList()
+ {
+ return m_npl;
+ }
+
+ ndn::security::ValidatorConfig&
+ getValidator()
+ {
+ return m_validator;
+ }
+
+ ndn::security::ValidatorConfig&
+ getPrefixUpdateValidator()
+ {
+ return m_prefixUpdateValidator;
+ }
+
+ security::CertificateStore&
+ getCertStore()
+ {
+ return m_certStore;
+ }
+
+ /*! \brief Dump the current state of all attributes to the log.
+ */
void
writeLog();
private:
+ std::string m_confFileName;
ndn::Name m_routerName;
ndn::Name m_siteName;
ndn::Name m_network;
@@ -445,7 +471,7 @@
ndn::Name m_routerPrefix;
ndn::Name m_lsaRouterPrefix;
- ndn::Name m_chronosyncPrefix;
+ ndn::Name m_syncPrefix;
ndn::Name m_lsaPrefix;
uint32_t m_lsaRefreshTime;
@@ -478,6 +504,12 @@
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
static const uint64_t SYNC_VERSION;
+
+ AdjacencyList m_adjl;
+ NamePrefixList m_npl;
+ ndn::security::ValidatorConfig m_validator;
+ ndn::security::ValidatorConfig m_prefixUpdateValidator;
+ security::CertificateStore m_certStore;
};
} // namespace nlsr
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();
}
}
}
diff --git a/src/hello-protocol.hpp b/src/hello-protocol.hpp
index ae95a0e..94330e2 100644
--- a/src/hello-protocol.hpp
+++ b/src/hello-protocol.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -24,6 +24,9 @@
#include "statistics.hpp"
#include "test-access-control.hpp"
+#include "conf-parameter.hpp"
+#include "lsdb.hpp"
+#include "route/routing-table.hpp"
#include <ndn-cxx/util/signal.hpp>
#include <ndn-cxx/face.hpp>
@@ -31,15 +34,16 @@
#include <ndn-cxx/mgmt/nfd/control-response.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/security/v2/validation-error.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
namespace nlsr {
-class Nlsr;
-
class HelloProtocol
{
public:
- HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler);
+ HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain,
+ ndn::security::SigningInfo& signingInfo,
+ ConfParameter& confParam, RoutingTable& routingTable, Lsdb& lsdb);
/*! \brief Schedules a Hello Interest event.
*
@@ -69,18 +73,16 @@
/*! \brief Sends Hello Interests to all neighbors
*
- * \param seconds (ignored)
- *
* This function is called as part of a schedule to regularly
* determine the adjacency status of neighbors. This function
* creates and sends a Hello Interest to each neighbor in
* Nlsr::m_adjacencyList. If the neighbor has not been contacted
- * before and curerntly has no Face in NFD, this method will call a
+ * before and currently has no Face in NFD, this method will call a
* different pipeline that creates the Face first, then registers
* prefixes.
*/
void
- sendScheduledInterest(uint32_t seconds);
+ sendScheduledInterest();
/*! \brief Processes a Hello Interest from a neighbor.
*
@@ -172,8 +174,13 @@
registerPrefixes(const ndn::Name& adjName, const std::string& faceUri,
double linkCost, const ndn::time::milliseconds& timeout);
private:
- Nlsr& m_nlsr;
- ndn::Scheduler& m_scheduler;
+ ndn::Face& m_face;
+ ndn::Scheduler m_scheduler;
+ ndn::security::v2::KeyChain& m_keyChain;
+ ndn::security::SigningInfo& m_signingInfo;
+ ConfParameter& m_confParam;
+ RoutingTable& m_routingTable;
+ Lsdb& m_lsdb;
static const std::string INFO_COMPONENT;
static const std::string NLSR_COMPONENT;
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 5146dcd..bee69db 100644
--- a/src/lsa.cpp
+++ b/src/lsa.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,
* Arizona Board of Regents.
*
@@ -261,26 +261,6 @@
}
void
-AdjLsa::addNptEntries(Nlsr& pnlsr)
-{
- // Only add NPT entries if this is an adj LSA from another router.
- if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
- // Pass the originating router as both the name to register and
- // where it came from.
- pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter());
- }
-}
-
-
-void
-AdjLsa::removeNptEntries(Nlsr& pnlsr)
-{
- if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
- pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter());
- }
-}
-
-void
AdjLsa::writeLog() const
{
NLSR_LOG_DEBUG(*this);
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 3d453d2..54a2c75 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -33,8 +33,6 @@
namespace nlsr {
-class Nlsr;
-
class Lsa
{
public:
@@ -286,17 +284,6 @@
bool
isEqualContent(const AdjLsa& alsa) const;
- /*! \brief Installs this LSA's name prefixes into the NPT.
-
- \param pnlsr The NLSR top-level whose NPT you want to install the
- entries into.
- */
- void
- addNptEntries(Nlsr& pnlsr);
-
- void
- removeNptEntries(Nlsr& pnlsr);
-
void
writeLog() const override;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 43b86bc..e4b3912 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -37,25 +37,34 @@
const ndn::time::steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE =
ndn::time::steady_clock::TimePoint::min();
-Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
- : m_nlsr(nlsr)
- , m_scheduler(scheduler)
- , m_sync(m_nlsr.getNlsrFace(),
+Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain,
+ ndn::security::SigningInfo& signingInfo, ConfParameter& confParam,
+ NamePrefixTable& namePrefixTable, RoutingTable& routingTable)
+ : m_face(face)
+ , m_scheduler(face.getIoService())
+ , m_signingInfo(signingInfo)
+ , m_confParam(confParam)
+ , m_namePrefixTable(namePrefixTable)
+ , m_routingTable(routingTable)
+ , m_sync(m_face,
[this] (const ndn::Name& routerName, const Lsa::Type& lsaType,
const uint64_t& sequenceNumber) {
return isLsaNew(routerName, lsaType, sequenceNumber);
- }, m_nlsr.getConfParameter())
- , m_lsaStorage(scheduler)
- , m_lsaRefreshTime(0)
- , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
- , m_sequencingManager()
+ }, m_confParam)
+ , m_lsaStorage(m_scheduler)
+ , m_lsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()))
+ , m_thisRouterPrefix(m_confParam.getRouterPrefix().toUri())
+ , m_adjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval())
+ , m_sequencingManager(m_confParam.getSeqFileDir(), m_confParam.getHyperbolicState())
, m_onNewLsaConnection(m_sync.onNewLsa->connect(
[this] (const ndn::Name& updateName, uint64_t sequenceNumber) {
ndn::Name lsaInterest{updateName};
lsaInterest.appendNumber(sequenceNumber);
expressInterest(lsaInterest, 0);
}))
- , m_segmentPublisher(m_nlsr.getNlsrFace(), m_nlsr.getKeyChain())
+ , m_segmentPublisher(m_face, keyChain)
+ , m_isBuildAdjLsaSheduled(false)
+ , m_adjBuildCount(0)
{
}
@@ -86,7 +95,7 @@
// immediately since at the least the LSA Interest lifetime has elapsed.
// Otherwise, it is necessary to delay the Interest re-expression to prevent
// the potential for constant Interest flooding.
- ndn::time::seconds delay = m_nlsr.getConfParameter().getLsaInterestLifetime();
+ ndn::time::seconds delay = m_confParam.getLsaInterestLifetime();
if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) {
delay = ndn::time::seconds(0);
@@ -143,10 +152,10 @@
bool
Lsdb::buildAndInstallOwnNameLsa()
{
- NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
+ NameLsa nameLsa(m_confParam.getRouterPrefix(),
m_sequencingManager.getNameLsaSeq() + 1,
getLsaExpirationTimePoint(),
- m_nlsr.getNamePrefixList());
+ m_confParam.getNamePrefixList());
m_sequencingManager.increaseNameLsaSeq();
m_sequencingManager.writeSeqNoToFile();
@@ -206,20 +215,20 @@
nlsa.writeLog();
NLSR_LOG_TRACE("nlsa.getOrigRouter(): " << nlsa.getOrigRouter());
- NLSR_LOG_TRACE("m_nlsr.getConfParameter().getRouterPrefix(): " << m_nlsr.getConfParameter().getRouterPrefix());
+ NLSR_LOG_TRACE("m_confParam.getRouterPrefix(): " << m_confParam.getRouterPrefix());
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
// If this name LSA is from another router, add the advertised
// prefixes to the NPT.
- m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
+ m_namePrefixTable.addEntry(nlsa.getOrigRouter(),
nlsa.getOrigRouter());
for (const auto& name : nlsa.getNpl().getNames()) {
- if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().addEntry(name, nlsa.getOrigRouter());
+ if (name != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.addEntry(name, nlsa.getOrigRouter());
}
}
}
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -250,9 +259,9 @@
std::inserter(namesToAdd, namesToAdd.begin()));
for (const auto& name : namesToAdd) {
chkNameLsa->addName(name);
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
- if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().addEntry(name, nlsa.getOrigRouter());
+ if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
+ if (name != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.addEntry(name, nlsa.getOrigRouter());
}
}
}
@@ -266,14 +275,14 @@
for (const auto& name : namesToRemove) {
NLSR_LOG_DEBUG("Removing name LSA no longer advertised: " << name);
chkNameLsa->removeName(name);
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
- if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().removeEntry(name, nlsa.getOrigRouter());
+ if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
+ if (name != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.removeEntry(name, nlsa.getOrigRouter());
}
}
}
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -314,13 +323,12 @@
(*it).writeLog();
// If the requested name LSA is not ours, we also need to remove
// its entries from the NPT.
- if ((*it).getOrigRouter() !=
- m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
- (*it).getOrigRouter());
+ if ((*it).getOrigRouter() != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.removeEntry((*it).getOrigRouter(), (*it).getOrigRouter());
+
for (const auto& name : it->getNpl().getNames()) {
- if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().removeEntry(name, it->getOrigRouter());
+ if (name != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.removeEntry(name, it->getOrigRouter());
}
}
}
@@ -372,14 +380,14 @@
bool
Lsdb::buildAndInstallOwnCoordinateLsa()
{
- CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
+ CoordinateLsa corLsa(m_confParam.getRouterPrefix(),
m_sequencingManager.getCorLsaSeq() + 1,
getLsaExpirationTimePoint(),
- m_nlsr.getConfParameter().getCorR(),
- m_nlsr.getConfParameter().getCorTheta());
+ m_confParam.getCorR(),
+ m_confParam.getCorTheta());
// Sync coordinate LSAs if using HR or HR dry run.
- if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
+ if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sequencingManager.increaseCorLsaSeq();
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq());
@@ -445,15 +453,15 @@
addCoordinateLsa(clsa);
// Register the LSA's origin router prefix
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
+ if (clsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.addEntry(clsa.getOrigRouter(),
clsa.getOrigRouter());
}
- if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
+ m_routingTable.scheduleRoutingTableCalculation();
}
// Set the expiration time for the new LSA.
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (clsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -473,12 +481,12 @@
if (!chkCorLsa->isEqualContent(clsa)) {
chkCorLsa->setCorRadius(clsa.getCorRadius());
chkCorLsa->setCorTheta(clsa.getCorTheta());
- if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ if (m_confParam.getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
+ m_routingTable.scheduleRoutingTableCalculation();
}
}
// If this is an LSA from another router, refresh its expiration time.
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (clsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -519,8 +527,8 @@
NLSR_LOG_DEBUG("Deleting Coordinate Lsa");
it->writeLog();
- if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
- m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter());
+ if (it->getOrigRouter() != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.removeEntry(it->getOrigRouter(), it->getOrigRouter());
}
m_corLsdb.erase(it);
@@ -572,19 +580,19 @@
void
Lsdb::scheduleAdjLsaBuild()
{
- m_nlsr.incrementAdjBuildCount();
+ m_adjBuildCount++;
- if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
// Don't build adjacency LSAs in hyperbolic routing
NLSR_LOG_DEBUG("Adjacency LSA not built. Currently in hyperbolic routing state.");
return;
}
- if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ if (m_isBuildAdjLsaSheduled == false) {
NLSR_LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
m_scheduler.scheduleEvent(m_adjLsaBuildInterval, std::bind(&Lsdb::buildAdjLsa, this));
- m_nlsr.setIsBuildAdjLsaSheduled(true);
+ m_isBuildAdjLsaSheduled = true;
}
}
@@ -593,15 +601,15 @@
{
NLSR_LOG_TRACE("Lsdb::buildAdjLsa called");
- m_nlsr.setIsBuildAdjLsaSheduled(false);
+ m_isBuildAdjLsaSheduled = false;
- if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr.getConfParameter().getInterestRetryNumber())) {
+ if (m_confParam.getAdjacencyList().isAdjLsaBuildable(m_confParam.getInterestRetryNumber())) {
- int adjBuildCount = m_nlsr.getAdjBuildCount();
+ int adjBuildCount = m_adjBuildCount;
// Only do the adjLsa build if there's one scheduled
if (adjBuildCount > 0) {
// It only makes sense to do the adjLsa build if we have neighbors
- if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
+ if (m_confParam.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
NLSR_LOG_DEBUG("Building and installing own Adj LSA");
buildAndInstallOwnAdjLsa();
}
@@ -612,26 +620,26 @@
else {
NLSR_LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors");
// Get this router's key
- ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
+ ndn::Name key = m_confParam.getRouterPrefix();
key.append(std::to_string(Lsa::Type::ADJACENCY));
removeAdjLsa(key);
// Recompute routing table after removal
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ m_routingTable.scheduleRoutingTableCalculation();
}
// In the case that during building the adj LSA, the FIB has to
// wait on an Interest response, the number of scheduled adj LSA
// builds could change, so we shouldn't just set it to 0.
- m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
+ m_adjBuildCount = m_adjBuildCount - adjBuildCount;
}
}
// We are still waiting to know the adjacency status of some
// neighbor, so schedule a build for later (when all that has
// hopefully finished)
else {
- m_nlsr.setIsBuildAdjLsaSheduled(true);
- int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
- m_nlsr.getConfParameter().getInterestResendTime();
+ m_isBuildAdjLsaSheduled = true;
+ int schedulingTime = m_confParam.getInterestRetryNumber() *
+ m_confParam.getInterestResendTime();
m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
std::bind(&Lsdb::buildAdjLsa, this));
}
@@ -646,6 +654,13 @@
alsa.getKey()));
if (it == m_adjLsdb.end()) {
m_adjLsdb.push_back(alsa);
+ // Add any new name prefixes to the NPT
+ // Only add NPT entries if this is an adj LSA from another router.
+ if (alsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
+ // Pass the originating router as both the name to register and
+ // where it came from.
+ m_namePrefixTable.addEntry(alsa.getOrigRouter(), alsa.getOrigRouter());
+ }
return true;
}
return false;
@@ -699,10 +714,9 @@
NLSR_LOG_DEBUG("Adding Adj Lsa");
alsa.writeLog();
addAdjLsa(alsa);
- // Add any new name prefixes to the NPT
- alsa.addNptEntries(m_nlsr);
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
- if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+
+ m_routingTable.scheduleRoutingTableCalculation();
+ if (alsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -724,9 +738,9 @@
if (!chkAdjLsa->isEqualContent(alsa)) {
chkAdjLsa->getAdl().reset();
chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ m_routingTable.scheduleRoutingTableCalculation();
}
- if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if (alsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
@@ -745,14 +759,14 @@
bool
Lsdb::buildAndInstallOwnAdjLsa()
{
- AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
+ AdjLsa adjLsa(m_confParam.getRouterPrefix(),
m_sequencingManager.getAdjLsaSeq() + 1,
getLsaExpirationTimePoint(),
- m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
- m_nlsr.getAdjacencyList());
+ m_confParam.getAdjacencyList().getNumOfActiveNeighbor(),
+ m_confParam.getAdjacencyList());
//Sync adjacency LSAs if link-state or dry-run HR is enabled.
- if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
+ if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_ON) {
m_sequencingManager.increaseAdjLsaSeq();
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq());
@@ -769,8 +783,10 @@
std::bind(adjLsaCompareByKey, _1, key));
if (it != m_adjLsdb.end()) {
NLSR_LOG_DEBUG("Deleting Adj Lsa");
- (*it).writeLog();
- (*it).removeNptEntries(m_nlsr);
+ it->writeLog();
+ if (it->getOrigRouter() != m_confParam.getRouterPrefix()) {
+ m_namePrefixTable.removeEntry(it->getOrigRouter(), it->getOrigRouter());
+ }
m_adjLsdb.erase(it);
return true;
}
@@ -795,18 +811,6 @@
return m_adjLsdb;
}
-void
-Lsdb::setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime)
-{
- m_lsaRefreshTime = lsaRefreshTime;
-}
-
-void
-Lsdb::setThisRouterPrefix(std::string trp)
-{
- m_thisRouterPrefix = trp;
-}
-
// This function determines whether a name LSA should be refreshed
// or expired. The conditions for getting refreshed are: it is still
// in the LSDB, it hasn't been updated by something else already (as
@@ -892,7 +896,7 @@
}
// We have changed the contents of the LSDB, so we have to
// schedule a routing calculation
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ m_routingTable.scheduleRoutingTableCalculation();
}
}
}
@@ -921,7 +925,7 @@
NLSR_LOG_DEBUG("Deleting Coordinate Lsa");
chkCorLsa->writeLog();
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
- if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
+ if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo());
}
@@ -934,7 +938,7 @@
chkCorLsa->getLsSeqNo(),
m_lsaRefreshTime));
// Only sync coordinate LSAs if link-state routing is disabled
- if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
+ if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq());
}
@@ -944,8 +948,8 @@
NLSR_LOG_DEBUG("Other's Cor LSA, so removing from LSDB");
removeCoordinateLsa(lsaKey);
}
- if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
- m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+ m_routingTable.scheduleRoutingTableCalculation();
}
}
}
@@ -981,11 +985,11 @@
ndn::Interest interest(interestName);
ndn::util::SegmentFetcher::Options options;
- options.interestLifetime = m_nlsr.getConfParameter().getLsaInterestLifetime();
+ options.interestLifetime = m_confParam.getLsaInterestLifetime();
NLSR_LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
- auto fetcher = ndn::util::SegmentFetcher::start(m_nlsr.getNlsrFace(),
- interest, m_nlsr.getValidator(), options);
+ auto fetcher = ndn::util::SegmentFetcher::start(m_face, interest,
+ m_confParam.getValidator(), options);
auto it = m_fetchers.insert(fetcher).first;
@@ -1002,7 +1006,9 @@
});
m_lsaStorage.connectToFetcher(*fetcher);
- m_nlsr.connectToFetcher(*fetcher);
+ fetcher->afterSegmentValidated.connect([this] (const ndn::Data& data) {
+ afterSegmentValidatedSignal(data);
+ });
// increment a specific SENT_LSA_INTEREST
Lsa::Type lsaType;
@@ -1046,12 +1052,12 @@
int32_t lsaPosition = util::getNameComponentPosition(interestName, chkString);
// Forms the name of the router that the Interest packet came from.
- ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
+ ndn::Name originRouter = m_confParam.getNetwork();
originRouter.append(interestName.getSubName(lsaPosition + 1,
interestName.size() - lsaPosition - 3));
// if the interest is for this router's LSA
- if (originRouter == m_nlsr.getConfParameter().getRouterPrefix() && lsaPosition >= 0) {
+ if (originRouter == m_confParam.getRouterPrefix() && lsaPosition >= 0) {
uint64_t seqNo = interestName[-1].toNumber();
NLSR_LOG_DEBUG("LSA sequence number from interest: " << seqNo);
@@ -1077,7 +1083,7 @@
const ndn::Data* lsaSegment = m_lsaStorage.getLsaSegment(interest);
if (lsaSegment != nullptr) {
NLSR_LOG_TRACE("Found data in lsa storage. Sending the data for " << interest.getName());
- m_nlsr.getNlsrFace().put(*lsaSegment);
+ m_face.put(*lsaSegment);
}
else {
NLSR_LOG_TRACE(interest << " was not found in this lsa storage.");
@@ -1098,14 +1104,14 @@
// increment RCV_NAME_LSA_INTEREST
lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST);
NLSR_LOG_DEBUG("nameLsa interest " << interest << " received");
- NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
+ NameLsa* nameLsa = findNameLsa(lsaKey);
if (nameLsa != nullptr) {
NLSR_LOG_TRACE("Verifying SeqNo for NameLsa is same as requested.");
if (nameLsa->getLsSeqNo() == seqNo) {
std::string content = nameLsa->serialize();
m_segmentPublisher.publish(interest.getName(), interest.getName(),
ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
- m_lsaRefreshTime, m_nlsr.getSigningInfo());
+ m_lsaRefreshTime, m_signingInfo);
lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA);
}
@@ -1128,20 +1134,20 @@
const ndn::Name& lsaKey,
uint64_t seqNo)
{
- if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
NLSR_LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled");
}
lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST);
NLSR_LOG_DEBUG("AdjLsa interest " << interest << " received");
- AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
+ AdjLsa* adjLsa = findAdjLsa(lsaKey);
if (adjLsa != nullptr) {
NLSR_LOG_TRACE("Verifying SeqNo for AdjLsa is same as requested.");
if (adjLsa->getLsSeqNo() == seqNo) {
std::string content = adjLsa->serialize();
m_segmentPublisher.publish(interest.getName(), interest.getName(),
ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
- m_lsaRefreshTime, m_nlsr.getSigningInfo());
+ m_lsaRefreshTime, m_signingInfo);
lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA);
}
@@ -1164,20 +1170,20 @@
const ndn::Name& lsaKey,
uint64_t seqNo)
{
- if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
NLSR_LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled");
}
lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST);
NLSR_LOG_DEBUG("CoordinateLsa interest " << interest << " received");
- CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
+ CoordinateLsa* corLsa = findCoordinateLsa(lsaKey);
if (corLsa != nullptr) {
NLSR_LOG_TRACE("Verifying SeqNo for CoordinateLsa is same as requested.");
if (corLsa->getLsSeqNo() == seqNo) {
std::string content = corLsa->serialize();
m_segmentPublisher.publish(interest.getName(), interest.getName(),
ndn::encoding::makeStringBlock(ndn::tlv::Content, content),
- m_lsaRefreshTime, m_nlsr.getSigningInfo());
+ m_lsaRefreshTime, m_signingInfo);
lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA);
}
@@ -1202,7 +1208,7 @@
if (lsaPosition >= 0) {
// Extracts the prefix of the originating router from the data.
- ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
+ ndn::Name originRouter = m_confParam.getNetwork();
originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
uint64_t seqNo = dataName[-1].toNumber();
@@ -1285,7 +1291,7 @@
{
ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
expirationTimePoint = expirationTimePoint +
- ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
+ ndn::time::seconds(m_confParam.getRouterDeadInterval());
return expirationTimePoint;
}
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 183f3dc..0ce9902 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -29,6 +29,7 @@
#include "test-access-control.hpp"
#include "communication/sync-logic-handler.hpp"
#include "statistics.hpp"
+#include "route/name-prefix-table.hpp"
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/signal.hpp>
@@ -42,12 +43,12 @@
namespace nlsr {
-class Nlsr;
-
class Lsdb
{
public:
- Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
+ Lsdb(ndn::Face& face, ndn::KeyChain& keyChain,
+ ndn::security::SigningInfo& signingInfo, ConfParameter& confParam,
+ NamePrefixTable& namePrefixTable, RoutingTable& routingTable);
~Lsdb();
@@ -202,22 +203,10 @@
return m_sequencingManager;
}
- LsaSegmentStorage&
- getLsaStorage()
- {
- return m_lsaStorage;
- }
-
void
writeAdjLsdbLog();
void
- setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime);
-
- void
- setThisRouterPrefix(std::string trp);
-
- void
expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
@@ -230,6 +219,12 @@
void
processInterest(const ndn::Name& name, const ndn::Interest& interest);
+ bool
+ getIsBuildAdjLsaSheduled()
+ {
+ return m_isBuildAdjLsaSheduled;
+ }
+
private:
/* \brief Add a name LSA to the LSDB if it isn't already there.
\param nlsa The candidade name LSA.
@@ -392,13 +387,22 @@
static const ndn::Name::Component NAME_COMPONENT;
ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
+ ndn::util::signal::Signal<Lsdb, const ndn::Data&> afterSegmentValidatedSignal;
private:
- Nlsr& m_nlsr;
- ndn::Scheduler& m_scheduler;
+ ndn::Face& m_face;
+ ndn::Scheduler m_scheduler;
+ ndn::security::SigningInfo& m_signingInfo;
+
+ ConfParameter& m_confParam;
+ NamePrefixTable& m_namePrefixTable;
+ RoutingTable& m_routingTable;
SyncLogicHandler m_sync;
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
LsaSegmentStorage m_lsaStorage;
+private:
std::list<NameLsa> m_nameLsdb;
std::list<AdjLsa> m_adjLsdb;
std::list<CoordinateLsa> m_corLsdb;
@@ -423,6 +427,9 @@
std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
psync::SegmentPublisher m_segmentPublisher;
+
+ bool m_isBuildAdjLsaSheduled;
+ int64_t m_adjBuildCount;
};
} // namespace nlsr
diff --git a/src/main.cpp b/src/main.cpp
index a2b9924..b271298 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,6 +19,7 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
+#include "conf-file-processor.hpp"
#include "nlsr-runner.hpp"
#include "version.hpp"
@@ -82,15 +83,25 @@
}
}
- nlsr::NlsrRunner runner(configFileName);
+ boost::asio::io_service ioService;
+ ndn::Face face(ioService);
+
+ nlsr::ConfParameter confParam(face, configFileName);
+ nlsr::ConfFileProcessor configProcessor(confParam);
+
+ if (!configProcessor.processConfFile()) {
+ std::cerr << "Error in configuration file processing" << std::endl;
+ return 2;
+ }
+
+ confParam.buildRouterPrefix();
+ confParam.writeLog();
+
+ nlsr::NlsrRunner runner(face, confParam);
try {
runner.run();
}
- catch (const nlsr::NlsrRunner::ConfFileError& e) {
- std::cerr << e.what() << std::endl;
- return 2;
- }
catch (const std::exception& e) {
std::cerr << "FATAL: " << getExtendedErrorMessage(e) << std::endl;
return 1;
diff --git a/src/nlsr-runner.cpp b/src/nlsr-runner.cpp
index b5ff594..41c0f8c 100644
--- a/src/nlsr-runner.cpp
+++ b/src/nlsr-runner.cpp
@@ -20,31 +20,23 @@
**/
#include "nlsr-runner.hpp"
-#include "conf-file-processor.hpp"
namespace nlsr {
-NlsrRunner::NlsrRunner(const std::string& configFileName)
- : m_scheduler(m_ioService)
- , m_face(m_ioService)
- , m_nlsr(m_ioService, m_scheduler, m_face, m_keyChain)
+NlsrRunner::NlsrRunner(ndn::Face& face, ConfParameter& confParam)
+ : m_face(face)
+ , m_confParam(confParam)
+ , m_nlsr(m_face, m_keyChain, m_confParam)
{
- m_nlsr.setConfFileName(configFileName);
}
void
NlsrRunner::run()
{
- ConfFileProcessor configProcessor(m_nlsr, m_nlsr.getConfFileName());
-
- if (!configProcessor.processConfFile()) {
- BOOST_THROW_EXCEPTION(ConfFileError("Error in configuration file processing"));
- }
-
m_nlsr.initialize();
try {
- m_nlsr.startEventLoop();
+ m_face.processEvents();
}
catch (...) {
m_nlsr.getFib().clean();
diff --git a/src/nlsr-runner.hpp b/src/nlsr-runner.hpp
index af32e1e..afe653e 100644
--- a/src/nlsr-runner.hpp
+++ b/src/nlsr-runner.hpp
@@ -23,13 +23,11 @@
#define NLSR_NLSR_RUNNER_HPP
#include "nlsr.hpp"
+#include "conf-parameter.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
-// boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ...
-#include <boost/asio/io_service.hpp>
-
namespace nlsr {
/*! \brief A wrapper class to instantiate and configure an NLSR object.
@@ -43,14 +41,8 @@
class NlsrRunner
{
public:
- class ConfFileError : public std::invalid_argument
- {
- public:
- using std::invalid_argument::invalid_argument;
- };
-
explicit
- NlsrRunner(const std::string& configFileName);
+ NlsrRunner(ndn::Face& face, ConfParameter& confParam);
/*! \brief Instantiate, configure, and start the NLSR process.
*
@@ -67,10 +59,9 @@
run();
private:
- boost::asio::io_service m_ioService;
- ndn::Scheduler m_scheduler;
- ndn::Face m_face;
+ ndn::Face& m_face;
ndn::KeyChain m_keyChain;
+ ConfParameter& m_confParam;
Nlsr m_nlsr;
};
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 214e6ec..33855ee 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -39,46 +39,42 @@
const ndn::Name Nlsr::LOCALHOST_PREFIX = ndn::Name("/localhost/nlsr");
-Nlsr::Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain)
- : m_nlsrFace(face)
- , m_scheduler(scheduler)
+Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
+ : m_face(face)
+ , m_scheduler(face.getIoService())
, m_keyChain(keyChain)
- , m_confParam()
- , m_adjacencyList()
- , m_namePrefixList()
- , m_configFileName("nlsr.conf")
- , m_nlsrLsdb(*this, scheduler)
- , m_adjBuildCount(0)
- , m_isBuildAdjLsaSheduled(false)
- , m_isRouteCalculationScheduled(false)
- , m_isRoutingTableCalculating(false)
- , m_routingTable(scheduler)
- , m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
- , m_namePrefixTable(*this, m_routingTable.afterRoutingChange)
- , m_dispatcher(m_nlsrFace, m_keyChain)
- , m_datasetHandler(m_nlsrLsdb,
- m_routingTable,
- m_dispatcher,
- m_nlsrFace,
- m_keyChain)
- , m_helloProtocol(*this, scheduler)
- , m_validator(std::make_unique<ndn::security::v2::CertificateFetcherDirectFetch>(m_nlsrFace))
- , m_controller(m_nlsrFace, m_keyChain)
- , m_faceDatasetController(m_nlsrFace, m_keyChain)
+ , m_confParam(confParam)
+ , m_adjacencyList(confParam.getAdjacencyList())
+ , m_namePrefixList(confParam.getNamePrefixList())
+ , m_validator(m_confParam.getValidator())
+ , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, m_keyChain)
+ , m_routingTable(m_scheduler, m_fib, m_lsdb, m_namePrefixTable, m_confParam)
+ , m_namePrefixTable(m_fib, m_routingTable, m_routingTable.afterRoutingChange)
+ , m_lsdb(m_face, m_keyChain, m_signingInfo,
+ m_confParam, m_namePrefixTable, m_routingTable)
+ , m_afterSegmentValidatedConnection(m_lsdb.afterSegmentValidatedSignal.connect(
+ std::bind(&Nlsr::afterFetcherSignalEmitted, this, _1)))
+ , m_dispatcher(m_face, m_keyChain)
+ , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
+ , m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb)
+ , m_certStore(m_confParam.getCertStore())
+ , m_controller(m_face, m_keyChain)
+ , m_faceDatasetController(m_face, m_keyChain)
, m_prefixUpdateProcessor(m_dispatcher,
- m_nlsrFace,
+ m_confParam.getPrefixUpdateValidator(),
m_namePrefixList,
- m_nlsrLsdb,
- m_configFileName)
+ m_lsdb,
+ m_confParam.getConfFileName())
, m_nfdRibCommandProcessor(m_dispatcher,
m_namePrefixList,
- m_nlsrLsdb)
- , m_statsCollector(m_nlsrLsdb, m_helloProtocol)
- , m_faceMonitor(m_nlsrFace)
- , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
+ m_lsdb)
+ , m_statsCollector(m_lsdb, m_helloProtocol)
+ , m_faceMonitor(m_face)
{
m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
m_faceMonitor.start();
+
+ setStrategies();
}
void
@@ -103,13 +99,11 @@
NLSR_LOG_DEBUG("Setting interest filter for Hello interest: " << name);
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
- 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_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
+ 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
@@ -119,16 +113,13 @@
NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name);
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
- 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_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
+ std::bind(&Lsdb::processInterest, &m_lsdb, _1, _2),
+ std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
}
-
void
Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
{
@@ -147,7 +138,7 @@
const std::string strategy("ndn:/localhost/nfd/strategy/multicast");
m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy, 0);
- m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy, 0);
+ m_fib.setStrategy(m_confParam.getSyncPrefix(), strategy, 0);
}
void
@@ -163,15 +154,6 @@
}
void
-Nlsr::connectToFetcher(ndn::util::SegmentFetcher& fetcher)
-{
- NLSR_LOG_TRACE("NLSR: Connect to SegmentFetcher.");
-
- fetcher.afterSegmentValidated.connect(std::bind(&Nlsr::afterFetcherSignalEmitted,
- this, _1));
-}
-
-void
Nlsr::afterFetcherSignalEmitted(const ndn::Data& lsaSegment)
{
NLSR_LOG_TRACE("SegmentFetcher fetched a data segment. Start inserting cert to own cert store.");
@@ -194,13 +176,11 @@
NLSR_LOG_TRACE(*cert);
ndn::Name certName = ndn::security::v2::extractKeyNameFromCertName(cert->getName());
NLSR_LOG_TRACE("Setting interest filter for: " << certName);
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(certName).allowLoopback(false),
- std::bind(&Nlsr::onKeyInterest,
- this, _1, _2),
- std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1),
- m_signingInfo,
- ndn::nfd::ROUTE_FLAG_CAPTURE);
+ m_face.setInterestFilter(ndn::InterestFilter(certName).allowLoopback(false),
+ std::bind(&Nlsr::onKeyInterest, this, _1, _2),
+ std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
if (!cert->getKeyName().equals(cert->getSignature().getKeyLocator().getName())) {
publishCertFromCache(cert->getSignature().getKeyLocator().getName());
@@ -215,29 +195,17 @@
Nlsr::initialize()
{
NLSR_LOG_DEBUG("Initializing Nlsr");
- m_confParam.buildRouterPrefix();
- m_datasetHandler.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());
-
- m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
- m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
-
- m_nlsrLsdb.getSyncLogicHandler().createSyncLogic(m_confParam.getChronosyncPrefix(),
- m_confParam.getSyncInterestLifetime());
// Logging start
- m_confParam.writeLog();
m_adjacencyList.writeLog();
NLSR_LOG_DEBUG(m_namePrefixList);
- // Logging end
initializeKey();
- setStrategies();
NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
+ // Can be moved to HelloProtocol and Lsdb ctor if initializeKey is set
+ // earlier in the Nlsr constructor so as to set m_signingInfo
setInfoInterestFilter();
setLsaInterestFilter();
@@ -250,23 +218,18 @@
enableIncomingFaceIdIndication();
- // Set event intervals
- setFirstHelloInterval(m_confParam.getFirstHelloInterval());
- m_nlsrLsdb.setAdjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval());
- m_routingTable.setRoutingCalcInterval(m_confParam.getRoutingCalcInterval());
-
- m_nlsrLsdb.buildAndInstallOwnNameLsa();
+ m_lsdb.buildAndInstallOwnNameLsa();
// Install coordinate LSAs if using HR or dry-run HR.
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
+ m_lsdb.buildAndInstallOwnCoordinateLsa();
}
registerKeyPrefix();
registerLocalhostPrefix();
registerRouterPrefix();
- m_helloProtocol.scheduleInterest(m_firstHelloInterval);
+ m_helloProtocol.scheduleInterest(m_confParam.getFirstHelloInterval());
// Need to set direct neighbors' costs to 0 for hyperbolic routing
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
@@ -334,79 +297,69 @@
nlsrInstanceName);
loadCertToPublish(certificate);
-
- m_defaultCertName = certificate.getName();
}
void
Nlsr::registerKeyPrefix()
{
// Start listening for the interest of this router's NLSR certificate
- ndn::Name nlsrKeyPrefix = getConfParameter().getRouterPrefix();
+ ndn::Name nlsrKeyPrefix = m_confParam.getRouterPrefix();
nlsrKeyPrefix.append("nlsr");
nlsrKeyPrefix.append("KEY");
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(nlsrKeyPrefix).allowLoopback(false),
- std::bind(&Nlsr::onKeyInterest,
- this, _1, _2),
- std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1),
- m_signingInfo,
- ndn::nfd::ROUTE_FLAG_CAPTURE);
+ m_face.setInterestFilter(ndn::InterestFilter(nlsrKeyPrefix).allowLoopback(false),
+ std::bind(&Nlsr::onKeyInterest, this, _1, _2),
+ std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
// Start listening for the interest of this router's certificate
- ndn::Name routerKeyPrefix = getConfParameter().getRouterPrefix();
+ ndn::Name routerKeyPrefix = m_confParam.getRouterPrefix();
routerKeyPrefix.append("KEY");
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(routerKeyPrefix).allowLoopback(false),
- std::bind(&Nlsr::onKeyInterest,
- this, _1, _2),
- std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1),
- m_signingInfo,
- ndn::nfd::ROUTE_FLAG_CAPTURE);
+ m_face.setInterestFilter(ndn::InterestFilter(routerKeyPrefix).allowLoopback(false),
+ std::bind(&Nlsr::onKeyInterest, this, _1, _2),
+ std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
// Start listening for the interest of this router's operator's certificate
- ndn::Name operatorKeyPrefix = getConfParameter().getNetwork();
- operatorKeyPrefix.append(getConfParameter().getSiteName());
+ ndn::Name operatorKeyPrefix = m_confParam.getNetwork();
+ operatorKeyPrefix.append(m_confParam.getSiteName());
operatorKeyPrefix.append(std::string("%C1.Operator"));
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(operatorKeyPrefix).allowLoopback(false),
- std::bind(&Nlsr::onKeyInterest,
- this, _1, _2),
- std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1),
- m_signingInfo,
- ndn::nfd::ROUTE_FLAG_CAPTURE);
+ m_face.setInterestFilter(ndn::InterestFilter(operatorKeyPrefix).allowLoopback(false),
+ std::bind(&Nlsr::onKeyInterest, this, _1, _2),
+ std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
// Start listening for the interest of this router's site's certificate
- ndn::Name siteKeyPrefix = getConfParameter().getNetwork();
- siteKeyPrefix.append(getConfParameter().getSiteName());
+ ndn::Name siteKeyPrefix = m_confParam.getNetwork();
+ siteKeyPrefix.append(m_confParam.getSiteName());
siteKeyPrefix.append("KEY");
- m_nlsrFace.setInterestFilter(ndn::InterestFilter(siteKeyPrefix).allowLoopback(false),
- std::bind(&Nlsr::onKeyInterest,
- this, _1, _2),
- std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1),
- m_signingInfo,
- ndn::nfd::ROUTE_FLAG_CAPTURE);
+ m_face.setInterestFilter(ndn::InterestFilter(siteKeyPrefix).allowLoopback(false),
+ std::bind(&Nlsr::onKeyInterest, this, _1, _2),
+ std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1),
+ m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
}
void
Nlsr::registerLocalhostPrefix()
{
- m_nlsrFace.registerPrefix(LOCALHOST_PREFIX,
- std::bind(&Nlsr::onRegistrationSuccess, this, _1),
- std::bind(&Nlsr::registrationFailed, this, _1));
+ m_face.registerPrefix(LOCALHOST_PREFIX,
+ std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1));
}
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));
+ m_face.registerPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"),
+ std::bind(&Nlsr::onRegistrationSuccess, this, _1),
+ std::bind(&Nlsr::registrationFailed, this, _1));
}
void
@@ -422,7 +375,7 @@
return; // cert is not found
}
- m_nlsrFace.put(*cert);
+ m_face.put(*cert);
}
void
@@ -470,10 +423,10 @@
adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- getRoutingTable().scheduleRoutingTableCalculation(*this);
+ m_routingTable.scheduleRoutingTableCalculation();
}
else {
- m_nlsrLsdb.scheduleAdjLsaBuild();
+ m_lsdb.scheduleAdjLsaBuild();
}
}
}
@@ -502,10 +455,10 @@
registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- getRoutingTable().scheduleRoutingTableCalculation(*this);
+ m_routingTable.scheduleRoutingTableCalculation();
}
else {
- m_nlsrLsdb.scheduleAdjLsaBuild();
+ m_lsdb.scheduleAdjLsaBuild();
}
}
break;
@@ -570,7 +523,7 @@
m_fib.registerPrefix(adjName, faceUri, linkCost,
timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
- m_fib.registerPrefix(m_confParam.getChronosyncPrefix(),
+ m_fib.registerPrefix(m_confParam.getSyncPrefix(),
faceUri, linkCost, timeout,
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
@@ -649,10 +602,4 @@
NLSR_LOG_DEBUG(os.str());
}
-void
-Nlsr::startEventLoop()
-{
- m_nlsrFace.processEvents();
-}
-
} // namespace nlsr
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 4614ccb..c0d6bc4 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -80,7 +80,7 @@
}
};
- Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain);
+ Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
void
registrationFailed(const ndn::Name& name);
@@ -102,147 +102,12 @@
void
addDispatcherTopPrefix(const ndn::Name& topPrefix);
- void
- startEventLoop();
-
- std::string
- getConfFileName() const
- {
- return m_configFileName;
- }
-
- void
- setConfFileName(const std::string& fileName)
- {
- m_configFileName = fileName;
- }
-
- ConfParameter&
- getConfParameter()
- {
- return m_confParam;
- }
-
- const ConfParameter&
- getConfParameter() const
- {
- return m_confParam;
- }
-
- AdjacencyList&
- getAdjacencyList()
- {
- return m_adjacencyList;
- }
-
- const AdjacencyList&
- getAdjacencyList() const
- {
- return m_adjacencyList;
- }
-
- NamePrefixList&
- getNamePrefixList()
- {
- return m_namePrefixList;
- }
-
- const NamePrefixList&
- getNamePrefixList() const
- {
- return m_namePrefixList;
- }
-
- ndn::Face&
- getNlsrFace()
- {
- return m_nlsrFace;
- }
-
- Lsdb&
- getLsdb()
- {
- return m_nlsrLsdb;
- }
-
- RoutingTable&
- getRoutingTable()
- {
- return m_routingTable;
- }
-
- NamePrefixTable&
- getNamePrefixTable()
- {
- return m_namePrefixTable;
- }
-
Fib&
getFib()
{
return m_fib;
}
- long int
- getAdjBuildCount()
- {
- return m_adjBuildCount;
- }
-
- void
- incrementAdjBuildCount()
- {
- m_adjBuildCount++;
- }
-
- void
- setAdjBuildCount(int64_t abc)
- {
- m_adjBuildCount = abc;
- }
-
- bool
- getIsBuildAdjLsaSheduled()
- {
- return m_isBuildAdjLsaSheduled;
- }
-
- void
- setIsBuildAdjLsaSheduled(bool iabls)
- {
- m_isBuildAdjLsaSheduled = iabls;
- }
-
- bool
- getIsRoutingTableCalculating()
- {
- return m_isRoutingTableCalculating;
- }
-
- void
- setIsRoutingTableCalculating(bool irtc)
- {
- m_isRoutingTableCalculating = irtc;
- }
-
- bool
- getIsRouteCalculationScheduled()
- {
- return m_isRouteCalculationScheduled;
- }
-
- void
- setIsRouteCalculationScheduled(bool ircs)
- {
- m_isRouteCalculationScheduled = ircs;
- }
-
- DatasetInterestHandler&
- getDatasetHandler()
- {
- return m_datasetHandler;
- }
-
void
initialize();
@@ -298,9 +163,6 @@
void
loadCertToPublish(const ndn::security::v2::Certificate& certificate);
- void
- connectToFetcher(ndn::util::SegmentFetcher& fetcher);
-
/*! \brief Callback when SegmentFetcher retrieves a segment.
*/
void
@@ -316,19 +178,6 @@
void
initializeKey();
- void
- loadValidator(boost::property_tree::ptree section,
- const std::string& filename)
- {
- m_validator.load(section, filename);
- }
-
- ndn::security::ValidatorConfig&
- getValidator()
- {
- return m_validator;
- }
-
/*! \brief Find a certificate
*
* Find a certificate that NLSR has. First it checks against the
@@ -346,57 +195,9 @@
return cert;
}
- ndn::security::v2::KeyChain&
- getKeyChain()
- {
- return m_keyChain;
- }
-
- const ndn::Name&
- getDefaultCertName()
- {
- return m_defaultCertName;
- }
-
- const ndn::security::SigningInfo&
- getSigningInfo()
- {
- return m_signingInfo;
- }
-
- update::PrefixUpdateProcessor&
- getPrefixUpdateProcessor()
- {
- return m_prefixUpdateProcessor;
- }
-
- update::NfdRibCommandProcessor&
- getNfdRibCommandProcessor()
- {
- return m_nfdRibCommandProcessor;
- }
-
- ndn::mgmt::Dispatcher&
- getDispatcher()
- {
- return m_dispatcher;
- }
-
void
setStrategies();
- uint32_t
- getFirstHelloInterval() const
- {
- return m_firstHelloInterval;
- }
-
- StatsCollector&
- getStatsCollector()
- {
- return m_statsCollector;
- }
-
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
security::CertificateStore&
@@ -437,12 +238,6 @@
onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
void
- setFirstHelloInterval(uint32_t interval)
- {
- m_firstHelloInterval = interval;
- }
-
- void
scheduleDatasetFetch();
/*! \brief Enables NextHopFaceId indication in NFD for incoming data packet.
@@ -465,49 +260,48 @@
static const ndn::Name LOCALHOST_PREFIX;
private:
- ndn::Face& m_nlsrFace;
- ndn::Scheduler& m_scheduler;
+ ndn::Face& m_face;
+ ndn::Scheduler m_scheduler;
ndn::security::v2::KeyChain& m_keyChain;
- ConfParameter m_confParam;
- AdjacencyList m_adjacencyList;
- NamePrefixList m_namePrefixList;
- std::string m_configFileName;
- Lsdb m_nlsrLsdb;
- int64_t m_adjBuildCount;
- bool m_isBuildAdjLsaSheduled;
- bool m_isRouteCalculationScheduled;
- bool m_isRoutingTableCalculating;
- RoutingTable m_routingTable;
- Fib m_fib;
- NamePrefixTable m_namePrefixTable;
-
- ndn::mgmt::Dispatcher m_dispatcher;
-
- DatasetInterestHandler m_datasetHandler;
+ ConfParameter& m_confParam;
+ AdjacencyList& m_adjacencyList;
+ NamePrefixList& m_namePrefixList;
+ bool m_isDaemonProcess;
+ ndn::security::ValidatorConfig& m_validator;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- HelloProtocol m_helloProtocol;
+ Fib m_fib;
+ RoutingTable m_routingTable;
+ NamePrefixTable m_namePrefixTable;
+ Lsdb m_lsdb;
- ndn::security::ValidatorConfig m_validator;
+private:
+ ndn::util::signal::ScopedConnection m_afterSegmentValidatedConnection;
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ ndn::mgmt::Dispatcher m_dispatcher;
+ DatasetInterestHandler m_datasetHandler;
+ HelloProtocol m_helloProtocol;
private:
/*! \brief Where NLSR stores certificates it claims to be
* authoritative for. Usually the router certificate.
*/
- security::CertificateStore m_certStore;
+ security::CertificateStore& m_certStore;
ndn::nfd::Controller m_controller;
ndn::nfd::Controller m_faceDatasetController;
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
ndn::security::SigningInfo m_signingInfo;
- ndn::Name m_defaultCertName;
update::PrefixUpdateProcessor m_prefixUpdateProcessor;
update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
+
StatsCollector m_statsCollector;
+private:
ndn::nfd::FaceMonitor m_faceMonitor;
- uint32_t m_firstHelloInterval;
-
friend class NlsrRunner;
};
diff --git a/src/publisher/dataset-interest-handler.cpp b/src/publisher/dataset-interest-handler.cpp
index 6e2e7d1..6fe9d4f 100644
--- a/src/publisher/dataset-interest-handler.cpp
+++ b/src/publisher/dataset-interest-handler.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,
* Arizona Board of Regents.
*
@@ -36,13 +36,11 @@
const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names");
const ndn::PartialName RT_DATASET = ndn::PartialName("routing-table");
-DatasetInterestHandler::DatasetInterestHandler(const Lsdb& lsdb,
- const RoutingTable& rt,
- ndn::mgmt::Dispatcher& dispatcher,
- const ndn::Face& face,
- const ndn::KeyChain& keyChain)
- : m_lsdb(lsdb)
- , m_dispatcher(dispatcher)
+DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher,
+ const Lsdb& lsdb,
+ const RoutingTable& rt)
+ : m_dispatcher(dispatcher)
+ , m_lsdb(lsdb)
, m_routingTableEntries(rt.getRoutingTableEntry())
, m_dryRoutingTableEntries(rt.getDryRoutingTableEntry())
{
diff --git a/src/publisher/dataset-interest-handler.hpp b/src/publisher/dataset-interest-handler.hpp
index 6e5169d..2822ae5 100644
--- a/src/publisher/dataset-interest-handler.hpp
+++ b/src/publisher/dataset-interest-handler.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -72,23 +72,9 @@
}
};
- DatasetInterestHandler(const Lsdb& lsdb,
- const RoutingTable& rt,
- ndn::mgmt::Dispatcher& dispatcher,
- const ndn::Face& face,
- const ndn::KeyChain& keyChain);
-
- ndn::Name&
- getRouterNameCommandPrefix()
- {
- return m_routerNamePrefix;
- }
-
- void
- setRouterNameCommandPrefix(const ndn::Name& routerName) {
- m_routerNamePrefix = routerName;
- m_routerNamePrefix.append(Lsdb::NAME_COMPONENT);
- }
+ DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher,
+ const Lsdb& lsdb,
+ const RoutingTable& rt);
private:
/*! \brief set dispatcher for localhost or remote router
@@ -126,10 +112,8 @@
ndn::mgmt::StatusDatasetContext& context);
private:
- const Lsdb& m_lsdb;
- ndn::Name m_routerNamePrefix;
-
ndn::mgmt::Dispatcher& m_dispatcher;
+ const Lsdb& m_lsdb;
const std::list<RoutingTableEntry>& m_routingTableEntries;
const std::list<RoutingTableEntry>& m_dryRoutingTableEntries;
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index a38d33b..1da774b 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.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).
@@ -38,7 +38,7 @@
Fib::Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList,
ConfParameter& conf, ndn::security::v2::KeyChain& keyChain)
: m_scheduler(scheduler)
- , m_refreshTime(0)
+ , m_refreshTime(2 * conf.getLsaRefreshTime())
, m_controller(face, keyChain)
, m_adjacencyList(adjacencyList)
, m_confParameter(conf)
diff --git a/src/route/map.hpp b/src/route/map.hpp
index 01801be..b4aa396 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -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).
@@ -54,8 +54,6 @@
} // namespace detail
-class Nlsr;
-
class Map
{
public:
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index 1c05c2c..65e935c 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.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,
* Arizona Board of Regents.
*
@@ -33,9 +33,10 @@
INIT_LOGGER(route.NamePrefixTable);
-NamePrefixTable::NamePrefixTable(Nlsr& nlsr,
+NamePrefixTable::NamePrefixTable(Fib& fib, RoutingTable& routingTable,
std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal)
- : m_nlsr(nlsr)
+ : m_fib(fib)
+ , m_routingTable(routingTable)
{
m_afterRoutingChangeConnection = afterRoutingChangeSignal->connect(
[this] (const std::list<RoutingTableEntry>& entries) {
@@ -70,8 +71,7 @@
// There isn't currently a routing table entry in the pool for this name
if (rtpeItr == m_rtpool.end()) {
// See if there is a routing table entry available we could use
- RoutingTableEntry* routeEntryPtr = m_nlsr.getRoutingTable()
- .findRoutingTableEntry(destRouter);
+ RoutingTableEntry* routeEntryPtr = m_routingTable.findRoutingTableEntry(destRouter);
// We have to create a new routing table entry
if (routeEntryPtr == nullptr) {
@@ -102,7 +102,7 @@
// If this entry has next hops, we need to inform the FIB
if (npte->getNexthopList().size() > 0) {
NLSR_LOG_TRACE("Updating FIB with next hops for " << npte->getNamePrefix());
- m_nlsr.getFib().update(name, npte->getNexthopList());
+ m_fib.update(name, npte->getNexthopList());
}
// The routing table may recalculate and add a routing table entry
// with no next hops to replace an existing routing table entry. In
@@ -112,7 +112,7 @@
// calculation may add next hops.
else {
NLSR_LOG_TRACE(npte->getNamePrefix() << " has no next hops; removing from FIB");
- m_nlsr.getFib().remove(name);
+ m_fib.remove(name);
}
}
else {
@@ -124,11 +124,11 @@
if ((*nameItr)->getNexthopList().size() > 0) {
NLSR_LOG_TRACE("Updating FIB with next hops for " << (**nameItr));
- m_nlsr.getFib().update(name, (*nameItr)->getNexthopList());
+ m_fib.update(name, (*nameItr)->getNexthopList());
}
else {
NLSR_LOG_TRACE(npte->getNamePrefix() << " has no next hops; removing from FIB");
- m_nlsr.getFib().remove(name);
+ m_fib.remove(name);
}
}
// Add the reference to this NPT to the RTPE.
@@ -189,13 +189,13 @@
NLSR_LOG_TRACE(**nameItr << " has no routing table entries;"
<< " removing from table and FIB");
m_table.erase(nameItr);
- m_nlsr.getFib().remove(name);
+ m_fib.remove(name);
}
else {
NLSR_LOG_TRACE(**nameItr << " has other routing table entries;"
<< " updating FIB with next hops");
(*nameItr)->generateNhlfromRteList();
- m_nlsr.getFib().update(name, (*nameItr)->getNexthopList());
+ m_fib.update(name, (*nameItr)->getNexthopList());
}
}
else {
diff --git a/src/route/name-prefix-table.hpp b/src/route/name-prefix-table.hpp
index aa55c9e..8349453 100644
--- a/src/route/name-prefix-table.hpp
+++ b/src/route/name-prefix-table.hpp
@@ -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,
* Arizona Board of Regents.
*
@@ -26,12 +26,12 @@
#include "routing-table-pool-entry.hpp"
#include "signals.hpp"
#include "test-access-control.hpp"
+#include "route/fib.hpp"
#include <list>
#include <unordered_map>
namespace nlsr {
-class Nlsr;
class NamePrefixTable
{
@@ -41,7 +41,8 @@
using NptEntryList = std::list<std::shared_ptr<NamePrefixTableEntry>>;
using const_iterator = NptEntryList::const_iterator;
- NamePrefixTable(Nlsr& nlsr, std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal);
+ NamePrefixTable(Fib& fib, RoutingTable& routingTable,
+ std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal);
~NamePrefixTable();
@@ -124,7 +125,8 @@
NptEntryList m_table;
private:
- Nlsr& m_nlsr;
+ Fib& m_fib;
+ RoutingTable& m_routingTable;
ndn::util::signal::Connection m_afterRoutingChangeConnection;
};
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 492c39b..68a7ca2 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -22,7 +22,6 @@
#include "routing-table-calculator.hpp"
#include "lsdb.hpp"
#include "map.hpp"
-#include "lsa.hpp"
#include "nexthop.hpp"
#include "nlsr.hpp"
#include "logger.hpp"
@@ -57,21 +56,17 @@
}
void
-RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map& pMap)
+RoutingTableCalculator::makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap)
{
- std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
// For each LSA represented in the map
- for (std::list<AdjLsa>::iterator it = adjLsdb.begin(); it != adjLsdb.end() ; it++) {
+ for (const auto& adjLsa : adjLsaList) {
+ ndn::optional<int32_t> row = pMap.getMappingNoByRouterName(adjLsa.getOrigRouter());
-
- ndn::optional<int32_t> row = pMap.getMappingNoByRouterName((*it).getOrigRouter());
-
- std::list<Adjacent> adl = (*it).getAdl().getAdjList();
+ std::list<Adjacent> adl = adjLsa.getAdl().getAdjList();
// For each adjacency represented in the LSA
- for (std::list<Adjacent>::iterator itAdl = adl.begin(); itAdl != adl.end() ; itAdl++) {
-
- ndn::optional<int32_t> col = pMap.getMappingNoByRouterName((*itAdl).getName());
- double cost = (*itAdl).getLinkCost();
+ for (const auto& adjacent : adl) {
+ ndn::optional<int32_t> col = pMap.getMappingNoByRouterName(adjacent.getName());
+ double cost = adjacent.getLinkCost();
if (row && col && *row < static_cast<int32_t>(m_nRouters)
&& *col < static_cast<int32_t>(m_nRouters))
@@ -224,24 +219,25 @@
}
void
-LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
- RoutingTable& rt, Nlsr& pnlsr)
+LinkStateRoutingTableCalculator::calculatePath(Map& pMap, RoutingTable& rt,
+ ConfParameter& confParam,
+ const std::list<AdjLsa>& adjLsaList)
{
NLSR_LOG_DEBUG("LinkStateRoutingTableCalculator::calculatePath Called");
allocateAdjMatrix();
initMatrix();
- makeAdjMatrix(pnlsr, pMap);
+ makeAdjMatrix(adjLsaList, pMap);
writeAdjMatrixLog(pMap);
ndn::optional<int32_t> sourceRouter =
- pMap.getMappingNoByRouterName(pnlsr.getConfParameter().getRouterPrefix());
+ pMap.getMappingNoByRouterName(confParam.getRouterPrefix());
allocateParent(); // These two matrices are used in Dijkstra's algorithm.
allocateDistance(); //
// We only bother to do the calculation if we have a router by that name.
- if (sourceRouter && pnlsr.getConfParameter().getMaxFacesPerPrefix() == 1) {
+ if (sourceRouter && confParam.getMaxFacesPerPrefix() == 1) {
// In the single path case we can simply run Dijkstra's algorithm.
doDijkstraPathCalculation(*sourceRouter);
// Inform the routing table of the new next hops.
- addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, *sourceRouter);
+ addAllLsNextHopsToRoutingTable(confParam.getAdjacencyList(), rt, pMap, *sourceRouter);
}
else {
// Multi Path
@@ -257,7 +253,7 @@
// Do Dijkstra's algorithm using the current neighbor as your start.
doDijkstraPathCalculation(*sourceRouter);
// Update the routing table with the calculations.
- addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, *sourceRouter);
+ addAllLsNextHopsToRoutingTable(confParam.getAdjacencyList(), rt, pMap, *sourceRouter);
}
freeLinks();
freeLinksCosts();
@@ -318,8 +314,9 @@
}
void
-LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
- Map& pMap, uint32_t sourceRouter)
+LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies,
+ RoutingTable& rt, Map& pMap,
+ uint32_t sourceRouter)
{
NLSR_LOG_DEBUG("LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called");
@@ -341,7 +338,7 @@
ndn::optional<ndn::Name> nextHopRouterName= pMap.getRouterNameByMappingNo(nextHopRouter);
if (nextHopRouterName) {
std::string nextHopFace =
- pnlsr.getAdjacencyList().getAdjacent(*nextHopRouterName).getFaceUri().toString();
+ adjacencies.getAdjacent(*nextHopRouterName).getFaceUri().toString();
// Add next hop to routing table
NextHop nh(nextHopFace, routeCost);
rt.addNextHop(*(pMap.getRouterNameByMappingNo(i)), nh);
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index 0812aad..dd1e658 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -23,6 +23,8 @@
#define NLSR_ROUTING_TABLE_CALCULATOR_HPP
#include "common.hpp"
+#include "lsa.hpp"
+#include "conf-parameter.hpp"
#include <list>
#include <iostream>
@@ -34,7 +36,6 @@
class Map;
class RoutingTable;
-class Nlsr;
class RoutingTableCalculator
{
@@ -56,12 +57,11 @@
initMatrix();
/*! \brief Constructs an adj. matrix to calculate with.
- \param pnlsr The NLSR object that contains the LSAs that we need to iterate
- over.
+ \param adjLsaList The Adjacency Lsa list.
\param pMap The map to populate with the adj. data.
*/
void
- makeAdjMatrix(Nlsr& pnlsr, Map& pMap);
+ makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap);
void
writeAdjMatrixLog(const Map& map) const;
@@ -137,7 +137,8 @@
}
void
- calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
+ calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
+ const std::list<AdjLsa>& adjLsaList);
private:
/*! \brief Performs a Dijkstra's calculation over the adjacency matrix.
@@ -168,7 +169,7 @@
isNotExplored(int* Q, int u, int start, int element);
void
- addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
+ addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
Map& pMap, uint32_t sourceRouter);
/*! \brief Determines a destination's next hop.
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 48ef422..4e2fa86 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -35,39 +35,44 @@
INIT_LOGGER(route.RoutingTable);
-RoutingTable::RoutingTable(ndn::Scheduler& scheduler)
+RoutingTable::RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
+ NamePrefixTable& namePrefixTable, ConfParameter& confParam)
: afterRoutingChange{std::make_unique<AfterRoutingChange>()}
, m_scheduler(scheduler)
+ , m_fib(fib)
+ , m_lsdb(lsdb)
+ , m_namePrefixTable(namePrefixTable)
, m_NO_NEXT_HOP{-12345}
- , m_routingCalcInterval{static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)}
+ , m_routingCalcInterval{confParam.getRoutingCalcInterval()}
+ , m_isRoutingTableCalculating(false)
+ , m_isRouteCalculationScheduled(false)
+ , m_confParam(confParam)
{
}
void
-RoutingTable::calculate(Nlsr& pnlsr)
+RoutingTable::calculate()
{
- pnlsr.getLsdb().writeCorLsdbLog();
- pnlsr.getLsdb().writeNameLsdbLog();
- pnlsr.getLsdb().writeAdjLsdbLog();
- pnlsr.getNamePrefixTable().writeLog();
- if (pnlsr.getIsRoutingTableCalculating() == false) {
- //setting routing table calculation
- pnlsr.setIsRoutingTableCalculating(true);
+ m_lsdb.writeCorLsdbLog();
+ m_lsdb.writeNameLsdbLog();
+ m_lsdb.writeAdjLsdbLog();
+ m_namePrefixTable.writeLog();
+ if (m_isRoutingTableCalculating == false) {
+ // setting routing table calculation
+ m_isRoutingTableCalculating = true;
- bool isHrEnabled = pnlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF;
+ bool isHrEnabled = m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF;
- if ((!isHrEnabled
- &&
- pnlsr.getLsdb()
- .doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()}
+ if ((!isHrEnabled &&
+ m_lsdb
+ .doesLsaExist(ndn::Name{m_confParam.getRouterPrefix()}
.append(std::to_string(Lsa::Type::ADJACENCY)), Lsa::Type::ADJACENCY))
||
- (isHrEnabled
- &&
- pnlsr.getLsdb()
- .doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()}
+ (isHrEnabled &&
+ m_lsdb
+ .doesLsaExist(ndn::Name{m_confParam.getRouterPrefix()}
.append(std::to_string(Lsa::Type::COORDINATE)), Lsa::Type::COORDINATE))) {
- if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
+ if (m_lsdb.getIsBuildAdjLsaSheduled() != 1) {
NLSR_LOG_TRACE("Clearing old routing table");
clearRoutingTable();
// for dry run options
@@ -76,24 +81,24 @@
NLSR_LOG_DEBUG("Calculating routing table");
// calculate Link State routing
- if ((pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF)
- || (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
- calculateLsRoutingTable(pnlsr);
+ if ((m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF)
+ || (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
+ calculateLsRoutingTable();
}
- // calculate hyperbolic
- if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
- calculateHypRoutingTable(pnlsr, false);
+ // calculate hyperbolic routing
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+ calculateHypRoutingTable(false);
}
- //calculate dry hyperbolic routing
- if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
- calculateHypRoutingTable(pnlsr, true);
+ // calculate dry hyperbolic routing
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
+ calculateHypRoutingTable(true);
}
// Inform the NPT that updates have been made
NLSR_LOG_DEBUG("Calling Update NPT With new Route");
(*afterRoutingChange)(m_rTable);
- writeLog(pnlsr.getConfParameter().getHyperbolicState());
- pnlsr.getNamePrefixTable().writeLog();
- pnlsr.getFib().writeLog();
+ writeLog();
+ m_namePrefixTable.writeLog();
+ m_fib.writeLog();
}
else {
NLSR_LOG_DEBUG("Adjacency building is scheduled, so"
@@ -108,61 +113,60 @@
// need to update NPT here
NLSR_LOG_DEBUG("Calling Update NPT With new Route");
(*afterRoutingChange)(m_rTable);
- writeLog(pnlsr.getConfParameter().getHyperbolicState());
- pnlsr.getNamePrefixTable().writeLog();
- pnlsr.getFib().writeLog();
- //debugging purpose end
+ writeLog();
+ m_namePrefixTable.writeLog();
+ m_fib.writeLog();
+ // debugging purpose end
}
- pnlsr.setIsRouteCalculationScheduled(false); //clear scheduled flag
- pnlsr.setIsRoutingTableCalculating(false); //unsetting routing table calculation
+ m_isRouteCalculationScheduled = false; // clear scheduled flag
+ m_isRoutingTableCalculating = false; // unsetting routing table calculation
}
else {
- scheduleRoutingTableCalculation(pnlsr);
+ scheduleRoutingTableCalculation();
}
}
void
-RoutingTable::calculateLsRoutingTable(Nlsr& nlsr)
+RoutingTable::calculateLsRoutingTable()
{
NLSR_LOG_DEBUG("RoutingTable::calculateLsRoutingTable Called");
Map map;
- map.createFromAdjLsdb(nlsr.getLsdb().getAdjLsdb().begin(), nlsr.getLsdb().getAdjLsdb().end());
+ map.createFromAdjLsdb(m_lsdb.getAdjLsdb().begin(), m_lsdb.getAdjLsdb().end());
map.writeLog();
size_t nRouters = map.getMapSize();
LinkStateRoutingTableCalculator calculator(nRouters);
- calculator.calculatePath(map, *this, nlsr);
+ calculator.calculatePath(map, *this, m_confParam, m_lsdb.getAdjLsdb());
}
void
-RoutingTable::calculateHypRoutingTable(Nlsr& nlsr, bool isDryRun)
+RoutingTable::calculateHypRoutingTable(bool isDryRun)
{
Map map;
- map.createFromCoordinateLsdb(nlsr.getLsdb().getCoordinateLsdb().begin(),
- nlsr.getLsdb().getCoordinateLsdb().end());
+ map.createFromCoordinateLsdb(m_lsdb.getCoordinateLsdb().begin(),
+ m_lsdb.getCoordinateLsdb().end());
map.writeLog();
size_t nRouters = map.getMapSize();
- HyperbolicRoutingCalculator calculator(nRouters, isDryRun,
- nlsr.getConfParameter().getRouterPrefix());
+ HyperbolicRoutingCalculator calculator(nRouters, isDryRun, m_confParam.getRouterPrefix());
- calculator.calculatePath(map, *this, nlsr.getLsdb(), nlsr.getAdjacencyList());
+ calculator.calculatePath(map, *this, m_lsdb, m_confParam.getAdjacencyList());
}
void
-RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
+RoutingTable::scheduleRoutingTableCalculation()
{
- if (pnlsr.getIsRouteCalculationScheduled() != true) {
+ if (m_isRouteCalculationScheduled != true) {
NLSR_LOG_DEBUG("Scheduling routing table calculation in " << m_routingCalcInterval);
m_scheduler.scheduleEvent(m_routingCalcInterval,
- std::bind(&RoutingTable::calculate, this, std::ref(pnlsr)));
+ std::bind(&RoutingTable::calculate, this));
- pnlsr.setIsRouteCalculationScheduled(true);
+ m_isRouteCalculationScheduled = true;
}
}
@@ -202,23 +206,21 @@
}
void
-RoutingTable::writeLog(int hyperbolicState)
+RoutingTable::writeLog()
{
NLSR_LOG_DEBUG("---------------Routing Table------------------");
- for (std::list<RoutingTableEntry>::iterator it = m_rTable.begin() ;
- it != m_rTable.end(); ++it) {
- NLSR_LOG_DEBUG("Destination: " << (*it).getDestination());
+ for (const auto& rte : m_rTable) {
+ NLSR_LOG_DEBUG("Destination: " << rte.getDestination());
NLSR_LOG_DEBUG("Nexthops: ");
- (*it).getNexthopList().writeLog();
+ rte.getNexthopList().writeLog();
}
- if (hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
NLSR_LOG_DEBUG("--------Hyperbolic Routing Table(Dry)---------");
- for (std::list<RoutingTableEntry>::iterator it = m_dryTable.begin() ;
- it != m_dryTable.end(); ++it) {
- NLSR_LOG_DEBUG("Destination: " << (*it).getDestination());
+ for (const auto& rte : m_dryTable) {
+ NLSR_LOG_DEBUG("Destination: " << rte.getDestination());
NLSR_LOG_DEBUG("Nexthops: ");
- (*it).getNexthopList().writeLog();
+ rte.getNexthopList().writeLog();
}
}
}
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index 5572aed..f43ad11 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -25,6 +25,8 @@
#include "conf-parameter.hpp"
#include "routing-table-entry.hpp"
#include "signals.hpp"
+#include "lsdb.hpp"
+#include "route/fib.hpp"
#include <iostream>
#include <utility>
@@ -34,22 +36,21 @@
namespace nlsr {
-class Nlsr;
class NextHop;
class RoutingTable : boost::noncopyable
{
public:
explicit
- RoutingTable(ndn::Scheduler& scheduler);
+ RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
+ NamePrefixTable& namePrefixTable, ConfParameter& confParam);
/*! \brief Calculates a list of next hops for each router in the network.
- * \param nlsr The NLSR object that contains the LSAs needed for adj. info.
*
* Calculates the list of next hops to every other router in the network.
*/
void
- calculate(Nlsr& nlsr);
+ calculate();
/*! \brief Adds a next hop to a routing table entry.
* \param destRouter The destination router whose RTE we want to modify.
@@ -70,10 +71,9 @@
/*! \brief Schedules a calculation event in the event scheduler only
* if one isn't already scheduled.
- * \param pnlsr The NLSR whose scheduling status is needed.
*/
void
- scheduleRoutingTableCalculation(Nlsr& pnlsr);
+ scheduleRoutingTableCalculation();
int
getNoNextHop()
@@ -114,11 +114,11 @@
private:
/*! \brief Calculates a link-state routing table. */
void
- calculateLsRoutingTable(Nlsr& pnlsr);
+ calculateLsRoutingTable();
/*! \brief Calculates a HR routing table. */
void
- calculateHypRoutingTable(Nlsr& pnlsr, bool isDryRun);
+ calculateHypRoutingTable(bool isDryRun);
void
clearRoutingTable();
@@ -127,7 +127,7 @@
clearDryRoutingTable();
void
- writeLog(int hyperbolicState);
+ writeLog();
public:
std::unique_ptr<AfterRoutingChange> afterRoutingChange;
@@ -137,12 +137,20 @@
private:
ndn::Scheduler& m_scheduler;
+ Fib& m_fib;
+ Lsdb& m_lsdb;
+ NamePrefixTable& m_namePrefixTable;
const int m_NO_NEXT_HOP;
std::list<RoutingTableEntry> m_dryTable;
ndn::time::seconds m_routingCalcInterval;
+
+ bool m_isRoutingTableCalculating;
+ bool m_isRouteCalculationScheduled;
+
+ ConfParameter& m_confParam;
};
} // namespace nlsr
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index ac2bb54..9f52b71 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.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,
* Arizona Board of Regents.
*
@@ -34,6 +34,16 @@
INIT_LOGGER(SequencingManager);
+SequencingManager::SequencingManager(std::string filePath, int hypState)
+ : m_nameLsaSeq(0)
+ , m_adjLsaSeq(0)
+ , m_corLsaSeq(0)
+ , m_hyperbolicState(hypState)
+{
+ setSeqFileDirectory(filePath);
+ initiateSeqNoFromFile();
+}
+
void
SequencingManager::writeSeqNoToFile() const
{
@@ -48,7 +58,7 @@
}
void
-SequencingManager::initiateSeqNoFromFile(int hypState)
+SequencingManager::initiateSeqNoFromFile()
{
NLSR_LOG_DEBUG("Seq File Name: " << m_seqFileNameWithPath);
std::ifstream inputFile(m_seqFileNameWithPath.c_str());
@@ -87,7 +97,7 @@
m_nameLsaSeq += 10;
// Increment the adjacency LSA seq. no. if link-state or dry HR is enabled
- if (hypState != HYPERBOLIC_STATE_ON) {
+ if (m_hyperbolicState != HYPERBOLIC_STATE_ON) {
if (m_corLsaSeq != 0) {
NLSR_LOG_WARN("This router was previously configured for hyperbolic"
<< " routing without clearing the seq. no. file.");
@@ -97,7 +107,7 @@
}
// Similarly, increment the coordinate LSA seq. no only if link-state is disabled.
- if (hypState != HYPERBOLIC_STATE_OFF) {
+ if (m_hyperbolicState != HYPERBOLIC_STATE_OFF) {
if (m_adjLsaSeq != 0) {
NLSR_LOG_WARN("This router was previously configured for link-state"
<< " routing without clearing the seq. no. file.");
@@ -110,7 +120,7 @@
}
void
-SequencingManager::setSeqFileDirectory(std::string filePath)
+SequencingManager::setSeqFileDirectory(const std::string& filePath)
{
m_seqFileNameWithPath = filePath;
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index 188cea6..85e323b 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -22,26 +22,21 @@
#ifndef NLSR_SEQUENCING_MANAGER_HPP
#define NLSR_SEQUENCING_MANAGER_HPP
-#include <list>
-#include <string>
-#include <boost/cstdint.hpp>
+#include "conf-parameter.hpp"
+#include "test-access-control.hpp"
#include <ndn-cxx/face.hpp>
-#include "conf-parameter.hpp"
+#include <list>
+#include <string>
+#include <boost/cstdint.hpp>
namespace nlsr {
class SequencingManager
{
public:
- SequencingManager()
- : m_nameLsaSeq(0)
- , m_adjLsaSeq(0)
- , m_corLsaSeq(0)
- , m_seqFileNameWithPath()
- {
- }
+ SequencingManager(std::string filePath, int hypState);
uint64_t
getNameLsaSeq() const
@@ -100,9 +95,11 @@
void
writeSeqNoToFile() const;
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
void
- initiateSeqNoFromFile(int hypState);
+ initiateSeqNoFromFile();
+private:
/*! \brief Set the sequence file directory
If the string is empty, home directory is set as sequence file directory
@@ -110,7 +107,7 @@
\param filePath The directory where sequence file will be stored
*/
void
- setSeqFileDirectory(std::string filePath);
+ setSeqFileDirectory(const std::string& filePath);
void
writeLog() const;
@@ -120,6 +117,9 @@
uint64_t m_adjLsaSeq;
uint64_t m_corLsaSeq;
std::string m_seqFileNameWithPath;
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ int m_hyperbolicState;
};
} // namespace nlsr
diff --git a/src/update/manager-base.cpp b/src/update/manager-base.cpp
index f8ab6d1..ccd00e1 100644
--- a/src/update/manager-base.cpp
+++ b/src/update/manager-base.cpp
@@ -64,7 +64,7 @@
NLSR_LOG_INFO("Advertising name: " << castParams.getName() << "\n");
m_lsdb.buildAndInstallOwnNameLsa();
if (castParams.hasFlags() && castParams.getFlags() == PREFIX_FLAG) {
- NLSR_LOG_INFO("Saving name to the configuration file");
+ NLSR_LOG_INFO("Saving name to the configuration file ");
if (afterAdvertise(castParams.getName()) == true) {
return done(ndn::nfd::ControlResponse(205, "OK").setBody(parameters.wireEncode()));
}
diff --git a/src/update/prefix-update-processor.cpp b/src/update/prefix-update-processor.cpp
index 3573ef0..6222198 100644
--- a/src/update/prefix-update-processor.cpp
+++ b/src/update/prefix-update-processor.cpp
@@ -51,11 +51,11 @@
}
PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
- ndn::Face& face,
+ ndn::security::ValidatorConfig& validator,
NamePrefixList& namePrefixList,
Lsdb& lsdb, const std::string& configFileName)
: CommandManagerBase(dispatcher, namePrefixList, lsdb, "prefix-update")
- , m_validator(std::make_unique<ndn::security::v2::CertificateFetcherDirectFetch>(face))
+ , m_validator(validator)
, m_configFileName(configFileName)
{
NLSR_LOG_DEBUG("Setting dispatcher to capture Interests for: "
@@ -178,14 +178,14 @@
}
ndn::optional<bool>
-PrefixUpdateProcessor::afterAdvertise(const ndn::Name& prefix) {
-
+PrefixUpdateProcessor::afterAdvertise(const ndn::Name& prefix)
+{
return addOrDeletePrefix(prefix, true);
}
ndn::optional<bool>
-PrefixUpdateProcessor::afterWithdraw(const ndn::Name& prefix) {
-
+PrefixUpdateProcessor::afterWithdraw(const ndn::Name& prefix)
+{
return addOrDeletePrefix(prefix, false);
}
diff --git a/src/update/prefix-update-processor.hpp b/src/update/prefix-update-processor.hpp
index 4491448..f397df1 100644
--- a/src/update/prefix-update-processor.hpp
+++ b/src/update/prefix-update-processor.hpp
@@ -44,7 +44,7 @@
{
public:
PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
- ndn::Face& face,
+ ndn::security::ValidatorConfig& validator,
NamePrefixList& namePrefixList,
Lsdb& lsdb, const std::string& configFileName);
@@ -95,7 +95,7 @@
makeAuthorization();
private:
- ndn::security::ValidatorConfig m_validator;
+ ndn::security::ValidatorConfig& m_validator;
const std::string& m_configFileName;
};