publisher: use ndn-cxx dispatcher for dataset publisher
Change-Id: I836a718ba40ff471bcdac7a7cc684c13914c4ea5
refs: #3728
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 02df4aa..ca829e0 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -56,7 +56,11 @@
, m_routingTable(scheduler)
, m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
, m_namePrefixTable(*this)
+ , m_localhostDispatcher(m_nlsrFace, m_keyChain)
+ , m_routerNameDispatcher(m_nlsrFace, m_keyChain)
, m_lsdbDatasetHandler(m_nlsrLsdb,
+ m_localhostDispatcher,
+ m_routerNameDispatcher,
m_nlsrFace,
m_keyChain)
, m_helloProtocol(*this, scheduler)
@@ -69,8 +73,7 @@
m_keyChain,
m_certificateCache,
m_certStore)
- , m_dispatcher(m_nlsrFace, m_keyChain, m_signingInfo)
- , m_nfdRibCommandProcessor(m_dispatcher,
+ , m_nfdRibCommandProcessor(m_localhostDispatcher,
m_namePrefixList,
m_nlsrLsdb)
, m_faceMonitor(m_nlsrFace)
@@ -93,23 +96,27 @@
_LOG_DEBUG("Successfully registered prefix: " << name);
if (name.equals(m_confParam.getRouterPrefix())) {
- m_lsdbDatasetHandler.startListeningOnRouterPrefix();
+ // the top-level prefixes are added.
+ try {
+ m_routerNameDispatcher.addTopPrefix(m_confParam.getRouterPrefix(), false, m_signingInfo);
+ }
+ catch (const std::exception& e) {
+ _LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what() << "\n");
+ }
}
}
void
Nlsr::onLocalhostRegistrationSuccess(const ndn::Name& name)
{
- _LOG_DEBUG("Successfully registered prefix: " << name);
+ _LOG_DEBUG("Successfully registered local prefix: " << name);
m_prefixUpdateProcessor.startListening();
- m_lsdbDatasetHandler.startListeningOnLocalhost();
- // Dispatcher prefix registrations
m_nfdRibCommandProcessor.startListening();
// All dispatcher-related sub-prefixes *must* be registered before
// the top-level prefixes are added.
try {
- m_dispatcher.addTopPrefix(LOCALHOST_PREFIX, false, m_signingInfo);
+ m_localhostDispatcher.addTopPrefix(LOCALHOST_PREFIX, false, m_signingInfo);
}
catch (const std::exception& e) {
_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what() << "\n");
@@ -136,7 +143,7 @@
ndn::Name name = m_confParam.getLsaPrefix();
name.append(m_confParam.getSiteName());
name.append(m_confParam.getRouterName());
- _LOG_DEBUG("Setting interest filter for name: " << name);
+ _LOG_DEBUG("Setting interest filter for LsaPrefix: " << name);
getNlsrFace().setInterestFilter(name,
std::bind(&Lsdb::processInterest,
&m_nlsrLsdb, _1, _2),
@@ -335,7 +342,6 @@
Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest)
{
const ndn::Name& interestName = interest.getName();
-
ndn::Name certName = interestName.getSubName(name.size());
if (certName[-2].toUri() == "ID-CERT")
@@ -394,9 +400,6 @@
}
}
-
-
-
void
Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
{
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 3df4fd1..81629ae 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -287,7 +287,13 @@
ndn::mgmt::Dispatcher&
getDispatcher()
{
- return m_dispatcher;
+ return m_localhostDispatcher;
+ }
+
+ ndn::mgmt::Dispatcher&
+ getDispatcherRouterName()
+ {
+ return m_routerNameDispatcher;
}
void
@@ -404,6 +410,9 @@
RoutingTable m_routingTable;
Fib m_fib;
NamePrefixTable m_namePrefixTable;
+ ndn::mgmt::Dispatcher m_localhostDispatcher;
+ ndn::mgmt::Dispatcher m_routerNameDispatcher;
+
LsdbDatasetInterestHandler m_lsdbDatasetHandler;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
@@ -416,7 +425,6 @@
ndn::security::SigningInfo m_signingInfo;
ndn::Name m_defaultCertName;
update::PrefixUpdateProcessor m_prefixUpdateProcessor;
- ndn::mgmt::Dispatcher m_dispatcher;
update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
ndn::nfd::FaceMonitor m_faceMonitor;
diff --git a/src/publisher/lsa-publisher.cpp b/src/publisher/lsa-publisher.cpp
index 7060c05..a46ef60 100644
--- a/src/publisher/lsa-publisher.cpp
+++ b/src/publisher/lsa-publisher.cpp
@@ -33,8 +33,7 @@
AdjacencyLsaPublisher::AdjacencyLsaPublisher(Lsdb& lsdb,
ndn::Face& face,
ndn::KeyChain& keyChain)
- : LsaPublisher(face, keyChain)
- , m_adjacencyLsas(lsdb.getAdjLsdb())
+ : m_adjacencyLsas(lsdb.getAdjLsdb())
{
}
@@ -73,8 +72,7 @@
CoordinateLsaPublisher::CoordinateLsaPublisher(Lsdb& lsdb,
ndn::Face& face,
ndn::KeyChain& keyChain)
- : LsaPublisher(face, keyChain)
- , m_coordinateLsas(lsdb.getCoordinateLsdb())
+ : m_coordinateLsas(lsdb.getCoordinateLsdb())
{
}
@@ -109,8 +107,7 @@
NameLsaPublisher::NameLsaPublisher(Lsdb& lsdb,
ndn::Face& face,
ndn::KeyChain& keyChain)
- : LsaPublisher(face, keyChain)
- , m_nameLsas(lsdb.getNameLsdb())
+ : m_nameLsas(lsdb.getNameLsdb())
{
}
diff --git a/src/publisher/lsa-publisher.hpp b/src/publisher/lsa-publisher.hpp
index 413731f..1c33242 100644
--- a/src/publisher/lsa-publisher.hpp
+++ b/src/publisher/lsa-publisher.hpp
@@ -32,43 +32,12 @@
namespace nlsr {
-template <class TlvType>
-class LsaPublisher : public SegmentPublisher<ndn::Face>
-{
-public:
- LsaPublisher(ndn::Face& face, ndn::KeyChain& keyChain)
- : SegmentPublisher<ndn::Face>(face, keyChain)
- {
- }
-
- virtual
- ~LsaPublisher()
- {
- }
-
-protected:
- virtual size_t
- generate(ndn::EncodingBuffer& outBuffer)
- {
- size_t totalLength = 0;
-
- for (const TlvType& lsaTlv : getTlvLsas()) {
- totalLength += lsaTlv.wireEncode(outBuffer);
- }
-
- return totalLength;
- }
-
- virtual std::list<TlvType>
- getTlvLsas() = 0;
-};
-
/*! \brief Class to publish adjacency lsa dataset
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
*/
-class AdjacencyLsaPublisher : public LsaPublisher<tlv::AdjacencyLsa>
+class AdjacencyLsaPublisher
{
public:
AdjacencyLsaPublisher(Lsdb& lsdb,
@@ -89,7 +58,7 @@
/*! \brief Class to publish coordinate lsa dataset
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
*/
-class CoordinateLsaPublisher : public LsaPublisher<tlv::CoordinateLsa>
+class CoordinateLsaPublisher
{
public:
CoordinateLsaPublisher(Lsdb& lsdb,
@@ -110,7 +79,7 @@
/*! \brief Class to publish name lsa dataset
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
*/
-class NameLsaPublisher : public LsaPublisher<tlv::NameLsa>
+class NameLsaPublisher
{
public:
NameLsaPublisher(Lsdb& lsdb,
diff --git a/src/publisher/lsdb-dataset-interest-handler.cpp b/src/publisher/lsdb-dataset-interest-handler.cpp
index 7ba0e92..e3cfa1f 100644
--- a/src/publisher/lsdb-dataset-interest-handler.cpp
+++ b/src/publisher/lsdb-dataset-interest-handler.cpp
@@ -34,110 +34,137 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/mgmt/nfd/control-response.hpp>
#include <ndn-cxx/util/regex.hpp>
+#include "tlv/lsdb-status.hpp"
namespace nlsr {
INIT_LOGGER("LsdbDatasetInterestHandler");
-
-const uint32_t LsdbDatasetInterestHandler::ERROR_CODE_MALFORMED_COMMAND = 400;
-const uint32_t LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND = 501;
+const ndn::PartialName ADJACENCIES_DATASET = ndn::PartialName("lsdb/adjacencies");
+const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates");
+const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names");
+const ndn::PartialName LISTS_DATASET = ndn::PartialName("lsdb/list");
+const ndn::PartialName LsdbDatasetInterestHandler::LOCALHOST_COMMAND_PREFIX =
+ ndn::Name(Nlsr::LOCALHOST_PREFIX).append(Lsdb::NAME_COMPONENT);
LsdbDatasetInterestHandler::LsdbDatasetInterestHandler(Lsdb& lsdb,
+ ndn::mgmt::Dispatcher& localHostDispatcher,
+ ndn::mgmt::Dispatcher& routerNameDispatcher,
ndn::Face& face,
ndn::KeyChain& keyChain)
- : LOCALHOST_COMMAND_PREFIX(ndn::Name(Nlsr::LOCALHOST_PREFIX).append(Lsdb::NAME_COMPONENT))
- , m_face(face)
- , m_keyChain(keyChain)
+ : m_localhostDispatcher(localHostDispatcher)
+ , m_routerNameDispatcher(routerNameDispatcher)
, m_adjacencyLsaPublisher(lsdb, face, keyChain)
, m_coordinateLsaPublisher(lsdb, face, keyChain)
, m_nameLsaPublisher(lsdb, face, keyChain)
- , m_lsdbStatusPublisher(lsdb, face, keyChain,
- m_adjacencyLsaPublisher,
- m_coordinateLsaPublisher,
- m_nameLsaPublisher)
-
+ , m_adjacencyLsas(lsdb.getAdjLsdb())
+ , m_coordinateLsas(lsdb.getCoordinateLsdb())
+ , m_nameLsas(lsdb.getNameLsdb())
{
+ _LOG_DEBUG("Setting dispatcher for lsdb status dataset:");
+ setDispatcher(m_localhostDispatcher);
+ setDispatcher(m_routerNameDispatcher);
}
void
-LsdbDatasetInterestHandler::startListeningOnLocalhost()
+LsdbDatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
{
- _LOG_DEBUG("Setting interest filter for: " << LOCALHOST_COMMAND_PREFIX);
- m_face.setInterestFilter(LOCALHOST_COMMAND_PREFIX,
- std::bind(&LsdbDatasetInterestHandler::onInterest, this, _2,
- std::cref(LOCALHOST_COMMAND_PREFIX)));
+ dispatcher.addStatusDataset(ADJACENCIES_DATASET,
+ ndn::mgmt::makeAcceptAllAuthorization(),
+ std::bind(&LsdbDatasetInterestHandler::publishAdjStatus, this, _1, _2, _3));
+ dispatcher.addStatusDataset(COORDINATES_DATASET,
+ ndn::mgmt::makeAcceptAllAuthorization(),
+ std::bind(&LsdbDatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3));
+ dispatcher.addStatusDataset(NAMES_DATASET,
+ ndn::mgmt::makeAcceptAllAuthorization(),
+ std::bind(&LsdbDatasetInterestHandler::publishNameStatus, this, _1, _2, _3));
+ dispatcher.addStatusDataset(LISTS_DATASET,
+ ndn::mgmt::makeAcceptAllAuthorization(),
+ std::bind(&LsdbDatasetInterestHandler::publishAllStatus, this, _1, _2, _3));
}
void
-LsdbDatasetInterestHandler::startListeningOnRouterPrefix()
+LsdbDatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context)
{
- _LOG_DEBUG("Setting interest filter for: " << m_routerNameCommandPrefix);
- m_face.setInterestFilter(m_routerNameCommandPrefix,
- std::bind(&LsdbDatasetInterestHandler::onInterest, this, _2,
- std::cref(m_routerNameCommandPrefix)));
+ _LOG_DEBUG("Received interest: " << interest);
+ for (AdjLsa lsa : m_adjacencyLsas) {
+ tlv::AdjacencyLsa tlvLsa;
+ std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
+ tlvLsa.setLsaInfo(*tlvLsaInfo);
+
+ for (const Adjacent& adj : lsa.getAdl().getAdjList()) {
+ tlv::Adjacency tlvAdj;
+ tlvAdj.setName(adj.getName());
+ tlvAdj.setUri(adj.getFaceUri().toString());
+ tlvAdj.setCost(adj.getLinkCost());
+ tlvLsa.addAdjacency(tlvAdj);
+ }
+ const ndn::Block& wire = tlvLsa.wireEncode();
+ context.append(wire);
+ }
+ context.end();
}
void
-LsdbDatasetInterestHandler::onInterest(const ndn::Interest& interest,
- const ndn::Name& commandPrefix)
+LsdbDatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context)
{
- if (!isValidCommandPrefix(interest, commandPrefix))
- {
- _LOG_DEBUG("Received malformed interest: " << interest.getName());
+ _LOG_DEBUG("Received interest: " << interest);
+ for (const CoordinateLsa lsa : m_coordinateLsas) {
+ tlv::CoordinateLsa tlvLsa;
+ std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
+ tlvLsa.setLsaInfo(*tlvLsaInfo);
- sendErrorResponse(interest.getName(), ERROR_CODE_MALFORMED_COMMAND, "Malformed command");
- return;
+ tlvLsa.setHyperbolicRadius(lsa.getCorRadius());
+ tlvLsa.setHyperbolicAngle(lsa.getCorTheta());
+
+ const ndn::Block& wire = tlvLsa.wireEncode();
+ context.append(wire);
}
-
- ndn::Name::Component command = interest.getName().get(commandPrefix.size());
- processCommand(interest, command);
-}
-
-bool
-LsdbDatasetInterestHandler::isValidCommandPrefix(const ndn::Interest& interest,
- const ndn::Name& commandPrefix)
-{
- size_t commandSize = interest.getName().size();
-
- return (commandSize == commandPrefix.size() + 1 && commandPrefix.isPrefixOf(interest.getName()));
+ context.end();
}
void
-LsdbDatasetInterestHandler::processCommand(const ndn::Interest& interest,
- const ndn::Name::Component& command)
+LsdbDatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context)
{
- _LOG_TRACE("Received interest with command: " << command);
+ _LOG_DEBUG("Received interest: " << interest);
+ for (NameLsa lsa : m_nameLsas) {
+ tlv::NameLsa tlvLsa;
- if (command.equals(AdjacencyLsaPublisher::DATASET_COMPONENT)) {
- m_adjacencyLsaPublisher.publish(interest.getName());
+ std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
+ tlvLsa.setLsaInfo(*tlvLsaInfo);
+
+ for (const ndn::Name& name : lsa.getNpl().getNameList()) {
+ tlvLsa.addName(name);
+ }
+
+ const ndn::Block& wire = tlvLsa.wireEncode();
+ context.append(wire);
}
- else if (command.equals(CoordinateLsaPublisher::DATASET_COMPONENT)) {
- m_coordinateLsaPublisher.publish(interest.getName());
- }
- else if (command.equals(NameLsaPublisher::DATASET_COMPONENT)) {
- m_nameLsaPublisher.publish(interest.getName());
- }
- else if (command.equals(LsdbStatusPublisher::DATASET_COMPONENT)) {
- m_lsdbStatusPublisher.publish(interest.getName());
- }
- else {
- _LOG_DEBUG("Unsupported command: " << command);
- sendErrorResponse(interest.getName(), ERROR_CODE_UNSUPPORTED_COMMAND, "Unsupported command");
- }
+ context.end();
}
void
-LsdbDatasetInterestHandler::sendErrorResponse(const ndn::Name& name,
- uint32_t code,
- const std::string& error)
+LsdbDatasetInterestHandler::publishAllStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context)
{
- ndn::nfd::ControlResponse response(code, error);
+ _LOG_DEBUG("Received interest: " << interest);
+ tlv::LsdbStatus lsdbStatus;
+ for (const tlv::AdjacencyLsa& tlvLsa : m_adjacencyLsaPublisher.getTlvLsas()) {
+ lsdbStatus.addAdjacencyLsa(tlvLsa);
+ }
- std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(name);
- data->setContent(response.wireEncode());
+ for (const tlv::CoordinateLsa& tlvLsa : m_coordinateLsaPublisher.getTlvLsas()) {
+ lsdbStatus.addCoordinateLsa(tlvLsa);
+ }
- m_keyChain.sign(*data);
- m_face.put(*data);
+ for (const tlv::NameLsa& tlvLsa : m_nameLsaPublisher.getTlvLsas()) {
+ lsdbStatus.addNameLsa(tlvLsa);
+ }
+ const ndn::Block& wire = lsdbStatus.wireEncode();
+ context.append(wire);
+ context.end();
}
} // namespace nlsr
diff --git a/src/publisher/lsdb-dataset-interest-handler.hpp b/src/publisher/lsdb-dataset-interest-handler.hpp
index 3976cd1..f16075f 100644
--- a/src/publisher/lsdb-dataset-interest-handler.hpp
+++ b/src/publisher/lsdb-dataset-interest-handler.hpp
@@ -23,17 +23,21 @@
#define NLSR_PUBLISHER_LSDB_DATASET_INTEREST_HANDLER_HPP
#include "lsa-publisher.hpp"
-#include "lsdb-status-publisher.hpp"
+#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/face.hpp>
+#include <boost/noncopyable.hpp>
+#include "tlv/adjacency-lsa.hpp"
+#include "tlv/coordinate-lsa.hpp"
+#include "tlv/name-lsa.hpp"
namespace nlsr {
/*!
\brief Class to publish all lsa dataset
- \sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
+ \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
*/
-class LsdbDatasetInterestHandler
+class LsdbDatasetInterestHandler : boost::noncopyable
{
public:
class Error : std::runtime_error
@@ -47,15 +51,11 @@
};
LsdbDatasetInterestHandler(Lsdb& lsdb,
+ ndn::mgmt::Dispatcher& localHostDispatcher,
+ ndn::mgmt::Dispatcher& routerNameDispatcher,
ndn::Face& face,
ndn::KeyChain& keyChain);
- void
- startListeningOnLocalhost();
-
- void
- startListeningOnRouterPrefix();
-
const ndn::Name&
getLocalhostCommandPrefix()
{
@@ -65,43 +65,59 @@
ndn::Name&
getRouterNameCommandPrefix()
{
- return m_routerNameCommandPrefix;
+ return m_routerNamePrefix;
}
void
setRouterNameCommandPrefix(const ndn::Name& routerName) {
- m_routerNameCommandPrefix = routerName;
- m_routerNameCommandPrefix.append(Lsdb::NAME_COMPONENT);
+ m_routerNamePrefix = routerName;
+ m_routerNamePrefix.append(Lsdb::NAME_COMPONENT);
}
private:
+ /*! \brief set dispatcher for localhost/router name.
+ */
void
- onInterest(const ndn::Interest& interest, const ndn::Name& commandPrefix);
+ setDispatcher(ndn::mgmt::Dispatcher& dispatcher);
- bool
- isValidCommandPrefix(const ndn::Interest& interest, const ndn::Name& commandPrefix);
-
+ /*! \brief provide adjacent status dataset
+ */
void
- processCommand(const ndn::Interest& interest, const ndn::Name::Component& command);
+ publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context);
+ /*! \brief provide coordinate status dataset
+ */
void
- sendErrorResponse(const ndn::Name& name, uint32_t code, const std::string& error);
+ publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context);
+
+ /*! \brief provide name status dataset
+ */
+ void
+ publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context);
+
+ /*! \brief provide ladb status dataset
+ */
+ void
+ publishAllStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
+ ndn::mgmt::StatusDatasetContext& context);
private:
- const ndn::Name LOCALHOST_COMMAND_PREFIX;
- ndn::Name m_routerNameCommandPrefix;
+ static const ndn::Name LOCALHOST_COMMAND_PREFIX;
+ ndn::Name m_routerNamePrefix;
- ndn::Face& m_face;
- ndn::KeyChain& m_keyChain;
+ ndn::mgmt::Dispatcher& m_localhostDispatcher;
+ ndn::mgmt::Dispatcher& m_routerNameDispatcher;
AdjacencyLsaPublisher m_adjacencyLsaPublisher;
CoordinateLsaPublisher m_coordinateLsaPublisher;
NameLsaPublisher m_nameLsaPublisher;
- LsdbStatusPublisher m_lsdbStatusPublisher;
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- static const uint32_t ERROR_CODE_MALFORMED_COMMAND;
- static const uint32_t ERROR_CODE_UNSUPPORTED_COMMAND;
+ const std::list<AdjLsa>& m_adjacencyLsas;
+ const std::list<CoordinateLsa>& m_coordinateLsas;
+ const std::list<NameLsa>& m_nameLsas;
};
} // namespace nlsr
diff --git a/src/publisher/lsdb-status-publisher.cpp b/src/publisher/lsdb-status-publisher.cpp
deleted file mode 100644
index b7b90bd..0000000
--- a/src/publisher/lsdb-status-publisher.cpp
+++ /dev/null
@@ -1,69 +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,
- * 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 "lsdb-status-publisher.hpp"
-
-#include "lsa.hpp"
-#include "tlv/lsdb-status.hpp"
-
-#include <ndn-cxx/face.hpp>
-
-namespace nlsr {
-
-const ndn::Name::Component LsdbStatusPublisher::DATASET_COMPONENT = ndn::Name::Component("list");
-
-LsdbStatusPublisher::LsdbStatusPublisher(Lsdb& lsdb,
- ndn::Face& face,
- ndn::KeyChain& keyChain,
- AdjacencyLsaPublisher& adjacencyLsaPublisher,
- CoordinateLsaPublisher& coordinateLsaPublisher,
- NameLsaPublisher& nameLsaPublisher)
- : SegmentPublisher<ndn::Face>(face, keyChain)
- , m_adjacencyLsaPublisher(adjacencyLsaPublisher)
- , m_coordinateLsaPublisher(coordinateLsaPublisher)
- , m_nameLsaPublisher(nameLsaPublisher)
-{
-}
-
-size_t
-LsdbStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
-{
- size_t totalLength = 0;
-
- tlv::LsdbStatus lsdbStatus;
- for (const tlv::AdjacencyLsa& tlvLsa : m_adjacencyLsaPublisher.getTlvLsas()) {
- lsdbStatus.addAdjacencyLsa(tlvLsa);
- }
-
- for (const tlv::CoordinateLsa& tlvLsa : m_coordinateLsaPublisher.getTlvLsas()) {
- lsdbStatus.addCoordinateLsa(tlvLsa);
- }
-
- for (const tlv::NameLsa& tlvLsa : m_nameLsaPublisher.getTlvLsas()) {
- lsdbStatus.addNameLsa(tlvLsa);
- }
-
- totalLength += lsdbStatus.wireEncode(outBuffer);
-
- return totalLength;
-}
-
-} // namespace nlsr
diff --git a/src/publisher/lsdb-status-publisher.hpp b/src/publisher/lsdb-status-publisher.hpp
deleted file mode 100644
index 4606b61..0000000
--- a/src/publisher/lsdb-status-publisher.hpp
+++ /dev/null
@@ -1,62 +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,
- * 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_PUBLISHER_LSDB_STATUS_PUBLISHER_HPP
-#define NLSR_PUBLISHER_LSDB_STATUS_PUBLISHER_HPP
-
-#include "lsa-publisher.hpp"
-#include "lsdb.hpp"
-#include "segment-publisher.hpp"
-
-#include <ndn-cxx/face.hpp>
-
-namespace nlsr {
-
-/*!
- \brief Publishes lsdb status dataset
- \sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
- */
-class LsdbStatusPublisher : public SegmentPublisher<ndn::Face>
-{
-public:
- LsdbStatusPublisher(Lsdb& lsdb,
- ndn::Face& face,
- ndn::KeyChain& keyChain,
- AdjacencyLsaPublisher& adjacencyLsaPublisher,
- CoordinateLsaPublisher& coordinateLsaPublisher,
- NameLsaPublisher& nameLsaPublisher);
-
-protected:
- virtual size_t
- generate(ndn::EncodingBuffer& outBuffer);
-
-private:
- AdjacencyLsaPublisher& m_adjacencyLsaPublisher;
- CoordinateLsaPublisher& m_coordinateLsaPublisher;
- NameLsaPublisher& m_nameLsaPublisher;
-
-public:
- static const ndn::Name::Component DATASET_COMPONENT;
-};
-
-} // namespace nlsr
-
-#endif // NLSR_PUBLISHER_LSDB_STATUS_PUBLISHER_HPP
diff --git a/tests/publisher/publisher-fixture.hpp b/tests/publisher/publisher-fixture.hpp
index 30ffa7c..aa80343 100644
--- a/tests/publisher/publisher-fixture.hpp
+++ b/tests/publisher/publisher-fixture.hpp
@@ -22,12 +22,18 @@
#ifndef NLSR_PUBLISHER_FIXTURE_HPP
#define NLSR_PUBLISHER_FIXTURE_HPP
+#include "publisher/lsdb-dataset-interest-handler.hpp"
#include "nlsr.hpp"
#include "../boost-test.hpp"
#include "../test-common.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#include <boost/filesystem.hpp>
+
+using namespace ndn;
namespace nlsr {
namespace test {
@@ -36,10 +42,15 @@
{
public:
PublisherFixture()
- : face(std::make_shared<ndn::util::DummyClientFace>())
- , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
- , lsdb(nlsr, g_scheduler)
+ : face(g_ioService, keyChain, {true, true})
+ , nlsr(g_ioService, g_scheduler, face, g_keyChain)
+ , lsdb(nlsr.getLsdb())
{
+ INIT_LOGGERS("/tmp/","TRACE");
+ nlsr.getConfParameter().setNetwork("/ndn");
+ nlsr.getConfParameter().setRouterName("/This/Router");
+ nlsr.initialize();
+ face.processEvents(ndn::time::milliseconds(10));
}
void
@@ -88,7 +99,6 @@
{
CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
radius, angle);
-
return lsa;
}
@@ -137,10 +147,11 @@
}
public:
- std::shared_ptr<ndn::util::DummyClientFace> face;
- Nlsr nlsr;
- Lsdb lsdb;
+ ndn::util::DummyClientFace face;
ndn::KeyChain keyChain;
+
+ Nlsr nlsr;
+ Lsdb& lsdb;
};
} // namespace test
diff --git a/tests/publisher/test-lsa-publisher.cpp b/tests/publisher/test-lsa-publisher.cpp
deleted file mode 100644
index 6a3045f..0000000
--- a/tests/publisher/test-lsa-publisher.cpp
+++ /dev/null
@@ -1,162 +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,
- * 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 "publisher/lsa-publisher.hpp"
-#include "tlv/adjacency.hpp"
-#include "tlv/adjacency-lsa.hpp"
-#include "tlv/tlv-nlsr.hpp"
-
-#include "publisher-fixture.hpp"
-#include "../boost-test.hpp"
-
-namespace nlsr {
-namespace test {
-
-BOOST_FIXTURE_TEST_SUITE(PublisherTestLsaPublisher, PublisherFixture)
-
-BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic)
-{
- ndn::Name thisRouter("/RouterA");
-
- // Adjacency LSA for RouterA
- AdjLsa routerALsa;
- routerALsa.setOrigRouter(thisRouter);
- addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10);
- lsdb.installAdjLsa(routerALsa);
-
- // Adjacency LSA for RouterB
- AdjLsa routerBLsa;
- routerBLsa.setOrigRouter("/RouterB");
- routerBLsa.setLsSeqNo(5);
- addAdjacency(routerBLsa, "/RouterB/adjacency1", "udp://face-1", 10);
- addAdjacency(routerBLsa, "/RouterB/adjacency2", "udp://face-2", 20);
- addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30);
- lsdb.installAdjLsa(routerBLsa);
-
- AdjacencyLsaPublisher publisher(lsdb, *face, keyChain);
-
- ndn::Name publishingPrefix = ndn::Name(thisRouter);
- publishingPrefix.append(Lsdb::NAME_COMPONENT).append(AdjacencyLsaPublisher::DATASET_COMPONENT);
-
- publisher.publish(publishingPrefix);
- face->processEvents(ndn::time::milliseconds(1));
-
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
- ndn::Block parser = face->sentData[0].getContent();
- parser.parse();
-
- // Check RouterB LSA
- ndn::Block::element_const_iterator it = parser.elements_begin();
- checkTlvAdjLsa(*it, routerBLsa);
-
- // Check RouterA LSA
- it++;
- checkTlvAdjLsa(*it, routerALsa);
-}
-
-BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
-{
- ndn::Name thisRouter("/RouterA");
-
- std::vector<double> anglesA, anglesB, anglesC;
- anglesA.push_back(20.00);
- anglesB.push_back(543.21);
- // Setting two angles for testing routerCLsa
- anglesC.push_back(0.02);
- anglesC.push_back(1.23);
-
- CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, anglesA);
- lsdb.installCoordinateLsa(routerALsa);
-
- CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, anglesB);
- lsdb.installCoordinateLsa(routerBLsa);
-
- CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, anglesC);
- lsdb.installCoordinateLsa(routerCLsa);
-
- CoordinateLsaPublisher publisher(lsdb, *face, keyChain);
-
- ndn::Name publishingPrefix = ndn::Name(thisRouter);
- publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT);
-
- publisher.publish(publishingPrefix);
- face->processEvents(ndn::time::milliseconds(1));
-
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
- ndn::Block parser = face->sentData[0].getContent();
- parser.parse();
-
- // Check RouterC LSA
- ndn::Block::element_const_iterator it = parser.elements_begin();
- checkTlvCoordinateLsa(*it, routerCLsa);
-
- // Check RouterB LSA
- ++it;
- checkTlvCoordinateLsa(*it, routerBLsa);
-
- // Check RouterA LSA
- ++it;
- checkTlvCoordinateLsa(*it, routerALsa);
-}
-
-BOOST_AUTO_TEST_CASE(NameLsaBasic)
-{
- ndn::Name thisRouter("/RouterA");
-
- // Name LSA for RouterA
- NameLsa routerALsa;
- routerALsa.setOrigRouter(thisRouter.toUri());
- routerALsa.addName(ndn::Name(thisRouter).append("name1"));
- lsdb.installNameLsa(routerALsa);
-
- // Name LSA for RouterB
- NameLsa routerBLsa;
- routerBLsa.setOrigRouter("/RouterB");
- routerBLsa.addName("/RouterB/name1");
- routerBLsa.addName("/RouterB/name2");
- routerBLsa.addName("/RouterB/name3");
- lsdb.installNameLsa(routerBLsa);
-
- NameLsaPublisher publisher(lsdb, *face, keyChain);
-
- ndn::Name publishingPrefix = ndn::Name(thisRouter);
- publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT);
-
- publisher.publish(publishingPrefix);
- face->processEvents(ndn::time::milliseconds(1));
-
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
- ndn::Block parser = face->sentData[0].getContent();
- parser.parse();
-
- // Check RouterB LSA
- ndn::Block::element_const_iterator it = parser.elements_begin();
- checkTlvNameLsa(*it, routerBLsa);
-
- // Check RouterA LSA
- it++;
- checkTlvNameLsa(*it, routerALsa);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace test
-} // namespace nlsr
diff --git a/tests/publisher/test-lsdb-dataset-interest-handler.cpp b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
index e08d1f2..cd9fcf3 100644
--- a/tests/publisher/test-lsdb-dataset-interest-handler.cpp
+++ b/tests/publisher/test-lsdb-dataset-interest-handler.cpp
@@ -20,6 +20,7 @@
**/
#include "publisher/lsdb-dataset-interest-handler.hpp"
+#include "tests/test-common.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "publisher-fixture.hpp"
@@ -31,13 +32,13 @@
namespace test {
void
-processDatasetInterest(std::shared_ptr<ndn::util::DummyClientFace> face,
+processDatasetInterest(ndn::util::DummyClientFace& face,
std::function<bool(const ndn::Block&)> isSameType)
{
- face->processEvents(ndn::time::milliseconds(1));
+ face.processEvents(ndn::time::milliseconds(30));
+ BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
- ndn::Block parser(face->sentData[0].getContent());
+ ndn::Block parser(face.sentData[0].getContent());
parser.parse();
ndn::Block::element_const_iterator it = parser.elements_begin();
@@ -46,23 +47,23 @@
BOOST_CHECK(it == parser.elements_end());
- face->sentData.clear();
+ face.sentData.clear();
}
void
-checkErrorResponse(std::shared_ptr<ndn::util::DummyClientFace> face, uint64_t expectedCode)
+checkErrorResponse(ndn::util::DummyClientFace& face, uint64_t expectedCode)
{
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
+ BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
- ndn::nfd::ControlResponse response(face->sentData[0].getContent().blockFromValue());
+ ndn::nfd::ControlResponse response(face.sentData[0].getContent().blockFromValue());
BOOST_CHECK_EQUAL(response.getCode(), expectedCode);
- face->sentData.clear();
+ face.sentData.clear();
}
BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
-BOOST_AUTO_TEST_CASE(Basic)
+BOOST_AUTO_TEST_CASE(Localhost)
{
// Install adjacency LSA
AdjLsa adjLsa;
@@ -82,109 +83,61 @@
nameLsa.addName("/RouterA/name1");
lsdb.installNameLsa(nameLsa);
- ndn::Name thisRouter("/This/Router");
- LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
- publisher.setRouterNameCommandPrefix(thisRouter);
-
- publisher.startListeningOnLocalhost();
-
- face->processEvents(ndn::time::milliseconds(10));
-
- // Localhost prefix
- ndn::Name localhostCommandPrefix = publisher.getLocalhostCommandPrefix();
-
// Request adjacency LSAs
- face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("adjacencies")));
+ face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("adjacencies")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
// Request coordinate LSAs
- face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("coordinates")));
+ face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("coordinates")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
// Request Name LSAs
- face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("names")));
+ face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("names")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
// Request LSDB Status
- face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("list")));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
-
- // Router name prefix
- ndn::Name routerCommandPrefix = publisher.getLocalhostCommandPrefix();
-
- // Request adjacency LSAs
- face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("adjacencies")));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
-
- // Request coordinate LSAs
- face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("coordinates")));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
-
- // Request Name LSAs
- face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("names")));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
-
- // Request LSDB Status
- face->receive(ndn::Interest(ndn::Name(routerCommandPrefix).append("list")));
+ face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("list")));
processDatasetInterest(face,
[] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
}
-BOOST_AUTO_TEST_CASE(InvalidCommand)
+
+BOOST_AUTO_TEST_CASE(Routername)
{
- ndn::Name thisRouter("/This/Router");
- LsdbDatasetInterestHandler publisher(lsdb, *face, keyChain);
- publisher.setRouterNameCommandPrefix(thisRouter);
+ //Install adjacencies LSA
+ AdjLsa adjLsa;
+ adjLsa.setOrigRouter("/RouterA");
+ addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
+ lsdb.installAdjLsa(adjLsa);
- // Localhost prefix
- publisher.startListeningOnLocalhost();
- face->processEvents(ndn::time::milliseconds(10));
+ std::vector<double> angles = {20.00, 30.00};
- ndn::Name localhostCommandPrefix = publisher.getLocalhostCommandPrefix();
+ //Install coordinate LSA
+ CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
+ lsdb.installCoordinateLsa(coordinateLsa);
- // Unsupported command
- face->receive(ndn::Interest(ndn::Name(localhostCommandPrefix).append("unsupported")));
- face->processEvents(ndn::time::milliseconds(1));
+ // Request adjacency LSAs
+ face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("adjacencies")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
- checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND);
+ // Request coordinate LSAs
+ face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("coordinates")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
- // Long malformed command
- face->receive(
- ndn::Interest(ndn::Name(localhostCommandPrefix).append("extra").append("malformed")));
- face->processEvents(ndn::time::milliseconds(1));
+ // Request Name LSAs
+ face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("names")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
- checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_MALFORMED_COMMAND);
-
- // Router name prefix
- publisher.startListeningOnRouterPrefix();
- face->processEvents(ndn::time::milliseconds(10));
-
- ndn::Name remoteCommandPrefix = publisher.getRouterNameCommandPrefix();
-
- // Unsupported command
- face->receive(ndn::Interest(ndn::Name(remoteCommandPrefix).append("unsupported")));
- face->processEvents(ndn::time::milliseconds(1));
-
- checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_UNSUPPORTED_COMMAND);
-
- // Long malformed command
- face->receive(ndn::Interest(ndn::Name(remoteCommandPrefix).append("extra").append("malformed")));
- face->processEvents(ndn::time::milliseconds(1));
-
- checkErrorResponse(face, LsdbDatasetInterestHandler::ERROR_CODE_MALFORMED_COMMAND);
-
- // Short malformed command
- face->receive(ndn::Interest(ndn::Name(thisRouter).append("malformed")));
- face->processEvents(ndn::time::milliseconds(1));
-
- BOOST_CHECK_EQUAL(face->sentData.size(), 0);
+ // Request LSDB Status
+ face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("list")));
+ processDatasetInterest(face,
+ [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/publisher/test-lsdb-status-publisher.cpp b/tests/publisher/test-lsdb-status-publisher.cpp
deleted file mode 100644
index c9412ad..0000000
--- a/tests/publisher/test-lsdb-status-publisher.cpp
+++ /dev/null
@@ -1,140 +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,
- * 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 "publisher/lsdb-status-publisher.hpp"
-#include "tlv/lsdb-status.hpp"
-#include "tlv/tlv-nlsr.hpp"
-
-#include "publisher-fixture.hpp"
-#include "../boost-test.hpp"
-
-namespace nlsr {
-namespace test {
-
-BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbStatusPublisher, PublisherFixture)
-
-BOOST_AUTO_TEST_CASE(Basic)
-{
- // Install adjacency LSAs
- // Adjacency LSA for RouterA
- AdjLsa routerAAdjLsa;
- routerAAdjLsa.setOrigRouter("/RouterA");
- addAdjacency(routerAAdjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
- lsdb.installAdjLsa(routerAAdjLsa);
-
- // Adjacency LSA for RouterB
- AdjLsa routerBAdjLsa;
- routerBAdjLsa.setOrigRouter("/RouterB");
- routerBAdjLsa.setLsSeqNo(5);
- addAdjacency(routerBAdjLsa, "/RouterB/adjacency1", "udp://face-1", 10);
- addAdjacency(routerBAdjLsa, "/RouterB/adjacency2", "udp://face-2", 20);
- addAdjacency(routerBAdjLsa, "/RouterB/adjacency3", "udp://face-3", 30);
- lsdb.installAdjLsa(routerBAdjLsa);
-
- std::vector<double> anglesA = {20.00},
- anglesB = {543.21},
- anglesC = {0.02, 2.25};
-
- // Install coordinate LSAs
- CoordinateLsa routerACorLsa = createCoordinateLsa("/RouterA", 10.0, anglesA);
- lsdb.installCoordinateLsa(routerACorLsa);
-
- CoordinateLsa routerBCorLsa = createCoordinateLsa("/RouterB", 123.45, anglesB);
- lsdb.installCoordinateLsa(routerBCorLsa);
-
- CoordinateLsa routerCCorLsa = createCoordinateLsa("/RouterC", 0.01, anglesC);
- lsdb.installCoordinateLsa(routerCCorLsa);
-
- // Install Name LSAs
- // Name LSA for RouterA
- NameLsa routerANameLsa;
- routerANameLsa.setOrigRouter("/RouterA");
- routerANameLsa.addName("/RouterA/name1");
- lsdb.installNameLsa(routerANameLsa);
-
- // Name LSA for RouterB
- NameLsa routerBNameLsa;
- routerBNameLsa.setOrigRouter("/RouterB");
- routerBNameLsa.addName("/RouterB/name1");
- routerBNameLsa.addName("/RouterB/name2");
- routerBNameLsa.addName("/RouterB/name3");
- lsdb.installNameLsa(routerBNameLsa);
-
- ndn::Name thisRouter("/This/Router");
- AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, keyChain);
- CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, keyChain);
- NameLsaPublisher nameLsaPublisher(lsdb, *face, keyChain);
-
- LsdbStatusPublisher publisher(lsdb, *face, keyChain,
- adjacencyLsaPublisher,
- coordinateLsaPublisher,
- nameLsaPublisher);
-
- ndn::Name publishingPrefix = ndn::Name(thisRouter);
- publishingPrefix.append(Lsdb::NAME_COMPONENT).append(LsdbStatusPublisher::DATASET_COMPONENT);
-
- publisher.publish(publishingPrefix);
- face->processEvents(ndn::time::milliseconds(1));
-
- BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
-
- ndn::Block parser = face->sentData[0].getContent();
- parser.parse();
-
- ndn::Block::element_const_iterator it = parser.elements_begin();
-
- BOOST_CHECK_EQUAL(it->type(), ndn::tlv::nlsr::LsdbStatus);
-
- tlv::LsdbStatus lsdbStatusTlv;
- BOOST_REQUIRE_NO_THROW(lsdbStatusTlv.wireDecode(*it));
-
- BOOST_CHECK_EQUAL(lsdbStatusTlv.hasAdjacencyLsas(), true);
-
- // Check adjacency LSAs
- std::list<tlv::AdjacencyLsa>::const_iterator adjLsaIt = lsdbStatusTlv.getAdjacencyLsas().begin();
- checkTlvAdjLsa(*adjLsaIt, routerAAdjLsa);
-
- ++adjLsaIt;
- checkTlvAdjLsa(*adjLsaIt, routerBAdjLsa);
-
- // Check coordinate LSAs
- std::list<tlv::CoordinateLsa>::const_iterator corLsaIt =
- lsdbStatusTlv.getCoordinateLsas().begin();
- checkTlvCoordinateLsa(*corLsaIt, routerACorLsa);
-
- ++corLsaIt;
- checkTlvCoordinateLsa(*corLsaIt, routerBCorLsa);
-
- ++corLsaIt;
- checkTlvCoordinateLsa(*corLsaIt, routerCCorLsa);
-
- // Check Name LSAs
- std::list<tlv::NameLsa>::const_iterator nameLsaIt = lsdbStatusTlv.getNameLsas().begin();
- checkTlvNameLsa(*nameLsaIt, routerANameLsa);
-
- ++nameLsaIt;
- checkTlvNameLsa(*nameLsaIt, routerBNameLsa);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace test
-} // namespace nlsr