Browse Source
Lsa de/serialize functions are replaced by wireEncode/Decode. Update LSA wire formats. Change TLV assignments as required. Update nlsrc to print using new encoding. refs: #4787 Change-Id: Ie8d40b7836d51ea5bb444c8db208dc2b3a0d1cecpull/14/head
83 changed files with 1552 additions and 3612 deletions
@ -1,379 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "lsa.hpp" |
||||
#include "nlsr.hpp" |
||||
#include "name-prefix-list.hpp" |
||||
#include "adjacent.hpp" |
||||
#include "logger.hpp" |
||||
|
||||
#include <string> |
||||
#include <iostream> |
||||
#include <sstream> |
||||
#include <algorithm> |
||||
#include <cmath> |
||||
#include <limits> |
||||
#include <boost/algorithm/string.hpp> |
||||
|
||||
namespace nlsr { |
||||
|
||||
INIT_LOGGER(Lsa); |
||||
|
||||
std::string |
||||
Lsa::getData() const |
||||
{ |
||||
std::ostringstream os; |
||||
os << m_origRouter << "|" << getType() << "|" << m_lsSeqNo << "|" |
||||
<< ndn::time::toIsoString(m_expirationTimePoint) << "|"; |
||||
return os.str(); |
||||
} |
||||
|
||||
const ndn::Name |
||||
Lsa::getKey() const |
||||
{ |
||||
return ndn::Name(m_origRouter).append(std::to_string(getType())); |
||||
} |
||||
|
||||
bool |
||||
Lsa::deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator) |
||||
{ |
||||
m_origRouter = ndn::Name(*iterator++); |
||||
if (m_origRouter.size() <= 0) |
||||
return false; |
||||
if (*iterator++ != std::to_string(getType())) |
||||
return false; |
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(*iterator++); |
||||
m_expirationTimePoint = ndn::time::fromIsoString(*iterator++); |
||||
return true; |
||||
} |
||||
|
||||
NameLsa::NameLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
NamePrefixList& npl) |
||||
{ |
||||
m_origRouter = origR; |
||||
m_lsSeqNo = lsn; |
||||
m_expirationTimePoint = lt; |
||||
for (const auto& name : npl.getNames()) { |
||||
addName(name); |
||||
} |
||||
} |
||||
|
||||
std::string |
||||
NameLsa::serialize() const |
||||
{ |
||||
std::ostringstream os; |
||||
os << getData() << m_npl.size(); |
||||
for (const auto& name : m_npl.getNames()) { |
||||
os << "|" << name; |
||||
} |
||||
os << "|"; |
||||
return os.str(); |
||||
} |
||||
|
||||
bool |
||||
NameLsa::deserialize(const std::string& content) noexcept |
||||
{ |
||||
uint32_t numName = 0; |
||||
boost::char_separator<char> sep("|"); |
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
||||
tokens.begin(); |
||||
|
||||
try { |
||||
if (!deserializeCommon(tok_iter)) |
||||
return false; |
||||
numName = boost::lexical_cast<uint32_t>(*tok_iter++); |
||||
for (uint32_t i = 0; i < numName; i++) { |
||||
ndn::Name name(*tok_iter++); |
||||
addName(name); |
||||
} |
||||
} |
||||
catch (const std::exception& e) { |
||||
NLSR_LOG_ERROR("Could not deserialize from content: " << e.what()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
bool |
||||
NameLsa::isEqualContent(const NameLsa& other) const |
||||
{ |
||||
return m_npl == other.getNpl(); |
||||
} |
||||
|
||||
void |
||||
NameLsa::writeLog() const |
||||
{ |
||||
NLSR_LOG_DEBUG(*this); |
||||
} |
||||
|
||||
CoordinateLsa::CoordinateLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
double r, std::vector<double> theta) |
||||
{ |
||||
m_origRouter = origR; |
||||
m_lsSeqNo = lsn; |
||||
m_expirationTimePoint = lt; |
||||
m_corRad = r; |
||||
m_angles = theta; |
||||
} |
||||
|
||||
bool |
||||
CoordinateLsa::isEqualContent(const CoordinateLsa& clsa) const |
||||
{ |
||||
if (clsa.getCorTheta().size() != m_angles.size()) { |
||||
return false; |
||||
} |
||||
|
||||
std::vector<double> m_angles2 = clsa.getCorTheta(); |
||||
for (unsigned int i = 0; i < clsa.getCorTheta().size(); i++) { |
||||
if (std::abs(m_angles[i] - m_angles2[i]) > std::numeric_limits<double>::epsilon()) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return (std::abs(m_corRad - clsa.getCorRadius()) < |
||||
std::numeric_limits<double>::epsilon()); |
||||
} |
||||
|
||||
std::string |
||||
CoordinateLsa::serialize() const |
||||
{ |
||||
std::ostringstream os; |
||||
os << getData() << m_corRad << "|" << m_angles.size() << "|"; |
||||
for (const auto& angle: m_angles) { |
||||
os << angle << "|"; |
||||
} |
||||
return os.str(); |
||||
} |
||||
|
||||
bool |
||||
CoordinateLsa::deserialize(const std::string& content) noexcept |
||||
{ |
||||
boost::char_separator<char> sep("|"); |
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
||||
tokens.begin(); |
||||
|
||||
try { |
||||
if (!deserializeCommon(tok_iter)) |
||||
return false; |
||||
m_corRad = boost::lexical_cast<double>(*tok_iter++); |
||||
int numAngles = boost::lexical_cast<uint32_t>(*tok_iter++); |
||||
for (int i = 0; i < numAngles; i++) { |
||||
m_angles.push_back(boost::lexical_cast<double>(*tok_iter++)); |
||||
} |
||||
} |
||||
catch (const std::exception& e) { |
||||
NLSR_LOG_ERROR("Could not deserialize from content: " << e.what()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void |
||||
CoordinateLsa::writeLog() const |
||||
{ |
||||
NLSR_LOG_DEBUG(*this); |
||||
} |
||||
|
||||
AdjLsa::AdjLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
uint32_t nl , AdjacencyList& adl) |
||||
{ |
||||
m_origRouter = origR; |
||||
m_lsSeqNo = lsn; |
||||
m_expirationTimePoint = lt; |
||||
m_noLink = nl; |
||||
std::list<Adjacent> al = adl.getAdjList(); |
||||
for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) { |
||||
if (it->getStatus() == Adjacent::STATUS_ACTIVE) { |
||||
addAdjacent((*it)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool |
||||
AdjLsa::isEqualContent(const AdjLsa& alsa) const |
||||
{ |
||||
return m_adl == alsa.getAdl(); |
||||
} |
||||
|
||||
std::string |
||||
AdjLsa::serialize() const |
||||
{ |
||||
std::ostringstream os; |
||||
os << getData() << m_adl.size(); |
||||
for (const auto& adjacent : m_adl.getAdjList()) { |
||||
os << "|" << adjacent.getName() << "|" << adjacent.getFaceUri() |
||||
<< "|" << adjacent.getLinkCost(); |
||||
} |
||||
os << "|"; |
||||
return os.str(); |
||||
} |
||||
|
||||
bool |
||||
AdjLsa::deserialize(const std::string& content) noexcept |
||||
{ |
||||
uint32_t numLink = 0; |
||||
boost::char_separator<char> sep("|"); |
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
||||
tokens.begin(); |
||||
|
||||
try { |
||||
if (!deserializeCommon(tok_iter)) |
||||
return false; |
||||
numLink = boost::lexical_cast<uint32_t>(*tok_iter++); |
||||
for (uint32_t i = 0; i < numLink; i++) { |
||||
ndn::Name adjName(*tok_iter++); |
||||
std::string connectingFaceUri(*tok_iter++); |
||||
double linkCost = boost::lexical_cast<double>(*tok_iter++); |
||||
|
||||
Adjacent adjacent(adjName, ndn::FaceUri(connectingFaceUri), linkCost, |
||||
Adjacent::STATUS_INACTIVE, 0, 0); |
||||
addAdjacent(adjacent); |
||||
} |
||||
} |
||||
// Ignore neighbors with negative cost received from the Adjacent LSA data.
|
||||
catch (const ndn::tlv::Error& e) { |
||||
NLSR_LOG_ERROR(e.what()); |
||||
} |
||||
catch (const std::exception& e) { |
||||
NLSR_LOG_ERROR("Could not deserialize from content: " << e.what()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void |
||||
AdjLsa::writeLog() const |
||||
{ |
||||
NLSR_LOG_DEBUG(*this); |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const AdjLsa& lsa) |
||||
{ |
||||
os << lsa.toString(); |
||||
os << "-Adjacents:"; |
||||
|
||||
int adjacencyIndex = 1; |
||||
|
||||
for (const Adjacent& adjacency : lsa.m_adl) { |
||||
os << "--Adjacent" << adjacencyIndex++ << ":\n" |
||||
<< "---Adjacent Name: " << adjacency.getName() << "\n" |
||||
<< "---Connecting FaceUri: " << adjacency.getFaceUri() << "\n" |
||||
<< "---Link Cost: " << adjacency.getLinkCost() << "\n"; |
||||
} |
||||
os << "adj_lsa_end"; |
||||
|
||||
return os; |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const CoordinateLsa& lsa) |
||||
{ |
||||
os << lsa.toString(); |
||||
os << "--Hyperbolic Radius: " << lsa.m_corRad << "\n"; |
||||
int i = 0; |
||||
for (const auto& value : lsa.m_angles) { |
||||
os << "---Hyperbolic Theta: " << i++ << ": " << value << "\n"; |
||||
} |
||||
os << "cor_lsa_end"; |
||||
|
||||
return os; |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const NameLsa& lsa) |
||||
{ |
||||
os << lsa.toString(); |
||||
os << "--Names:\n"; |
||||
int i = 0; |
||||
auto names = lsa.m_npl.getNames(); |
||||
for (const auto& name : names) { |
||||
os << "---Name " << i++ << ": " << name << "\n"; |
||||
} |
||||
os << "name_lsa_end"; |
||||
|
||||
return os; |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Lsa::Type& type) |
||||
{ |
||||
os << std::to_string(type); |
||||
return os; |
||||
} |
||||
|
||||
std::istream& |
||||
operator>>(std::istream& is, Lsa::Type& type) |
||||
{ |
||||
std::string typeString; |
||||
is >> typeString; |
||||
if (typeString == "ADJACENCY") { |
||||
type = Lsa::Type::ADJACENCY; |
||||
} |
||||
else if (typeString == "COORDINATE") { |
||||
type = Lsa::Type::COORDINATE; |
||||
} |
||||
else if (typeString == "NAME") { |
||||
type = Lsa::Type::NAME; |
||||
} |
||||
else { |
||||
type = Lsa::Type::BASE; |
||||
} |
||||
return is; |
||||
} |
||||
|
||||
std::string |
||||
Lsa::toString() const |
||||
{ |
||||
std::ostringstream os; |
||||
os << "LSA of type " << getType() << ":\n-Origin Router: " << getOrigRouter() |
||||
<< "\n-Sequence Number: " << getLsSeqNo() << "\n-Expiration Point: " |
||||
<< getExpirationTimePoint() << "\n"; |
||||
return os.str(); |
||||
} |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
namespace std { |
||||
std::string |
||||
to_string(const nlsr::Lsa::Type& type) |
||||
{ |
||||
switch (type) { |
||||
case nlsr::Lsa::Type::ADJACENCY: |
||||
return "ADJACENCY"; |
||||
case nlsr::Lsa::Type::COORDINATE: |
||||
return "COORDINATE"; |
||||
case nlsr::Lsa::Type::NAME: |
||||
return "NAME"; |
||||
case nlsr::Lsa::Type::MOCK: |
||||
return "MOCK"; |
||||
default: |
||||
return "BASE"; |
||||
} |
||||
} |
||||
|
||||
} // namespace std
|
@ -1,401 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/*
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef NLSR_LSA_HPP |
||||
#define NLSR_LSA_HPP |
||||
|
||||
#include "name-prefix-list.hpp" |
||||
#include "adjacent.hpp" |
||||
#include "adjacency-list.hpp" |
||||
|
||||
#include <ndn-cxx/util/scheduler.hpp> |
||||
#include <ndn-cxx/util/time.hpp> |
||||
#include <boost/tokenizer.hpp> |
||||
|
||||
namespace nlsr { |
||||
|
||||
class Lsa |
||||
{ |
||||
public: |
||||
enum class Type { |
||||
ADJACENCY, |
||||
COORDINATE, |
||||
NAME, |
||||
BASE, |
||||
MOCK |
||||
}; |
||||
|
||||
virtual |
||||
~Lsa() = default; |
||||
|
||||
virtual Type |
||||
getType() const |
||||
{ |
||||
return Type::BASE; |
||||
} |
||||
|
||||
void |
||||
setLsSeqNo(uint32_t lsn) |
||||
{ |
||||
m_lsSeqNo = lsn; |
||||
} |
||||
|
||||
uint32_t |
||||
getLsSeqNo() const |
||||
{ |
||||
return m_lsSeqNo; |
||||
} |
||||
|
||||
const ndn::Name& |
||||
getOrigRouter() const |
||||
{ |
||||
return m_origRouter; |
||||
} |
||||
|
||||
void |
||||
setOrigRouter(const ndn::Name& org) |
||||
{ |
||||
m_origRouter = org; |
||||
} |
||||
|
||||
const ndn::time::system_clock::TimePoint& |
||||
getExpirationTimePoint() const |
||||
{ |
||||
return m_expirationTimePoint; |
||||
} |
||||
|
||||
void |
||||
setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt) |
||||
{ |
||||
m_expirationTimePoint = lt; |
||||
} |
||||
|
||||
void |
||||
setExpiringEventId(ndn::scheduler::EventId eid) |
||||
{ |
||||
m_expiringEventId = std::move(eid); |
||||
} |
||||
|
||||
ndn::scheduler::EventId |
||||
getExpiringEventId() const |
||||
{ |
||||
return m_expiringEventId; |
||||
} |
||||
|
||||
/*! \brief Return the data that this LSA represents.
|
||||
*/ |
||||
virtual std::string |
||||
serialize() const = 0; |
||||
|
||||
/*! \brief Gets the key for this LSA.
|
||||
|
||||
Format is: \<router name\>/\<LSA type>\
|
||||
*/ |
||||
const ndn::Name |
||||
getKey() const; |
||||
|
||||
/*! \brief Populate this LSA with content from the string "content".
|
||||
\param content The string containing a valid serialization of LSA content. |
||||
|
||||
This method populates "this" LSA with data from the string. |
||||
*/ |
||||
virtual bool |
||||
deserialize(const std::string& content) noexcept = 0; |
||||
|
||||
virtual void |
||||
writeLog() const = 0; |
||||
|
||||
protected: |
||||
/*! Get data common to all LSA types.
|
||||
|
||||
This method should be called by all LSA classes in their |
||||
serialize() method. |
||||
*/ |
||||
std::string |
||||
getData() const; |
||||
|
||||
/*! Print data common to all LSA types.
|
||||
*/ |
||||
std::string |
||||
toString() const; |
||||
|
||||
bool |
||||
deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator); |
||||
|
||||
protected: |
||||
ndn::Name m_origRouter; |
||||
uint32_t m_lsSeqNo = 0; |
||||
ndn::time::system_clock::TimePoint m_expirationTimePoint; |
||||
ndn::scheduler::EventId m_expiringEventId; |
||||
}; |
||||
|
||||
class NameLsa : public Lsa |
||||
{ |
||||
public: |
||||
NameLsa() = default; |
||||
|
||||
NameLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
NamePrefixList& npl); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::NAME; |
||||
} |
||||
|
||||
NamePrefixList& |
||||
getNpl() |
||||
{ |
||||
return m_npl; |
||||
} |
||||
|
||||
const NamePrefixList& |
||||
getNpl() const |
||||
{ |
||||
return m_npl; |
||||
} |
||||
|
||||
void |
||||
addName(const ndn::Name& name) |
||||
{ |
||||
m_npl.insert(name); |
||||
} |
||||
|
||||
void |
||||
removeName(const ndn::Name& name) |
||||
{ |
||||
m_npl.remove(name); |
||||
} |
||||
|
||||
/*! \brief Initializes this LSA object with content's data.
|
||||
|
||||
\param content The data (e.g. name prefixes) to initialize this LSA with. |
||||
|
||||
This function initializes this object to represent the data |
||||
contained in content. The format for this is the same as for |
||||
getData(); getData() returns data of this format, in other words. |
||||
*/ |
||||
bool |
||||
deserialize(const std::string& content) noexcept override; |
||||
|
||||
bool |
||||
isEqualContent(const NameLsa& other) const; |
||||
|
||||
void |
||||
writeLog() const override; |
||||
|
||||
/*! \brief Returns the data that this name LSA has.
|
||||
|
||||
Format is: \<original router |
||||
prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix |
||||
2\>|...|\<prefix n\>| |
||||
*/ |
||||
std::string |
||||
serialize() const override; |
||||
|
||||
private: |
||||
NamePrefixList m_npl; |
||||
|
||||
friend std::ostream& |
||||
operator<<(std::ostream& os, const NameLsa& lsa); |
||||
}; |
||||
|
||||
class AdjLsa : public Lsa |
||||
{ |
||||
public: |
||||
typedef AdjacencyList::const_iterator const_iterator; |
||||
|
||||
AdjLsa() = default; |
||||
|
||||
AdjLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
uint32_t nl , AdjacencyList& adl); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::ADJACENCY; |
||||
} |
||||
|
||||
AdjacencyList& |
||||
getAdl() |
||||
{ |
||||
return m_adl; |
||||
} |
||||
|
||||
const AdjacencyList& |
||||
getAdl() const |
||||
{ |
||||
return m_adl; |
||||
} |
||||
|
||||
void |
||||
addAdjacent(Adjacent adj) |
||||
{ |
||||
m_adl.insert(adj); |
||||
} |
||||
|
||||
/*! \brief Initializes this adj. LSA from the supplied content.
|
||||
|
||||
\param content The content that this LSA is to have, formatted |
||||
according to getData(). |
||||
*/ |
||||
bool |
||||
deserialize(const std::string& content) noexcept override; |
||||
|
||||
uint32_t |
||||
getNoLink() |
||||
{ |
||||
return m_noLink; |
||||
} |
||||
|
||||
bool |
||||
isEqualContent(const AdjLsa& alsa) const; |
||||
|
||||
void |
||||
writeLog() const override; |
||||
|
||||
const_iterator |
||||
begin() const |
||||
{ |
||||
return m_adl.begin(); |
||||
} |
||||
|
||||
const_iterator |
||||
end() const |
||||
{ |
||||
return m_adl.end(); |
||||
} |
||||
|
||||
/*! \brief Returns the data this adjacency LSA has.
|
||||
|
||||
The format is: \<original |
||||
router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix |
||||
1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri |
||||
n\>|\<cost n\>| |
||||
*/ |
||||
std::string |
||||
serialize() const override; |
||||
|
||||
private: |
||||
uint32_t m_noLink; |
||||
AdjacencyList m_adl; |
||||
|
||||
friend std::ostream& |
||||
operator<<(std::ostream& os, const AdjLsa& lsa); |
||||
}; |
||||
|
||||
class CoordinateLsa : public Lsa |
||||
{ |
||||
public: |
||||
CoordinateLsa() = default; |
||||
|
||||
CoordinateLsa(const ndn::Name& origR, uint32_t lsn, |
||||
const ndn::time::system_clock::TimePoint& lt, |
||||
double r, std::vector<double> theta); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::COORDINATE; |
||||
} |
||||
|
||||
/*! \brief Initializes this coordinate LSA with the data in content.
|
||||
|
||||
\param content The string content that is used to build the LSA. |
||||
|
||||
This function initializes this LSA object to represent the data |
||||
specified by the parameter. The format that it is expecting is the |
||||
same as for getData(); |
||||
*/ |
||||
bool |
||||
deserialize(const std::string& content) noexcept override; |
||||
|
||||
double |
||||
getCorRadius() const |
||||
{ |
||||
return m_corRad; |
||||
} |
||||
|
||||
void |
||||
setCorRadius(double cr) |
||||
{ |
||||
m_corRad = cr; |
||||
} |
||||
|
||||
const std::vector<double> |
||||
getCorTheta() const |
||||
{ |
||||
return m_angles; |
||||
} |
||||
|
||||
void |
||||
setCorTheta(std::vector<double> ct) |
||||
{ |
||||
m_angles = ct; |
||||
} |
||||
|
||||
bool |
||||
isEqualContent(const CoordinateLsa& clsa) const; |
||||
|
||||
void |
||||
writeLog() const override; |
||||
|
||||
/*! \brief Returns the data that this coordinate LSA represents.
|
||||
|
||||
The format is: \<original |
||||
router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>| |
||||
*/ |
||||
std::string |
||||
serialize() const override; |
||||
|
||||
private: |
||||
double m_corRad = 0.0; |
||||
std::vector<double> m_angles; |
||||
|
||||
friend std::ostream& |
||||
operator<<(std::ostream& os, const CoordinateLsa& lsa); |
||||
}; |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const AdjLsa& lsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const CoordinateLsa& lsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const NameLsa& lsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Lsa::Type& type); |
||||
|
||||
std::istream& |
||||
operator>>(std::istream& is, Lsa::Type& type); |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
namespace std { |
||||
std::string |
||||
to_string(const nlsr::Lsa::Type& type); |
||||
} // namespace std
|
||||
|
||||
#endif // NLSR_LSA_HPP
|
@ -0,0 +1,123 @@
|
||||
/* -*- 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/>.
|
||||
**/ |
||||
|
||||
#ifndef NLSR_LSA_ADJ_LSA_HPP |
||||
#define NLSR_LSA_ADJ_LSA_HPP |
||||
|
||||
#include "lsa.hpp" |
||||
#include "test-access-control.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for AdjLsa |
||||
AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH |
||||
Lsa |
||||
Adjacency* |
||||
|
||||
*/ |
||||
class AdjLsa : public Lsa |
||||
{ |
||||
public: |
||||
typedef AdjacencyList::const_iterator const_iterator; |
||||
|
||||
AdjLsa() = default; |
||||
|
||||
AdjLsa(const ndn::Name& originR, uint32_t seqNo, |
||||
const ndn::time::system_clock::TimePoint& timepoint, |
||||
uint32_t noLink, AdjacencyList& adl); |
||||
|
||||
AdjLsa(const ndn::Block& block); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::ADJACENCY; |
||||
} |
||||
|
||||
const AdjacencyList& |
||||
getAdl() const |
||||
{ |
||||
return m_adl; |
||||
} |
||||
|
||||
void |
||||
resetAdl() |
||||
{ |
||||
m_wire.reset(); |
||||
m_adl.reset(); |
||||
} |
||||
|
||||
void |
||||
addAdjacent(Adjacent adj) |
||||
{ |
||||
m_wire.reset(); |
||||
m_adl.insert(adj); |
||||
} |
||||
|
||||
uint32_t |
||||
getNoLink() |
||||
{ |
||||
return m_noLink; |
||||
} |
||||
|
||||
bool |
||||
isEqualContent(const AdjLsa& alsa) const; |
||||
|
||||
const_iterator |
||||
begin() const |
||||
{ |
||||
return m_adl.begin(); |
||||
} |
||||
|
||||
const_iterator |
||||
end() const |
||||
{ |
||||
return m_adl.end(); |
||||
} |
||||
|
||||
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: |
||||
uint32_t m_noLink; |
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
||||
AdjacencyList m_adl; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjLsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const AdjLsa& lsa); |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_LSA_ADJ_LSA_HPP
|
@ -0,0 +1,106 @@
|
||||
/* -*- 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/>.
|
||||
**/ |
||||
|
||||
#ifndef NLSR_LSA_COORDINATE_LSA_HPP |
||||
#define NLSR_LSA_COORDINATE_LSA_HPP |
||||
|
||||
#include "lsa.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for CoordinateLsa |
||||
CoordinateLsa := COORDINATE-LSA-TYPE TLV-LENGTH |
||||
Lsa |
||||
HyperbolicRadius |
||||
HyperbolicAngle+ |
||||
*/ |
||||
class CoordinateLsa : public Lsa |
||||
{ |
||||
public: |
||||
CoordinateLsa() = default; |
||||
|
||||
CoordinateLsa(const ndn::Name& originRouter, uint32_t seqNo, |
||||
const ndn::time::system_clock::TimePoint& timepoint, |
||||
double radius, std::vector<double> angles); |
||||
|
||||
CoordinateLsa(const ndn::Block& block); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::COORDINATE; |
||||
} |
||||
|
||||
double |
||||
getCorRadius() const |
||||
{ |
||||
return m_hyperbolicRadius; |
||||
} |
||||
|
||||
void |
||||
setCorRadius(double cr) |
||||
{ |
||||
m_wire.reset(); |
||||
m_hyperbolicRadius = cr; |
||||
} |
||||
|
||||
const std::vector<double> |
||||
getCorTheta() const |
||||
{ |
||||
return m_hyperbolicAngles; |
||||
} |
||||
|
||||
void |
||||
setCorTheta(std::vector<double> ct) |
||||
{ |
||||
m_wire.reset(); |
||||
m_hyperbolicAngles = ct; |
||||
} |
||||
|
||||
bool |
||||
isEqualContent(const CoordinateLsa& clsa) const; |
||||
|
||||
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: |
||||
double m_hyperbolicRadius = 0.0; |
||||
std::vector<double> m_hyperbolicAngles; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CoordinateLsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const CoordinateLsa& lsa); |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_LSA_COORDINATE_LSA_HPP
|
@ -0,0 +1,167 @@
|
||||
/* -*- 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 "lsa.hpp" |
||||
#include "nlsr.hpp" |
||||
#include "name-prefix-list.hpp" |
||||
#include "adjacent.hpp" |
||||
#include "tlv/tlv-nlsr.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
Lsa::Lsa(const ndn::Name& originRouter, uint32_t seqNo, |
||||
ndn::time::system_clock::TimePoint expirationTimePoint) |
||||
: m_originRouter(originRouter) |
||||
, m_seqNo(seqNo) |
||||
, m_expirationTimePoint(expirationTimePoint) |
||||
{ |
||||
} |
||||
|
||||
ndn::Name |
||||
Lsa::getKey() const |
||||
{ |
||||
return ndn::Name(m_originRouter).append(boost::lexical_cast<std::string>((getType()))); |
||||
} |
||||
|
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
Lsa::wireEncode(ndn::EncodingImpl<TAG>& encoder) const |
||||
{ |
||||
size_t totalLength = 0; |
||||
|
||||
totalLength += prependStringBlock(encoder, |
||||
ndn::tlv::nlsr::ExpirationTime, |
||||
ndn::time::toString(m_expirationTimePoint)); |
||||
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder, ndn::tlv::nlsr::SequenceNumber, |
||||
m_seqNo); |
||||
|
||||
totalLength += m_originRouter.wireEncode(encoder); |
||||
|
||||
totalLength += encoder.prependVarNumber(totalLength); |
||||
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::Lsa); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Lsa); |
||||
|
||||
void |
||||
Lsa::wireDecode(const ndn::Block& wire) |
||||
{ |
||||
m_originRouter.clear(); |
||||
m_seqNo = 0; |
||||
|
||||
m_baseWire = wire; |
||||
|
||||
if (m_baseWire.type() != ndn::tlv::nlsr::Lsa) { |
||||
std::stringstream error; |
||||
error << "Expected Lsa Block, but Block is of a different type: #" |
||||
<< m_baseWire.type(); |
||||
BOOST_THROW_EXCEPTION(Error(error.str())); |
||||
} |
||||
|
||||
m_baseWire.parse(); |
||||
|
||||
ndn::Block::element_const_iterator val = m_baseWire.elements_begin(); |
||||
|
||||
if (val != m_baseWire.elements_end() && val->type() == ndn::tlv::Name) { |
||||
m_originRouter.wireDecode(*val); |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("OriginRouter: Missing required Name field")); |
||||
} |
||||
|
||||
++val; |
||||
|
||||
if (val != m_baseWire.elements_end() && val->type() == ndn::tlv::nlsr::SequenceNumber) { |
||||
m_seqNo = ndn::readNonNegativeInteger(*val); |
||||
++val; |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("Missing required SequenceNumber field")); |
||||
} |
||||
|
||||
if (val != m_baseWire.elements_end() && val->type() == ndn::tlv::nlsr::ExpirationTime) { |
||||
m_expirationTimePoint = ndn::time::fromString(readString(*val)); |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("Missing required ExpirationTimePoint field")); |
||||
} |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Lsa::Type& type) |
||||
{ |
||||
switch (type) { |
||||
case nlsr::Lsa::Type::ADJACENCY: |
||||
os << "ADJACENCY"; |
||||
break; |
||||
|
||||
case nlsr::Lsa::Type::COORDINATE: |
||||
os << "COORDINATE"; |
||||
break; |
||||
|
||||
case nlsr::Lsa::Type::NAME: |
||||
os << "NAME"; |
||||
break; |
||||
|
||||
default: |
||||
os << "BASE"; |
||||
break; |
||||
} |
||||
return os; |
||||
} |
||||
|
||||
std::istream& |
||||
operator>>(std::istream& is, Lsa::Type& type) |
||||
{ |
||||
std::string typeString; |
||||
is >> typeString; |
||||
if (typeString == "ADJACENCY") { |
||||
type = Lsa::Type::ADJACENCY; |
||||
} |
||||
else if (typeString == "COORDINATE") { |
||||
type = Lsa::Type::COORDINATE; |
||||
} |
||||
else if (typeString == "NAME") { |
||||
type = Lsa::Type::NAME; |
||||
} |
||||
else { |
||||
type = Lsa::Type::BASE; |
||||
} |
||||
return is; |
||||
} |
||||
|
||||
std::string |
||||
Lsa::toString() const |
||||
{ |
||||
std::ostringstream os; |
||||
auto duration = getExpirationTimePoint() - ndn::time::system_clock::now(); |
||||
os << " " << getType() << " LSA:\n" |
||||
<< " Origin Router : " << getOriginRouter() << "\n" |
||||
<< " Sequence Number : " << getSeqNo() << "\n" |
||||
<< " Expires in : " << ndn::time::duration_cast<ndn::time::milliseconds>(duration) |
||||
<< "\n"; |
||||
return os.str(); |
||||
} |
||||
|
||||
} // namespace nlsr
|
@ -0,0 +1,160 @@
|
||||
/* -*- 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/>.
|
||||
*/ |
||||
|
||||
#ifndef NLSR_LSA_LSA_HPP |
||||
#define NLSR_LSA_LSA_HPP |
||||
|
||||
#include "name-prefix-list.hpp" |
||||
#include "adjacent.hpp" |
||||
#include "adjacency-list.hpp" |
||||
#include "test-access-control.hpp" |
||||
|
||||
#include <ndn-cxx/util/scheduler.hpp> |
||||
#include <ndn-cxx/util/time.hpp> |
||||
|
||||
namespace nlsr { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for Lsa |
||||
Lsa := LSA-TYPE TLV-LENGTH |
||||
Name |
||||
SequenceNumber |
||||
ExpirationTimePoint |
||||
*/ |
||||
class Lsa |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
enum class Type { |
||||
ADJACENCY, |
||||
COORDINATE, |
||||
NAME, |
||||
BASE |
||||
}; |
||||
|
||||
protected: |
||||
Lsa(const ndn::Name& originRouter, uint32_t seqNo, |
||||
ndn::time::system_clock::TimePoint expirationTimePoint); |
||||
|
||||
Lsa() = default; |
||||
|
||||
public: |
||||
virtual |
||||
~Lsa() = default; |
||||
|
||||
virtual Type |
||||
getType() const |
||||
{ |
||||
return Type::BASE; |
||||
} |
||||
|
||||
void |
||||
setSeqNo(uint64_t seqNo) |
||||
{ |
||||
m_seqNo = seqNo; |
||||
m_baseWire.reset(); |
||||
} |
||||
|
||||
uint64_t |
||||
getSeqNo() const |
||||
{ |
||||
return m_seqNo; |
||||
} |
||||
|
||||
const ndn::Name& |
||||
getOriginRouter() const |
||||
{ |
||||
return m_originRouter; |
||||
} |
||||
|
||||
const ndn::time::system_clock::TimePoint& |
||||
getExpirationTimePoint() const |
||||
{ |
||||
return m_expirationTimePoint; |
||||
} |
||||
|
||||
void |
||||
setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt) |
||||
{ |
||||
m_expirationTimePoint = lt; |
||||
m_baseWire.reset(); |
||||
} |
||||
|
||||
void |
||||
setExpiringEventId(ndn::scheduler::EventId eid) |
||||
{ |
||||
m_expiringEventId = std::move(eid); |
||||
} |
||||
|
||||
ndn::scheduler::EventId |
||||
getExpiringEventId() const |
||||
{ |
||||
return m_expiringEventId; |
||||
} |
||||
|
||||
/*! \brief Gets the key for this LSA.
|
||||
|
||||
Format is: \<router name\>/\<LSA type>\
|
||||
*/ |
||||
ndn::Name |
||||
getKey() const; |
||||
|
||||
/*! Get data common to all LSA types.
|
||||
*/ |
||||
std::string |
||||
toString() const; |
||||
|
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
||||
ndn::Name m_originRouter; |
||||
uint64_t m_seqNo = 0; |
||||
ndn::time::system_clock::TimePoint m_expirationTimePoint; |
||||
ndn::scheduler::EventId m_expiringEventId; |
||||
|
||||
mutable ndn::Block m_baseWire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Lsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Lsa::Type& type); |
||||
|
||||
std::istream& |
||||
operator>>(std::istream& is, Lsa::Type& type); |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_LSA_LSA_HPP
|
@ -0,0 +1,103 @@
|
||||
/* -*- 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/>.
|
||||
**/ |
||||
|
||||
#ifndef NLSR_LSA_NAME_LSA_HPP |
||||
#define NLSR_LSA_NAME_LSA_HPP |
||||
|
||||
#include "lsa.hpp" |
||||
|
||||
namespace nlsr { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for NameLsa |
||||
NameLsa := NAME-LSA-TYPE TLV-LENGTH |
||||
Lsa |
||||
Name+ |
||||
*/ |
||||
class NameLsa : public Lsa |
||||
{ |
||||
public: |
||||
NameLsa() = default; |
||||
|
||||
NameLsa(const ndn::Name& originRouter, uint32_t seqNo, |
||||
const ndn::time::system_clock::TimePoint& timepoint, |
||||
NamePrefixList& npl); |
||||
|
||||
NameLsa(const ndn::Block& block); |
||||
|
||||
Lsa::Type |
||||
getType() const override |
||||
{ |
||||
return Lsa::Type::NAME; |
||||
} |
||||
|
||||
NamePrefixList& |
||||
getNpl() |
||||
{ |
||||
return m_npl; |
||||
} |
||||
|
||||
const NamePrefixList& |
||||
getNpl() const |
||||
{ |
||||
return m_npl; |
||||
} |
||||
|
||||
void |
||||
addName(const ndn::Name& name) |
||||
{ |
||||
m_wire.reset(); |
||||
m_npl.insert(name); |
||||
} |
||||
|
||||
void |
||||
removeName(const ndn::Name& name) |
||||
{ |
||||
m_wire.reset(); |
||||
m_npl.remove(name); |
||||
} |
||||
|
||||
bool |
||||
isEqualContent(const NameLsa& other) const; |
||||
|
||||
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: |
||||
NamePrefixList m_npl; |
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NameLsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const NameLsa& lsa); |
||||
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_LSA_NAME_LSA_HPP
|
@ -1,176 +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_ADJACENCY_LSA_HPP |
||||
#define NLSR_TLV_ADJACENCY_LSA_HPP |
||||
|
||||
#include "lsa-info.hpp" |
||||
#include "adjacency.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 AdjacencyLsa |
||||
|
||||
AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH |
||||
LsaInfo |
||||
Adjacency* |
||||
|
||||
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
|
||||
*/ |
||||
class AdjacencyLsa |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
typedef std::list<Adjacency> AdjacencyList; |
||||
typedef AdjacencyList::const_iterator iterator; |
||||
|
||||
AdjacencyLsa(); |
||||
|
||||
explicit |
||||
AdjacencyLsa(const ndn::Block& block); |
||||
|
||||
const LsaInfo& |
||||
getLsaInfo() const |
||||
{ |
||||
return m_lsaInfo; |
||||
} |
||||
|
||||
AdjacencyLsa& |
||||
setLsaInfo(const LsaInfo& lsaInfo) |
||||
{ |
||||
m_lsaInfo = lsaInfo; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
bool |
||||
hasAdjacencies() const |
||||
{ |
||||
return m_hasAdjacencies; |
||||
} |
||||
|
||||
const std::list<Adjacency>& |
||||
getAdjacencies() const |
||||
{ |
||||
return m_adjacencies; |
||||
} |
||||
|
||||
AdjacencyLsa& |
||||
addAdjacency(const Adjacency& adjacency) |
||||
{ |
||||
m_adjacencies.push_back(adjacency); |
||||
m_wire.reset(); |
||||
m_hasAdjacencies = true; |
||||
return *this; |
||||
} |
||||
|
||||
AdjacencyLsa& |
||||
clearAdjacencies() |
||||
{ |
||||
m_adjacencies.clear(); |
||||
m_hasAdjacencies = false; |
||||
return *this; |
||||
} |
||||
|
||||
/*! \brief Encodes the Adjacent objects and some info using the method in TAG.
|
||||
* |
||||
* This function will TLV-format the Adjacent objects and some LSA |
||||
* info using the implementation speciifed by TAG. Usually this is |
||||
* called with an estimator first to guess how long the buffer needs |
||||
* to be, then with an encoder to do the real work. This process is |
||||
* automated by the other wireEncode. |
||||
* \sa AdjacencyLsa::wireEncode() |
||||
*/ |
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
/*! \brief Create a TLV encoding of this object.
|
||||
* |
||||
* Create a block containing the TLV encoding of this object. That |
||||
* involves two steps: estimating the size that the information will |
||||
* take up, and then creating a buffer of that size and encoding the |
||||
* information into it. Both steps are accomplished by |
||||
* AdjacencyLsa::wireEncode(ndn::EncodingImpl<TAG>&) |
||||
*/ |
||||
const ndn::Block& |
||||
wireEncode() const; |
||||
|
||||
/*! \brief Populate this object by decoding the one contained in the
|
||||
* given block. |
||||
*/ |
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
iterator |
||||
begin() const; |
||||
|
||||
iterator |
||||
end() const; |
||||
|
||||
private: |
||||
LsaInfo m_lsaInfo; |
||||
bool m_hasAdjacencies; |
||||
AdjacencyList m_adjacencies; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjacencyLsa); |
||||
|
||||
inline AdjacencyLsa::iterator |
||||
AdjacencyLsa::begin() const |
||||
{ |
||||
return m_adjacencies.begin(); |
||||
} |
||||
|
||||
inline AdjacencyLsa::iterator |
||||
AdjacencyLsa::end() const |
||||
{ |
||||
return m_adjacencies.end(); |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const AdjacencyLsa& adjacencyLsa); |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TLV_ADJACENCY_LSA_HPP
|
@ -1,140 +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 "adjacency.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<Adjacency>)); |
||||
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<Adjacency>)); |
||||
static_assert(std::is_base_of<ndn::tlv::Error, Adjacency::Error>::value, |
||||
"Adjacency::Error must inherit from tlv::Error"); |
||||
|
||||
Adjacency::Adjacency() |
||||
: m_cost(0) |
||||
{ |
||||
} |
||||
|
||||
Adjacency::Adjacency(const ndn::Block& block) |
||||
{ |
||||
wireDecode(block); |
||||
} |
||||
|
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
Adjacency::wireEncode(ndn::EncodingImpl<TAG>& encoder) const |
||||
{ |
||||
size_t totalLength = 0; |
||||
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder, ndn::tlv::nlsr::Cost, m_cost); |
||||
|
||||
totalLength += encoder.prependByteArrayBlock( |
||||
ndn::tlv::nlsr::Uri, reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size()); |
||||
|
||||
totalLength += m_name.wireEncode(encoder); |
||||
|
||||
totalLength += encoder.prependVarNumber(totalLength); |
||||
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::Adjacency); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacency); |
||||
|
||||
const ndn::Block& |
||||
Adjacency::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 |
||||
Adjacency::wireDecode(const ndn::Block& wire) |
||||
{ |
||||
m_name.clear(); |
||||
m_uri = ""; |
||||
m_cost = 0; |
||||
|
||||
m_wire = wire; |
||||
|
||||
if (m_wire.type() != ndn::tlv::nlsr::Adjacency) { |
||||
BOOST_THROW_EXCEPTION(Error("Expected Adjacency Block, but Block is of a different type: #" + |
||||
ndn::to_string(m_wire.type()))); |
||||
} |
||||
|
||||
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")); |
||||
} |
||||
|
||||
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")); |
||||
} |
||||
|
||||
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Cost) { |
||||
m_cost = ndn::readNonNegativeInteger(*val); |
||||
++val; |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("Missing required Cost field")); |
||||
} |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Adjacency& adjacency) |
||||
{ |
||||
os << "Adjacency(" |
||||
<< "Name: " << adjacency.getName() << ", " |
||||
<< "Uri: " << adjacency.getUri() << ", " |
||||
<< "Cost: " << adjacency.getCost() << ")"; |
||||
|
||||
return os; |
||||
} |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,148 +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_ADJACENCY_HPP |
||||
#define NLSR_TLV_ADJACENCY_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> |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for Adjacency |
||||
|
||||
Adjacency := ADJACENCY-TYPE TLV-LENGTH |
||||
Name |
||||
Uri |
||||
Cost |
||||
|
||||
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
|
||||
*/ |
||||
class Adjacency |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
Adjacency(); |
||||
|
||||
explicit |
||||
Adjacency(const ndn::Block& block); |
||||
|
||||
const ndn::Name& |
||||
getName() const |
||||
{ |
||||
return m_name; |
||||
} |
||||
|
||||
Adjacency& |
||||
setName(const ndn::Name& name) |
||||
{ |
||||
m_name = name; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
const std::string& |
||||
getUri() const |
||||
{ |
||||
return m_uri; |
||||
} |
||||
|
||||
Adjacency& |
||||
setUri(const std::string& uri) |
||||
{ |
||||
m_uri = uri; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
uint64_t |
||||
getCost() const |
||||
{ |
||||
return m_cost; |
||||
} |
||||
|
||||
Adjacency& |
||||
setCost(uint64_t cost) |
||||
{ |
||||
m_cost = cost; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
/*! \brief TLV-encode this object using the implementation in from TAG.
|
||||
* |
||||
* This method TLV-encodes this Adjacency object using the |
||||
* implementation given by TAG. Usually two implementations are |
||||
* provided: a size estimator and a real encoder, which are used in |
||||
* sequence to allocate the necessary block size and then encode it. |
||||
* \sa Adjacency::wireEncode() |
||||
*/ |
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
/*! \brief Create a TLV encoding of this object.
|
||||
* |
||||
* This function automates the process of guessing the necessary |
||||
* size of a block containing this object, and then creating a block |
||||
* and putting the TLV encoding into it. |
||||
* \sa Adjacency::wireEncode(ndn::EncodingImpl<TAG>&) |
||||
*/ |
||||
const ndn::Block& |
||||
wireEncode() const; |
||||
|
||||
/*! \brief Populate this object by decoding the object contained in
|
||||
* the given block. |
||||
*/ |
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
private: |
||||
ndn::Name m_name; |
||||
std::string m_uri; |
||||
uint64_t m_cost; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Adjacency); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const Adjacency& adjacency); |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TLV_ADJACENCY_HPP
|
@ -1,152 +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_COORDINATE_LSA_HPP |
||||
#define NLSR_TLV_COORDINATE_LSA_HPP |
||||
|
||||
#include "lsa-info.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> |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
|
||||
/*!
|
||||
\brief Data abstraction for CoordinateLsa |
||||
|
||||
CoordinateLsa := COORDINATE-LSA-TYPE TLV-LENGTH |
||||
LsaInfo |
||||
HyperbolicRadius |
||||
HyperbolicAngle+ |
||||
|
||||
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
|
||||
*/ |
||||
class CoordinateLsa |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
CoordinateLsa(); |
||||
|
||||
explicit |
||||
CoordinateLsa(const ndn::Block& block); |
||||
|
||||
const LsaInfo& |
||||
getLsaInfo() const |
||||
{ |
||||
return m_lsaInfo; |
||||
} |
||||
|
||||
CoordinateLsa& |
||||
setLsaInfo(const LsaInfo& lsaInfo) |
||||
{ |
||||
m_lsaInfo = lsaInfo; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
double |
||||
getHyperbolicRadius() const |
||||
{ |
||||
return m_hyperbolicRadius; |
||||
} |
||||
|
||||
CoordinateLsa& |
||||
setHyperbolicRadius(double hyperbolicRadius) |
||||
{ |
||||
m_hyperbolicRadius = hyperbolicRadius; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
const std::vector<double> |
||||
getHyperbolicAngle() const |
||||
{ |
||||
return m_hyperbolicAngle; |
||||
} |
||||
|
||||
CoordinateLsa& |
||||
setHyperbolicAngle(const std::vector<double>& hyperbolicAngle) |
||||
{ |
||||
m_hyperbolicAngle = hyperbolicAngle; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
/*! \brief Encodes the hyperbolic coordinates and some info using the method in TAG.
|
||||
* |
||||
* This function will TLV-format the hyperbolic coordinates objects and some LSA |
||||
* info using the implementation speciifed by TAG. Usually this is |
||||
* called with an estimator first to guess how long the buffer needs |
||||
* to be, then with an encoder to do the real work. This process is |
||||
* automated by the other wireEncode. |
||||
* \sa CoordinateLsa::wireEncode() |
||||
*/ |
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
/*! \brief Create a TLV encoding of this object.
|
||||
* |
||||
* Create a block containing the TLV encoding of this object. That |
||||
* involves two steps: estimating the size that the information will |
||||
* take up, and then creating a buffer of that size and encoding the |
||||
* information into it. Both steps are accomplished by |
||||
* CoordinateLsa::wireEncode(ndn::EncodingImpl<TAG>&) |
||||
*/ |
||||
const ndn::Block& |
||||
wireEncode() const; |
||||
|
||||
/*! \brief Populate this object by decoding the one contained in the
|
||||
* given block. |
||||
*/ |
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
private: |
||||
LsaInfo m_lsaInfo; |
||||
double m_hyperbolicRadius; |
||||
std::vector<double> m_hyperbolicAngle; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CoordinateLsa); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const CoordinateLsa& coordinateLsa); |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TLV_COORDINATE_LSA_HPP
|
@ -1,186 +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 "lsa-info.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<LsaInfo>)); |
||||
BOOST_CONCEPT_ASSERT((ndn::WireDecodable<LsaInfo>)); |
||||
static_assert(std::is_base_of<ndn::tlv::Error, LsaInfo::Error>::value, |
||||
"LsaInfo::Error must inherit from tlv::Error"); |
||||
|
||||
const ndn::time::milliseconds LsaInfo::INFINITE_EXPIRATION_PERIOD(ndn::time::milliseconds::max()); |
||||
|
||||
LsaInfo::LsaInfo() |
||||
: m_sequenceNumber(0) |
||||
, m_expirationPeriod(INFINITE_EXPIRATION_PERIOD) |
||||
, m_hasInfiniteExpirationPeriod(true) |
||||
{ |
||||
} |
||||
|
||||
LsaInfo::LsaInfo(const ndn::Block& block) |
||||
{ |
||||
wireDecode(block); |
||||
} |
||||
|
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
LsaInfo::wireEncode(ndn::EncodingImpl<TAG>& encoder) const |
||||
{ |
||||
size_t totalLength = 0; |
||||
|
||||
// Absence of an ExpirationPeriod signifies non-expiration
|
||||
if (!m_hasInfiniteExpirationPeriod) { |
||||
totalLength += prependNonNegativeIntegerBlock(encoder, |
||||
ndn::tlv::nlsr::ExpirationPeriod, |
||||
m_expirationPeriod.count()); |
||||
} |
||||
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder, |
||||
ndn::tlv::nlsr::SequenceNumber, |
||||
m_sequenceNumber); |
||||
|
||||
totalLength += prependNestedBlock(encoder, ndn::tlv::nlsr::OriginRouter, m_originRouter); |
||||
|
||||
totalLength += encoder.prependVarNumber(totalLength); |
||||
totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::LsaInfo); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(LsaInfo); |
||||
|
||||
const ndn::Block& |
||||
LsaInfo::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 |
||||
LsaInfo::wireDecode(const ndn::Block& wire) |
||||
{ |
||||
m_originRouter.clear(); |
||||
m_sequenceNumber = 0; |
||||
m_expirationPeriod = ndn::time::milliseconds::min(); |
||||
|
||||
m_wire = wire; |
||||
|
||||
if (m_wire.type() != ndn::tlv::nlsr::LsaInfo) { |
||||
std::stringstream error; |
||||
error << "Expected LsaInfo 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::OriginRouter) { |
||||
val->parse(); |
||||
ndn::Block::element_const_iterator it = val->elements_begin(); |
||||
|
||||
if (it != val->elements_end() && it->type() == ndn::tlv::Name) { |
||||
m_originRouter.wireDecode(*it); |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("OriginRouter: Missing required Name field")); |
||||
} |
||||
|
||||
++val; |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("Missing required OriginRouter field")); |
||||
} |
||||
|
||||
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::SequenceNumber) { |
||||
m_sequenceNumber = ndn::readNonNegativeInteger(*val); |
||||
++val; |
||||
} |
||||
else { |
||||
BOOST_THROW_EXCEPTION(Error("Missing required SequenceNumber field")); |
||||
} |
||||
|
||||
if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::ExpirationPeriod) { |
||||
m_expirationPeriod = ndn::time::milliseconds(ndn::readNonNegativeInteger(*val)); |
||||
m_hasInfiniteExpirationPeriod = false; |
||||
} |
||||
else { |
||||
m_expirationPeriod = INFINITE_EXPIRATION_PERIOD; |
||||
m_hasInfiniteExpirationPeriod = true; |
||||
} |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const LsaInfo& lsaInfo) |
||||
{ |
||||
os << "LsaInfo(" |
||||
<< "OriginRouter: " << lsaInfo.getOriginRouter() << ", " |
||||
<< "SequenceNumber: " << lsaInfo.getSequenceNumber() << ", "; |
||||
|
||||
if (!lsaInfo.hasInfiniteExpirationPeriod()) { |
||||
os << "ExpirationPeriod: " << lsaInfo.getExpirationPeriod(); |
||||
} |
||||
else { |
||||
os << "ExpirationPeriod: Infinity"; |
||||
} |
||||
|
||||
os << ")"; |
||||
|
||||
return os; |
||||
} |
||||
|
||||
std::shared_ptr<LsaInfo> |
||||
makeLsaInfo(const Lsa& lsa) |
||||
{ |
||||
std::shared_ptr<LsaInfo> lsaInfo = std::make_shared<LsaInfo>(); |
||||
|
||||
lsaInfo->setOriginRouter(lsa.getOrigRouter()); |
||||
lsaInfo->setSequenceNumber(lsa.getLsSeqNo()); |
||||
|
||||
ndn::time::system_clock::duration duration |
||||
= lsa.getExpirationTimePoint() - ndn::time::system_clock::now(); |
||||
|
||||
lsaInfo->setExpirationPeriod(ndn::time::duration_cast<ndn::time::milliseconds>(duration)); |
||||
|
||||
return lsaInfo; |
||||
} |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,168 +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_LSA_INFO_HPP |
||||
#define NLSR_TLV_LSA_INFO_HPP |
||||
|
||||
#include "lsa.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 LsaInfo |
||||
|
||||
LsaInfo := LSA-TYPE TLV-LENGTH |
||||
OriginRouter |
||||
SequenceNumber |
||||
ExpirationPeriod? |
||||
|
||||
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
|
||||
*/ |
||||
class LsaInfo |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
LsaInfo(); |
||||
|
||||
explicit |
||||
LsaInfo(const ndn::Block& block); |
||||
|
||||
const ndn::Name& |
||||
getOriginRouter() const |
||||
{ |
||||
return m_originRouter; |
||||
} |
||||
|
||||
LsaInfo& |
||||
setOriginRouter(const ndn::Name& name) |
||||
{ |
||||
m_originRouter = name; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
uint64_t |
||||
getSequenceNumber() const |
||||
{ |
||||
return m_sequenceNumber; |
||||
} |
||||
|
||||
LsaInfo& |
||||
setSequenceNumber(uint64_t sequenceNumber) |
||||
{ |
||||
m_sequenceNumber = sequenceNumber; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
static const ndn::time::milliseconds INFINITE_EXPIRATION_PERIOD; |
||||
|
||||
const ndn::time::milliseconds& |
||||
getExpirationPeriod() const |
||||
{ |
||||
return m_expirationPeriod; |
||||
} |
||||
|
||||
LsaInfo& |
||||
setExpirationPeriod(const ndn::time::milliseconds& expirationPeriod) |
||||
{ |
||||
m_expirationPeriod = expirationPeriod; |
||||
|
||||
m_hasInfiniteExpirationPeriod = (m_expirationPeriod == INFINITE_EXPIRATION_PERIOD); |
||||
|
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
bool |
||||
hasInfiniteExpirationPeriod() const |
||||
{ |
||||
return m_hasInfiniteExpirationPeriod; |
||||
} |
||||
|
||||
/*! \brief Encodes LSA info using the method in TAG.
|
||||
* |
||||
* This function will TLV-format LSA info using the implementation |
||||
* speciifed by TAG. Usually this is called with an estimator first |
||||
* to guess how long the buffer needs to be, then with an encoder to |
||||
* do the real work. This process is automated by the other |
||||
* wireEncode. |
||||
* \sa LsaInfo::wireEncode() |
||||
*/ |
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
/*! \brief Create a TLV encoding of this object.
|
||||
* |
||||
* Create a block containing the TLV encoding of this object. That |
||||
* involves two steps: estimating the size that the information will |
||||
* take up, and then creating a buffer of that size and encoding the |
||||
* information into it. Both steps are accomplished by |
||||
* LsaInfo::wireEncode(ndn::EncodingImpl<TAG>&) |
||||
*/ |
||||
const ndn::Block& |
||||
wireEncode() const; |
||||
|
||||
/*! \brief Populate this object by decoding the one contained in the
|
||||
* given block. |
||||
*/ |
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
private: |
||||
ndn::Name m_originRouter; |
||||
uint64_t m_sequenceNumber; |
||||
ndn::time::milliseconds m_expirationPeriod; |
||||
bool m_hasInfiniteExpirationPeriod; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(LsaInfo); |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const LsaInfo& lsaInfo); |
||||
|
||||
std::shared_ptr<LsaInfo> |
||||
makeLsaInfo(const Lsa& lsa); |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TLV_LSA_INFO_HPP
|
@ -1,175 +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_NAME_LSA_HPP |
||||
#define NLSR_TLV_NAME_LSA_HPP |
||||
|
||||
#include "lsa-info.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 NameLsa |
||||
|
||||
NameLsa := NAME-LSA-TYPE TLV-LENGTH |
||||
LsaInfo |
||||
Name+ |
||||
|
||||
\sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
|
||||
*/ |
||||
class NameLsa |
||||
{ |
||||
public: |
||||
class Error : public ndn::tlv::Error |
||||
{ |
||||
public: |
||||
explicit |
||||
Error(const std::string& what) |
||||
: ndn::tlv::Error(what) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
typedef std::list<ndn::Name> NameList; |
||||
typedef NameList::const_iterator iterator; |
||||
|
||||
NameLsa(); |
||||
|
||||
explicit |
||||
NameLsa(const ndn::Block& block); |
||||
|
||||
const LsaInfo& |
||||
getLsaInfo() const |
||||
{ |
||||
return m_lsaInfo; |
||||
} |
||||
|
||||
NameLsa& |
||||
setLsaInfo(const LsaInfo& lsaInfo) |
||||
{ |
||||
m_lsaInfo = lsaInfo; |
||||
m_wire.reset(); |
||||
return *this; |
||||
} |
||||
|
||||
bool |
||||
hasNames() const |
||||
{ |
||||
return m_hasNames; |
||||
} |
||||
|
||||
const std::list<ndn::Name>& |
||||
getNames() const |
||||
{ |
||||
return m_names; |
||||
} |
||||
|
||||
NameLsa& |
||||
addName(const ndn::Name& name) |
||||
{ |
||||
m_names.push_back(name); |
||||
m_wire.reset(); |
||||
m_hasNames = true; |
||||
return *this; |
||||
} |
||||
|
||||
NameLsa& |
||||
clearNames() |
||||
{ |
||||
m_names.clear(); |
||||
m_hasNames = false; |
||||
return *this; |
||||
} |
||||
|
||||
/*! \brief Encodes the Name objects and some info using the method in TAG.
|
||||
* |
||||
* This function will TLV-format the Name objects and some LSA |
||||
* info using the implementation speciifed by TAG. Usually this is |
||||
* called with an estimator first to guess how long the buffer needs |
||||
* to be, then with an encoder to do the real work. This process is |
||||
* automated by the other wireEncode. |
||||
* \sa NameLsa::wireEncode() |
||||
*/ |
||||
template<ndn::encoding::Tag TAG> |
||||
size_t |
||||
wireEncode(ndn::EncodingImpl<TAG>& block) const; |
||||
|
||||
/*! \brief Create a TLV encoding of this object.
|
||||
* |
||||
* Create a block containing the TLV encoding of this object. That |
||||
* involves two steps: estimating the size that the information will |
||||
* take up, and then creating a buffer of that size and encoding the |
||||
* information into it. Both steps are accomplished by |
||||
* NameLsa::wireEncode(ndn::EncodingImpl<TAG>&) |
||||
*/ |
||||
const ndn::Block& |
||||
wireEncode() const; |
||||
|
||||
/*! \brief Populate this object by decoding the one contained in the
|
||||
* given block. |
||||
*/ |
||||
void |
||||
wireDecode(const ndn::Block& wire); |
||||
|
||||
iterator |
||||
begin() const; |
||||
|
||||
iterator |
||||
end() const; |
||||
|
||||
private: |
||||
LsaInfo m_lsaInfo; |
||||
bool m_hasNames; |
||||
NameList m_names; |
||||
|
||||
mutable ndn::Block m_wire; |
||||
}; |
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NameLsa); |
||||
|
||||
inline NameLsa::iterator |
||||
NameLsa::begin() const |
||||
{ |
||||
return m_names.begin(); |
||||
} |
||||
|
||||
inline NameLsa::iterator |
||||
NameLsa::end() const |
||||
{ |
||||
return m_names.end(); |
||||
} |
||||
|
||||
std::ostream& |
||||
operator<<(std::ostream& os, const NameLsa& nameLsa); |
||||
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TLV_NAME_LSA_HPP
|
@ -1,56 +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 "./lsa.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace test { |
||||
|
||||
std::string |
||||
MockLsa::serialize() const |
||||
{ |
||||
return ""; |
||||
} |
||||
|
||||
bool |
||||
MockLsa::deserialize(const std::string& content) noexcept |
||||
{ |
||||
boost::char_separator<char> sep("|"); |
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
||||
tokens.begin(); |
||||
|
||||
try { |
||||
deserializeCommon(tok_iter); |
||||
} |
||||
catch (const std::exception& e) { |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void |
||||
MockLsa::writeLog() const |
||||
{ |
||||
} |
||||
|
||||
} // namespace test
|
||||
} // namespace nlsr
|
@ -1,54 +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_TESTS_MOCKS_LSA_HPP |
||||
#define NLSR_TESTS_MOCKS_LSA_HPP |
||||
|
||||
#include "src/lsa.hpp" |
||||
|
||||
#include <boost/tokenizer.hpp> |
||||
#include <boost/algorithm/string.hpp> |
||||
#include <boost/lexical_cast.hpp> |
||||
|
||||
namespace nlsr { |
||||
namespace test { |
||||
|
||||
class MockLsa : public Lsa |
||||
{ |
||||
public: |
||||
MockLsa() |
||||
{ |
||||
} |
||||
|
||||
std::string |
||||
serialize() const override; |
||||
|
||||
bool |
||||
deserialize(const std::string& content) noexcept override; |
||||
|
||||
void |
||||
writeLog() const override; |
||||
}; |
||||
|
||||
} // namespace test
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // NLSR_TESTS_MOCKS_LSA_HPP
|
@ -1,223 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/adjacency-lsa.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestAdjacencyLsa) |
||||
|
||||
const uint8_t AdjacencyLsaWithAdjacenciesData[] = |
||||
{ |
||||
// Header
|
||||
0x83, 0x3d, |
||||
// LsaInfo
|
||||
0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01, |
||||
0x80, 0x8b, 0x02, 0x27, 0x10, |
||||
// Adjacency
|
||||
0x84, 0x13, 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x8d, 0x05, 0x74, |
||||
0x65, 0x73, 0x74, 0x31, 0x8c, 0x01, 0x80, |
||||
// Adjacency
|
||||
0x84, 0x13, 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x8d, 0x05, 0x74, |
||||
0x65, 0x73, 0x74, 0x32, 0x8c, 0x01, 0x80 |
||||
}; |
||||
|
||||
const uint8_t AdjacencyLsaWithoutAdjacenciesData[] = |
||||
{ |
||||
// Header
|
||||
0x83, 0x13, |
||||
// LsaInfo
|
||||
0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01, |
||||
0x80, 0x8b, 0x02, 0x27, 0x10 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaEncodeWithAdjacencies) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
adjacencyLsa.setLsaInfo(lsaInfo); |
||||
|
||||
Adjacency adjacency1; |
||||
adjacency1.setName("test1"); |
||||
adjacency1.setUri("test1"); |
||||
adjacency1.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency1); |
||||
|
||||
Adjacency adjacency2; |
||||
adjacency2.setName("test2"); |
||||
adjacency2.setUri("test2"); |
||||
adjacency2.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency2); |
||||
|
||||
const ndn::Block& wire = adjacencyLsa.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyLsaWithAdjacenciesData, |
||||
AdjacencyLsaWithAdjacenciesData + |
||||
sizeof(AdjacencyLsaWithAdjacenciesData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaDecodeWithAdjacencies) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
adjacencyLsa.wireDecode(ndn::Block(AdjacencyLsaWithAdjacenciesData, |
||||
sizeof(AdjacencyLsaWithAdjacenciesData))); |
||||
|
||||
LsaInfo lsaInfo = adjacencyLsa.getLsaInfo(); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test"); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000)); |
||||
|
||||
BOOST_CHECK_EQUAL(adjacencyLsa.hasAdjacencies(), true); |
||||
std::list<Adjacency> adjacencies = adjacencyLsa.getAdjacencies(); |
||||
std::list<Adjacency>::const_iterator it = adjacencies.begin(); |
||||
BOOST_CHECK_EQUAL(it->getName(), "test1"); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "test1"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 128); |
||||
|
||||
it++; |
||||
BOOST_CHECK_EQUAL(it->getName(), "test2"); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "test2"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 128); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaEncodeWithoutAdjacencies) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
adjacencyLsa.setLsaInfo(lsaInfo); |
||||
|
||||
const ndn::Block& wire = adjacencyLsa.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyLsaWithoutAdjacenciesData, |
||||
AdjacencyLsaWithoutAdjacenciesData + |
||||
sizeof(AdjacencyLsaWithoutAdjacenciesData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaDecodeWithoutAdjacencies) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
adjacencyLsa.wireDecode(ndn::Block(AdjacencyLsaWithoutAdjacenciesData, |
||||
sizeof(AdjacencyLsaWithoutAdjacenciesData))); |
||||
|
||||
LsaInfo lsaInfo = adjacencyLsa.getLsaInfo(); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test"); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000)); |
||||
|
||||
BOOST_CHECK_EQUAL(adjacencyLsa.hasAdjacencies(), false); |
||||
} |
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaClear) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
adjacencyLsa.setLsaInfo(lsaInfo); |
||||
|
||||
Adjacency adjacency1; |
||||
adjacency1.setName("test1"); |
||||
adjacency1.setUri("test1"); |
||||
adjacency1.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency1); |
||||
BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 1); |
||||
|
||||
std::list<Adjacency> adjacencies = adjacencyLsa.getAdjacencies(); |
||||
std::list<Adjacency>::const_iterator it = adjacencies.begin(); |
||||
BOOST_CHECK_EQUAL(it->getName(), "test1"); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "test1"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 128); |
||||
|
||||
adjacencyLsa.clearAdjacencies(); |
||||
BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 0); |
||||
|
||||
Adjacency adjacency2; |
||||
adjacency2.setName("test2"); |
||||
adjacency2.setUri("test2"); |
||||
adjacency2.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency2); |
||||
BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 1); |
||||
|
||||
adjacencies = adjacencyLsa.getAdjacencies(); |
||||
it = adjacencies.begin(); |
||||
BOOST_CHECK_EQUAL(it->getName(), "test2"); |
||||
BOOST_CHECK_EQUAL(it->getUri(), "test2"); |
||||
BOOST_CHECK_EQUAL(it->getCost(), 128); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaOutputStream) |
||||
{ |
||||
AdjacencyLsa adjacencyLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
adjacencyLsa.setLsaInfo(lsaInfo); |
||||
|
||||
Adjacency adjacency1; |
||||
adjacency1.setName("test1"); |
||||
adjacency1.setUri("test1"); |
||||
adjacency1.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency1); |
||||
|
||||
Adjacency adjacency2; |
||||
adjacency2.setName("test2"); |
||||
adjacency2.setUri("test2"); |
||||
adjacency2.setCost(128); |
||||
adjacencyLsa.addAdjacency(adjacency2); |
||||
|
||||
std::ostringstream os; |
||||
os << adjacencyLsa; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "AdjacencyLsa(" |
||||
"LsaInfo(" |
||||
"OriginRouter: /test, " |
||||
"SequenceNumber: 128, " |
||||
"ExpirationPeriod: 10000 milliseconds), " |
||||
"Adjacency(Name: /test1, Uri: test1, Cost: 128), " |
||||
"Adjacency(Name: /test2, Uri: test2, Cost: 128))"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,91 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/adjacency.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestAdjacency) |
||||
|
||||
const uint8_t AdjacencyData[] = |
||||
{ |
||||
// Header
|
||||
0x84, 0x30, |
||||
// Name
|
||||
0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x09, 0x61, 0x64, 0x6a, 0x61, |
||||
0x63, 0x65, 0x6e, 0x63, 0x79, 0x08, 0x03, 0x74, 0x6c, 0x76, |
||||
// Uri
|
||||
0x8d, 0x13, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x61, 0x64, 0x6a, 0x61, 0x63, 0x65, |
||||
0x6e, 0x63, 0x79, 0x2f, 0x74, 0x6c, 0x76, |
||||
// Cost
|
||||
0x8c, 0x01, 0x80 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyEncode) |
||||
{ |
||||
Adjacency adjacency; |
||||
adjacency.setName("/test/adjacency/tlv"); |
||||
adjacency.setUri("/test/adjacency/tlv"); |
||||
adjacency.setCost(128); |
||||
|
||||
const ndn::Block& wire = adjacency.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyData, |
||||
AdjacencyData + sizeof(AdjacencyData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyDecode) |
||||
{ |
||||
Adjacency adjacency; |
||||
|
||||
adjacency.wireDecode(ndn::Block(AdjacencyData, sizeof(AdjacencyData))); |
||||
|
||||
ndn::Name name("/test/adjacency/tlv"); |
||||
BOOST_REQUIRE_EQUAL(adjacency.getName(), name); |
||||
BOOST_REQUIRE_EQUAL(adjacency.getUri(), "/test/adjacency/tlv"); |
||||
BOOST_REQUIRE_EQUAL(adjacency.getCost(), 128); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyOutputStream) |
||||
{ |
||||
Adjacency adjacency; |
||||
adjacency.setName("/test/adjacency/tlv"); |
||||
adjacency.setUri("/test/adjacency/tlv"); |
||||
adjacency.setCost(128); |
||||
|
||||
std::ostringstream os; |
||||
os << adjacency; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "Adjacency(Name: /test/adjacency/tlv, " |
||||
"Uri: /test/adjacency/tlv, " |
||||
"Cost: 128)"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,126 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/coordinate-lsa.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestCoordinateLsa) |
||||
|
||||
const uint8_t CoordinateLsaData[] = |
||||
{ |
||||
// Header
|
||||
0x85, 0x27, |
||||
// LsaInfo
|
||||
0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01, |
||||
0x80, 0x8b, 0x02, 0x27, 0x10, |
||||
// HyperbolicRadius
|
||||
0x87, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, |
||||
// HyperbolicAngle
|
||||
0x88, 0x08, 0x3f, 0xfc, 0x7a, 0xe1, 0x47, 0xae, 0x14, 0x7b |
||||
|
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(CoordinateLsaEncode) |
||||
{ |
||||
CoordinateLsa coordinateLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
coordinateLsa.setLsaInfo(lsaInfo); |
||||
|
||||
coordinateLsa.setHyperbolicRadius(1.65); |
||||
std::vector<double> angles; |
||||
angles.push_back(1.78); |
||||
coordinateLsa.setHyperbolicAngle(angles); |
||||
|
||||
const ndn::Block& wire = coordinateLsa.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(CoordinateLsaData, |
||||
CoordinateLsaData + sizeof(CoordinateLsaData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(CoordinateLsaDecode) |
||||
{ |
||||
CoordinateLsa coordinateLsa; |
||||
|
||||
coordinateLsa.wireDecode(ndn::Block(CoordinateLsaData, sizeof(CoordinateLsaData))); |
||||
|
||||
BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getOriginRouter(), "test"); |
||||
BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getSequenceNumber(), 128); |
||||
BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getExpirationPeriod(), |
||||
ndn::time::milliseconds(10000)); |
||||
BOOST_REQUIRE_EQUAL(coordinateLsa.getHyperbolicRadius(), 1.65); |
||||
std::vector<double> angles = {1.78}; |
||||
BOOST_REQUIRE(coordinateLsa.getHyperbolicAngle() == angles); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(CoordinateLsaOutputStream) |
||||
{ |
||||
CoordinateLsa coordinateLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
coordinateLsa.setLsaInfo(lsaInfo); |
||||
|
||||
coordinateLsa.setHyperbolicRadius(1.65); |
||||
std::vector<double> angles = {1.78}; |
||||
coordinateLsa.setHyperbolicAngle(angles); |
||||
|
||||
std::ostringstream os; |
||||
os << coordinateLsa; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "CoordinateLsa(" |
||||
"LsaInfo(OriginRouter: /test, " |
||||
"SequenceNumber: 128, " |
||||
"ExpirationPeriod: 10000 milliseconds), " |
||||
"HyperbolicRadius: 1.65, " |
||||
"HyperbolicAngles: 1.78)"); |
||||
|
||||
angles.push_back(3.21); |
||||
coordinateLsa.setHyperbolicAngle(angles); |
||||
|
||||
std::ostringstream os2; |
||||
os2 << coordinateLsa; |
||||
|
||||
BOOST_CHECK_EQUAL(os2.str(), "CoordinateLsa(" |
||||
"LsaInfo(OriginRouter: /test, " |
||||
"SequenceNumber: 128, " |
||||
"ExpirationPeriod: 10000 milliseconds), " |
||||
"HyperbolicRadius: 1.65, " |
||||
"HyperbolicAngles: 1.78, 3.21)"); |
||||
} |
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,144 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/lsa-info.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
#include "tests/mocks/lsa.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestLsaInfo) |
||||
|
||||
const uint8_t LsaInfoData[] = |
||||
{ |
||||
// Header
|
||||
0x80, 0x21, |
||||
// OriginRouter
|
||||
0x81, 0x18, 0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x03, 0x6c, 0x73, |
||||
0x61, 0x08, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x08, 0x03, 0x74, 0x6c, 0x76, |
||||
// SequenceNumber
|
||||
0x82, 0x01, 0x80, |
||||
// ExpirationPeriod
|
||||
0x8b, 0x02, 0x27, 0x10 |
||||
}; |
||||
|
||||
const uint8_t LsaInfoDataInfiniteExpirationPeriod[] = |
||||
{ |
||||
// Header
|
||||
0x80, 0x1d, |
||||
// OriginRouter
|
||||
0x81, 0x18, 0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x03, 0x6c, 0x73, |
||||
0x61, 0x08, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x08, 0x03, 0x74, 0x6c, 0x76, |
||||
// SequenceNumber
|
||||
0x82, 0x1, 0x80 |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoEncode) |
||||
{ |
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("/test/lsa/info/tlv"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
|
||||
const ndn::Block& wire = lsaInfo.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(LsaInfoData, |
||||
LsaInfoData + sizeof(LsaInfoData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoDecode) |
||||
{ |
||||
LsaInfo lsaInfo; |
||||
|
||||
lsaInfo.wireDecode(ndn::Block(LsaInfoData, sizeof(LsaInfoData))); |
||||
|
||||
ndn::Name originRouter("/test/lsa/info/tlv"); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getOriginRouter(), originRouter); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000)); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.hasInfiniteExpirationPeriod(), false); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoInfiniteExpirationPeriodEncode) |
||||
{ |
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("/test/lsa/info/tlv"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(LsaInfo::INFINITE_EXPIRATION_PERIOD); |
||||
|
||||
const ndn::Block& wire = lsaInfo.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(LsaInfoDataInfiniteExpirationPeriod, |
||||
LsaInfoDataInfiniteExpirationPeriod + |
||||
sizeof(LsaInfoDataInfiniteExpirationPeriod), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoInfiniteExpirationPeriodDecode) |
||||
{ |
||||
LsaInfo lsaInfo; |
||||
|
||||
lsaInfo.wireDecode(ndn::Block(LsaInfoDataInfiniteExpirationPeriod, |
||||
sizeof(LsaInfoDataInfiniteExpirationPeriod))); |
||||
|
||||
ndn::Name originRouter("/test/lsa/info/tlv"); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getOriginRouter(), originRouter); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.getExpirationPeriod(), LsaInfo::INFINITE_EXPIRATION_PERIOD); |
||||
BOOST_REQUIRE_EQUAL(lsaInfo.hasInfiniteExpirationPeriod(), true); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoOutputStream) |
||||
{ |
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("/test/lsa/info/tlv"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
|
||||
std::ostringstream os; |
||||
os << lsaInfo; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "LsaInfo(OriginRouter: /test/lsa/info/tlv, SequenceNumber: 128, " |
||||
"ExpirationPeriod: 10000 milliseconds)"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(LsaInfoMake) |
||||
{ |
||||
nlsr::test::MockLsa lsa; |
||||
lsa.setOrigRouter("/test/lsa/info/tlv"); |
||||
lsa.setLsSeqNo(128); |
||||
lsa.setExpirationTimePoint(ndn::time::system_clock::now()); |
||||
|
||||
std::shared_ptr<LsaInfo> lsaInfo = makeLsaInfo(lsa); |
||||
BOOST_CHECK_EQUAL(lsaInfo->getOriginRouter(), lsa.getOrigRouter()); |
||||
BOOST_CHECK_EQUAL(lsaInfo->getSequenceNumber(), lsa.getLsSeqNo()); |
||||
BOOST_CHECK_LE(lsaInfo->getExpirationPeriod(), ndn::time::milliseconds(0)); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
@ -1,182 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2014-2019, The University of Memphis, |
||||
* Regents of the University of California, |
||||
* Arizona Board of Regents. |
||||
* |
||||
* This file is part of NLSR (Named-data Link State Routing). |
||||
* See AUTHORS.md for complete list of NLSR authors and contributors. |
||||
* |
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms |
||||
* of the GNU General Public License as published by the Free Software Foundation, |
||||
* either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
||||
* PURPOSE. See the GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with |
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/ |
||||
|
||||
#include "tlv/name-lsa.hpp" |
||||
|
||||
#include "tests/boost-test.hpp" |
||||
|
||||
namespace nlsr { |
||||
namespace tlv { |
||||
namespace test { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(TlvTestNameLsa) |
||||
|
||||
const uint8_t NameLsaWithNamesData[] = |
||||
{ |
||||
// Header
|
||||
0x89, 0x25, |
||||
// LsaInfo
|
||||
0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01, |
||||
0x80, 0x8b, 0x02, 0x27, 0x10, |
||||
// Name
|
||||
0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, |
||||
// Name
|
||||
0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32 |
||||
}; |
||||
|
||||
const uint8_t NameLsaWithoutNamesData[] = |
||||
{ |
||||
// Header
|
||||
0x89, 0x13, |
||||
// LsaInfo
|
||||
0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01, |
||||
0x80, 0x8b, 0x02, 0x27, 0x10, |
||||
}; |
||||
|
||||
BOOST_AUTO_TEST_CASE(NameLsaEncodeWithNames) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
nameLsa.setLsaInfo(lsaInfo); |
||||
|
||||
nameLsa.addName("test1"); |
||||
nameLsa.addName("test2"); |
||||
|
||||
const ndn::Block& wire = nameLsa.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(NameLsaWithNamesData, |
||||
NameLsaWithNamesData + sizeof(NameLsaWithNamesData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(NameLsaDecodeWithNames) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
nameLsa.wireDecode(ndn::Block(NameLsaWithNamesData, sizeof(NameLsaWithNamesData))); |
||||
|
||||
LsaInfo lsaInfo = nameLsa.getLsaInfo(); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test"); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000)); |
||||
|
||||
BOOST_CHECK_EQUAL(nameLsa.hasNames(), true); |
||||
std::list<ndn::Name> names = nameLsa.getNames(); |
||||
std::list<ndn::Name>::const_iterator it = names.begin(); |
||||
BOOST_CHECK_EQUAL(*it, "test1"); |
||||
|
||||
it++; |
||||
BOOST_CHECK_EQUAL(*it, "test2"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(NameLsaEncodeWithoutNames) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
nameLsa.setLsaInfo(lsaInfo); |
||||
|
||||
const ndn::Block& wire = nameLsa.wireEncode(); |
||||
|
||||
BOOST_REQUIRE_EQUAL_COLLECTIONS(NameLsaWithoutNamesData, |
||||
NameLsaWithoutNamesData + sizeof(NameLsaWithoutNamesData), |
||||
wire.begin(), wire.end()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(NameLsaDecodeWithoutNames) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
nameLsa.wireDecode(ndn::Block(NameLsaWithoutNamesData, sizeof(NameLsaWithoutNamesData))); |
||||
|
||||
LsaInfo lsaInfo = nameLsa.getLsaInfo(); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test"); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128); |
||||
BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000)); |
||||
|
||||
BOOST_CHECK_EQUAL(nameLsa.hasNames(), false); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(NameLsaClear) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
nameLsa.setLsaInfo(lsaInfo); |
||||
|
||||
nameLsa.addName("test1"); |
||||
BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 1); |
||||
|
||||
std::list<ndn::Name> names = nameLsa.getNames(); |
||||
std::list<ndn::Name>::const_iterator it = names.begin(); |
||||
BOOST_CHECK_EQUAL(*it, "test1"); |
||||
|
||||
nameLsa.clearNames(); |
||||
BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 0); |
||||
|
||||
nameLsa.addName("test2"); |
||||
BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 1); |
||||
|
||||
names = nameLsa.getNames(); |
||||
it = names.begin(); |
||||
BOOST_CHECK_EQUAL(*it, "test2"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(AdjacencyLsaOutputStream) |
||||
{ |
||||
NameLsa nameLsa; |
||||
|
||||
LsaInfo lsaInfo; |
||||
lsaInfo.setOriginRouter("test"); |
||||
lsaInfo.setSequenceNumber(128); |
||||
lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000)); |
||||
nameLsa.setLsaInfo(lsaInfo); |
||||
|
||||
nameLsa.addName("test1"); |
||||
nameLsa.addName("test2"); |
||||
|
||||
std::ostringstream os; |
||||
os << nameLsa; |
||||
|
||||
BOOST_CHECK_EQUAL(os.str(), "NameLsa(" |
||||
"LsaInfo(" |
||||
"OriginRouter: /test, " |
||||
"SequenceNumber: 128, " |
||||
"ExpirationPeriod: 10000 milliseconds), " |
||||
"Name: /test1, " |
||||
"Name: /test2)"); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() |
||||
|
||||
} // namespace test
|
||||
} // namespace tlv
|
||||
} // namespace nlsr
|
Loading…
Reference in new issue