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/nlsr.conf b/nlsr.conf
index 2f2287b..2f2440f 100644
--- a/nlsr.conf
+++ b/nlsr.conf
@@ -1,14 +1,97 @@
-network ndn
-site-name memphis.edu
-router-name cs/macbook
+; the general section contains all the general settings for router
-ndnneighbor /ndn/memphis.edu/cs/maia 7
-link-cost /ndn/memphis.edu/cs/maia 30
-ndnneighbor /ndn/memphis.edu/cs/pollux 10
-link-cost /ndn/memphis.edu/cs/pollux 25
+general
+{
+; mandatory configuration command section network, site and router
-ndnname /ndn/memphis.edu/cs/macbook/name1
-ndnname /ndn/memphis.edu/cs/macbook/name2
+ network /ndn/ ; name of the network the router belongs to in ndn URI format
+ site /memphis.edu/ ; name of the site the router belongs to in ndn URI format
+ router /cs/pollux/ ; name of the network the router belongs to in ndn URI format
+
+; lsa-refresh-time is the time in seconds, after which router will refresh its LSAs
+
+ lsa-refresh-time 1800 ; default value 1800. Valid values 240-7200
+
+; log-level is to set the levels of log for NLSR
+
+ log-level INFO ; default value INFO, valid value DEBUG, INFO
+}
+
+; the neighbors section contains the configuration for router's neighbors and hello's behavior
+
+neighbors
+{
+; in case hello interest timed out, router will try 'hello-retries' times at 'hello-time-out'
+; seconds interval before giving up for any neighbors (deciding link is down)
+
+ hello-retries 3 ; interest retries number in integer. Default value 3
+ ; valid values 1-10
+
+ hello-timeout 1 ; interest time out value in integer. Default value 1
+ ; Valid values 1-15
+
+ hello-interval 60 ; interest sending interval in seconds. Default value 60
+ ; valid values 30-90
+; neighbor command is used to configure router's neighbor. Each neighbor will need
+; one block of neighbor command
+
+ neighbor
+ {
+ name /ndn/memphis.edu/cs/castor ; name prefix of the neighbor router consists
+ ; of network, site-name and router-name
+
+ face-uri udp://castor.cs.memphis.edu ; face id of the face connected to the neighbor
+ link-cost 25 ; cost of the connecting link to neighbor
+ }
+
+ neighbor
+ {
+ name /ndn/memphis.edu/cs/mira ; name prefix of the neighbor router consists
+ ; of network, site-name and router-name
+
+ face-uri udp://mira.cs.memphis.edu ; face id of the face connected to the neighbor
+ link-cost 30 ; cost of the connecting link to neighbor
+ }
+}
+
+; the hyperbolic section contains the configuration settings of enabling a router to calculate
+; routing table using [hyperbolic routing table calculation](http://arxiv.org/abs/0805.1266) method
+
+hyperbolic
+{
+; commands in this section follows a strict order
+; the switch is used to set hyperbolic routing calculation in NLSR
+
+ state off ; default value 'off', set value 'on' to enable hyperbolic routing table
+ ; calculation which turns link state routing 'off'. set value to 'dry-run"
+ ; to test hyperbolic routing and compare with link state routing.
-!logdir /Users/akmhoque/NLSR-CPP/log
+ radius 123.456 ; radius of the router in hyperbolic coordinate system
+ angle 1.45 ; angle of the router in hyperbolic coordinate system
+}
+
+
+; the fib section is used to configure fib entry's type to ndn FIB updated by NLSR
+
+fib
+{
+; the max-faces-per-prefix is used to limit the number of faces for each name prefixes
+; by NLSR in ndn FIB
+
+ max-faces-per-prefix 3 ; default value 0. Valid value 0-60. By default (value 0) NLSR adds
+ ; all available faces for each reachable name prefixes in NDN FIB
+
+}
+
+; the advertising section contains the configuration settings of the name prefixes
+; hosted by this router
+
+advertising
+{
+; the ndnname is used to advertised name from the router. To advertise each name prefix
+; configure one block of ndnname configuration command for every name prefix.
+
+ prefix /ndn/edu/memphis/cs/netlab ; name in ndn URI format
+ prefix /ndn/edu/memphis/sports/basketball
+}
diff --git a/nsync/sync-logic.cc b/nsync/sync-logic.cc
index 3038532..af864d3 100644
--- a/nsync/sync-logic.cc
+++ b/nsync/sync-logic.cc
@@ -17,7 +17,7 @@
*
* Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
* Yingdi Yu <yingdi@cs.ucla.edu>
*/
@@ -46,10 +46,10 @@
#define GET_RANDOM(var) var ()
#define TIME_SECONDS_WITH_JITTER(sec) \
- (time::seconds(sec) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
+ (ndn::time::seconds(sec) + ndn::time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
#define TIME_MILLISECONDS_WITH_JITTER(ms) \
- (time::seconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
+ (ndn::time::seconds(ms) + ndn::time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
namespace Sync {
@@ -66,7 +66,7 @@
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove)
: m_state (new FullState)
- , m_syncInterestTable (*face->ioService(), time::seconds(m_syncInterestReexpress))
+ , m_syncInterestTable (face->getIoService(), ndn::time::seconds(m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdate (onUpdate)
, m_onRemove (onRemove)
@@ -74,18 +74,22 @@
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
- , m_scheduler(*face->ioService())
+ , m_scheduler(face->getIoService())
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
, m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
{
m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
- bind(&SyncLogic::onSyncInterest, this, _1, _2),
- bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2));
+ bind(&SyncLogic::onSyncInterest,
+ this, _1, _2),
+ bind(&SyncLogic::onSyncRegisterSucceed,
+ this, _1),
+ bind(&SyncLogic::onSyncRegisterFailed,
+ this, _1, _2));
- m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (ndn::time::seconds (0),
bind (&SyncLogic::sendSyncInterest, this));
m_instanceId = string("Instance " + boost::lexical_cast<string>(m_instanceCounter++) + " ");
@@ -96,24 +100,28 @@
shared_ptr<Face> face,
LogicPerBranchCallback onUpdateBranch)
: m_state (new FullState)
- , m_syncInterestTable (*face->ioService(), time::seconds (m_syncInterestReexpress))
+ , m_syncInterestTable (face->getIoService(), ndn::time::seconds (m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdateBranch (onUpdateBranch)
, m_perBranch(true)
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
- , m_scheduler(*face->ioService())
+ , m_scheduler(face->getIoService())
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
, m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
{
m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
- bind(&SyncLogic::onSyncInterest, this, _1, _2),
- bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2));
+ bind(&SyncLogic::onSyncInterest,
+ this, _1, _2),
+ bind(&SyncLogic::onSyncRegisterSucceed,
+ this, _1),
+ bind(&SyncLogic::onSyncRegisterFailed,
+ this, _1, _2));
- m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (ndn::time::seconds (0),
bind (&SyncLogic::sendSyncInterest, this));
}
@@ -139,13 +147,13 @@
BOOST_ASSERT (nameLengthDiff > 0);
BOOST_ASSERT (nameLengthDiff < 3);
- string hash = name.get(-1).toEscapedString();
+ string hash = name.get(-1).toUri();
string interestType;
if(nameLengthDiff == 1)
interestType = "normal";
else
- interestType = name.get(-2).toEscapedString();
+ interestType = name.get(-2).toUri();
_LOG_DEBUG_ID (hash << ", " << interestType);
@@ -189,6 +197,12 @@
}
void
+SyncLogic::onSyncRegisterSucceed(const Name& prefix)
+{
+ _LOG_DEBUG_ID("Sync prefix registration succeeded! " << prefix);
+}
+
+void
SyncLogic::onSyncRegisterFailed(const Name& prefix, const string& msg)
{
_LOG_DEBUG_ID("Sync prefix registration failed! " << msg);
@@ -249,7 +263,8 @@
}
void
-SyncLogic::processSyncInterest (const Name &name, DigestConstPtr digest, bool timedProcessing/*=false*/)
+SyncLogic::processSyncInterest (const Name &name, DigestConstPtr digest,
+ bool timedProcessing/*=false*/)
{
_LOG_DEBUG_ID("processSyncInterest");
DigestConstPtr rootDigest;
@@ -291,19 +306,22 @@
bool exists = m_syncInterestTable.insert (digest, name.toUri(), true);
if (exists) // somebody else replied, so restart random-game timer
{
- _LOG_DEBUG_ID ("Unknown digest, but somebody may have already replied, so restart our timer");
+ _LOG_DEBUG_ID("Unknown digest, but somebody may have already replied, " <<
+ "so restart our timer");
m_scheduler.cancelEvent (m_delayedInterestProcessingId);
}
uint32_t waitDelay = GET_RANDOM (m_rangeUniformRandom);
- _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << time::milliseconds (waitDelay));
+ _LOG_DEBUG_ID("Digest is not in the log. Schedule processing after small delay: " <<
+ ndn::time::milliseconds (waitDelay));
- m_delayedInterestProcessingId = m_scheduler.scheduleEvent (time::milliseconds (waitDelay),
- bind (&SyncLogic::processSyncInterest, this, name, digest, true));
+ m_delayedInterestProcessingId =
+ m_scheduler.scheduleEvent(ndn::time::milliseconds (waitDelay),
+ bind (&SyncLogic::processSyncInterest, this, name, digest, true));
}
else
{
- _LOG_DEBUG_ID (" (timed processing)");
+ _LOG_DEBUG_ID(" (timed processing)");
m_recoveryRetransmissionInterval = m_defaultRecoveryRetransmitInterval;
sendSyncRecoveryInterests (digest);
@@ -311,7 +329,8 @@
}
void
-SyncLogic::processSyncData (const Name &name, DigestConstPtr digest, const char *wireData, size_t len)
+SyncLogic::processSyncData (const Name &name, DigestConstPtr digest,
+ const char *wireData, size_t len)
{
DiffStatePtr diffLog = boost::make_shared<DiffState> ();
bool ownInterestSatisfied = false;
@@ -367,13 +386,17 @@
MissingDataInfo mdi = {info->toString(), oldSeq, seq};
{
ostringstream interestName;
- interestName << mdi.prefix << "/" << mdi.high.getSession() << "/" << mdi.high.getSeq();
+ interestName << mdi.prefix <<
+ "/" << mdi.high.getSession() <<
+ "/" << mdi.high.getSeq();
_LOG_DEBUG_ID("+++++++++++++++ " + interestName.str());
}
if (m_perBranch)
{
ostringstream interestName;
- interestName << mdi.prefix << "/" << mdi.high.getSession() << "/" << mdi.high.getSeq();
+ interestName << mdi.prefix <<
+ "/" << mdi.high.getSession() <<
+ "/" << mdi.high.getSeq();
m_onUpdateBranch(interestName.str());
}
else
@@ -424,10 +447,12 @@
// Do it only if everything went fine and state changed
// this is kind of wrong
- // satisfyPendingSyncInterests (diffLog); // if there are interests in PIT, there is a point to satisfy them using new state
+ // satisfyPendingSyncInterests (diffLog); // if there are interests in PIT,
+ // // there is a point to satisfy them using new state
// if state has changed, then it is safe to express a new interest
- time::system_clock::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
+ ndn::time::system_clock::Duration after =
+ ndn::time::milliseconds(GET_RANDOM (m_reexpressionJitter));
// cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
@@ -503,7 +528,8 @@
{
m_log.get<sequenced> ().front ()->setNext (diffLog);
}
- m_log.erase (m_state->getDigest()); // remove diff state with the same digest. next pointers are still valid
+ m_log.erase (m_state->getDigest()); // remove diff state with the same digest.
+ // next pointers are still valid
/// @todo Optimization
m_log.get<sequenced> ().push_front (diffLog);
}
@@ -577,8 +603,10 @@
_LOG_DEBUG_ID("sendSyncInterest: " << m_outstandingInterestName);
- EventId eventId = m_scheduler.scheduleEvent (time::seconds(m_syncInterestReexpress) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)),
- bind (&SyncLogic::sendSyncInterest, this));
+ EventId eventId =
+ m_scheduler.scheduleEvent(ndn::time::seconds(m_syncInterestReexpress) +
+ ndn::time::milliseconds(GET_RANDOM(m_reexpressionJitter)),
+ bind (&SyncLogic::sendSyncInterest, this));
m_scheduler.cancelEvent (m_reexpressingInterestId);
m_reexpressingInterestId = eventId;
@@ -599,14 +627,16 @@
Name interestName = m_syncPrefix;
interestName.append("recovery").append(os.str());
- time::system_clock::Duration nextRetransmission = time::milliseconds (m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter));
+ ndn::time::system_clock::Duration nextRetransmission =
+ ndn::time::milliseconds(m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter));
m_recoveryRetransmissionInterval <<= 1;
m_scheduler.cancelEvent (m_reexpressingRecoveryInterestId);
if (m_recoveryRetransmissionInterval < 100*1000) // <100 seconds
- m_reexpressingRecoveryInterestId = m_scheduler.scheduleEvent (nextRetransmission,
- bind (&SyncLogic::sendSyncRecoveryInterests, this, digest));
+ m_reexpressingRecoveryInterestId =
+ m_scheduler.scheduleEvent (nextRetransmission,
+ bind (&SyncLogic::sendSyncRecoveryInterests, this, digest));
ndn::Interest interest(interestName);
interest.setMustBeFresh(true);
@@ -637,7 +667,7 @@
Data syncData(name);
syncData.setContent(reinterpret_cast<const uint8_t*>(wireData), size);
- syncData.setFreshnessPeriod(time::seconds(m_syncResponseFreshness));
+ syncData.setFreshnessPeriod(ndn::time::seconds(m_syncResponseFreshness));
m_keyChain->sign(syncData);
@@ -655,7 +685,8 @@
{
_LOG_DEBUG_ID ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)");
- time::system_clock::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
+ ndn::time::system_clock::Duration after =
+ ndn::time::milliseconds(GET_RANDOM(m_reexpressionJitter));
// cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
diff --git a/nsync/sync-logic.h b/nsync/sync-logic.h
index afb732a..25c3aae 100644
--- a/nsync/sync-logic.h
+++ b/nsync/sync-logic.h
@@ -63,7 +63,6 @@
class SyncLogic
{
public:
- //typedef boost::function< void ( const std::string &/*prefix*/, const SeqNo &/*newSeq*/, const SeqNo &/*oldSeq*/ ) > LogicUpdateCallback;
typedef boost::function< void (const std::vector<MissingDataInfo> & ) > LogicUpdateCallback;
typedef boost::function< void (const std::string &/*prefix*/ ) > LogicRemoveCallback;
typedef boost::function< void (const std::string &)> LogicPerBranchCallback;
@@ -122,6 +121,9 @@
onSyncInterest (const ndn::Name& prefix, const ndn::Interest& interest);
void
+ onSyncRegisterSucceed(const ndn::Name& prefix);
+
+ void
onSyncRegisterFailed(const ndn::Name& prefix, const std::string& msg);
void
diff --git a/nsync/sync-socket.cc b/nsync/sync-socket.cc
index 7c4e410..e3fbcf1 100644
--- a/nsync/sync-socket.cc
+++ b/nsync/sync-socket.cc
@@ -40,7 +40,6 @@
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
- , m_ioService(face->ioService())
, m_syncLogic (syncPrefix,
validator,
face,
@@ -53,23 +52,28 @@
}
bool
-SyncSocket::publishData(const Name &prefix, uint64_t session, const char *buf, size_t len, int freshness,uint64_t seq)
+SyncSocket::publishData(const Name &prefix, uint64_t session,
+ const char *buf, size_t len,
+ int freshness,uint64_t seq)
{
shared_ptr<Data> data = make_shared<Data>();
data->setContent(reinterpret_cast<const uint8_t*>(buf), len);
- data->setFreshnessPeriod(time::seconds(freshness));
+ data->setFreshnessPeriod(ndn::time::seconds(freshness));
- m_ioService->post(bind(&SyncSocket::publishDataInternal, this, data, prefix, session,seq));
+ m_face->getIoService().post(bind(&SyncSocket::publishDataInternal, this,
+ data, prefix, session,seq));
return true;
}
void
-SyncSocket::publishDataInternal(shared_ptr<Data> data, const Name &prefix, uint64_t session,uint64_t seq)
+SyncSocket::publishDataInternal(shared_ptr<Data> data,
+ const Name &prefix, uint64_t session, uint64_t seq)
{
uint64_t sequence = seq;
Name dataName = prefix;
- dataName.append(boost::lexical_cast<string>(session)).append(boost::lexical_cast<string>(sequence));
+ dataName.append(boost::lexical_cast<string>(session))
+ .append(boost::lexical_cast<string>(sequence));
data->setName(dataName);
m_keyChain->sign(*data);
@@ -82,18 +86,23 @@
}
void
-SyncSocket::fetchData(const Name &prefix, const SeqNo &seq, const OnDataValidated& onValidated, int retry)
+SyncSocket::fetchData(const Name &prefix, const SeqNo &seq,
+ const OnDataValidated& onValidated, int retry)
{
Name interestName = prefix;
- interestName.append(boost::lexical_cast<string>(seq.getSession())).append(boost::lexical_cast<string>(seq.getSeq()));
+ interestName.append(boost::lexical_cast<string>(seq.getSession()))
+ .append(boost::lexical_cast<string>(seq.getSeq()));
- const OnDataValidationFailed& onValidationFailed = bind(&SyncSocket::onDataValidationFailed, this, _1);
+ const OnDataValidationFailed& onValidationFailed =
+ bind(&SyncSocket::onDataValidationFailed, this, _1);
ndn::Interest interest(interestName);
interest.setMustBeFresh(true);
m_face->expressInterest(interest,
- bind(&SyncSocket::onData, this, _1, _2, onValidated, onValidationFailed),
- bind(&SyncSocket::onDataTimeout, this, _1, retry, onValidated, onValidationFailed));
+ bind(&SyncSocket::onData, this, _1, _2,
+ onValidated, onValidationFailed),
+ bind(&SyncSocket::onDataTimeout, this, _1, retry,
+ onValidated, onValidationFailed));
}
diff --git a/nsync/sync-socket.h b/nsync/sync-socket.h
index 541673c..ef54a99 100644
--- a/nsync/sync-socket.h
+++ b/nsync/sync-socket.h
@@ -42,8 +42,8 @@
class SyncSocket
{
public:
- typedef ndn::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
- typedef ndn::function< void (const std::string &/*prefix*/ ) > RemoveCallback;
+ typedef ndn::function<void(const std::vector<MissingDataInfo> &, SyncSocket *)> NewDataCallback;
+ typedef ndn::function<void(const std::string &/*prefix*/)> RemoveCallback;
/**
* @brief the constructor for SyncAppSocket; the parameter syncPrefix
@@ -56,47 +56,52 @@
* @param syncPrefix the name prefix for Sync Interest
* @param dataCallback the callback to process data
*/
- SyncSocket (const ndn::Name &syncPrefix,
+ SyncSocket (const ndn::Name &syncPrefix,
ndn::shared_ptr<ndn::Validator> validator,
ndn::shared_ptr<ndn::Face> face,
- NewDataCallback dataCallback,
+ NewDataCallback dataCallback,
RemoveCallback rmCallback);
~SyncSocket ();
- bool
- publishData(const ndn::Name &prefix, uint64_t session, const char *buf, size_t len, int freshness,uint64_t seq);
+ bool
+ publishData(const ndn::Name &prefix, uint64_t session, const char *buf, size_t len,
+ int freshness,uint64_t seq);
- void
- remove (const ndn::Name &prefix)
+ void
+ remove (const ndn::Name &prefix)
{ m_syncLogic.remove(prefix); }
- void
- fetchData(const ndn::Name &prefix, const SeqNo &seq, const ndn::OnDataValidated& onValidated, int retry = 0);
+ void
+ fetchData(const ndn::Name &prefix, const SeqNo &seq,
+ const ndn::OnDataValidated& onValidated, int retry = 0);
- std::string
- getRootDigest()
+ std::string
+ getRootDigest()
{ return m_syncLogic.getRootDigest(); }
uint64_t
getNextSeq (const ndn::Name &prefix, uint64_t session);
SyncLogic &
- getLogic ()
+ getLogic ()
{ return m_syncLogic; }
// make this a static function so we don't have to create socket instance without
// knowing the local prefix. it's a wrong place for this function anyway
static std::string
- GetLocalPrefix ();
-
+ GetLocalPrefix ();
+
private:
void
- publishDataInternal(ndn::shared_ptr<ndn::Data> data, const ndn::Name &prefix, uint64_t session,uint64_t seq);
+ publishDataInternal(ndn::shared_ptr<ndn::Data> data,
+ const ndn::Name &prefix, uint64_t session,uint64_t seq);
- void
- passCallback(const std::vector<MissingDataInfo> &v)
- { m_newDataCallback(v, this); }
+ void
+ passCallback(const std::vector<MissingDataInfo> &v)
+ {
+ m_newDataCallback(v, this);
+ }
void
onData(const ndn::Interest& interest, ndn::Data& data,
@@ -104,7 +109,7 @@
const ndn::OnDataValidationFailed& onValidationFailed);
void
- onDataTimeout(const ndn::Interest& interest,
+ onDataTimeout(const ndn::Interest& interest,
int retry,
const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed);
@@ -119,7 +124,6 @@
ndn::shared_ptr<ndn::Validator> m_validator;
ndn::shared_ptr<ndn::KeyChain> m_keyChain;
ndn::shared_ptr<ndn::Face> m_face;
- ndn::shared_ptr<boost::asio::io_service> m_ioService;
SyncLogic m_syncLogic;
};
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index 117ba76..48e35cf 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -22,8 +22,7 @@
AdjacencyList::insert(Adjacent& adjacent)
{
std::list<Adjacent>::iterator it = find(adjacent.getName());
- if (it != m_adjList.end())
- {
+ if (it != m_adjList.end()) {
return -1;
}
m_adjList.push_back(adjacent);
@@ -34,8 +33,7 @@
AdjacencyList::addAdjacents(AdjacencyList& adl)
{
for (std::list<Adjacent>::iterator it = adl.getAdjList().begin();
- it != adl.getAdjList().end(); ++it)
- {
+ it != adl.getAdjList().end(); ++it) {
insert((*it));
}
}
@@ -44,8 +42,7 @@
AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, int32_t s)
{
std::list<Adjacent>::iterator it = find(adjName);
- if (it == m_adjList.end())
- {
+ if (it == m_adjList.end()) {
return -1;
}
(*it).setStatus(s);
@@ -57,8 +54,7 @@
{
Adjacent adj(adjName);
std::list<Adjacent>::iterator it = find(adjName);
- if (it != m_adjList.end())
- {
+ if (it != m_adjList.end()) {
return (*it);
}
return adj;
@@ -73,8 +69,7 @@
bool
AdjacencyList::operator==(AdjacencyList& adl)
{
- if (getSize() != adl.getSize())
- {
+ if (getSize() != adl.getSize()) {
return false;
}
m_adjList.sort(compareAdjacent);
@@ -84,10 +79,8 @@
std::list<Adjacent>::iterator it1;
std::list<Adjacent>::iterator it2;
for (it1 = m_adjList.begin(), it2 = adjList2.begin();
- it1 != m_adjList.end(); it1++, it2++)
- {
- if (!((*it1) == (*it2)))
- {
+ it1 != m_adjList.end(); it1++, it2++) {
+ if (!((*it1) == (*it2))) {
break;
}
equalAdjCount++;
@@ -99,8 +92,7 @@
AdjacencyList::updateAdjacentLinkCost(const ndn::Name& adjName, double lc)
{
std::list<Adjacent>::iterator it = find(adjName);
- if (it == m_adjList.end())
- {
+ if (it == m_adjList.end()) {
return -1;
}
(*it).setLinkCost(lc);
@@ -122,8 +114,7 @@
AdjacencyList::incrementTimedOutInterestCount(const ndn::Name& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
- if (it == m_adjList.end())
- {
+ if (it == m_adjList.end()) {
return ;
}
(*it).setInterestTimedOutNo((*it).getInterestTimedOutNo() + 1);
@@ -134,8 +125,7 @@
uint32_t count)
{
std::list<Adjacent>::iterator it = find(neighbor);
- if (it != m_adjList.end())
- {
+ if (it != m_adjList.end()) {
(*it).setInterestTimedOutNo(count);
}
}
@@ -144,8 +134,7 @@
AdjacencyList::getTimedOutInterestCount(const ndn::Name& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
- if (it == m_adjList.end())
- {
+ if (it == m_adjList.end()) {
return -1;
}
return (*it).getInterestTimedOutNo();
@@ -155,8 +144,7 @@
AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
- if (it == m_adjList.end())
- {
+ if (it == m_adjList.end()) {
return -1;
}
return (*it).getStatus();
@@ -166,8 +154,7 @@
AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status)
{
std::list<Adjacent>::iterator it = find(neighbor);
- if (it != m_adjList.end())
- {
+ if (it != m_adjList.end()) {
(*it).setStatus(status);
}
}
@@ -183,23 +170,18 @@
{
uint32_t nbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin();
- it != m_adjList.end() ; it++)
- {
- if (((*it).getStatus() == 1))
- {
+ it != m_adjList.end() ; it++) {
+ if (((*it).getStatus() == 1)) {
nbrCount++;
}
- else
- {
+ else {
if ((*it).getInterestTimedOutNo() >=
- pnlsr.getConfParameter().getInterestRetryNumber())
- {
+ pnlsr.getConfParameter().getInterestRetryNumber()) {
nbrCount++;
}
}
}
- if (nbrCount == m_adjList.size())
- {
+ if (nbrCount == m_adjList.size()) {
return true;
}
return false;
@@ -210,10 +192,8 @@
{
int32_t actNbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin();
- it != m_adjList.end(); it++)
- {
- if (((*it).getStatus() == 1))
- {
+ it != m_adjList.end(); it++) {
+ if (((*it).getStatus() == 1)) {
actNbrCount++;
}
}
@@ -235,8 +215,7 @@
AdjacencyList::print()
{
for (std::list<Adjacent>::iterator it = m_adjList.begin();
- it != m_adjList.end(); it++)
- {
+ it != m_adjList.end(); it++) {
cout << (*it) << endl;
}
}
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index c3c2195..95600cc 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -71,8 +71,7 @@
void
reset()
{
- if (m_adjList.size() > 0)
- {
+ if (m_adjList.size() > 0) {
m_adjList.clear();
}
}
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index 94dceee..f27c4b8 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -10,11 +10,31 @@
using namespace std;
-Adjacent::Adjacent(const ndn::Name& an, uint32_t cf, double lc, uint32_t s,
- uint32_t iton)
+const float Adjacent::DEFAULT_LINK_COST = 10.0;
+
+Adjacent::Adjacent()
+ : m_name()
+ , m_connectingFaceUri()
+ , m_linkCost(DEFAULT_LINK_COST)
+ , m_status(ADJACENT_STATUS_INACTIVE)
+ , m_interestTimedOutNo(0)
+{
+}
+
+Adjacent::Adjacent(const ndn::Name& an)
+ : m_name(an)
+ , m_connectingFaceUri()
+ , m_linkCost(DEFAULT_LINK_COST)
+ , m_status(ADJACENT_STATUS_INACTIVE)
+ , m_interestTimedOutNo(0)
+ {
+ }
+
+Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
+ uint32_t s, uint32_t iton)
{
m_name = an;
- m_connectingFace = cf;
+ m_connectingFaceUri = cfu;
m_linkCost = lc;
m_status = s;
m_interestTimedOutNo = iton;
@@ -24,7 +44,7 @@
Adjacent::operator==(const Adjacent& adjacent) const
{
return (m_name == adjacent.getName()) &&
- (m_connectingFace == adjacent.getConnectingFace()) &&
+ (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
(std::abs(m_linkCost - adjacent.getLinkCost()) <
std::numeric_limits<double>::epsilon()) ;
}
@@ -39,7 +59,7 @@
operator<<(std::ostream& os, const Adjacent& adj)
{
os << "Adjacent : " << adj.getName() << endl;
- os << "Connecting Face: " << adj.getConnectingFace() << endl;
+ os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl;
os << "Link Cost: " << adj.getLinkCost() << endl;
os << "Status: " << adj.getStatus() << endl;
os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl;
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index bb043f8..cbfb0fa 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -6,30 +6,22 @@
#define NLSR_ADJACENT_HPP
namespace nlsr {
+
+enum {
+ ADJACENT_STATUS_INACTIVE = 0,
+ ADJACENT_STATUS_ACTIVE = 1
+};
+
class Adjacent
{
public:
- Adjacent()
- : m_name()
- , m_connectingFace(0)
- , m_linkCost(10.0)
- , m_status(0)
- , m_interestTimedOutNo(0)
- {
- }
+ Adjacent();
- Adjacent(const ndn::Name& an)
- : m_connectingFace(0)
- , m_linkCost(0.0)
- , m_status(0)
- , m_interestTimedOutNo(0)
- {
- m_name = an;
- }
+ Adjacent(const ndn::Name& an);
- Adjacent(const ndn::Name& an, uint32_t cf, double lc, uint32_t s,
- uint32_t iton);
+ Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
+ uint32_t s, uint32_t iton);
const ndn::Name&
getName() const
@@ -43,16 +35,16 @@
m_name = an;
}
- 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
@@ -97,9 +89,12 @@
bool
compare(const ndn::Name& adjacencyName);
+public:
+ static const float DEFAULT_LINK_COST;
+
private:
ndn::Name m_name;
- uint32_t m_connectingFace;
+ std::string m_connectingFaceUri;
double m_linkCost;
uint32_t m_status;
uint32_t m_interestTimedOutNo;
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 10a40ec..85b1da0 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -14,12 +14,12 @@
{
std::cout << "Creating Sync socket ......" << std::endl;
std::cout << "Sync prefix: " << m_syncPrefix << std::endl;
- m_syncSocket = make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
- m_syncFace,
- bind(&SyncLogicHandler::nsyncUpdateCallBack, this,
- _1, _2, boost::ref(pnlsr)),
- bind(&SyncLogicHandler::nsyncRemoveCallBack, this,
- _1, boost::ref(pnlsr)));
+ m_syncSocket = ndn::make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
+ m_syncFace,
+ ndn::bind(&SyncLogicHandler::nsyncUpdateCallBack,
+ this, _1, _2, ndn::ref(pnlsr)),
+ ndn::bind(&SyncLogicHandler::nsyncRemoveCallBack,
+ this, _1, ndn::ref(pnlsr)));
}
void
@@ -28,8 +28,7 @@
{
std::cout << "nsyncUpdateCallBack called ...." << std::endl;
int32_t n = v.size();
- for (int32_t i = 0; i < n; i++)
- {
+ for (int32_t i = 0; i < n; i++){
std::cout << "Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq() <<
endl;
processUpdateFromSync(v[i].prefix, v[i].high.getSeq(), pnlsr);
@@ -51,11 +50,9 @@
SyncLogicHandler::processUpdateFromSync(const ndn::Name& updateName,
uint64_t seqNo, Nlsr& pnlsr)
{
- //const ndn::Name name(updateName);
string chkString("LSA");
int32_t lasPosition = util::getNameComponentPosition(updateName, chkString);
- if (lasPosition >= 0)
- {
+ if (lasPosition >= 0) {
ndn::Name routerName = updateName.getSubName(lasPosition + 1);
processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
return;
@@ -67,17 +64,14 @@
uint64_t seqNo, Nlsr& pnlsr)
{
ndn::Name rName = routerName;
- if (routerName != pnlsr.getConfParameter().getRouterPrefix())
- {
+ if (routerName != pnlsr.getConfParameter().getRouterPrefix()) {
SequencingManager sm(seqNo);
std::cout << sm;
std::cout << "Router Name: " << routerName << endl;
- try
- {
- if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq()))
- {
+ try {
+ if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq())) {
std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
- ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+ ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("name");
interestName.appendNumber(sm.getNameLsaSeq());
@@ -85,10 +79,9 @@
pnlsr.getConfParameter().getInterestResendTime());
}
if (pnlsr.getLsdb().isAdjLsaNew(rName.append("adjacency"),
- sm.getAdjLsaSeq()))
- {
+ sm.getAdjLsaSeq())) {
std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
- ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+ ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("adjacency");
interestName.appendNumber(sm.getAdjLsaSeq());
@@ -96,10 +89,9 @@
pnlsr.getConfParameter().getInterestResendTime());
}
if (pnlsr.getLsdb().isCoordinateLsaNew(rName.append("coordinate"),
- sm.getCorLsaSeq()))
- {
+ sm.getCorLsaSeq())) {
std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
- ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+ ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("coordinate");
interestName.appendNumber(sm.getCorLsaSeq());
@@ -107,8 +99,7 @@
pnlsr.getConfParameter().getInterestResendTime());
}
}
- catch (std::exception& e)
- {
+ catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return;
}
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 1f62554..739f90b 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -7,7 +7,6 @@
#include <ndn-cxx/face.hpp>
#include <nsync/sync-socket.h>
#include <ndn-cxx/security/validator-null.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
#include "sequencing-manager.hpp"
@@ -26,7 +25,8 @@
SyncLogicHandler(boost::asio::io_service& ioService)
: m_validator(new ndn::ValidatorNull())
, m_syncFace(new ndn::Face(ioService))
- {}
+ {
+ }
void
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 18ae0a5..7726869 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -1,551 +1,352 @@
#include <iostream>
#include <fstream>
-#include <string>
-#include <cstdlib>
-#include <sstream>
+#include <boost/algorithm/string.hpp>
+#include <boost/property_tree/info_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
-#include "conf-file-processor.hpp"
+#include <ndn-cxx/name.hpp>
+
#include "conf-parameter.hpp"
-#include "utility/tokenizer.hpp"
+#include "conf-file-processor.hpp"
#include "adjacent.hpp"
+#include "utility/name-helper.hpp"
namespace nlsr {
using namespace std;
-int
+bool
ConfFileProcessor::processConfFile()
{
- int ret = 0;
- if (!m_confFileName.empty())
+ bool ret = true;
+ ifstream inputFile;
+ inputFile.open(m_confFileName.c_str());
+ if (!inputFile.is_open()) {
+ string msg = "Failed to read configuration file: ";
+ msg += m_confFileName;
+ cerr << msg << endl;
+ ret = false;
+ }
+ ret = load(inputFile);
+ inputFile.close();
+ return ret;
+}
+
+bool
+ConfFileProcessor::load(istream& input)
+{
+ boost::property_tree::ptree pt;
+ bool ret = true;
+ try {
+ boost::property_tree::read_info(input, pt);
+ }
+ catch (const boost::property_tree::info_parser_error& error) {
+ stringstream msg;
+ std::cerr << "Failed to parse configuration file " << std::endl;
+ std::cerr << m_confFileName << std::endl;
+ return false;
+ }
+ for (boost::property_tree::ptree::const_iterator tn = pt.begin();
+ tn != pt.end(); ++tn) {
+ std::string section = tn->first;
+ boost::property_tree::ptree SectionAttributeTree = tn ->second;
+ ret = processSection(section, SectionAttributeTree);
+ if (ret == false) {
+ break;
+ }
+ }
+ return ret;
+}
+
+bool
+ConfFileProcessor::processSection(const std::string& section,
+ boost::property_tree::ptree SectionAttributeTree)
+{
+ bool ret = true;
+ if (section == "general")
{
- std::ifstream inputFile(m_confFileName.c_str());
- if (inputFile.is_open())
+ ret = processConfSectionGeneral(SectionAttributeTree);
+ }
+ else if (section == "neighbors")
+ {
+ ret = processConfSectionNeighbors(SectionAttributeTree);
+ }
+ else if (section == "hyperbolic")
+ {
+ ret = processConfSectionHyperbolic(SectionAttributeTree);
+ }
+ else if (section == "fib")
+ {
+ ret = processConfSectionFib(SectionAttributeTree);
+ }
+ else if (section == "advertising")
+ {
+ ret = processConfSectionAdvertising(SectionAttributeTree);
+ }
+ else
+ {
+ std::cerr << "Wrong configuration Command: " << section << std::endl;
+ }
+ return ret;
+}
+
+bool
+ConfFileProcessor::processConfSectionGeneral(boost::property_tree::ptree
+ SectionAttributeTree)
+{
+ try {
+ std::string network = SectionAttributeTree.get<string>("network");
+ std::string site = SectionAttributeTree.get<string>("site");
+ std::string router = SectionAttributeTree.get<string>("router");
+ ndn::Name networkName(network);
+ if (!networkName.empty()) {
+ m_nlsr.getConfParameter().setNetwork(networkName);
+ }
+ else {
+ cerr << " Network can not be null or empty or in bad URI format :(!" << endl;
+ return false;
+ }
+ ndn::Name siteName(site);
+ if (!siteName.empty()) {
+ m_nlsr.getConfParameter().setSiteName(siteName);
+ }
+ else {
+ cerr << "Site can not be null or empty or in bad URI format:( !" << endl;
+ return false;
+ }
+ ndn::Name routerName(router);
+ if (!routerName.empty()) {
+ m_nlsr.getConfParameter().setRouterName(routerName);
+ }
+ else {
+ cerr << " Router name can not be null or empty or in bad URI format:( !" << endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ cerr << ex.what() << endl;
+ return false;
+ }
+
+ try {
+ int32_t lsaRefreshTime = SectionAttributeTree.get<int32_t>("lsa-refresh-time");
+ if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN &&
+ lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
+ m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
+ }
+ else {
+ std::cerr << "Wrong value for lsa-refresh-time ";
+ std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";;
+ std::cerr << LSA_REFRESH_TIME_MAX << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
+
+ try {
+ std::string logLevel = SectionAttributeTree.get<string>("log-level");
+ if ( boost::iequals(logLevel, "info") || boost::iequals(logLevel, "debug")) {
+ m_nlsr.getConfParameter().setLogLevel(logLevel);
+ }
+ else {
+ std::cerr << "Wrong value for log-level ";
+ std::cerr << "Allowed value: INFO, DEBUG" << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+bool
+ConfFileProcessor::processConfSectionNeighbors(boost::property_tree::ptree
+ SectionAttributeTree)
+{
+ try {
+ int retrials = SectionAttributeTree.get<int>("hello-retries");
+ if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
+ m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
+ }
+ else {
+ std::cerr << "Wrong value for hello-retries. ";
+ std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
+ std::cerr << HELLO_RETRIES_MAX << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
+ try {
+ int timeOut = SectionAttributeTree.get<int>("hello-timeout");
+ if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
+ m_nlsr.getConfParameter().setInterestResendTime(timeOut);
+ }
+ else {
+ std::cerr << "Wrong value for hello-timeout. ";
+ std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
+ std::cerr << HELLO_TIMEOUT_MAX << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ }
+ try {
+ int interval = SectionAttributeTree.get<int>("hello-interval");
+ if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
+ m_nlsr.getConfParameter().setInfoInterestInterval(interval);
+ }
+ else {
+ std::cerr << "Wrong value for hello-interval. ";
+ std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
+ std::cerr << HELLO_INTERVAL_MAX << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ }
+ for (boost::property_tree::ptree::const_iterator tn =
+ SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) {
+
+ if (tn->first == "neighbor")
{
- for (string line; getline(inputFile, line);)
- {
- if (!line.empty())
- {
- if (line[0] != '#' && line[0] != '!')
- {
- ret = processConfCommand(line);
- if (ret == -1)
- {
- break;
- }
- }
+ try {
+ boost::property_tree::ptree CommandAttriTree = tn->second;
+ std::string name = CommandAttriTree.get<std::string>("name");
+ std::string faceUri = CommandAttriTree.get<std::string>("face-uri");
+ double linkCost = CommandAttriTree.get<double>("link-cost",
+ Adjacent::DEFAULT_LINK_COST);
+ ndn::Name neighborName(name);
+ if (!neighborName.empty()) {
+ Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0);
+ m_nlsr.getAdjacencyList().insert(adj);
+ }
+ else {
+ cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
+ std::cerr << " or bad URI format" << std::endl;
}
}
- }
- else
- {
- std::cerr << "Configuration file: (" << m_confFileName << ") does not exist :(";
- std::cerr << endl;
- ret = -1;
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
}
}
- return ret;
+ return true;
}
-
-int
-ConfFileProcessor::processConfCommand(string command)
+bool
+ConfFileProcessor::processConfSectionHyperbolic(boost::property_tree::ptree
+ SectionAttributeTree)
{
- int ret = 0;
- Tokenizer nt(command, " ");
- if ((nt.getFirstToken() == "network"))
- {
- ret = processConfCommandNetwork(nt.getRestOfLine());
+ std::string state;
+ try {
+ state= SectionAttributeTree.get<string>("state","off");
+ if (boost::iequals(state, "off")) {
+ m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
+ }
+ else if (boost::iequals(state, "on")) {
+ m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
+ }
+ else if (state == "dry-run") {
+ m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
+ }
+ else {
+ std::cerr << "Wrong format for hyperbolic state." << std::endl;
+ std::cerr << "Allowed value: off, on, dry-run" << std::endl;
+ return false;
+ }
}
- else if ((nt.getFirstToken() == "site-name"))
- {
- ret = processConfCommandSiteName(nt.getRestOfLine());
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
}
- else if ((nt.getFirstToken() == "root-key-prefix"))
- {
- ret = processConfCommandRootKeyPrefix(nt.getRestOfLine());
+
+ try {
+ /* Radius and angle is mandatory configuration parameter in hyperbolic section.
+ * Even if router can have hyperbolic routing calculation off but other router
+ * in the network may use hyperbolic routing calculation for FIB generation.
+ * So each router need to advertise its hyperbolic coordinates in the network
+ */
+ double radius = SectionAttributeTree.get<double>("radius");
+ double angle = SectionAttributeTree.get<double>("angle");
+ if (!m_nlsr.getConfParameter().setCorR(radius)) {
+ return false;
+ }
+ m_nlsr.getConfParameter().setCorTheta(angle);
}
- else if ((nt.getFirstToken() == "router-name"))
- {
- ret = processConfCommandRouterName(nt.getRestOfLine());
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ if (state == "on" || state == "dry-run") {
+ return false;
+ }
}
- else if ((nt.getFirstToken() == "ndnneighbor"))
- {
- ret = processConfCommandNdnNeighbor(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "link-cost"))
- {
- ret = processConfCommandLinkCost(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "ndnname"))
- {
- ret = processConfCommandNdnName(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "interest-retry-num"))
- {
- processConfCommandInterestRetryNumber(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "interest-resend-time"))
- {
- processConfCommandInterestResendTime(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "lsa-refresh-time"))
- {
- processConfCommandLsaRefreshTime(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "max-faces-per-prefix"))
- {
- processConfCommandMaxFacesPerPrefix(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "log-dir"))
- {
- processConfCommandLogDir(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "cert-dir"))
- {
- processConfCommandCertDir(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "detailed-logging"))
- {
- processConfCommandDetailedLogging(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "debugging"))
- {
- processConfCommandDebugging(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "chronosync-sync-prefix"))
- {
- processConfCommandChronosyncSyncPrefix(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "hyperbolic-cordinate"))
- {
- processConfCommandHyperbolicCordinate(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "hyperbolic-routing"))
- {
- processConfCommandIsHyperbolicCalc(nt.getRestOfLine());
- }
- else if ((nt.getFirstToken() == "tunnel-type"))
- {
- processConfCommandTunnelType(nt.getRestOfLine());
- }
- else
- {
- cout << "Wrong configuration Command: " << nt.getFirstToken() << endl;
- }
- return ret;
+
+ return true;
}
-int
-ConfFileProcessor::processConfCommandNetwork(string command)
+bool
+ConfFileProcessor::processConfSectionFib(boost::property_tree::ptree
+ SectionAttributeTree)
{
- if (command.empty())
- {
- cerr << " Network can not be null or empty :( !" << endl;
- return -1;
- }
- else
- {
- if (command[command.size() - 1] == '/')
+ try {
+ int maxFacesPerPrefixNumber =
+ SectionAttributeTree.get<int>("max-faces-per-prefix");
+ if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN &&
+ maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX)
{
- command.erase(command.size() - 1);
+ m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber);
}
- if (command[0] == '/')
- {
- command.erase(0, 1);
+ else {
+ std::cerr << "Wrong value for max-faces-per-prefix. ";
+ std::cerr << "NLSR will user default value";
+ std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
+ return false;
}
- m_nlsr.getConfParameter().setNetwork(command);
}
- return 0;
+ catch (const std::exception& ex) {
+ cerr << ex.what() << endl;
+ return false;
+ }
+ return true;
}
-int
-ConfFileProcessor::processConfCommandSiteName(string command)
+bool
+ConfFileProcessor::processConfSectionAdvertising(boost::property_tree::ptree
+ SectionAttributeTree)
{
- if (command.empty())
- {
- cerr << "Site name can not be null or empty :( !" << endl;
- return -1;
- }
- else
- {
- if (command[command.size() - 1] == '/')
- {
- command.erase(command.size() - 1);
+ for (boost::property_tree::ptree::const_iterator tn =
+ SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) {
+ if (tn->first == "prefix") {
+ try {
+ std::string prefix = tn->second.data();
+ ndn::Name namePrefix(prefix);
+ if (!namePrefix.empty()) {
+ m_nlsr.getNamePrefixList().insert(namePrefix);
+ }
+ else {
+ std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI";
+ std::cerr << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
}
- if (command[0] == '/')
- {
- command.erase(0, 1);
- }
- m_nlsr.getConfParameter().setSiteName(command);
}
- return 0;
+ return true;
}
-
-int
-ConfFileProcessor::processConfCommandRootKeyPrefix(string command)
-{
- if (command.empty())
- {
- cerr << "Root Key Prefix can not be null or empty :( !" << endl;
- return -1;
- }
- else
- {
- if (command[command.size() - 1] == '/')
- {
- command.erase(command.size() - 1);
- }
- if (command[0] == '/')
- {
- command.erase(0, 1);
- }
- m_nlsr.getConfParameter().setRootKeyPrefix(command);
- }
- return 0;
-}
-
-
-int
-ConfFileProcessor::processConfCommandRouterName(string command)
-{
- if (command.empty())
- {
- cerr << " Router name can not be null or empty :( !" << endl;
- return -1;
- }
- else
- {
- if (command[command.size() - 1] == '/')
- {
- command.erase(command.size() - 1);
- }
- if (command[0] == '/')
- {
- command.erase(0, 1);
- }
- m_nlsr.getConfParameter().setRouterName(command);
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandInterestRetryNumber(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [interest-retry-num n]" << endl;
- }
- else
- {
- int irn;
- stringstream ss(command.c_str());
- ss >> irn;
- if (irn >= 1 && irn <= 5)
- {
- m_nlsr.getConfParameter().setInterestRetryNumber(irn);
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandInterestResendTime(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [interest-resend-time s]" << endl;
- }
- else
- {
- int irt;
- stringstream ss(command.c_str());
- ss >> irt;
- if (irt >= 1 && irt <= 20)
- {
- m_nlsr.getConfParameter().setInterestResendTime(irt);
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandLsaRefreshTime(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [interest-resend-time s]" << endl;
- }
- else
- {
- int lrt;
- stringstream ss(command.c_str());
- ss >> lrt;
- if (lrt >= 240 && lrt <= 7200)
- {
- m_nlsr.getConfParameter().setLsaRefreshTime(lrt);
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandMaxFacesPerPrefix(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [max-faces-per-prefix n]" << endl;
- }
- else
- {
- int mfpp;
- stringstream ss(command.c_str());
- ss >> mfpp;
- if (mfpp >= 0 && mfpp <= 60)
- {
- m_nlsr.getConfParameter().setMaxFacesPerPrefix(mfpp);
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandTunnelType(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl;
- }
- else
- {
- if (command == "tcp" || command == "TCP")
- {
- m_nlsr.getConfParameter().setTunnelType(1);
- }
- else if (command == "udp" || command == "UDP")
- {
- m_nlsr.getConfParameter().setTunnelType(0);
- }
- else
- {
- cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl;
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandChronosyncSyncPrefix(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [chronosync-sync-prefix name/prefix]!" << endl;
- }
- else
- {
- m_nlsr.getConfParameter().setChronosyncSyncPrefix(command);
- }
- return 0;
-}
-
-
-int
-ConfFileProcessor::processConfCommandLogDir(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [log-dir /path/to/log/dir]!" << endl;
- }
- else
- {
- m_nlsr.getConfParameter().setLogDir(command);
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandCertDir(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [cert-dir /path/to/cert/dir]!" << endl;
- }
- else
- {
- m_nlsr.getConfParameter().setCertDir(command);
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandDebugging(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [debugging on/of]!" << endl;
- }
- else
- {
- if (command == "on" || command == "ON")
- {
- m_nlsr.getConfParameter().setDebugging(1);
- }
- else if (command == "off" || command == "off")
- {
- m_nlsr.getConfParameter().setDebugging(0);
- }
- else
- {
- cerr << " Wrong command format ! [debugging on/off]!" << endl;
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandDetailedLogging(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [detailed-logging on/off]!" << endl;
- }
- else
- {
- if (command == "on" || command == "ON")
- {
- m_nlsr.getConfParameter().setDetailedLogging(1);
- }
- else if (command == "off" || command == "off")
- {
- m_nlsr.getConfParameter().setDetailedLogging(0);
- }
- else
- {
- cerr << " Wrong command format ! [detailed-logging on/off]!" << endl;
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandIsHyperbolicCalc(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl;
- }
- else
- {
- if (command == "on" || command == "ON")
- {
- m_nlsr.getConfParameter().setIsHyperbolicCalc(1);
- }
- else if (command == "dry-run" || command == "DRY-RUN")
- {
- m_nlsr.getConfParameter().setIsHyperbolicCalc(2);
- }
- else if (command == "off" || command == "off")
- {
- m_nlsr.getConfParameter().setIsHyperbolicCalc(0);
- }
- else
- {
- cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl;
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandHyperbolicCordinate(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [hyperbolic-cordinate r 0]!" << endl;
- if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0)
- {
- return -1;
- }
- }
- else
- {
- Tokenizer nt(command, " ");
- stringstream ssr(nt.getFirstToken().c_str());
- stringstream sst(nt.getRestOfLine().c_str());
- double r, theta;
- ssr >> r;
- sst >> theta;
- m_nlsr.getConfParameter().setCorR(r);
- m_nlsr.getConfParameter().setCorTheta(theta);
- }
- return 0;
-}
-
-
-int
-ConfFileProcessor::processConfCommandNdnNeighbor(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl;
- }
- else
- {
- Tokenizer nt(command, " ");
- if (nt.getRestOfLine().empty())
- {
- cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl;
- return 0;
- }
- else
- {
- stringstream sst(nt.getRestOfLine().c_str());
- int faceId;
- sst >> faceId;
- Adjacent adj(nt.getFirstToken(), faceId, 10, 0, 0);
- m_nlsr.getAdjacencyList().insert(adj);
- }
- }
- return 0;
-}
-
-int
-ConfFileProcessor::processConfCommandNdnName(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [ndnname name/prefix]!" << endl;
- }
- else
- {
- m_nlsr.getNamePrefixList().insert(command);
- }
- return 0;
-}
-
-
-int
-ConfFileProcessor::processConfCommandLinkCost(string command)
-{
- if (command.empty())
- {
- cerr << " Wrong command format ! [link-cost nbr/name cost]!" << endl;
- if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0)
- {
- return -1;
- }
- }
- else
- {
- Tokenizer nt(command, " ");
- stringstream sst(nt.getRestOfLine().c_str());
- double cost;
- sst >> cost;
- m_nlsr.getAdjacencyList().updateAdjacentLinkCost(nt.getFirstToken(), cost);
- }
- return 0;
-}
-
-} //namespace nlsr
-
+}//namespace NLSR
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index 61265b7..b12e8f9 100644
--- a/src/conf-file-processor.hpp
+++ b/src/conf-file-processor.hpp
@@ -1,7 +1,10 @@
-#ifndef CONF_FILE_PROCESSOR_HPP
-#define CONF_FILE_PROCESSOR_HPP
+#ifndef CONF_PROCESSOR_HPP
+#define CONF_PROCESSOR_HPP
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <boost/property_tree/ptree.hpp>
#include <boost/cstdint.hpp>
+
#include "nlsr.hpp"
namespace nlsr {
@@ -15,69 +18,31 @@
{
}
- int processConfFile();
+ bool
+ processConfFile();
private:
- int
- processConfCommand(std::string command);
+ bool
+ load(std::istream& input);
- int
- processConfCommandNetwork(std::string command);
+ bool
+ processSection(const std::string& section,
+ boost::property_tree::ptree SectionAttributeTree);
- int
- processConfCommandSiteName(std::string command);
+ bool
+ processConfSectionGeneral(boost::property_tree::ptree SectionAttributeTree);
- int
- processConfCommandRootKeyPrefix(std::string command);
+ bool
+ processConfSectionNeighbors(boost::property_tree::ptree SectionAttributeTree);
- int
- processConfCommandRouterName(std::string command);
+ bool
+ processConfSectionHyperbolic(boost::property_tree::ptree SectionAttributeTree);
- int
- processConfCommandInterestRetryNumber(std::string command);
+ bool
+ processConfSectionFib(boost::property_tree::ptree SectionAttributeTree);
- int
- processConfCommandInterestResendTime(std::string command);
-
- int
- processConfCommandLsaRefreshTime(std::string command);
-
- int
- processConfCommandMaxFacesPerPrefix(std::string command);
-
- int
- processConfCommandTunnelType(std::string command);
-
- int
- processConfCommandChronosyncSyncPrefix(std::string command);
-
- int
- processConfCommandLogDir(std::string command);
-
- int
- processConfCommandCertDir(std::string command);
-
- int
- processConfCommandDebugging(std::string command);
-
- int
- processConfCommandDetailedLogging(std::string command);
-
- int
- processConfCommandIsHyperbolicCalc(std::string command);
-
- int
- processConfCommandHyperbolicCordinate(std::string command);
-
- int
- processConfCommandNdnNeighbor(std::string command);
-
- int
- processConfCommandNdnName(std::string command);
-
- int
- processConfCommandLinkCost(std::string command);
-
+ bool
+ processConfSectionAdvertising(boost::property_tree::ptree SectionAttributeTree);
private:
std::string m_confFileName;
@@ -85,4 +50,4 @@
};
} //namespace nlsr
-#endif //CONF_FILE_PROCESSOR_HPP
+#endif //CONF_PROCESSOR_HPP
diff --git a/src/conf-parameter.cpp b/src/conf-parameter.cpp
deleted file mode 100644
index 2bb337f..0000000
--- a/src/conf-parameter.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <iostream>
-#include "conf-parameter.hpp"
-
-namespace nlsr {
-
-using namespace std;
-
-ostream&
-operator<<(ostream& os, ConfParameter& cfp)
-{
- os << "Router Name: " << cfp.getRouterName() << endl;
- os << "Site Name: " << cfp.getSiteName() << endl;
- os << "Network: " << cfp.getNetwork() << endl;
- os << "Router Prefix: " << cfp.getRouterPrefix() << endl;
- os << "ChronoSync sync Prifex: " << cfp.getChronosyncSyncPrefix() << endl;
- os << "Interest Retry number: " << cfp.getInterestRetryNumber() << endl;
- os << "Interest Resend second: " << cfp.getInterestResendTime() << endl;
- os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << endl;
- os << "LSA refresh time: " << cfp.getLsaRefreshTime() << endl;
- os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << endl;
- os << "Log Dir: " << cfp.getLogDir() << endl;
- os << "Detalied logging: " << cfp.getDetailedLogging() << endl;
- os << "Debugging: " << cfp.getDebugging() << endl;
- os << "Hyperbolic ROuting: " << cfp.getIsHyperbolicCalc() << endl;
- os << "Hyp R: " << cfp.getCorR() << endl;
- os << "Hyp theta: " << cfp.getCorTheta() << endl;
- os << "Tunnel Type: " << cfp.getTunnelType() << endl;
- return os;
-}
-
-} //namespace nlsr
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 5b5b560..6f1dc86 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -7,58 +7,70 @@
#include <ndn-cxx/face.hpp>
namespace nlsr {
+
+enum {
+ LSA_REFRESH_TIME_MIN = 240,
+ LSA_REFRESH_TIME_DEFAULT = 1800,
+ LSA_REFRESH_TIME_MAX = 7200
+};
+
+enum {
+ HELLO_RETRIES_MIN = 1,
+ HELLO_RETRIES_DEFAULT = 3,
+ HELLO_RETRIES_MAX = 15
+};
+
+enum {
+ HELLO_TIMEOUT_MIN = 1,
+ HELLO_TIMEOUT_DEFAULT = 3,
+ HELLO_TIMEOUT_MAX = 15
+};
+
+enum {
+ HELLO_INTERVAL_MIN = 30,
+ HELLO_INTERVAL_DEFAULT = 60,
+ HELLO_INTERVAL_MAX =90
+};
+
+enum {
+ MAX_FACES_PER_PREFIX_MIN = 0,
+ MAX_FACES_PER_PREFIX_MAX = 60
+};
+
+enum {
+ HYPERBOLIC_STATE_OFF = 0,
+ HYPERBOLIC_STATE_ON = 1,
+ HYPERBOLIC_STATE_DRY_RUN = 2
+};
+
class ConfParameter
{
public:
ConfParameter()
- : m_chronosyncSyncPrefix("ndn/nlsr/sync")
- , m_chronosyncLsaPrefix("/ndn/nlsr/LSA")
- , m_rootKeyPrefix("/ndn/keys")
- , m_interestRetryNumber(3)
- , m_interestResendTime(5)
- , m_infoInterestInterval(60)
- , m_lsaRefreshTime(1800)
- , m_routerDeadInterval(3600)
- , m_maxFacesPerPrefix(0)
- , m_tunnelType(0)
- , m_detailedLogging(0)
- , m_certDir()
- , m_debugging(0)
- , m_seqFileDir()
- , m_isHyperbolicCalc(0)
+ : m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
+ , m_routerDeadInterval(2*LSA_REFRESH_TIME_DEFAULT)
+ , m_logLevel("INFO")
+ , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
+ , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
+ , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
+ , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
, m_corR(0)
, m_corTheta(0)
+ , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
{}
void
- setRouterName(const std::string& rn)
+ setNetwork(const ndn::Name& networkName)
{
- m_routerName = ndn::Name(rn);
- }
-
- const ndn::Name&
- getRouterName()
- {
- return m_routerName;
- }
-
- void
- setSiteName(const std::string& sn)
- {
- m_siteName = ndn::Name(sn);
- }
-
- const ndn::Name&
- getSiteName()
- {
- return m_siteName;
- }
-
- void
- setNetwork(const std::string& nn)
- {
- m_network = ndn::Name(nn);
+ m_network = networkName;
+ m_chronosyncPrefix = m_network;
+ m_chronosyncPrefix.append("nlsr");
+ m_chronosyncPrefix.append("sync");
+
+ m_lsaPrefix = m_network;
+ m_lsaPrefix.append("nlsr");
+ m_lsaPrefix.append("LSA");
}
const ndn::Name&
@@ -68,9 +80,32 @@
}
void
+ setRouterName(const ndn::Name& routerName)
+ {
+ m_routerName = routerName;
+ }
+
+ const ndn::Name&
+ getRouterName()
+ {
+ return m_routerName;
+ }
+
+ void
+ setSiteName(const ndn::Name& siteName)
+ {
+ m_siteName = siteName;
+ }
+
+ const ndn::Name&
+ getSiteName()
+ {
+ return m_siteName;
+ }
+
+ void
buildRouterPrefix()
{
- //m_routerPrefix = "/" + m_network + "/" + m_siteName + "/" + m_routerName;
m_routerPrefix = m_network;
m_routerPrefix.append(m_siteName);
m_routerPrefix.append(m_routerName);
@@ -82,40 +117,17 @@
return m_routerPrefix;
}
+
const ndn::Name&
- getRootKeyPrefix()
+ getChronosyncPrefix()
{
- return m_rootKeyPrefix;
+ return m_chronosyncPrefix;
}
- void
- setRootKeyPrefix(std::string rkp)
+ const ndn::Name&
+ getLsaPrefix()
{
- m_rootKeyPrefix = ndn::Name(rkp);
- }
-
- void
- setInterestRetryNumber(uint32_t irn)
- {
- m_interestRetryNumber = irn;
- }
-
- uint32_t
- getInterestRetryNumber()
- {
- return m_interestRetryNumber;
- }
-
- void
- setInterestResendTime(int32_t irt)
- {
- m_interestResendTime = irt;
- }
-
- int32_t
- getInterestResendTime()
- {
- return m_interestResendTime;
+ return m_lsaPrefix;
}
void
@@ -142,95 +154,75 @@
{
return m_routerDeadInterval;
}
+
+ void
+ setLogLevel(const std::string& logLevel)
+ {
+ m_logLevel = logLevel;
+ }
+
+ const std::string&
+ getLogLevel()
+ {
+ return m_logLevel;
+ }
void
- setMaxFacesPerPrefix(int32_t mfpp)
+ setInterestRetryNumber(uint32_t irn)
{
- m_maxFacesPerPrefix = mfpp;
+ m_interestRetryNumber = irn;
+ }
+
+ uint32_t
+ getInterestRetryNumber()
+ {
+ return m_interestRetryNumber;
+ }
+
+ void
+ setInterestResendTime(int32_t irt)
+ {
+ m_interestResendTime = irt;
}
int32_t
- getMaxFacesPerPrefix()
+ getInterestResendTime()
{
- return m_maxFacesPerPrefix;
- }
-
- void
- setLogDir(const std::string& ld)
- {
- m_logDir = ld;
- }
-
- std::string
- getLogDir()
- {
- return m_logDir;
- }
-
- void
- setCertDir(const std::string& cd)
- {
- m_certDir = cd;
- }
-
- const std::string&
- getCertDir()
- {
- return m_certDir;
- }
-
- void
- setSeqFileDir(const std::string& ssfd)
- {
- m_seqFileDir = ssfd;
- }
-
- const std::string&
- getSeqFileDir()
- {
- return m_seqFileDir;
- }
-
- void
- setDetailedLogging(int dl)
- {
- m_detailedLogging = dl;
- }
-
- int
- getDetailedLogging()
- {
- return m_detailedLogging;
- }
-
- void
- setDebugging(int32_t d)
- {
- m_debugging = d;
+ return m_interestResendTime;
}
int32_t
- getDebugging()
+ getInfoInterestInterval()
{
- return m_debugging;
+ return m_infoInterestInterval;
}
void
- setIsHyperbolicCalc(int32_t ihc)
+ setInfoInterestInterval(int32_t iii)
{
- m_isHyperbolicCalc = ihc;
+ m_infoInterestInterval = iii;
+ }
+
+ void
+ setHyperbolicState(int32_t ihc)
+ {
+ m_hyperbolicState = ihc;
}
int32_t
- getIsHyperbolicCalc()
+ getHyperbolicState()
{
- return m_isHyperbolicCalc;
+ return m_hyperbolicState;
}
- void
+ bool
setCorR(double cr)
{
- m_corR = cr;
+ if ( cr >= 0 ) {
+ m_corR = cr;
+ return true;
+ }
+ return false;
}
double
@@ -250,54 +242,31 @@
{
return m_corTheta;
}
-
+
void
- setTunnelType(int tt)
+ setMaxFacesPerPrefix(int32_t mfpp)
{
- m_tunnelType = tt;
+ m_maxFacesPerPrefix = mfpp;
}
int32_t
- getTunnelType()
+ getMaxFacesPerPrefix()
{
- return m_tunnelType;
+ return m_maxFacesPerPrefix;
}
void
- setChronosyncSyncPrefix(const std::string& csp)
+ setSeqFileDir(const std::string& ssfd)
{
- m_chronosyncSyncPrefix = ndn::Name(csp);
+ m_seqFileDir = ssfd;
}
- const ndn::Name&
- getChronosyncSyncPrefix()
+ const std::string&
+ getSeqFileDir()
{
- return m_chronosyncSyncPrefix;
+ return m_seqFileDir;
}
- void
- setChronosyncLsaPrefix(const std::string& clp)
- {
- m_chronosyncLsaPrefix = ndn::Name(clp);
- }
-
- const ndn::Name&
- getChronosyncLsaPrefix()
- {
- return m_chronosyncLsaPrefix;
- }
-
- int32_t
- getInfoInterestInterval()
- {
- return m_infoInterestInterval;
- }
-
- void
- setInfoInterestInterval(int32_t iii)
- {
- m_infoInterestInterval = iii;
- }
private:
ndn::Name m_routerName;
@@ -307,35 +276,48 @@
ndn::Name m_routerPrefix;
ndn::Name m_lsaRouterPrefix;
- ndn::Name m_chronosyncSyncPrefix;
- ndn::Name m_chronosyncLsaPrefix;
- ndn::Name m_rootKeyPrefix;
+ ndn::Name m_chronosyncPrefix;
+ ndn::Name m_lsaPrefix;
+
+ int32_t m_lsaRefreshTime;
+ int64_t m_routerDeadInterval;
+ std::string m_logLevel;
uint32_t m_interestRetryNumber;
- int32_t m_interestResendTime;
- int32_t m_infoInterestInterval;
- int32_t m_lsaRefreshTime;
- int64_t m_routerDeadInterval;
-
- int32_t m_maxFacesPerPrefix;
- int32_t m_tunnelType;
- int32_t m_detailedLogging;
-
- std::string m_certDir;
- int32_t m_debugging;
- std::string m_seqFileDir;
-
- int32_t m_isHyperbolicCalc;
+ int32_t m_interestResendTime;
+
+
+ int32_t m_infoInterestInterval;
+
+ int32_t m_hyperbolicState;
double m_corR;
double m_corTheta;
- std::string m_logFile;
- std::string m_logDir;
+ int32_t m_maxFacesPerPrefix;
+
+ std::string m_seqFileDir;
};
-std::ostream&
-operator<<(std::ostream& os, ConfParameter& cfp);
+inline std::ostream&
+operator<<(std::ostream& os, ConfParameter& cfp)
+{
+ os << "Router Name: " << cfp.getRouterName() << std::endl;
+ os << "Site Name: " << cfp.getSiteName() << std::endl;
+ os << "Network: " << cfp.getNetwork() << std::endl;
+ os << "Router Prefix: " << cfp.getRouterPrefix() << std::endl;
+ os << "ChronoSync sync Prifex: " << cfp.getChronosyncPrefix() << std::endl;
+ os << "ChronoSync LSA prefix: " << cfp.getLsaPrefix() << std::endl;
+ os << "Interest Retry number: " << cfp.getInterestRetryNumber() << std::endl;
+ os << "Interest Resend second: " << cfp.getInterestResendTime() << std::endl;
+ os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << std::endl;
+ os << "LSA refresh time: " << cfp.getLsaRefreshTime() << std::endl;
+ os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << std::endl;
+ os << "Hyperbolic ROuting: " << cfp.getHyperbolicState() << std::endl;
+ os << "Hyp R: " << cfp.getCorR() << std::endl;
+ os << "Hyp theta: " << cfp.getCorTheta() << std::endl;
+ return os;
+}
} // namespace nlsr
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index ccc2f5b..2dc106c 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -5,6 +5,8 @@
namespace nlsr {
+const std::string HelloProtocol::INFO_COMPONENT="info";
+
void
HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
{
@@ -25,11 +27,10 @@
{
std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
- ++it)
- {
+ ++it) {
ndn::Name interestName = (*it).getName() ;
- interestName.append("info");
- interestName.append(ndn::Name(m_nlsr.getConfParameter().getRouterPrefix()));
+ interestName.append(INFO_COMPONENT);
+ interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
@@ -50,27 +51,24 @@
{
const ndn::Name interestName = interest.getName();
std::cout << "Interest Received for Name: " << interestName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(interestName, chkString);
- if (infoPosition < 0)
- {
+ if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
- ndn::Name neighbor = interestName.getSubName(infoPosition + 1);
+ ndn::Name neighbor;
+ neighbor.wireDecode(interestName.get(-1).blockFromValue());
std::cout << "Neighbor: " << neighbor << std::endl;
- if (m_nlsr.getAdjacencyList().isNeighbor(neighbor))
- {
+ if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
- data.setContent((const uint8_t*)"info", sizeof("info"));
+ data.setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
+ INFO_COMPONENT.size());
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
m_nlsr.getNlsrFace().put(data);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
- if (status == 0)
- {
+ if (status == 0) {
ndn::Name interestName(neighbor);
- interestName.append("info");
+ interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
@@ -83,13 +81,10 @@
{
const ndn::Name interestName(interest.getName());
std::cout << "Interest timed out for Name: " << interestName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(interestName, chkString);
- if (infoPosition < 0)
- {
+ if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
- ndn::Name neighbor = interestName.getSubName(0, infoPosition);
+ ndn::Name neighbor = interestName.getPrefix(-2);
std::cout << "Neighbor: " << neighbor << std::endl;
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
@@ -98,22 +93,19 @@
std::cout << "Neighbor: " << neighbor << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
- if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber()))
- {
+ if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) {
ndn::Name interestName(neighbor);
- interestName.append("info");
- interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
+ interestName.append(INFO_COMPONENT);
+ interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
else if ((status == 1) &&
- (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
- {
+ (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
m_nlsr.incrementAdjBuildCount();
- if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
- {
- m_nlsr.setIsBuildAdjLsaSheduled(1);
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
@@ -129,11 +121,8 @@
{
ndn::Name dataName = data.getName();
std::cout << "Data received for name: " << dataName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(dataName, chkString);
- if (infoPosition >= 0)
- {
- ndn::Name neighbor = dataName.getSubName(0, infoPosition);
+ if (dataName.get(-3).toUri() == INFO_COMPONENT) {
+ ndn::Name neighbor = dataName.getPrefix(-3);
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
int infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
neighbor);
@@ -154,17 +143,16 @@
std::cout << "Status: " << newStatus << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
//debugging purpose end
- if ((oldStatus - newStatus) != 0) // change in Adjacency list
- {
+ // change in Adjacency list
+ if ((oldStatus - newStatus) != 0) {
m_nlsr.incrementAdjBuildCount();
/* Need to schedule event for Adjacency LSA building */
- if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
- {
- m_nlsr.setIsBuildAdjLsaSheduled(1);
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- boost::ref(m_nlsr.getLsdb())));
+ ndn::ref(m_nlsr.getLsdb())));
}
}
}
diff --git a/src/hello-protocol.hpp b/src/hello-protocol.hpp
index 984413d..ecdd6c5 100644
--- a/src/hello-protocol.hpp
+++ b/src/hello-protocol.hpp
@@ -41,6 +41,7 @@
private:
Nlsr& m_nlsr;
ndn::KeyChain m_keyChain;
+ static const std::string INFO_COMPONENT;
};
} //namespace nlsr
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 2ad95c5..14d033a 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -11,14 +11,12 @@
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
-#include "utility/tokenizer.hpp"
namespace nlsr {
using namespace std;
-
const ndn::Name
NameLsa::getKey() const
{
@@ -36,8 +34,7 @@
m_lsSeqNo = lsn;
m_lifeTime = lt;
std::list<ndn::Name>& nl = npl.getNameList();
- for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
- {
+ for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) {
addName((*it));
}
}
@@ -52,8 +49,7 @@
nameLsaData += "|";
nameLsaData += boost::lexical_cast<std::string>(m_npl.getSize());
std::list<ndn::Name> nl = m_npl.getNameList();
- for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
- {
+ for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) {
nameLsaData += "|";
nameLsaData += (*it).toUri();
}
@@ -69,8 +65,7 @@
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
tokens.begin();
m_origRouter = ndn::Name(*tok_iter++);
- if (!(m_origRouter.size() > 0))
- {
+ if (!(m_origRouter.size() > 0)) {
return false;
}
try {
@@ -82,8 +77,7 @@
catch (std::exception& e) {
return false;
}
- for (uint32_t i = 0; i < numName; i++)
- {
+ for (uint32_t i = 0; i < numName; i++) {
string name(*tok_iter++);
addName(name);
}
@@ -167,8 +161,7 @@
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
tokens.begin();
m_origRouter = ndn::Name(*tok_iter++);
- if (!(m_origRouter.size() > 0))
- {
+ if (!(m_origRouter.size() > 0)) {
return false;
}
try {
@@ -208,10 +201,8 @@
m_lifeTime = lt;
m_noLink = nl;
std::list<Adjacent> al = adl.getAdjList();
- for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++)
- {
- if ((*it).getStatus() == 1)
- {
+ for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) {
+ if ((*it).getStatus() == 1) {
addAdjacent((*it));
}
}
@@ -242,12 +233,11 @@
adjLsaData += "|";
adjLsaData += boost::lexical_cast<std::string>(m_adl.getSize());
std::list<Adjacent> al = m_adl.getAdjList();
- for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++)
- {
+ for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) {
adjLsaData += "|";
adjLsaData += (*it).getName().toUri();
adjLsaData += "|";
- adjLsaData += boost::lexical_cast<std::string>((*it).getConnectingFace());
+ adjLsaData += (*it).getConnectingFaceUri();
adjLsaData += "|";
adjLsaData += boost::lexical_cast<std::string>((*it).getLinkCost());
}
@@ -263,8 +253,7 @@
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
tokens.begin();
m_origRouter = ndn::Name(*tok_iter++);
- if (!(m_origRouter.size() > 0))
- {
+ if (!(m_origRouter.size() > 0)) {
return false;
}
try {
@@ -276,13 +265,12 @@
catch (std::exception& e) {
return false;
}
- for (uint32_t i = 0; i < numLink; i++)
- {
+ for (uint32_t i = 0; i < numLink; i++) {
try {
string adjName(*tok_iter++);
- int connectingFace = boost::lexical_cast<int>(*tok_iter++);
+ std::string connectingFaceUri(*tok_iter++);
double linkCost = boost::lexical_cast<double>(*tok_iter++);
- Adjacent adjacent(adjName, connectingFace, linkCost, 0, 0);
+ Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0);
addAdjacent(adjacent);
}
catch (std::exception& e) {
@@ -296,8 +284,7 @@
void
AdjLsa::addNptEntries(Nlsr& pnlsr)
{
- if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
- {
+ if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter());
}
}
@@ -306,8 +293,7 @@
void
AdjLsa::removeNptEntries(Nlsr& pnlsr)
{
- if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
- {
+ if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter());
}
}
@@ -330,7 +316,7 @@
{
os << " Adjacent " << i << ": " << endl;
os << " Adjacent Name: " << (*it).getName() << endl;
- os << " Connecting Face: " << (*it).getConnectingFace() << endl;
+ os << " Connecting FaceUri: " << (*it).getConnectingFaceUri() << endl;
os << " Link Cost: " << (*it).getLinkCost() << endl;
}
return os;
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 0220897..041e32c 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -152,8 +152,7 @@
}
AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
- uint32_t lt,
- uint32_t nl , AdjacencyList& adl);
+ uint32_t lt, uint32_t nl , AdjacencyList& adl);
AdjacencyList&
getAdl()
@@ -226,20 +225,13 @@
double
getCorRadius() const
{
- if (m_corRad >= 0)
- {
return m_corRad;
- }
- else
- {
- return -1;
- }
}
void
setCorRadius(double cr)
{
- m_corRad = cr;
+ m_corRad = cr;
}
double
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index a5eb2b2..0b34867 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -1,7 +1,9 @@
#include <string>
#include <utility>
+
#include "lsdb.hpp"
#include "nlsr.hpp"
+#include "conf-parameter.hpp"
#include "utility/name-helper.hpp"
namespace nlsr {
@@ -39,8 +41,7 @@
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
bind(nameLsaCompareByKey, _1, key));
- if (it != m_nameLsdb.end())
- {
+ if (it != m_nameLsdb.end()) {
return &(*it);
}
return 0;
@@ -50,14 +51,11 @@
Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
{
NameLsa* nameLsaCheck = findNameLsa(key);
- if (nameLsaCheck != 0)
- {
- if (nameLsaCheck->getLsSeqNo() < seqNo)
- {
+ if (nameLsaCheck != 0) {
+ if (nameLsaCheck->getLsSeqNo() < seqNo) {
return true;
}
- else
- {
+ else {
return false;
}
}
@@ -77,37 +75,30 @@
{
int timeToExpire = m_lsaRefreshTime;
NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
- if (chkNameLsa == 0)
- {
+ if (chkNameLsa == 0) {
addNameLsa(nlsa);
nlsa.writeLog();
printNameLsdb();
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
nlsa.getOrigRouter());
std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
- it++)
- {
- if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ it++) {
+ if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
}
}
}
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = nlsa.getLifeTime();
}
nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
nlsa.getLsSeqNo(),
timeToExpire));
}
- else
- {
- if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo())
- {
+ else {
+ if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
chkNameLsa->writeLog();
chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
chkNameLsa->setLifeTime(nlsa.getLifeTime());
@@ -120,14 +111,10 @@
chkNameLsa->getNpl().getNameList().end(),
std::inserter(nameToAdd, nameToAdd.begin()));
for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
- it != nameToAdd.end();
- ++it)
- {
+ it != nameToAdd.end(); ++it) {
chkNameLsa->addName((*it));
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
- if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
}
}
@@ -139,19 +126,15 @@
nlsa.getNpl().getNameList().end(),
std::inserter(nameToRemove, nameToRemove.begin()));
for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
- it != nameToRemove.end(); ++it)
- {
+ it != nameToRemove.end(); ++it) {
chkNameLsa->removeName((*it));
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
- if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
+ if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
}
}
}
- if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = nlsa.getLifeTime();
}
cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
@@ -171,8 +154,7 @@
m_nameLsdb.end(),
bind(nameLsaCompareByKey, _1,
nlsa.getKey()));
- if (it == m_nameLsdb.end())
- {
+ if (it == m_nameLsdb.end()) {
m_nameLsdb.push_back(nlsa);
return true;
}
@@ -184,20 +166,16 @@
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
- bind(nameLsaCompareByKey, _1, key));
- if (it != m_nameLsdb.end())
- {
+ ndn::bind(nameLsaCompareByKey, _1, key));
+ if (it != m_nameLsdb.end()) {
(*it).writeLog();
if ((*it).getOrigRouter() !=
- m_nlsr.getConfParameter().getRouterPrefix())
- {
+ m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
(*it).getOrigRouter());
for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
- nit != (*it).getNpl().getNameList().end(); ++nit)
- {
- if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ nit != (*it).getNpl().getNameList().end(); ++nit) {
+ if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
}
}
@@ -213,9 +191,8 @@
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
- bind(nameLsaCompareByKey, _1, key));
- if (it == m_nameLsdb.end())
- {
+ ndn::bind(nameLsaCompareByKey, _1, key));
+ if (it == m_nameLsdb.end()) {
return false;
}
return true;
@@ -226,8 +203,7 @@
{
cout << "---------------Name LSDB-------------------" << endl;
for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
- it != m_nameLsdb.end() ; it++)
- {
+ it != m_nameLsdb.end() ; it++) {
cout << (*it) << endl;
}
}
@@ -260,9 +236,8 @@
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
- if (it != m_corLsdb.end())
- {
+ ndn::bind(corLsaCompareByKey, _1, key));
+ if (it != m_corLsdb.end()) {
return &(*it);
}
return 0;
@@ -272,14 +247,11 @@
Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
{
CoordinateLsa* clsa = findCoordinateLsa(key);
- if (clsa != 0)
- {
- if (clsa->getLsSeqNo() < seqNo)
- {
+ if (clsa != 0) {
+ if (clsa->getLsSeqNo() < seqNo) {
return true;
}
- else
- {
+ else {
return false;
}
}
@@ -300,43 +272,35 @@
{
int timeToExpire = m_lsaRefreshTime;
CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
- if (chkCorLsa == 0)
- {
+ if (chkCorLsa == 0) {
addCoordinateLsa(clsa);
- printCorLsdb(); //debugging purpose
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ //debugging purpose
+ printCorLsdb();
+ if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
clsa.getOrigRouter());
}
- if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
- {
+ if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = clsa.getLifeTime();
}
scheduleCoordinateLsaExpiration(clsa.getKey(),
clsa.getLsSeqNo(), timeToExpire);
}
- else
- {
- if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo())
- {
+ else {
+ if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
chkCorLsa->setLifeTime(clsa.getLifeTime());
- if (!chkCorLsa->isEqualContent(clsa))
- {
+ if (!chkCorLsa->isEqualContent(clsa)) {
chkCorLsa->setCorRadius(clsa.getCorRadius());
chkCorLsa->setCorTheta(clsa.getCorTheta());
- if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
- {
+ if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
}
- if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = clsa.getLifeTime();
}
cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
@@ -353,10 +317,9 @@
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
- bind(corLsaCompareByKey, _1,
- clsa.getKey()));
- if (it == m_corLsdb.end())
- {
+ ndn::bind(corLsaCompareByKey, _1,
+ clsa.getKey()));
+ if (it == m_corLsdb.end()) {
m_corLsdb.push_back(clsa);
return true;
}
@@ -368,12 +331,11 @@
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
- if (it != m_corLsdb.end())
- {
+ ndn::bind(corLsaCompareByKey,
+ _1, key));
+ if (it != m_corLsdb.end()) {
if ((*it).getOrigRouter() !=
- m_nlsr.getConfParameter().getRouterPrefix())
- {
+ m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
(*it).getOrigRouter());
}
@@ -388,21 +350,21 @@
{
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
- if (it == m_corLsdb.end())
- {
+ ndn::bind(corLsaCompareByKey,
+ _1, key));
+ if (it == m_corLsdb.end()) {
return false;
}
return true;
}
+//debugging
void
-Lsdb::printCorLsdb() //debugging
+Lsdb::printCorLsdb()
{
cout << "---------------Cor LSDB-------------------" << endl;
for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
- it != m_corLsdb.end() ; it++)
- {
+ it != m_corLsdb.end() ; it++) {
cout << (*it) << endl;
}
}
@@ -422,17 +384,13 @@
{
cout << "scheduledAdjLsaBuild Called" << endl;
m_nlsr.setIsBuildAdjLsaSheduled(0);
- if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr))
- {
+ if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
int adjBuildCount = m_nlsr.getAdjBuildCount();
- if (adjBuildCount > 0)
- {
- if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0)
- {
+ if (adjBuildCount > 0) {
+ if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
buildAndInstallOwnAdjLsa();
}
- else
- {
+ else {
ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
key.append("adjacency");
removeAdjLsa(key);
@@ -441,8 +399,7 @@
m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
}
}
- else
- {
+ else {
m_nlsr.setIsBuildAdjLsaSheduled(1);
int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
m_nlsr.getConfParameter().getInterestResendTime();
@@ -460,8 +417,7 @@
m_adjLsdb.end(),
bind(adjLsaCompareByKey, _1,
alsa.getKey()));
- if (it == m_adjLsdb.end())
- {
+ if (it == m_adjLsdb.end()) {
m_adjLsdb.push_back(alsa);
return true;
}
@@ -474,8 +430,7 @@
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
bind(adjLsaCompareByKey, _1, key));
- if (it != m_adjLsdb.end())
- {
+ if (it != m_adjLsdb.end()) {
return &(*it);
}
return 0;
@@ -486,14 +441,11 @@
Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
{
AdjLsa* adjLsaCheck = findAdjLsa(key);
- if (adjLsaCheck != 0)
- {
- if (adjLsaCheck->getLsSeqNo() < seqNo)
- {
+ if (adjLsaCheck != 0) {
+ if (adjLsaCheck->getLsSeqNo() < seqNo) {
return true;
}
- else
- {
+ else {
return false;
}
}
@@ -514,32 +466,26 @@
{
int timeToExpire = m_lsaRefreshTime;
AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
- if (chkAdjLsa == 0)
- {
+ if (chkAdjLsa == 0) {
addAdjLsa(alsa);
alsa.addNptEntries(m_nlsr);
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
- if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = alsa.getLifeTime();
}
scheduleAdjLsaExpiration(alsa.getKey(),
alsa.getLsSeqNo(), timeToExpire);
}
- else
- {
- if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo())
- {
+ else {
+ if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
chkAdjLsa->setLifeTime(alsa.getLifeTime());
- if (!chkAdjLsa->isEqualContent(alsa))
- {
+ if (!chkAdjLsa->isEqualContent(alsa)) {
chkAdjLsa->getAdl().reset();
chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
- if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
- {
+ if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
timeToExpire = alsa.getLifeTime();
}
cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
@@ -562,7 +508,7 @@
m_nlsr.getAdjacencyList());
m_nlsr.getSequencingManager().increaseAdjLsaSeq();
// publish routing update
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
+ ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
lsaPrefix);
@@ -574,9 +520,8 @@
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
- bind(adjLsaCompareByKey, _1, key));
- if (it != m_adjLsdb.end())
- {
+ ndn::bind(adjLsaCompareByKey, _1, key));
+ if (it != m_adjLsdb.end()) {
(*it).removeNptEntries(m_nlsr);
m_adjLsdb.erase(it);
return true;
@@ -590,8 +535,7 @@
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
bind(adjLsaCompareByKey, _1, key));
- if (it == m_adjLsdb.end())
- {
+ if (it == m_adjLsdb.end()) {
return false;
}
return true;
@@ -621,13 +565,10 @@
cout << "Lsdb::exprireOrRefreshNameLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
NameLsa* chkNameLsa = findNameLsa(lsaKey);
- if (chkNameLsa != 0)
- {
+ if (chkNameLsa != 0) {
cout << " LSA Exists with seq no: " << chkNameLsa->getLsSeqNo() << endl;
- if (chkNameLsa->getLsSeqNo() == seqNo)
- {
- if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix)
- {
+ if (chkNameLsa->getLsSeqNo() == seqNo) {
+ if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
chkNameLsa->writeLog();
cout << "Own Name LSA, so refreshing name LSA" << endl;
chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
@@ -638,13 +579,12 @@
chkNameLsa->getLsSeqNo(),
m_lsaRefreshTime));
// publish routing update
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
+ ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
lsaPrefix);
}
- else
- {
+ else {
cout << "Other's Name LSA, so removing form LSDB" << endl;
removeNameLsa(lsaKey);
}
@@ -658,13 +598,10 @@
cout << "Lsdb::exprireOrRefreshAdjLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
- if (chkAdjLsa != 0)
- {
+ if (chkAdjLsa != 0) {
cout << " LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo() << endl;
- if (chkAdjLsa->getLsSeqNo() == seqNo)
- {
- if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix)
- {
+ if (chkAdjLsa->getLsSeqNo() == seqNo) {
+ if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
cout << "Own Adj LSA, so refreshing Adj LSA" << endl;
chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
@@ -673,13 +610,12 @@
chkAdjLsa->getLsSeqNo(),
m_lsaRefreshTime));
// publish routing update
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
+ ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
lsaPrefix);
}
- else
- {
+ else {
cout << "Other's Adj LSA, so removing form LSDB" << endl;
removeAdjLsa(lsaKey);
}
@@ -696,13 +632,10 @@
cout << "Lsdb::exprireOrRefreshCorLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
- if (chkCorLsa != 0)
- {
+ if (chkCorLsa != 0) {
cout << " LSA Exists with seq no: " << chkCorLsa->getLsSeqNo() << endl;
- if (chkCorLsa->getLsSeqNo() == seqNo)
- {
- if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix)
- {
+ if (chkCorLsa->getLsSeqNo() == seqNo) {
+ if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
cout << "Own Cor LSA, so refreshing Cor LSA" << endl;
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
@@ -712,18 +645,16 @@
chkCorLsa->getLsSeqNo(),
m_lsaRefreshTime));
// publish routing update
- ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
+ ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
lsaPrefix);
}
- else
- {
+ else {
cout << "Other's Cor LSA, so removing form LSDB" << endl;
removeCoordinateLsa(lsaKey);
}
- if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
- {
+ if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
}
}
@@ -753,41 +684,36 @@
string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
chkString);
- if (lsaPosition >= 0)
- {
+ if (lsaPosition >= 0) {
std::string interestedLsType;
uint64_t interestedLsSeqNo;
ndn::Name origRouter = intName.getSubName(lsaPosition + 1,
interest.getName().size() - lsaPosition - 3);
- interestedLsType = intName[-2].toEscapedString();
+ interestedLsType = intName[-2].toUri();
interestedLsSeqNo = intName[-1].toNumber();
std::cout << "Router Name: " << origRouter << std::endl;
std::cout << "Ls Type : " << interestedLsType << std::endl;
std::cout << "Ls Seq : " << interestedLsSeqNo << endl;
std::cout << "Ls Type: " << interestedLsType << std::endl;
- if (interestedLsType == "name")
- {
+ if (interestedLsType == "name") {
processInterestForNameLsa(interest,
origRouter.append(interestedLsType),
interestedLsSeqNo);
return;
}
- else if (interestedLsType == "adjacency")
- {
+ else if (interestedLsType == "adjacency") {
processInterestForAdjacencyLsa(interest,
origRouter.append(interestedLsType),
interestedLsSeqNo);
return;
}
- else if (interestedLsType == "coordinate")
- {
+ else if (interestedLsType == "coordinate") {
processInterestForCoordinateLsa(interest,
origRouter.append(interestedLsType),
interestedLsSeqNo);
return;
}
- else
- {
+ else {
cout << "Unrecognized LSA Type :(" << endl;
}
}
@@ -799,10 +725,8 @@
uint32_t interestedlsSeqNo)
{
NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
- if (nameLsa != 0)
- {
- if (nameLsa->getLsSeqNo() >= interestedlsSeqNo)
- {
+ if (nameLsa != 0) {
+ if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = nameLsa->getData();
@@ -821,10 +745,8 @@
uint32_t interestedlsSeqNo)
{
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
- if (adjLsa != 0)
- {
- if (adjLsa->getLsSeqNo() >= interestedlsSeqNo)
- {
+ if (adjLsa != 0) {
+ if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = adjLsa->getData();
@@ -843,10 +765,8 @@
uint32_t interestedlsSeqNo)
{
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
- if (corLsa != 0)
- {
- if (corLsa->getLsSeqNo() >= interestedlsSeqNo)
- {
+ if (corLsa != 0) {
+ if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = corLsa->getData();
@@ -867,37 +787,32 @@
string dataContent(reinterpret_cast<const char*>(data.getContent().value()));
string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
- if (lsaPosition >= 0)
- {
+ if (lsaPosition >= 0) {
std::string interestedLsType;
uint64_t interestedLsSeqNo;
ndn::Name origRouter = dataName.getSubName(lsaPosition + 1,
dataName.size() - lsaPosition - 4);
- interestedLsType = dataName[-3].toEscapedString();
+ interestedLsType = dataName[-3].toUri();
interestedLsSeqNo = dataName[-2].toNumber();
std::cout << "Ls Type : " << interestedLsType << std::endl;
std::cout << "Ls Seq : " << interestedLsSeqNo << std::endl;
std::cout << "Ls Type: " << interestedLsType << std::endl;
- if (interestedLsType == "name")
- {
+ if (interestedLsType == "name") {
processContentNameLsa(origRouter.append(interestedLsType),
interestedLsSeqNo, dataContent);
return;
}
- else if (interestedLsType == "adjacency")
- {
+ else if (interestedLsType == "adjacency") {
processContentAdjacencyLsa(origRouter.append(interestedLsType),
interestedLsSeqNo, dataContent);
return;
}
- else if (interestedLsType == "coordinate")
- {
+ else if (interestedLsType == "coordinate") {
processContentCoordinateLsa(origRouter.append(interestedLsType),
interestedLsSeqNo, dataContent);
return;
}
- else
- {
+ else {
cout << "Unrecognized LSA Type :(" << endl;
}
}
@@ -907,15 +822,12 @@
Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
uint32_t lsSeqNo, std::string& dataContent)
{
- if (isNameLsaNew(lsaKey, lsSeqNo))
- {
+ if (isNameLsaNew(lsaKey, lsSeqNo)) {
NameLsa nameLsa;
- if (nameLsa.initializeFromContent(dataContent))
- {
+ if (nameLsa.initializeFromContent(dataContent)) {
installNameLsa(nameLsa);
}
- else
- {
+ else {
std::cout << "LSA data decoding error :(" << std::endl;
}
}
@@ -925,15 +837,12 @@
Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
uint32_t lsSeqNo, std::string& dataContent)
{
- if (isAdjLsaNew(lsaKey, lsSeqNo))
- {
+ if (isAdjLsaNew(lsaKey, lsSeqNo)) {
AdjLsa adjLsa;
- if (adjLsa.initializeFromContent(dataContent))
- {
+ if (adjLsa.initializeFromContent(dataContent)) {
installAdjLsa(adjLsa);
}
- else
- {
+ else {
std::cout << "LSA data decoding error :(" << std::endl;
}
}
@@ -943,15 +852,12 @@
Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
uint32_t lsSeqNo, std::string& dataContent)
{
- if (isCoordinateLsaNew(lsaKey, lsSeqNo))
- {
+ if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
CoordinateLsa corLsa;
- if (corLsa.initializeFromContent(dataContent))
- {
+ if (corLsa.initializeFromContent(dataContent)) {
installCoordinateLsa(corLsa);
}
- else
- {
+ else {
std::cout << "LSA data decoding error :(" << std::endl;
}
}
@@ -970,8 +876,7 @@
{
cout << "---------------Adj LSDB-------------------" << endl;
for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
- it != m_adjLsdb.end() ; it++)
- {
+ it != m_adjLsdb.end() ; it++) {
cout << (*it) << endl;
}
}
@@ -980,16 +885,13 @@
bool
Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
{
- if (lsType == "name")
- {
+ if (lsType == "name") {
return doesNameLsaExist(key);
}
- else if (lsType == "adjacency")
- {
+ else if (lsType == "adjacency") {
return doesAdjLsaExist(key);
}
- else if (lsType == "coordinate")
- {
+ else if (lsType == "coordinate") {
return doesCoordinateLsaExist(key);
}
return false;
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 3ad3007..ff7450a 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -39,8 +39,9 @@
bool
isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
+ //debugging
void
- printNameLsdb(); //debugging
+ printNameLsdb();
//function related to Cor LSDB
bool
@@ -58,8 +59,9 @@
bool
isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
+ //debugging
void
- printCorLsdb(); //debugging
+ printCorLsdb();
//function related to Adj LSDB
void
diff --git a/src/main.cpp b/src/main.cpp
index 59829b1..9e3bf12 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,8 +30,7 @@
std::string programName(argv[0]);
nlsr.setConfFileName("nlsr.conf");
int32_t opt;
- while ((opt = getopt(argc, argv, "df:p:h")) != -1)
- {
+ while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
switch (opt)
{
case 'f':
@@ -56,8 +55,7 @@
}
ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
int32_t res = cfp.processConfFile();
- if (res < 0)
- {
+ if (res < 0) {
std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
std::endl;
return EXIT_FAILURE;
diff --git a/src/name-prefix-list.cpp b/src/name-prefix-list.cpp
index c8d9285..f00d0d0 100644
--- a/src/name-prefix-list.cpp
+++ b/src/name-prefix-list.cpp
@@ -30,8 +30,7 @@
m_nameList.end(),
ndn::bind(&nameCompare, _1 ,
ndn::cref(name)));
- if (it != m_nameList.end())
- {
+ if (it != m_nameList.end()) {
return -1;
}
m_nameList.push_back(name);
@@ -45,8 +44,7 @@
m_nameList.end(),
ndn::bind(&nameCompare, _1 ,
ndn::cref(name)));
- if (it != m_nameList.end())
- {
+ if (it != m_nameList.end()) {
m_nameList.erase(it);
}
return -1;
@@ -63,9 +61,7 @@
{
int i = 1;
for (std::list<ndn::Name>::iterator it = m_nameList.begin();
- it != m_nameList.end();
- it++)
- {
+ it != m_nameList.end(); it++) {
cout << "Name " << i << " : " << (*it) << endl;
i++;
}
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 91b4c25..a55f634 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -4,6 +4,7 @@
#include <cstdio>
#include "nlsr.hpp"
+#include "adjacent.hpp"
namespace nlsr {
@@ -18,6 +19,10 @@
throw Error("Error: Prefix registration failed");
}
+void
+Nlsr::onRegistrationSuccess(const ndn::Name& name)
+{
+}
void
Nlsr::setInfoInterestFilter()
@@ -26,23 +31,43 @@
getNlsrFace().setInterestFilter(name,
ndn::bind(&HelloProtocol::processInterest,
&m_helloProtocol, _1, _2),
+ ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
ndn::bind(&Nlsr::registrationFailed, this, _1));
}
void
Nlsr::setLsaInterestFilter()
{
- // ndn::Name name(m_confParam.getChronosyncLsaPrefix() +
- // m_confParam.getRouterPrefix());
- ndn::Name name = m_confParam.getChronosyncLsaPrefix();
+ ndn::Name name = m_confParam.getLsaPrefix();
name.append(m_confParam.getRouterPrefix());
getNlsrFace().setInterestFilter(name,
ndn::bind(&Lsdb::processInterest,
&m_nlsrLsdb, _1, _2),
+ ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
ndn::bind(&Nlsr::registrationFailed, this, _1));
}
void
+Nlsr::registerPrefixes()
+{
+ std::string strategy("ndn:/localhost/nfd/strategy/broadcast");
+ std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
+ for (std::list<Adjacent>::iterator it = adjacents.begin();
+ it != adjacents.end(); it++) {
+ m_fib.registerPrefix((*it).getName(), (*it).getConnectingFaceUri(),
+ (*it).getLinkCost(), 31536000); /* One Year in seconds */
+ m_fib.registerPrefix(m_confParam.getChronosyncPrefix(),
+ (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
+ m_fib.registerPrefix(m_confParam.getLsaPrefix(),
+ (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
+ m_fib.setStrategy((*it).getName(), strategy);
+ }
+
+ m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy);
+ m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy);
+}
+
+void
Nlsr::initialize()
{
m_confParam.buildRouterPrefix();
@@ -56,11 +81,12 @@
m_adjacencyList.print();
m_namePrefixList.print();
/* debugging purpose end */
+ registerPrefixes();
m_nlsrLsdb.buildAndInstallOwnNameLsa();
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
setInfoInterestFilter();
setLsaInterestFilter();
- m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix().toUri());
+ m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncPrefix().toUri());
m_syncLogicHandler.createSyncSocket(boost::ref(*this));
//m_interestManager.scheduleInfoInterest(10);
m_helloProtocol.scheduleInterest(10);
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 6bf45bd..6fc255d 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -59,6 +59,9 @@
registrationFailed(const ndn::Name& name);
void
+ onRegistrationSuccess(const ndn::Name& name);
+
+ void
setInfoInterestFilter();
void
@@ -172,7 +175,7 @@
m_adjBuildCount = abc;
}
- int
+ bool
getIsBuildAdjLsaSheduled()
{
return m_isBuildAdjLsaSheduled;
@@ -231,6 +234,10 @@
initialize();
private:
+ void
+ registerPrefixes();
+
+private:
ndn::Face m_nlsrFace;
ndn::Scheduler m_scheduler;
ConfParameter m_confParam;
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();
}
}
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index 9a5ec89..3d63a3d 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -42,8 +42,7 @@
{
cout << "Seq File Name: " << m_seqFileNameWithPath << endl;
std::ifstream inputFile(m_seqFileNameWithPath.c_str(), ios::binary);
- if (inputFile.good())
- {
+ if (inputFile.good()) {
inputFile >> m_combinedSeqNo;
splittSequenceNo(m_combinedSeqNo);
m_adjLsaSeq += 10;
@@ -52,8 +51,7 @@
combineSequenceNo();
inputFile.close();
}
- else
- {
+ else {
splittSequenceNo(0);
}
}
@@ -62,8 +60,7 @@
SequencingManager::setSeqFileName(string filePath)
{
m_seqFileNameWithPath = filePath;
- if (m_seqFileNameWithPath.empty())
- {
+ if (m_seqFileNameWithPath.empty()) {
m_seqFileNameWithPath = getUserHomeDirectory();
}
m_seqFileNameWithPath = m_seqFileNameWithPath + "/nlsrSeqNo.txt";
@@ -73,8 +70,7 @@
SequencingManager::getUserHomeDirectory()
{
string homeDirPath(getpwuid(getuid())->pw_dir);
- if (homeDirPath.empty())
- {
+ if (homeDirPath.empty()) {
homeDirPath = getenv("HOME");
}
return homeDirPath;
diff --git a/src/utility/name-helper.hpp b/src/utility/name-helper.hpp
index 5a01a1a..90b3eca 100644
--- a/src/utility/name-helper.hpp
+++ b/src/utility/name-helper.hpp
@@ -1,6 +1,9 @@
#ifndef NLSR_NAME_HELPER_HPP
#define NLSR_NAME_HELPER_HPP
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/regex_find_format.hpp>
+#include <boost/regex.hpp>
#include <boost/cstdint.hpp>
#include <ndn-cxx/name-component.hpp>
#include <ndn-cxx/name.hpp>
@@ -20,10 +23,8 @@
{
ndn::name::Component component(searchString);
size_t nameSize = name.size();
- for (uint32_t i = 0; i < nameSize; i++)
- {
- if (component == name[i])
- {
+ for (uint32_t i = 0; i < nameSize; i++) {
+ if (component == name[i]) {
return (int32_t)i;
}
}
diff --git a/src/utility/tokenizer.cpp b/src/utility/tokenizer.cpp
deleted file mode 100644
index 095e55d..0000000
--- a/src/utility/tokenizer.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <iostream>
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string.hpp>
-#include <string>
-#include <algorithm>
-
-#include <ndn-cxx/face.hpp>
-
-#include "tokenizer.hpp"
-
-namespace nlsr {
-
-using namespace std;
-using namespace boost;
-
-void
-Tokenizer::makeToken()
-{
- char_separator<char> sep(m_seps.c_str());
- tokenizer<char_separator<char> >tokens(m_originalString, sep);
- tokenizer<char_separator<char> >::iterator tok_iter = tokens.begin();
- for (; tok_iter != tokens.end(); ++tok_iter)
- {
- string oneToken(*tok_iter);
- trim(oneToken);
- if (!oneToken.empty())
- {
- insertToken(oneToken);
- }
- }
- m_firstToken = m_vTokenList[0];
- makeRestOfTheLine();
-}
-
-void
-Tokenizer::insertToken(const string& token)
-{
- m_tokenList.push_back(token);
- m_vTokenList.push_back(token);
-}
-
-uint32_t
-Tokenizer::getTokenPosition(string& token)
-{
- uint32_t pos = -1;
- uint32_t i = 0;
- for (std::list<string>::iterator it = m_tokenList.begin();
- it != m_tokenList.end(); it++)
- {
- if ((*it) == token)
- {
- break;
- }
- i++;
- }
- if (i < m_tokenList.size())
- {
- pos = i;
- }
- return pos;
-}
-
-string
-Tokenizer::getTokenString(uint32_t from , uint32_t to)
-{
- string returnString = "";
- if ((to < m_tokenList.size()) &&
- (to >= from && to < m_tokenList.size()))
- {
- for (uint32_t i = from; i <= to; i++)
- {
- returnString += m_seps;
- returnString += m_vTokenList[i];
- }
- }
- trim(returnString);
- return returnString;
-}
-
-string
-Tokenizer::getTokenString(uint32_t from)
-{
- return getTokenString(from, m_tokenList.size() - 1);
-}
-
-static bool
-tokenCompare(string& s1, string& s2)
-{
- return s1 == s2;
-}
-
-void
-Tokenizer::makeRestOfTheLine()
-{
- m_restOfTheLine = getTokenString(1);
-}
-
-bool
-Tokenizer::doesTokenExist(string token)
-{
- std::list<string>::iterator it = std::find_if(m_tokenList.begin(),
- m_tokenList.end(),
- ndn::bind(&tokenCompare, _1 , token));
- if (it != m_tokenList.end())
- {
- return true;
- }
- return false;
-}
-
-}//namespace nlsr
diff --git a/src/utility/tokenizer.hpp b/src/utility/tokenizer.hpp
deleted file mode 100644
index 8ae6f88..0000000
--- a/src/utility/tokenizer.hpp
+++ /dev/null
@@ -1,117 +0,0 @@
-#ifndef NLSR_TOKENIZER_HPP
-#define NLSR_TOKENIZER_HPP
-
-#include <iostream>
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string.hpp>
-#include <string>
-#include <list>
-#include <vector>
-
-namespace nlsr {
-
-class Tokenizer
-{
-public:
- Tokenizer(const std::string& inputString)
- : m_firstToken()
- , m_restOfTheLine()
- , m_currentPosition(0)
- {
- m_seps = " ";
- m_originalString = inputString;
- makeToken();
- }
-
- Tokenizer(const std::string& inputString, const std::string& separator)
- : m_firstToken()
- , m_restOfTheLine()
- , m_currentPosition(0)
- {
- m_seps = separator;
- m_originalString = inputString;
- makeToken();
- }
-
- std::string
- getFirstToken()
- {
- return m_firstToken;
- }
-
- std::string
- getRestOfLine()
- {
- return m_restOfTheLine;
- }
-
- void
- resetCurrentPosition(uint32_t cp = 0)
- {
- if (cp <= m_vTokenList.size())
- {
- m_currentPosition = cp;
- }
- }
-
- std::string
- getNextToken()
- {
- if (m_currentPosition <= (m_vTokenList.size() - 1))
- {
- return m_vTokenList[m_currentPosition++];
- }
- return "";
- }
-
- uint32_t
- getTokenNumber()
- {
- return m_tokenList.size();
- }
-
- std::string
- getToken(unsigned int position)
- {
- if (position < m_vTokenList.size())
- {
- return m_vTokenList[position];
- }
- return "";
- }
-
- uint32_t
- getTokenPosition(std::string& token);
-
- std::string
- getTokenString(uint32_t from , uint32_t to);
-
- std::string
- getTokenString(uint32_t from);
-
- bool
- doesTokenExist(std::string token);
-
-
-private:
-
- void
- makeToken();
-
- void
- insertToken(const std::string& token);
-
- void
- makeRestOfTheLine();
-
- std::string m_seps;
- std::string m_originalString;
- std::string m_firstToken;
- std::string m_restOfTheLine;
- std::list<std::string> m_tokenList;
- std::vector<std::string> m_vTokenList;
- uint32_t m_currentPosition;
-};
-
-}//namespace nlsr
-#endif //NLSR_TOKENIZER_HPP
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 8ec3a4e..576b87f 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -2,7 +2,7 @@
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
-
+#include <fstream>
#include "conf-file-processor.hpp"
#include "nlsr.hpp"
#include <boost/test/unit_test.hpp>
@@ -18,16 +18,47 @@
Nlsr nlsr1;
const std::string CONFIG =
- "network ndn\n"
- "site-name memphis.edu\n"
- "router-name cs/macbook\n\n"
- "ndnneighbor /ndn/memphis.edu/cs/maia 7\n"
- "link-cost /ndn/memphis.edu/cs/maia 30\n"
- "ndnneighbor /ndn/memphis.edu/cs/pollux 10\n"
- "link-cost /ndn/memphis.edu/cs/pollux 25\n\n"
- "ndnname /ndn/memphis.edu/cs/macbook/name1\n"
- "ndnname /ndn/memphis.edu/cs/macbook/name2\n\n\n"
- ;
+ "general\n"
+ "{\n"
+ " network /ndn/\n"
+ " site /memphis.edu/\n"
+ " router /cs/pollux/\n"
+ " lsa-refresh-time 1800\n"
+ " log-level INFO\n"
+ "}\n\n"
+ "neighbors\n"
+ "{\n"
+ " hello-retries 3\n"
+ " hello-time-out 1\n"
+ " hello-interval 60\n\n"
+ " neighbor\n"
+ " {\n"
+ " name /ndn/memphis.edu/cs/castor\n"
+ " face-id 15\n"
+ " link-cost 20\n"
+ " }\n\n"
+ " neighbor\n"
+ " {\n"
+ " name /ndn/memphis.edu/cs/mira\n"
+ " face-id 17\n"
+ " link-cost 30\n"
+ " }\n"
+ "}\n\n"
+ "hyperbolic\n"
+ "{\n"
+ "state off\n"
+ "radius 123.456\n"
+ "angle 1.45\n"
+ "}\n\n"
+ "fib\n"
+ "{\n"
+ " max-faces-per-prefix 3\n"
+ "}\n\n"
+ "advertising\n"
+ "{\n"
+ "prefix /ndn/edu/memphis/cs/netlab\n"
+ "prefix /ndn/edu/memphis/sports/basketball\n"
+ "}\n";
std::ofstream config;
config.open("unit-test-nlsr.conf");
@@ -40,12 +71,12 @@
cfp1.processConfFile();
- BOOST_CHECK(nlsr1.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/maia"));
+ BOOST_CHECK(nlsr1.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
BOOST_CHECK_EQUAL(
- nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/maia").getName(),
- "/ndn/memphis.edu/cs/maia");
+ nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getName(),
+ "/ndn/memphis.edu/cs/mira");
BOOST_CHECK_EQUAL(
- nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/maia").getLinkCost(),
+ nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getLinkCost(),
30);
BOOST_CHECK_EQUAL(nlsr1.getNamePrefixList().getSize(), 2);
diff --git a/tests/test-conf-parameter.cpp b/tests/test-conf-parameter.cpp
index 95ae19e..d9a38f9 100644
--- a/tests/test-conf-parameter.cpp
+++ b/tests/test-conf-parameter.cpp
@@ -28,8 +28,6 @@
cp1.setNetwork(NETWORK);
- cp1.setRootKeyPrefix("adminRootKey");
-
cp1.setInterestRetryNumber(2);
cp1.setInterestResendTime(1000);
@@ -40,29 +38,12 @@
cp1.setMaxFacesPerPrefix(50);
- cp1.setLogDir("log");
-
- cp1.setCertDir("cert");
-
- cp1.setSeqFileDir("ssfd");
-
- cp1.setDetailedLogging(1);
-
- cp1.setDebugging(1);
-
- cp1.setIsHyperbolicCalc(1);
+ cp1.setHyperbolicState(1);
cp1.setCorR(2.5);
cp1.setCorTheta(102.5);
- cp1.setTunnelType(2);
-
- const string a = "csp";
- cp1.setChronosyncSyncPrefix(a);
-
- cp1.setChronosyncLsaPrefix("cla");
-
cp1.setInfoInterestInterval(3);
BOOST_CHECK_EQUAL(cp1.getRouterName(), "router1");
@@ -75,8 +56,6 @@
BOOST_CHECK_EQUAL(cp1.getRouterPrefix(), "/ATT/memphis/router1");
- BOOST_CHECK_EQUAL(cp1.getRootKeyPrefix(), "adminRootKey");
-
BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), (uint32_t)2);
BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);
@@ -87,26 +66,10 @@
BOOST_CHECK_EQUAL(cp1.getMaxFacesPerPrefix(), 50);
- BOOST_CHECK_EQUAL(cp1.getLogDir(), "log");
-
- BOOST_CHECK_EQUAL(cp1.getCertDir(), "cert");
-
- BOOST_CHECK_EQUAL(cp1.getSeqFileDir(), "ssfd");
-
- BOOST_CHECK_EQUAL(cp1.getDetailedLogging(), 1);
-
- BOOST_CHECK_EQUAL(cp1.getDebugging(), 1);
-
- BOOST_CHECK_EQUAL(cp1.getIsHyperbolicCalc(), 1);
+ BOOST_CHECK_EQUAL(cp1.getHyperbolicState(), 1);
BOOST_CHECK_CLOSE(cp1.getCorTheta(), 102.5, 0.0001);
- BOOST_CHECK_EQUAL(cp1.getTunnelType(), 2);
-
- BOOST_CHECK_EQUAL(cp1.getChronosyncSyncPrefix(), "csp");
-
- BOOST_CHECK_EQUAL(cp1.getChronosyncLsaPrefix(), "cla");
-
BOOST_CHECK_EQUAL(cp1.getInfoInterestInterval(), 3);
}
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 022efa7..a72c55e 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -28,7 +28,7 @@
npl1.insert(s1);
npl1.insert(s2);
-//For NameLsa lsType is 1.
+//For NameLsa lsType is name.
//12 is seqNo, randomly generated.
//1800 is the default life time.
NameLsa nlsa1("router1", std::string("name"), 12, 1800, npl1);
diff --git a/tests/test-nexthop.cpp b/tests/test-nexthop.cpp
index 0cdf23c..fb6a8fb 100644
--- a/tests/test-nexthop.cpp
+++ b/tests/test-nexthop.cpp
@@ -16,11 +16,11 @@
{
NextHop np1;
- np1.setConnectingFace(1);
+ np1.setConnectingFaceUri("udp://test/uri");
np1.setRouteCost(10.5);
- BOOST_CHECK_EQUAL(np1.getConnectingFace(), (uint32_t)1);
+ BOOST_CHECK_EQUAL(np1.getConnectingFaceUri(), "udp://test/uri");
BOOST_CHECK_CLOSE(np1.getRouteCost(), 10.5, 0.0001);
}
diff --git a/tests/test-tokenizer.cpp b/tests/test-tokenizer.cpp
deleted file mode 100644
index b3a8234..0000000
--- a/tests/test-tokenizer.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (C) 2014 Regents of the University of Memphis.
- * See COPYING for copyright and distribution information.
- */
-
-#include "utility/tokenizer.hpp"
-#include <boost/test/unit_test.hpp>
-
-namespace nlsr {
-
-namespace test {
-
-BOOST_AUTO_TEST_SUITE(TestTokenizer)
-
-BOOST_AUTO_TEST_CASE(TokenizerBasic)
-{
- Tokenizer token1("/ndn/memphis.edu/cs", "/");
- Tokenizer token2("/ndn/memphis.edu/cs", "/");
-
- Tokenizer token3("/test/hello");
-
- BOOST_CHECK(token1.getFirstToken() == token2.getFirstToken());
-
- BOOST_CHECK_EQUAL(token1.getRestOfLine(), token2.getRestOfLine());
-
- BOOST_CHECK(token1.getFirstToken() != token3.getFirstToken());
-
- BOOST_CHECK(token1.getRestOfLine() != token3.getRestOfLine());
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} //namespace test
-} //namespace nlsr
diff --git a/wscript b/wscript
index 146b5e8..909a2df 100644
--- a/wscript
+++ b/wscript
@@ -46,7 +46,7 @@
conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
uselib_store='NDN_CPP', mandatory=True)
- boost_libs = 'system chrono program_options iostreams thread'
+ boost_libs = 'system chrono program_options iostreams thread regex'
if conf.options.with_tests:
conf.env['WITH_TESTS'] = 1
conf.define('WITH_TESTS', 1);