Browse Source

**breaking** route: consolidate routing tlv into route

refs: #5116

Plus some misc improvements

Change-Id: Id0902fec65160b4368b1b5066f460433aced98ed
pull/14/head
Ashlesh Gawande 5 years ago
parent
commit
0421bc6bcd
  1. 6
      src/adjacent.cpp
  2. 3
      src/adjacent.hpp
  3. 16
      src/communication/sync-logic-handler.cpp
  4. 8
      src/communication/sync-logic-handler.hpp
  5. 14
      src/conf-file-processor.hpp
  6. 8
      src/lsa/adj-lsa.cpp
  7. 8
      src/lsa/coordinate-lsa.cpp
  8. 6
      src/lsa/lsa.cpp
  9. 6
      src/lsa/name-lsa.cpp
  10. 10
      src/lsdb.cpp
  11. 14
      src/nlsr.cpp
  12. 7
      src/nlsr.hpp
  13. 50
      src/publisher/dataset-interest-handler.cpp
  14. 16
      src/publisher/dataset-interest-handler.hpp
  15. 8
      src/route/fib-entry.cpp
  16. 5
      src/route/fib.hpp
  17. 71
      src/route/map-entry.hpp
  18. 38
      src/route/map.cpp
  19. 22
      src/route/map.hpp
  20. 20
      src/route/name-prefix-table-entry.cpp
  21. 10
      src/route/name-prefix-table-entry.hpp
  22. 6
      src/route/name-prefix-table.cpp
  23. 40
      src/route/nexthop-list.cpp
  24. 28
      src/route/nexthop-list.hpp
  25. 86
      src/route/nexthop.cpp
  26. 43
      src/route/nexthop.hpp
  27. 89
      src/route/routing-table-entry.cpp
  28. 43
      src/route/routing-table-entry.hpp
  29. 129
      src/route/routing-table.cpp
  30. 78
      src/route/routing-table.hpp
  31. 3
      src/tlv-nlsr.hpp
  32. 122
      src/tlv/destination.cpp
  33. 105
      src/tlv/destination.hpp
  34. 123
      src/tlv/nexthop.cpp
  35. 114
      src/tlv/nexthop.hpp
  36. 164
      src/tlv/routing-table-entry.cpp
  37. 156
      src/tlv/routing-table-entry.hpp
  38. 161
      src/tlv/routing-table-status.cpp
  39. 106
      src/tlv/routing-table-status.hpp
  40. 6
      tests/publisher/test-dataset-interest-handler.cpp
  41. 7
      tests/route/test-hyperbolic-calculator.cpp
  42. 7
      tests/route/test-link-state-calculator.cpp
  43. 45
      tests/route/test-map-entry.cpp
  44. 10
      tests/route/test-nexthop-list.cpp
  45. 52
      tests/route/test-nexthop.cpp
  46. 136
      tests/route/test-routing-table-entry.cpp
  47. 107
      tests/route/test-routing-table.cpp
  48. 86
      tests/tlv/test-destination.cpp
  49. 80
      tests/tlv/test-nexthops.cpp
  50. 192
      tests/tlv/test-routing-table-entry.cpp
  51. 168
      tests/tlv/test-routing-table.cpp
  52. 30
      tools/nlsrc.cpp
  53. 8
      tools/nlsrc.hpp

6
src/adjacent.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,11 +16,11 @@
*
* 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 "adjacent.hpp"
#include "logger.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
namespace nlsr {

3
src/adjacent.hpp

@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
* 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.

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

@ -17,7 +17,7 @@
*
* 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 "sync-logic-handler.hpp"
#include "common.hpp"
@ -28,9 +28,6 @@
namespace nlsr {
const std::string NLSR_COMPONENT = "nlsr";
const std::string LSA_COMPONENT = "LSA";
INIT_LOGGER(SyncLogicHandler);
SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew,
@ -49,12 +46,11 @@ SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew,
m_coorLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
.append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE));
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF ||
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_ON) {
m_syncLogic.addUserNode(m_adjLsaUserPrefix);
}
else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON ||
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_syncLogic.addUserNode(m_coorLsaUserPrefix);
}
}
@ -64,8 +60,8 @@ SyncLogicHandler::processUpdate(const ndn::Name& updateName, uint64_t highSeq)
{
NLSR_LOG_DEBUG("Update Name: " << updateName << " Seq no: " << highSeq);
int32_t nlsrPosition = util::getNameComponentPosition(updateName, nlsr::NLSR_COMPONENT);
int32_t lsaPosition = util::getNameComponentPosition(updateName, nlsr::LSA_COMPONENT);
int32_t nlsrPosition = util::getNameComponentPosition(updateName, NLSR_COMPONENT);
int32_t lsaPosition = util::getNameComponentPosition(updateName, LSA_COMPONENT);
if (nlsrPosition < 0 || lsaPosition < 0) {
NLSR_LOG_WARN("Received malformed sync update");

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

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,7 +17,7 @@
*
* 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_SYNC_LOGIC_HANDLER_HPP
#define NLSR_SYNC_LOGIC_HANDLER_HPP
@ -114,8 +114,8 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
SyncProtocolAdapter m_syncLogic;
private:
static const std::string NLSR_COMPONENT;
static const std::string LSA_COMPONENT;
const std::string NLSR_COMPONENT = "nlsr";
const std::string LSA_COMPONENT = "LSA";
};
} // namespace nlsr

14
src/conf-file-processor.hpp

@ -1,7 +1,8 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2019, The University of Memphis,
* Regents of the University of California
/*
* Copyright (c) 2014-2020, 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.
@ -16,7 +17,7 @@
*
* 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_CONF_FILE_PROCESSOR_HPP
#define NLSR_CONF_FILE_PROCESSOR_HPP
@ -39,12 +40,7 @@ using ConfigSection = boost::property_tree::ptree;
* set all the parameters in NLSR to the received values. There are
* defaults for any unconfigured settings.
*
* This is currently called by the wrapper class NlsrRunner to
* populate the NLSR object with its configuration before NLSR is
* started.
*
* \sa nlsr::ConfParameter
* \sa NlsrRunner::run
*/
class ConfFileProcessor
{

8
src/lsa/adj-lsa.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,10 +17,10 @@
*
* 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 "adj-lsa.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
namespace nlsr {
@ -141,4 +141,4 @@ operator<<(std::ostream& os, const AdjLsa& lsa)
return os;
}
} // namespace nlsr
} // namespace nlsr

8
src/lsa/coordinate-lsa.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,10 +17,10 @@
*
* 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 "coordinate-lsa.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
#include <boost/lexical_cast.hpp>
@ -156,4 +156,4 @@ operator<<(std::ostream& os, const CoordinateLsa& lsa)
return os;
}
} // namespace nlsr
} // namespace nlsr

6
src/lsa/lsa.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,13 +17,13 @@
*
* 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 "lsa.hpp"
#include "nlsr.hpp"
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
namespace nlsr {

6
src/lsa/name-lsa.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,10 +17,10 @@
*
* 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 "name-lsa.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
namespace nlsr {

10
src/lsdb.cpp

@ -17,7 +17,7 @@
*
* 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 "lsdb.hpp"
@ -368,9 +368,9 @@ Lsdb::doesNameLsaExist(const ndn::Name& key)
void
Lsdb::writeNameLsdbLog()
{
NLSR_LOG_DEBUG("---------------Name LSDB-------------------");
NLSR_LOG_TRACE("---------------Name LSDB-------------------");
for (const auto& nlsa : m_nameLsdb) {
NLSR_LOG_DEBUG(nlsa);
NLSR_LOG_TRACE(nlsa);
}
}
@ -1247,9 +1247,9 @@ Lsdb::writeAdjLsdbLog()
return;
}
NLSR_LOG_DEBUG("---------------Adj LSDB-------------------");
NLSR_LOG_TRACE("---------------Adj LSDB-------------------");
for (const auto& adj : m_adjLsdb) {
NLSR_LOG_DEBUG(adj);
NLSR_LOG_TRACE(adj);
}
}

14
src/nlsr.cpp

@ -42,16 +42,14 @@ const ndn::Name Nlsr::LOCALHOST_PREFIX = ndn::Name("/localhost/nlsr");
Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
: m_face(face)
, m_scheduler(face.getIoService())
, m_keyChain(keyChain)
, m_confParam(confParam)
, m_adjacencyList(confParam.getAdjacencyList())
, m_namePrefixList(confParam.getNamePrefixList())
, m_validator(m_confParam.getValidator())
, m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, m_keyChain)
, m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, 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_confParam, m_namePrefixTable, m_routingTable)
, m_helloProtocol(m_face, m_keyChain, confParam, m_routingTable, m_lsdb)
, m_lsdb(m_face, keyChain, m_confParam, m_namePrefixTable, m_routingTable)
, m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb)
, m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect(
[this] (const ndn::Name& updateName, uint64_t sequenceNumber,
const ndn::Name& originRouter) {
@ -69,10 +67,10 @@ Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}))
, m_dispatcher(m_face, m_keyChain)
, m_dispatcher(m_face, keyChain)
, m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
, m_controller(m_face, m_keyChain)
, m_faceDatasetController(m_face, m_keyChain)
, m_controller(m_face, keyChain)
, m_faceDatasetController(m_face, keyChain)
, m_prefixUpdateProcessor(m_dispatcher,
m_confParam.getPrefixUpdateValidator(),
m_namePrefixList,

7
src/nlsr.hpp

@ -61,8 +61,6 @@
namespace nlsr {
static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
class Nlsr
{
public:
@ -208,12 +206,9 @@ public:
private:
ndn::Face& m_face;
ndn::Scheduler m_scheduler;
ndn::security::KeyChain& m_keyChain;
ConfParameter& m_confParam;
AdjacencyList& m_adjacencyList;
NamePrefixList& m_namePrefixList;
bool m_isDaemonProcess;
ndn::security::ValidatorConfig& m_validator;
std::vector<ndn::Name> m_strategySetOnRouters;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
@ -248,8 +243,6 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
private:
ndn::nfd::FaceMonitor m_faceMonitor;
friend class NlsrRunner;
};
} // namespace nlsr

50
src/publisher/dataset-interest-handler.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,7 +17,7 @@
*
* 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 "dataset-interest-handler.hpp"
#include "nlsr.hpp"
@ -40,8 +40,7 @@ DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher
const RoutingTable& rt)
: m_dispatcher(dispatcher)
, m_lsdb(lsdb)
, m_routingTableEntries(rt.getRoutingTableEntry())
, m_dryRoutingTableEntries(rt.getDryRoutingTableEntry())
, m_routingTable(rt)
{
setDispatcher(m_dispatcher);
}
@ -93,51 +92,12 @@ DatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn:
context.end();
}
std::vector<tlv::RoutingTable>
DatasetInterestHandler::getTlvRTEntries()
{
std::vector<tlv::RoutingTable> rtable;
for (const auto& rte : m_routingTableEntries) {
tlv::RoutingTable tlvRoutingTable;
std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(rte);
tlvRoutingTable.setDestination(*tlvDes);
for (const auto& nh : rte.getNexthopList().getNextHops()) {
tlv::NextHop tlvNexthop;
tlvNexthop.setUri(nh.getConnectingFaceUri());
tlvNexthop.setCost(nh.getRouteCost());
tlvRoutingTable.addNexthops(tlvNexthop);
}
rtable.push_back(tlvRoutingTable);
}
if (!m_dryRoutingTableEntries.empty()) {
for (const auto& dryRte : m_dryRoutingTableEntries) {
tlv::RoutingTable tlvRoutingTable;
std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(dryRte);
tlvRoutingTable.setDestination(*tlvDes);
for (const auto& nh : dryRte.getNexthopList().getNextHops()) {
tlv::NextHop tlvNexthop;
tlvNexthop.setUri(nh.getConnectingFaceUri());
tlvNexthop.setCost(nh.getRouteCost());
tlvRoutingTable.addNexthops(tlvNexthop);
}
rtable.push_back(tlvRoutingTable);
}
}
return rtable;
}
void
DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
ndn::mgmt::StatusDatasetContext& context)
{
NLSR_LOG_DEBUG("Received interest: " << interest);
tlv::RoutingTableStatus rtStatus;
for (const tlv::RoutingTable& rt : getTlvRTEntries()) {
rtStatus.addRoutingTable(rt);
}
const ndn::Block& wire = rtStatus.wireEncode();
context.append(wire);
NLSR_LOG_DEBUG("Received interest: " << interest);
context.append(m_routingTable.wireEncode());
context.end();
}

16
src/publisher/dataset-interest-handler.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,7 +17,7 @@
*
* 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/>.
**/
*/
/*! \file dataset-interest-handler.hpp
@ -37,9 +37,6 @@
#include "lsdb.hpp"
#include "logger.hpp"
#include "tlv/routing-table-status.hpp"
#include "tlv/routing-table-entry.hpp"
#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/face.hpp>
#include <boost/noncopyable.hpp>
@ -79,11 +76,6 @@ private:
void
setDispatcher(ndn::mgmt::Dispatcher& dispatcher);
/*! \brief generate a TLV-format of routing table entry
*/
std::vector<tlv::RoutingTable>
getTlvRTEntries();
/*! \brief provide routing-table dataset
*/
void
@ -111,9 +103,7 @@ private:
private:
ndn::mgmt::Dispatcher& m_dispatcher;
const Lsdb& m_lsdb;
const std::list<RoutingTableEntry>& m_routingTableEntries;
const std::list<RoutingTableEntry>& m_dryRoutingTableEntries;
const RoutingTable& m_routingTable;
};
} // namespace nlsr

8
src/route/fib-entry.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-2020, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@ -16,7 +16,7 @@
*
* 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 "fib-entry.hpp"
#include "logger.hpp"
@ -30,7 +30,7 @@ FibEntry::writeLog() const
{
NLSR_LOG_DEBUG("Name Prefix: " << m_name);
NLSR_LOG_DEBUG("Seq No: " << m_seqNo);
m_nexthopList.writeLog();
NLSR_LOG_DEBUG(m_nexthopList);
}
} // namespace nlsr

5
src/route/fib.hpp

@ -87,9 +87,6 @@ public:
* strictly necessary, because eventually those prefix registrations
* will expire, but cleaning up after ourselves improves
* performance.
*
* \sa NlsrRunner::run
*
*/
void
clean();
@ -212,8 +209,6 @@ private:
* an entry is removed. Typically this happens when NLSR is
* terminated or crashes, and we don't want the scheduler to crash
* because it's referencing memory that has no valid function.
*
* \sa NlsrRunner::run
*/
void
cancelEntryRefresh(const FibEntry& entry);

71
src/route/map-entry.hpp

@ -1,71 +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_MAP_ENTRY_HPP
#define NLSR_MAP_ENTRY_HPP
#include <boost/cstdint.hpp>
#include <ndn-cxx/name.hpp>
namespace nlsr {
class MapEntry
{
public:
MapEntry()
: m_router()
, m_mappingNumber(-1)
{
}
~MapEntry()
{
}
MapEntry(const ndn::Name& rtr, int32_t mn)
{
m_router = rtr;
m_mappingNumber = mn;
}
const ndn::Name&
getRouter() const
{
return m_router;
}
int32_t
getMappingNumber() const
{
return m_mappingNumber;
}
void
reset();
private:
ndn::Name m_router;
int32_t m_mappingNumber;
};
} // namespace nlsr
#endif // NLSR_MAP_ENTRY_HPP

38
src/route/map.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,7 +16,7 @@
*
* 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 "map.hpp"
#include "nlsr.hpp"
@ -32,7 +32,7 @@ INIT_LOGGER(route.Map);
void
Map::addEntry(const ndn::Name& rtrName)
{
MapEntry me(rtrName, m_mappingIndex);
MapEntry me {rtrName, m_mappingIndex};
if (addEntry(me)) {
m_mappingIndex++;
}
@ -48,43 +48,25 @@ ndn::optional<ndn::Name>
Map::getRouterNameByMappingNo(int32_t mn) const
{
auto&& mappingNumberView = m_entries.get<detail::byMappingNumber>();
auto iterator = mappingNumberView.find(mn);
if (iterator == mappingNumberView.end()) {
return {};
}
else {
return {iterator->getRouter()};
}
auto it = mappingNumberView.find(mn);
return it == mappingNumberView.end() ? ndn::nullopt : ndn::optional<ndn::Name>(it->router);
}
ndn::optional<int32_t>
Map::getMappingNoByRouterName(const ndn::Name& rName)
{
auto&& routerNameView = m_entries.get<detail::byRouterName>();
auto iterator = routerNameView.find(rName);
if (iterator == routerNameView.end()) {
return {};
}
else {
return {iterator->getMappingNumber()};
}
}
void
Map::reset()
{
m_entries = detail::entryContainer{};
m_mappingIndex = 0;
auto it = routerNameView.find(rName);
return it == routerNameView.end() ? ndn::nullopt : ndn::optional<int32_t>(it->mappingNumber);
}
void
Map::writeLog()
{
NLSR_LOG_DEBUG("---------------Map----------------------");
auto&& routerNameView = m_entries.get<detail::byRouterName>();
for (auto entry = routerNameView.begin(); entry != routerNameView.end(); entry++) {
NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry->getRouter() << " Mapping No: "
<< entry->getMappingNumber() << " )");
for (const auto& entry : m_entries.get<detail::byRouterName>()) {
NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry.router << " Mapping No: " <<
entry.mappingNumber << " )");
}
}

22
src/route/map.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,24 +16,25 @@
*
* 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_MAP_HPP
#define NLSR_MAP_HPP
#include "common.hpp"
#include "map-entry.hpp"
#include <list>
#include <boost/cstdint.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/tag.hpp>
namespace nlsr {
struct MapEntry {
ndn::Name router;
int32_t mappingNumber = -1;
};
namespace detail {
using namespace boost::multi_index;
@ -44,10 +45,10 @@ namespace detail {
MapEntry,
indexed_by<
hashed_unique<tag<byRouterName>,
const_mem_fun<MapEntry, const ndn::Name&, &MapEntry::getRouter>,
member<MapEntry, ndn::Name, &MapEntry::router>,
std::hash<ndn::Name>>,
hashed_unique<tag<byMappingNumber>,
const_mem_fun<MapEntry, int32_t, &MapEntry::getMappingNumber>>
member<MapEntry, int32_t, &MapEntry::mappingNumber>>
>
>;
@ -107,9 +108,6 @@ public:
ndn::optional<int32_t>
getMappingNoByRouterName(const ndn::Name& rName);
void
reset();
size_t
getMapSize() const
{

20
src/route/name-prefix-table-entry.cpp

@ -17,7 +17,7 @@
*
* 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 "name-prefix-table-entry.hpp"
@ -32,7 +32,7 @@ INIT_LOGGER(route.NamePrefixTableEntry);
void
NamePrefixTableEntry::generateNhlfromRteList()
{
m_nexthopList.reset();
m_nexthopList.clear();
for (auto iterator = m_rteList.begin(); iterator != m_rteList.end(); ++iterator) {
for (auto nhItr = (*iterator)->getNexthopList().getNextHops().begin();
nhItr != (*iterator)->getNexthopList().getNextHops().end();
@ -76,18 +76,6 @@ NamePrefixTableEntry::addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry
// be updated there.
}
void
NamePrefixTableEntry::writeLog()
{
NLSR_LOG_DEBUG("Name: " << m_namePrefix);
for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) {
NLSR_LOG_DEBUG("Destination: " << (*it)->getDestination());
NLSR_LOG_DEBUG("Nexthops: ");
(*it)->getNexthopList().writeLog();
}
m_nexthopList.writeLog();
}
bool
operator==(const NamePrefixTableEntry& lhs, const NamePrefixTableEntry& rhs)
{
@ -104,8 +92,10 @@ std::ostream&
operator<<(std::ostream& os, const NamePrefixTableEntry& entry)
{
os << "Name: " << entry.getNamePrefix() << "\n";
for (const auto& entryPtr : entry.getRteList()) {
os << "Destination: " << entryPtr->getDestination() << "\n";
os << " Destination: " << entryPtr->getDestination() << "\n";
os << entryPtr->getNexthopList();
}
return os;
}

10
src/route/name-prefix-table-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-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@ -17,13 +17,12 @@
*
* 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_NAME_PREFIX_TABLE_ENTRY_HPP
#define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
#include "routing-table-pool-entry.hpp"
#include "test-access-control.hpp"
#include <list>
@ -64,7 +63,7 @@ public:
{
if (m_rteList.size() > 0) {
for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) {
(*it)->getNexthopList().reset();
(*it)->getNexthopList().clear();
}
}
}
@ -112,7 +111,6 @@ private:
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::list<std::shared_ptr<RoutingTablePoolEntry>> m_rteList;
NexthopList m_nexthopList;
};
bool

6
src/route/name-prefix-table.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,7 +17,7 @@
*
* 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 "name-prefix-table.hpp"
@ -228,7 +228,7 @@ NamePrefixTable::updateWithNewRoute(const std::list<RoutingTableEntry>& entries)
}
else if (sourceEntry == entries.end()) {
NLSR_LOG_DEBUG("Routing entry: " << poolEntry->getDestination() << " now has no next-hops.");
poolEntry->getNexthopList().reset();
poolEntry->getNexthopList().clear();
for (const auto& nameEntry : poolEntry->namePrefixTableEntries) {
auto nameEntryFullPtr = nameEntry.second.lock();
addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());

40
src/route/nexthop-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-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@ -17,16 +17,15 @@
*
* 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 "nexthop-list.hpp"
#include "common.hpp"
#include "nexthop.hpp"
#include "logger.hpp"
namespace nlsr {
#include <ndn-cxx/util/ostream-joiner.hpp>
INIT_LOGGER(route.NexthopList);
namespace nlsr {
static bool
nexthopAddCompare(const NextHop& nh1, const NextHop& nh2)
@ -71,21 +70,16 @@ operator!=(const NexthopList& lhs, const NexthopList& rhs)
std::ostream&
operator<<(std::ostream& os, const NexthopList& nhl)
{
NexthopList& ucnhl = const_cast<NexthopList&>(nhl);
os << "NexthopList(\nNext hops: ";
for (auto&& nh : ucnhl.getNextHops()) {
os << nh;
}
os << ")";
os << " ";
std::copy(nhl.cbegin(), nhl.cend(), ndn::make_ostream_joiner(os, "\n "));
return os;
}
void
NexthopList::addNextHop(const NextHop& nh)
{
std::set<NextHop, NextHopComparator>::iterator it = std::find_if(m_nexthopList.begin(),
m_nexthopList.end(),
std::bind(&nexthopAddCompare, _1, nh));
auto it = std::find_if(m_nexthopList.begin(), m_nexthopList.end(),
std::bind(&nexthopAddCompare, _1, nh));
if (it == m_nexthopList.end()) {
m_nexthopList.insert(nh);
}
@ -98,23 +92,11 @@ NexthopList::addNextHop(const NextHop& nh)
void
NexthopList::removeNextHop(const NextHop& nh)
{
std::set<NextHop, NextHopComparator>::iterator it = std::find_if(m_nexthopList.begin(),
m_nexthopList.end(),
std::bind(&nexthopRemoveCompare, _1, nh));
auto it = std::find_if(m_nexthopList.begin(), m_nexthopList.end(),
std::bind(&nexthopRemoveCompare, _1, nh));
if (it != m_nexthopList.end()) {
m_nexthopList.erase(it);
}
}
void
NexthopList::writeLog() const
{
int i = 1;
for (const auto& nexthop : m_nexthopList) {
NLSR_LOG_DEBUG("Nexthop " << i++ << ": " << nexthop.getConnectingFaceUri() <<
" Route Cost: " << nexthop.getRouteCost());
}
}
} // namespace nlsr

28
src/route/nexthop-list.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,7 +16,7 @@
*
* 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_NEXTHOP_LIST_HPP
#define NLSR_NEXTHOP_LIST_HPP
@ -47,13 +47,7 @@ struct NextHopComparator {
class NexthopList
{
public:
NexthopList()
{
}
~NexthopList()
{
}
NexthopList() = default;
/*! \brief Adds a next hop to the list.
\param nh The next hop.
@ -80,7 +74,7 @@ public:
}
void
reset()
clear()
{
m_nexthopList.clear();
}
@ -93,6 +87,7 @@ public:
typedef std::set<NextHop, NextHopComparator>::iterator iterator;
typedef std::set<NextHop, NextHopComparator>::const_iterator const_iterator;
typedef std::set<NextHop, NextHopComparator>::reverse_iterator reverse_iterator;
iterator
begin()
@ -118,8 +113,17 @@ public:
return m_nexthopList.end();
}
void
writeLog() const;
reverse_iterator
rbegin() const
{
return m_nexthopList.rbegin();
}
reverse_iterator
rend() const
{
return m_nexthopList.rend();
}
private:
std::set<NextHop, NextHopComparator> m_nexthopList;

86
src/route/nexthop.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-2020, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@ -16,29 +16,91 @@
*
* 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 "nexthop.hpp"
#include "tlv-nlsr.hpp"
#include <ndn-cxx/encoding/block-helpers.hpp>
namespace nlsr {
template<ndn::encoding::Tag TAG>
size_t
NextHop::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
totalLength += ndn::encoding::prependDoubleBlock(block, ndn::tlv::nlsr::CostDouble, m_routeCost);
totalLength += ndn::encoding::prependStringBlock(block, ndn::tlv::nlsr::Uri, m_connectingFaceUri);
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::NextHop);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(NextHop);
const ndn::Block&
NextHop::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
NextHop::wireDecode(const ndn::Block& wire)
{
m_connectingFaceUri = "";
m_routeCost = 0;
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::NextHop) {
std::stringstream error;
error << "Expected NextHop Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
ndn::Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Uri) {
m_connectingFaceUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
++val;
}
else {
BOOST_THROW_EXCEPTION(Error("Missing required Uri field"));
}
m_routeCost = ndn::encoding::readDouble(*val);
}
bool
operator==(const NextHop& lhs, const NextHop& rhs)
{
return ((lhs.getRouteCostAsAdjustedInteger() == rhs.getRouteCostAsAdjustedInteger())
&&
(lhs.getConnectingFaceUri() == rhs.getConnectingFaceUri()));
return (lhs.getRouteCostAsAdjustedInteger() == rhs.getRouteCostAsAdjustedInteger()) &&
(lhs.getConnectingFaceUri() == rhs.getConnectingFaceUri());
}
std::ostream&
operator<<(std::ostream& os, const NextHop& hop)
{
os << "Nexthop("
<< "face-uri: " << hop.getConnectingFaceUri()
<< ", cost: " << hop.getRouteCost() << ")";
os << "NextHop(Uri: " << hop.getConnectingFaceUri() << ", Cost: " << hop.getRouteCost() << ")";
return os;
}

43
src/route/nexthop.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,22 +16,36 @@
*
* 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_ROUTE_NEXTHOP_HPP
#define NLSR_ROUTE_NEXTHOP_HPP
#include "test-access-control.hpp"
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <iostream>
#include <cmath>
#include <boost/cstdint.hpp>
namespace nlsr {
/*! \brief Data abstraction for Nexthop
*
* NextHop := NEXTHOP-TYPE TLV-LENGTH
* Uri
* Cost
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
*/
class NextHop
{
public:
using Error = ndn::tlv::Error;
NextHop()
: m_connectingFaceUri()
, m_routeCost(0)
@ -40,10 +54,15 @@ public:
}
NextHop(const std::string& cfu, double rc)
: m_isHyperbolic(false)
: m_connectingFaceUri(cfu)
, m_routeCost(rc)
, m_isHyperbolic(false)
{
m_connectingFaceUri = cfu;
m_routeCost = rc;
}
NextHop(const ndn::Block& block)
{
wireDecode(block);
}
const std::string&
@ -96,11 +115,23 @@ public:
return m_isHyperbolic;
}
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
private:
std::string m_connectingFaceUri;
double m_routeCost;
bool m_isHyperbolic;
mutable ndn::Block m_wire;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Used to adjust floating point route costs to integers
Since NFD uses integer route costs in the FIB, hyperbolic paths with similar route costs
@ -115,6 +146,8 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
static const uint64_t HYPERBOLIC_COST_ADJUSTMENT_FACTOR = 1000;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHop);
bool
operator==(const NextHop& lhs, const NextHop& rhs);

89
src/route/routing-table-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-2020, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@ -16,19 +16,96 @@
*
* 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 "routing-table-entry.hpp"
#include "nexthop-list.hpp"
#include "tlv-nlsr.hpp"
namespace nlsr {
template<ndn::encoding::Tag TAG>
size_t
RoutingTableEntry::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
for (auto it = m_nexthopList.rbegin(); it != m_nexthopList.rend(); ++it) {
totalLength += it->wireEncode(block);
}
totalLength += m_destination.wireEncode(block);
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::RoutingTableEntry);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(RoutingTableEntry);
const ndn::Block&
RoutingTableEntry::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
RoutingTableEntry::wireDecode(const ndn::Block& wire)
{
m_nexthopList.clear();
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::RoutingTableEntry) {
std::stringstream error;
error << "Expected RoutingTable Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
auto val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
m_destination.wireDecode(*val);
++val;
}
else {
BOOST_THROW_EXCEPTION(Error("Missing required destination field"));
}
for (; val != m_wire.elements_end(); ++val) {
if (val->type() == ndn::tlv::nlsr::NextHop) {
m_nexthopList.addNextHop(NextHop(*val));
}
else {
std::stringstream error;
error << "Expected NextHop Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
}
}
std::ostream&
operator<<(std::ostream& os, const RoutingTableEntry& rte)
{
os << "RoutingTableEntry("
<< "Destination: " << rte.getDestination()
<< "Next hop list: " << rte.getNexthopList() << ")";
os << " Destination: " << rte.getDestination() << "\n"
<< rte.getNexthopList() << "\n";
return os;
}

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

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,27 +16,38 @@
*
* 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_ROUTING_TABLE_ENTRY_HPP
#define NLSR_ROUTING_TABLE_ENTRY_HPP
#include "nexthop-list.hpp"
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/name.hpp>
namespace nlsr {
/*! \brief Data abstraction for RouteTableInfo
*
* RoutingTableEntry := ROUTINGTABLEENTRY-TYPE TLV-LENGTH
* Name
* NexthopList*
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet
*/
class RoutingTableEntry
{
public:
RoutingTableEntry()
{
}
using Error = ndn::tlv::Error;
RoutingTableEntry() = default;
~RoutingTableEntry()
RoutingTableEntry(const ndn::Block& block)
{
wireDecode(block);
}
RoutingTableEntry(const ndn::Name& dest)
@ -65,15 +76,29 @@ public:
inline bool
operator==(RoutingTableEntry& rhs)
{
return ((*this).getDestination() == rhs.getDestination() &&
(*this).getNexthopList() == rhs.getNexthopList());
return m_destination == rhs.getDestination() &&
m_nexthopList == rhs.getNexthopList();
}
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
protected:
ndn::Name m_destination;
NexthopList m_nexthopList;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RoutingTableEntry);
std::ostream&
operator<<(std::ostream& os, const RoutingTableEntry& rte);

129
src/route/routing-table.cpp

@ -16,7 +16,7 @@
*
* 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 "routing-table.hpp"
#include "nlsr.hpp"
@ -26,6 +26,7 @@
#include "routing-table-entry.hpp"
#include "name-prefix-table.hpp"
#include "logger.hpp"
#include "tlv-nlsr.hpp"
#include <list>
#include <string>
@ -94,24 +95,22 @@ RoutingTable::calculate()
// Inform the NPT that updates have been made
NLSR_LOG_DEBUG("Calling Update NPT With new Route");
(*afterRoutingChange)(m_rTable);
writeLog();
NLSR_LOG_DEBUG(*this);
m_namePrefixTable.writeLog();
m_fib.writeLog();
}
else {
NLSR_LOG_DEBUG("Adjacency building is scheduled, so"
" routing table can not be calculated :(");
NLSR_LOG_DEBUG("Adjacency building is scheduled, so routing table can not be calculated :(");
}
}
else {
NLSR_LOG_DEBUG("No Adj LSA of router itself,"
" so Routing table can not be calculated :(");
NLSR_LOG_DEBUG("No Adj LSA of router itself, so Routing table can not be calculated :(");
clearRoutingTable();
clearDryRoutingTable(); // for dry run options
// need to update NPT here
NLSR_LOG_DEBUG("Calling Update NPT With new Route");
(*afterRoutingChange)(m_rTable);
writeLog();
NLSR_LOG_DEBUG(*this);
m_namePrefixTable.writeLog();
m_fib.writeLog();
// debugging purpose end
@ -198,26 +197,6 @@ RoutingTable::findRoutingTableEntry(const ndn::Name& destRouter)
return nullptr;
}
void
RoutingTable::writeLog()
{
NLSR_LOG_DEBUG("---------------Routing Table------------------");
for (const auto& rte : m_rTable) {
NLSR_LOG_DEBUG("Destination: " << rte.getDestination());
NLSR_LOG_DEBUG("Nexthops: ");
rte.getNexthopList().writeLog();
}
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
NLSR_LOG_DEBUG("--------Hyperbolic Routing Table(Dry)---------");
for (const auto& rte : m_dryTable) {
NLSR_LOG_DEBUG("Destination: " << rte.getDestination());
NLSR_LOG_DEBUG("Nexthops: ");
rte.getNexthopList().writeLog();
}
}
}
void
RoutingTable::addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh)
{
@ -251,4 +230,100 @@ RoutingTable::clearDryRoutingTable()
}
}
template<ndn::encoding::Tag TAG>
size_t
RoutingTableStatus::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
for (auto it = m_dryTable.rbegin(); it != m_dryTable.rend(); ++it) {
totalLength += it->wireEncode(block);
}
for (auto it = m_rTable.rbegin(); it != m_rTable.rend(); ++it) {
totalLength += it->wireEncode(block);
}
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::RoutingTable);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(RoutingTableStatus);
const ndn::Block&
RoutingTableStatus::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
RoutingTableStatus::wireDecode(const ndn::Block& wire)
{
m_rTable.clear();
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::RoutingTable) {
std::stringstream error;
error << "Expected RoutingTableStatus Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
auto val = m_wire.elements_begin();
std::set<ndn::Name> destinations;
for (; val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::RoutingTableEntry; ++val) {
auto entry = RoutingTableEntry(*val);
if (destinations.emplace(entry.getDestination()).second) {
m_rTable.push_back(entry);
}
else {
// If destination already exists then this is the start of dry HR table
m_dryTable.push_back(entry);
}
}
if (val != m_wire.elements_end()) {
std::stringstream error;
error << "Expected the end of elements, but Block is of a different type: #"
<< val->type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
}
std::ostream&
operator<<(std::ostream& os, const RoutingTableStatus& rts)
{
os << "Routing Table:\n";
for (const auto& rte : rts.getRoutingTableEntry()) {
os << rte;
}
if (!rts.getDryRoutingTableEntry().empty()) {
os << "Dry-Run Hyperbolic Routing Table:\n";
for (const auto& rte : rts.getDryRoutingTableEntry()) {
os << rte;
}
}
return os;
}
} // namespace nlsr

78
src/route/routing-table.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,8 +16,7 @@
*
* 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_ROUTING_TABLE_HPP
#define NLSR_ROUTING_TABLE_HPP
@ -35,7 +34,58 @@ namespace nlsr {
class NextHop;
class RoutingTable : boost::noncopyable
/*! \brief Data abstraction for routing table status
*
* RtStatus := RT-STATUS-TYPE TLV-LENGTH
* RouteTableEntry*
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
*/
class RoutingTableStatus
{
public:
using Error = ndn::tlv::Error;
RoutingTableStatus() = default;
RoutingTableStatus(const ndn::Block& block)
{
wireDecode(block);
}
const std::list<RoutingTableEntry>&
getRoutingTableEntry() const
{
return m_rTable;
}
const std::list<RoutingTableEntry>&
getDryRoutingTableEntry() const
{
return m_dryTable;
}
const ndn::Block&
wireEncode() const;
private:
void
wireDecode(const ndn::Block& wire);
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
PUBLIC_WITH_TESTS_ELSE_PROTECTED:
std::list<RoutingTableEntry> m_dryTable;
std::list<RoutingTableEntry> m_rTable;
mutable ndn::Block m_wire;
};
std::ostream&
operator<<(std::ostream& os, const RoutingTableStatus& rts);
class RoutingTable : public RoutingTableStatus
{
public:
explicit
@ -84,18 +134,6 @@ public:
return m_routingCalcInterval;
}
const std::list<RoutingTableEntry>&
getRoutingTableEntry() const
{
return m_rTable;
}
const std::list<RoutingTableEntry>&
getDryRoutingTableEntry() const
{
return m_dryTable;
}
uint64_t
getRtSize()
{
@ -117,23 +155,15 @@ private:
void
clearDryRoutingTable();
void
writeLog();
public:
std::unique_ptr<AfterRoutingChange> afterRoutingChange;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::list<RoutingTableEntry> m_rTable;
private:
ndn::Scheduler& m_scheduler;
Fib& m_fib;
Lsdb& m_lsdb;
NamePrefixTable& m_namePrefixTable;
std::list<RoutingTableEntry> m_dryTable;
ndn::time::seconds m_routingCalcInterval;
bool m_isRoutingTableCalculating;

3
src/tlv/tlv-nlsr.hpp → src/tlv-nlsr.hpp

@ -17,7 +17,7 @@
*
* 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_TLV_NLSR_HPP
#define NLSR_TLV_NLSR_HPP
@ -47,7 +47,6 @@ enum {
ExpirationTime = 139,
Cost = 140,
Uri = 141,
Destination = 142,
NextHop = 143,
RoutingTable = 144,
RoutingTableEntry = 145

122
src/tlv/destination.cpp

@ -1,122 +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,
* 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 "destination.hpp"
#include "tlv-nlsr.hpp"
#include <ndn-cxx/util/concepts.hpp>
#include <ndn-cxx/encoding/block-helpers.hpp>
namespace nlsr {
namespace tlv {
BOOST_CONCEPT_ASSERT((ndn::WireEncodable<Destination>));
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<Destination>));
static_assert(std::is_base_of<ndn::tlv::Error, Destination::Error>::value,
"Destination::Error must inherit from tlv::Error");
Destination::Destination() = default;
Destination::Destination(const ndn::Block& block)
{
wireDecode(block);
}
template<ndn::encoding::Tag TAG>
size_t
Destination::wireEncode(ndn::EncodingImpl<TAG>& encoder) const
{
size_t totalLength = 0;
totalLength += m_name.wireEncode(encoder);
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::Destination);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Destination);
const ndn::Block&
Destination::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
Destination::wireDecode(const ndn::Block& wire)
{
m_name.clear();
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::Destination) {
std::stringstream error;
error << "Expected Destination Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
ndn::Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
m_name.wireDecode(*val);
++val;
}
else {
BOOST_THROW_EXCEPTION(Error("Missing required Name field"));
}
}
std::ostream&
operator<<(std::ostream& os, const Destination& Destination)
{
os << "Destination: " << Destination.getName();
return os;
}
std::shared_ptr<Destination>
makeDes(const RoutingTableEntry& rte)
{
std::shared_ptr<Destination> desInfo = std::make_shared<Destination>();
desInfo->setName(rte.getDestination());
return desInfo;
}
} // namespace tlv
} // namespace nlsr

105
src/tlv/destination.hpp

@ -1,105 +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,
* 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_TLV_DESTINATION_HPP
#define NLSR_TLV_DESTINATION_HPP
#include "route/routing-table-entry.hpp"
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/name.hpp>
#include <boost/throw_exception.hpp>
#include <list>
namespace nlsr {
namespace tlv {
/*! \brief Data abstraction for Destination
*
* Destination := DESTINATION-TYPE TLV-LENGTH
* Name
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet
*/
class Destination
{
public:
class Error : public ndn::tlv::Error
{
public:
explicit
Error(const std::string& what)
: ndn::tlv::Error(what)
{
}
};
Destination();
explicit
Destination(const ndn::Block& block);
const ndn::Name&
getName() const
{
return m_name;
}
Destination&
setName(const ndn::Name& name)
{
m_name = name;
m_wire.reset();
return *this;
}
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
private:
ndn::Name m_name;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Destination);
std::ostream&
operator<<(std::ostream& os, const Destination& destination);
std::shared_ptr<Destination>
makeDes(const RoutingTableEntry& rte);
} // namespace tlv
} // namespace nlsr
#endif // NLSR_TLV_DESTINATION_HPP

123
src/tlv/nexthop.cpp

@ -1,123 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, 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 "nexthop.hpp"
#include "tlv-nlsr.hpp"
#include <ndn-cxx/util/concepts.hpp>
#include <ndn-cxx/encoding/block-helpers.hpp>
namespace nlsr {
namespace tlv {
BOOST_CONCEPT_ASSERT((ndn::WireEncodable<NextHop>));
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<NextHop>));
static_assert(std::is_base_of<ndn::tlv::Error, NextHop::Error>::value,
"NextHop::Error must inherit from tlv::Error");
NextHop::NextHop()
: m_cost(0)
{
}
NextHop::NextHop(const ndn::Block& block)
{
wireDecode(block);
}
template<ndn::encoding::Tag TAG>
size_t
NextHop::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
totalLength += ndn::encoding::prependDoubleBlock(block, ndn::tlv::nlsr::CostDouble, m_cost);
totalLength += block.prependByteArrayBlock(
ndn::tlv::nlsr::Uri, reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size());
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::NextHop);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(NextHop);
const ndn::Block&
NextHop::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
NextHop::wireDecode(const ndn::Block& wire)
{
m_uri = "";
m_cost = 0;
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::NextHop) {
std::stringstream error;
error << "Expected NextHop Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
ndn::Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Uri) {
m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
++val;
}
else {
BOOST_THROW_EXCEPTION(Error("Missing required Uri field"));
}
m_cost = ndn::encoding::readDouble(*val);
}
std::ostream&
operator<<(std::ostream& os, const NextHop& nexthop)
{
os << "NextHop("
<< "Uri: " << nexthop.getUri() << ", "<< "Cost: " << nexthop.getCost() << ")" << std::endl;
return os;
}
} // namespace tlv
} // namespace nlsr

114
src/tlv/nexthop.hpp

@ -1,114 +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,
* 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_TLV_NEXTHOP_HPP
#define NLSR_TLV_NEXTHOP_HPP
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/name.hpp>
#include <boost/throw_exception.hpp>
namespace nlsr {
namespace tlv {
/*! \brief Data abstraction for Nexthop
*
* NextHop := NEXTHOP-TYPE TLV-LENGTH
* Uri
* Cost
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
*/
class NextHop
{
public:
class Error : public ndn::tlv::Error
{
public:
explicit
Error(const std::string& what)
: ndn::tlv::Error(what)
{
}
};
NextHop();
explicit
NextHop(const ndn::Block& block);
const std::string&
getUri() const
{
return m_uri;
}
NextHop&
setUri(const std::string& uri)
{
m_uri = uri;
m_wire.reset();
return *this;
}
double
getCost() const
{
return m_cost;
}
NextHop&
setCost(double cost)
{
m_cost = cost;
m_wire.reset();
return *this;
}
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
private:
std::string m_uri;
double m_cost;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHop);
std::ostream&
operator<<(std::ostream& os, const NextHop& nexthop);
} // namespace tlv
} // namespace nlsr
#endif // NLSR_TLV_NEXTHOP_HPP

164
src/tlv/routing-table-entry.cpp

@ -1,164 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "routing-table-entry.hpp"
#include "tlv-nlsr.hpp"
#include <ndn-cxx/util/concepts.hpp>
#include <ndn-cxx/encoding/block-helpers.hpp>
namespace nlsr {
namespace tlv {
BOOST_CONCEPT_ASSERT((ndn::WireEncodable<RoutingTable>));
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<RoutingTable>));
static_assert(std::is_base_of<ndn::tlv::Error, RoutingTable::Error>::value,
"RoutingTable::Error must inherit from tlv::Error");
RoutingTable::RoutingTable()
: m_hasNexthops(false)
{
}
RoutingTable::RoutingTable(const ndn::Block& block)
{
wireDecode(block);
}
bool
RoutingTable::hasNexthops() const
{
return m_hasNexthops;
}
RoutingTable&
RoutingTable::addNexthops(const NextHop& nexthop)
{
m_nexthops.push_back(nexthop);
m_wire.reset();
m_hasNexthops = true;
return *this;
}
RoutingTable&
RoutingTable::clearNexthops()
{
m_nexthops.clear();
m_hasNexthops = false;
return *this;
}
template<ndn::encoding::Tag TAG>
size_t
RoutingTable::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
for (std::list<NextHop>::const_reverse_iterator it = m_nexthops.rbegin();
it != m_nexthops.rend(); ++it) {
totalLength += it->wireEncode(block);
}
totalLength += m_des.wireEncode(block);
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::RoutingTableEntry);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(RoutingTable);
const ndn::Block&
RoutingTable::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
RoutingTable::wireDecode(const ndn::Block& wire)
{
m_hasNexthops = false;
m_nexthops.clear();
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::RoutingTableEntry) {
std::stringstream error;
error << "Expected RoutingTable Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
ndn::Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Destination) {
m_des.wireDecode(*val);
++val;
}
else {
BOOST_THROW_EXCEPTION(Error("Missing required destination field"));
}
for (; val != m_wire.elements_end(); ++val) {
if (val->type() == ndn::tlv::nlsr::NextHop) {
m_nexthops.push_back(NextHop(*val));
m_hasNexthops = true;
}
else {
std::stringstream error;
error << "Expected NextHop Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
}
}
std::ostream&
operator<<(std::ostream& os, const RoutingTable& routingtable)
{
os << routingtable.getDestination() << std::endl;
os << "NexthopList(" << std::endl;
for (const auto& rtentry : routingtable) {
os << rtentry;
}
os << ")";
return os;
}
} // namespace tlv
} // namespace nlsr

156
src/tlv/routing-table-entry.hpp

@ -1,156 +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,
* 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_TLV_ROUTING_TABLE_ENTRY_HPP
#define NLSR_TLV_ROUTING_TABLE_ENTRY_HPP
#include "destination.hpp"
#include "nexthop.hpp"
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/name.hpp>
#include <list>
namespace nlsr {
namespace tlv {
/*! \brief Data abstraction for RouteTableInfo
*
* RouteTableInfo := ROUTINGTABLE-TYPE TLV-LENGTH
* Destination
* NexthopList*
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet
*/
class RoutingTable
{
public:
class Error : public ndn::tlv::Error
{
public:
explicit
Error(const std::string& what)
: ndn::tlv::Error(what)
{
}
};
typedef std::list<NextHop> HopList;
typedef HopList::const_iterator const_iterator;
RoutingTable();
explicit
RoutingTable(const ndn::Block& block);
const Destination&
getDestination() const
{
return m_des;
}
RoutingTable&
setDestination(const Destination& des)
{
m_des = des;
m_wire.reset();
return *this;
}
uint64_t
getRtSize() const
{
return m_size;
}
RoutingTable&
setRtSize(uint64_t size)
{
m_size = size;
m_wire.reset();
return *this;
}
bool
hasNexthops() const;
const std::list<NextHop>&
getNextHops() const
{
return m_nexthops;
}
RoutingTable&
addNexthops(const NextHop& nexthop);
RoutingTable&
clearNexthops();
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
const_iterator
begin() const;
const_iterator
end() const;
private:
Destination m_des;
uint64_t m_size;
bool m_hasNexthops;
HopList m_nexthops;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RoutingTable);
inline RoutingTable::const_iterator
RoutingTable::begin() const
{
return m_nexthops.begin();
}
inline RoutingTable::const_iterator
RoutingTable::end() const
{
return m_nexthops.end();
}
std::ostream&
operator<<(std::ostream& os, const RoutingTable& routetable);
} // namespace tlv
} // namespace nlsr
#endif // NLSR_TLV_ROUTING_TABLE_ENTRY_HPP

161
src/tlv/routing-table-status.cpp

@ -1,161 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "routing-table-status.hpp"
#include "tlv-nlsr.hpp"
#include <ndn-cxx/util/concepts.hpp>
#include <ndn-cxx/encoding/block-helpers.hpp>
namespace nlsr {
namespace tlv {
BOOST_CONCEPT_ASSERT((ndn::WireEncodable<RoutingTableStatus>));
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<RoutingTableStatus>));
static_assert(std::is_base_of<ndn::tlv::Error, RoutingTableStatus::Error>::value,
"RoutingTableStatus::Error must inherit from tlv::Error");
RoutingTableStatus::RoutingTableStatus()
: m_hasRoutingtable(false)
{
}
RoutingTableStatus::RoutingTableStatus(const ndn::Block& block)
{
wireDecode(block);
}
RoutingTableStatus&
RoutingTableStatus::addRoutingTable(const RoutingTable& routetable)
{
m_routingtables.push_back(routetable);
m_wire.reset();
m_hasRoutingtable = true;
return *this;
}
RoutingTableStatus&
RoutingTableStatus::clearRoutingTable()
{
m_routingtables.clear();
m_hasRoutingtable = false;
return *this;
}
bool
RoutingTableStatus::hasRoutingTable()
{
return m_hasRoutingtable;
}
template<ndn::encoding::Tag TAG>
size_t
RoutingTableStatus::wireEncode(ndn::EncodingImpl<TAG>& block) const
{
size_t totalLength = 0;
for (std::list<RoutingTable>::const_reverse_iterator it = m_routingtables.rbegin();
it != m_routingtables.rend(); ++it) {
totalLength += it->wireEncode(block);
}
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(ndn::tlv::nlsr::RoutingTable);
return totalLength;
}
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(RoutingTableStatus);
const ndn::Block&
RoutingTableStatus::wireEncode() const
{
if (m_wire.hasWire()) {
return m_wire;
}
ndn::EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
ndn::EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
void
RoutingTableStatus::wireDecode(const ndn::Block& wire)
{
m_routingtables.clear();
m_hasRoutingtable = false;
m_wire = wire;
if (m_wire.type() != ndn::tlv::nlsr::RoutingTable) {
std::stringstream error;
error << "Expected RoutingTableStatus Block, but Block is of a different type: #"
<< m_wire.type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
m_wire.parse();
ndn::Block::element_const_iterator val = m_wire.elements_begin();
for (; val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::RoutingTableEntry; ++val) {
m_routingtables.push_back(RoutingTable(*val));
m_hasRoutingtable = true;
}
if (val != m_wire.elements_end()) {
std::stringstream error;
error << "Expected the end of elements, but Block is of a different type: #"
<< val->type();
BOOST_THROW_EXCEPTION(Error(error.str()));
}
}
std::ostream&
operator<<(std::ostream& os, const RoutingTableStatus& rtStatus)
{
os << "Routing Table Status: " << std::endl;
bool isFirst = true;
for (const auto& routingtable : rtStatus.getRoutingtable()) {
if (isFirst) {
isFirst = false;
}
else {
os << ", ";
}
os << routingtable;
}
return os;
}
} // namespace tlv
} // namespace nlsr

106
src/tlv/routing-table-status.hpp

@ -1,106 +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,
* 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_TLV_ROUTING_TABLE_STATUS_HPP
#define NLSR_TLV_ROUTING_TABLE_STATUS_HPP
#include "routing-table-entry.hpp"
#include "destination.hpp"
#include <ndn-cxx/util/time.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/encoding-buffer.hpp>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/name.hpp>
#include <list>
namespace nlsr {
namespace tlv {
/*! \brief Data abstraction for routing table status
*
* RtStatus := RT-STATUS-TYPE TLV-LENGTH
* RouteTableInfo*
*
* \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
*/
class RoutingTableStatus
{
public:
class Error : public ndn::tlv::Error
{
public:
explicit
Error(const std::string& what)
: ndn::tlv::Error(what)
{
}
};
typedef std::list<RoutingTable> RTList;
RoutingTableStatus();
explicit
RoutingTableStatus(const ndn::Block& block);
const std::list<RoutingTable>&
getRoutingtable() const
{
return m_routingtables;
}
RoutingTableStatus&
addRoutingTable(const RoutingTable& routeTable);
RoutingTableStatus&
clearRoutingTable();
bool
hasRoutingTable();
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
const ndn::Block&
wireEncode() const;
void
wireDecode(const ndn::Block& wire);
private:
RTList m_routingtables;
bool m_hasRoutingtable;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RoutingTableStatus);
std::ostream&
operator<<(std::ostream& os, const RoutingTableStatus& rtStatus);
} // namespace tlv
} // namespace nlsr
#endif // NLSR_TLV_ROUTING_TABLE_STATUS_HPP

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

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,10 +17,10 @@
*
* 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 "publisher/dataset-interest-handler.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "tlv-nlsr.hpp"
#include "tests/test-common.hpp"
#include "publisher-fixture.hpp"

7
tests/test-hyperbolic-calculator.cpp → tests/route/test-hyperbolic-calculator.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,14 +17,13 @@
*
* 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 "test-common.hpp"
#include "../test-common.hpp"
#include "route/routing-table-calculator.hpp"
#include "adjacency-list.hpp"
//#include "lsa.hpp"
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "route/map.hpp"

7
tests/test-link-state-calculator.cpp → tests/route/test-link-state-calculator.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,15 +17,14 @@
*
* 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 "route/routing-table-calculator.hpp"
#include "adjacency-list.hpp"
//#include "lsa.hpp"
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "test-common.hpp"
#include "../test-common.hpp"
#include "route/map.hpp"
#include "route/routing-table.hpp"
#include "adjacent.hpp"

45
tests/route/test-map-entry.cpp

@ -1,45 +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
*
* 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 Ashlesh Gawande <agawande@memphis.edu>
**/
#include "route/map.hpp"
#include "tests/boost-test.hpp"
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestMapEntry)
BOOST_AUTO_TEST_CASE(MapEntryConstructorAndGetters)
{
std::string rtr = "r0";
MapEntry me1(rtr, 1);
BOOST_CHECK_EQUAL(me1.getRouter(), "r0");
BOOST_CHECK_EQUAL(me1.getMappingNumber(), 1);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace nlsr

10
tests/route/test-nexthop-list.cpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2019, The University of Memphis,
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@ -17,7 +17,7 @@
*
* 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 "route/nexthop-list.hpp"
#include "route/nexthop.hpp"
@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(TieBreaker)
NexthopList::iterator it = list.begin();
BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), hopA.getConnectingFaceUri());
list.reset();
list.clear();
list.addNextHop(hopZ);
list.addNextHop(hopA);
@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(TieBreaker)
shortUriHop.setRouteCost(25);
shortUriHop.setConnectingFaceUri("AAA");
list.reset();
list.clear();
list.addNextHop(longUriHop);
list.addNextHop(shortUriHop);

52
tests/route/test-nexthop.cpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2019, The University of Memphis,
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@ -16,9 +16,7 @@
*
* 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 Ashlesh Gawande <agawande@memphis.edu>
**/
*/
#include "route/nexthop.hpp"
#include "tests/boost-test.hpp"
@ -102,6 +100,50 @@ BOOST_AUTO_TEST_CASE(HyperbolicRound)
BOOST_CHECK(hop1.getRouteCostAsAdjustedInteger() > hop2.getRouteCostAsAdjustedInteger());
}
const uint8_t NexthopData[] =
{
// Header
0x8f, 0x1d,
// Uri
0x8d, 0x11, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f,
0x70, 0x2f, 0x74, 0x6c, 0x76,
// Cost
0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66
};
BOOST_AUTO_TEST_CASE(NexthopEncode)
{
NextHop nexthops1;
nexthops1.setConnectingFaceUri("/test/nexthop/tlv");
nexthops1.setRouteCost(1.65);
const ndn::Block& wire = nexthops1.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(NexthopData,
NexthopData + sizeof(NexthopData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(NexthopDecode)
{
NextHop nexthops1;
nexthops1.wireDecode(ndn::Block(NexthopData, sizeof(NexthopData)));
BOOST_REQUIRE_EQUAL(nexthops1.getConnectingFaceUri(), "/test/nexthop/tlv");
BOOST_REQUIRE_EQUAL(nexthops1.getRouteCost(), 1.65);
}
BOOST_AUTO_TEST_CASE(AdjacencyOutputStream)
{
NextHop nexthops1;
nexthops1.setConnectingFaceUri("/test/nexthop/tlv");
nexthops1.setRouteCost(99);
std::ostringstream os;
os << nexthops1;
BOOST_CHECK_EQUAL(os.str(), "NextHop(Uri: /test/nexthop/tlv, Cost: 99)");
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test

136
tests/route/test-routing-table-entry.cpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2019, The University of Memphis,
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@ -16,9 +16,7 @@
*
* 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 Ashlesh Gawande <agawande@memphis.edu>
**/
*/
#include "route/routing-table-entry.hpp"
#include "tests/boost-test.hpp"
@ -35,6 +33,134 @@ BOOST_AUTO_TEST_CASE(RoutingTableEntryDestination)
BOOST_CHECK_EQUAL(rte1.getDestination(), "router1");
}
const uint8_t RoutingTableEntryWithNexthopsData[] =
{
// Header
0x91, 0x35,
// Destination Name
0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x14,
// Nexthop
0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08, 0x3f, 0xfa,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14, 0x8d, 0x08,
// Nexthop
0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66
};
const uint8_t RoutingTableEntryWithoutNexthopsData[] =
{
// Header
0x91, 0x09,
// Destination Name
0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31
};
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithNexthops)
{
RoutingTableEntry rte(ndn::Name("dest1"));
NextHop nexthops1;
nexthops1.setConnectingFaceUri("nexthop1");
nexthops1.setRouteCost(1.65);
rte.getNexthopList().addNextHop(nexthops1);
NextHop nexthops2;
nexthops2.setConnectingFaceUri("nexthop2");
nexthops2.setRouteCost(1.65);
rte.getNexthopList().addNextHop(nexthops2);
const ndn::Block& wire = rte.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithNexthopsData,
RoutingTableEntryWithNexthopsData +
sizeof(RoutingTableEntryWithNexthopsData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops)
{
RoutingTableEntry rte(ndn::Block(RoutingTableEntryWithNexthopsData,
sizeof(RoutingTableEntryWithNexthopsData)));
BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
BOOST_CHECK(rte.getNexthopList().size() != 0);
auto it = rte.getNexthopList().begin();
BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
it++;
BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops)
{
RoutingTableEntry rte(ndn::Name("dest1"));
auto wire = rte.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithoutNexthopsData,
RoutingTableEntryWithoutNexthopsData +
sizeof(RoutingTableEntryWithoutNexthopsData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops)
{
RoutingTableEntry rte(ndn::Block(RoutingTableEntryWithoutNexthopsData,
sizeof(RoutingTableEntryWithoutNexthopsData)));
BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
BOOST_CHECK(rte.getNexthopList().size() == 0);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryClear)
{
RoutingTableEntry rte(ndn::Name("dest1"));
NextHop nexthops1;
nexthops1.setConnectingFaceUri("nexthop1");
nexthops1.setRouteCost(99);
rte.getNexthopList().addNextHop(nexthops1);
BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
auto it = rte.getNexthopList().begin();
BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
rte.getNexthopList().clear();
BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
NextHop nexthops2;
nexthops2.setConnectingFaceUri("nexthop2");
nexthops2.setRouteCost(99);
rte.getNexthopList().addNextHop(nexthops2);
BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
it = rte.getNexthopList().begin();
BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream)
{
RoutingTableEntry rte(ndn::Name("dest1"));
NextHop nexthops1;
nexthops1.setConnectingFaceUri("nexthop1");
nexthops1.setRouteCost(99);
rte.getNexthopList().addNextHop(nexthops1);
std::ostringstream os;
os << rte;
BOOST_CHECK_EQUAL(os.str(),
" Destination: /dest1\n"
" NextHop(Uri: nexthop1, Cost: 99)\n");
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test

107
tests/route/test-routing-table.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California
*
@ -16,9 +16,7 @@
*
* 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 Ashlesh Gawande <agawande@memphis.edu>
**/
*/
#include "route/routing-table.hpp"
#include "nlsr.hpp"
@ -30,23 +28,106 @@
namespace nlsr {
namespace test {
BOOST_FIXTURE_TEST_SUITE(TestRoutingTable, BaseFixture)
BOOST_AUTO_TEST_CASE(RoutingTableAddNextHop)
class RoutingTableFixture
{
public:
RoutingTableFixture()
: conf(face, keyChain)
, nlsr(face, keyChain, conf)
, rt(nlsr.m_routingTable)
{
}
public:
ndn::util::DummyClientFace face;
ndn::KeyChain keyChain;
ConfParameter conf(face, keyChain);
Nlsr nlsr(face, keyChain, conf);
ConfParameter conf;
Nlsr nlsr;
RoutingTable& rt;
};
RoutingTable rt1(m_scheduler, nlsr.m_fib, nlsr.m_lsdb,
nlsr.m_namePrefixTable, conf);
BOOST_AUTO_TEST_SUITE(TestRoutingTable)
BOOST_FIXTURE_TEST_CASE(RoutingTableAddNextHop, RoutingTableFixture)
{
NextHop nh1;
const std::string DEST_ROUTER = "destRouter";
rt1.addNextHop(DEST_ROUTER, nh1);
rt.addNextHop(DEST_ROUTER, nh1);
BOOST_CHECK_EQUAL(rt.findRoutingTableEntry(DEST_ROUTER)->getDestination(), DEST_ROUTER);
}
const uint8_t RoutingTableData1[] =
{
// Header
0x90, 0x20,
// Routing table entry
0x91, 0x1e,
// Destination
0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x13,
// Nexthop
0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, 0xfa, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66
};
const uint8_t RoutingTableData2[] =
{
// Header
0x90, 0x00
};
BOOST_FIXTURE_TEST_CASE(RoutingTableEncode1, RoutingTableFixture)
{
NextHop nexthops;
nexthops.setConnectingFaceUri("nexthop");
nexthops.setRouteCost(1.65);
rt.addNextHop("dest1", nexthops);
auto wire = rt.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1,
RoutingTableData1 + sizeof(RoutingTableData1),
wire.begin(), wire.end());
}
BOOST_FIXTURE_TEST_CASE(RoutingTableEncode2, RoutingTableFixture)
{
auto wire = rt.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2,
RoutingTableData2 + sizeof(RoutingTableData2),
wire.begin(), wire.end());
}
BOOST_FIXTURE_TEST_CASE(RoutingTableDecode1, RoutingTableFixture)
{
RoutingTableStatus rtStatus(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1)));
auto it1 = rtStatus.m_rTable.begin();
ndn::Name des1 = it1->getDestination();
BOOST_CHECK_EQUAL(des1, "dest1");
auto it2 = it1->getNexthopList().begin();
BOOST_CHECK_EQUAL(it2->getConnectingFaceUri(), "nexthop");
BOOST_CHECK_EQUAL(it2->getRouteCost(), 1.65);
BOOST_CHECK_EQUAL(rtStatus.m_rTable.size(), 1);
}
BOOST_FIXTURE_TEST_CASE(RoutingTableOutputStream, RoutingTableFixture)
{
NextHop nexthops;
nexthops.setConnectingFaceUri("nexthop");
nexthops.setRouteCost(99);
rt.addNextHop("dest1", nexthops);
std::ostringstream os;
os << rt;
BOOST_CHECK_EQUAL(rt1.findRoutingTableEntry(DEST_ROUTER)->getDestination(), DEST_ROUTER);
BOOST_CHECK_EQUAL(os.str(),
"Routing Table:\n"
" Destination: /dest1\n"
" NextHop(Uri: nexthop, Cost: 99)\n");
}
BOOST_AUTO_TEST_SUITE_END()

86
tests/tlv/test-destination.cpp

@ -1,86 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "tlv/destination.hpp"
#include "tests/boost-test.hpp"
namespace nlsr {
namespace tlv {
namespace test {
BOOST_AUTO_TEST_SUITE(TlvTestDes)
const uint8_t DesData[] =
{
// Header
0x8e, 0x13,
// Routername 746573742f646573742f746c76
0x07, 0x11, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x65, 0x73, 0x74,
0x08, 0x03, 0x74, 0x6c, 0x76
};
BOOST_AUTO_TEST_CASE(DesEncode)
{
Destination des1;
des1.setName("/test/dest/tlv");
const ndn::Block& wire = des1.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(DesData,
DesData + sizeof(DesData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(DesDecode)
{
Destination des1;
des1.wireDecode(ndn::Block(DesData, sizeof(DesData)));
ndn::Name DEST_NAME = ndn::Name("/test/dest/tlv");
BOOST_REQUIRE_EQUAL(des1.getName(), DEST_NAME);
}
BOOST_AUTO_TEST_CASE(DesOutputStream)
{
Destination des1;
des1.setName("/test/dest/tlv");
std::ostringstream os;
os << des1;
BOOST_CHECK_EQUAL(os.str(), "Destination: /test/dest/tlv");
}
BOOST_AUTO_TEST_CASE(DesMake)
{
RoutingTableEntry rte("/test/dest/tlv");
std::shared_ptr<Destination> des = makeDes(rte);
BOOST_CHECK_EQUAL(des->getName(), rte.getDestination());
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace tlv
} // namespace nlsr

80
tests/tlv/test-nexthops.cpp

@ -1,80 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "tlv/nexthop.hpp"
#include "tests/boost-test.hpp"
namespace nlsr {
namespace tlv {
namespace test {
BOOST_AUTO_TEST_SUITE(TlvTestNexthops)
const uint8_t NexthopData[] =
{
// Header
0x8f, 0x1d,
// Uri
0x8d, 0x11, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f,
0x70, 0x2f, 0x74, 0x6c, 0x76,
// Cost
0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66
};
BOOST_AUTO_TEST_CASE(NexthopEncode)
{
NextHop nexthops1;
nexthops1.setUri("/test/nexthop/tlv");
nexthops1.setCost(1.65);
const ndn::Block& wire = nexthops1.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(NexthopData,
NexthopData + sizeof(NexthopData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(NexthopDecode)
{
NextHop nexthops1;
nexthops1.wireDecode(ndn::Block(NexthopData, sizeof(NexthopData)));
BOOST_REQUIRE_EQUAL(nexthops1.getUri(), "/test/nexthop/tlv");
BOOST_REQUIRE_EQUAL(nexthops1.getCost(), 1.65);
}
BOOST_AUTO_TEST_CASE(AdjacencyOutputStream)
{
NextHop nexthops1;
nexthops1.setUri("/test/nexthop/tlv");
nexthops1.setCost(99);
std::ostringstream os;
os << nexthops1;
BOOST_CHECK_EQUAL(os.str(), "NextHop(Uri: /test/nexthop/tlv, Cost: 99)\n");
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace tlv
} // namespace nlsr

192
tests/tlv/test-routing-table-entry.cpp

@ -1,192 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "tlv/routing-table-entry.hpp"
#include "tests/boost-test.hpp"
namespace nlsr {
namespace tlv {
namespace test {
BOOST_AUTO_TEST_SUITE(TlvTestRoutingTableEntry)
const uint8_t RoutingTableEntryWithNexthopsData[] =
{
// Header
0x91, 0x37,
// Destination
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31,
// Nexthop
0x8f, 0x14, 0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08,
0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14,
// Nexthop
0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66
};
const uint8_t RoutingTableEntryWithoutNexthopsData[] =
{
// Header
0x91, 0x0b,
// Destination
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31
};
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithNexthops)
{
RoutingTable rt;
Destination des1;
des1.setName("dest1");
rt.setDestination(des1);
NextHop nexthops1;
nexthops1.setUri("nexthop1");
nexthops1.setCost(1.65);
rt.addNexthops(nexthops1);
NextHop nexthops2;
nexthops2.setUri("nexthop2");
nexthops2.setCost(1.65);
rt.addNexthops(nexthops2);
const ndn::Block& wire = rt.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithNexthopsData,
RoutingTableEntryWithNexthopsData +
sizeof(RoutingTableEntryWithNexthopsData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops)
{
RoutingTable rt;
rt.wireDecode(ndn::Block(RoutingTableEntryWithNexthopsData,
sizeof(RoutingTableEntryWithNexthopsData)));
Destination des = rt.getDestination();
BOOST_CHECK_EQUAL(des.getName(), "dest1");
BOOST_CHECK_EQUAL(rt.hasNexthops(), true);
std::list<NextHop> nexthops = rt.getNextHops();
std::list<NextHop>::const_iterator it = nexthops.begin();
BOOST_CHECK_EQUAL(it->getUri(), "nexthop1");
BOOST_CHECK_EQUAL(it->getCost(), 1.65);
it++;
BOOST_CHECK_EQUAL(it->getUri(), "nexthop2");
BOOST_CHECK_EQUAL(it->getCost(), 1.65);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops)
{
RoutingTable rt;
Destination des1;
des1.setName("dest1");
rt.setDestination(des1);
const ndn::Block& wire = rt.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithoutNexthopsData,
RoutingTableEntryWithoutNexthopsData +
sizeof(RoutingTableEntryWithoutNexthopsData),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops)
{
RoutingTable rt;
rt.wireDecode(ndn::Block(RoutingTableEntryWithoutNexthopsData,
sizeof(RoutingTableEntryWithoutNexthopsData)));
Destination des = rt.getDestination();
BOOST_CHECK_EQUAL(des.getName(), "dest1");
BOOST_CHECK_EQUAL(rt.hasNexthops(), false);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryClear)
{
RoutingTable rt;
Destination des1;
des1.setName("dest1");
rt.setDestination(des1);
NextHop nexthops1;
nexthops1.setUri("nexthop1");
nexthops1.setCost(99);
rt.addNexthops(nexthops1);
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 1);
std::list<NextHop> nexthops = rt.getNextHops();
std::list<NextHop>::const_iterator it = nexthops.begin();
BOOST_CHECK_EQUAL(it->getUri(), "nexthop1");
BOOST_CHECK_EQUAL(it->getCost(), 99);
rt.clearNexthops();
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 0);
NextHop nexthops2;
nexthops2.setUri("nexthop2");
nexthops2.setCost(99);
rt.addNexthops(nexthops2);
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 1);
nexthops = rt.getNextHops();
it = nexthops.begin();
BOOST_CHECK_EQUAL(it->getUri(), "nexthop2");
BOOST_CHECK_EQUAL(it->getCost(), 99);
}
BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream)
{
RoutingTable rt;
Destination des1;
des1.setName("dest1");
rt.setDestination(des1);
NextHop nexthops1;
nexthops1.setUri("nexthop1");
nexthops1.setCost(99);
rt.addNexthops(nexthops1);
std::ostringstream os;
os << rt;
BOOST_CHECK_EQUAL(os.str(),
"Destination: /dest1\n"
"NexthopList(\n"
"NextHop(Uri: nexthop1, Cost: 99)\n"
")");
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace tlv
} // namespace nlsr

168
tests/tlv/test-routing-table.cpp

@ -1,168 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2020, 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 "tlv/routing-table-status.hpp"
#include "tests/boost-test.hpp"
namespace nlsr {
namespace tlv {
namespace test {
BOOST_AUTO_TEST_SUITE(TlvTestRoutingTable)
const uint8_t RoutingTableData1[] =
{
// Header
0x90, 0x22,
// Routing table entry
0x91, 0x20,
// Destination
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31,
// Nexthop
0x8f, 0x13, 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f,
0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66
};
const uint8_t RoutingTableData2[] =
{
// Header
0x90, 0x00
};
BOOST_AUTO_TEST_CASE(RoutingTableEncode1)
{
RoutingTableStatus rtStatus;
Destination des;
des.setName("dest1");
// RoutingtableEntry
RoutingTable rt;
rt.setDestination(des);
NextHop nexthops;
nexthops.setUri("nexthop");
nexthops.setCost(1.65);
rt.addNexthops(nexthops);
rtStatus.addRoutingTable(rt);
const ndn::Block& wire = rtStatus.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1,
RoutingTableData1 + sizeof(RoutingTableData1),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableEncode2)
{
RoutingTableStatus rtStatus;
const ndn::Block& wire = rtStatus.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2,
RoutingTableData2 + sizeof(RoutingTableData2),
wire.begin(), wire.end());
}
BOOST_AUTO_TEST_CASE(RoutingTableDecode1)
{
RoutingTableStatus rtStatus;
rtStatus.wireDecode(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1)));
std::list<RoutingTable> rte = rtStatus.getRoutingtable();
std::list<RoutingTable>::const_iterator it1 = rte.begin();
Destination des1 = it1->getDestination();
BOOST_CHECK_EQUAL(des1.getName(), "dest1");
std::list<NextHop> nexthops = it1->getNextHops();
std::list<NextHop>::const_iterator it2 = nexthops.begin();
BOOST_CHECK_EQUAL(it2->getUri(), "nexthop");
BOOST_CHECK_EQUAL(it2->getCost(), 1.65);
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true);
}
BOOST_AUTO_TEST_CASE(RoutingTableDecode2)
{
RoutingTableStatus rtStatus;
rtStatus.wireDecode(ndn::Block(RoutingTableData2, sizeof(RoutingTableData2)));
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false);
}
BOOST_AUTO_TEST_CASE(RoutingTableClear)
{
RoutingTableStatus rtStatus;
Destination des;
des.setName("dest1");
// RoutingtableEntry
RoutingTable rt;
rt.setDestination(des);
NextHop nexthops;
nexthops.setUri("nexthop");
nexthops.setCost(1.65);
rt.addNexthops(nexthops);
rtStatus.addRoutingTable(rt);
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true);
rtStatus.clearRoutingTable();
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false);
}
BOOST_AUTO_TEST_CASE(RoutingTableOutputStream)
{
RoutingTableStatus rtStatus;
Destination des;
des.setName("dest1");
// RoutingtableEntry
RoutingTable rt;
rt.setDestination(des);
NextHop nexthops;
nexthops.setUri("nexthop");
nexthops.setCost(99);
rt.addNexthops(nexthops);
rtStatus.addRoutingTable(rt);
std::ostringstream os;
os << rtStatus;
BOOST_CHECK_EQUAL(os.str(), "Routing Table Status: \n"
"Destination: /dest1\n"
"NexthopList(\n"
"NextHop(Uri: nexthop, Cost: 99)\n"
")");
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace tlv
} // namespace nlsr

30
tools/nlsrc.cpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,7 +17,7 @@
*
* 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 "nlsrc.hpp"
@ -273,10 +273,7 @@ Nlsrc::fetchNameLsas()
void
Nlsrc::fetchRtables()
{
fetchFromRt<nlsr::tlv::RoutingTableStatus>(
[this] (const nlsr::tlv::RoutingTableStatus& rts) {
recordRtable(rts);
});
fetchFromRt<nlsr::RoutingTableStatus>([this] (const auto& rts) { recordRtable(rts); });
}
template <class T>
@ -373,24 +370,10 @@ Nlsrc::recordLsa(const nlsr::Lsa& lsa)
}
void
Nlsrc::recordRtable(const nlsr::tlv::RoutingTableStatus& rts)
Nlsrc::recordRtable(const nlsr::RoutingTableStatus& rts)
{
std::ostringstream os;
ndn::Name firstDes;
for (const auto& rt : rts.getRoutingtable()) {
if (firstDes.empty()) {
firstDes = rt.getDestination().getName();
os << rt << std::endl;
continue;
}
if (firstDes == rt.getDestination().getName()) {
os << "\n------Dry-run Hyperbolic Routing Tables:------- \n " << std::endl;
}
os << rt << std::endl;
}
os << rts;
m_rtString = os.str();
}
@ -423,8 +406,7 @@ void
Nlsrc::printRT()
{
if (!m_rtString.empty()) {
std::cout << "Routing Table" << std::endl;
std::cout << m_rtString << std::endl;
std::cout << m_rtString;
}
else {
std::cout << "Routing Table is not calculated yet" << std::endl;

8
tools/nlsrc.hpp

@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
/*
* Copyright (c) 2014-2020, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
@ -17,12 +17,12 @@
*
* 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 "lsa/adj-lsa.hpp"
#include "lsa/coordinate-lsa.hpp"
#include "lsa/name-lsa.hpp"
#include "tlv/routing-table-status.hpp"
#include "route/routing-table.hpp"
#include <boost/noncopyable.hpp>
#include <ndn-cxx/face.hpp>
@ -123,7 +123,7 @@ private:
recordLsa(const nlsr::Lsa& lsa);
void
recordRtable(const nlsr::tlv::RoutingTableStatus& rts);
recordRtable(const nlsr::RoutingTableStatus& rts);
void
printLsdb();

Loading…
Cancel
Save