src: Remove Scheduler instance from Nlsr class
refs: #1981
Change-Id: Iecbe9f975c2740ce04df8593ccde03486d4b7be8
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 764c7d3..cefaa29 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -74,9 +74,8 @@
void
HelloProtocol::scheduleInterest(uint32_t seconds)
{
- m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
- ndn::bind(&HelloProtocol::sendScheduledInterest,
- this, seconds));
+ m_scheduler.scheduleEvent(ndn::time::seconds(seconds),
+ ndn::bind(&HelloProtocol::sendScheduledInterest, this, seconds));
}
void
@@ -156,9 +155,8 @@
_LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
- m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- &m_nlsr.getLsdb()));
+ m_scheduler.scheduleEvent(ndn::time::seconds(5),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild, &m_nlsr.getLsdb()));
}
}
}
@@ -202,9 +200,8 @@
_LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
- m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- ndn::ref(m_nlsr.getLsdb())));
+ m_scheduler.scheduleEvent(ndn::time::seconds(5),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild, &m_nlsr.getLsdb()));
}
}
}
@@ -288,9 +285,8 @@
_LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
- m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- &m_nlsr.getLsdb()));
+ m_scheduler.scheduleEvent(ndn::time::seconds(5),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild, &m_nlsr.getLsdb()));
}
}
}
diff --git a/src/hello-protocol.hpp b/src/hello-protocol.hpp
index fa2528c..30385d9 100644
--- a/src/hello-protocol.hpp
+++ b/src/hello-protocol.hpp
@@ -35,8 +35,9 @@
{
public:
- HelloProtocol(Nlsr& nlsr)
+ HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler)
: m_nlsr(nlsr)
+ , m_scheduler(scheduler)
{
}
@@ -80,6 +81,8 @@
double linkCost, const ndn::time::milliseconds& timeout);
private:
Nlsr& m_nlsr;
+ ndn::Scheduler& m_scheduler;
+
static const std::string INFO_COMPONENT;
static const std::string NLSR_COMPONENT;
};
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 74daed4..0490276 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -40,7 +40,7 @@
void
Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
{
- m_nlsr.getScheduler().cancelEvent(eid);
+ m_scheduler.cancelEvent(eid);
}
static bool
@@ -93,9 +93,8 @@
Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
- return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
- ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
- this, key, seqNo));
+ return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
+ ndn::bind(&Lsdb::exprireOrRefreshNameLsa, this, key, seqNo));
}
bool
@@ -299,9 +298,9 @@
Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
- return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
- ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
- this, key, seqNo));
+ return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
+ ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
+ this, key, seqNo));
}
bool
@@ -451,9 +450,8 @@
m_nlsr.setIsBuildAdjLsaSheduled(true);
int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
m_nlsr.getConfParameter().getInterestResendTime();
- m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- this));
+ m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild, this));
}
}
@@ -505,9 +503,8 @@
Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
- return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
- ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
- this, key, seqNo));
+ return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
+ ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
}
bool
@@ -952,9 +949,8 @@
// Stop retrying if delayed re-validation will be scheduled pass the deadline
if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
_LOG_DEBUG("Scheduling revalidation");
- m_nlsr.getScheduler().scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
- ndn::bind(&Lsdb::retryContentValidation,
- this, data, deadline));
+ m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
+ ndn::bind(&Lsdb::retryContentValidation, this, data, deadline));
}
}
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index c5dcbed..8f1e779 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -39,8 +39,9 @@
class Lsdb
{
public:
- Lsdb(Nlsr& nlsr)
+ Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
: m_nlsr(nlsr)
+ , m_scheduler(scheduler)
, m_lsaRefreshTime(0)
{
}
@@ -232,6 +233,8 @@
cancelScheduleLsaExpiringEvent(ndn::EventId eid);
Nlsr& m_nlsr;
+ ndn::Scheduler& m_scheduler;
+
std::list<NameLsa> m_nameLsdb;
std::list<AdjLsa> m_adjLsdb;
std::list<CoordinateLsa> m_corLsdb;
diff --git a/src/main.cpp b/src/main.cpp
index aafca1d..a06fcee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,18 +21,26 @@
* \author Yingdi Yu <yingdi@cs.ucla.edu>
*
**/
-#include <boost/cstdint.hpp>
-#include "nlsr.hpp"
#include "conf-file-processor.hpp"
#include "logger.hpp"
+#include "nlsr.hpp"
#include "version.hpp"
+#include <boost/asio.hpp>
+#include <boost/cstdint.hpp>
+
+#include <ndn-cxx/util/scheduler.hpp>
+
namespace nlsr {
int
main(int32_t argc, char** argv)
{
- Nlsr nlsr;
+ boost::asio::io_service ioService;
+ ndn::Scheduler scheduler(ioService);
+
+ Nlsr nlsr(ioService, scheduler);
+
std::string programName(argv[0]);
nlsr.setConfFileName("nlsr.conf");
int32_t opt;
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 6197588..e013930 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -64,28 +64,27 @@
};
public:
- Nlsr()
- : m_scheduler(m_nlsrFace.getIoService())
+ Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler)
+ : m_nlsrFace(ioService)
+ , m_scheduler(scheduler)
, m_confParam()
, m_adjacencyList()
, m_namePrefixList()
, m_sequencingManager()
, m_isDaemonProcess(false)
, m_configFileName("nlsr.conf")
- , m_nlsrLsdb(*this)
+ , m_nlsrLsdb(*this, scheduler)
, m_adjBuildCount(0)
, m_isBuildAdjLsaSheduled(false)
, m_isRouteCalculationScheduled(false)
, m_isRoutingTableCalculating(false)
- , m_routingTable()
- , m_fib(*this, m_nlsrFace)
+ , m_routingTable(scheduler)
+ , m_fib(*this, m_nlsrFace, scheduler)
, m_namePrefixTable(*this)
- , m_syncLogicHandler(m_nlsrFace.getIoService())
- , m_helloProtocol(*this)
-
- , m_certificateCache(new ndn::CertificateCacheTtl(m_nlsrFace.getIoService()))
+ , m_syncLogicHandler(ioService)
+ , m_helloProtocol(*this, scheduler)
+ , m_certificateCache(new ndn::CertificateCacheTtl(ioService))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
-
, m_faceMonitor(m_nlsrFace)
{
m_faceMonitor.onNotification += ndn::bind(&Nlsr::onFaceEventNotification, this, _1);
@@ -152,12 +151,6 @@
return m_namePrefixList;
}
- ndn::Scheduler&
- getScheduler()
- {
- return m_scheduler;
- }
-
ndn::Face&
getNlsrFace()
{
@@ -343,7 +336,7 @@
typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
ndn::Face m_nlsrFace;
- ndn::Scheduler m_scheduler;
+ ndn::Scheduler& m_scheduler;
ConfParameter m_confParam;
AdjacencyList m_adjacencyList;
NamePrefixList m_namePrefixList;
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 1e8b9ed..2010858 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -50,7 +50,7 @@
void
Fib::cancelScheduledExpiringEvent(EventId eid)
{
- m_nlsr.getScheduler().cancelEvent(eid);
+ m_scheduler.cancelEvent(eid);
}
@@ -60,8 +60,8 @@
{
_LOG_DEBUG("Fib::scheduleEntryExpiration Called");
_LOG_INFO("Name: " << name << " Seq Num: " << feSeqNum);
- return m_nlsr.getScheduler().scheduleEvent(expTime,
- ndn::bind(&Fib::remove, this, name));
+
+ return m_scheduler.scheduleEvent(expTime, ndn::bind(&Fib::remove, this, name));
}
void
@@ -206,7 +206,7 @@
entry.setSeqNo(entry.getSeqNo() + 1);
// Cancel previosuly scheduled event
- m_nlsr.getScheduler().cancelEvent(entry.getExpiringEventId());
+ m_scheduler.cancelEvent(entry.getExpiringEventId());
// Schedule entry to be refreshed
entry.setExpiringEventId(scheduleEntryExpiration(name , entry.getSeqNo(),
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 6b448fb..9893ff2 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -42,8 +42,9 @@
class Fib
{
public:
- Fib(Nlsr& nlsr, ndn::Face& face)
+ Fib(Nlsr& nlsr, ndn::Face& face, ndn::Scheduler& scheduler)
: m_nlsr(nlsr)
+ , m_scheduler(scheduler)
, m_table()
, m_refreshTime(0)
, m_controller(face)
@@ -178,6 +179,8 @@
private:
Nlsr& m_nlsr;
+ ndn::Scheduler& m_scheduler;
+
std::list<FibEntry> m_table;
int32_t m_refreshTime;
ndn::nfd::Controller m_controller;
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 7ab5b8e..e05db49 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -142,9 +142,9 @@
RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
{
if (pnlsr.getIsRouteCalculationScheduled() != true) {
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate, this,
- ndn::ref(pnlsr)));
+ m_scheduler.scheduleEvent(ndn::time::seconds(15),
+ ndn::bind(&RoutingTable::calculate, this, ndn::ref(pnlsr)));
+
pnlsr.setIsRouteCalculationScheduled(true);
}
}
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index 3a3c96a..6dd3ef2 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -27,6 +27,7 @@
#include <utility>
#include <string>
#include <boost/cstdint.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
#include "routing-table-entry.hpp"
@@ -38,8 +39,9 @@
class RoutingTable
{
public:
- RoutingTable()
- : m_NO_NEXT_HOP(-12345)
+ RoutingTable(ndn::Scheduler& scheduler)
+ : m_scheduler(scheduler)
+ , m_NO_NEXT_HOP(-12345)
{
}
void
@@ -82,6 +84,9 @@
void
writeLog(int hyperbolicState);
+private:
+ ndn::Scheduler& m_scheduler;
+
const int m_NO_NEXT_HOP;
std::list<RoutingTableEntry> m_rTable;