Browse Source

src: change initialization order

Send Hello Interest after route to neighbor is successfully registered
--> First Hello interval is eliminated
--> After Hello Nack, wait exponentially before processing it as a timeout
Register sync route for each neighbor after its Hello Data is validated

refs: #5009

Change-Id: Ice39a591f1e58e474b494d93c913fa45e10f24f2
pull/14/head
Ashlesh Gawande 6 years ago
parent
commit
6b388fc36d
  1. 9
      nlsr.conf
  2. 34
      src/adjacency-list.cpp
  3. 6
      src/adjacent.cpp
  4. 3
      src/adjacent.hpp
  5. 89
      src/communication/sync-logic-handler.cpp
  6. 23
      src/communication/sync-logic-handler.hpp
  7. 11
      src/conf-file-processor.cpp
  8. 14
      src/conf-parameter.cpp
  9. 41
      src/conf-parameter.hpp
  10. 88
      src/hello-protocol.cpp
  11. 26
      src/hello-protocol.hpp
  12. 26
      src/lsdb.cpp
  13. 3
      src/lsdb.hpp
  14. 10
      src/main.cpp
  15. 47
      src/nlsr-runner.cpp
  16. 70
      src/nlsr-runner.hpp
  17. 124
      src/nlsr.cpp
  18. 5
      src/nlsr.hpp
  19. 44
      src/route/face-map.cpp
  20. 121
      src/route/face-map.hpp
  21. 71
      src/route/fib.cpp
  22. 20
      src/route/fib.hpp
  23. 9
      src/route/routing-table-calculator.cpp
  24. 1
      src/route/routing-table-calculator.hpp
  25. 7
      src/route/routing-table-entry.hpp
  26. 5
      src/route/routing-table-pool-entry.cpp
  27. 2
      src/route/routing-table.cpp
  28. 8
      src/route/routing-table.hpp
  29. 10
      src/sequencing-manager.cpp
  30. 27
      tests/communication/test-sync-logic-handler.cpp
  31. 4
      tests/publisher/test-dataset-interest-handler.cpp
  32. 4
      tests/route/test-fib.cpp
  33. 2
      tests/route/test-name-prefix-table.cpp
  34. 4
      tests/test-common.hpp
  35. 13
      tests/test-conf-file-processor.cpp
  36. 4
      tests/test-conf-parameter.cpp
  37. 13
      tests/test-lsdb.cpp
  38. 9
      tests/test-nlsr.cpp
  39. 7
      tests/test-statistics.cpp

9
nlsr.conf

@ -38,7 +38,7 @@ neighbors
hello-retries 3 ; interest retries number in integer. Default value 3
; valid values 1-10
hello-timeout 1 ; interest time out value in integer. Default value 1
hello-timeout 1 ; interest time out value in seconds. Default value 1
; Valid values 1-15
hello-interval 60 ; interest sending interval in seconds. Default value 60
@ -47,12 +47,7 @@ neighbors
; adj-lsa-build-interval is the time to wait in seconds after an Adjacency LSA build is scheduled
; before actually building the Adjacency LSA
adj-lsa-build-interval 5 ; default value 5. Valid values 0-5. It is recommended that
; adj-lsa-build-interval have a lower value than routing-calc-interval
; first-hello-interval is the time to wait in seconds before sending the first Hello Interest
first-hello-interval 10 ; Default value 10. Valid values 0-10
adj-lsa-build-interval 10 ; default value 10. Valid values 5-30.
face-dataset-fetch-tries 3 ; default is 3. Valid values 1-10. The FaceDataset is
; gotten from NFD, and is needed to configure NLSR

34
src/adjacency-list.cpp

@ -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.
*
@ -186,9 +186,8 @@ int32_t
AdjacencyList::getNumOfActiveNeighbor() const
{
int32_t actNbrCount = 0;
for (std::list<Adjacent>::const_iterator it = m_adjList.begin(); it != m_adjList.end(); it++) {
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
for (const auto& adjacent: m_adjList) {
if (adjacent.getStatus() == Adjacent::STATUS_ACTIVE) {
actNbrCount++;
}
}
@ -198,24 +197,19 @@ AdjacencyList::getNumOfActiveNeighbor() const
std::list<Adjacent>::iterator
AdjacencyList::find(const ndn::Name& adjName)
{
std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
m_adjList.end(),
std::bind(&Adjacent::compare,
_1, std::cref(adjName)));
return it;
return std::find_if(m_adjList.begin(),
m_adjList.end(),
std::bind(&Adjacent::compare, _1, std::cref(adjName)));
}
std::list<Adjacent>::const_iterator
AdjacencyList::find(const ndn::Name& adjName) const
{
std::list<Adjacent>::const_iterator it = std::find_if(m_adjList.cbegin(),
m_adjList.cend(),
std::bind(&Adjacent::compare,
_1, std::cref(adjName)));
return it;
return std::find_if(m_adjList.cbegin(),
m_adjList.cend(),
std::bind(&Adjacent::compare, _1, std::cref(adjName)));
}
AdjacencyList::iterator
AdjacencyList::findAdjacent(const ndn::Name& adjName)
{
@ -250,20 +244,16 @@ AdjacencyList::getFaceId(const ndn::FaceUri& faceUri)
m_adjList.end(),
std::bind(&Adjacent::compareFaceUri,
_1, faceUri));
if (it != m_adjList.end()) {
return it->getFaceId();
}
return 0;
return it != m_adjList.end() ? it->getFaceId() : 0;
}
void
AdjacencyList::writeLog()
{
NLSR_LOG_DEBUG("-------Adjacency List--------");
for (std::list<Adjacent>::iterator it = m_adjList.begin();
it != m_adjList.end(); it++) {
(*it).writeLog();
for (const auto& adjacent : m_adjList) {
NLSR_LOG_DEBUG(adjacent);
}
}

6
src/adjacent.cpp

@ -104,10 +104,4 @@ operator<<(std::ostream& os, const Adjacent& adjacent)
return os;
}
void
Adjacent::writeLog()
{
NLSR_LOG_DEBUG(*this);
}
} // namespace nlsr

3
src/adjacent.hpp

@ -153,9 +153,6 @@ public:
return m_faceUri == faceUri;
}
void
writeLog();
public:
static const double DEFAULT_LINK_COST;
static const double NON_ADJACENT_COST;

89
src/communication/sync-logic-handler.cpp

@ -33,59 +33,29 @@ const std::string LSA_COMPONENT = "LSA";
INIT_LOGGER(SyncLogicHandler);
template<class T>
class NullDeleter
{
public:
void
operator()(T*)
{
}
};
SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew,
const ConfParameter& conf)
: onNewLsa(std::make_unique<OnNewLsa>())
, m_syncFace(face)
, m_isLsaNew(isLsaNew)
, m_confParam(conf)
, m_nameLsaUserPrefix(ndn::Name(m_confParam.getSyncUserPrefix()).append(std::to_string(Lsa::Type::NAME)))
, m_syncLogic(m_syncFace, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(),
m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(),
std::bind(&SyncLogicHandler::processUpdate, this, _1, _2))
{
createSyncLogic(conf.getSyncPrefix());
}
void
SyncLogicHandler::createSyncLogic(const ndn::Name& syncPrefix, const ndn::time::milliseconds& syncInterestLifetime)
{
if (m_syncLogic != nullptr) {
NLSR_LOG_WARN("Trying to create Sync Logic object, but Sync Logic object already exists");
return;
m_adjLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
.append(std::to_string(Lsa::Type::ADJACENCY));
m_coorLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
.append(std::to_string(Lsa::Type::COORDINATE));
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF ||
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
m_syncLogic.addUserNode(m_adjLsaUserPrefix);
}
// Build LSA sync update prefix
buildUpdatePrefix();
NLSR_LOG_DEBUG("Creating Sync Logic object. Sync Prefix: " << syncPrefix);
// The face's lifetime is managed in main.cpp; Logic should not manage the memory
// of the object
std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
m_syncLogic = std::make_shared<SyncProtocolAdapter>(*facePtr,
m_confParam.getSyncProtocol(),
syncPrefix,
m_nameLsaUserPrefix,
syncInterestLifetime,
std::bind(&SyncLogicHandler::processUpdate, this, _1, _2));
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
m_syncLogic->addUserNode(m_adjLsaUserPrefix);
}
else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
m_syncLogic->addUserNode(m_coorLsaUserPrefix);
}
else {
m_syncLogic->addUserNode(m_adjLsaUserPrefix);
m_syncLogic->addUserNode(m_coorLsaUserPrefix);
else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON ||
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
m_syncLogic.addUserNode(m_coorLsaUserPrefix);
}
}
@ -148,42 +118,19 @@ SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
void
SyncLogicHandler::publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo)
{
if (m_syncLogic == nullptr) {
NLSR_LOG_FATAL("Cannot publish routing update; SyncLogic does not exist");
BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncLogic does not exist"));
}
switch (type) {
case Lsa::Type::ADJACENCY:
m_syncLogic->publishUpdate(m_adjLsaUserPrefix, seqNo);
m_syncLogic.publishUpdate(m_adjLsaUserPrefix, seqNo);
break;
case Lsa::Type::COORDINATE:
m_syncLogic->publishUpdate(m_coorLsaUserPrefix, seqNo);
m_syncLogic.publishUpdate(m_coorLsaUserPrefix, seqNo);
break;
case Lsa::Type::NAME:
m_syncLogic->publishUpdate(m_nameLsaUserPrefix, seqNo);
m_syncLogic.publishUpdate(m_nameLsaUserPrefix, seqNo);
break;
default:
break;
}
}
void
SyncLogicHandler::buildUpdatePrefix()
{
ndn::Name updatePrefix = m_confParam.getLsaPrefix();
updatePrefix.append(m_confParam.getSiteName());
updatePrefix.append(m_confParam.getRouterName());
m_nameLsaUserPrefix = updatePrefix;
m_nameLsaUserPrefix.append(std::to_string(Lsa::Type::NAME));
m_adjLsaUserPrefix = updatePrefix;
m_adjLsaUserPrefix.append(std::to_string(Lsa::Type::ADJACENCY));
m_coorLsaUserPrefix = updatePrefix;
m_coorLsaUserPrefix.append(std::to_string(Lsa::Type::COORDINATE));
}
} // namespace nlsr

23
src/communication/sync-logic-handler.hpp

@ -77,19 +77,6 @@ public:
publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Create and configure a Logic object to enable Sync for this NLSR.
*
* In a typical situation this only needs to be called once, when NLSR starts.
* \param syncPrefix The sync prefix you want this Sync to use
* \param syncInterestLifetime ChronoSync/PSync sends a periodic sync interest every
* \p syncInterestLifetime / 2 ms
* \sa Nlsr::initialize
*/
void
createSyncLogic(const ndn::Name& syncPrefix,
const ndn::time::milliseconds& syncInterestLifetime =
ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
/*! \brief Callback from Sync protocol
*
* In a typical situation this only needs to be called once, when NLSR starts.
@ -99,11 +86,6 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
void
processUpdate(const ndn::Name& updateName, uint64_t highSeq);
/*! \brief Simple function to glue Name components together
*/
void
buildUpdatePrefix();
/*! \brief Determine which kind of LSA was updated and fetch it.
*
* Checks that the received update is not from us, which can happen,
@ -121,9 +103,6 @@ public:
private:
ndn::Face& m_syncFace;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::shared_ptr<SyncProtocolAdapter> m_syncLogic;
private:
IsLsaNew m_isLsaNew;
const ConfParameter& m_confParam;
@ -132,6 +111,8 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
ndn::Name m_adjLsaUserPrefix;
ndn::Name m_coorLsaUserPrefix;
SyncProtocolAdapter m_syncLogic;
private:
static const std::string NLSR_COMPONENT;
static const std::string LSA_COMPONENT;

11
src/conf-file-processor.cpp

@ -451,17 +451,6 @@ ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
return false;
}
// first-hello-interval
ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
std::bind(&ConfParameter::setFirstHelloInterval,
&m_confParam, _1));
firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
if (!firstHelloInterval.parseFromConfigSection(section)) {
return false;
}
for (ConfigSection::const_iterator tn =
section.begin(); tn != section.end(); ++tn) {

14
src/conf-parameter.cpp

@ -43,7 +43,6 @@ ConfParameter::ConfParameter(ndn::Face& face, const std::string& confFileName)
: m_confFileName(confFileName)
, m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
, m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
, m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
, m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT)
, m_faceDatasetFetchInterval(ndn::time::seconds(static_cast<int>(FACE_DATASET_FETCH_INTERVAL_DEFAULT)))
, m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT)))
@ -80,17 +79,18 @@ ConfParameter::writeLog()
NLSR_LOG_INFO("LSA Interest lifetime: " << getLsaInterestLifetime());
NLSR_LOG_INFO("Router dead interval: " << getRouterDeadInterval());
NLSR_LOG_INFO("Max Faces Per Prefix: " << m_maxFacesPerPrefix);
NLSR_LOG_INFO("Hyperbolic Routing: " << m_hyperbolicState);
NLSR_LOG_INFO("Hyp R: " << m_corR);
int i=0;
for (auto const& value: m_corTheta) {
NLSR_LOG_INFO("Hyp Angle " << i++ << ": "<< value);
if (m_hyperbolicState == HYPERBOLIC_STATE_ON || m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
NLSR_LOG_INFO("Hyperbolic Routing: " << m_hyperbolicState);
NLSR_LOG_INFO("Hyp R: " << m_corR);
int i=0;
for (auto const& value: m_corTheta) {
NLSR_LOG_INFO("Hyp Angle " << i++ << ": "<< value);
}
}
NLSR_LOG_INFO("State Directory: " << m_stateFileDir);
// Event Intervals
NLSR_LOG_INFO("Adjacency LSA build interval: " << m_adjLsaBuildInterval);
NLSR_LOG_INFO("First Hello Interest interval: " << m_firstHelloInterval);
NLSR_LOG_INFO("Routing calculation interval: " << m_routingCalcInterval);
}

41
src/conf-parameter.hpp

@ -56,15 +56,9 @@ enum {
};
enum {
ADJ_LSA_BUILD_INTERVAL_MIN = 0,
ADJ_LSA_BUILD_INTERVAL_DEFAULT = 5,
ADJ_LSA_BUILD_INTERVAL_MAX = 5
};
enum {
FIRST_HELLO_INTERVAL_MIN = 0,
FIRST_HELLO_INTERVAL_DEFAULT = 10,
FIRST_HELLO_INTERVAL_MAX = 10
ADJ_LSA_BUILD_INTERVAL_MIN = 5,
ADJ_LSA_BUILD_INTERVAL_DEFAULT = 10,
ADJ_LSA_BUILD_INTERVAL_MAX = 30
};
enum {
@ -94,7 +88,7 @@ enum {
enum {
HELLO_TIMEOUT_MIN = 1,
HELLO_TIMEOUT_DEFAULT = 3,
HELLO_TIMEOUT_DEFAULT = 1,
HELLO_TIMEOUT_MAX = 15
};
@ -180,11 +174,15 @@ public:
}
void
buildRouterPrefix()
buildRouterAndSyncUserPrefix()
{
m_routerPrefix = m_network;
m_routerPrefix.append(m_siteName);
m_routerPrefix.append(m_routerName);
m_syncUserPrefix = m_lsaPrefix;
m_syncUserPrefix.append(m_siteName);
m_syncUserPrefix.append(m_routerName);
}
const ndn::Name&
@ -193,6 +191,12 @@ public:
return m_routerPrefix;
}
const ndn::Name&
getSyncUserPrefix() const
{
return m_syncUserPrefix;
}
const ndn::Name&
getSyncPrefix() const
{
@ -255,18 +259,6 @@ public:
return m_adjLsaBuildInterval;
}
void
setFirstHelloInterval(uint32_t interval)
{
m_firstHelloInterval = interval;
}
uint32_t
getFirstHelloInterval() const
{
return m_firstHelloInterval;
}
void
setRoutingCalcInterval(uint32_t interval)
{
@ -481,7 +473,7 @@ private:
ndn::Name m_network;
ndn::Name m_routerPrefix;
ndn::Name m_lsaRouterPrefix;
ndn::Name m_syncUserPrefix;
ndn::Name m_syncPrefix;
ndn::Name m_lsaPrefix;
@ -489,7 +481,6 @@ private:
uint32_t m_lsaRefreshTime;
uint32_t m_adjLsaBuildInterval;
uint32_t m_firstHelloInterval;
uint32_t m_routingCalcInterval;
uint32_t m_faceDatasetFetchTries;

88
src/hello-protocol.cpp

@ -42,55 +42,55 @@ HelloProtocol::HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain,
, m_confParam(confParam)
, m_routingTable(routingTable)
, m_lsdb(lsdb)
, m_adjacencyList(m_confParam.getAdjacencyList())
{
}
void
HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
{
NLSR_LOG_DEBUG("Expressing Interest :" << interestName);
NLSR_LOG_DEBUG("Expressing Interest: " << interestName);
ndn::Interest interest(interestName);
interest.setInterestLifetime(ndn::time::seconds(seconds));
interest.setMustBeFresh(true);
interest.setCanBePrefix(true);
m_face.expressInterest(interest,
std::bind(&HelloProtocol::onContent, this, _1, _2),
[this] (const ndn::Interest& interest, const ndn::lp::Nack& nack)
{
NDN_LOG_TRACE("Received Nack with reason " << nack.getReason());
NDN_LOG_TRACE("Treating as timeout");
processInterestTimedOut(interest);
},
std::bind(&HelloProtocol::processInterestTimedOut, this, _1));
std::bind(&HelloProtocol::onContent, this, _1, _2),
[this, seconds] (const ndn::Interest& interest, const ndn::lp::Nack& nack)
{
NDN_LOG_TRACE("Received Nack with reason: " << nack.getReason());
NDN_LOG_TRACE("Will treat as timeout in " << 2 * seconds << " seconds");
m_scheduler.schedule(ndn::time::seconds(2 * seconds),
[this, interest] { processInterestTimedOut(interest); });
},
std::bind(&HelloProtocol::processInterestTimedOut, this, _1));
// increment SENT_HELLO_INTEREST
hpIncrementSignal(Statistics::PacketType::SENT_HELLO_INTEREST);
}
void
HelloProtocol::sendScheduledInterest()
HelloProtocol::sendHelloInterest(const ndn::Name& neighbor)
{
for (const auto& adjacent : m_confParam.getAdjacencyList().getAdjList()) {
// If this adjacency has a Face, just proceed as usual.
if(adjacent.getFaceId() != 0) {
// interest name: /<neighbor>/NLSR/INFO/<router>
ndn::Name interestName = adjacent.getName() ;
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_confParam.getRouterPrefix().wireEncode());
expressInterest(interestName, m_confParam.getInterestResendTime());
NLSR_LOG_DEBUG("Sending scheduled interest: " << interestName);
}
auto adjacent = m_adjacencyList.findAdjacent(neighbor);
if (adjacent == m_adjacencyList.end()) {
return;
}
scheduleInterest(m_confParam.getInfoInterestInterval());
}
void
HelloProtocol::scheduleInterest(uint32_t seconds)
{
NLSR_LOG_DEBUG("Scheduling HELLO Interests in " << ndn::time::seconds(seconds));
// If this adjacency has a Face, just proceed as usual.
if(adjacent->getFaceId() != 0) {
// interest name: /<neighbor>/NLSR/INFO/<router>
ndn::Name interestName = adjacent->getName() ;
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_confParam.getRouterPrefix().wireEncode());
expressInterest(interestName, m_confParam.getInterestResendTime());
NLSR_LOG_DEBUG("Sending HELLO interest: " << interestName);
}
m_scheduler.schedule(ndn::time::seconds(seconds), [this] { sendScheduledInterest(); });
m_scheduler.schedule(ndn::time::seconds(m_confParam.getInfoInterestInterval()),
[this, neighbor] { sendHelloInterest(neighbor); });
}
void
@ -113,7 +113,7 @@ HelloProtocol::processInterest(const ndn::Name& name,
ndn::Name neighbor;
neighbor.wireDecode(interestName.get(-1).blockFromValue());
NLSR_LOG_DEBUG("Neighbor: " << neighbor);
if (m_confParam.getAdjacencyList().isNeighbor(neighbor)) {
if (m_adjacencyList.isNeighbor(neighbor)) {
std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
data->setName(ndn::Name(interest.getName()).appendVersion());
data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
@ -128,7 +128,7 @@ HelloProtocol::processInterest(const ndn::Name& name,
// increment SENT_HELLO_DATA
hpIncrementSignal(Statistics::PacketType::SENT_HELLO_DATA);
auto adjacent = m_confParam.getAdjacencyList().findAdjacent(neighbor);
auto adjacent = m_adjacencyList.findAdjacent(neighbor);
// If this neighbor was previously inactive, send our own hello interest, too
if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) {
// We can only do that if the neighbor currently has a face.
@ -155,15 +155,14 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
}
ndn::Name neighbor = interestName.getPrefix(-3);
NLSR_LOG_DEBUG("Neighbor: " << neighbor);
m_confParam.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
m_adjacencyList.incrementTimedOutInterestCount(neighbor);
Adjacent::Status status = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
Adjacent::Status status = m_adjacencyList.getStatusOfNeighbor(neighbor);
uint32_t infoIntTimedOutCount =
m_confParam.getAdjacencyList().getTimedOutInterestCount(neighbor);
uint32_t infoIntTimedOutCount = m_adjacencyList.getTimedOutInterestCount(neighbor);
NLSR_LOG_DEBUG("Status: " << status);
NLSR_LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount);
if (infoIntTimedOutCount < m_confParam.getInterestRetryNumber()) {
if (infoIntTimedOutCount <= m_confParam.getInterestRetryNumber()) {
// interest name: /<neighbor>/NLSR/INFO/<router>
ndn::Name interestName(neighbor);
interestName.append(NLSR_COMPONENT);
@ -174,7 +173,7 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
}
else if ((status == Adjacent::STATUS_ACTIVE) &&
(infoIntTimedOutCount == m_confParam.getInterestRetryNumber())) {
m_confParam.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
m_adjacencyList.setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
NLSR_LOG_DEBUG("Neighbor: " << neighbor << " status changed to INACTIVE");
@ -189,10 +188,9 @@ void
HelloProtocol::onContent(const ndn::Interest& interest, const ndn::Data& data)
{
NLSR_LOG_DEBUG("Received data for INFO(name): " << data.getName());
if (data.getSignature().hasKeyLocator()) {
if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
NLSR_LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
}
if (data.getSignature().hasKeyLocator() &&
data.getSignature().getKeyLocator().getType() == ndn::tlv::Name) {
NLSR_LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
}
m_confParam.getValidator().validate(data,
std::bind(&HelloProtocol::onContentValidated, this, _1),
@ -210,10 +208,10 @@ HelloProtocol::onContentValidated(const ndn::Data& data)
if (dataName.get(-3).toUri() == INFO_COMPONENT) {
ndn::Name neighbor = dataName.getPrefix(-4);
Adjacent::Status oldStatus = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
m_confParam.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
m_confParam.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
Adjacent::Status newStatus = m_confParam.getAdjacencyList().getStatusOfNeighbor(neighbor);
Adjacent::Status oldStatus = m_adjacencyList.getStatusOfNeighbor(neighbor);
m_adjacencyList.setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
m_adjacencyList.setTimedOutInterestCount(neighbor, 0);
Adjacent::Status newStatus = m_adjacencyList.getStatusOfNeighbor(neighbor);
NLSR_LOG_DEBUG("Neighbor : " << neighbor);
NLSR_LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus);
@ -226,6 +224,8 @@ HelloProtocol::onContentValidated(const ndn::Data& data)
m_lsdb.scheduleAdjLsaBuild();
}
}
onHelloDataValidated(neighbor);
}
// increment RCV_HELLO_DATA
hpIncrementSignal(Statistics::PacketType::RCV_HELLO_DATA);

26
src/hello-protocol.hpp

@ -45,18 +45,6 @@ public:
ndn::security::SigningInfo& signingInfo,
ConfParameter& confParam, RoutingTable& routingTable, Lsdb& lsdb);
/*! \brief Schedules a Hello Interest event.
*
* This function serves as the Hello Interest loop, and must be
* explicitly called to start the Hello cycle. This is done at
* NLSR's initialization.
*
* \sa Nlsr::initialize
* \param seconds The number of seconds to wait before calling the event.
*/
void
scheduleInterest(uint32_t seconds);
/*! \brief Sends a Hello Interest packet.
*
* \param interestNamePrefix The name of the router that has published the
@ -75,14 +63,12 @@ public:
*
* This function is called as part of a schedule to regularly
* determine the adjacency status of neighbors. This function
* creates and sends a Hello Interest to each neighbor in
* Nlsr::m_adjacencyList. If the neighbor has not been contacted
* before and currently has no Face in NFD, this method will call a
* different pipeline that creates the Face first, then registers
* prefixes.
* creates and sends a Hello Interest to the given adjacent.
*
* \param neighbor the name of the neighbor
*/
void
sendScheduledInterest();
sendHelloInterest(const ndn::Name& neighbor);
/*! \brief Processes a Hello Interest from a neighbor.
*
@ -167,6 +153,9 @@ private:
onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const ndn::Name& neighbor, const ndn::time::milliseconds& timeout);
public:
ndn::util::Signal<HelloProtocol, const ndn::Name&> onHelloDataValidated;
private:
ndn::Face& m_face;
ndn::Scheduler m_scheduler;
@ -175,6 +164,7 @@ private:
ConfParameter& m_confParam;
RoutingTable& m_routingTable;
Lsdb& m_lsdb;
AdjacencyList& m_adjacencyList;
static const std::string INFO_COMPONENT;
static const std::string NLSR_COMPONENT;

26
src/lsdb.cpp

@ -211,8 +211,8 @@ Lsdb::installNameLsa(NameLsa& nlsa)
if (nlsa.getOrigRouter() != m_confParam.getRouterPrefix()) {
// If this name LSA is from another router, add the advertised
// prefixes to the NPT.
m_namePrefixTable.addEntry(nlsa.getOrigRouter(),
nlsa.getOrigRouter());
m_namePrefixTable.addEntry(nlsa.getOrigRouter(), nlsa.getOrigRouter());
for (const auto& name : nlsa.getNpl().getNames()) {
if (name != m_confParam.getRouterPrefix()) {
m_namePrefixTable.addEntry(name, nlsa.getOrigRouter());
@ -523,6 +523,10 @@ Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
void
Lsdb::writeCorLsdbLog()
{
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
return;
}
NLSR_LOG_DEBUG("---------------Cor LSDB-------------------");
for (const auto& corLsa : m_corLsdb) {
corLsa.writeLog();
@ -558,12 +562,14 @@ Lsdb::scheduleAdjLsaBuild()
return;
}
if (m_isBuildAdjLsaSheduled == false) {
if (m_isBuildAdjLsaSheduled) {
NLSR_LOG_DEBUG("Rescheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
}
else {
NLSR_LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
m_scheduler.schedule(m_adjLsaBuildInterval, [this] { buildAdjLsa(); });
m_isBuildAdjLsaSheduled = true;
}
m_scheduledAdjLsaBuild = m_scheduler.schedule(m_adjLsaBuildInterval, [this] { buildAdjLsa(); });
}
void
@ -608,9 +614,9 @@ Lsdb::buildAdjLsa()
// hopefully finished)
else {
m_isBuildAdjLsaSheduled = true;
int schedulingTime = m_confParam.getInterestRetryNumber() *
m_confParam.getInterestResendTime();
m_scheduler.schedule(ndn::time::seconds(schedulingTime), [this] { buildAdjLsa(); });
auto schedulingTime = ndn::time::seconds(m_confParam.getInterestRetryNumber() *
m_confParam.getInterestResendTime());
m_scheduledAdjLsaBuild = m_scheduler.schedule(schedulingTime, [this] { buildAdjLsa(); });
}
}
@ -1264,6 +1270,10 @@ Lsdb::getLsaExpirationTimePoint()
void
Lsdb::writeAdjLsdbLog()
{
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
return;
}
NLSR_LOG_DEBUG("---------------Adj LSDB-------------------");
for (const auto& adj : m_adjLsdb) {
adj.writeLog();

3
src/lsdb.hpp

@ -207,7 +207,7 @@ public:
return m_isBuildAdjLsaSheduled;
}
const SyncLogicHandler&
SyncLogicHandler&
getSync() {
return m_sync;
}
@ -412,6 +412,7 @@ private:
bool m_isBuildAdjLsaSheduled;
int64_t m_adjBuildCount;
ndn::scheduler::ScopedEventId m_scheduledAdjLsaBuild;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
ndn::InMemoryStoragePersistent m_lsaStorage;

10
src/main.cpp

@ -20,7 +20,7 @@
**/
#include "conf-file-processor.hpp"
#include "nlsr-runner.hpp"
#include "nlsr.hpp"
#include "version.hpp"
#include <boost/exception/get_error_info.hpp>
@ -85,6 +85,7 @@ main(int argc, char** argv)
boost::asio::io_service ioService;
ndn::Face face(ioService);
ndn::KeyChain keyChain;
nlsr::ConfParameter confParam(face, configFileName);
nlsr::ConfFileProcessor configProcessor(confParam);
@ -94,15 +95,16 @@ main(int argc, char** argv)
return 2;
}
confParam.buildRouterPrefix();
confParam.buildRouterAndSyncUserPrefix();
confParam.writeLog();
nlsr::NlsrRunner runner(face, confParam);
nlsr::Nlsr nlsr(face, keyChain, confParam);
try {
runner.run();
face.processEvents();
}
catch (const std::exception& e) {
nlsr.getFib().clean();
std::cerr << "FATAL: " << getExtendedErrorMessage(e) << std::endl;
return 1;
}

47
src/nlsr-runner.cpp

@ -1,47 +0,0 @@
/* -*- 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.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* 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 "nlsr-runner.hpp"
namespace nlsr {
NlsrRunner::NlsrRunner(ndn::Face& face, ConfParameter& confParam)
: m_face(face)
, m_confParam(confParam)
, m_nlsr(m_face, m_keyChain, m_confParam)
{
}
void
NlsrRunner::run()
{
m_nlsr.initialize();
try {
m_face.processEvents();
}
catch (...) {
m_nlsr.getFib().clean();
throw;
}
}
} // namespace nlsr

70
src/nlsr-runner.hpp

@ -1,70 +0,0 @@
/* -*- 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.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* 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/>.
**/
#ifndef NLSR_NLSR_RUNNER_HPP
#define NLSR_NLSR_RUNNER_HPP
#include "nlsr.hpp"
#include "conf-parameter.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
namespace nlsr {
/*! \brief A wrapper class to instantiate and configure an NLSR object.
*
* As its name suggests, this class is responsible for running
* NLSR. It creates an nlsr::ConfFileProcessor to read a configuration
* file and uses that to configure and then start an NLSR process.
* This class only exists to provide this functionality, and there is
* no special reliance of NLSR on this class.
*/
class NlsrRunner
{
public:
explicit
NlsrRunner(ndn::Face& face, ConfParameter& confParam);
/*! \brief Instantiate, configure, and start the NLSR process.
*
* Each NlsrRunner is uniquely paired to the Face it's instantiated
* with. This is *not* a factory-type class, but a one-to-one
* relationship. If one wants to create multiple NLSR classes,
* multiple NLSR runners need to be created, too.
*
* \throws ConfFileError The configuration file cannot be processed.
* NLSR is not started.
* \sa Nlsr::canonizeNeighborUris
*/
void
run();
private:
ndn::Face& m_face;
ndn::KeyChain m_keyChain;
ConfParameter& m_confParam;
Nlsr m_nlsr;
};
} // namespace nlsr
#endif // NLSR_NLSR_RUNNER_HPP

124
src/nlsr.cpp

@ -50,36 +50,77 @@ Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
, m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, m_keyChain)
, m_routingTable(m_scheduler, m_fib, m_lsdb, m_namePrefixTable, m_confParam)
, m_namePrefixTable(m_fib, m_routingTable, m_routingTable.afterRoutingChange)
, m_lsdb(m_face, m_keyChain, m_signingInfo,
m_confParam, m_namePrefixTable, m_routingTable)
, m_lsdb(m_face, m_keyChain, m_signingInfo, m_confParam, m_namePrefixTable, m_routingTable)
, m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb)
, m_afterSegmentValidatedConnection(m_lsdb.afterSegmentValidatedSignal.connect(
std::bind(&Nlsr::afterFetcherSignalEmitted, this, _1)))
, m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect(
[this] (const ndn::Name& updateName, uint64_t sequenceNumber,
const ndn::Name& originRouter) {
registerStrategyForCerts(originRouter);
}))
[this] (const ndn::Name& updateName, uint64_t sequenceNumber,
const ndn::Name& originRouter) {
registerStrategyForCerts(originRouter);
}))
, m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect(
[this] (const ndn::Name& name) {
m_helloProtocol.sendHelloInterest(name);
}))
, m_onHelloDataValidated(m_helloProtocol.onHelloDataValidated.connect(
[this] (const ndn::Name& neighbor) {
auto it = m_adjacencyList.findAdjacent(neighbor);
if (it != m_adjacencyList.end()) {
m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}))
, m_dispatcher(m_face, m_keyChain)
, m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
, m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb)
, m_certStore(m_confParam.getCertStore())
, m_controller(m_face, m_keyChain)
, m_faceDatasetController(m_face, m_keyChain)
, m_prefixUpdateProcessor(m_dispatcher,
m_confParam.getPrefixUpdateValidator(),
m_namePrefixList,
m_lsdb,
m_confParam.getConfFileNameDynamic())
m_confParam.getPrefixUpdateValidator(),
m_namePrefixList,
m_lsdb,
m_confParam.getConfFileNameDynamic())
, m_nfdRibCommandProcessor(m_dispatcher,
m_namePrefixList,
m_lsdb)
m_namePrefixList,
m_lsdb)
, m_statsCollector(m_lsdb, m_helloProtocol)
, m_faceMonitor(m_face)
{
NLSR_LOG_DEBUG("Initializing Nlsr");
m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
m_faceMonitor.start();
// Do key initialization and registrations first, then initialize faces
// which will create routes to neighbor
setStrategies();
initializeKey();
NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
// Can be moved to HelloProtocol and Lsdb ctor if initializeKey is set
// earlier in the Nlsr constructor so as to set m_signingInfo
setInfoInterestFilter();
setLsaInterestFilter();
// add top-level prefixes: router and localhost prefix
addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
addDispatcherTopPrefix(LOCALHOST_PREFIX);
enableIncomingFaceIdIndication();
registerKeyPrefix();
registerLocalhostPrefix();
registerRouterPrefix();
initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
// Could be moved into ctor, but unit tests need to be modified
initialize();
}
void
@ -120,7 +161,7 @@ Nlsr::registerStrategyForCerts(const ndn::Name& originRouter)
void
Nlsr::registrationFailed(const ndn::Name& name)
{
NLSR_LOG_ERROR("ERROR: Failed to register prefix in local hub's daemon");
NLSR_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon");
BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed"));
}
@ -234,30 +275,10 @@ Nlsr::publishCertFromCache(const ndn::Name& keyName)
void
Nlsr::initialize()
{
NLSR_LOG_DEBUG("Initializing Nlsr");
// Logging start
m_adjacencyList.writeLog();
NLSR_LOG_DEBUG(m_namePrefixList);
initializeKey();
NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
// Can be moved to HelloProtocol and Lsdb ctor if initializeKey is set
// earlier in the Nlsr constructor so as to set m_signingInfo
setInfoInterestFilter();
setLsaInterestFilter();
// add top-level prefixes: router and localhost prefix
addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
addDispatcherTopPrefix(LOCALHOST_PREFIX);
initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
enableIncomingFaceIdIndication();
m_lsdb.buildAndInstallOwnNameLsa();
// Install coordinate LSAs if using HR or dry-run HR.
@ -265,19 +286,10 @@ Nlsr::initialize()
m_lsdb.buildAndInstallOwnCoordinateLsa();
}
registerKeyPrefix();
registerLocalhostPrefix();
registerRouterPrefix();
m_helloProtocol.scheduleInterest(m_confParam.getFirstHelloInterval());
// Need to set direct neighbors' costs to 0 for hyperbolic routing
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
std::list<Adjacent>& neighbors = m_adjacencyList.getAdjList();
for (std::list<Adjacent>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) {
it->setLinkCost(0);
for (auto&& neighbor : m_adjacencyList.getAdjList()) {
neighbor.setLinkCost(0);
}
}
}
@ -302,8 +314,9 @@ Nlsr::initializeKey()
nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
}
catch (const std::exception& e) {
NLSR_LOG_ERROR(e.what());
NLSR_LOG_ERROR("Unable to create identity, NLSR will run without security!");
NLSR_LOG_DEBUG("Can be ignored if running in non-production environments.");
NLSR_LOG_ERROR("Can be ignored if running in non-production environments.");
return;
}
auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
@ -333,13 +346,8 @@ Nlsr::initializeKey()
.setSignatureInfo(signatureInfo));
}
catch (const std::exception& e) {
NLSR_LOG_WARN("ERROR: Router's " << e.what()
<< "NLSR is running without security."
<< " If security is enabled NLSR will not converge.");
std::cerr << "Router's " << e.what() << ". NLSR is running without security "
<< "(Only for testing, should not be used in production.)"
<< " If security is enabled NLSR will not converge." << std::endl;
NLSR_LOG_ERROR("Router's " << e.what() << "NLSR is running without security." <<
" If security is enabled NLSR will not converge.");
}
m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
@ -535,11 +543,11 @@ Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
NLSR_LOG_DEBUG("Processing face dataset");
// Iterate over each neighbor listed in nlsr.conf
for (auto& adjacent : m_adjacencyList.getAdjList()) {
for (auto&& adjacent : m_adjacencyList.getAdjList()) {
const std::string faceUriString = adjacent.getFaceUri().toString();
const std::string& faceUriString = adjacent.getFaceUri().toString();
// Check the list of FaceStatus objects we got for a match
for (const ndn::nfd::FaceStatus& faceStatus : faces) {
for (const auto& faceStatus : faces) {
// Set the adjacency FaceID if we find a URI match and it was
// previously unset. Change the boolean to true.
if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
@ -574,10 +582,6 @@ Nlsr::registerAdjacencyPrefixes(const Adjacent& adj,
m_fib.registerPrefix(adjName, faceUri, linkCost,
timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
m_fib.registerPrefix(m_confParam.getSyncPrefix(),
faceUri, linkCost, timeout,
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
m_fib.registerPrefix(m_confParam.getLsaPrefix(),
faceUri, linkCost, timeout,
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);

5
src/nlsr.hpp

@ -272,21 +272,24 @@ private:
bool m_isDaemonProcess;
ndn::security::ValidatorConfig& m_validator;
std::vector<ndn::Name> m_strategySetOnRouters;
uint16_t m_numSyncPrefixRegistered = 0;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Fib m_fib;
RoutingTable m_routingTable;
NamePrefixTable m_namePrefixTable;
Lsdb m_lsdb;
HelloProtocol m_helloProtocol;
private:
ndn::util::signal::ScopedConnection m_afterSegmentValidatedConnection;
ndn::util::signal::ScopedConnection m_onNewLsaConnection;
ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
ndn::util::signal::ScopedConnection m_onHelloDataValidated;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
ndn::mgmt::Dispatcher m_dispatcher;
DatasetInterestHandler m_datasetHandler;
HelloProtocol m_helloProtocol;
private:
/*! \brief Where NLSR stores certificates it claims to be

44
src/route/face-map.cpp

@ -1,44 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* 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/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#include "face-map.hpp"
#include "common.hpp"
#include "logger.hpp"
#include <iostream>
#include <utility>
namespace nlsr {
INIT_LOGGER(route.FaceMap);
void
FaceMap::writeLog()
{
NLSR_LOG_DEBUG("------- Face Map-----------");
for (const auto& it : m_table) {
NLSR_LOG_DEBUG("Face Map Entry (FaceUri: " << (it.second).getFaceUri()
<< " Face Id: " << (it.second).getFaceId() << ")");
}
}
} // namespace nlsr

121
src/route/face-map.hpp

@ -1,121 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* 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/>.
*
**/
#ifndef NLSR_FACE_MAP_HPP
#define NLSR_FACE_MAP_HPP
#include "common.hpp"
#include <map>
namespace nlsr {
class FaceMapEntry
{
public:
FaceMapEntry(const std::string& faceUri, uint32_t faceId)
: m_faceUri(faceUri)
, m_faceId(faceId)
{
}
void
setFaceUri(const std::string& faceUri)
{
m_faceUri = faceUri;
}
const std::string&
getFaceUri() const
{
return m_faceUri;
}
void
setFaceId(uint32_t faceId)
{
m_faceId = faceId;
}
uint32_t
getFaceId() const
{
return m_faceId;
}
bool
compare(const FaceMapEntry& fme)
{
return m_faceUri == fme.getFaceUri();
}
private:
std::string m_faceUri;
uint32_t m_faceId;
};
class FaceMap
{
public:
FaceMap()
{
}
~FaceMap()
{
}
inline void
update(const std::string& faceUri, uint32_t faceId)
{
FaceMapEntry fme(faceUri, faceId);
std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri);
if (it == m_table.end()) {
m_table.emplace(faceUri, fme);
}
else {
(it->second).setFaceId(fme.getFaceId());
}
}
inline uint32_t
getFaceId(const std::string& faceUri)
{
FaceMapEntry fme(faceUri, 0);
std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri);
if (it != m_table.end()) {
return (it->second).getFaceId();
}
return 0;
}
void
writeLog();
private:
std::map<std::string, FaceMapEntry> m_table;
};
} // namespace nlsr
#endif // NLSR_FACE_MAP_HPP

71
src/route/fib.cpp

@ -202,9 +202,9 @@ Fib::registerPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri,
uint64_t faceCost, const ndn::time::milliseconds& timeout,
uint64_t flags, uint8_t times)
{
uint64_t faceId = m_adjacencyList.getFaceId(ndn::FaceUri(faceUri));
uint64_t faceId = m_adjacencyList.getFaceId(faceUri);
if (faceId != 0) {
if (faceId > 0) {
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setName(namePrefix)
@ -216,13 +216,9 @@ Fib::registerPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri,
NLSR_LOG_DEBUG("Registering prefix: " << faceParameters.getName() << " faceUri: " << faceUri);
m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
std::bind(&Fib::onRegistrationSuccess, this, _1,
"Successful in name registration",
faceUri),
std::bind(&Fib::onRegistrationFailure, this, _1,
"Failed in name registration",
faceParameters,
faceUri, times));
std::bind(&Fib::onRegistrationSuccess, this, _1, faceUri),
std::bind(&Fib::onRegistrationFailure, this, _1,
faceParameters, faceUri, times));
}
else {
NLSR_LOG_WARN("Error: No Face Id for face uri: " << faceUri);
@ -230,31 +226,28 @@ Fib::registerPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri,
}
void
Fib::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message, const ndn::FaceUri& faceUri)
Fib::onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
const ndn::FaceUri& faceUri)
{
NLSR_LOG_DEBUG(message << ": " << commandSuccessResult.getName() <<
" Face Uri: " << faceUri << " faceId: " << commandSuccessResult.getFaceId());
NLSR_LOG_DEBUG("Successful in name registration: " << param.getName() <<
" Face Uri: " << faceUri << " faceId: " << param.getFaceId());
auto adjacent = m_adjacencyList.findAdjacent(faceUri);
if (adjacent != m_adjacencyList.end()) {
adjacent->setFaceId(commandSuccessResult.getFaceId());
adjacent->setFaceId(param.getFaceId());
}
// Update the fast-access FaceMap with the new Face ID, too
m_faceMap.update(faceUri.toString(), commandSuccessResult.getFaceId());
m_faceMap.writeLog();
onPrefixRegistrationSuccess(param.getName());
}
void
Fib::onRegistrationFailure(const ndn::nfd::ControlResponse& response,
const std::string& message,
const ndn::nfd::ControlParameters& parameters,
const ndn::FaceUri& faceUri,
uint8_t times)
{
NLSR_LOG_DEBUG(message << ": " << response.getText() << " (code: " << response.getCode() << ")");
NLSR_LOG_DEBUG("Prefix: " << parameters.getName() << " failed for: " << times);
NLSR_LOG_DEBUG("Failed in name registration: " << response.getText() <<
" (code: " << response.getCode() << ")");
NLSR_LOG_DEBUG("Prefix: " << parameters.getName() << " failed for: " << +times);
if (times < 3) {
NLSR_LOG_DEBUG("Trying to register again...");
registerPrefix(parameters.getName(), faceUri,
@ -270,7 +263,12 @@ Fib::onRegistrationFailure(const ndn::nfd::ControlResponse& response,
void
Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
{
uint32_t faceId = m_faceMap.getFaceId(faceUri);
uint64_t faceId = 0;
auto adjacent = m_adjacencyList.findAdjacent(ndn::FaceUri(faceUri));
if (adjacent != m_adjacencyList.end()) {
faceId = adjacent->getFaceId();
}
NLSR_LOG_DEBUG("Unregister prefix: " << namePrefix << " Face Uri: " << faceUri);
if (faceId > 0) {
ndn::nfd::ControlParameters controlParameters;
@ -278,30 +276,19 @@ Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
.setName(namePrefix)
.setFaceId(faceId)
.setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
std::bind(&Fib::onUnregistrationSuccess, this, _1,
"Successful in unregistering name"),
std::bind(&Fib::onUnregistrationFailure,
this, _1,
"Failed in unregistering name"));
[] (const ndn::nfd::ControlParameters& commandSuccessResult) {
NLSR_LOG_DEBUG("Unregister successful Prefix: " << commandSuccessResult.getName() <<
" Face Id: " << commandSuccessResult.getFaceId());
},
[] (const ndn::nfd::ControlResponse& response) {
NLSR_LOG_DEBUG("Failed in unregistering name" << ": " << response.getText() <<
" (code: " << response.getCode() << ")");
});
}
}
void
Fib::onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message)
{
NLSR_LOG_DEBUG("Unregister successful Prefix: " << commandSuccessResult.getName() <<
" Face Id: " << commandSuccessResult.getFaceId());
}
void
Fib::onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
const std::string& message)
{
NLSR_LOG_DEBUG(message << ": " << response.getText() << " (code: " << response.getCode() << ")");
}
void
Fib::setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count)
{

20
src/route/fib.hpp

@ -22,7 +22,6 @@
#ifndef NLSR_ROUTE_FIB_HPP
#define NLSR_ROUTE_FIB_HPP
#include "face-map.hpp"
#include "fib-entry.hpp"
#include "test-access-control.hpp"
@ -164,30 +163,17 @@ private:
/*! \brief Log registration success, and update the Face ID associated with a URI.
*/
void
onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message, const ndn::FaceUri& faceUri);
onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
const ndn::FaceUri& faceUri);
/*! \brief Retry a prefix (next-hop) registration up to three (3) times.
*/
void
onRegistrationFailure(const ndn::nfd::ControlResponse& response,
const std::string& message,
const ndn::nfd::ControlParameters& parameters,
const ndn::FaceUri& faceUri,
uint8_t times);
/*! \brief Log a successful unregistration.
*/
void
onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message);
/*! \brief Log an unregistration failure. Does not retry.
*/
void
onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
const std::string& message);
/*! \brief Log a successful strategy setting.
*/
void
@ -240,6 +226,7 @@ private:
public:
static const std::string MULTICAST_STRATEGY;
static const std::string BEST_ROUTE_V2_STRATEGY;
ndn::util::Signal<Fib, const ndn::Name&> onPrefixRegistrationSuccess;
private:
ndn::Scheduler& m_scheduler;
@ -247,7 +234,6 @@ private:
ndn::nfd::Controller m_controller;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
FaceMap m_faceMap;
std::map<ndn::Name, FibEntry> m_table;
private:

9
src/route/routing-table-calculator.cpp

@ -142,8 +142,13 @@ RoutingTableCalculator::writeAdjMatrixLog(const Map& map) const
for (size_t i = 0; i < m_nRouters; i++) {
std::string line;
for (size_t j = 0; j < m_nRouters; j++) {
line += boost::lexical_cast<std::string>(adjMatrix[i][j]);
line += " ";
if (adjMatrix[i][j] == LinkStateRoutingTableCalculator::NO_NEXT_HOP) {
line += "0 ";
}
else {
line += boost::lexical_cast<std::string>(adjMatrix[i][j]);
line += " ";
}
}
line = boost::lexical_cast<std::string>(i) + "|" + line;
NLSR_LOG_DEBUG(line);

1
src/route/routing-table-calculator.hpp

@ -200,6 +200,7 @@ private:
static const int EMPTY_PARENT;
static const double INF_DISTANCE;
static const int NO_MAPPING_NUM;
public:
static const int NO_NEXT_HOP;
};

7
src/route/routing-table-entry.hpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, 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).
@ -66,9 +66,8 @@ public:
inline bool
operator==(RoutingTableEntry& rhs)
{
return ((*this).getDestination() == rhs.getDestination()
&&
(*this).getNexthopList() == rhs.getNexthopList());
return ((*this).getDestination() == rhs.getDestination() &&
(*this).getNexthopList() == rhs.getNexthopList());
}
protected:

5
src/route/routing-table-pool-entry.cpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, 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).
@ -43,8 +43,7 @@ operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe)
bool
operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs)
{
return (lhs.getDestination() == rhs.getDestination()
&&
return (lhs.getDestination() == rhs.getDestination() &&
lhs.getNexthopList() == rhs.getNexthopList());
}

2
src/route/routing-table.cpp

@ -27,7 +27,6 @@
#include "name-prefix-table.hpp"
#include "logger.hpp"
#include <iostream>
#include <list>
#include <string>
@ -42,7 +41,6 @@ RoutingTable::RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
, m_fib(fib)
, m_lsdb(lsdb)
, m_namePrefixTable(namePrefixTable)
, m_NO_NEXT_HOP{-12345}
, m_routingCalcInterval{confParam.getRoutingCalcInterval()}
, m_isRoutingTableCalculating(false)
, m_isRouteCalculationScheduled(false)

8
src/route/routing-table.hpp

@ -75,12 +75,6 @@ public:
void
scheduleRoutingTableCalculation();
int
getNoNextHop()
{
return m_NO_NEXT_HOP;
}
void
setRoutingCalcInterval(uint32_t interval)
{
@ -141,8 +135,6 @@ private:
Lsdb& m_lsdb;
NamePrefixTable& m_namePrefixTable;
const int m_NO_NEXT_HOP;
std::list<RoutingTableEntry> m_dryTable;
ndn::time::seconds m_routingCalcInterval;

10
src/sequencing-manager.cpp

@ -138,8 +138,14 @@ void
SequencingManager::writeLog() const
{
NLSR_LOG_DEBUG("----SequencingManager----");
NLSR_LOG_DEBUG("Adj LSA seq no: " << m_adjLsaSeq);
NLSR_LOG_DEBUG("Cor LSA Seq no: " << m_corLsaSeq);
if (m_hyperbolicState == HYPERBOLIC_STATE_OFF ||
m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
NLSR_LOG_DEBUG("Adj LSA seq no: " << m_adjLsaSeq);
}
if (m_hyperbolicState == HYPERBOLIC_STATE_ON ||
m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
NLSR_LOG_DEBUG("Cor LSA Seq no: " << m_corLsaSeq);
}
NLSR_LOG_DEBUG("Name LSA Seq no: " << m_nameLsaSeq);
}

27
tests/communication/test-sync-logic-handler.cpp

@ -61,12 +61,12 @@ public:
if (Protocol == SYNC_PROTOCOL_CHRONOSYNC) {
std::vector<chronosync::MissingDataInfo> updates;
updates.push_back({ndn::Name(prefix).appendNumber(1), 0, seqNo});
sync.m_syncLogic->onChronoSyncUpdate(updates);
sync.m_syncLogic.onChronoSyncUpdate(updates);
}
else {
std::vector<psync::MissingDataInfo> updates;
updates.push_back({ndn::Name(prefix), 0, seqNo});
sync.m_syncLogic->onPSyncUpdate(updates);
sync.m_syncLogic.onPSyncUpdate(updates);
}
this->advanceClocks(ndn::time::milliseconds(1), 10);
@ -246,8 +246,6 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePrefix, T, Protocols, SyncLogicFixture<T:
expectedPrefix.append(this->conf.getSiteName());
expectedPrefix.append(this->conf.getRouterName());
this->sync.buildUpdatePrefix();
BOOST_CHECK_EQUAL(this->sync.m_nameLsaUserPrefix,
ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::NAME)));
BOOST_CHECK_EQUAL(this->sync.m_adjLsaUserPrefix,
@ -256,27 +254,6 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePrefix, T, Protocols, SyncLogicFixture<T:
ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::COORDINATE)));
}
/* Tests that SyncLogicHandler's socket will be created when
Nlsr is initialized, preventing use of sync before the
socket is created.
NB: This test is as much an Nlsr class test as a
SyncLogicHandler class test, but it rides the line and ends up here.
*/
BOOST_FIXTURE_TEST_CASE_TEMPLATE(createSyncLogicOnInitialization, T, Protocols,
SyncLogicFixture<T::value>) // Bug #2649
{
Nlsr nlsr(this->face, this->m_keyChain, this->conf);
// Make sure an adjacency LSA has not been built yet
ndn::Name key = ndn::Name(this->conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
AdjLsa* lsa = nlsr.m_lsdb.findAdjLsa(key);
BOOST_REQUIRE(lsa == nullptr);
// Publish a routing update before an Adjacency LSA is built
BOOST_CHECK_NO_THROW(nlsr.m_lsdb.m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, 0));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test

4
tests/publisher/test-dataset-interest-handler.cpp

@ -45,9 +45,7 @@ processDatasetInterest(ndn::util::DummyClientFace& face,
parser.parse();
ndn::Block::element_const_iterator it = parser.elements_begin();
BOOST_CHECK_EQUAL(isSameType(*it), true);
++it;
BOOST_CHECK_EQUAL(isSameType(*it++), true);
BOOST_CHECK(it == parser.elements_end());
face.sentData.clear();

4
tests/route/test-fib.cpp

@ -53,10 +53,6 @@ public:
fib = std::make_shared<Fib>(*face, m_scheduler, adjacencies, conf, m_keyChain);
fib->setEntryRefreshTime(1);
fib->m_faceMap.update(router1FaceUri, router1FaceId);
fib->m_faceMap.update(router2FaceUri, router2FaceId);
fib->m_faceMap.update(router3FaceUri, router3FaceId);
}
public:

2
tests/route/test-name-prefix-table.cpp

@ -56,7 +56,7 @@ BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
conf.setNetwork("/ndn");
conf.setSiteName("/router");
conf.setRouterName("/a");
conf.buildRouterPrefix();
conf.buildRouterAndSyncUserPrefix();
RoutingTable& routingTable = nlsr.m_routingTable;
routingTable.setRoutingCalcInterval(0);

4
tests/test-common.hpp

@ -181,10 +181,10 @@ public:
conf.setNetwork("/ndn");
conf.setSiteName("/site");
conf.setRouterName("/%C1.Router/this-router");
conf.buildRouterPrefix();
conf.buildRouterAndSyncUserPrefix();
conf.setSyncProtocol(protocol);
conf.setHyperbolicState(HYPERBOLIC_STATE_OFF);
conf.setHyperbolicState(hyperbolicState);
}
};

13
tests/test-conf-file-processor.cpp

@ -54,8 +54,7 @@ const std::string SECTION_NEIGHBORS =
" hello-retries 3\n"
" hello-timeout 1\n"
" hello-interval 60\n\n"
" adj-lsa-build-interval 3\n"
" first-hello-interval 6\n"
" adj-lsa-build-interval 10\n"
" neighbor\n"
" {\n"
" name /ndn/memphis.edu/cs/castor\n"
@ -162,7 +161,7 @@ BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
BOOST_AUTO_TEST_CASE(LinkState)
{
processConfigurationString(CONFIG_LINK_STATE);
conf.buildRouterPrefix();
conf.buildRouterAndSyncUserPrefix();
// General
BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
@ -183,8 +182,7 @@ BOOST_AUTO_TEST_CASE(LinkState)
BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3);
BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10);
BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
@ -219,8 +217,7 @@ BOOST_AUTO_TEST_CASE(MalformedUri)
" hello-retries 3\n"
" hello-timeout 1\n"
" hello-interval 60\n\n"
" adj-lsa-build-interval 3\n"
" first-hello-interval 6\n"
" adj-lsa-build-interval 10\n"
" neighbor\n"
" {\n"
" name /ndn/memphis.edu/cs/castor\n"
@ -286,8 +283,6 @@ BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
}

4
tests/test-conf-parameter.cpp

@ -79,10 +79,12 @@ BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
BOOST_CHECK_EQUAL(cp1.getNetwork(), "ATT");
cp1.buildRouterPrefix();
cp1.buildRouterAndSyncUserPrefix();
BOOST_CHECK_EQUAL(cp1.getRouterPrefix(), "/ATT/memphis/router1");
BOOST_CHECK_EQUAL(cp1.getSyncUserPrefix(), "/localhop/ATT/nlsr/LSA/memphis/router1");
BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), 2);
BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);

13
tests/test-lsdb.cpp

@ -183,14 +183,15 @@ BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
int nPrefixes = 0;
while (nameLsa->serialize().size() < ndn::MAX_NDN_PACKET_SIZE) {
nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
break;
}
lsdb.installNameLsa(*nameLsa);
// Create another Lsdb and expressInterest
ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
face.linkTo(face2);
ConfParameter conf2(face2);
Nlsr nlsr2(face2, m_keyChain, conf2);
std::string config = R"CONF(
trust-anchor
{
@ -198,19 +199,19 @@ BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
}
)CONF";
conf2.getValidator().load(config, "config-file-from-string");
Nlsr nlsr2(face2, m_keyChain, conf2);
Lsdb& lsdb2(nlsr2.m_lsdb);
advanceClocks(ndn::time::milliseconds(1), 10);
advanceClocks(ndn::time::milliseconds(10), 10);
ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
interestName.appendNumber(seqNo);
// 0 == timeout count
lsdb2.expressInterest(interestName, 0);
lsdb2.expressInterest(interestName, 0/*= timeout count*/);
advanceClocks(ndn::time::milliseconds(1), 10);
advanceClocks(ndn::time::milliseconds(200), 20);
BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().front().getNpl());
BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().back().getNpl());
}
BOOST_AUTO_TEST_CASE(SegmentLsaData)

9
tests/test-nlsr.cpp

@ -65,6 +65,7 @@ public:
AdjacencyList& neighbors;
uint32_t nSuccessCallbacks;
uint32_t nFailureCallbacks;
ndn::util::signal::ScopedConnection connection;
};
BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
@ -121,7 +122,6 @@ BOOST_AUTO_TEST_CASE(SetEventIntervals)
{
// Simulate loading configuration file
conf.setAdjLsaBuildInterval(3);
conf.setFirstHelloInterval(6);
conf.setRoutingCalcInterval(9);
Nlsr nlsr2(m_face, m_keyChain, conf);
@ -130,7 +130,6 @@ BOOST_AUTO_TEST_CASE(SetEventIntervals)
const RoutingTable& rt = nlsr2.m_routingTable;
BOOST_CHECK_EQUAL(lsdb.m_adjLsaBuildInterval, ndn::time::seconds(3));
BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9));
}
@ -265,6 +264,9 @@ BOOST_AUTO_TEST_CASE(FaceDestroyEvent)
10, Adjacent::STATUS_ACTIVE, 0, 256);
neighbors.insert(otherNeighbor);
// Set HelloInterest lifetime as 10 seconds so that neighbors are not marked INACTIVE
// upon timeout before this test ends
conf.setInterestResendTime(10);
nlsr.initialize();
// Simulate successful HELLO responses
@ -531,9 +533,6 @@ BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch)
conf.setFaceDatasetFetchInterval(fetchInterval);
conf.setFaceDatasetFetchTries(0);
nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1),
std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0));
// Elapse the default timeout time of the interest.
this->advanceClocks(defaultTimeout);

7
tests/test-statistics.cpp

@ -36,15 +36,12 @@ public:
StatisticsFixture()
: face(m_ioService, m_keyChain)
, conf(face)
, confProcessor(conf)
, nlsr(face, m_keyChain, conf)
, lsdb(nlsr.m_lsdb)
, hello(nlsr.m_helloProtocol)
, collector(nlsr.m_statsCollector)
{
conf.setNetwork("/ndn");
conf.setSiteName("/site");
conf.setRouterName("/%C1.Router/this-router");
conf.buildRouterPrefix();
// Otherwise code coverage node fails with default 60 seconds lifetime
conf.setSyncInterestLifetime(1000);
@ -116,6 +113,7 @@ public:
public:
ndn::util::DummyClientFace face;
ConfParameter conf;
DummyConfFileProcessor confProcessor;
Nlsr nlsr;
Lsdb& lsdb;
@ -254,6 +252,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveInterestSendData)
nameLsaKey.append(std::to_string(Lsa::Type::NAME));
NameLsa* nameLsa = lsdb.findNameLsa(nameLsaKey);
BOOST_ASSERT(nameLsa != nullptr);
seqNo = nameLsa->getLsSeqNo();

Loading…
Cancel
Save