src: Renaming class to spell out them (Adl, Nhl, Npl, Npt, Npte)
Refs: #1534
Change-Id: If4a205e8ad2419505cc796027a5c863471ef5439
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index 05bee41..524b04c 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -9,17 +9,17 @@
bool
FibEntry::isEqualNextHops(NexthopList& nhlOther)
{
- if (m_nhl.getSize() != nhlOther.getSize())
+ if (m_nexthopList.getSize() != nhlOther.getSize())
{
return false;
}
else
{
- int nhCount = 0;
+ uint32_t nhCount = 0;
std::list<NextHop>::iterator it1, it2;
- for (it1 = m_nhl.getNextHopList().begin(),
- it2 = nhlOther.getNextHopList().begin() ;
- it1 != m_nhl.getNextHopList().end() ; it1++, it2++)
+ for (it1 = m_nexthopList.getNextHops().begin(),
+ it2 = nhlOther.getNextHops().begin() ;
+ it1 != m_nexthopList.getNextHops().end() ; it1++, it2++)
{
if (it1->getConnectingFace() == it2->getConnectingFace())
{
@@ -31,7 +31,7 @@
break;
}
}
- return nhCount == m_nhl.getSize();
+ return nhCount == m_nexthopList.getSize();
}
}
@@ -40,7 +40,7 @@
{
os << "Name Prefix: " << fe.getName() << endl;
os << "Time to Refresh: " << fe.getTimeToRefresh() << endl;
- os << fe.getNhl() << endl;
+ os << fe.getNexthopList() << endl;
return os;
}
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index d320c9a..88de53e 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.hpp
@@ -1,8 +1,10 @@
-#ifndef NLSR_FE_HPP
-#define NLSR_FE_HPP
+#ifndef NLSR_FIB_ENTRY_HPP
+#define NLSR_FIB_ENTRY_HPP
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
+
#include <ndn-cxx/util/scheduler.hpp>
#include "nexthop.hpp"
@@ -10,8 +12,6 @@
namespace nlsr {
-using namespace std;
-
class FibEntry
{
public:
@@ -19,38 +19,38 @@
: m_name()
, m_timeToRefresh(0)
, m_seqNo(0)
- , m_nhl()
+ , m_nexthopList()
{
}
- FibEntry(string n)
+ FibEntry(const std::string& name)
: m_timeToRefresh(0)
, m_seqNo(0)
- , m_nhl()
+ , m_nexthopList()
{
- m_name = n;
+ m_name = name;
}
- std::string
+ const std::string&
getName() const
{
return m_name;
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
- int
+ int32_t
getTimeToRefresh() const
{
return m_timeToRefresh;
}
void
- setTimeToRefresh(int ttr)
+ setTimeToRefresh(int32_t ttr)
{
m_timeToRefresh = ttr;
}
@@ -68,12 +68,12 @@
}
void
- setSeqNo(int fsn)
+ setSeqNo(int32_t fsn)
{
m_seqNo = fsn;
}
- int
+ int32_t
getSeqNo()
{
return m_seqNo;
@@ -84,10 +84,10 @@
private:
std::string m_name;
- int m_timeToRefresh;
+ int32_t m_timeToRefresh;
ndn::EventId m_expiringEventId;
- int m_seqNo;
- NexthopList m_nhl;
+ int32_t m_seqNo;
+ NexthopList m_nexthopList;
};
std::ostream&
@@ -95,4 +95,4 @@
} //namespace nlsr
-#endif //NLSR_FE_HPP
+#endif //NLSR_FIB_ENTRY_HPP
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 1d7582b..1272ab1 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -1,9 +1,10 @@
#include <list>
+#include <cmath>
#include "nlsr.hpp"
-#include "fib-entry.hpp"
-#include "fib.hpp"
#include "nexthop-list.hpp"
+#include "fib.hpp"
+
@@ -13,9 +14,9 @@
using namespace ndn;
static bool
-fibEntryNameCompare(FibEntry& fe, string name)
+fibEntryNameCompare(const FibEntry& fibEntry, const string& name)
{
- return fe.getName() == name ;
+ return fibEntry.getName() == name ;
}
void
@@ -26,32 +27,78 @@
ndn::EventId
-Fib::scheduleEntryRefreshing(Nlsr& pnlsr, string name, int feSeqNum,
- int refreshTime)
+Fib::scheduleEntryRefreshing(Nlsr& pnlsr, const string& name, int32_t feSeqNum,
+ int32_t refreshTime)
{
+ std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl;
+ std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
- ndn::bind(&Fib::refreshEntry, this, name, feSeqNum));
+ ndn::bind(&Fib::refreshEntry, this,
+ boost::ref(pnlsr),
+ name, feSeqNum));
}
void
-Fib::refreshEntry(string name, int feSeqNum)
+Fib::refreshEntry(Nlsr& nlsr, const string& name, int32_t feSeqNum)
{
+ std::cout << "Fib::refreshEntry Called" << std::endl;
+ std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
+ std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(),
+ bind(&fibEntryNameCompare, _1, name));
+ if (it != m_table.end())
+ {
+ std::cout << "Entry found with Seq Num: " << feSeqNum << std::endl;
+ 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++)
+ {
+ // add entry to NDN-FIB
+ registerPrefixInNfd(it->getName(), nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
+ }
+
+ // increase sequence number and schedule refresh again
+ it->setSeqNo(feSeqNum + 1);
+ it->setExpiringEventId(scheduleEntryRefreshing(nlsr,
+ it->getName() ,
+ it->getSeqNo(),
+ m_refreshTime));
+
+ }
+ }
}
void
-Fib::remove(Nlsr& pnlsr, string name)
+Fib::remove(Nlsr& pnlsr, const std::string& name)
{
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
- m_table.end(),
+ m_table.end(),
bind(&fibEntryNameCompare, _1, name));
if (it != m_table.end())
{
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
{
//remove entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
+ nhit->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ }
}
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
m_table.erase(it);
}
@@ -59,7 +106,7 @@
void
-Fib::update(Nlsr& pnlsr, string name, NexthopList& nextHopList)
+Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
{
std::cout << "Fib::updateFib Called" << std::endl;
int startFace = 0;
@@ -74,14 +121,15 @@
{
nextHopList.sort();
FibEntry newEntry(name);
- std::list<NextHop> nhl = nextHopList.getNextHopList();
+ std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
{
- newEntry.getNhl().addNextHop((*nhit));
+ newEntry.getNexthopList().addNextHop((*nhit));
//Add entry to NDN-FIB
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
}
- newEntry.getNhl().sort();
+ newEntry.getNexthopList().sort();
newEntry.setTimeToRefresh(m_refreshTime);
newEntry.setSeqNo(1);
newEntry.setExpiringEventId(scheduleEntryRefreshing(pnlsr,
@@ -97,21 +145,25 @@
nextHopList.sort();
if (!it->isEqualNextHops(nextHopList))
{
- std::list<NextHop> nhl = nextHopList.getNextHopList();
+ std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
// Add first Entry to NDN-FIB
- removeHop(pnlsr, it->getNhl(), nhit->getConnectingFace());
- it->getNhl().reset();
- it->getNhl().addNextHop((*nhit));
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
+ removeHop(pnlsr, it->getNexthopList(), nhit->getConnectingFace(), name);
+ it->getNexthopList().reset();
+ it->getNexthopList().addNextHop((*nhit));
++startFace;
++nhit;
for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
{
- it->getNhl().addNextHop((*nhit));
+ it->getNexthopList().addNextHop((*nhit));
//Add Entry to NDN_FIB
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
}
}
it->setTimeToRefresh(m_refreshTime);
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
cancelScheduledExpiringEvent(pnlsr, it->getExpiringEventId());
it->setSeqNo(it->getSeqNo() + 1);
(*it).setExpiringEventId(scheduleEntryRefreshing(pnlsr,
@@ -133,12 +185,26 @@
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
++it)
{
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() << std::endl;
+ cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
{
- cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
//Remove entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
+ nhit->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ }
}
}
if (m_table.size() > 0)
@@ -148,7 +214,7 @@
}
int
-Fib::getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix)
+Fib::getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix)
{
int endFace = 0;
if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix))
@@ -163,19 +229,79 @@
}
void
-Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, int doNotRemoveHopFaceId)
+Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+ const std::string& name)
{
- for (std::list<NextHop>::iterator it = nl.getNextHopList().begin();
- it != nl.getNextHopList().end(); ++it)
+ for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
+ it != nl.getNextHops().end(); ++it)
{
if (it->getConnectingFace() != doNotRemoveHopFaceId)
{
//Remove FIB Entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(name))
+ {
+ unregisterPrefixFromNfd(name, it->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(name).getConnectingFace() !=
+ it->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(name, it->getConnectingFace());
+ }
+ }
}
}
}
void
+Fib::registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost)
+{
+ ndn::nfd::ControlParameters controlParameters;
+ controlParameters
+ .setName(namePrefix)
+ .setCost(faceCost)
+ .setFaceId(faceId)
+ .setExpirationPeriod(ndn::time::milliseconds(m_refreshTime*1000))
+ .setOrigin(128);
+
+ m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
+ ndn::bind(&Fib::onSuccess, this, _1,
+ "Successful in name registration"),
+ ndn::bind(&Fib::onFailure, this, _1, _2,
+ "Failed in name registration"));
+}
+
+void
+Fib::unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId)
+{
+ 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::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message)
+{
+ std::cout << message << ": " << commandSuccessResult << std::endl;
+}
+
+void
+Fib::onFailure(uint32_t code, const std::string& error, const std::string& message)
+{
+ std::cout << message << ": " << error << " (code: " << code << ")";
+}
+
+
+void
Fib::print()
{
cout << "-------------------FIB-----------------------------" << endl;
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 4a80c48..2a90fc1 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -2,35 +2,41 @@
#define NLSR_FIB_HPP
#include <list>
+#include <boost/cstdint.hpp>
+
+#include <ndn-cxx/management/nfd-controller.hpp>
+
#include "fib-entry.hpp"
namespace nlsr {
class Nlsr;
-using namespace std;
-using namespace ndn;
class Fib
{
public:
- Fib()
+ Fib(ndn::Face& face)
: m_table()
, m_refreshTime(0)
+ , m_controller(face)
+ {
+ }
+ ~Fib()
{
}
void
- remove(Nlsr& pnlsr, string name);
+ remove(Nlsr& pnlsr, const std::string& name);
void
- update(Nlsr& pnlsr, string name, NexthopList& nextHopList);
+ update(Nlsr& pnlsr, const std::string& name, NexthopList& nextHopList);
void
clean(Nlsr& pnlsr);
void
- setEntryRefreshTime(int fert)
+ setEntryRefreshTime(int32_t fert)
{
m_refreshTime = fert;
}
@@ -40,23 +46,38 @@
private:
void
- removeHop(Nlsr& pnlsr, NexthopList& nl, int doNotRemoveHopFaceId);
+ removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+ const std::string& name);
int
- getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix);
+ getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
ndn::EventId
- scheduleEntryRefreshing(Nlsr& pnlsr, string name, int feSeqNum,
- int refreshTime);
- void
- cancelScheduledExpiringEvent(Nlsr& pnlsr, EventId eid);
+ scheduleEntryRefreshing(Nlsr& pnlsr, const std::string& name, int32_t feSeqNum,
+ int32_t refreshTime);
void
- refreshEntry(string name, int feSeqNum);
+ cancelScheduledExpiringEvent(Nlsr& pnlsr, ndn::EventId eid);
+
+ void
+ refreshEntry(Nlsr& nlsr, const std::string& name, int32_t feSeqNum);
+
+ void
+ registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost);
+
+ void
+ unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId);
+
+ void
+ onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message);
+
+ void
+ onFailure(uint32_t code, const std::string& error, const std::string& message);
private:
std::list<FibEntry> m_table;
- int m_refreshTime;
+ int32_t m_refreshTime;
+ ndn::nfd::Controller m_controller;
};
}//namespace nlsr
diff --git a/src/route/map-entry.hpp b/src/route/map-entry.hpp
new file mode 100644
index 0000000..9174345
--- /dev/null
+++ b/src/route/map-entry.hpp
@@ -0,0 +1,54 @@
+#ifndef NLSR_MAP_ENTRY_HPP
+#define NLSR_MAP_ENTRY_HPP
+
+#include <boost/cstdint.hpp>
+
+namespace nlsr{
+
+class MapEntry
+{
+public:
+ MapEntry()
+ : m_router()
+ , m_mappingNumber(-1)
+ {
+ }
+
+ ~MapEntry()
+ {
+ }
+
+ MapEntry(const std::string& rtr, int32_t mn)
+ {
+ m_router = rtr;
+ m_mappingNumber = mn;
+ }
+
+ const std::string&
+ getRouter() const
+ {
+ return m_router;
+ }
+
+ int32_t
+ getMappingNumber() const
+ {
+ return m_mappingNumber;
+ }
+
+private:
+ std::string m_router;
+ int32_t m_mappingNumber;
+};
+
+inline std::ostream&
+operator<<(std::ostream& os, const MapEntry& mpe)
+{
+ os << "MapEntry: ( Router: " << mpe.getRouter() << " Mapping No: ";
+ os << mpe.getMappingNumber() << " )" << std::endl;
+ return os;
+}
+
+} // namespace nlsr
+
+#endif // NLSR_MAP_ENTRY_HPP
diff --git a/src/route/map.cpp b/src/route/map.cpp
index e7ab979..4701a05 100644
--- a/src/route/map.cpp
+++ b/src/route/map.cpp
@@ -11,38 +11,30 @@
using namespace std;
-ostream&
-operator<< (ostream& os, MapEntry& mpe)
-{
- os << "MapEntry: ( Router: " << mpe.getRouter() << " Mapping No: ";
- os << mpe.getMappingNumber() << " )" << endl;
- return os;
-}
-
static bool
-mapEntryCompareByRouter(MapEntry& mpe1, string& rtrName)
+mapEntryCompareByRouter(MapEntry& mpe1, const string& rtrName)
{
return mpe1.getRouter() == rtrName;
}
static bool
-mapEntryCompareByMappingNo(MapEntry& mpe1, int mappingNo)
+mapEntryCompareByMappingNo(MapEntry& mpe1, int32_t mappingNo)
{
return mpe1.getMappingNumber() == mappingNo;
}
void
-Map::addElement(string& rtrName)
+Map::addEntry(const string& rtrName)
{
MapEntry me(rtrName, m_mappingIndex);
- if (addElement(me))
+ if (addEntry(me))
{
m_mappingIndex++;
}
}
bool
-Map::addElement(MapEntry& mpe)
+Map::addEntry(MapEntry& mpe)
{
//cout << mpe;
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
@@ -57,7 +49,7 @@
}
string
-Map::getRouterNameByMappingNo(int mn)
+Map::getRouterNameByMappingNo(int32_t mn)
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
@@ -70,7 +62,7 @@
return "";
}
-int
+int32_t
Map::getMappingNoByRouterName(string& rName)
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
@@ -92,13 +84,13 @@
it != adjLsdb.end() ; it++)
{
string linkStartRouter = (*it).getOrigRouter();
- addElement(linkStartRouter);
+ addEntry(linkStartRouter);
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
for (std::list<Adjacent>::iterator itAdl = adl.begin();
itAdl != adl.end() ; itAdl++)
{
string linkEndRouter = (*itAdl).getName();
- addElement(linkEndRouter);
+ addEntry(linkEndRouter);
}
}
}
diff --git a/src/route/map.hpp b/src/route/map.hpp
index bdacd4d..cc08771 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -3,52 +3,16 @@
#include <iostream>
#include <list>
+#include <boost/cstdint.hpp>
-#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/common.hpp>
+
+#include "map-entry.hpp"
namespace nlsr {
class Nlsr;
-class MapEntry
-{
-public:
- MapEntry()
- : m_router()
- , m_mappingNumber(-1)
- {
- }
-
- ~MapEntry()
- {
- }
-
- MapEntry(std::string rtr, int mn)
- {
- m_router = rtr;
- m_mappingNumber = mn;
- }
-
- std::string
- getRouter() const
- {
- return m_router;
- }
-
- int
- getMappingNumber() const
- {
- return m_mappingNumber;
- }
-
-private:
- std::string m_router;
- int m_mappingNumber;
-};
-
-std::ostream&
-operator<<(std::ostream& os, MapEntry& mpe);
-
class Map
{
public:
@@ -59,15 +23,15 @@
void
- addElement(std::string& rtrName);
+ addEntry(const std::string& rtrName);
void
createFromAdjLsdb(Nlsr& pnlsr);
std::string
- getRouterNameByMappingNo(int mn);
+ getRouterNameByMappingNo(int32_t mn);
- int
+ int32_t
getMappingNoByRouterName(std::string& rName);
void
@@ -88,9 +52,9 @@
private:
bool
- addElement(MapEntry& mpe);
+ addEntry(MapEntry& mpe);
- int m_mappingIndex;
+ int32_t m_mappingIndex;
std::list<MapEntry> m_table;
};
diff --git a/src/route/name-prefix-table-entry.cpp b/src/route/name-prefix-table-entry.cpp
index 4389373..01eea0d 100644
--- a/src/route/name-prefix-table-entry.cpp
+++ b/src/route/name-prefix-table-entry.cpp
@@ -11,15 +11,15 @@
void
NamePrefixTableEntry::generateNhlfromRteList()
{
- m_nhl.reset();
+ m_nexthopList.reset();
for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
it != m_rteList.end(); ++it)
{
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().end(); ++nhit)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
{
- m_nhl.addNextHop((*nhit));
+ m_nexthopList.addNextHop((*nhit));
}
}
}
@@ -56,11 +56,11 @@
}
else
{
- (*it).getNhl().reset(); // reseting existing routing table's next hop
- for (std::list<NextHop>::iterator nhit = rte.getNhl().getNextHopList().begin();
- nhit != rte.getNhl().getNextHopList().end(); ++nhit)
+ (*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)
{
- (*it).getNhl().addNextHop((*nhit));
+ (*it).getNexthopList().addNextHop((*nhit));
}
}
}
@@ -76,7 +76,7 @@
{
cout << (*it);
}
- os << npte.getNhl();
+ os << npte.getNexthopList();
return os;
}
diff --git a/src/route/name-prefix-table-entry.hpp b/src/route/name-prefix-table-entry.hpp
index 7f4f83a..0ee28fa 100644
--- a/src/route/name-prefix-table-entry.hpp
+++ b/src/route/name-prefix-table-entry.hpp
@@ -1,31 +1,29 @@
-#ifndef NLSR_NPTE_HPP
-#define NLSR_NPTE_HPP
+#ifndef NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
+#define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
#include <list>
#include <utility>
+#include <boost/cstdint.hpp>
+
#include "routing-table-entry.hpp"
namespace nlsr {
-using namespace std;
-
class NamePrefixTableEntry
{
public:
NamePrefixTableEntry()
- : m_namePrefix()
- , m_nhl()
{
}
- NamePrefixTableEntry(string np)
- : m_nhl()
+ NamePrefixTableEntry(const std::string& namePrefix)
+ : m_nexthopList()
{
- m_namePrefix = np;
+ m_namePrefix = namePrefix;
}
- std::string
- getNamePrefix()
+ const std::string&
+ getNamePrefix() const
{
return m_namePrefix;
}
@@ -44,21 +42,21 @@
for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
it != m_rteList.end(); ++it)
{
- (*it).getNhl().reset();
+ (*it).getNexthopList().reset();
}
}
}
- int
+ size_t
getRteListSize()
{
return m_rteList.size();
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
void
@@ -73,7 +71,7 @@
private:
std::string m_namePrefix;
std::list<RoutingTableEntry> m_rteList;
- NexthopList m_nhl;
+ NexthopList m_nexthopList;
};
std::ostream&
@@ -81,4 +79,4 @@
}//namespace nlsr
-#endif //NLSR_NPTE_HPP
+#endif //NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index e37751b..e6a7ccf 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.cpp
@@ -13,7 +13,7 @@
using namespace std;
static bool
-npteCompare(NamePrefixTableEntry& npte, string& name)
+npteCompare(NamePrefixTableEntry& npte, const string& name)
{
return npte.getNamePrefix() == name;
}
@@ -21,46 +21,46 @@
void
-NamePrefixTable::addNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
{
- std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_npteList.begin(),
- m_npteList.end(), bind(&npteCompare, _1, name));
- if (it == m_npteList.end())
+ std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(), bind(&npteCompare, _1, name));
+ if (it == m_table.end())
{
NamePrefixTableEntry newEntry(name);
newEntry.addRoutingTableEntry(rte);
newEntry.generateNhlfromRteList();
- newEntry.getNhl().sort();
- m_npteList.push_back(newEntry);
- if (rte.getNhl().getSize() > 0)
+ newEntry.getNexthopList().sort();
+ m_table.push_back(newEntry);
+ if (rte.getNexthopList().getSize() > 0)
{
- pnlsr.getFib().update(pnlsr, name, newEntry.getNhl());
+ pnlsr.getFib().update(pnlsr, name, newEntry.getNexthopList());
}
}
else
{
- if (rte.getNhl().getSize() > 0)
+ if (rte.getNexthopList().getSize() > 0)
{
(*it).addRoutingTableEntry(rte);
(*it).generateNhlfromRteList();
- (*it).getNhl().sort();
- pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ (*it).getNexthopList().sort();
+ pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
}
else
{
(*it).resetRteListNextHop();
- (*it).getNhl().reset();
+ (*it).getNexthopList().reset();
pnlsr.getFib().remove(pnlsr, name);
}
}
}
void
-NamePrefixTable::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+NamePrefixTable::removeEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
{
- std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_npteList.begin(),
- m_npteList.end(), bind(&npteCompare, _1, name));
- if (it != m_npteList.end())
+ std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(), bind(&npteCompare, _1, name));
+ if (it != m_table.end())
{
string destRouter = rte.getDestination();
(*it).removeRoutingTableEntry(rte);
@@ -69,56 +69,55 @@
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/2", 2)) &&
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/3", 3)))
{
- m_npteList.erase(it);
+ m_table.erase(it);
pnlsr.getFib().remove(pnlsr, name);
}
else
{
(*it).generateNhlfromRteList();
- pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
}
}
}
void
-NamePrefixTable::addNpteByDestName(string name, string destRouter, Nlsr& pnlsr)
+NamePrefixTable::addEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
{
RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0)
{
- addNpte(name, *(rteCheck) , pnlsr);
+ addEntry(name, *(rteCheck) , pnlsr);
}
else
{
RoutingTableEntry rte(destRouter);
- addNpte(name, rte, pnlsr);
+ addEntry(name, rte, pnlsr);
}
}
void
-NamePrefixTable::removeNpte(string name, string destRouter, Nlsr& pnlsr)
+NamePrefixTable::removeEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
{
RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0)
{
- removeNpte(name, *(rteCheck), pnlsr);
+ removeEntry(name, *(rteCheck), pnlsr);
}
else
{
RoutingTableEntry rte(destRouter);
- removeNpte(name, rte, pnlsr);
+ removeEntry(name, rte, pnlsr);
}
}
void
NamePrefixTable::updateWithNewRoute(Nlsr& pnlsr)
{
- for (std::list<NamePrefixTableEntry>::iterator it = m_npteList.begin();
- it != m_npteList.end();
- ++it)
+ for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
+ it != m_table.end(); ++it)
{
std::list<RoutingTableEntry> rteList = (*it).getRteList();
for (std::list<RoutingTableEntry>::iterator rteit = rteList.begin();
@@ -128,12 +127,12 @@
pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
if (rteCheck != 0)
{
- addNpte((*it).getNamePrefix(), *(rteCheck), pnlsr);
+ addEntry((*it).getNamePrefix(), *(rteCheck), pnlsr);
}
else
{
RoutingTableEntry rte((*rteit).getDestination());
- addNpte((*it).getNamePrefix(), rte, pnlsr);
+ addEntry((*it).getNamePrefix(), rte, pnlsr);
}
}
}
@@ -143,8 +142,8 @@
NamePrefixTable::print()
{
std::cout << "----------------NPT----------------------" << std::endl;
- for (std::list<NamePrefixTableEntry>::iterator it = m_npteList.begin();
- it != m_npteList.end();
+ for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
+ it != m_table.end();
++it)
{
cout << (*it) << endl;
diff --git a/src/route/name-prefix-table.hpp b/src/route/name-prefix-table.hpp
index 1a59af2..4f7fbb4 100644
--- a/src/route/name-prefix-table.hpp
+++ b/src/route/name-prefix-table.hpp
@@ -1,7 +1,9 @@
-#ifndef NLSR_NPT_HPP
-#define NLSR_NPT_HPP
+#ifndef NLSR_NAME_PREFIX_TABLE_HPP
+#define NLSR_NAME_PREFIX_TABLE_HPP
#include <list>
+#include <boost/cstdint.hpp>
+
#include "name-prefix-table-entry.hpp"
#include "routing-table-entry.hpp"
@@ -14,11 +16,12 @@
NamePrefixTable()
{
}
- void
- addNpteByDestName(std::string name, std::string destRouter, Nlsr& pnlsr);
void
- removeNpte(std::string name, std::string destRouter, Nlsr& pnlsr);
+ addEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
+
+ void
+ removeEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
void
updateWithNewRoute(Nlsr& pnlsr);
@@ -28,15 +31,15 @@
private:
void
- addNpte(std::string name, RoutingTableEntry& rte, Nlsr& pnlsr);
+ addEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
void
- removeNpte(std::string name, RoutingTableEntry& rte, Nlsr& pnlsr);
+ removeEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
private:
- std::list<NamePrefixTableEntry> m_npteList;
+ std::list<NamePrefixTableEntry> m_table;
};
}//namespace nlsr
-#endif //NLSR_NPT_HPP
+#endif //NLSR_NAME_PREFIX_TABLE_HPP
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 7edb96e..5468b40 100644
--- a/src/route/nexthop-list.cpp
+++ b/src/route/nexthop-list.cpp
@@ -75,7 +75,7 @@
ostream&
operator<<(ostream& os, NexthopList& nhl)
{
- std::list<NextHop> nexthopList = nhl.getNextHopList();
+ std::list<NextHop> nexthopList = nhl.getNextHops();
int i = 1;
for (std::list<NextHop>::iterator it = nexthopList.begin();
it != nexthopList.end() ; it++, i++)
diff --git a/src/route/nexthop-list.hpp b/src/route/nexthop-list.hpp
index a8ebe7b..2607218 100644
--- a/src/route/nexthop-list.hpp
+++ b/src/route/nexthop-list.hpp
@@ -1,9 +1,11 @@
-#ifndef NLSR_NHL_HPP
-#define NLSR_NHL_HPP
+#ifndef NLSR_NEXTHOP_LIST_HPP
+#define NLSR_NEXTHOP_LIST_HPP
-#include <ndn-cxx/face.hpp>
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
+
+#include <ndn-cxx/face.hpp>
#include "nexthop.hpp"
#include "adjacent.hpp"
@@ -14,13 +16,13 @@
{
public:
NexthopList()
- : m_nexthopList()
{
}
~NexthopList()
{
}
+
void
addNextHop(NextHop& nh);
@@ -30,7 +32,7 @@
void
sort();
- int
+ size_t
getSize()
{
return m_nexthopList.size();
@@ -39,14 +41,11 @@
void
reset()
{
- if (m_nexthopList.size() > 0)
- {
- m_nexthopList.clear();
- }
+ m_nexthopList.clear();
}
std::list<NextHop>&
- getNextHopList()
+ getNextHops()
{
return m_nexthopList;
}
@@ -60,4 +59,4 @@
}//namespace nlsr
-#endif //NLSR_NLH_HPP
+#endif //NLSR_NEXTHOP_LIST_HPP
diff --git a/src/route/nexthop.hpp b/src/route/nexthop.hpp
index 7153e0f..ed8d319 100644
--- a/src/route/nexthop.hpp
+++ b/src/route/nexthop.hpp
@@ -2,6 +2,7 @@
#define NLSR_NEXTHOP_HPP
#include <iostream>
+#include <boost/cstdint.hpp>
namespace nlsr {
class NextHop
@@ -13,20 +14,20 @@
{
}
- NextHop(int cf, double rc)
+ NextHop(uint32_t cf, double rc)
{
m_connectingFace = cf;
m_routeCost = rc;
}
- int
+ uint32_t
getConnectingFace() const
{
return m_connectingFace;
}
void
- setConnectingFace(int cf)
+ setConnectingFace(uint32_t cf)
{
m_connectingFace = cf;
}
@@ -44,7 +45,7 @@
}
private:
- int m_connectingFace;
+ uint32_t m_connectingFace;
double m_routeCost;
};
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index b248b15..544896c 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -1,8 +1,9 @@
-#ifndef NLSR_RTC_HPP
-#define NLSR_RTC_HPP
+#ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
+#define NLSR_ROUTING_TABLE_CALCULATOR_HPP
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
namespace nlsr {
@@ -198,4 +199,4 @@
}//namespace nlsr
-#endif //NLSR_RTC_HPP
+#endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP
diff --git a/src/route/routing-table-entry.cpp b/src/route/routing-table-entry.cpp
deleted file mode 100644
index 5222cb9..0000000
--- a/src/route/routing-table-entry.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <iostream>
-#include <string>
-
-#include "routing-table-entry.hpp"
-
-namespace nlsr {
-
-using namespace std;
-
-ostream&
-operator<<(ostream& os, RoutingTableEntry& rte)
-{
- os << "Destination: " << rte.getDestination() << endl;
- os << "Nexthops: " << endl;
- int i = 1;
- std::list<NextHop> nhl = rte.getNhl().getNextHopList();
- for (std::list<NextHop>::iterator it = nhl.begin();
- it != nhl.end() ; it++, i++)
- {
- os << " Nexthop " << i << ": " << (*it) << endl;
- }
- return os;
-}
-
-}//namespace nlsr
diff --git a/src/route/routing-table-entry.hpp b/src/route/routing-table-entry.hpp
index 8877275..0d0b662 100644
--- a/src/route/routing-table-entry.hpp
+++ b/src/route/routing-table-entry.hpp
@@ -1,5 +1,5 @@
-#ifndef NLSR_RTE_HPP
-#define NLSR_RTE_HPP
+#ifndef NLSR_ROUTING_TABLE_ENTRY_HPP
+#define NLSR_ROUTING_TABLE_ENTRY_HPP
#include <iostream>
@@ -11,8 +11,6 @@
{
public:
RoutingTableEntry()
- : m_destination()
- , m_nhl()
{
}
@@ -20,8 +18,7 @@
{
}
- RoutingTableEntry(std::string dest)
- : m_nhl()
+ RoutingTableEntry(const std::string& dest)
{
m_destination = dest;
}
@@ -33,19 +30,31 @@
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
private:
std::string m_destination;
- NexthopList m_nhl;
+ NexthopList m_nexthopList;
};
-std::ostream&
-operator<<(std::ostream& os, RoutingTableEntry& rte);
+inline std::ostream&
+operator<<(std::ostream& os, RoutingTableEntry& rte)
+{
+ os << "Destination: " << rte.getDestination() << std::endl;
+ os << "Nexthops: " << std::endl;
+ int32_t i = 1;
+ std::list<NextHop> nhl = rte.getNexthopList().getNextHops();
+ for (std::list<NextHop>::iterator it = nhl.begin();
+ it != nhl.end() ; it++, i++)
+ {
+ os << " Nexthop " << i << ": " << (*it) << std::endl;
+ }
+ return os;
+}
} //namespace nlsr
-#endif //NLSR_RTE_HPP
+#endif //NLSR_ROUTING_TABLE_ENTRY_HPP
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 2bc827c..bb7d3fa 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -144,12 +144,12 @@
if (rteChk == 0)
{
RoutingTableEntry rte(destRouter);
- rte.getNhl().addNextHop(nh);
+ rte.getNexthopList().addNextHop(nh);
m_rTable.push_back(rte);
}
else
{
- rteChk->getNhl().addNextHop(nh);
+ rteChk->getNexthopList().addNextHop(nh);
}
}
@@ -188,12 +188,12 @@
if (it == m_dryTable.end())
{
RoutingTableEntry rte(destRouter);
- rte.getNhl().addNextHop(nh);
+ rte.getNexthopList().addNextHop(nh);
m_dryTable.push_back(rte);
}
else
{
- (*it).getNhl().addNextHop(nh);
+ (*it).getNexthopList().addNextHop(nh);
}
}
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index 8518b12..35f563e 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -1,9 +1,10 @@
-#ifndef NLSR_RT_HPP
-#define NLSR_RT_HPP
+#ifndef NLSR_ROUTING_TABLE_HPP
+#define NLSR_ROUTING_TABLE_HPP
#include <iostream>
#include <utility>
#include <string>
+#include <boost/cstdint.hpp>
#include "routing-table-entry.hpp"
@@ -70,4 +71,4 @@
}//namespace nlsr
-#endif //NLSR_RT_HPP
+#endif //NLSR_ROUTING_TABLE_HPP