lsa: change type variable to enum class
Change-Id: I7fba951649771700ce6ccc4be7fb400546607e96
refs: #4340
diff --git a/src/common.hpp b/src/common.hpp
index 93b3e87..3337520 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -56,8 +56,6 @@
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
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 95b656c..d87f4fc 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -118,20 +118,21 @@
// 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 @@
}
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 @@
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 @@
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
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index afa1464..3a074ef 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -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 @@
{
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 @@
* \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.
*
diff --git a/src/lsa.cpp b/src/lsa.cpp
index ec27a35..1b5e804 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -38,22 +38,17 @@
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 @@
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 @@
return false;
}
try {
- if (*tok_iter++ != NameLsa::TYPE_STRING) {
+ if (*tok_iter++ != std::to_string(Lsa::Type::NAME)) {
return false;
}
@@ -119,7 +114,7 @@
{
_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 @@
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 @@
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 @@
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 @@
}
try {
- if (*tok_iter++ != CoordinateLsa::TYPE_STRING) {
+ if (*tok_iter++ != std::to_string(Lsa::Type::COORDINATE)) {
return false;
}
@@ -223,7 +217,7 @@
{
_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 @@
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 @@
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 @@
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 @@
return false;
}
try {
- if (*tok_iter++ != AdjLsa::TYPE_STRING) {
+ if (*tok_iter++ != std::to_string(Lsa::Type::ADJACENCY)) {
return false;
}
@@ -351,7 +344,7 @@
{
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 @@
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
diff --git a/src/lsa.hpp b/src/lsa.hpp
index d27ddd6..dd69d8e 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -37,19 +37,25 @@
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 @@
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 @@
{
public:
NameLsa()
- : Lsa(NameLsa::TYPE_STRING)
- , m_npl()
{
}
@@ -121,6 +124,12 @@
const ndn::time::system_clock::TimePoint& lt,
NamePrefixList& npl);
+ Lsa::Type
+ getType() const override
+ {
+ return Lsa::Type::NAME;
+ }
+
NamePrefixList&
getNpl()
{
@@ -180,8 +189,6 @@
private:
NamePrefixList m_npl;
-public:
- static const std::string TYPE_STRING;
};
class AdjLsa: public Lsa
@@ -190,8 +197,6 @@
typedef AdjacencyList::const_iterator const_iterator;
AdjLsa()
- : Lsa(AdjLsa::TYPE_STRING)
- , m_adl()
{
}
@@ -199,6 +204,12 @@
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 @@
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 @@
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 @@
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
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 480248e..2661813 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -66,7 +66,7 @@
: 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 @@
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 @@
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 @@
_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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
//-----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;
}
}
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 3a63e68..9fd76b7 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -51,10 +51,10 @@
}
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.
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 318ec64..c5f8e09 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -472,12 +472,12 @@
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);
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 0f31885..a414e8a 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -58,14 +58,14 @@
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();
diff --git a/tests/test-link-state-calculator.cpp b/tests/test-link-state-calculator.cpp
index 8aee304..d0605f3 100644
--- a/tests/test-link-state-calculator.cpp
+++ b/tests/test-link-state-calculator.cpp
@@ -175,7 +175,7 @@
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(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);
diff --git a/tests/test-lsa-rule.cpp b/tests/test-lsa-rule.cpp
index e7f6a69..0ec3ff5 100644
--- a/tests/test-lsa-rule.cpp
+++ b/tests/test-lsa-rule.cpp
@@ -171,7 +171,7 @@
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 @@
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());
diff --git a/tests/test-lsa.cpp b/tests/test-lsa.cpp
index 2750bb4..c7851f8 100644
--- a/tests/test-lsa.cpp
+++ b/tests/test-lsa.cpp
@@ -47,7 +47,7 @@
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 @@
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 @@
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"
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 866c91b..e04c74b 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -187,7 +187,7 @@
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 @@
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 @@
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 @@
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 @@
// 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
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index 48cd7bf..fe30864 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -68,13 +68,16 @@
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(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 @@
// 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 @@
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 @@
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_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 @@
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 @@
// 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 @@
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 @@
// 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 @@
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 @@
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(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(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;
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index bcfc29c..ad2f0d9 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -200,21 +200,25 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
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_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_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);
diff --git a/tests/test-sync-logic-handler.cpp b/tests/test-sync-logic-handler.cpp
index bb6a6db..e660a5d 100644
--- a/tests/test-sync-logic-handler.cpp
+++ b/tests/test-sync-logic-handler.cpp
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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(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 @@
});
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 @@
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()
diff --git a/tests/tlv/test-lsa-info.cpp b/tests/tlv/test-lsa-info.cpp
index 2997231..a179e2c 100644
--- a/tests/tlv/test-lsa-info.cpp
+++ b/tests/tlv/test-lsa-info.cpp
@@ -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(LsaInfoMake)
{
- Lsa lsa("lsa-type");
+ Lsa lsa;
lsa.setOrigRouter("/test/lsa/info/tlv");
lsa.setLsSeqNo(128);
lsa.setExpirationTimePoint(ndn::time::system_clock::now());
diff --git a/tests/update/test-nfd-rib-command-processor.cpp b/tests/update/test-nfd-rib-command-processor.cpp
index 20856fe..53c77a1 100644
--- a/tests/update/test-nfd-rib-command-processor.cpp
+++ b/tests/update/test-nfd-rib-command-processor.cpp
@@ -75,7 +75,7 @@
// 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);
diff --git a/tests/update/test-prefix-update-processor.cpp b/tests/update/test-prefix-update-processor.cpp
index 8fb4c27..62ec8f6 100644
--- a/tests/update/test-prefix-update-processor.cpp
+++ b/tests/update/test-prefix-update-processor.cpp
@@ -163,7 +163,7 @@
// 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);