src: configuration file parsing
used boost::property_tree::info_parser for parsing nlsr's configuration file and
changed configuration command style to info command style. Removed tokenizer from
nlsr
Refs: #1542
Change-Id: If017ddd7eef5caa59b33940bfc27a71aa4de266b
diff --git a/src/route/face-map.hpp b/src/route/face-map.hpp
new file mode 100644
index 0000000..d861339
--- /dev/null
+++ b/src/route/face-map.hpp
@@ -0,0 +1,115 @@
+#ifndef NLSR_FACE_MAP_HPP
+#define NLSR_FACE_MAP_HPP
+
+namespace nlsr {
+
+class FaceMapEntry {
+
+public:
+ FaceMapEntry(const std::string& faceUri, uint32_t faceId)
+ : m_faceUri(faceUri)
+ , m_faceId(faceId)
+ {
+ }
+
+ void
+ setFaceUri(const std::string& faceUri)
+ {
+ m_faceUri = faceUri;
+ }
+
+ const std::string&
+ getFaceUri() const
+ {
+ return m_faceUri;
+ }
+
+ void
+ setFaceId(uint32_t faceId)
+ {
+ m_faceId = faceId;
+ }
+
+ uint32_t
+ getFaceId() const
+ {
+ return m_faceId;
+ }
+
+ bool
+ compare(const FaceMapEntry& fme)
+ {
+ return m_faceUri == fme.getFaceUri();
+ }
+
+private:
+ std::string m_faceUri;
+ uint32_t m_faceId;
+};
+
+inline std::ostream&
+operator<<(std::ostream& os, const FaceMapEntry& fme)
+{
+ os << "Face Map Entry (FaceUri: " << fme.getFaceUri() << " Face Id: ";
+ os << fme.getFaceId() << ")" << std::endl;
+ return os;
+}
+
+class FaceMap {
+
+public:
+ FaceMap()
+ {
+ }
+
+ ~FaceMap()
+ {
+ }
+
+ inline void
+ update(const std::string& faceUri, uint32_t faceId)
+ {
+ FaceMapEntry fme(faceUri, faceId);
+ std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(),
+ bind(&FaceMapEntry::compare,
+ &fme, _1));
+ if (it == m_table.end()) {
+ m_table.push_back(fme);
+ }
+ else {
+ (*it).setFaceId(fme.getFaceId());
+ }
+ }
+
+ inline uint32_t
+ getFaceId(const std::string& faceUri)
+ {
+ FaceMapEntry fme(faceUri, 0);
+ std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(),
+ bind(&FaceMapEntry::compare,
+ &fme, _1));
+ if (it != m_table.end()) {
+ return (*it).getFaceId();
+ }
+ return 0;
+ }
+
+ inline void
+ print()
+ {
+ std::cout << "------- Face Map-----------" << std::endl;
+ for(std::list<FaceMapEntry>::iterator it = m_table.begin();
+ it != m_table.end(); ++it) {
+ std::cout << (*it);
+ }
+ }
+
+private:
+ std::list<FaceMapEntry> m_table;
+};
+
+} //namespace nlsr
+
+#endif //NLSR_FACE_MAP_HPP
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index 524b04c..ba3d77a 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -9,25 +9,20 @@
bool
FibEntry::isEqualNextHops(NexthopList& nhlOther)
{
- if (m_nexthopList.getSize() != nhlOther.getSize())
- {
+ if (m_nexthopList.getSize() != nhlOther.getSize()) {
return false;
}
- else
- {
+ else {
uint32_t nhCount = 0;
std::list<NextHop>::iterator it1, it2;
for (it1 = m_nexthopList.getNextHops().begin(),
it2 = nhlOther.getNextHops().begin() ;
- it1 != m_nexthopList.getNextHops().end() ; it1++, it2++)
- {
- if (it1->getConnectingFace() == it2->getConnectingFace())
- {
+ it1 != m_nexthopList.getNextHops().end() ; it1++, it2++) {
+ if (it1->getConnectingFaceUri() == it2->getConnectingFaceUri()) {
it1->setRouteCost(it2->getRouteCost());
nhCount++;
}
- else
- {
+ else {
break;
}
}
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index fc823c1..a68d4d6 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -1,8 +1,10 @@
#include <list>
#include <cmath>
+#include <ndn-cxx/common.hpp>
#include "nlsr.hpp"
#include "nexthop-list.hpp"
+#include "face-map.hpp"
#include "fib.hpp"
@@ -45,19 +47,16 @@
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&fibEntryNameCompare, _1, name));
- if (it != m_table.end())
- {
+ if (it != m_table.end()) {
std::cout << "Entry found with Seq Num: " << feSeqNum << std::endl;
- if (it->getSeqNo() == feSeqNum)
- {
+ if (it->getSeqNo() == feSeqNum) {
std::cout << "Refreshing the FIB entry" << std::endl;
for (std::list<NextHop>::iterator nhit =
(*it).getNexthopList().getNextHops().begin();
- nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
- {
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
// add entry to NDN-FIB
- registerPrefixInNfd(it->getName(), nhit->getConnectingFace(),
- std::ceil(nhit->getRouteCost()));
+ registerPrefix(it->getName(), nhit->getConnectingFaceUri(),
+ std::ceil(nhit->getRouteCost()), m_refreshTime);
}
// increase sequence number and schedule refresh again
it->setSeqNo(feSeqNum + 1);
@@ -74,23 +73,19 @@
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&fibEntryNameCompare, _1, name));
- if (it != m_table.end())
- {
+ if (it != m_table.end()) {
for (std::list<NextHop>::iterator nhit =
(*it).getNexthopList().getNextHops().begin();
- nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
- {
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
//remove entry from NDN-FIB
- if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName()))
- {
- unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) {
+ unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
}
else
{
- if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
- nhit->getConnectingFace())
- {
- unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() !=
+ nhit->getConnectingFaceUri()) {
+ unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
}
}
}
@@ -112,20 +107,17 @@
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&fibEntryNameCompare, _1, name));
- if (it == m_table.end())
- {
- if (nextHopList.getSize() > 0)
- {
+ if (it == m_table.end()) {
+ if (nextHopList.getSize() > 0) {
nextHopList.sort();
FibEntry newEntry(name);
std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
- for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
- {
+ for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
newEntry.getNexthopList().addNextHop((*nhit));
//Add entry to NDN-FIB
- registerPrefixInNfd(name, nhit->getConnectingFace(),
- std::ceil(nhit->getRouteCost()));
+ registerPrefix(name, nhit->getConnectingFaceUri(),
+ std::ceil(nhit->getRouteCost()), m_refreshTime);
}
newEntry.getNexthopList().sort();
newEntry.setTimeToRefresh(m_refreshTime);
@@ -134,30 +126,26 @@
m_table.push_back(newEntry);
}
}
- else
- {
+ else {
std::cout << "Old FIB Entry" << std::endl;
- if (nextHopList.getSize() > 0)
- {
+ if (nextHopList.getSize() > 0) {
nextHopList.sort();
- if (!it->isEqualNextHops(nextHopList))
- {
+ if (!it->isEqualNextHops(nextHopList)) {
std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
// Add first Entry to NDN-FIB
- registerPrefixInNfd(name, nhit->getConnectingFace(),
- std::ceil(nhit->getRouteCost()));
- removeHop(it->getNexthopList(), nhit->getConnectingFace(), name);
+ registerPrefix(name, nhit->getConnectingFaceUri(),
+ std::ceil(nhit->getRouteCost()), m_refreshTime);
+ removeHop(it->getNexthopList(), nhit->getConnectingFaceUri(), name);
it->getNexthopList().reset();
it->getNexthopList().addNextHop((*nhit));
++startFace;
++nhit;
- for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
- {
+ for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
it->getNexthopList().addNextHop((*nhit));
//Add Entry to NDN_FIB
- registerPrefixInNfd(name, nhit->getConnectingFace(),
- std::ceil(nhit->getRouteCost()));
+ registerPrefix(name, nhit->getConnectingFaceUri(),
+ std::ceil(nhit->getRouteCost()), m_refreshTime);
}
}
it->setTimeToRefresh(m_refreshTime);
@@ -168,8 +156,7 @@
(*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
it->getSeqNo(), m_refreshTime));
}
- else
- {
+ else {
remove(name);
}
}
@@ -181,33 +168,27 @@
Fib::clean()
{
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
- ++it)
- {
+ ++it) {
std::cout << "Cancellling Scheduled event" << std::endl;
std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() <<
std::endl;
cancelScheduledExpiringEvent((*it).getExpiringEventId());
for (std::list<NextHop>::iterator nhit =
(*it).getNexthopList().getNextHops().begin();
- nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
- {
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
//Remove entry from NDN-FIB
- if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName()))
- {
- unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) {
+ unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
}
- else
- {
- if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
- nhit->getConnectingFace())
- {
- unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ else {
+ if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() !=
+ nhit->getConnectingFaceUri()) {
+ unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
}
}
}
}
- if (m_table.size() > 0)
- {
+ if (m_table.size() > 0) {
m_table.clear();
}
}
@@ -217,37 +198,30 @@
uint32_t maxFacesPerPrefix)
{
int endFace = 0;
- if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix))
- {
+ if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) {
return nextHopList.getSize();
}
- else
- {
+ else {
return maxFacesPerPrefix;
}
return endFace;
}
void
-Fib::removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
const ndn::Name& name)
{
for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
- it != nl.getNextHops().end(); ++it)
- {
- if (it->getConnectingFace() != doNotRemoveHopFaceId)
- {
+ it != nl.getNextHops().end(); ++it) {
+ if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) {
//Remove FIB Entry from NDN-FIB
- if (!m_nlsr.getAdjacencyList().isNeighbor(name))
- {
- unregisterPrefixFromNfd(name, it->getConnectingFace());
+ if (!m_nlsr.getAdjacencyList().isNeighbor(name)) {
+ unregisterPrefix(name, it->getConnectingFaceUri());
}
- else
- {
- if (m_nlsr.getAdjacencyList().getAdjacent(name).getConnectingFace() !=
- it->getConnectingFace())
- {
- unregisterPrefixFromNfd(name, it->getConnectingFace());
+ else {
+ if (m_nlsr.getAdjacencyList().getAdjacent(name).getConnectingFaceUri() !=
+ it->getConnectingFaceUri()) {
+ unregisterPrefix(name, it->getConnectingFaceUri());
}
}
}
@@ -255,43 +229,88 @@
}
void
-Fib::registerPrefixInNfd(const ndn::Name& namePrefix, uint64_t faceId,
- uint64_t faceCost)
+Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
+ uint64_t faceCost, uint64_t timeout)
+{
+ ndn::nfd::ControlParameters faceParameters;
+ faceParameters
+ .setUri(faceUri);
+
+ m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
+ ndn::bind(&Fib::registerPrefixInNfd, this,_1,
+ namePrefix, faceCost, timeout),
+ ndn::bind(&Fib::onFailure, this, _1, _2,
+ "Failed in name registration"));
+
+}
+
+void
+Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
+ const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout)
{
ndn::nfd::ControlParameters controlParameters;
controlParameters
- .setName(namePrefix)
- .setCost(faceCost)
- .setFaceId(faceId)
- .setExpirationPeriod(ndn::time::milliseconds(m_refreshTime * 1000))
- .setOrigin(128);
+ .setName(namePrefix)
+ .setFaceId(faceCreateResult.getFaceId())
+ .setCost(faceCost)
+ .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
+ .setOrigin(128);
m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
- ndn::bind(&Fib::onSuccess, this, _1,
- "Successful in name registration"),
+ ndn::bind(&Fib::onRegistration, this, _1,
+ "Successful in name registration",
+ faceCreateResult.getUri()),
ndn::bind(&Fib::onFailure, this, _1, _2,
"Failed in name registration"));
}
void
-Fib::unregisterPrefixFromNfd(const ndn::Name& namePrefix, uint64_t faceId)
+Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
{
- ndn::nfd::ControlParameters controlParameters;
- controlParameters
- .setName(namePrefix)
- .setFaceId(faceId)
- .setOrigin(128);
- m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
+ uint32_t faceId = m_faceMap.getFaceId(faceUri);
+ if (faceId > 0) {
+ ndn::nfd::ControlParameters controlParameters;
+ controlParameters
+ .setName(namePrefix)
+ .setFaceId(faceId)
+ .setOrigin(128);
+ m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
ndn::bind(&Fib::onSuccess, this, _1,
"Successful in unregistering name"),
ndn::bind(&Fib::onFailure, this, _1, _2,
"Failed in unregistering name"));
+ }
}
void
+Fib::setStrategy(const ndn::Name& name, const std::string& strategy)
+{
+ ndn::nfd::ControlParameters parameters;
+ parameters
+ .setName(name)
+ .setStrategy(strategy);
+
+ m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
+ bind(&Fib::onSuccess, this, _1,
+ "Successfully set strategy choice"),
+ bind(&Fib::onFailure, this, _1, _2,
+ "Failed to set strategy choice"));
+}
+
+void
+Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
+ const std::string& message, const std::string& faceUri)
+{
+ //std::cout << message << ": " << commandSuccessResult << std::endl;
+ m_faceMap.update(faceUri, commandSuccessResult.getFaceId());
+ m_faceMap.print();
+}
+
+
+void
Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message)
{
- std::cout << message << ": " << commandSuccessResult << std::endl;
+ //std::cout << message << ": " << commandSuccessResult << std::endl;
}
void
@@ -307,8 +326,7 @@
{
cout << "-------------------FIB-----------------------------" << endl;
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
- ++it)
- {
+ ++it) {
cout << (*it);
}
}
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 0f58351..559df7a 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -5,7 +5,7 @@
#include <boost/cstdint.hpp>
#include <ndn-cxx/management/nfd-controller.hpp>
-
+#include "face-map.hpp"
#include "fib-entry.hpp"
namespace nlsr {
@@ -21,6 +21,7 @@
, m_table()
, m_refreshTime(0)
, m_controller(face)
+ , m_faceMap()
{
}
~Fib()
@@ -47,7 +48,7 @@
private:
void
- removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+ removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
const ndn::Name& name);
int
@@ -63,12 +64,25 @@
void
refreshEntry(const ndn::Name& name, int32_t feSeqNum);
+public:
void
- registerPrefixInNfd(const ndn::Name& namePrefix, uint64_t faceId,
- uint64_t faceCost);
+ registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
+ uint64_t faceCost, uint64_t timeout);
void
- unregisterPrefixFromNfd(const ndn::Name& namePrefix, uint64_t faceId);
+ registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
+ const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
+
+ void
+ setStrategy(const ndn::Name& name, const std::string& strategy);
+
+private:
+ void
+ unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
+
+ void
+ onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
+ const std::string& message, const std::string& faceUri);
void
onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
@@ -82,6 +96,7 @@
std::list<FibEntry> m_table;
int32_t m_refreshTime;
ndn::nfd::Controller m_controller;
+ FaceMap m_faceMap;
};
}//namespace nlsr
diff --git a/src/route/map.cpp b/src/route/map.cpp
index 07310e7..8dca590 100644
--- a/src/route/map.cpp
+++ b/src/route/map.cpp
@@ -27,8 +27,7 @@
Map::addEntry(const ndn::Name& rtrName)
{
MapEntry me(rtrName, m_mappingIndex);
- if (addEntry(me))
- {
+ if (addEntry(me)) {
m_mappingIndex++;
}
}
@@ -39,9 +38,9 @@
//cout << mpe;
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
- bind(&mapEntryCompareByRouter, _1, mpe.getRouter()));
- if (it == m_table.end())
- {
+ ndn::bind(&mapEntryCompareByRouter,
+ _1, mpe.getRouter()));
+ if (it == m_table.end()) {
m_table.push_back(mpe);
return true;
}
@@ -53,10 +52,9 @@
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
- bind(&mapEntryCompareByMappingNo,
- _1, mn));
- if (it != m_table.end())
- {
+ ndn::bind(&mapEntryCompareByMappingNo,
+ _1, mn));
+ if (it != m_table.end()) {
return (*it).getRouter();
}
return ndn::Name();
@@ -67,10 +65,9 @@
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
- bind(&mapEntryCompareByRouter,
- _1, rName));
- if (it != m_table.end())
- {
+ ndn::bind(&mapEntryCompareByRouter,
+ _1, rName));
+ if (it != m_table.end()) {
return (*it).getMappingNumber();
}
return -1;
@@ -81,15 +78,11 @@
{
std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
- it != adjLsdb.end() ; it++)
- {
- //ndn::Name& linkStartRouter = (*it).getOrigRouter();
+ it != adjLsdb.end() ; it++) {
addEntry((*it).getOrigRouter());
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
for (std::list<Adjacent>::iterator itAdl = adl.begin();
- itAdl != adl.end() ; itAdl++)
- {
- //ndn::Name& linkEndRouter = (*itAdl).getName();
+ itAdl != adl.end() ; itAdl++) {
addEntry((*itAdl).getName());
}
}
@@ -107,8 +100,7 @@
{
os << "---------------Map----------------------" << endl;
std::list<MapEntry> ml = map.getMapList();
- for (std::list<MapEntry>::iterator it = ml.begin(); it != ml.end() ; it++)
- {
+ for (std::list<MapEntry>::iterator it = ml.begin(); it != ml.end() ; it++) {
os << (*it);
}
return os;
diff --git a/src/route/name-prefix-table-entry.cpp b/src/route/name-prefix-table-entry.cpp
index 0ca9bcb..cb7b869 100644
--- a/src/route/name-prefix-table-entry.cpp
+++ b/src/route/name-prefix-table-entry.cpp
@@ -59,8 +59,7 @@
(*it).getNexthopList().reset(); // reseting existing routing table's next hop
for (std::list<NextHop>::iterator nhit =
rte.getNexthopList().getNextHops().begin();
- nhit != rte.getNexthopList().getNextHops().end(); ++nhit)
- {
+ nhit != rte.getNexthopList().getNextHops().end(); ++nhit) {
(*it).getNexthopList().addNextHop((*nhit));
}
}
@@ -73,8 +72,7 @@
os << "Name: " << npte.getNamePrefix() << endl;
std::list<RoutingTableEntry> rteList = npte.getRteList();
for (std::list<RoutingTableEntry>::iterator it = rteList.begin();
- it != rteList.end(); ++it)
- {
+ it != rteList.end(); ++it) {
cout << (*it);
}
os << npte.getNexthopList();
diff --git a/src/route/name-prefix-table-entry.hpp b/src/route/name-prefix-table-entry.hpp
index ab507d7..13a31ea 100644
--- a/src/route/name-prefix-table-entry.hpp
+++ b/src/route/name-prefix-table-entry.hpp
@@ -37,11 +37,9 @@
void
resetRteListNextHop()
{
- if (m_rteList.size() > 0)
- {
+ if (m_rteList.size() > 0) {
for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
- it != m_rteList.end(); ++it)
- {
+ it != m_rteList.end(); ++it) {
(*it).getNexthopList().reset();
}
}
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index f791d0a..61b2722 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.cpp
@@ -25,30 +25,26 @@
NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
- m_table.end(), bind(&npteCompare, _1, name));
- if (it == m_table.end())
- {
+ m_table.end(),
+ ndn::bind(&npteCompare, _1, name));
+ if (it == m_table.end()) {
NamePrefixTableEntry newEntry(name);
newEntry.addRoutingTableEntry(rte);
newEntry.generateNhlfromRteList();
newEntry.getNexthopList().sort();
m_table.push_back(newEntry);
- if (rte.getNexthopList().getSize() > 0)
- {
+ if (rte.getNexthopList().getSize() > 0) {
m_nlsr.getFib().update(name, newEntry.getNexthopList());
}
}
- else
- {
- if (rte.getNexthopList().getSize() > 0)
- {
+ else {
+ if (rte.getNexthopList().getSize() > 0) {
(*it).addRoutingTableEntry(rte);
(*it).generateNhlfromRteList();
(*it).getNexthopList().sort();
m_nlsr.getFib().update(name, (*it).getNexthopList());
}
- else
- {
+ else {
(*it).resetRteListNextHop();
(*it).getNexthopList().reset();
m_nlsr.getFib().remove(name);
@@ -60,9 +56,9 @@
NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
- m_table.end(), bind(&npteCompare, _1, name));
- if (it != m_table.end())
- {
+ m_table.end(),
+ ndn::bind(&npteCompare, _1, name));
+ if (it != m_table.end()) {
ndn::Name destRouter = rte.getDestination();
(*it).removeRoutingTableEntry(rte);
if (((*it).getRteListSize() == 0) &&
@@ -71,13 +67,11 @@
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/adjacency"),
std::string("adjacency"))) &&
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/coordinate"),
- std::string("coordinate"))))
- {
+ std::string("coordinate")))) {
m_table.erase(it);
m_nlsr.getFib().remove(name);
}
- else
- {
+ else {
(*it).generateNhlfromRteList();
m_nlsr.getFib().update(name, (*it).getNexthopList());
}
@@ -91,12 +85,10 @@
//
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
- if (rteCheck != 0)
- {
+ if (rteCheck != 0) {
addEntry(name, *(rteCheck));
}
- else
- {
+ else {
RoutingTableEntry rte(destRouter);
addEntry(name, rte);
}
@@ -108,12 +100,10 @@
//
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
- if (rteCheck != 0)
- {
+ if (rteCheck != 0) {
removeEntry(name, *(rteCheck));
}
- else
- {
+ else {
RoutingTableEntry rte(destRouter);
removeEntry(name, rte);
}
@@ -123,20 +113,16 @@
NamePrefixTable::updateWithNewRoute()
{
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
- it != m_table.end(); ++it)
- {
+ it != m_table.end(); ++it) {
std::list<RoutingTableEntry> rteList = (*it).getRteList();
for (std::list<RoutingTableEntry>::iterator rteit = rteList.begin();
- rteit != rteList.end(); ++rteit)
- {
+ rteit != rteList.end(); ++rteit) {
RoutingTableEntry* rteCheck =
m_nlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
- if (rteCheck != 0)
- {
+ if (rteCheck != 0) {
addEntry((*it).getNamePrefix(), *(rteCheck));
}
- else
- {
+ else {
RoutingTableEntry rte((*rteit).getDestination());
addEntry((*it).getNamePrefix(), rte);
}
@@ -150,8 +136,7 @@
std::cout << "----------------NPT----------------------" << std::endl;
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
it != m_table.end();
- ++it)
- {
+ ++it) {
cout << (*it) << endl;
}
}
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 5468b40..12536f1 100644
--- a/src/route/nexthop-list.cpp
+++ b/src/route/nexthop-list.cpp
@@ -9,13 +9,13 @@
static bool
nexthopCompare(NextHop& nh1, NextHop& nh2)
{
- return nh1.getConnectingFace() == nh2.getConnectingFace();
+ return nh1.getConnectingFaceUri() == nh2.getConnectingFaceUri();
}
static bool
nexthopRemoveCompare(NextHop& nh1, NextHop& nh2)
{
- return (nh1.getConnectingFace() == nh2.getConnectingFace() &&
+ return (nh1.getConnectingFaceUri() == nh2.getConnectingFaceUri() &&
nh1.getRouteCost() == nh2.getRouteCost()) ;
}
@@ -38,13 +38,11 @@
{
std::list<NextHop>::iterator it = std::find_if(m_nexthopList.begin(),
m_nexthopList.end(),
- bind(&nexthopCompare, _1, nh));
- if (it == m_nexthopList.end())
- {
+ ndn::bind(&nexthopCompare, _1, nh));
+ if (it == m_nexthopList.end()) {
m_nexthopList.push_back(nh);
}
- if ((*it).getRouteCost() > nh.getRouteCost())
- {
+ if ((*it).getRouteCost() > nh.getRouteCost()) {
(*it).setRouteCost(nh.getRouteCost());
}
}
@@ -59,9 +57,8 @@
{
std::list<NextHop>::iterator it = std::find_if(m_nexthopList.begin(),
m_nexthopList.end(),
- bind(&nexthopRemoveCompare, _1, nh));
- if (it != m_nexthopList.end())
- {
+ ndn::bind(&nexthopRemoveCompare, _1, nh));
+ if (it != m_nexthopList.end()) {
m_nexthopList.erase(it);
}
}
@@ -78,8 +75,7 @@
std::list<NextHop> nexthopList = nhl.getNextHops();
int i = 1;
for (std::list<NextHop>::iterator it = nexthopList.begin();
- it != nexthopList.end() ; it++, i++)
- {
+ it != nexthopList.end() ; it++, i++) {
os << "Nexthop " << i << ": " << (*it) << endl;
}
return os;
diff --git a/src/route/nexthop.cpp b/src/route/nexthop.cpp
deleted file mode 100644
index 0a375b0..0000000
--- a/src/route/nexthop.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "nexthop.hpp"
-
-namespace nlsr {
-
-std::ostream&
-operator<<(std::ostream& os, NextHop& nh)
-{
- os << "Face: " << nh.getConnectingFace() << " Route Cost: " <<
- nh.getRouteCost();
- return os;
-}
-
-}//namespace nlsr
diff --git a/src/route/nexthop.hpp b/src/route/nexthop.hpp
index ed8d319..73ee473 100644
--- a/src/route/nexthop.hpp
+++ b/src/route/nexthop.hpp
@@ -9,27 +9,27 @@
{
public:
NextHop()
- : m_connectingFace(0)
+ : m_connectingFaceUri()
, m_routeCost(0)
{
}
- NextHop(uint32_t cf, double rc)
+ NextHop(const std::string& cfu, double rc)
{
- m_connectingFace = cf;
+ m_connectingFaceUri = cfu;
m_routeCost = rc;
}
- uint32_t
- getConnectingFace() const
+ const std::string&
+ getConnectingFaceUri() const
{
- return m_connectingFace;
+ return m_connectingFaceUri;
}
void
- setConnectingFace(uint32_t cf)
+ setConnectingFaceUri(const std::string& cfu)
{
- m_connectingFace = cf;
+ m_connectingFaceUri = cfu;
}
double
@@ -45,13 +45,18 @@
}
private:
- uint32_t m_connectingFace;
+ std::string m_connectingFaceUri;
double m_routeCost;
};
-std::ostream&
-operator<<(std::ostream& os, NextHop& nh);
+inline std::ostream&
+operator<<(std::ostream& os, const NextHop& nh)
+{
+ os << "Face: " << nh.getConnectingFaceUri() << " Route Cost: " <<
+ nh.getRouteCost();
+ return os;
+}
}//namespace nlsr
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 33a703d..7eab0eb 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -15,8 +15,7 @@
RoutingTableCalculator::allocateAdjMatrix()
{
adjMatrix = new double*[numOfRouter];
- for (int i = 0; i < numOfRouter; ++i)
- {
+ for (int i = 0; i < numOfRouter; ++i) {
adjMatrix[i] = new double[numOfRouter];
}
}
@@ -24,10 +23,10 @@
void
RoutingTableCalculator::initMatrix()
{
- for (int i = 0; i < numOfRouter; i++)
- {
- for (int j = 0; j < numOfRouter; j++)
+ for (int i = 0; i < numOfRouter; i++) {
+ for (int j = 0; j < numOfRouter; j++) {
adjMatrix[i][j] = 0;
+ }
}
}
@@ -36,17 +35,14 @@
{
std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
- it != adjLsdb.end() ; it++)
- {
+ it != adjLsdb.end() ; it++) {
int row = pMap.getMappingNoByRouterName((*it).getOrigRouter());
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
for (std::list<Adjacent>::iterator itAdl = adl.begin();
- itAdl != adl.end() ; itAdl++)
- {
+ itAdl != adl.end() ; itAdl++) {
int col = pMap.getMappingNoByRouterName((*itAdl).getName());
double cost = (*itAdl).getLinkCost();
- if ((row >= 0 && row < numOfRouter) && (col >= 0 && col < numOfRouter))
- {
+ if ((row >= 0 && row < numOfRouter) && (col >= 0 && col < numOfRouter)) {
adjMatrix[row][col] = cost;
}
}
@@ -56,10 +52,10 @@
void
RoutingTableCalculator::printAdjMatrix()
{
- for (int i = 0; i < numOfRouter; i++)
- {
- for (int j = 0; j < numOfRouter; j++)
+ for (int i = 0; i < numOfRouter; i++) {
+ for (int j = 0; j < numOfRouter; j++) {
printf("%f ", adjMatrix[i][j]);
+ }
printf("\n");
}
}
@@ -67,14 +63,11 @@
void
RoutingTableCalculator::adjustAdMatrix(int source, int link, double linkCost)
{
- for (int i = 0; i < numOfRouter; i++)
- {
- if (i == link)
- {
+ for (int i = 0; i < numOfRouter; i++) {
+ if (i == link) {
adjMatrix[source][i] = linkCost;
}
- else
- {
+ else {
adjMatrix[source][i] = 0;
}
}
@@ -84,10 +77,8 @@
RoutingTableCalculator::getNumOfLinkfromAdjMatrix(int sRouter)
{
int noLink = 0;
- for (int i = 0; i < numOfRouter; i++)
- {
- if (adjMatrix[sRouter][i] > 0)
- {
+ for (int i = 0; i < numOfRouter; i++) {
+ if (adjMatrix[sRouter][i] > 0) {
noLink++;
}
}
@@ -99,10 +90,8 @@
double* linkCosts, int source)
{
int j = 0;
- for (int i = 0; i < numOfRouter; i++)
- {
- if (adjMatrix[source][i] > 0)
- {
+ for (int i = 0; i < numOfRouter; i++) {
+ if (adjMatrix[source][i] > 0) {
links[j] = i;
linkCosts[j] = adjMatrix[source][i];
j++;
@@ -113,8 +102,7 @@
void
RoutingTableCalculator::freeAdjMatrix()
{
- for (int i = 0; i < numOfRouter; ++i)
- {
+ for (int i = 0; i < numOfRouter; ++i) {
delete [] adjMatrix[i];
}
delete [] adjMatrix;
@@ -160,8 +148,7 @@
//int noLink=getNumOfLinkfromAdjMatrix(sourceRouter);
allocateParent();
allocateDistance();
- if (pnlsr.getConfParameter().getMaxFacesPerPrefix() == 1)
- {
+ if (pnlsr.getConfParameter().getMaxFacesPerPrefix() == 1) {
// Single Path
doDijkstraPathCalculation(sourceRouter);
// print all ls path -- debugging purpose
@@ -169,15 +156,13 @@
// update routing table
addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, sourceRouter);
}
- else
- {
+ else {
// Multi Path
setNoLink(getNumOfLinkfromAdjMatrix(sourceRouter));
allocateLinks();
allocateLinkCosts();
getLinksFromAdjMatrix(links, linkCosts, sourceRouter);
- for (int i = 0 ; i < vNoLink; i++)
- {
+ for (int i = 0 ; i < vNoLink; i++) {
adjustAdMatrix(sourceRouter, links[i], linkCosts[i]);
printAdjMatrix();
doDijkstraPathCalculation(sourceRouter);
@@ -202,31 +187,23 @@
int* Q = new int[numOfRouter];
int head = 0;
/* Initiate the Parent */
- for (i = 0 ; i < numOfRouter; i++)
- {
+ for (i = 0 ; i < numOfRouter; i++) {
m_parent[i] = EMPTY_PARENT;
m_distance[i] = INF_DISTANCE;
Q[i] = i;
}
- if (sourceRouter != NO_MAPPING_NUM)
- {
+ if (sourceRouter != NO_MAPPING_NUM) {
m_distance[sourceRouter] = 0;
sortQueueByDistance(Q, m_distance, head, numOfRouter);
- while (head < numOfRouter)
- {
+ while (head < numOfRouter) {
u = Q[head];
- if (m_distance[u] == INF_DISTANCE)
- {
+ if (m_distance[u] == INF_DISTANCE) {
break;
}
- for (v = 0 ; v < numOfRouter; v++)
- {
- if (adjMatrix[u][v] > 0)
- {
- if (isNotExplored(Q, v, head + 1, numOfRouter))
- {
- if (m_distance[u] + adjMatrix[u][v] < m_distance[v])
- {
+ for (v = 0 ; v < numOfRouter; v++) {
+ if (adjMatrix[u][v] > 0) {
+ if (isNotExplored(Q, v, head + 1, numOfRouter)) {
+ if (m_distance[u] + adjMatrix[u][v] < m_distance[v]) {
m_distance[v] = m_distance[u] + adjMatrix[u][v] ;
m_parent[v] = u;
}
@@ -248,24 +225,21 @@
"LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called";
std::cout << std::endl;
int nextHopRouter = 0;
- for (int i = 0; i < numOfRouter ; i++)
- {
- if (i != sourceRouter)
- {
+ for (int i = 0; i < numOfRouter ; i++) {
+ if (i != sourceRouter) {
nextHopRouter = getLsNextHop(i, sourceRouter);
- if (nextHopRouter != NO_NEXT_HOP)
- {
+ if (nextHopRouter != NO_NEXT_HOP) {
double routeCost = m_distance[i];
ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(nextHopRouter);
- int nxtHopFace =
- pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFace();
+ std::string nextHopFace =
+ pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFaceUri();
std::cout << "Dest Router: " << pMap.getRouterNameByMappingNo(i) << std::endl;
std::cout << "Next hop Router: " << nextHopRouterName << std::endl;
- std::cout << "Next hop Face: " << nxtHopFace << std::endl;
+ std::cout << "Next hop Face: " << nextHopFace << std::endl;
std::cout << "Route Cost: " << routeCost << std::endl;
std::cout << std::endl;
// Add next hop to routing table
- NextHop nh(nxtHopFace, routeCost);
+ NextHop nh(nextHopFace, routeCost);
rt.addNextHop(pMap.getRouterNameByMappingNo(i), nh);
}
}
@@ -276,13 +250,11 @@
LinkStateRoutingTableCalculator::getLsNextHop(int dest, int source)
{
int nextHop = NO_NEXT_HOP;
- while (m_parent[dest] != EMPTY_PARENT)
- {
+ while (m_parent[dest] != EMPTY_PARENT) {
nextHop = dest;
dest = m_parent[dest];
}
- if (dest != source)
- {
+ if (dest != source) {
nextHop = NO_NEXT_HOP;
}
return nextHop;
@@ -294,10 +266,8 @@
std::cout << "LinkStateRoutingTableCalculator::printAllLsPath Called" <<
std::endl;
std::cout << "Source Router: " << sourceRouter << std::endl;
- for (int i = 0; i < numOfRouter ; i++)
- {
- if (i != sourceRouter)
- {
+ for (int i = 0; i < numOfRouter ; i++) {
+ if (i != sourceRouter) {
printLsPath(i);
std::cout << std::endl;
}
@@ -307,8 +277,7 @@
void
LinkStateRoutingTableCalculator::printLsPath(int destRouter)
{
- if (m_parent[destRouter] != EMPTY_PARENT)
- {
+ if (m_parent[destRouter] != EMPTY_PARENT) {
printLsPath(m_parent[destRouter]);
}
std:: cout << " " << destRouter;
@@ -318,12 +287,9 @@
LinkStateRoutingTableCalculator::sortQueueByDistance(int* Q,
double* dist, int start, int element)
{
- for (int i = start ; i < element ; i++)
- {
- for (int j = i + 1; j < element; j++)
- {
- if (dist[Q[j]] < dist[Q[i]])
- {
+ for (int i = start ; i < element ; i++) {
+ for (int j = i + 1; j < element; j++) {
+ if (dist[Q[j]] < dist[Q[i]]) {
int tempU = Q[j];
Q[j] = Q[i];
Q[i] = tempU;
@@ -337,10 +303,8 @@
int u, int start, int element)
{
int ret = 0;
- for (int i = start; i < element; i++)
- {
- if (Q[i] == u)
- {
+ for (int i = start; i < element; i++) {
+ if (Q[i] == u) {
ret = 1;
break;
}
@@ -385,26 +349,22 @@
allocateLinks();
allocateLinkCosts();
getLinksFromAdjMatrix(links, linkCosts, sourceRouter);
- for (int i = 0 ; i < numOfRouter ; ++i)
- {
+ for (int i = 0 ; i < numOfRouter ; ++i) {
int k = 0;
- if (i != sourceRouter)
- {
+ if (i != sourceRouter) {
allocateLinkFaces();
allocateDistanceToNeighbor();
allocateDistFromNbrToDest();
- for (int j = 0; j < vNoLink; j++)
- {
+ for (int j = 0; j < vNoLink; j++) {
ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(links[j]);
- int nextHopFace =
- pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFace();
+ std::string nextHopFaceUri =
+ pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFaceUri();
double distToNbr = getHyperbolicDistance(pnlsr, pMap,
sourceRouter, links[j]);
double distToDestFromNbr = getHyperbolicDistance(pnlsr,
pMap, links[j], i);
- if (distToDestFromNbr >= 0)
- {
- m_linkFaces[k] = nextHopFace;
+ if (distToDestFromNbr >= 0) {
+ m_linkFaceUris[k] = nextHopFaceUri;
m_distanceToNeighbor[k] = distToNbr;
m_distFromNbrToDest[k] = distToDestFromNbr;
k++;
@@ -425,13 +385,11 @@
HypRoutingTableCalculator::addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap,
RoutingTable& rt, int noFaces, int dest)
{
- for (int i = 0 ; i < noFaces ; ++i)
- {
+ for (int i = 0 ; i < noFaces ; ++i) {
ndn::Name destRouter = pMap.getRouterNameByMappingNo(dest);
- NextHop nh(m_linkFaces[i], m_distFromNbrToDest[i]);
+ NextHop nh(m_linkFaceUris[i], m_distFromNbrToDest[i]);
rt.addNextHop(destRouter, nh);
- if (m_isDryRun)
- {
+ if (m_isDryRun) {
rt.addNextHopToDryTable(destRouter, nh);
}
}
@@ -455,20 +413,19 @@
double destTheta = (pnlsr.getLsdb().findCoordinateLsa(
destRouterKey))->getCorTheta();
double diffTheta = fabs(srcTheta - destTheta);
- if (diffTheta > MATH_PI)
- {
+ if (diffTheta > MATH_PI) {
diffTheta = 2 * MATH_PI - diffTheta;
}
- if (srcRadius != -1 && destRadius != -1)
- {
- if (diffTheta == 0)
+ if (srcRadius != -1 && destRadius != -1) {
+ if (diffTheta == 0) {
distance = fabs(srcRadius - destRadius);
- else
+ }
+ else {
distance = acosh((cosh(srcRadius) * cosh(destRadius)) -
(sinh(srcRadius) * sinh(destRadius) * cos(diffTheta)));
+ }
}
- else
- {
+ else {
distance = -1;
}
return distance;
@@ -477,7 +434,7 @@
void
HypRoutingTableCalculator::allocateLinkFaces()
{
- m_linkFaces = new int[vNoLink];
+ m_linkFaceUris.reserve(vNoLink);
}
void
@@ -495,7 +452,7 @@
void
HypRoutingTableCalculator::freeLinkFaces()
{
- delete [] m_linkFaces;
+ m_linkFaceUris.clear();
}
void
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index 544896c..b7df54b 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -189,7 +189,7 @@
private:
bool m_isDryRun;
- int* m_linkFaces;
+ std::vector<std::string> m_linkFaceUris;
double* m_distanceToNeighbor;
double* m_distFromNbrToDest;
diff --git a/src/route/routing-table-entry.hpp b/src/route/routing-table-entry.hpp
index fbba243..ce26f59 100644
--- a/src/route/routing-table-entry.hpp
+++ b/src/route/routing-table-entry.hpp
@@ -48,8 +48,7 @@
int32_t i = 1;
std::list<NextHop> nhl = rte.getNexthopList().getNextHops();
for (std::list<NextHop>::iterator it = nhl.begin();
- it != nhl.end() ; it++, i++)
- {
+ it != nhl.end() ; it++, i++) {
os << " Nexthop " << i << ": " << (*it) << std::endl;
}
return os;
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 7664b89..bcfb61c 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -5,6 +5,7 @@
#include "routing-table.hpp"
#include "nlsr.hpp"
#include "map.hpp"
+#include "conf-parameter.hpp"
#include "routing-table-calculator.hpp"
#include "routing-table-entry.hpp"
#include "name-prefix-table.hpp"
@@ -21,32 +22,28 @@
pnlsr.getLsdb().printAdjLsdb();
pnlsr.getLsdb().printCorLsdb();
pnlsr.getLsdb().printNameLsdb();
- if (pnlsr.getIsRoutingTableCalculating() == 0)
- {
- pnlsr.setIsRoutingTableCalculating(1); //setting routing table calculation
+ if (pnlsr.getIsRoutingTableCalculating() == false) {
+ //setting routing table calculation
+ pnlsr.setIsRoutingTableCalculating(true);
if (pnlsr.getLsdb().doesLsaExist(
pnlsr.getConfParameter().getRouterPrefix().toUri() + "/" + "adjacency",
- std::string("adjacency")))
- {
- if (pnlsr.getIsBuildAdjLsaSheduled() != 1)
- {
+ std::string("adjacency"))) {
+ if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
std::cout << "CLearing old routing table ....." << std::endl;
clearRoutingTable();
- clearDryRoutingTable(); // for dry run options
+ // for dry run options
+ clearDryRoutingTable();
// calculate Link State routing
- if ((pnlsr.getConfParameter().getIsHyperbolicCalc() == 0)
- || (pnlsr.getConfParameter().getIsHyperbolicCalc() == 2))
- {
+ if ((pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF)
+ || (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
calculateLsRoutingTable(pnlsr);
}
//calculate hyperbolic routing
- if (pnlsr.getConfParameter().getIsHyperbolicCalc() == 1)
- {
+ if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
calculateHypRoutingTable(pnlsr);
}
//calculate dry hyperbolic routing
- if (pnlsr.getConfParameter().getIsHyperbolicCalc() == 2)
- {
+ if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
calculateHypDryRoutingTable(pnlsr);
}
//need to update NPT here
@@ -57,14 +54,12 @@
pnlsr.getFib().print();
//debugging purpose end
}
- else
- {
+ else {
std::cout << "Adjacency building is scheduled, so ";
std::cout << "routing table can not be calculated :(" << std::endl;
}
}
- else
- {
+ else {
std::cout << "No Adj LSA of router itself,";
std::cout << " so Routing table can not be calculated :(" << std::endl;
clearRoutingTable();
@@ -78,11 +73,10 @@
pnlsr.getFib().print();
//debugging purpose end
}
- pnlsr.setIsRouteCalculationScheduled(0); //clear scheduled flag
- pnlsr.setIsRoutingTableCalculating(0); //unsetting routing table calculation
+ pnlsr.setIsRouteCalculationScheduled(false); //clear scheduled flag
+ pnlsr.setIsRoutingTableCalculating(false); //unsetting routing table calculation
}
- else
- {
+ else {
scheduleRoutingTableCalculation(pnlsr);
}
}
@@ -96,7 +90,7 @@
vMap.createFromAdjLsdb(pnlsr);
int numOfRouter = vMap.getMapSize();
LinkStateRoutingTableCalculator lsrtc(numOfRouter);
- lsrtc.calculatePath(vMap, boost::ref(*this), pnlsr);
+ lsrtc.calculatePath(vMap, ndn::ref(*this), pnlsr);
}
void
@@ -106,7 +100,7 @@
vMap.createFromAdjLsdb(pnlsr);
int numOfRouter = vMap.getMapSize();
HypRoutingTableCalculator hrtc(numOfRouter, 0);
- hrtc.calculatePath(vMap, boost::ref(*this), pnlsr);
+ hrtc.calculatePath(vMap, ndn::ref(*this), pnlsr);
}
void
@@ -116,17 +110,17 @@
vMap.createFromAdjLsdb(pnlsr);
int numOfRouter = vMap.getMapSize();
HypRoutingTableCalculator hrtc(numOfRouter, 1);
- hrtc.calculatePath(vMap, boost::ref(*this), pnlsr);
+ hrtc.calculatePath(vMap, ndn::ref(*this), pnlsr);
}
void
RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
{
- if (pnlsr.getIsRouteCalculationScheduled() != 1)
- {
+ if (pnlsr.getIsRouteCalculationScheduled() != true) {
pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate, this, boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
+ ndn::bind(&RoutingTable::calculate, this,
+ ndn::ref(pnlsr)));
+ pnlsr.setIsRouteCalculationScheduled(true);
}
}
@@ -141,14 +135,12 @@
RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh)
{
RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter);
- if (rteChk == 0)
- {
+ if (rteChk == 0) {
RoutingTableEntry rte(destRouter);
rte.getNexthopList().addNextHop(nh);
m_rTable.push_back(rte);
}
- else
- {
+ else {
rteChk->getNexthopList().addNextHop(nh);
}
}
@@ -158,9 +150,9 @@
{
std::list<RoutingTableEntry>::iterator it = std::find_if(m_rTable.begin(),
m_rTable.end(),
- bind(&routingTableEntryCompare, _1, destRouter));
- if (it != m_rTable.end())
- {
+ ndn::bind(&routingTableEntryCompare,
+ _1, destRouter));
+ if (it != m_rTable.end()) {
return &(*it);
}
return 0;
@@ -171,8 +163,7 @@
{
std::cout << "---------------Routing Table------------------" << std::endl;
for (std::list<RoutingTableEntry>::iterator it = m_rTable.begin() ;
- it != m_rTable.end(); ++it)
- {
+ it != m_rTable.end(); ++it) {
std::cout << (*it) << std::endl;
}
}
@@ -184,15 +175,14 @@
{
std::list<RoutingTableEntry>::iterator it = std::find_if(m_dryTable.begin(),
m_dryTable.end(),
- bind(&routingTableEntryCompare, _1, destRouter));
- if (it == m_dryTable.end())
- {
+ ndn::bind(&routingTableEntryCompare,
+ _1, destRouter));
+ if (it == m_dryTable.end()) {
RoutingTableEntry rte(destRouter);
rte.getNexthopList().addNextHop(nh);
m_dryTable.push_back(rte);
}
- else
- {
+ else {
(*it).getNexthopList().addNextHop(nh);
}
}
@@ -202,8 +192,7 @@
{
std::cout << "--------Dry Run's Routing Table--------------" << std::endl;
for (std::list<RoutingTableEntry>::iterator it = m_dryTable.begin() ;
- it != m_dryTable.end(); ++it)
- {
+ it != m_dryTable.end(); ++it) {
cout << (*it) << endl;
}
}
@@ -212,8 +201,7 @@
void
RoutingTable::clearRoutingTable()
{
- if (m_rTable.size() > 0)
- {
+ if (m_rTable.size() > 0) {
m_rTable.clear();
}
}
@@ -221,8 +209,7 @@
void
RoutingTable::clearDryRoutingTable()
{
- if (m_dryTable.size() > 0)
- {
+ if (m_dryTable.size() > 0) {
m_dryTable.clear();
}
}