comm: Make SyncLogic responsible for update prefix
refs: #2289
Change-Id: I7687e36c88853bdf58de654b1ca280662a826b4b
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 5e20795..5f87436 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -132,6 +132,20 @@
}
};
+SyncLogicHandler::SyncLogicHandler(ndn::Face& face,
+ Lsdb& lsdb, ConfParameter& conf,
+ SequencingManager& seqManager)
+ : m_validator(new ndn::ValidatorNull())
+ , m_syncFace(face)
+ , m_lsdb(lsdb)
+ , m_confParam(conf)
+ , m_sequencingManager(seqManager)
+{
+ m_updatePrefix = m_confParam.getLsaPrefix();
+ m_updatePrefix.append(m_confParam.getSiteName());
+ m_updatePrefix.append(m_confParam.getRouterName());
+}
+
void
SyncLogicHandler::createSyncSocket()
{
@@ -247,10 +261,11 @@
}
void
-SyncLogicHandler::publishRoutingUpdate(SequencingManager& manager, const ndn::Name& updatePrefix)
+SyncLogicHandler::publishRoutingUpdate()
{
- manager.writeSeqNoToFile();
- publishSyncUpdate(updatePrefix, manager.getCombinedSeqNo());
+ m_sequencingManager.writeSeqNoToFile();
+
+ publishSyncUpdate(m_updatePrefix, m_sequencingManager.getCombinedSeqNo());
}
void
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 70fd07e..e602037 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -41,13 +41,7 @@
class SyncLogicHandler
{
public:
- SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf)
- : m_validator(new ndn::ValidatorNull())
- , m_syncFace(face)
- , m_lsdb(lsdb)
- , m_confParam(conf)
- {
- }
+ SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
void
createSyncSocket();
@@ -59,7 +53,7 @@
onNsyncRemoval(const std::string& prefix);
void
- publishRoutingUpdate(SequencingManager& manager, const ndn::Name& updatePrefix);
+ publishRoutingUpdate();
void
setSyncPrefix(const std::string& sp)
@@ -89,6 +83,9 @@
Lsdb& m_lsdb;
ConfParameter& m_confParam;
+ const SequencingManager& m_sequencingManager;
+
+ ndn::Name m_updatePrefix;
static const std::string NLSR_COMPONENT;
static const std::string LSA_COMPONENT;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 212ae42..ce7c706 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -579,11 +579,7 @@
m_hasSyncPrefixBeenRegistered = true;
}
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
- lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
-
- m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), lsaPrefix);
+ m_sync.publishRoutingUpdate();
return isInstalled;
}
@@ -656,14 +652,7 @@
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
chkNameLsa->getLsSeqNo(),
m_lsaRefreshTime));
- // publish routing update
- //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
- lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
- m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
- lsaPrefix);
+ m_sync.publishRoutingUpdate();
}
else {
_LOG_DEBUG("Other's Name LSA, so removing form LSDB");
@@ -695,14 +684,7 @@
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
chkAdjLsa->getLsSeqNo(),
m_lsaRefreshTime));
- // publish routing update
- //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
- lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
- m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
- lsaPrefix);
+ m_sync.publishRoutingUpdate();
}
else {
_LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
@@ -738,14 +720,7 @@
chkCorLsa->getKey(),
chkCorLsa->getLsSeqNo(),
m_lsaRefreshTime));
- // publish routing update
- //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
- lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
- lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
- m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
- lsaPrefix);
+ m_sync.publishRoutingUpdate();
}
else {
_LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 5d66f01..efef94c 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -37,13 +37,15 @@
using namespace ndn::time;
class Nlsr;
+class SyncLogicHandler;
class Lsdb
{
public:
- Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
+ Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
: m_nlsr(nlsr)
, m_scheduler(scheduler)
+ , m_sync(sync)
, m_hasSyncPrefixBeenRegistered(false)
, m_lsaRefreshTime(0)
{
@@ -242,6 +244,7 @@
private:
Nlsr& m_nlsr;
ndn::Scheduler& m_scheduler;
+ SyncLogicHandler& m_sync;
std::list<NameLsa> m_nameLsdb;
std::list<AdjLsa> m_adjLsdb;
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 60728fd..e332808 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -75,7 +75,7 @@
, m_sequencingManager()
, m_isDaemonProcess(false)
, m_configFileName("nlsr.conf")
- , m_nlsrLsdb(*this, scheduler)
+ , m_nlsrLsdb(*this, scheduler, m_syncLogicHandler)
, m_adjBuildCount(0)
, m_isBuildAdjLsaSheduled(false)
, m_isRouteCalculationScheduled(false)
@@ -83,7 +83,7 @@
, 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_syncLogicHandler(m_nlsrFace, m_nlsrLsdb, m_confParam, m_sequencingManager)
, m_helloProtocol(*this, scheduler)
, m_certificateCache(new ndn::CertificateCacheTtl(ioService))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index 01a22fa..b988d9c 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -55,7 +55,7 @@
}
void
-SequencingManager::writeSeqNoToFile()
+SequencingManager::writeSeqNoToFile() const
{
std::ofstream outputFile(m_seqFileNameWithPath.c_str(), ios::binary);
outputFile << m_combinedSeqNo;
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index c91cec4..209f0e5 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -122,7 +122,7 @@
}
void
- writeSeqNoToFile();
+ writeSeqNoToFile() const;
void
initiateSeqNoFromFile();
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 23083c9..d0508e1 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -42,7 +42,7 @@
LsdbFixture()
: face(ndn::makeDummyFace())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
- , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter())
+ , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter(), nlsr.getSequencingManager())
, lsdb(nlsr.getLsdb())
, conf(nlsr.getConfParameter())
, REGISTER_COMMAND_PREFIX("/localhost/nfd/rib")
@@ -175,7 +175,7 @@
//1800 is the default life time.
NameLsa nlsa1(ndn::Name("/router1/1"), std::string("name"), 12, testTimePoint, npl1);
- Lsdb lsdb1(nlsr, g_scheduler);
+ Lsdb lsdb1(nlsr, g_scheduler, nlsr.getSyncLogicHandler());
lsdb1.installNameLsa(nlsa1);
lsdb1.writeNameLsdbLog();
diff --git a/tests/test-sync-logic-handler.cpp b/tests/test-sync-logic-handler.cpp
index 00839b1..c229f35 100644
--- a/tests/test-sync-logic-handler.cpp
+++ b/tests/test-sync-logic-handler.cpp
@@ -37,7 +37,7 @@
SyncLogicFixture()
: face(ndn::makeDummyFace())
, nlsr(g_ioService, g_scheduler, ndn::ref(*face))
- , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter())
+ , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter(), nlsr.getSequencingManager())
, CONFIG_NETWORK("/ndn")
, CONFIG_SITE("/site")
, CONFIG_ROUTER_NAME("/%C1.Router/this-router")