Browse Source
refs: #5116 Plus some misc improvements Change-Id: Id0902fec65160b4368b1b5066f460433aced98edpull/14/head
53 changed files with 798 additions and 2078 deletions
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -1,45 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* \author Ashlesh Gawande <agawande@memphis.edu> |
||||
**/ |
||||
|
||||
#include "route/map.hpp" |
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestMapEntry) |
||||
|
||||
BOOST_AUTO_TEST_CASE(MapEntryConstructorAndGetters) |
||||
{ |
||||
std::string rtr = "r0"; |
||||
|
||||
MapEntry me1(rtr, 1); |
||||
|
||||
BOOST_CHECK_EQUAL(me1.getRouter(), "r0"); |
||||
|
||||
BOOST_CHECK_EQUAL(me1.getMappingNumber(), 1); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace nlsr
|
@ -1,86 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2020, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/destination.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestDes) |
||||
|
||||
const uint8_t DesData[] = |
||||
{ |
||||
// Header
|
||||
0x8e, 0x13, |
||||
// Routername 746573742f646573742f746c76
|
||||
0x07, 0x11, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x65, 0x73, 0x74, |
||||
0x08, 0x03, 0x74, 0x6c, 0x76 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(DesEncode) |
||||
{ |
||||
Destination des1; |
||||
des1.setName("/test/dest/tlv"); |
||||
|
||||
const ndn::Block& wire = des1.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(DesData, |
||||
DesData + sizeof(DesData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(DesDecode) |
||||
{ |
||||
Destination des1; |
||||
|
||||
des1.wireDecode(ndn::Block(DesData, sizeof(DesData))); |
||||
|
||||
ndn::Name DEST_NAME = ndn::Name("/test/dest/tlv"); |
||||
BOOST_REQUIRE_EQUAL(des1.getName(), DEST_NAME); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(DesOutputStream) |
||||
{ |
||||
Destination des1; |
||||
des1.setName("/test/dest/tlv"); |
||||
|
||||
std::ostringstream os; |
||||
os << des1; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "Destination: /test/dest/tlv"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(DesMake) |
||||
{ |
||||
RoutingTableEntry rte("/test/dest/tlv"); |
||||
|
||||
std::shared_ptr<Destination> des = makeDes(rte); |
||||
BOOST_CHECK_EQUAL(des->getName(), rte.getDestination()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,80 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2020, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/nexthop.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestNexthops) |
||||
|
||||
const uint8_t NexthopData[] = |
||||
{ |
||||
// Header
|
||||
0x8f, 0x1d, |
||||
// Uri
|
||||
0x8d, 0x11, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, |
||||
0x70, 0x2f, 0x74, 0x6c, 0x76, |
||||
// Cost
|
||||
0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(NexthopEncode) |
||||
{ |
||||
NextHop nexthops1; |
||||
nexthops1.setUri("/test/nexthop/tlv"); |
||||
nexthops1.setCost(1.65); |
||||
|
||||
const ndn::Block& wire = nexthops1.wireEncode(); |
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(NexthopData, |
||||
NexthopData + sizeof(NexthopData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(NexthopDecode) |
||||
{ |
||||
NextHop nexthops1; |
||||
|
||||
nexthops1.wireDecode(ndn::Block(NexthopData, sizeof(NexthopData))); |
||||
|
||||
BOOST_REQUIRE_EQUAL(nexthops1.getUri(), "/test/nexthop/tlv"); |
||||
BOOST_REQUIRE_EQUAL(nexthops1.getCost(), 1.65); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyOutputStream) |
||||
{ |
||||
NextHop nexthops1; |
||||
nexthops1.setUri("/test/nexthop/tlv"); |
||||
nexthops1.setCost(99); |
||||
|
||||
std::ostringstream os; |
||||
os << nexthops1; |
||||
BOOST_CHECK_EQUAL(os.str(), "NextHop(Uri: /test/nexthop/tlv, Cost: 99)\n"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,192 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2020, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/routing-table-entry.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestRoutingTableEntry) |
||||
|
||||
const uint8_t RoutingTableEntryWithNexthopsData[] = |
||||
{ |
||||
// Header
|
||||
0x91, 0x37, |
||||
// Destination
|
||||
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, |
||||
// Nexthop
|
||||
0x8f, 0x14, 0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08, |
||||
0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14, |
||||
// Nexthop
|
||||
0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa, |
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66 |
||||
}; |
||||
|
||||
const uint8_t RoutingTableEntryWithoutNexthopsData[] = |
||||
{ |
||||
// Header
|
||||
0x91, 0x0b, |
||||
// Destination
|
||||
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithNexthops) |
||||
{ |
||||
RoutingTable rt; |
||||
|
||||
Destination des1; |
||||
des1.setName("dest1"); |
||||
rt.setDestination(des1); |
||||
|
||||
NextHop nexthops1; |
||||
nexthops1.setUri("nexthop1"); |
||||
nexthops1.setCost(1.65); |
||||
rt.addNexthops(nexthops1); |
||||
|
||||
NextHop nexthops2; |
||||
nexthops2.setUri("nexthop2"); |
||||
nexthops2.setCost(1.65); |
||||
rt.addNexthops(nexthops2); |
||||
|
||||
const ndn::Block& wire = rt.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithNexthopsData, |
||||
RoutingTableEntryWithNexthopsData + |
||||
sizeof(RoutingTableEntryWithNexthopsData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops) |
||||
{ |
||||
RoutingTable rt; |
||||
|
||||
rt.wireDecode(ndn::Block(RoutingTableEntryWithNexthopsData, |
||||
sizeof(RoutingTableEntryWithNexthopsData))); |
||||
|
||||
Destination des = rt.getDestination(); |
||||
BOOST_CHECK_EQUAL(des.getName(), "dest1"); |
||||
|
||||
BOOST_CHECK_EQUAL(rt.hasNexthops(), true); |
||||
std::list<NextHop> nexthops = rt.getNextHops(); |
||||
std::list<NextHop>::const_iterator it = nexthops.begin(); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "nexthop1"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 1.65); |
||||
|
||||
it++; |
||||
BOOST_CHECK_EQUAL(it->getUri(), "nexthop2"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 1.65); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops) |
||||
{ |
||||
RoutingTable rt; |
||||
|
||||
Destination des1; |
||||
des1.setName("dest1"); |
||||
rt.setDestination(des1); |
||||
|
||||
const ndn::Block& wire = rt.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithoutNexthopsData, |
||||
RoutingTableEntryWithoutNexthopsData + |
||||
sizeof(RoutingTableEntryWithoutNexthopsData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops) |
||||
{ |
||||
RoutingTable rt; |
||||
|
||||
rt.wireDecode(ndn::Block(RoutingTableEntryWithoutNexthopsData, |
||||
sizeof(RoutingTableEntryWithoutNexthopsData))); |
||||
|
||||
Destination des = rt.getDestination(); |
||||
BOOST_CHECK_EQUAL(des.getName(), "dest1"); |
||||
|
||||
BOOST_CHECK_EQUAL(rt.hasNexthops(), false); |
||||
} |
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryClear) |
||||
{ |
||||
RoutingTable rt; |
||||
Destination des1; |
||||
des1.setName("dest1"); |
||||
rt.setDestination(des1); |
||||
|
||||
NextHop nexthops1; |
||||
nexthops1.setUri("nexthop1"); |
||||
nexthops1.setCost(99); |
||||
rt.addNexthops(nexthops1); |
||||
|
||||
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 1); |
||||
|
||||
std::list<NextHop> nexthops = rt.getNextHops(); |
||||
std::list<NextHop>::const_iterator it = nexthops.begin(); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "nexthop1"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 99); |
||||
|
||||
rt.clearNexthops(); |
||||
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 0); |
||||
|
||||
NextHop nexthops2; |
||||
nexthops2.setUri("nexthop2"); |
||||
nexthops2.setCost(99); |
||||
rt.addNexthops(nexthops2); |
||||
|
||||
BOOST_CHECK_EQUAL(rt.getNextHops().size(), 1); |
||||
|
||||
nexthops = rt.getNextHops(); |
||||
it = nexthops.begin(); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "nexthop2"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 99); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream) |
||||
{ |
||||
RoutingTable rt; |
||||
Destination des1; |
||||
des1.setName("dest1"); |
||||
rt.setDestination(des1); |
||||
|
||||
NextHop nexthops1; |
||||
nexthops1.setUri("nexthop1"); |
||||
nexthops1.setCost(99); |
||||
rt.addNexthops(nexthops1); |
||||
|
||||
std::ostringstream os; |
||||
os << rt; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), |
||||
"Destination: /dest1\n" |
||||
"NexthopList(\n" |
||||
"NextHop(Uri: nexthop1, Cost: 99)\n" |
||||
")"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,168 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2020, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/routing-table-status.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestRoutingTable) |
||||
|
||||
const uint8_t RoutingTableData1[] = |
||||
{ |
||||
// Header
|
||||
0x90, 0x22, |
||||
// Routing table entry
|
||||
0x91, 0x20, |
||||
// Destination
|
||||
0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, |
||||
// Nexthop
|
||||
0x8f, 0x13, 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, |
||||
0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66 |
||||
}; |
||||
|
||||
const uint8_t RoutingTableData2[] = |
||||
{ |
||||
// Header
|
||||
0x90, 0x00 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEncode1) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
|
||||
Destination des; |
||||
des.setName("dest1"); |
||||
|
||||
// RoutingtableEntry
|
||||
RoutingTable rt; |
||||
rt.setDestination(des); |
||||
|
||||
NextHop nexthops; |
||||
nexthops.setUri("nexthop"); |
||||
nexthops.setCost(1.65); |
||||
rt.addNexthops(nexthops); |
||||
|
||||
rtStatus.addRoutingTable(rt); |
||||
|
||||
const ndn::Block& wire = rtStatus.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1, |
||||
RoutingTableData1 + sizeof(RoutingTableData1), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableEncode2) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
|
||||
const ndn::Block& wire = rtStatus.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2, |
||||
RoutingTableData2 + sizeof(RoutingTableData2), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableDecode1) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
|
||||
rtStatus.wireDecode(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1))); |
||||
|
||||
std::list<RoutingTable> rte = rtStatus.getRoutingtable(); |
||||
std::list<RoutingTable>::const_iterator it1 = rte.begin(); |
||||
|
||||
Destination des1 = it1->getDestination(); |
||||
BOOST_CHECK_EQUAL(des1.getName(), "dest1"); |
||||
|
||||
std::list<NextHop> nexthops = it1->getNextHops(); |
||||
std::list<NextHop>::const_iterator it2 = nexthops.begin(); |
||||
BOOST_CHECK_EQUAL(it2->getUri(), "nexthop"); |
||||
BOOST_CHECK_EQUAL(it2->getCost(), 1.65); |
||||
|
||||
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableDecode2) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
rtStatus.wireDecode(ndn::Block(RoutingTableData2, sizeof(RoutingTableData2))); |
||||
|
||||
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableClear) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
Destination des; |
||||
des.setName("dest1"); |
||||
|
||||
// RoutingtableEntry
|
||||
RoutingTable rt; |
||||
rt.setDestination(des); |
||||
|
||||
NextHop nexthops; |
||||
nexthops.setUri("nexthop"); |
||||
nexthops.setCost(1.65); |
||||
rt.addNexthops(nexthops); |
||||
|
||||
rtStatus.addRoutingTable(rt); |
||||
|
||||
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true); |
||||
rtStatus.clearRoutingTable(); |
||||
BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(RoutingTableOutputStream) |
||||
{ |
||||
RoutingTableStatus rtStatus; |
||||
Destination des; |
||||
des.setName("dest1"); |
||||
|
||||
// RoutingtableEntry
|
||||
RoutingTable rt; |
||||
rt.setDestination(des); |
||||
|
||||
NextHop nexthops; |
||||
nexthops.setUri("nexthop"); |
||||
nexthops.setCost(99); |
||||
rt.addNexthops(nexthops); |
||||
|
||||
rtStatus.addRoutingTable(rt); |
||||
|
||||
std::ostringstream os; |
||||
os << rtStatus; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "Routing Table Status: \n" |
||||
"Destination: /dest1\n" |
||||
"NexthopList(\n" |
||||
"NextHop(Uri: nexthop, Cost: 99)\n" |
||||
")"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
Loading…
Reference in new issue