**breaking** route: consolidate routing tlv into route
refs: #5116
Plus some misc improvements
Change-Id: Id0902fec65160b4368b1b5066f460433aced98ed
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index 9e85d4a..fae92d5 100644
--- a/src/adjacent.cpp
+++ b/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 {
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index 178ae78..a540a5c 100644
--- a/src/adjacent.hpp
+++ b/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.
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 9dd2659..99bdeac 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/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 @@
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 @@
{
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");
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 47f6c9a..7deb06a 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/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 @@
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
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index e33b50b..f7270ba 100644
--- a/src/conf-file-processor.hpp
+++ b/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 @@
* 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
{
diff --git a/src/lsa/adj-lsa.cpp b/src/lsa/adj-lsa.cpp
index e2d0a2b..e7dbf95 100644
--- a/src/lsa/adj-lsa.cpp
+++ b/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 @@
return os;
}
-} // namespace nlsr
\ No newline at end of file
+} // namespace nlsr
diff --git a/src/lsa/coordinate-lsa.cpp b/src/lsa/coordinate-lsa.cpp
index a73ab76..b195e39 100644
--- a/src/lsa/coordinate-lsa.cpp
+++ b/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 @@
return os;
}
-} // namespace nlsr
\ No newline at end of file
+} // namespace nlsr
diff --git a/src/lsa/lsa.cpp b/src/lsa/lsa.cpp
index c0d6435..73ddbe7 100644
--- a/src/lsa/lsa.cpp
+++ b/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 {
diff --git a/src/lsa/name-lsa.cpp b/src/lsa/name-lsa.cpp
index 37b7408..f73014b 100644
--- a/src/lsa/name-lsa.cpp
+++ b/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 {
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index e3fe9d3..9913751 100644
--- a/src/lsdb.cpp
+++ b/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 @@
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 @@
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);
}
}
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 73a1ac5..b2c6118 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -42,16 +42,14 @@
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 @@
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,
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 02e3625..9d7f032 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -61,8 +61,6 @@
namespace nlsr {
-static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
-
class Nlsr
{
public:
@@ -208,12 +206,9 @@
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 @@
private:
ndn::nfd::FaceMonitor m_faceMonitor;
-
- friend class NlsrRunner;
};
} // namespace nlsr
diff --git a/src/publisher/dataset-interest-handler.cpp b/src/publisher/dataset-interest-handler.cpp
index a574622..24c6e1a 100644
--- a/src/publisher/dataset-interest-handler.cpp
+++ b/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 @@
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 @@
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();
}
diff --git a/src/publisher/dataset-interest-handler.hpp b/src/publisher/dataset-interest-handler.hpp
index 28a6c4c..b39ac25 100644
--- a/src/publisher/dataset-interest-handler.hpp
+++ b/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 @@
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:
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
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index 0091245..bc11634 100644
--- a/src/route/fib-entry.cpp
+++ b/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 @@
{
NLSR_LOG_DEBUG("Name Prefix: " << m_name);
NLSR_LOG_DEBUG("Seq No: " << m_seqNo);
- m_nexthopList.writeLog();
+ NLSR_LOG_DEBUG(m_nexthopList);
}
} // namespace nlsr
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 3e4ef68..27891eb 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -87,9 +87,6 @@
* 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 @@
* 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);
diff --git a/src/route/map-entry.hpp b/src/route/map-entry.hpp
deleted file mode 100644
index e4c998c..0000000
--- a/src/route/map-entry.hpp
+++ /dev/null
@@ -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
diff --git a/src/route/map.cpp b/src/route/map.cpp
index 3f6513c..0aab84f 100644
--- a/src/route/map.cpp
+++ b/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 @@
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 @@
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 << " )");
}
}
diff --git a/src/route/map.hpp b/src/route/map.hpp
index c9511bf..ae92d25 100644
--- a/src/route/map.hpp
+++ b/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 @@
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 @@
ndn::optional<int32_t>
getMappingNoByRouterName(const ndn::Name& rName);
- void
- reset();
-
size_t
getMapSize() const
{
diff --git a/src/route/name-prefix-table-entry.cpp b/src/route/name-prefix-table-entry.cpp
index 9890101..368cc08 100644
--- a/src/route/name-prefix-table-entry.cpp
+++ b/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 @@
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 @@
// 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 @@
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;
}
diff --git a/src/route/name-prefix-table-entry.hpp b/src/route/name-prefix-table-entry.hpp
index 828d64a..c298e97 100644
--- a/src/route/name-prefix-table-entry.hpp
+++ b/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 @@
{
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 @@
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::list<std::shared_ptr<RoutingTablePoolEntry>> m_rteList;
NexthopList m_nexthopList;
-
};
bool
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index b38bbea..55f0c54 100644
--- a/src/route/name-prefix-table.cpp
+++ b/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 @@
}
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());
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 8b9366e..7ab1352 100644
--- a/src/route/nexthop-list.cpp
+++ b/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,17 +17,16 @@
*
* 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"
+
+#include <ndn-cxx/util/ostream-joiner.hpp>
namespace nlsr {
-INIT_LOGGER(route.NexthopList);
-
static bool
nexthopAddCompare(const NextHop& nh1, const NextHop& nh2)
{
@@ -71,21 +70,16 @@
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 @@
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
diff --git a/src/route/nexthop-list.hpp b/src/route/nexthop-list.hpp
index e405889..537448e 100644
--- a/src/route/nexthop-list.hpp
+++ b/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 @@
class NexthopList
{
public:
- NexthopList()
- {
- }
-
- ~NexthopList()
- {
- }
+ NexthopList() = default;
/*! \brief Adds a next hop to the list.
\param nh The next hop.
@@ -80,7 +74,7 @@
}
void
- reset()
+ clear()
{
m_nexthopList.clear();
}
@@ -93,6 +87,7 @@
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 @@
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;
diff --git a/src/route/nexthop.cpp b/src/route/nexthop.cpp
index 14bfb43..11399aa 100644
--- a/src/route/nexthop.cpp
+++ b/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;
}
diff --git a/src/route/nexthop.hpp b/src/route/nexthop.hpp
index e24df7b..7f91cfe 100644
--- a/src/route/nexthop.hpp
+++ b/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 @@
}
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 @@
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 @@
static const uint64_t HYPERBOLIC_COST_ADJUSTMENT_FACTOR = 1000;
};
+NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHop);
+
bool
operator==(const NextHop& lhs, const NextHop& rhs);
diff --git a/src/route/routing-table-entry.cpp b/src/route/routing-table-entry.cpp
index 750dc79..7320d91 100644
--- a/src/route/routing-table-entry.cpp
+++ b/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;
}
diff --git a/src/route/routing-table-entry.hpp b/src/route/routing-table-entry.hpp
index 83731b9..ffbbfac 100644
--- a/src/route/routing-table-entry.hpp
+++ b/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()
+ RoutingTableEntry() = default;
+
+ RoutingTableEntry(const ndn::Block& block)
{
+ wireDecode(block);
}
RoutingTableEntry(const ndn::Name& dest)
@@ -65,15 +76,29 @@
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);
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 3fcd654..a2ec12b 100644
--- a/src/route/routing-table.cpp
+++ b/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 @@
// 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
@@ -199,26 +198,6 @@
}
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)
{
NLSR_LOG_DEBUG("Adding " << nh << " to dry table for destination: " << destRouter);
@@ -251,4 +230,100 @@
}
}
+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
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index af2ba93..8f9309b 100644
--- a/src/route/routing-table.hpp
+++ b/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 @@
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 @@
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 @@
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;
diff --git a/src/tlv/tlv-nlsr.hpp b/src/tlv-nlsr.hpp
similarity index 97%
rename from src/tlv/tlv-nlsr.hpp
rename to src/tlv-nlsr.hpp
index e7d2253..93cfd2d 100644
--- a/src/tlv/tlv-nlsr.hpp
+++ b/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 @@
ExpirationTime = 139,
Cost = 140,
Uri = 141,
- Destination = 142,
NextHop = 143,
RoutingTable = 144,
RoutingTableEntry = 145
diff --git a/src/tlv/destination.cpp b/src/tlv/destination.cpp
deleted file mode 100644
index a1ea06f..0000000
--- a/src/tlv/destination.cpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/destination.hpp b/src/tlv/destination.hpp
deleted file mode 100644
index 859c8a8..0000000
--- a/src/tlv/destination.hpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/nexthop.cpp b/src/tlv/nexthop.cpp
deleted file mode 100644
index 508bf1a..0000000
--- a/src/tlv/nexthop.cpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/nexthop.hpp b/src/tlv/nexthop.hpp
deleted file mode 100644
index 9b0f72c..0000000
--- a/src/tlv/nexthop.hpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/routing-table-entry.cpp b/src/tlv/routing-table-entry.cpp
deleted file mode 100644
index 255d418..0000000
--- a/src/tlv/routing-table-entry.cpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/routing-table-entry.hpp b/src/tlv/routing-table-entry.hpp
deleted file mode 100644
index 167f63a..0000000
--- a/src/tlv/routing-table-entry.hpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/routing-table-status.cpp b/src/tlv/routing-table-status.cpp
deleted file mode 100644
index 00d2c78..0000000
--- a/src/tlv/routing-table-status.cpp
+++ /dev/null
@@ -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
diff --git a/src/tlv/routing-table-status.hpp b/src/tlv/routing-table-status.hpp
deleted file mode 100644
index 97d083f..0000000
--- a/src/tlv/routing-table-status.hpp
+++ /dev/null
@@ -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