Follow ndn::Scheduler API changes

Switch from ndn::EventId to ndn::scheduler::EventId
and simplify some code.

Refs: #4883
Change-Id: Ifbd3b00da441ca0a277900265f8f6e31fdcebf2a
This commit is contained in:
Davide Pesavento authored and Ashlesh Gawande committed 2019-03-20 08:01:58 -07:00
1 parent 0b0eddd60c
commit af7a2113e4
10 files changed
+116 -205

No files matched your search

+2 -6
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California
*
@@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "hello-protocol.hpp"
#include "hello-protocol.hpp"
#include "nlsr.hpp"
@@ -91,10 +90,7 @@ HelloProtocol::scheduleInterest(uint32_t seconds)
{
NLSR_LOG_DEBUG("Scheduling HELLO Interests in " << ndn::time::seconds(seconds));
m_scheduler.scheduleEvent(ndn::time::seconds(seconds),
[this] {
sendScheduledInterest();
});
m_scheduler.schedule(ndn::time::seconds(seconds), [this] { sendScheduledInterest(); });
}
void
+4 -6
View File
@@ -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.
*
@@ -140,10 +140,8 @@ LsaSegmentStorage::scheduleLsaSegmentDeletion(const ndn::Name& lsaSegmentsKey,
{
NLSR_LOG_TRACE("Scheduling LSA segment deletion for "
<< lsaSegmentsKey << " in: " << expirationTime);
m_scheduler.scheduleEvent(expirationTime,
[lsaSegmentsKey, this] {
m_lsaSegments.erase(lsaSegmentsKey);
});
m_scheduler.schedule(expirationTime,
[lsaSegmentsKey, this] { m_lsaSegments.erase(lsaSegmentsKey); });
}
} // namespace nlsr
+9 -25
View File
@@ -26,7 +26,6 @@
#include "adjacent.hpp"
#include "adjacency-list.hpp"
#include <boost/cstdint.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/time.hpp>
#include <boost/tokenizer.hpp>
@@ -44,14 +43,6 @@ public:
MOCK
};
Lsa()
: m_origRouter()
, m_lsSeqNo()
, m_expirationTimePoint()
, m_expiringEventId()
{
}
virtual
~Lsa() = default;
@@ -98,12 +89,12 @@ public:
}
void
setExpiringEventId(const ndn::EventId leei)
setExpiringEventId(ndn::scheduler::EventId eid)
{
m_expiringEventId = leei;
m_expiringEventId = std::move(eid);
}
ndn::EventId
ndn::scheduler::EventId
getExpiringEventId() const
{
return m_expiringEventId;
@@ -151,17 +142,15 @@ protected:
protected:
ndn::Name m_origRouter;
uint32_t m_lsSeqNo;
uint32_t m_lsSeqNo = 0;
ndn::time::system_clock::TimePoint m_expirationTimePoint;
ndn::EventId m_expiringEventId;
ndn::scheduler::EventId m_expiringEventId;
};
class NameLsa : public Lsa
{
public:
NameLsa()
{
}
NameLsa() = default;
NameLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
@@ -235,9 +224,7 @@ class AdjLsa : public Lsa
public:
typedef AdjacencyList::const_iterator const_iterator;
AdjLsa()
{
}
AdjLsa() = default;
AdjLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
@@ -320,10 +307,7 @@ private:
class CoordinateLsa : public Lsa
{
public:
CoordinateLsa()
: m_corRad(0)
{
}
CoordinateLsa() = default;
CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
@@ -385,7 +369,7 @@ public:
serialize() const override;
private:
double m_corRad;
double m_corRad = 0.0;
std::vector<double> m_angles;
friend std::ostream&
+59 -96
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@@ -88,8 +88,7 @@ Lsdb::onFetchLsaError(uint32_t errorCode,
<< ", Message: " << msg);
if (ndn::time::steady_clock::now() < deadline) {
SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
auto it = m_highestSeqNo.find(lsaName);
if (it != m_highestSeqNo.end() && it->second == seqNo) {
// If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express
// immediately since at the least the LSA Interest lifetime has elapsed.
@@ -101,7 +100,7 @@ Lsdb::onFetchLsaError(uint32_t errorCode,
delay = ndn::time::seconds(0);
}
m_scheduler.scheduleEvent(delay, std::bind(&Lsdb::expressInterest, this,
m_scheduler.schedule(delay, std::bind(&Lsdb::expressInterest, this,
interestName, retransmitNo + 1, deadline));
}
}
@@ -132,12 +131,6 @@ Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& inter
onContentValidated(data);
}
void
Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
{
m_scheduler.cancelEvent(eid);
}
/*! \brief Compares if a name LSA is the same as the one specified by key
\param nlsa1 A name LSA object
@@ -167,13 +160,12 @@ Lsdb::buildAndInstallOwnNameLsa()
NameLsa*
Lsdb::findNameLsa(const ndn::Name& key)
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
auto it = std::find_if(m_nameLsdb.begin(), m_nameLsdb.end(),
std::bind(nameLsaCompareByKey, _1, key));
if (it != m_nameLsdb.end()) {
return &(*it);
return &*it;
}
return 0;
return nullptr;
}
bool
@@ -181,7 +173,7 @@ Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
{
NameLsa* nameLsaCheck = findNameLsa(key);
// Is the name in the LSDB
if (nameLsaCheck != 0) {
if (nameLsaCheck != nullptr) {
// And the supplied seq no is the highest so far
if (nameLsaCheck->getLsSeqNo() < seqNo) {
return true;
@@ -193,11 +185,11 @@ Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
return true;
}
ndn::EventId
ndn::scheduler::EventId
Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
return m_scheduler.schedule(expTime + GRACE_PERIOD,
std::bind(&Lsdb::expireOrRefreshNameLsa, this, key, seqNo));
}
@@ -208,7 +200,7 @@ Lsdb::installNameLsa(NameLsa& nlsa)
ndn::time::seconds timeToExpire = m_lsaRefreshTime;
NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
// Determines if the name LSA is new or not.
if (chkNameLsa == 0) {
if (chkNameLsa == nullptr) {
addNameLsa(nlsa);
NLSR_LOG_DEBUG("New Name LSA");
NLSR_LOG_DEBUG("Adding Name Lsa");
@@ -283,11 +275,10 @@ Lsdb::installNameLsa(NameLsa& nlsa)
}
if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
auto duration = nlsa.getExpirationTimePoint() - ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
}
cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
chkNameLsa->getExpiringEventId().cancel();
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
nlsa.getLsSeqNo(),
timeToExpire));
@@ -301,10 +292,8 @@ Lsdb::installNameLsa(NameLsa& nlsa)
bool
Lsdb::addNameLsa(NameLsa& nlsa)
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
std::bind(nameLsaCompareByKey, _1,
nlsa.getKey()));
auto it = std::find_if(m_nameLsdb.begin(), m_nameLsdb.end(),
std::bind(nameLsaCompareByKey, _1, nlsa.getKey()));
if (it == m_nameLsdb.end()) {
m_nameLsdb.push_back(nlsa);
return true;
@@ -315,16 +304,15 @@ Lsdb::addNameLsa(NameLsa& nlsa)
bool
Lsdb::removeNameLsa(const ndn::Name& key)
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
auto it = std::find_if(m_nameLsdb.begin(), m_nameLsdb.end(),
std::bind(nameLsaCompareByKey, _1, key));
if (it != m_nameLsdb.end()) {
NLSR_LOG_DEBUG("Deleting Name Lsa");
(*it).writeLog();
it->writeLog();
// If the requested name LSA is not ours, we also need to remove
// its entries from the NPT.
if ((*it).getOrigRouter() != m_confParam.getRouterPrefix()) {
m_namePrefixTable.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_confParam.getRouterPrefix()) {
@@ -341,13 +329,9 @@ Lsdb::removeNameLsa(const ndn::Name& key)
bool
Lsdb::doesNameLsaExist(const ndn::Name& key)
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
auto it = std::find_if(m_nameLsdb.begin(), m_nameLsdb.end(),
std::bind(nameLsaCompareByKey, _1, key));
if (it == m_nameLsdb.end()) {
return false;
}
return true;
return it != m_nameLsdb.end();
}
void
@@ -401,13 +385,12 @@ Lsdb::buildAndInstallOwnCoordinateLsa()
CoordinateLsa*
Lsdb::findCoordinateLsa(const ndn::Name& key)
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
auto it = std::find_if(m_corLsdb.begin(), m_corLsdb.end(),
std::bind(corLsaCompareByKey, _1, key));
if (it != m_corLsdb.end()) {
return &(*it);
return &*it;
}
return 0;
return nullptr;
}
bool
@@ -415,7 +398,7 @@ Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
{
CoordinateLsa* clsa = findCoordinateLsa(key);
// Is the coordinate LSA in the LSDB already
if (clsa != 0) {
if (clsa != nullptr) {
// And the seq no is newer (higher) than the current one
if (clsa->getLsSeqNo() < seqNo) {
return true;
@@ -431,13 +414,12 @@ Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
// \param key The name of the router that published the LSA.
// \param seqNo the seq. no. associated with the LSA to check.
// \param expTime How long to wait before triggering the event.
ndn::EventId
ndn::scheduler::EventId
Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
std::bind(&Lsdb::expireOrRefreshCoordinateLsa,
this, key, seqNo));
return m_scheduler.schedule(expTime + GRACE_PERIOD,
std::bind(&Lsdb::expireOrRefreshCoordinateLsa, this, key, seqNo));
}
bool
@@ -446,7 +428,7 @@ Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
ndn::time::seconds timeToExpire = m_lsaRefreshTime;
CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
// Checking whether the LSA is new or not.
if (chkCorLsa == 0) {
if (chkCorLsa == nullptr) {
NLSR_LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
NLSR_LOG_DEBUG("Adding Coordinate Lsa");
clsa.writeLog();
@@ -487,11 +469,10 @@ Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
}
// If this is an LSA from another router, refresh its expiration time.
if (clsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
auto duration = clsa.getExpirationTimePoint() - ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
}
cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
chkCorLsa->getExpiringEventId().cancel();
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
clsa.getLsSeqNo(),
timeToExpire));
@@ -505,10 +486,8 @@ Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
bool
Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
std::bind(corLsaCompareByKey, _1,
clsa.getKey()));
auto it = std::find_if(m_corLsdb.begin(), m_corLsdb.end(),
std::bind(corLsaCompareByKey, _1, clsa.getKey()));
if (it == m_corLsdb.end()) {
m_corLsdb.push_back(clsa);
return true;
@@ -519,10 +498,9 @@ Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
bool
Lsdb::removeCoordinateLsa(const ndn::Name& key)
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
std::bind(corLsaCompareByKey,
_1, key));
auto it = std::find_if(m_corLsdb.begin(), m_corLsdb.end(),
std::bind(corLsaCompareByKey, _1, key));
if (it != m_corLsdb.end()) {
NLSR_LOG_DEBUG("Deleting Coordinate Lsa");
it->writeLog();
@@ -540,14 +518,9 @@ Lsdb::removeCoordinateLsa(const ndn::Name& key)
bool
Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
std::bind(corLsaCompareByKey,
_1, key));
if (it == m_corLsdb.end()) {
return false;
}
return true;
auto it = std::find_if(m_corLsdb.begin(), m_corLsdb.end(),
std::bind(corLsaCompareByKey, _1, key));
return it != m_corLsdb.end();
}
void
@@ -591,7 +564,7 @@ Lsdb::scheduleAdjLsaBuild()
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_scheduler.schedule(m_adjLsaBuildInterval, [this] { buildAdjLsa(); });
m_isBuildAdjLsaSheduled = true;
}
}
@@ -640,18 +613,15 @@ Lsdb::buildAdjLsa()
m_isBuildAdjLsaSheduled = true;
int schedulingTime = m_confParam.getInterestRetryNumber() *
m_confParam.getInterestResendTime();
m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
std::bind(&Lsdb::buildAdjLsa, this));
m_scheduler.schedule(ndn::time::seconds(schedulingTime), [this] { buildAdjLsa(); });
}
}
bool
Lsdb::addAdjLsa(AdjLsa& alsa)
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
std::bind(adjLsaCompareByKey, _1,
alsa.getKey()));
auto it = std::find_if(m_adjLsdb.begin(), m_adjLsdb.end(),
std::bind(adjLsaCompareByKey, _1, alsa.getKey()));
if (it == m_adjLsdb.end()) {
m_adjLsdb.push_back(alsa);
// Add any new name prefixes to the NPT
@@ -669,13 +639,12 @@ Lsdb::addAdjLsa(AdjLsa& alsa)
AdjLsa*
Lsdb::findAdjLsa(const ndn::Name& key)
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
auto it = std::find_if(m_adjLsdb.begin(), m_adjLsdb.end(),
std::bind(adjLsaCompareByKey, _1, key));
if (it != m_adjLsdb.end()) {
return &(*it);
return &*it;
}
return 0;
return nullptr;
}
bool
@@ -683,7 +652,7 @@ Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
{
AdjLsa* adjLsaCheck = findAdjLsa(key);
// If it is in the LSDB
if (adjLsaCheck != 0) {
if (adjLsaCheck != nullptr) {
// And the supplied seq no is newer (higher) than the current one.
if (adjLsaCheck->getLsSeqNo() < seqNo) {
return true;
@@ -695,11 +664,11 @@ Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
return true;
}
ndn::EventId
ndn::scheduler::EventId
Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime)
{
return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
return m_scheduler.schedule(expTime + GRACE_PERIOD,
std::bind(&Lsdb::expireOrRefreshAdjLsa, this, key, seqNo));
}
@@ -709,7 +678,7 @@ Lsdb::installAdjLsa(AdjLsa& alsa)
ndn::time::seconds timeToExpire = m_lsaRefreshTime;
AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
// If this adj. LSA is not in the LSDB already
if (chkAdjLsa == 0) {
if (chkAdjLsa == nullptr) {
NLSR_LOG_DEBUG("New Adj LSA. Adding to LSDB");
NLSR_LOG_DEBUG("Adding Adj Lsa");
alsa.writeLog();
@@ -721,8 +690,7 @@ Lsdb::installAdjLsa(AdjLsa& alsa)
ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
}
scheduleAdjLsaExpiration(alsa.getKey(),
alsa.getLsSeqNo(), timeToExpire);
scheduleAdjLsaExpiration(alsa.getKey(), alsa.getLsSeqNo(), timeToExpire);
}
else {
if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
@@ -741,11 +709,10 @@ Lsdb::installAdjLsa(AdjLsa& alsa)
m_routingTable.scheduleRoutingTableCalculation();
}
if (alsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
ndn::time::system_clock::now();
auto duration = alsa.getExpirationTimePoint() - ndn::time::system_clock::now();
timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
}
cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
chkAdjLsa->getExpiringEventId().cancel();
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
alsa.getLsSeqNo(),
timeToExpire));
@@ -778,9 +745,9 @@ Lsdb::buildAndInstallOwnAdjLsa()
bool
Lsdb::removeAdjLsa(const ndn::Name& key)
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
auto it = std::find_if(m_adjLsdb.begin(), m_adjLsdb.end(),
std::bind(adjLsaCompareByKey, _1, key));
if (it != m_adjLsdb.end()) {
NLSR_LOG_DEBUG("Deleting Adj Lsa");
it->writeLog();
@@ -796,13 +763,9 @@ Lsdb::removeAdjLsa(const ndn::Name& key)
bool
Lsdb::doesAdjLsaExist(const ndn::Name& key)
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
auto it = std::find_if(m_adjLsdb.begin(), m_adjLsdb.end(),
std::bind(adjLsaCompareByKey, _1, key));
if (it == m_adjLsdb.end()) {
return false;
}
return true;
return it != m_adjLsdb.end();
}
const std::list<AdjLsa>&
@@ -825,7 +788,7 @@ Lsdb::expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
NLSR_LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
NameLsa* chkNameLsa = findNameLsa(lsaKey);
// If this name LSA exists in the LSDB
if (chkNameLsa != 0) {
if (chkNameLsa != nullptr) {
NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
// If its seq no is the one we are expecting.
if (chkNameLsa->getLsSeqNo() == seqNo) {
@@ -868,7 +831,7 @@ Lsdb::expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
NLSR_LOG_DEBUG("LSA Key: " << lsaKey << " Seq No: " << seqNo);
AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
// If this is a valid LSA
if (chkAdjLsa != 0) {
if (chkAdjLsa != nullptr) {
NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
// And if it hasn't been updated for some other reason
if (chkAdjLsa->getLsSeqNo() == seqNo) {
@@ -916,7 +879,7 @@ Lsdb::expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
NLSR_LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
// Whether the LSA is in the LSDB or not.
if (chkCorLsa != 0) {
if (chkCorLsa != nullptr) {
NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
// Whether the LSA has been updated without our knowledge.
if (chkCorLsa->getLsSeqNo() == seqNo) {
+4 -9
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@@ -277,7 +277,7 @@ private:
\param seqNo The seq. no. associated with the LSA.
\param expTime How many seconds to wait before triggering the event.
*/
ndn::EventId
ndn::scheduler::EventId
scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime);
@@ -294,16 +294,15 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
\param seqNo The sequence number of the LSA to check.
\param expTime The number of seconds to wait before triggering the event.
*/
ndn::EventId
ndn::scheduler::EventId
scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime);
private:
void
expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
ndn::EventId
ndn::scheduler::EventId
scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
const ndn::time::seconds& expTime);
@@ -379,10 +378,6 @@ private:
ndn::time::system_clock::TimePoint
getLsaExpirationTimePoint();
/*! \brief Cancels an event in the event scheduler. */
void
cancelScheduleLsaExpiringEvent(ndn::EventId eid);
public:
static const ndn::Name::Component NAME_COMPONENT;
+2 -2
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@@ -561,7 +561,7 @@ Nlsr::scheduleDatasetFetch()
{
NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval());
m_scheduler.scheduleEvent(m_confParam.getFaceDatasetFetchInterval(),
m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(),
[this] {
this->initializeFaces(
[this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
+9 -16
View File
@@ -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).
@@ -30,18 +30,11 @@ namespace nlsr {
class FibEntry
{
public:
FibEntry()
: m_name()
, m_seqNo(1)
, m_nexthopList()
{
}
FibEntry() = default;
FibEntry(const ndn::Name& name)
: m_seqNo(1)
, m_nexthopList()
: m_name(name)
{
m_name = name;
}
const ndn::Name&
@@ -57,12 +50,12 @@ public:
}
void
setRefreshEventId(ndn::EventId id)
setRefreshEventId(ndn::scheduler::EventId id)
{
m_refreshEventId = id;
m_refreshEventId = std::move(id);
}
ndn::EventId
ndn::scheduler::EventId
getRefreshEventId() const
{
return m_refreshEventId;
@@ -93,8 +86,8 @@ public:
private:
ndn::Name m_name;
ndn::EventId m_refreshEventId;
int32_t m_seqNo;
ndn::scheduler::EventId m_refreshEventId;
int32_t m_seqNo = 1;
NexthopList m_nexthopList;
};
+14 -23
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California
*
@@ -49,7 +49,7 @@ void
Fib::remove(const ndn::Name& name)
{
NLSR_LOG_DEBUG("Fib::remove called");
std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
auto it = m_table.find(name);
// Only unregister the prefix if it ISN'T a neighbor.
if (it != m_table.end() && isNotNeighbor((it->second).getName())) {
@@ -96,12 +96,11 @@ Fib::update(const ndn::Name& name, const NexthopList& allHops)
unsigned int nFaces = 0;
// Create a list of next hops to be installed with length == maxFaces
for (NexthopList::iterator it = allHops.cbegin(); it != allHops.cend() && nFaces < maxFaces;
++it, ++nFaces) {
for (auto it = allHops.cbegin(); it != allHops.cend() && nFaces < maxFaces; ++it, ++nFaces) {
hopsToAdd.addNextHop(*it);
}
std::map<ndn::Name, FibEntry>::iterator entryIt = m_table.find(name);
auto entryIt = m_table.find(name);
// New FIB entry that has nextHops
if (entryIt == m_table.end() && hopsToAdd.size() != 0) {
@@ -236,7 +235,7 @@ Fib::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResu
NLSR_LOG_DEBUG(message << ": " << commandSuccessResult.getName() <<
" Face Uri: " << faceUri << " faceId: " << commandSuccessResult.getFaceId());
AdjacencyList::iterator adjacent = m_adjacencyList.findAdjacent(faceUri);
auto adjacent = m_adjacencyList.findAdjacent(faceUri);
if (adjacent != m_adjacencyList.end()) {
adjacent->setFaceId(commandSuccessResult.getFaceId());
}
@@ -311,29 +310,24 @@ Fib::setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t co
.setStrategy(strategy);
m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
std::bind(&Fib::onSetStrategySuccess, this, _1,
"Successfully set strategy choice"),
std::bind(&Fib::onSetStrategySuccess, this, _1),
std::bind(&Fib::onSetStrategyFailure, this, _1,
parameters,
count,
"Failed to set strategy choice"));
parameters, count));
}
void
Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message)
Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult)
{
NLSR_LOG_DEBUG(message << ": " << commandSuccessResult.getStrategy() <<
NLSR_LOG_DEBUG("Successfully set strategy choice: " << commandSuccessResult.getStrategy() <<
" for name: " << commandSuccessResult.getName());
}
void
Fib::onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
const ndn::nfd::ControlParameters& parameters,
uint32_t count,
const std::string& message)
uint32_t count)
{
NLSR_LOG_DEBUG(message << ": " << parameters.getStrategy() <<
NLSR_LOG_DEBUG("Failed to set strategy choice: " << parameters.getStrategy() <<
" for name: " << parameters.getName());
if (count < 3) {
setStrategy(parameters.getName(), parameters.getStrategy().toUri(), count + 1);
@@ -347,7 +341,7 @@ Fib::scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCa
" Seq Num: " << entry.getSeqNo() <<
" in " << m_refreshTime << " seconds");
entry.setRefreshEventId(m_scheduler.scheduleEvent(ndn::time::seconds(m_refreshTime),
entry.setRefreshEventId(m_scheduler.schedule(ndn::time::seconds(m_refreshTime),
std::bind(&Fib::refreshEntry, this,
entry.getName(), refreshCallback)));
}
@@ -362,16 +356,13 @@ void
Fib::cancelEntryRefresh(const FibEntry& entry)
{
NLSR_LOG_DEBUG("Canceling refresh for " << entry.getName() << " Seq Num: " << entry.getSeqNo());
m_scheduler.cancelEvent(entry.getRefreshEventId());
entry.getRefreshEventId().reset();
entry.getRefreshEventId().cancel();
}
void
Fib::refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb)
{
std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
auto it = m_table.find(name);
if (it == m_table.end()) {
return;
}
+3 -5
View File
@@ -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.
*
@@ -191,16 +191,14 @@ private:
/*! \brief Log a successful strategy setting.
*/
void
onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message);
onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
/*! \brief Retry a strategy setting up to three (3) times.
*/
void
onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
const ndn::nfd::ControlParameters& parameters,
uint32_t count,
const std::string& message);
uint32_t count);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Schedule a refresh event for an entry.
+10 -17
View File
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California
*
@@ -160,12 +160,9 @@ RoutingTable::calculateHypRoutingTable(bool isDryRun)
void
RoutingTable::scheduleRoutingTableCalculation()
{
if (m_isRouteCalculationScheduled != true) {
if (!m_isRouteCalculationScheduled) {
NLSR_LOG_DEBUG("Scheduling routing table calculation in " << m_routingCalcInterval);
m_scheduler.scheduleEvent(m_routingCalcInterval,
std::bind(&RoutingTable::calculate, this));
m_scheduler.schedule(m_routingCalcInterval, [this] { calculate(); });
m_isRouteCalculationScheduled = true;
}
}
@@ -182,7 +179,7 @@ RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh)
NLSR_LOG_DEBUG("Adding " << nh << " for destination: " << destRouter);
RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter);
if (rteChk == 0) {
if (rteChk == nullptr) {
RoutingTableEntry rte(destRouter);
rte.getNexthopList().addNextHop(nh);
m_rTable.push_back(rte);
@@ -195,14 +192,12 @@ RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh)
RoutingTableEntry*
RoutingTable::findRoutingTableEntry(const ndn::Name& destRouter)
{
std::list<RoutingTableEntry>::iterator it = std::find_if(m_rTable.begin(),
m_rTable.end(),
std::bind(&routingTableEntryCompare,
_1, destRouter));
auto it = std::find_if(m_rTable.begin(), m_rTable.end(),
std::bind(&routingTableEntryCompare, _1, destRouter));
if (it != m_rTable.end()) {
return &(*it);
}
return 0;
return nullptr;
}
void
@@ -230,17 +225,15 @@ RoutingTable::addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh)
{
NLSR_LOG_DEBUG("Adding " << nh << " to dry table for destination: " << destRouter);
std::list<RoutingTableEntry>::iterator it = std::find_if(m_dryTable.begin(),
m_dryTable.end(),
std::bind(&routingTableEntryCompare,
_1, destRouter));
auto it = std::find_if(m_dryTable.begin(), m_dryTable.end(),
std::bind(&routingTableEntryCompare, _1, destRouter));
if (it == m_dryTable.end()) {
RoutingTableEntry rte(destRouter);
rte.getNexthopList().addNextHop(nh);
m_dryTable.push_back(rte);
}
else {
(*it).getNexthopList().addNextHop(nh);
it->getNexthopList().addNextHop(nh);
}
}