Use separate name prefix and sequence number for each LSA type
refs: #1523
Change-Id: I9db6b3a3ea9ce5e17e132d2a4e2ae9f30dd4f591
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 09d5c27..1413b39 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -26,7 +26,6 @@
#include "logger.hpp"
#include "lsa.hpp"
#include "lsdb.hpp"
-#include "sequencing-manager.hpp"
#include "utility/name-helper.hpp"
namespace nlsr {
@@ -36,85 +35,8 @@
using namespace ndn;
using namespace std;
-class SyncUpdate
-{
-public:
- class Error : public std::runtime_error
- {
- public:
- explicit
- Error(const std::string& what)
- : std::runtime_error(what)
- {
- }
- };
-
-public:
- SyncUpdate(const ndn::Name& name, uint64_t seqNo)
- : m_name(name)
- , m_seqManager(seqNo)
- {
- }
-
- const ndn::Name&
- getName() const
- {
- return m_name;
- }
-
- const ndn::Name
- getOriginRouter() const
- {
- int32_t nlsrPosition = util::getNameComponentPosition(m_name, NLSR_COMPONENT);
- int32_t lsaPosition = util::getNameComponentPosition(m_name, LSA_COMPONENT);
-
- if (nlsrPosition < 0 || lsaPosition < 0) {
- BOOST_THROW_EXCEPTION(Error("Cannot parse update name because expected components are missing"));
- }
-
- ndn::Name networkName = m_name.getSubName(1, nlsrPosition-1);
- ndn::Name routerName = m_name.getSubName(lsaPosition + 1);
-
- ndn::Name originRouter = networkName;
- originRouter.append(routerName);
-
- return originRouter;
- }
-
- uint64_t
- getNameLsaSeqNo() const
- {
- return m_seqManager.getNameLsaSeq();
- }
-
- uint64_t
- getAdjLsaSeqNo() const
- {
- return m_seqManager.getAdjLsaSeq();
- }
-
- uint64_t
- getCorLsaSeqNo() const
- {
- return m_seqManager.getCorLsaSeq();
- }
-
- const SequencingManager&
- getSequencingManager() const
- {
- return m_seqManager;
- }
-
-private:
- const ndn::Name m_name;
- SequencingManager m_seqManager;
-
- static const std::string NLSR_COMPONENT;
- static const std::string LSA_COMPONENT;
-};
-
-const std::string SyncUpdate::NLSR_COMPONENT = "NLSR";
-const std::string SyncUpdate::LSA_COMPONENT = "LSA";
+const std::string NLSR_COMPONENT = "NLSR";
+const std::string LSA_COMPONENT = "LSA";
template<class T>
class NullDeleter
@@ -127,13 +49,10 @@
};
SyncLogicHandler::SyncLogicHandler(ndn::Face& face,
- Lsdb& lsdb, ConfParameter& conf,
- SequencingManager& seqManager)
- : m_validator(new ndn::ValidatorNull())
- , m_syncFace(face)
+ Lsdb& lsdb, ConfParameter& conf)
+ : m_syncFace(face)
, m_lsdb(lsdb)
, m_confParam(conf)
- , m_sequencingManager(seqManager)
{
}
@@ -156,8 +75,16 @@
// of the object
std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
- m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_updatePrefix, *facePtr,
+
+ m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
bind(&SyncLogicHandler::onNsyncUpdate, this, _1));
+
+ if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+ m_syncSocket->addSyncNode(m_adjLsaUserPrefix);
+ }
+ else {
+ m_syncSocket->addSyncNode(m_coorLsaUserPrefix);
+ }
}
void
@@ -166,75 +93,64 @@
_LOG_DEBUG("Received Nsync update event");
for (size_t i = 0; i < v.size(); i++){
- _LOG_DEBUG("Update Name: " << v[i].session.getPrefix(-1).toUri() << " Seq no: " << v[i].high);
+ ndn::Name updateName = v[i].session.getPrefix(-1);
- SyncUpdate update(v[i].session.getPrefix(-1), v[i].high);
+ _LOG_DEBUG("Update Name: " << updateName << " Seq no: " << v[i].high);
- processUpdateFromSync(update);
+ int32_t nlsrPosition = util::getNameComponentPosition(updateName, nlsr::NLSR_COMPONENT);
+ int32_t lsaPosition = util::getNameComponentPosition(updateName, nlsr::LSA_COMPONENT);
+
+ if (nlsrPosition < 0 || lsaPosition < 0) {
+ _LOG_WARN("Received malformed sync update");
+ return;
+ }
+
+ ndn::Name networkName = updateName.getSubName(1, nlsrPosition-1);
+ ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
+
+ ndn::Name originRouter = networkName;
+ originRouter.append(routerName);
+
+ processUpdateFromSync(originRouter, updateName, v[i].high);
}
}
void
-SyncLogicHandler::onNsyncRemoval(const string& prefix)
+SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
+ const ndn::Name& updateName, const uint64_t& seqNo)
{
- _LOG_DEBUG("Received Nsync removal event");
-}
-
-void
-SyncLogicHandler::processUpdateFromSync(const SyncUpdate& update)
-{
- ndn::Name originRouter;
-
- try {
- originRouter = update.getOriginRouter();
- }
- catch (const std::exception& e) {
- _LOG_WARN("Received malformed sync update");
- return;
- }
+ _LOG_DEBUG("Origin Router of update: " << originRouter);
// A router should not try to fetch its own LSA
if (originRouter != m_confParam.getRouterPrefix()) {
- update.getSequencingManager().writeLog();
+ std::string lsaType = updateName.get(updateName.size()-1).toUri();
- if (isLsaNew(originRouter, NameLsa::TYPE_STRING, update.getNameLsaSeqNo())) {
- _LOG_DEBUG("Received sync update with higher Name LSA sequence number than entry in LSDB");
+ _LOG_DEBUG("Received sync update with higher " << lsaType
+ << " sequence number than entry in LSDB");
- expressInterestForLsa(update, NameLsa::TYPE_STRING, update.getNameLsaSeqNo());
+ if (isLsaNew(originRouter, lsaType, seqNo)) {
+ if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
+ m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+ _LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
+ << " is enabled. Not going to fetch.");
+ return;
}
- if (isLsaNew(originRouter, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo())) {
- _LOG_DEBUG("Received sync update with higher Adj LSA sequence number than entry in LSDB");
- if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
- if (update.getAdjLsaSeqNo() != 0) {
- _LOG_ERROR("Tried to fetch an adjacency LSA when hyperbolic routing"
- << " is enabled.");
- }
- }
- else {
- expressInterestForLsa(update, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo());
- }
+ if (lsaType == CoordinateLsa::TYPE_STRING && seqNo != 0 &&
+ m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+ _LOG_ERROR("Got an update for coordinate LSA when link-state"
+ << " is enabled. Not going to fetch.");
+ return;
}
-
- if (isLsaNew(originRouter, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo())) {
- _LOG_DEBUG("Received sync update with higher Cor LSA sequence number than entry in LSDB");
- if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
- if (update.getCorLsaSeqNo() != 0) {
- _LOG_ERROR("Tried to fetch a coordinate LSA when link-state"
- << " is enabled.");
- }
- }
- else {
- expressInterestForLsa(update, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo());
- }
- }
+ expressInterestForLsa(updateName, seqNo);
+ }
}
}
bool
SyncLogicHandler::isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
- uint64_t seqNo)
+ const uint64_t& seqNo)
{
ndn::Name lsaKey = originRouter;
lsaKey.append(lsaType);
@@ -256,18 +172,17 @@
}
void
-SyncLogicHandler::expressInterestForLsa(const SyncUpdate& update, std::string lsaType,
- uint64_t seqNo)
+SyncLogicHandler::expressInterestForLsa(const ndn::Name& updateName,
+ const uint64_t& seqNo)
{
- ndn::Name interest(update.getName());
- interest.append(lsaType);
+ ndn::Name interest(updateName);
interest.appendNumber(seqNo);
m_lsdb.expressInterest(interest, 0);
}
void
-SyncLogicHandler::publishRoutingUpdate()
+SyncLogicHandler::publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo)
{
if (m_syncSocket == nullptr) {
_LOG_FATAL("Cannot publish routing update; SyncSocket does not exist");
@@ -275,17 +190,32 @@
BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncSocket does not exist"));
}
- m_sequencingManager.writeSeqNoToFile();
-
- publishSyncUpdate(m_updatePrefix, m_sequencingManager.getCombinedSeqNo());
+ if (type == NameLsa::TYPE_STRING) {
+ publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
+ }
+ else if (type == AdjLsa::TYPE_STRING) {
+ publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
+ }
+ else {
+ publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
+ }
}
void
SyncLogicHandler::buildUpdatePrefix()
{
- m_updatePrefix = m_confParam.getLsaPrefix();
- m_updatePrefix.append(m_confParam.getSiteName());
- m_updatePrefix.append(m_confParam.getRouterName());
+ ndn::Name updatePrefix = m_confParam.getLsaPrefix();
+ updatePrefix.append(m_confParam.getSiteName());
+ updatePrefix.append(m_confParam.getRouterName());
+
+ m_nameLsaUserPrefix = updatePrefix;
+ m_nameLsaUserPrefix.append(NameLsa::TYPE_STRING);
+
+ m_adjLsaUserPrefix = updatePrefix;
+ m_adjLsaUserPrefix.append(AdjLsa::TYPE_STRING);
+
+ m_coorLsaUserPrefix = updatePrefix;
+ m_coorLsaUserPrefix.append(CoordinateLsa::TYPE_STRING);
}
void
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index c8e143e..2b7dd94 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -23,7 +23,6 @@
#define NLSR_SYNC_LOGIC_HANDLER_HPP
#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/security/validator-null.hpp>
#include <ChronoSync/socket.hpp>
#include <iostream>
@@ -39,8 +38,6 @@
class ConfParameter;
class Lsdb;
-class SequencingManager;
-class SyncUpdate;
class SyncLogicHandler
{
@@ -55,21 +52,29 @@
}
};
- SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
+ SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf);
- /*! \brief Simple wrapper function to handle updates from Sync.
+ /*! \brief Receive and parse update from Sync
+
+ Parses the router name the update came from and passes it to processUpdateFromSync
\param v The information that Sync has acquired.
*/
void
onNsyncUpdate(const std::vector<chronosync::MissingDataInfo>& v);
- void
- onNsyncRemoval(const std::string& prefix);
+ /*! \brief Wrapper function to call publishSyncUpdate with correct LSA type
+ \param type The LSA type constant
+ \param seqNo The latest seqNo known to lsdb
+ */
void
- publishRoutingUpdate();
+ publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo);
+ /*! \brief Creates ChronoSync socket and register additional sync nodes (user prefixes)
+
+ \param syncPrefix /localhop/NLSR/sync
+ */
void
createSyncSocket(const ndn::Name& syncPrefix);
@@ -78,19 +83,20 @@
buildUpdatePrefix();
void
- processUpdateFromSync(const SyncUpdate& updateName);
+ processUpdateFromSync(const ndn::Name& originRouter,
+ const ndn::Name& updateName, const uint64_t& seqNo);
bool
- isLsaNew(const ndn::Name& originRouter, const std::string& lsaType, uint64_t seqNo);
+ isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
+ const uint64_t& seqNo);
void
- expressInterestForLsa(const SyncUpdate& updateName, std::string lsaType, uint64_t seqNo);
+ expressInterestForLsa(const ndn::Name& updateName, const uint64_t& seqNo);
void
publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
private:
- std::shared_ptr<ndn::ValidatorNull> m_validator;
ndn::Face& m_syncFace;
std::shared_ptr<chronosync::Socket> m_syncSocket;
ndn::Name m_syncPrefix;
@@ -98,10 +104,11 @@
private:
Lsdb& m_lsdb;
ConfParameter& m_confParam;
- const SequencingManager& m_sequencingManager;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- ndn::Name m_updatePrefix;
+ ndn::Name m_nameLsaUserPrefix;
+ ndn::Name m_adjLsaUserPrefix;
+ ndn::Name m_coorLsaUserPrefix;
private:
static const std::string NLSR_COMPONENT;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 8468947..61a23f5 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -63,12 +63,13 @@
const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
-Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
+Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
: m_nlsr(nlsr)
, m_scheduler(scheduler)
- , m_sync(sync)
+ , m_sync(m_nlsr.getNlsrFace(), *this, m_nlsr.getConfParameter())
, m_lsaRefreshTime(0)
, m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
+ , m_sequencingManager()
{
}
@@ -150,10 +151,14 @@
Lsdb::buildAndInstallOwnNameLsa()
{
NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
- m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
+ m_sequencingManager.getNameLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getNamePrefixList());
- m_nlsr.getSequencingManager().increaseNameLsaSeq();
+ m_sequencingManager.increaseNameLsaSeq();
+
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
+
return installNameLsa(nameLsa);
}
@@ -378,15 +383,16 @@
Lsdb::buildAndInstallOwnCoordinateLsa()
{
CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
- m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
+ m_sequencingManager.getCorLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getConfParameter().getCorR(),
m_nlsr.getConfParameter().getCorTheta());
// Sync coordinate LSAs if using HR or HR dry run.
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- m_nlsr.getSequencingManager().increaseCorLsaSeq();
- m_sync.publishRoutingUpdate();
+ m_sequencingManager.increaseCorLsaSeq();
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
}
installCoordinateLsa(corLsa);
@@ -751,15 +757,16 @@
Lsdb::buildAndInstallOwnAdjLsa()
{
AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
- m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
+ m_sequencingManager.getAdjLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
m_nlsr.getAdjacencyList());
//Sync adjacency LSAs if link-state or dry-run HR is enabled.
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
- m_nlsr.getSequencingManager().increaseAdjLsaSeq();
- m_sync.publishRoutingUpdate();
+ m_sequencingManager.increaseAdjLsaSeq();
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
}
return installAdjLsa(adjLsa);
@@ -834,7 +841,7 @@
_LOG_DEBUG("Deleting Name Lsa");
chkNameLsa->writeLog();
chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
- m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
+ m_sequencingManager.setNameLsaSeq(chkNameLsa->getLsSeqNo());
chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
_LOG_DEBUG("Adding Name Lsa");
chkNameLsa->writeLog();
@@ -842,7 +849,8 @@
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
chkNameLsa->getLsSeqNo(),
m_lsaRefreshTime));
- m_sync.publishRoutingUpdate();
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
}
// Since we cannot refresh other router's LSAs, our only choice is to expire.
else {
@@ -877,7 +885,7 @@
_LOG_DEBUG("Deleting Adj Lsa");
chkAdjLsa->writeLog();
chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
- m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
+ m_sequencingManager.setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
_LOG_DEBUG("Adding Adj Lsa");
chkAdjLsa->writeLog();
@@ -885,7 +893,8 @@
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
chkAdjLsa->getLsSeqNo(),
m_lsaRefreshTime));
- m_sync.publishRoutingUpdate();
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
}
// An LSA from another router is expiring
else {
@@ -924,7 +933,7 @@
chkCorLsa->writeLog();
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
+ m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo());
}
chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
@@ -937,7 +946,8 @@
m_lsaRefreshTime));
// Only sync coordinate LSAs if link-state routing is disabled
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
- m_sync.publishRoutingUpdate();
+ m_sequencingManager.writeSeqNoToFile();
+ m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
}
}
// We can't refresh other router's LSAs, so we remove it.
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index a2d42cd..1ac25f2 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -30,19 +30,26 @@
#include "conf-parameter.hpp"
#include "lsa.hpp"
+#include "sequencing-manager.hpp"
#include "test-access-control.hpp"
+#include "communication/sync-logic-handler.hpp"
namespace nlsr {
using namespace ndn::time;
class Nlsr;
-class SyncLogicHandler;
class Lsdb
{
public:
- Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync);
+ Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
+
+ SyncLogicHandler&
+ getSyncLogicHandler()
+ {
+ return m_sync;
+ }
bool
doesLsaExist(const ndn::Name& key, const std::string& lsType);
@@ -181,6 +188,12 @@
return m_adjLsaBuildInterval;
}
+ SequencingManager&
+ getSequencingManager()
+ {
+ return m_sequencingManager;
+ }
+
void
writeAdjLsdbLog();
@@ -364,7 +377,7 @@
private:
Nlsr& m_nlsr;
ndn::Scheduler& m_scheduler;
- SyncLogicHandler& m_sync;
+ SyncLogicHandler m_sync;
std::list<NameLsa> m_nameLsdb;
std::list<AdjLsa> m_adjLsdb;
@@ -383,6 +396,8 @@
static const steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
ndn::time::seconds m_adjLsaBuildInterval;
+
+ SequencingManager m_sequencingManager;
};
} // namespace nlsr
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 8a88c1f..f0c4305 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -46,10 +46,9 @@
, m_confParam()
, m_adjacencyList()
, m_namePrefixList()
- , m_sequencingManager()
, m_isDaemonProcess(false)
, m_configFileName("nlsr.conf")
- , m_nlsrLsdb(*this, scheduler, m_syncLogicHandler)
+ , m_nlsrLsdb(*this, scheduler)
, m_adjBuildCount(0)
, m_isBuildAdjLsaSheduled(false)
, m_isRouteCalculationScheduled(false)
@@ -57,7 +56,6 @@
, m_routingTable(scheduler)
, m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
, m_namePrefixTable(*this)
- , m_syncLogicHandler(m_nlsrFace, m_nlsrLsdb, m_confParam, m_sequencingManager)
, m_lsdbDatasetHandler(m_nlsrLsdb,
m_nlsrFace,
m_keyChain)
@@ -67,7 +65,6 @@
, m_prefixUpdateProcessor(m_nlsrFace,
m_namePrefixList,
m_nlsrLsdb,
- m_syncLogicHandler,
DEFAULT_BROADCAST_PREFIX,
m_keyChain,
m_certificateCache,
@@ -75,8 +72,7 @@
, m_dispatcher(m_nlsrFace, m_keyChain, m_signingInfo)
, m_nfdRibCommandProcessor(m_dispatcher,
m_namePrefixList,
- m_nlsrLsdb,
- m_syncLogicHandler)
+ m_nlsrLsdb)
, m_faceMonitor(m_nlsrFace)
, m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
{
@@ -232,10 +228,11 @@
m_nlsrLsdb.setLsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()));
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
- m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
- m_sequencingManager.initiateSeqNoFromFile(m_confParam.getHyperbolicState());
- m_syncLogicHandler.createSyncSocket(m_confParam.getChronosyncPrefix());
+ m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
+ m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
+
+ m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix());
// Logging start
m_confParam.writeLog();
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 574e53a..3df4fd1 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -40,10 +40,8 @@
#include "hello-protocol.hpp"
#include "lsdb.hpp"
#include "name-prefix-list.hpp"
-#include "sequencing-manager.hpp"
#include "test-access-control.hpp"
#include "validator.hpp"
-#include "communication/sync-logic-handler.hpp"
#include "publisher/lsdb-dataset-interest-handler.hpp"
#include "route/fib.hpp"
#include "route/name-prefix-table.hpp"
@@ -140,12 +138,6 @@
return m_nlsrFace;
}
- SequencingManager&
- getSequencingManager()
- {
- return m_sequencingManager;
- }
-
Lsdb&
getLsdb()
{
@@ -224,12 +216,6 @@
m_isRouteCalculationScheduled = ircs;
}
- SyncLogicHandler&
- getSyncLogicHandler()
- {
- return m_syncLogicHandler;
- }
-
LsdbDatasetInterestHandler&
getLsdbDatasetHandler()
{
@@ -408,7 +394,6 @@
ConfParameter m_confParam;
AdjacencyList m_adjacencyList;
NamePrefixList m_namePrefixList;
- SequencingManager m_sequencingManager;
bool m_isDaemonProcess;
std::string m_configFileName;
Lsdb m_nlsrLsdb;
@@ -419,7 +404,6 @@
RoutingTable m_routingTable;
Fib m_fib;
NamePrefixTable m_namePrefixTable;
- SyncLogicHandler m_syncLogicHandler;
LsdbDatasetInterestHandler m_lsdbDatasetHandler;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index 1c91700..6eaab5d 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -25,6 +25,7 @@
#include <pwd.h>
#include <cstdlib>
#include <unistd.h>
+#include <boost/algorithm/string.hpp>
#include "sequencing-manager.hpp"
#include "logger.hpp"
@@ -36,28 +37,15 @@
using namespace std;
void
-SequencingManager::splitSequenceNo(uint64_t seqNo)
-{
- m_combinedSeqNo = seqNo;
- m_adjLsaSeq = (m_combinedSeqNo & 0xFFFFF);
- m_corLsaSeq = ((m_combinedSeqNo >> 20) & 0xFFFFF);
- m_nameLsaSeq = ((m_combinedSeqNo >> 40) & 0xFFFFFF);
-}
-
-void
-SequencingManager::combineSequenceNo()
-{
- m_combinedSeqNo = 0;
- m_combinedSeqNo = m_combinedSeqNo | m_adjLsaSeq;
- m_combinedSeqNo = m_combinedSeqNo | (m_corLsaSeq << 20);
- m_combinedSeqNo = m_combinedSeqNo | (m_nameLsaSeq << 40);
-}
-
-void
SequencingManager::writeSeqNoToFile() const
{
- std::ofstream outputFile(m_seqFileNameWithPath.c_str(), ios::binary);
- outputFile << m_combinedSeqNo;
+ writeLog();
+ std::ofstream outputFile(m_seqFileNameWithPath.c_str());
+ std::ostringstream os;
+ os << "NameLsaSeq " << std::to_string(m_nameLsaSeq) << "\n"
+ << "AdjLsaSeq " << std::to_string(m_adjLsaSeq) << "\n"
+ << "CorLsaSeq " << std::to_string(m_corLsaSeq);
+ outputFile << os.str();
outputFile.close();
}
@@ -65,10 +53,40 @@
SequencingManager::initiateSeqNoFromFile(int hypState)
{
_LOG_DEBUG("Seq File Name: " << m_seqFileNameWithPath);
- std::ifstream inputFile(m_seqFileNameWithPath.c_str(), ios::binary);
+ std::ifstream inputFile(m_seqFileNameWithPath.c_str());
+
+ // Good checks that file is not (bad or eof or fail)
if (inputFile.good()) {
- inputFile >> m_combinedSeqNo;
- splitSequenceNo(m_combinedSeqNo);
+ std::string lsaOrCombinedSeqNo;
+ uint64_t seqNo = 0;
+
+ // If file has a combined seq number, lsaOrCombinedSeqNo would hold it
+ // and seqNo will be zero everytime
+ inputFile >> lsaOrCombinedSeqNo >> seqNo;
+ m_nameLsaSeq = seqNo;
+
+ inputFile >> lsaOrCombinedSeqNo >> seqNo;
+ m_adjLsaSeq = seqNo;
+
+ inputFile >> lsaOrCombinedSeqNo >> seqNo;;
+ m_corLsaSeq = seqNo;
+
+ // File was in old format and had a combined sequence number
+ // if all of the seqNo should are still zero and
+ // lsaOrCombinedSeqNo != CorLsaSeq
+ if (m_nameLsaSeq == 0 && m_adjLsaSeq == 0 && m_corLsaSeq == 0 &&
+ lsaOrCombinedSeqNo != "CorLsaSeq") {
+ _LOG_DEBUG("Old file had combined sequence number: " << lsaOrCombinedSeqNo);
+ std::istringstream iss(lsaOrCombinedSeqNo);
+ iss >> seqNo;
+ m_adjLsaSeq = (seqNo & 0xFFFFF);
+ m_corLsaSeq = ((seqNo >> 20) & 0xFFFFF);
+ m_nameLsaSeq = ((seqNo >> 40) & 0xFFFFFF);
+ }
+
+ inputFile.close();
+
+ m_nameLsaSeq += 10;
// Increment the adjacency LSA seq. no. if link-state or dry HR is enabled
if (hypState != HYPERBOLIC_STATE_ON) {
@@ -82,43 +100,32 @@
// Similarly, increment the coordinate LSA seq. no only if link-state is disabled.
if (hypState != HYPERBOLIC_STATE_OFF) {
- if (m_adjLsaSeq != 0 &&
- hypState == HYPERBOLIC_STATE_ON) {
+ if (m_adjLsaSeq != 0) {
_LOG_WARN("This router was previously configured for link-state"
<< " routing without clearing the seq. no. file.");
m_adjLsaSeq = 0;
}
m_corLsaSeq += 10;
}
- m_nameLsaSeq += 10;
- combineSequenceNo();
- inputFile.close();
}
- else {
- splitSequenceNo(0);
- }
+ writeLog();
}
void
-SequencingManager::setSeqFileName(string filePath)
+SequencingManager::setSeqFileDirectory(string filePath)
{
m_seqFileNameWithPath = filePath;
+
if (m_seqFileNameWithPath.empty()) {
- m_seqFileNameWithPath = getUserHomeDirectory();
+ string homeDirPath(getpwuid(getuid())->pw_dir);
+ if (homeDirPath.empty()) {
+ homeDirPath = getenv("HOME");
+ }
+ m_seqFileNameWithPath = homeDirPath;
}
m_seqFileNameWithPath = m_seqFileNameWithPath + "/nlsrSeqNo.txt";
}
-string
-SequencingManager::getUserHomeDirectory()
-{
- string homeDirPath(getpwuid(getuid())->pw_dir);
- if (homeDirPath.empty()) {
- homeDirPath = getenv("HOME");
- }
- return homeDirPath;
-}
-
void
SequencingManager::writeLog() const
{
@@ -126,7 +133,6 @@
_LOG_DEBUG("Adj LSA seq no: " << m_adjLsaSeq);
_LOG_DEBUG("Cor LSA Seq no: " << m_corLsaSeq);
_LOG_DEBUG("Name LSA Seq no: " << m_nameLsaSeq);
- _LOG_DEBUG("Combined LSDB Seq no: " << m_combinedSeqNo);
}
} // namespace nlsr
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index ce06de8..188cea6 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -39,24 +39,10 @@
: m_nameLsaSeq(0)
, m_adjLsaSeq(0)
, m_corLsaSeq(0)
- , m_combinedSeqNo(0)
, m_seqFileNameWithPath()
{
}
- SequencingManager(uint64_t seqNo)
- {
- splitSequenceNo(seqNo);
- }
-
- SequencingManager(uint64_t nlsn, uint64_t alsn, uint64_t clsn)
- {
- m_nameLsaSeq = nlsn;
- m_adjLsaSeq = alsn;
- m_corLsaSeq = clsn;
- combineSequenceNo();
- }
-
uint64_t
getNameLsaSeq() const
{
@@ -67,7 +53,6 @@
setNameLsaSeq(uint64_t nlsn)
{
m_nameLsaSeq = nlsn;
- combineSequenceNo();
}
uint64_t
@@ -80,7 +65,6 @@
setAdjLsaSeq(uint64_t alsn)
{
m_adjLsaSeq = alsn;
- combineSequenceNo();
}
uint64_t
@@ -93,34 +77,24 @@
setCorLsaSeq(uint64_t clsn)
{
m_corLsaSeq = clsn;
- combineSequenceNo();
}
void
increaseNameLsaSeq()
{
m_nameLsaSeq++;
- combineSequenceNo();
}
void
increaseAdjLsaSeq()
{
m_adjLsaSeq++;
- combineSequenceNo();
}
void
increaseCorLsaSeq()
{
m_corLsaSeq++;
- combineSequenceNo();
- }
-
- uint64_t
- getCombinedSeqNo() const
- {
- return m_combinedSeqNo;
}
void
@@ -129,29 +103,24 @@
void
initiateSeqNoFromFile(int hypState);
- void
- setSeqFileName(std::string filePath);
+ /*! \brief Set the sequence file directory
- std::string
- getUserHomeDirectory();
+ If the string is empty, home directory is set as sequence file directory
+
+ \param filePath The directory where sequence file will be stored
+ */
+ void
+ setSeqFileDirectory(std::string filePath);
void
writeLog() const;
private:
- void
- splitSequenceNo(uint64_t seqNo);
-
- void
- combineSequenceNo();
-
-private:
uint64_t m_nameLsaSeq;
uint64_t m_adjLsaSeq;
uint64_t m_corLsaSeq;
- uint64_t m_combinedSeqNo;
std::string m_seqFileNameWithPath;
};
} // namespace nlsr
-#endif //NLSR_SEQUENCING_MANAGER_HPP
+#endif // NLSR_SEQUENCING_MANAGER_HPP
diff --git a/src/update/nfd-rib-command-processor.cpp b/src/update/nfd-rib-command-processor.cpp
index f4baeb5..e90503a 100644
--- a/src/update/nfd-rib-command-processor.cpp
+++ b/src/update/nfd-rib-command-processor.cpp
@@ -33,12 +33,10 @@
NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixes,
- Lsdb& lsdb,
- SyncLogicHandler& sync)
+ Lsdb& lsdb)
: m_dispatcher(dispatcher)
, m_namePrefixList(namePrefixes)
, m_lsdb(lsdb)
- , m_sync(sync)
{
}
@@ -96,7 +94,6 @@
if (m_namePrefixList.insert(castParams.getName())) {
m_lsdb.buildAndInstallOwnNameLsa();
- m_sync.publishRoutingUpdate();
}
}
@@ -110,7 +107,6 @@
if (m_namePrefixList.remove(castParams.getName())) {
m_lsdb.buildAndInstallOwnNameLsa();
- m_sync.publishRoutingUpdate();
}
}
diff --git a/src/update/nfd-rib-command-processor.hpp b/src/update/nfd-rib-command-processor.hpp
index a022b58..239d349 100644
--- a/src/update/nfd-rib-command-processor.hpp
+++ b/src/update/nfd-rib-command-processor.hpp
@@ -26,7 +26,6 @@
#include "nfd-rib-commands.hpp"
#include "name-prefix-list.hpp"
#include "lsdb.hpp"
-#include "communication/sync-logic-handler.hpp"
#include <ndn-cxx/mgmt/nfd/control-command.hpp>
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
@@ -55,8 +54,7 @@
public:
NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixes,
- Lsdb& lsdb,
- SyncLogicHandler& sync);
+ Lsdb& lsdb);
/*! \brief Registers an Interest filter with face
@@ -116,7 +114,6 @@
ndn::mgmt::Dispatcher& m_dispatcher;
NamePrefixList& m_namePrefixList;
Lsdb& m_lsdb;
- SyncLogicHandler& m_sync;
};
} // namespace update
diff --git a/src/update/prefix-update-processor.cpp b/src/update/prefix-update-processor.cpp
index e0c8f3b..ad1f9a6 100644
--- a/src/update/prefix-update-processor.cpp
+++ b/src/update/prefix-update-processor.cpp
@@ -24,7 +24,6 @@
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "prefix-update-commands.hpp"
-#include "communication/sync-logic-handler.hpp"
#include <ndn-cxx/mgmt/nfd/control-response.hpp>
@@ -40,7 +39,6 @@
PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::Face& face,
NamePrefixList& namePrefixList,
Lsdb& lsdb,
- SyncLogicHandler& sync,
const ndn::Name broadcastPrefix,
ndn::KeyChain& keyChain,
std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
@@ -48,7 +46,6 @@
: m_face(face)
, m_namePrefixList(namePrefixList)
, m_lsdb(lsdb)
- , m_sync(sync)
, m_keyChain(keyChain)
, m_validator(m_face, broadcastPrefix, certificateCache, certStore)
, m_isEnabled(false)
@@ -153,7 +150,6 @@
if (m_namePrefixList.insert(parameters.getName())) {
// Only build a Name LSA if the added name is new
m_lsdb.buildAndInstallOwnNameLsa();
- m_sync.publishRoutingUpdate();
}
}
@@ -173,7 +169,6 @@
if (m_namePrefixList.remove(parameters.getName())) {
// Only build a Name LSA if a name was actually removed
m_lsdb.buildAndInstallOwnNameLsa();
- m_sync.publishRoutingUpdate();
}
}
diff --git a/src/update/prefix-update-processor.hpp b/src/update/prefix-update-processor.hpp
index 4f08bc7..f1a5b50 100644
--- a/src/update/prefix-update-processor.hpp
+++ b/src/update/prefix-update-processor.hpp
@@ -39,7 +39,6 @@
namespace nlsr {
class Lsdb;
-class SyncLogicHandler;
namespace security {
class CertificateStore;
@@ -66,7 +65,6 @@
PrefixUpdateProcessor(ndn::Face& face,
NamePrefixList& namePrefixList,
Lsdb& lsdb,
- SyncLogicHandler& sync,
const ndn::Name broadcastPrefix,
ndn::KeyChain& keyChain,
std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
@@ -134,7 +132,6 @@
ndn::Face& m_face;
NamePrefixList& m_namePrefixList;
Lsdb& m_lsdb;
- SyncLogicHandler& m_sync;
ndn::KeyChain& m_keyChain;
Validator m_validator;
bool m_isEnabled;