Follow ndn::Scheduler API changes
Switch from ndn::EventId to ndn::scheduler::EventId
and simplify some code.
Refs: #4883
Change-Id: Ifbd3b00da441ca0a277900265f8f6e31fdcebf2a
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index 2d653ad..248c0fd 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.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).
@@ -30,18 +30,11 @@
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 @@
}
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 @@
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;
};
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 1da774b..5966108 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -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 @@
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 @@
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 @@
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 @@
.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,9 +341,9 @@
" Seq Num: " << entry.getSeqNo() <<
" in " << m_refreshTime << " seconds");
- entry.setRefreshEventId(m_scheduler.scheduleEvent(ndn::time::seconds(m_refreshTime),
- std::bind(&Fib::refreshEntry, this,
- entry.getName(), refreshCallback)));
+ entry.setRefreshEventId(m_scheduler.schedule(ndn::time::seconds(m_refreshTime),
+ std::bind(&Fib::refreshEntry, this,
+ entry.getName(), refreshCallback)));
}
void
@@ -362,16 +356,13 @@
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;
}
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 012d61d..2d4f47f 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.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.
*
@@ -191,16 +191,14 @@
/*! \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.
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 4e2fa86..f0e4aac 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -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 @@
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 @@
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 @@
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 @@
{
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);
}
}