lsa: change type variable to enum class

Change-Id: I7fba951649771700ce6ccc4be7fb400546607e96
refs: #4340
This commit is contained in:
Nick Gordon committed 2017-10-19 15:44:06 -07:00
1 parent ff9a62713b
commit 727d4830d7
19 files changed
+288 -190

No files matched your search

-2
View File
@@ -56,8 +56,6 @@ struct is_iterator<T, typename std::enable_if<!std::is_same<
static constexpr bool value = true;
};
using IsLsaNew = std::function<bool(const ndn::Name&, const std::string&, const uint64_t&)>;
} // namespace nlsr
#endif // NLSR_COMMON_HPP
+19 -13
View File
@@ -118,20 +118,21 @@ SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
// A router should not try to fetch its own LSA
if (originRouter != m_confParam.getRouterPrefix()) {
std::string lsaType = updateName.get(updateName.size()-1).toUri();
Lsa::Type lsaType;
std::istringstream(updateName.get(updateName.size()-1).toUri()) >> lsaType;
_LOG_DEBUG("Received sync update with higher " << lsaType
<< " sequence number than entry in LSDB");
if (m_isLsaNew(originRouter, lsaType, seqNo)) {
if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
<< " is enabled. Not going to fetch.");
return;
}
if (lsaType == CoordinateLsa::TYPE_STRING && seqNo != 0 &&
if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
_LOG_ERROR("Got an update for coordinate LSA when link-state"
<< " is enabled. Not going to fetch.");
@@ -143,7 +144,7 @@ SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
}
void
SyncLogicHandler::publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo)
SyncLogicHandler::publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo)
{
if (m_syncSocket == nullptr) {
_LOG_FATAL("Cannot publish routing update; SyncSocket does not exist");
@@ -151,14 +152,19 @@ SyncLogicHandler::publishRoutingUpdate(const ndn::Name& type, const uint64_t& se
BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncSocket does not exist"));
}
if (type == NameLsa::TYPE_STRING) {
publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
}
else if (type == AdjLsa::TYPE_STRING) {
switch (type) {
case Lsa::Type::ADJACENCY:
publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
}
else {
break;
case Lsa::Type::COORDINATE:
publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
break;
case Lsa::Type::NAME:
publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
break;
default:
break;
}
}
@@ -170,13 +176,13 @@ SyncLogicHandler::buildUpdatePrefix()
updatePrefix.append(m_confParam.getRouterName());
m_nameLsaUserPrefix = updatePrefix;
m_nameLsaUserPrefix.append(NameLsa::TYPE_STRING);
m_nameLsaUserPrefix.append(std::to_string(Lsa::Type::NAME));
m_adjLsaUserPrefix = updatePrefix;
m_adjLsaUserPrefix.append(AdjLsa::TYPE_STRING);
m_adjLsaUserPrefix.append(std::to_string(Lsa::Type::ADJACENCY));
m_coorLsaUserPrefix = updatePrefix;
m_coorLsaUserPrefix.append(CoordinateLsa::TYPE_STRING);
m_coorLsaUserPrefix.append(std::to_string(Lsa::Type::COORDINATE));
}
void
+3 -2
View File
@@ -24,6 +24,7 @@
#include "test-access-control.hpp"
#include "signals.hpp"
#include "lsa.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/signal.hpp>
@@ -48,7 +49,7 @@ class SyncLogicHandler
{
public:
using IsLsaNew =
std::function<bool(const ndn::Name&, const std::string& lsaType, const uint64_t&)>;
std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&)>;
class Error : public std::runtime_error
{
@@ -83,7 +84,7 @@ public:
* \sa publishSyncUpdate
*/
void
publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo);
publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
/*! \brief Create and configure a socket to enable ChronoSync for this NLSR.
*
+57 -19
View File
@@ -38,22 +38,17 @@ namespace nlsr {
INIT_LOGGER("Lsa");
const std::string NameLsa::TYPE_STRING = "name";
const std::string AdjLsa::TYPE_STRING = "adjacency";
const std::string CoordinateLsa::TYPE_STRING = "coordinate";
const ndn::Name
NameLsa::getKey() const
{
ndn::Name key = m_origRouter;
key.append(NameLsa::TYPE_STRING);
key.append(std::to_string(Lsa::Type::NAME));
return key;
}
NameLsa::NameLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
NamePrefixList& npl)
: Lsa(NameLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsSeqNo = lsn;
@@ -67,7 +62,7 @@ std::string
NameLsa::getData()
{
std::ostringstream os;
os << m_origRouter << "|" << NameLsa::TYPE_STRING << "|" << m_lsSeqNo << "|"
os << m_origRouter << "|" << Lsa::Type::NAME << "|" << m_lsSeqNo << "|"
<< ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_npl.size();
for (const auto& name : m_npl.getNames()) {
os << "|" << name;
@@ -89,7 +84,7 @@ NameLsa::initializeFromContent(const std::string& content)
return false;
}
try {
if (*tok_iter++ != NameLsa::TYPE_STRING) {
if (*tok_iter++ != std::to_string(Lsa::Type::NAME)) {
return false;
}
@@ -119,7 +114,7 @@ NameLsa::writeLog()
{
_LOG_DEBUG("Name Lsa: ");
_LOG_DEBUG(" Origination Router: " << m_origRouter);
_LOG_DEBUG(" Ls Type: " << m_lsType);
_LOG_DEBUG(" Ls Type: " << getType());
_LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo);
_LOG_DEBUG(" Ls Lifetime: " << m_expirationTimePoint);
_LOG_DEBUG(" Names: ");
@@ -135,7 +130,6 @@ NameLsa::writeLog()
CoordinateLsa::CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
double r, std::vector<double> theta)
: Lsa(CoordinateLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsSeqNo = lsn;
@@ -148,7 +142,7 @@ const ndn::Name
CoordinateLsa::getKey() const
{
ndn::Name key = m_origRouter;
key.append(CoordinateLsa::TYPE_STRING);
key.append(std::to_string(Lsa::Type::COORDINATE));
return key;
}
@@ -174,7 +168,7 @@ std::string
CoordinateLsa::getData()
{
std::ostringstream os;
os << m_origRouter << "|" << CoordinateLsa::TYPE_STRING << "|" << m_lsSeqNo << "|"
os << m_origRouter << "|" << Lsa::Type::COORDINATE << "|" << m_lsSeqNo << "|"
<< ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_corRad << "|"
<< m_angles.size() << "|";
@@ -198,7 +192,7 @@ CoordinateLsa::initializeFromContent(const std::string& content)
}
try {
if (*tok_iter++ != CoordinateLsa::TYPE_STRING) {
if (*tok_iter++ != std::to_string(Lsa::Type::COORDINATE)) {
return false;
}
@@ -223,7 +217,7 @@ CoordinateLsa::writeLog()
{
_LOG_DEBUG("Cor Lsa: ");
_LOG_DEBUG(" Origination Router: " << m_origRouter);
_LOG_DEBUG(" Ls Type: " << m_lsType);
_LOG_DEBUG(" Ls Type: " << getType());
_LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo);
_LOG_DEBUG(" Ls Lifetime: " << m_expirationTimePoint);
_LOG_DEBUG(" Hyperbolic Radius: " << m_corRad);
@@ -236,7 +230,6 @@ CoordinateLsa::writeLog()
AdjLsa::AdjLsa(const ndn::Name& origR, uint32_t lsn,
const ndn::time::system_clock::TimePoint& lt,
uint32_t nl , AdjacencyList& adl)
: Lsa(AdjLsa::TYPE_STRING)
{
m_origRouter = origR;
m_lsSeqNo = lsn;
@@ -254,7 +247,7 @@ const ndn::Name
AdjLsa::getKey() const
{
ndn::Name key = m_origRouter;
key.append(AdjLsa::TYPE_STRING);
key.append(std::to_string(Lsa::Type::ADJACENCY));
return key;
}
@@ -268,7 +261,7 @@ std::string
AdjLsa::getData()
{
std::ostringstream os;
os << m_origRouter << "|" << AdjLsa::TYPE_STRING << "|" << m_lsSeqNo << "|"
os << m_origRouter << "|" << Lsa::Type::ADJACENCY << "|" << m_lsSeqNo << "|"
<< ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_adl.size();
for (const auto& adjacent : m_adl.getAdjList()) {
os << "|" << adjacent.getName() << "|" << adjacent.getFaceUri()
@@ -291,7 +284,7 @@ AdjLsa::initializeFromContent(const std::string& content)
return false;
}
try {
if (*tok_iter++ != AdjLsa::TYPE_STRING) {
if (*tok_iter++ != std::to_string(Lsa::Type::ADJACENCY)) {
return false;
}
@@ -351,7 +344,7 @@ operator<<(std::ostream& os, const AdjLsa& adjLsa)
{
os << "Adj Lsa:\n"
<< " Origination Router: " << adjLsa.getOrigRouter() << "\n"
<< " Ls Type: " << adjLsa.getLsType() << "\n"
<< " Ls Type: " << adjLsa.getType() << "\n"
<< " Ls Seq No: " << adjLsa.getLsSeqNo() << "\n"
<< " Ls Lifetime: " << adjLsa.getExpirationTimePoint() << "\n"
<< " Adjacents: \n";
@@ -369,4 +362,49 @@ operator<<(std::ostream& os, const AdjLsa& adjLsa)
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;
}
} // 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";
default:
return "BASE";
}
}
} // namespace std
+41 -20
View File
@@ -37,19 +37,25 @@ class Nlsr;
class Lsa
{
public:
Lsa(const std::string& lsaType)
enum class Type {
ADJACENCY,
COORDINATE,
NAME,
BASE
};
Lsa()
: m_origRouter()
, m_lsType(lsaType)
, m_lsSeqNo()
, m_expirationTimePoint()
, m_expiringEventId()
{
}
const std::string&
getLsType() const
virtual Type
getType() const
{
return m_lsType;
return Type::BASE;
}
void
@@ -102,7 +108,6 @@ public:
protected:
ndn::Name m_origRouter;
const std::string m_lsType;
uint32_t m_lsSeqNo;
ndn::time::system_clock::TimePoint m_expirationTimePoint;
ndn::EventId m_expiringEventId;
@@ -112,8 +117,6 @@ class NameLsa: public Lsa
{
public:
NameLsa()
: Lsa(NameLsa::TYPE_STRING)
, m_npl()
{
}
@@ -121,6 +124,12 @@ public:
const ndn::time::system_clock::TimePoint& lt,
NamePrefixList& npl);
Lsa::Type
getType() const override
{
return Lsa::Type::NAME;
}
NamePrefixList&
getNpl()
{
@@ -180,8 +189,6 @@ public:
private:
NamePrefixList m_npl;
public:
static const std::string TYPE_STRING;
};
class AdjLsa: public Lsa
@@ -190,8 +197,6 @@ public:
typedef AdjacencyList::const_iterator const_iterator;
AdjLsa()
: Lsa(AdjLsa::TYPE_STRING)
, m_adl()
{
}
@@ -199,6 +204,12 @@ public:
const ndn::time::system_clock::TimePoint& lt,
uint32_t nl , AdjacencyList& adl);
Lsa::Type
getType() const override
{
return Lsa::Type::ADJACENCY;
}
AdjacencyList&
getAdl()
{
@@ -277,17 +288,13 @@ public:
private:
uint32_t m_noLink;
AdjacencyList m_adl;
public:
static const std::string TYPE_STRING;
};
class CoordinateLsa: public Lsa
{
public:
CoordinateLsa()
: Lsa(CoordinateLsa::TYPE_STRING)
, m_corRad(0)
: m_corRad(0)
{
}
@@ -295,6 +302,12 @@ public:
const ndn::time::system_clock::TimePoint& lt,
double r, std::vector<double> theta);
Lsa::Type
getType() const override
{
return Lsa::Type::COORDINATE;
}
const ndn::Name
getKey() const;
@@ -350,14 +363,22 @@ public:
private:
double m_corRad;
std::vector<double> m_angles;
public:
static const std::string TYPE_STRING;
};
std::ostream&
operator<<(std::ostream& os, const AdjLsa& adjLsa);
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
+57 -49
View File
@@ -66,7 +66,7 @@ Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
: m_nlsr(nlsr)
, m_scheduler(scheduler)
, m_sync(m_nlsr.getNlsrFace(),
[this] (const ndn::Name& routerName, const std::string& lsaType,
[this] (const ndn::Name& routerName, const Lsa::Type& lsaType,
const uint64_t& sequenceNumber) {
return isLsaNew(routerName, lsaType, sequenceNumber);
}, m_nlsr.getConfParameter())
@@ -166,7 +166,7 @@ Lsdb::buildAndInstallOwnNameLsa()
m_sequencingManager.increaseNameLsaSeq();
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq());
return installNameLsa(nameLsa);
}
@@ -396,7 +396,7 @@ Lsdb::buildAndInstallOwnCoordinateLsa()
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sequencingManager.increaseCorLsaSeq();
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq());
}
installCoordinateLsa(corLsa);
@@ -628,7 +628,7 @@ Lsdb::buildAdjLsa()
_LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors");
// Get this router's key
ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
key.append(AdjLsa::TYPE_STRING);
key.append(std::to_string(Lsa::Type::ADJACENCY));
removeAdjLsa(key);
// Recompute routing table after removal
@@ -770,7 +770,7 @@ Lsdb::buildAndInstallOwnAdjLsa()
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
m_sequencingManager.increaseAdjLsaSeq();
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq());
}
return installAdjLsa(adjLsa);
@@ -854,7 +854,7 @@ Lsdb::expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
chkNameLsa->getLsSeqNo(),
m_lsaRefreshTime));
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq());
}
// Since we cannot refresh other router's LSAs, our only choice is to expire.
else {
@@ -898,7 +898,7 @@ Lsdb::expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
chkAdjLsa->getLsSeqNo(),
m_lsaRefreshTime));
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq());
}
// An LSA from another router is expiring
else {
@@ -951,7 +951,7 @@ Lsdb::expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
// Only sync coordinate LSAs if link-state routing is disabled
if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
m_sequencingManager.writeSeqNoToFile();
m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq());
}
}
// We can't refresh other router's LSAs, so we remove it.
@@ -1004,18 +1004,20 @@ Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
std::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
timeoutCount, deadline, lsaName, seqNo));
// increment a specific SENT_LSA_INTEREST
std::string typeLSA = interestName[-2].toUri();
if (typeLSA == AdjLsa::TYPE_STRING) {
Lsa::Type lsaType;
std::istringstream(interestName[-2].toUri()) >> lsaType;
switch (lsaType) {
case Lsa::Type::ADJACENCY:
lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_INTEREST);
}
else if (typeLSA == CoordinateLsa::TYPE_STRING) {
break;
case Lsa::Type::COORDINATE:
lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_INTEREST);
}
else if (typeLSA == NameLsa::TYPE_STRING) {
break;
case Lsa::Type::NAME:
lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_INTEREST);
}
else {
_LOG_ERROR("typeLSA " + typeLSA + " not recognized; failed Statistics::PacketType conversion");
break;
default:
_LOG_ERROR("lsaType " << lsaType << " not recognized; failed Statistics::PacketType conversion");
}
}
@@ -1041,16 +1043,20 @@ Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
uint64_t seqNo = interestName[-1].toNumber();
_LOG_DEBUG("LSA sequence number from interest: " << seqNo);
std::string interestedLsType = interestName[-2].toUri();
Lsa::Type interestedLsType;
std::istringstream(interestName[-2].toUri()) >> interestedLsType;
if (interestedLsType == NameLsa::TYPE_STRING) {
processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
if (interestedLsType == Lsa::Type::NAME) {
processInterestForNameLsa(interest, originRouter.append(std::to_string(interestedLsType)),
seqNo);
}
else if (interestedLsType == AdjLsa::TYPE_STRING) {
processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
else if (interestedLsType == Lsa::Type::ADJACENCY) {
processInterestForAdjacencyLsa(interest, originRouter.append(std::to_string(interestedLsType)),
seqNo);
}
else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
else if (interestedLsType == Lsa::Type::COORDINATE) {
processInterestForCoordinateLsa(interest, originRouter.append(std::to_string(interestedLsType)),
seqNo);
}
else {
_LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
@@ -1192,16 +1198,20 @@ Lsdb::onContentValidated(const std::shared_ptr<const ndn::Data>& data)
std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()),
data->getContent().value_size());
std::string interestedLsType = dataName[-2].toUri();
Lsa::Type interestedLsType;
std::istringstream(dataName[-2].toUri()) >> interestedLsType;
if (interestedLsType == NameLsa::TYPE_STRING) {
processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
if (interestedLsType == Lsa::Type::NAME) {
processContentNameLsa(originRouter.append(std::to_string(interestedLsType)), seqNo,
dataContent);
}
else if (interestedLsType == AdjLsa::TYPE_STRING) {
processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
else if (interestedLsType == Lsa::Type::ADJACENCY) {
processContentAdjacencyLsa(originRouter.append(std::to_string(interestedLsType)), seqNo,
dataContent);
}
else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
else if (interestedLsType == Lsa::Type::COORDINATE) {
processContentCoordinateLsa(originRouter.append(std::to_string(interestedLsType)), seqNo,
dataContent);
}
else {
_LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
@@ -1284,36 +1294,34 @@ Lsdb::writeAdjLsdbLog()
//-----utility function -----
bool
Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
Lsdb::doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType)
{
if (lsType == NameLsa::TYPE_STRING) {
return doesNameLsaExist(key);
}
else if (lsType == AdjLsa::TYPE_STRING) {
switch (lsType) {
case Lsa::Type::ADJACENCY:
return doesAdjLsaExist(key);
}
else if (lsType == CoordinateLsa::TYPE_STRING) {
case Lsa::Type::COORDINATE:
return doesCoordinateLsaExist(key);
case Lsa::Type::NAME:
return doesNameLsaExist(key);
default:
return false;
}
return false;
}
bool
Lsdb::isLsaNew(const ndn::Name& routerName, const std::string& lsaType,
Lsdb::isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType,
const uint64_t& sequenceNumber) {
ndn::Name lsaKey = routerName;
lsaKey.append(lsaType);
lsaKey.append(std::to_string(lsaType));
if (lsaType == NameLsa::TYPE_STRING) {
return isNameLsaNew(lsaKey, sequenceNumber);
}
else if (lsaType == AdjLsa::TYPE_STRING) {
switch (lsaType) {
case Lsa::Type::ADJACENCY:
return isAdjLsaNew(lsaKey, sequenceNumber);
}
else if (lsaType == CoordinateLsa::TYPE_STRING) {
case Lsa::Type::COORDINATE:
return isCoordinateLsaNew(lsaKey, sequenceNumber);
}
else {
case Lsa::Type::NAME:
return isNameLsaNew(lsaKey, sequenceNumber);
default:
return false;
}
}
+2 -2
View File
@@ -51,10 +51,10 @@ public:
}
bool
isLsaNew(const ndn::Name& routerName, const std::string& lsaType, const uint64_t& sequenceNumber);
isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
bool
doesLsaExist(const ndn::Name& key, const std::string& lsType);
doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
/*! \brief Builds a name LSA for this router and then installs it
into the LSDB.
+2 -2
View File
@@ -472,12 +472,12 @@ HyperbolicRoutingCalculator::getHyperbolicDistance(Map& map, Lsdb& lsdb,
double distance = UNKNOWN_DISTANCE;
ndn::Name srcLsaKey = src;
srcLsaKey.append("coordinate");
srcLsaKey.append(std::to_string(Lsa::Type::COORDINATE));
CoordinateLsa* srcLsa = lsdb.findCoordinateLsa(srcLsaKey);
ndn::Name destLsaKey = dest;
destLsaKey.append("coordinate");
destLsaKey.append(std::to_string(Lsa::Type::COORDINATE));
CoordinateLsa* destLsa = lsdb.findCoordinateLsa(destLsaKey);
+4 -4
View File
@@ -58,14 +58,14 @@ RoutingTable::calculate(Nlsr& pnlsr)
if ((!isHrEnabled
&&
pnlsr.getLsdb()
.doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri()
+ "/" + "adjacency", std::string("adjacency")))
.doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()}
.append(std::to_string(Lsa::Type::ADJACENCY)), Lsa::Type::ADJACENCY))
||
(isHrEnabled
&&
pnlsr.getLsdb()
.doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri()
+ "/" + "coordinate", std::string("coordinate")))) {
.doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()}
.append(std::to_string(Lsa::Type::COORDINATE)), Lsa::Type::COORDINATE))) {
if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
_LOG_TRACE("Clearing old routing table");
clearRoutingTable();
+2 -2
View File
@@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(Basic)
BOOST_AUTO_TEST_CASE(Asymmetric)
{
// Asymmetric link cost between B and C
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(AdjLsa::TYPE_STRING);
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(std::to_string(Lsa::Type::ADJACENCY));
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
@@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(Asymmetric)
BOOST_AUTO_TEST_CASE(AsymmetricZeroCost)
{
// Asymmetric link cost between B and C
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(AdjLsa::TYPE_STRING);
ndn::Name key = ndn::Name(ROUTER_B_NAME).append(std::to_string(Lsa::Type::ADJACENCY));
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
+2 -2
View File
@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(ValidateCorrectLSA)
lsaInterestName.append(nlsr.getConfParameter().getRouterName());
// Append LSA type
lsaInterestName.append(ndn::Name("name"));
lsaInterestName.append(std::to_string(Lsa::Type::NAME));
// This would be the sequence number of its own NameLsa
lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(DoNotValidateIncorrectLSA)
lsaInterestName.append(nlsr.getConfParameter().getRouterName());
// Append LSA type
lsaInterestName.append(ndn::Name("name"));
lsaInterestName.append(std::to_string(Lsa::Type::NAME));
// This would be the sequence number of its own NameLsa
lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
+3 -3
View File
@@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic)
NameLsa nlsa1("router1", 12, testTimePoint, npl1);
NameLsa nlsa2("router2", 12, testTimePoint, npl1);
BOOST_CHECK_EQUAL(nlsa1.getLsType(), NameLsa::TYPE_STRING);
BOOST_CHECK_EQUAL(nlsa1.getType(), Lsa::Type::NAME);
BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
AdjLsa alsa1(routerName, seqNo, testTimePoint,
activeAdjacencies.size(), activeAdjacencies);
BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING);
BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), seqNo);
BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
std::string EXPECTED_OUTPUT =
"Adj Lsa:\n"
" Origination Router: /router1\n"
" Ls Type: adjacency\n"
" Ls Type: ADJACENCY\n"
" Ls Seq No: 12\n"
" Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n"
" Adjacents: \n"
+9 -9
View File
@@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(SegmentLsaData)
std::string expectedDataContent = lsa.getData();
lsdb.installNameLsa(lsa);
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/");
interestName.appendNumber(seqNo);
ndn::Interest interest(interestName);
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
}
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/");
interestName.appendNumber(seqNo);
const ndn::ConstBufferPtr bufferPtr = std::make_shared<ndn::Buffer>(lsa.getData().c_str(),
@@ -258,11 +258,11 @@ BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
lsdb1.installNameLsa(nlsa1);
lsdb1.writeNameLsdbLog();
BOOST_CHECK(lsdb1.doesLsaExist(ndn::Name("/router1/1/name"), NameLsa::TYPE_STRING));
BOOST_CHECK(lsdb1.doesLsaExist(ndn::Name("/router1/1/NAME"), Lsa::Type::NAME));
lsdb1.removeNameLsa(router1);
BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(ndn::Name("/router1/1"), NameLsa::TYPE_STRING), false);
BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(ndn::Name("/router1/1"), Lsa::Type::NAME), false);
}
BOOST_AUTO_TEST_CASE(InstallNameLsa)
@@ -281,8 +281,8 @@ BOOST_AUTO_TEST_CASE(InstallNameLsa)
NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
lsdb.installNameLsa(lsa);
BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter + "/name", NameLsa::TYPE_STRING), true);
NamePrefixList& nameList = lsdb.findNameLsa(otherRouter + "/name")->getNpl();
BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter + "/NAME", Lsa::Type::NAME), true);
NamePrefixList& nameList = lsdb.findNameLsa(otherRouter + "/NAME")->getNpl();
BOOST_CHECK_EQUAL(nameList, prefixes);
//areNamePrefixListsEqual(nameList, prefixes);
@@ -346,15 +346,15 @@ BOOST_AUTO_TEST_CASE(TestIsLsaNew)
// Lower NameLSA sequence number
uint64_t lowerSeqNo = 998;
BOOST_CHECK(!lsdb.isLsaNew(originRouter, NameLsa::TYPE_STRING, lowerSeqNo));
BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
// Same NameLSA sequence number
uint64_t sameSeqNo = 999;
BOOST_CHECK(!lsdb.isLsaNew(originRouter, NameLsa::TYPE_STRING, sameSeqNo));
BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
// Higher NameLSA sequence number
uint64_t higherSeqNo = 1000;
BOOST_CHECK(lsdb.isLsaNew(originRouter, NameLsa::TYPE_STRING, higherSeqNo));
BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
}
BOOST_AUTO_TEST_SUITE_END() // TestLsdb
+41 -21
View File
@@ -68,13 +68,16 @@ BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
{
// Simulate loading configuration file
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborB);
Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborC);
nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
@@ -91,13 +94,16 @@ BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
{
// Simulate loading configuration file
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborB);
Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborC);
nlsr.initialize();
@@ -131,7 +137,8 @@ BOOST_AUTO_TEST_CASE(FaceCreateEvent)
// Setting constants for the unit test
const uint32_t faceId = 1;
const std::string faceUri = "udp4://10.0.0.1:6363";
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10,
Adjacent::STATUS_INACTIVE, 0, 0);
BOOST_REQUIRE_EQUAL(nlsr.getAdjacencyList().insert(neighbor), 0);
this->advanceClocks(ndn::time::milliseconds(1));
@@ -162,7 +169,8 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch)
const uint32_t faceId = 1;
const std::string eventUri = "udp4://10.0.0.1:6363";
const std::string neighborUri = "udp4://10.0.0.2:6363";
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(neighborUri), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(neighborUri), 10,
Adjacent::STATUS_INACTIVE, 0, 0);
nlsr.getAdjacencyList().insert(neighbor);
// Build, sign, and send the Face Event
@@ -190,7 +198,8 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured)
const uint32_t eventFaceId = 1;
const uint32_t neighborFaceId = 2;
const std::string faceUri = "udp4://10.0.0.1:6363";
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10, Adjacent::STATUS_ACTIVE, 0, neighborFaceId);
Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10,
Adjacent::STATUS_ACTIVE, 0, neighborFaceId);
nlsr.getAdjacencyList().insert(neighbor);
// Build, sign, and send the Face Event
@@ -214,7 +223,8 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured)
BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
{
std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService);
std::shared_ptr<ndn::util::DummyClientFace> face =
std::make_shared<ndn::util::DummyClientFace>(g_ioService);
Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain);
Lsdb& lsdb = nlsr.getLsdb();
@@ -236,7 +246,8 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
neighbors.insert(failNeighbor);
// Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_ACTIVE, 0, 256);
Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10,
Adjacent::STATUS_ACTIVE, 0, 256);
neighbors.insert(otherNeighbor);
nlsr.initialize();
@@ -246,7 +257,8 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
// Set up adjacency LSAs
// This router
Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.3"), 10, Adjacent::STATUS_ACTIVE, 0, 256);
Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.3"), 10,
Adjacent::STATUS_ACTIVE, 0, 256);
AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors);
lsdb.installAdjLsa(ownAdjLsa);
@@ -273,7 +285,8 @@ BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
this->advanceClocks(ndn::time::milliseconds(1));
// Make sure an adjacency LSA was built
ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix())
.append(std::to_string(Lsa::Type::ADJACENCY));
AdjLsa* lsa = lsdb.findAdjLsa(key);
BOOST_REQUIRE(lsa != nullptr);
@@ -374,12 +387,14 @@ BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
// Add neighbors
// Router A
ndn::Name neighborAName("/ndn/site/%C1.router/routerA");
Adjacent neighborA(neighborAName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborA(neighborAName, ndn::util::FaceUri("udp4://10.0.0.1"), 0,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
// Router B
ndn::Name neighborBName("/ndn/site/%C1.router/routerB");
Adjacent neighborB(neighborBName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborB(neighborBName, ndn::util::FaceUri("udp4://10.0.0.1"), 0,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborB);
nlsr.initialize();
@@ -389,7 +404,7 @@ BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
receiveHelloData(neighborAName, conf.getRouterPrefix());
this->advanceClocks(ndn::time::seconds(1));
ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING);
ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
// Adjacency LSA should be built even though other router is INACTIVE
AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
@@ -440,12 +455,14 @@ BOOST_AUTO_TEST_CASE(CanonizeUris)
nlsr.initialize();
};
std::function<void(std::list<Adjacent>::iterator)> thenCallback =
[this, &thenCallback, &finallyCallback, &nCanonizationsLeft] (std::list<Adjacent>::iterator iterator) {
[this, &thenCallback, &finallyCallback, &nCanonizationsLeft]
(std::list<Adjacent>::iterator iterator) {
nCanonizationsLeft--;
nlsr.canonizeNeighborUris(iterator, thenCallback, finallyCallback);
};
nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(),
[&thenCallback, &finallyCallback] (std::list<Adjacent>::iterator iterator) {
[&thenCallback, &finallyCallback]
(std::list<Adjacent>::iterator iterator) {
thenCallback(iterator);
},
finallyCallback);
@@ -504,10 +521,12 @@ BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure)
BOOST_AUTO_TEST_CASE(FaceDatasetProcess)
{
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://192.168.0.101:6363"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://192.168.0.101:6363"), 10,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborB);
ndn::nfd::FaceStatus payload1;
@@ -529,7 +548,8 @@ BOOST_AUTO_TEST_CASE(FaceDatasetProcess)
BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor)
{
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25,
Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
ndn::nfd::FaceStatus payload;
+15 -11
View File
@@ -200,21 +200,25 @@ BOOST_AUTO_TEST_CASE(LsdbSendLsaInterest)
uint32_t seqNo = 1;
// Adjacency LSA
sendInterestAndCheckStats(interestPrefix, AdjLsa::TYPE_STRING, seqNo, Statistics::PacketType::SENT_ADJ_LSA_INTEREST);
sendInterestAndCheckStats(interestPrefix, std::to_string(Lsa::Type::ADJACENCY), seqNo,
Statistics::PacketType::SENT_ADJ_LSA_INTEREST);
// Coordinate LSA
sendInterestAndCheckStats(interestPrefix, CoordinateLsa::TYPE_STRING, seqNo, Statistics::PacketType::SENT_COORD_LSA_INTEREST);
sendInterestAndCheckStats(interestPrefix, std::to_string(Lsa::Type::COORDINATE), seqNo,
Statistics::PacketType::SENT_COORD_LSA_INTEREST);
// Name LSA
sendInterestAndCheckStats(interestPrefix, NameLsa::TYPE_STRING, seqNo, Statistics::PacketType::SENT_NAME_LSA_INTEREST);
sendInterestAndCheckStats(interestPrefix, std::to_string(Lsa::Type::NAME), seqNo,
Statistics::PacketType::SENT_NAME_LSA_INTEREST);
// 3 total lsa interests were sent
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::SENT_LSA_INTEREST), 3);
}
/*
* Tests the statistics collected upon processing incoming lsa interests and respective outgoing data.
* This process will trigger both an increment for received lsa interest and sent lsa data.
* Tests the statistics collected upon processing incoming lsa
* interests and respective outgoing data. This process will trigger
* both an increment for received lsa interest and sent lsa data.
*
* /sa receiveInterestAndCheckSentStats
*/
@@ -238,7 +242,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveInterestSendData)
// Receive Adjacency LSA Interest
receiveInterestAndCheckSentStats(interestPrefix,
AdjLsa::TYPE_STRING,
std::to_string(Lsa::Type::ADJACENCY),
seqNo,
Statistics::PacketType::RCV_ADJ_LSA_INTEREST,
Statistics::PacketType::SENT_ADJ_LSA_DATA);
@@ -252,7 +256,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveInterestSendData)
// Receive Name LSA Interest
receiveInterestAndCheckSentStats(interestPrefix,
NameLsa::TYPE_STRING,
std::to_string(Lsa::Type::NAME),
seqNo,
Statistics::PacketType::RCV_NAME_LSA_INTEREST,
Statistics::PacketType::SENT_NAME_LSA_DATA);
@@ -264,7 +268,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveInterestSendData)
// Receive Adjacency LSA Interest
receiveInterestAndCheckSentStats(interestPrefix,
CoordinateLsa::TYPE_STRING,
std::to_string(Lsa::Type::COORDINATE),
seqNo,
Statistics::PacketType::RCV_COORD_LSA_INTEREST,
Statistics::PacketType::SENT_COORD_LSA_DATA);
@@ -287,7 +291,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveData)
ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
// adjacency lsa
ndn::Name adjInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/adjacency/");
ndn::Name adjInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/ADJACENCY/");
adjInterest.appendNumber(seqNo);
AdjLsa aLsa(routerName, seqNo, MAX_TIME, 1, nlsr.getAdjacencyList());
lsdb.installAdjLsa(aLsa);
@@ -298,7 +302,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveData)
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_ADJ_LSA_DATA), 1);
// coordinate lsa
ndn::Name coordInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/coordinate/");
ndn::Name coordInterest("/ndn/NLSR/LSA/cs/%C1.Router/router1/COORDINATE/");
coordInterest.appendNumber(seqNo);
std::vector<double> angles = {20.0, 30.0};
CoordinateLsa cLsa(routerName, seqNo, MAX_TIME, 2.5, angles);
@@ -310,7 +314,7 @@ BOOST_AUTO_TEST_CASE(LsdbReceiveData)
BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_COORD_LSA_DATA), 1);
// name lsa
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/name/");
ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/");
interestName.appendNumber(seqNo);
NameLsa nLsa(routerName, seqNo, MAX_TIME, nlsr.getNamePrefixList());
lsdb.installNameLsa(nLsa);
+27 -25
View File
@@ -23,6 +23,7 @@
#include "test-common.hpp"
#include "common.hpp"
#include "nlsr.hpp"
#include "lsa.hpp"
#include "logger.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -38,7 +39,7 @@ public:
SyncLogicFixture()
: face(std::make_shared<ndn::util::DummyClientFace>())
, nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
, testIsLsaNew([] (const ndn::Name& name, const std::string& lsaType,
, testIsLsaNew([] (const ndn::Name& name, const Lsa::Type& lsaType,
const uint64_t sequenceNumber) {
return true;
})
@@ -79,14 +80,14 @@ public:
std::shared_ptr<ndn::util::DummyClientFace> face;
Nlsr nlsr;
ConfParameter conf;
IsLsaNew testIsLsaNew;
SyncLogicHandler::IsLsaNew testIsLsaNew;
const std::string CONFIG_NETWORK;
const std::string CONFIG_SITE;
const std::string CONFIG_ROUTER_NAME;
const std::string OTHER_ROUTER_NAME;
const std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING,
CoordinateLsa::TYPE_STRING};
const std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::ADJACENCY,
Lsa::Type::COORDINATE};
};
BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
@@ -100,13 +101,13 @@ BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf};
sync.createSyncSocket(conf.getChronosyncPrefix());
std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING};
std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::ADJACENCY};
uint64_t syncSeqNo = 1;
for (const std::string& lsaType : lsaTypes) {
for (const Lsa::Type& lsaType : lsaTypes) {
std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
+ OTHER_ROUTER_NAME + lsaType;
+ OTHER_ROUTER_NAME + std::to_string(lsaType);
// Actual testing done here -- signal function callback
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
@@ -131,11 +132,11 @@ BOOST_AUTO_TEST_CASE(UpdateForOtherHR)
sync.createSyncSocket(conf.getChronosyncPrefix());
uint64_t syncSeqNo = 1;
std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, CoordinateLsa::TYPE_STRING};
std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::COORDINATE};
for (const std::string& lsaType : lsaTypes) {
for (const Lsa::Type& lsaType : lsaTypes) {
std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
+ OTHER_ROUTER_NAME + lsaType;
+ OTHER_ROUTER_NAME + std::to_string(lsaType);
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
[& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
@@ -158,11 +159,11 @@ BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry)
SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf};
sync.createSyncSocket(conf.getChronosyncPrefix());
for (const std::string& lsaType : lsaTypes) {
for (const Lsa::Type& lsaType : lsaTypes) {
uint64_t syncSeqNo = 1;
std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
+ OTHER_ROUTER_NAME + lsaType;
+ OTHER_ROUTER_NAME + std::to_string(lsaType);
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
[& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
@@ -185,11 +186,11 @@ BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf};
sync.createSyncSocket(conf.getChronosyncPrefix());
for (const std::string& lsaType : lsaTypes) {
for (const Lsa::Type& lsaType : lsaTypes) {
// To ensure that we get correctly-separated components, create
// and modify a Name to hand off.
ndn::Name updateName = ndn::Name{conf.getLsaPrefix()};
updateName.append(CONFIG_SITE).append(CONFIG_ROUTER_NAME).append(lsaType);
updateName.append(CONFIG_SITE).append(CONFIG_ROUTER_NAME).append(std::to_string(lsaType));
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
[& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
@@ -211,9 +212,9 @@ BOOST_AUTO_TEST_CASE(MalformedUpdate)
SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf};
sync.createSyncSocket(conf.getChronosyncPrefix());
for (const std::string& lsaType : lsaTypes) {
for (const Lsa::Type& lsaType : lsaTypes) {
ndn::Name updateName{CONFIG_SITE};
updateName.append(CONFIG_ROUTER_NAME).append(lsaType);
updateName.append(CONFIG_ROUTER_NAME).append(std::to_string(lsaType));
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
[& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
@@ -230,7 +231,7 @@ BOOST_AUTO_TEST_CASE(MalformedUpdate)
*/
BOOST_AUTO_TEST_CASE(LsaNotNew)
{
auto testLsaAlwaysFalse = [] (const ndn::Name& routerName, const std::string& lsaType,
auto testLsaAlwaysFalse = [] (const ndn::Name& routerName, const Lsa::Type& lsaType,
const uint64_t& sequenceNumber) {
return false;
};
@@ -244,7 +245,8 @@ BOOST_AUTO_TEST_CASE(LsaNotNew)
});
std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
CONFIG_SITE + "/%C1.Router/other-router/" + NameLsa::TYPE_STRING;
CONFIG_SITE + "/%C1.Router/other-router/" +
std::to_string(Lsa::Type::NAME);
receiveUpdate(updateName, sequenceNumber, sync);
}
@@ -265,32 +267,32 @@ BOOST_AUTO_TEST_CASE(UpdatePrefix)
sync.buildUpdatePrefix();
BOOST_CHECK_EQUAL(sync.m_nameLsaUserPrefix,
ndn::Name(expectedPrefix).append(NameLsa::TYPE_STRING));
ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::NAME)));
BOOST_CHECK_EQUAL(sync.m_adjLsaUserPrefix,
ndn::Name(expectedPrefix).append(AdjLsa::TYPE_STRING));
ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::ADJACENCY)));
BOOST_CHECK_EQUAL(sync.m_coorLsaUserPrefix,
ndn::Name(expectedPrefix).append(CoordinateLsa::TYPE_STRING));
ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::COORDINATE)));
}
/* Tests that SyncLogicHandler's socket will be created when
Nlsr::initialize is called, preventing use of sync before the
socket is created.
NB: This test is as much an Nlsr class test as a SyncLogicHandler
class test, but it rides the line and ends up here.
NB: This test is as much an Nlsr class test as a
SyncLogicHandler class test, but it rides the line and ends up here.
*/
BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
{
nlsr.initialize();
// Make sure an adjacency LSA has not been built yet
ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
BOOST_REQUIRE(lsa == nullptr);
// Publish a routing update before an Adjacency LSA is built
BOOST_CHECK_NO_THROW(nlsr.getLsdb().getSyncLogicHandler()
.publishRoutingUpdate(AdjLsa::TYPE_STRING, 0));
.publishRoutingUpdate(Lsa::Type::ADJACENCY, 0));
}
BOOST_AUTO_TEST_SUITE_END()
+2 -2
View File
@@ -24,7 +24,7 @@
#include "../boost-test.hpp"
namespace nlsr {
namespace tlv {
namespace tlv {
namespace test {
BOOST_AUTO_TEST_SUITE(TlvTestLsaInfo)
@@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(LsaInfoOutputStream)
BOOST_AUTO_TEST_CASE(LsaInfoMake)
{
Lsa lsa("lsa-type");
Lsa lsa;
lsa.setOrigRouter("/test/lsa/info/tlv");
lsa.setLsSeqNo(128);
lsa.setExpirationTimePoint(ndn::time::system_clock::now());
@@ -75,7 +75,7 @@ public:
// no longer does face->put(*data) in publishData.
// Instead it does it in onInterest
ndn::Name lsaInterestName("/localhop/ndn/NLSR/LSA");
lsaInterestName.append(NameLsa::TYPE_STRING);
lsaInterestName.append(std::to_string(Lsa::Type::NAME));
// The part after LSA is Chronosync getSession
lsaInterestName.append(sessionTime);
@@ -163,7 +163,7 @@ public:
// no longer does face->put(*data) in publishData.
// Instead it does it in onInterest
ndn::Name lsaInterestName("/localhop/ndn/NLSR/LSA");
lsaInterestName.append(NameLsa::TYPE_STRING);
lsaInterestName.append(std::to_string(Lsa::Type::NAME));
// The part after LSA is Chronosync getSession
lsaInterestName.append(sessionTime);