Browse Source

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
pull/1/head
akmhoque 11 years ago
parent
commit
157b0a473a
  1. 103
      nlsr.conf
  2. 101
      nsync/sync-logic.cc
  3. 4
      nsync/sync-logic.h
  4. 31
      nsync/sync-socket.cc
  5. 46
      nsync/sync-socket.h
  6. 63
      src/adjacency-list.cpp
  7. 3
      src/adjacency-list.hpp
  8. 30
      src/adjacent.cpp
  9. 43
      src/adjacent.hpp
  10. 43
      src/communication/sync-logic-handler.cpp
  11. 4
      src/communication/sync-logic-handler.hpp
  12. 715
      src/conf-file-processor.cpp
  13. 81
      src/conf-file-processor.hpp
  14. 31
      src/conf-parameter.cpp
  15. 310
      src/conf-parameter.hpp
  16. 68
      src/hello-protocol.cpp
  17. 1
      src/hello-protocol.hpp
  18. 46
      src/lsa.cpp
  19. 12
      src/lsa.hpp
  20. 348
      src/lsdb.cpp
  21. 6
      src/lsdb.hpp
  22. 6
      src/main.cpp
  23. 10
      src/name-prefix-list.cpp
  24. 34
      src/nlsr.cpp
  25. 9
      src/nlsr.hpp
  26. 115
      src/route/face-map.hpp
  27. 15
      src/route/fib-entry.cpp
  28. 206
      src/route/fib.cpp
  29. 25
      src/route/fib.hpp
  30. 34
      src/route/map.cpp
  31. 6
      src/route/name-prefix-table-entry.cpp
  32. 6
      src/route/name-prefix-table-entry.hpp
  33. 57
      src/route/name-prefix-table.cpp
  34. 20
      src/route/nexthop-list.cpp
  35. 13
      src/route/nexthop.cpp
  36. 27
      src/route/nexthop.hpp
  37. 173
      src/route/routing-table-calculator.cpp
  38. 2
      src/route/routing-table-calculator.hpp
  39. 3
      src/route/routing-table-entry.hpp
  40. 87
      src/route/routing-table.cpp
  41. 12
      src/sequencing-manager.cpp
  42. 9
      src/utility/name-helper.hpp
  43. 111
      src/utility/tokenizer.cpp
  44. 117
      src/utility/tokenizer.hpp
  45. 61
      tests/test-conf-file-processor.cpp
  46. 41
      tests/test-conf-parameter.cpp
  47. 2
      tests/test-lsdb.cpp
  48. 4
      tests/test-nexthop.cpp
  49. 34
      tests/test-tokenizer.cpp
  50. 2
      wscript

103
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
!logdir /Users/akmhoque/NLSR-CPP/log
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.
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
}

101
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 @@ INIT_LOGGER ("SyncLogic");
#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 @@ SyncLogic::SyncLogic (const Name& syncPrefix,
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 @@ SyncLogic::SyncLogic (const Name& syncPrefix,
, 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 @@ SyncLogic::SyncLogic (const Name& syncPrefix,
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));
m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
bind(&SyncLogic::onSyncInterest,
this, _1, _2),
bind(&SyncLogic::onSyncRegisterSucceed,
this, _1),
bind(&SyncLogic::onSyncRegisterFailed,
this, _1, _2));
m_reexpressingInterestId = m_scheduler.scheduleEvent (ndn::time::seconds (0),
bind (&SyncLogic::sendSyncInterest, this));
}
@ -139,13 +147,13 @@ SyncLogic::convertNameToDigestAndType (const Name &name)
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);
@ -188,6 +196,12 @@ SyncLogic::onSyncInterest (const Name& prefix, const ndn::Interest& interest)
}
}
void
SyncLogic::onSyncRegisterSucceed(const Name& prefix)
{
_LOG_DEBUG_ID("Sync prefix registration succeeded! " << prefix);
}
void
SyncLogic::onSyncRegisterFailed(const Name& prefix, const string& msg)
{
@ -249,7 +263,8 @@ SyncLogic::onSyncDataValidated(const shared_ptr<const Data>& data)
}
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 @@ SyncLogic::processSyncInterest (const Name &name, DigestConstPtr digest, bool ti
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 @@ SyncLogic::processSyncInterest (const Name &name, DigestConstPtr digest, bool ti
}
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 @@ SyncLogic::processSyncData (const Name &name, DigestConstPtr digest, const char
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 @@ SyncLogic::processSyncData (const Name &name, DigestConstPtr digest, const char
// 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 @@ SyncLogic::insertToDiffLog (DiffStatePtr diffLog)
{
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 @@ SyncLogic::sendSyncInterest ()
_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 @@ SyncLogic::sendSyncRecoveryInterests (DigestConstPtr digest)
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 @@ SyncLogic::sendSyncData (const Name &name, DigestConstPtr digest, SyncStateMsg &
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 @@ SyncLogic::sendSyncData (const Name &name, DigestConstPtr digest, SyncStateMsg &
{
_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));

4
nsync/sync-logic.h

@ -63,7 +63,6 @@ struct MissingDataInfo {
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;
@ -121,6 +120,9 @@ private:
void
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);

31
nsync/sync-socket.cc

@ -40,7 +40,6 @@ SyncSocket::SyncSocket (const Name &syncPrefix,
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
, m_ioService(face->ioService())
, m_syncLogic (syncPrefix,
validator,
face,
@ -53,23 +52,28 @@ SyncSocket::~SyncSocket()
}
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 @@ SyncSocket::publishDataInternal(shared_ptr<Data> data, const Name &prefix, uint6
}
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));
}

46
nsync/sync-socket.h

@ -42,8 +42,8 @@ namespace Sync {
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 @@ public:
* @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 @@ private:
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 @@ private:
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;
};

63
src/adjacency-list.cpp

@ -22,8 +22,7 @@ int32_t
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 @@ void
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 @@ int32_t
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 @@ AdjacencyList::getAdjacent(const ndn::Name& adjName)
{
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 @@ compareAdjacent(const Adjacent& adjacent1, const Adjacent& adjacent2)
bool
AdjacencyList::operator==(AdjacencyList& adl)
{
if (getSize() != adl.getSize())
{
if (getSize() != adl.getSize()) {
return false;
}
m_adjList.sort(compareAdjacent);
@ -84,10 +79,8 @@ AdjacencyList::operator==(AdjacencyList& adl)
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 @@ int32_t
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 @@ void
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 @@ AdjacencyList::setTimedOutInterestCount(const ndn::Name& neighbor,
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 @@ int32_t
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 @@ uint32_t
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 @@ void
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 @@ AdjacencyList::isAdjLsaBuildable(Nlsr& pnlsr)
{
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 @@ AdjacencyList::getNumOfActiveNeighbor()
{
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 @@ void
AdjacencyList::print()
{
for (std::list<Adjacent>::iterator it = m_adjList.begin();
it != m_adjList.end(); it++)
{
it != m_adjList.end(); it++) {
cout << (*it) << endl;
}
}

3
src/adjacency-list.hpp

@ -71,8 +71,7 @@ public:
void
reset()
{
if (m_adjList.size() > 0)
{
if (m_adjList.size() > 0) {
m_adjList.clear();
}
}

30
src/adjacent.cpp

@ -10,11 +10,31 @@ namespace nlsr {
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 @@ bool
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 @@ std::ostream&
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;

43
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 @@ public:
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 @@ public:
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;

43
src/communication/sync-logic-handler.cpp

@ -14,12 +14,12 @@ SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
{
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 @@ SyncLogicHandler::nsyncUpdateCallBack(const vector<Sync::MissingDataInfo>& v,
{
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 @@ void
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 @@ SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
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 @@ SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
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 @@ SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
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 @@ SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
pnlsr.getConfParameter().getInterestResendTime());
}
}
catch (std::exception& e)
{
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return;
}

4
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 @@ public:
SyncLogicHandler(boost::asio::io_service& ioService)
: m_validator(new ndn::ValidatorNull())
, m_syncFace(new ndn::Face(ioService))
{}
{
}
void

715
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 <ndn-cxx/name.hpp>
#include "conf-file-processor.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())
{
std::ifstream inputFile(m_confFileName.c_str());
if (inputFile.is_open())
{
for (string line; getline(inputFile, line);)
{
if (!line.empty())
{
if (line[0] != '#' && line[0] != '!')
{
ret = processConfCommand(line);
if (ret == -1)
{
break;
}
}
}
}
}
else
{
std::cerr << "Configuration file: (" << m_confFileName << ") does not exist :(";
std::cerr << endl;
ret = -1;
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;
}
int
ConfFileProcessor::processConfCommand(string command)
bool
ConfFileProcessor::processSection(const std::string& section,
boost::property_tree::ptree SectionAttributeTree)
{
int ret = 0;
Tokenizer nt(command, " ");
if ((nt.getFirstToken() == "network"))
{
ret = processConfCommandNetwork(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "site-name"))
{
ret = processConfCommandSiteName(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "root-key-prefix"))
{
ret = processConfCommandRootKeyPrefix(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "router-name"))
{
ret = processConfCommandRouterName(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "ndnneighbor"))
{
ret = processConfCommandNdnNeighbor(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "link-cost"))
{
ret = processConfCommandLinkCost(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "ndnname"))
bool ret = true;
if (section == "general")
{
ret = processConfCommandNdnName(nt.getRestOfLine());
ret = processConfSectionGeneral(SectionAttributeTree);
}
else if ((nt.getFirstToken() == "interest-retry-num"))
else if (section == "neighbors")
{
processConfCommandInterestRetryNumber(nt.getRestOfLine());
ret = processConfSectionNeighbors(SectionAttributeTree);
}
else if ((nt.getFirstToken() == "interest-resend-time"))
else if (section == "hyperbolic")
{
processConfCommandInterestResendTime(nt.getRestOfLine());
ret = processConfSectionHyperbolic(SectionAttributeTree);
}
else if ((nt.getFirstToken() == "lsa-refresh-time"))
else if (section == "fib")
{
processConfCommandLsaRefreshTime(nt.getRestOfLine());
ret = processConfSectionFib(SectionAttributeTree);
}
else if ((nt.getFirstToken() == "max-faces-per-prefix"))
else if (section == "advertising")
{
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());
ret = processConfSectionAdvertising(SectionAttributeTree);
}
else
{
cout << "Wrong configuration Command: " << nt.getFirstToken() << endl;
std::cerr << "Wrong configuration Command: " << section << std::endl;
}
return ret;
}
int
ConfFileProcessor::processConfCommandNetwork(string command)
bool
ConfFileProcessor::processConfSectionGeneral(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] == '/')
{
command.erase(command.size() - 1);
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);
}
if (command[0] == '/')
{
command.erase(0, 1);
else {
cerr << " Network can not be null or empty or in bad URI format :(!" << endl;
return false;
}
m_nlsr.getConfParameter().setNetwork(command);
}
return 0;
}
int
ConfFileProcessor::processConfCommandSiteName(string command)
{
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);
ndn::Name siteName(site);
if (!siteName.empty()) {
m_nlsr.getConfParameter().setSiteName(siteName);
}
if (command[0] == '/')
{
command.erase(0, 1);
else {
cerr << "Site can not be null or empty or in bad URI format:( !" << endl;
return false;
}
m_nlsr.getConfParameter().setSiteName(command);
}
return 0;
}
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);
ndn::Name routerName(router);
if (!routerName.empty()) {
m_nlsr.getConfParameter().setRouterName(routerName);
}
if (command[0] == '/')
{
command.erase(0, 1);
else {
cerr << " Router name can not be null or empty or in bad URI format:( !" << endl;
return false;
}
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;
catch (const std::exception& ex) {
cerr << ex.what() << endl;
return false;
}
else
{
if (command[command.size() - 1] == '/')
{
command.erase(command.size() - 1);
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);
}
if (command[0] == '/')
{
command.erase(0, 1);
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;
}
m_nlsr.getConfParameter().setRouterName(command);
}
return 0;
}
int
ConfFileProcessor::processConfCommandInterestRetryNumber(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [interest-retry-num n]" << endl;
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return false;
}
else
{
int irn;
stringstream ss(command.c_str());
ss >> irn;
if (irn >= 1 && irn <= 5)
{
m_nlsr.getConfParameter().setInterestRetryNumber(irn);
try {
std::string logLevel = SectionAttributeTree.get<string>("log-level");
if ( boost::iequals(logLevel, "info") || boost::iequals(logLevel, "debug")) {
m_nlsr.getConfParameter().setLogLevel(logLevel);
}
}
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);
else {
std::cerr << "Wrong value for log-level ";
std::cerr << "Allowed value: INFO, DEBUG" << std::endl;
return false;
}
}
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);
}
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return false;
}
return 0;
return true;
}
int
ConfFileProcessor::processConfCommandMaxFacesPerPrefix(string command)
bool
ConfFileProcessor::processConfSectionNeighbors(boost::property_tree::ptree
SectionAttributeTree)
{
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);
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;
}
}
return 0;
}
int
ConfFileProcessor::processConfCommandTunnelType(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl;
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return false;
}
else
{
if (command == "tcp" || command == "TCP")
{
m_nlsr.getConfParameter().setTunnelType(1);
try {
int timeOut = SectionAttributeTree.get<int>("hello-timeout");
if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
m_nlsr.getConfParameter().setInterestResendTime(timeOut);
}
else if (command == "udp" || command == "UDP")
{
m_nlsr.getConfParameter().setTunnelType(0);
}
else
{
cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl;
else {
std::cerr << "Wrong value for hello-timeout. ";
std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
std::cerr << HELLO_TIMEOUT_MAX << std::endl;
return false;
}
}
return 0;
}
int
ConfFileProcessor::processConfCommandChronosyncSyncPrefix(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [chronosync-sync-prefix name/prefix]!" << endl;
catch (const std::exception& ex) {
std::cerr << ex.what() << std::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);
try {
int interval = SectionAttributeTree.get<int>("hello-interval");
if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
m_nlsr.getConfParameter().setInfoInterestInterval(interval);
}
else if (command == "off" || command == "off")
{
m_nlsr.getConfParameter().setDebugging(0);
}
else
{
cerr << " Wrong command format ! [debugging on/off]!" << endl;
else {
std::cerr << "Wrong value for hello-interval. ";
std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
std::cerr << HELLO_INTERVAL_MAX << std::endl;
return false;
}
}
return 0;
}
int
ConfFileProcessor::processConfCommandDetailedLogging(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [detailed-logging on/off]!" << endl;
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
}
else
{
if (command == "on" || command == "ON")
for (boost::property_tree::ptree::const_iterator tn =
SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) {
if (tn->first == "neighbor")
{
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;
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;
}
}
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return false;
}
}
}
return 0;
return true;
}
int
ConfFileProcessor::processConfCommandIsHyperbolicCalc(string command)
bool
ConfFileProcessor::processConfSectionHyperbolic(boost::property_tree::ptree
SectionAttributeTree)
{
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);
std::string state;
try {
state= SectionAttributeTree.get<string>("state","off");
if (boost::iequals(state, "off")) {
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
}
else if (command == "dry-run" || command == "DRY-RUN")
{
m_nlsr.getConfParameter().setIsHyperbolicCalc(2);
else if (boost::iequals(state, "on")) {
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
}
else if (command == "off" || command == "off")
{
m_nlsr.getConfParameter().setIsHyperbolicCalc(0);
else if (state == "dry-run") {
m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
}
else
{
cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl;
else {
std::cerr << "Wrong format for hyperbolic state." << std::endl;
std::cerr << "Allowed value: off, on, dry-run" << std::endl;
return false;
}
}
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;
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return false;
}
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
{
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);
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
if (state == "on" || state == "dry-run") {
return false;
}
}
return 0;
return true;
}
int
ConfFileProcessor::processConfCommandNdnNeighbor(string command)
bool
ConfFileProcessor::processConfSectionFib(boost::property_tree::ptree
SectionAttributeTree)
{
if (command.empty())
{
cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl;
}
else
{
Tokenizer nt(command, " ");
if (nt.getRestOfLine().empty())
try {
int maxFacesPerPrefixNumber =
SectionAttributeTree.get<int>("max-faces-per-prefix");
if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN &&
maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX)
{
cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl;
return 0;
m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber);
}
else
{
stringstream sst(nt.getRestOfLine().c_str());
int faceId;
sst >> faceId;
Adjacent adj(nt.getFirstToken(), faceId, 10, 0, 0);
m_nlsr.getAdjacencyList().insert(adj);
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;
}
}
return 0;
}
int
ConfFileProcessor::processConfCommandNdnName(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [ndnname name/prefix]!" << endl;
}
else
{
m_nlsr.getNamePrefixList().insert(command);
catch (const std::exception& ex) {
cerr << ex.what() << endl;
return false;
}
return 0;
return true;
}
int
ConfFileProcessor::processConfCommandLinkCost(string command)
bool
ConfFileProcessor::processConfSectionAdvertising(boost::property_tree::ptree
SectionAttributeTree)
{
if (command.empty())
{
cerr << " Wrong command format ! [link-cost nbr/name cost]!" << endl;
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0)
{
return -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;
}
}
}
else
{
Tokenizer nt(command, " ");
stringstream sst(nt.getRestOfLine().c_str());
double cost;
sst >> cost;
m_nlsr.getAdjacencyList().updateAdjacentLinkCost(nt.getFirstToken(), cost);
}
return 0;
return true;
}
} //namespace nlsr
}//namespace NLSR

81
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 @@ public:
{
}
int processConfFile();
bool
processConfFile();
private:
int
processConfCommand(std::string command);
int
processConfCommandNetwork(std::string command);
int
processConfCommandSiteName(std::string command);
int
processConfCommandRootKeyPrefix(std::string command);
int
processConfCommandRouterName(std::string command);
int
processConfCommandInterestRetryNumber(std::string command);
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);
bool
load(std::istream& input);
int
processConfCommandIsHyperbolicCalc(std::string command);
bool
processSection(const std::string& section,
boost::property_tree::ptree SectionAttributeTree);
int
processConfCommandHyperbolicCordinate(std::string command);
bool
processConfSectionGeneral(boost::property_tree::ptree SectionAttributeTree);
int
processConfCommandNdnNeighbor(std::string command);
bool
processConfSectionNeighbors(boost::property_tree::ptree SectionAttributeTree);
int
processConfCommandNdnName(std::string command);
bool
processConfSectionHyperbolic(boost::property_tree::ptree SectionAttributeTree);
int
processConfCommandLinkCost(std::string command);
bool
processConfSectionFib(boost::property_tree::ptree SectionAttributeTree);
bool
processConfSectionAdvertising(boost::property_tree::ptree SectionAttributeTree);
private:
std::string m_confFileName;
@ -85,4 +50,4 @@ private:
};
} //namespace nlsr
#endif //CONF_FILE_PROCESSOR_HPP
#endif //CONF_PROCESSOR_HPP

31
src/conf-parameter.cpp

@ -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

310
src/conf-parameter.hpp

@ -7,70 +7,105 @@
#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);
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&
getRouterName()
getNetwork()
{
return m_routerName;
return m_network;
}
void
setSiteName(const std::string& sn)
setRouterName(const ndn::Name& routerName)
{
m_siteName = ndn::Name(sn);
m_routerName = routerName;
}
const ndn::Name&
getSiteName()
getRouterName()
{
return m_siteName;
return m_routerName;
}
void
setNetwork(const std::string& nn)
setSiteName(const ndn::Name& siteName)
{
m_network = ndn::Name(nn);
m_siteName = siteName;
}
const ndn::Name&
getNetwork()
getSiteName()
{
return m_network;
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 @@ public:
return m_routerPrefix;
}
const ndn::Name&
getRootKeyPrefix()
{
return m_rootKeyPrefix;
}
void
setRootKeyPrefix(std::string rkp)
{
m_rootKeyPrefix = ndn::Name(rkp);
}
void
setInterestRetryNumber(uint32_t irn)
{
m_interestRetryNumber = irn;
}
uint32_t
getInterestRetryNumber()
{
return m_interestRetryNumber;
}
void
setInterestResendTime(int32_t irt)
const ndn::Name&
getChronosyncPrefix()
{
m_interestResendTime = irt;
return m_chronosyncPrefix;
}
int32_t
getInterestResendTime()
const ndn::Name&
getLsaPrefix()
{
return m_interestResendTime;
return m_lsaPrefix;
}
void
@ -142,95 +154,75 @@ public:
{
return m_routerDeadInterval;
}
void
setMaxFacesPerPrefix(int32_t mfpp)
void
setLogLevel(const std::string& logLevel)
{
m_maxFacesPerPrefix = mfpp;
m_logLevel = logLevel;
}
int32_t
getMaxFacesPerPrefix()
const std::string&
getLogLevel()
{
return m_maxFacesPerPrefix;
return m_logLevel;
}
void
setLogDir(const std::string& ld)
{
m_logDir = ld;
}
std::string
getLogDir()
{
return m_logDir;
}
void
setCertDir(const std::string& cd)
setInterestRetryNumber(uint32_t irn)
{
m_certDir = cd;
m_interestRetryNumber = irn;
}
const std::string&
getCertDir()
uint32_t
getInterestRetryNumber()
{
return m_certDir;
return m_interestRetryNumber;
}
void
setSeqFileDir(const std::string& ssfd)
{
m_seqFileDir = ssfd;
}
const std::string&
getSeqFileDir()
setInterestResendTime(int32_t irt)
{
return m_seqFileDir;
m_interestResendTime = irt;
}
void
setDetailedLogging(int dl)
int32_t
getInterestResendTime()
{
m_detailedLogging = dl;
return m_interestResendTime;
}
int
getDetailedLogging()
int32_t
getInfoInterestInterval()
{
return m_detailedLogging;
return m_infoInterestInterval;
}
void
setDebugging(int32_t d)
{
m_debugging = d;
}
int32_t
getDebugging()
setInfoInterestInterval(int32_t iii)
{
return m_debugging;
m_infoInterestInterval = iii;
}
void
setIsHyperbolicCalc(int32_t ihc)
setHyperbolicState(int32_t ihc)
{
m_isHyperbolicCalc = 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 @@ public:
{
return m_corTheta;
}
void
setTunnelType(int tt)
setMaxFacesPerPrefix(int32_t mfpp)
{
m_tunnelType = tt;
m_maxFacesPerPrefix = mfpp;
}
int32_t
getTunnelType()
{
return m_tunnelType;
}
void
setChronosyncSyncPrefix(const std::string& csp)
{
m_chronosyncSyncPrefix = ndn::Name(csp);
}
const ndn::Name&
getChronosyncSyncPrefix()
getMaxFacesPerPrefix()
{
return m_chronosyncSyncPrefix;
return m_maxFacesPerPrefix;
}
void
setChronosyncLsaPrefix(const std::string& clp)
{
m_chronosyncLsaPrefix = ndn::Name(clp);
}
const ndn::Name&
getChronosyncLsaPrefix()
setSeqFileDir(const std::string& ssfd)
{
return m_chronosyncLsaPrefix;
m_seqFileDir = ssfd;
}
int32_t
getInfoInterestInterval()
const std::string&
getSeqFileDir()
{
return m_infoInterestInterval;
return m_seqFileDir;
}
void
setInfoInterestInterval(int32_t iii)
{
m_infoInterestInterval = iii;
}
private:
ndn::Name m_routerName;
@ -307,35 +276,48 @@ private:
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;
uint32_t m_interestRetryNumber;
int32_t m_interestResendTime;
int32_t m_infoInterestInterval;
int32_t m_lsaRefreshTime;
int64_t m_routerDeadInterval;
int32_t m_lsaRefreshTime;
int64_t m_routerDeadInterval;
std::string m_logLevel;
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;
uint32_t m_interestRetryNumber;
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

68
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 @@ HelloProtocol::sendScheduledInterest(uint32_t seconds)
{
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 @@ HelloProtocol::processInterest(const ndn::Name& name,
{
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 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
{
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 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
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 @@ HelloProtocol::processContent(const ndn::Interest& interest,
{
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 @@ HelloProtocol::processContent(const ndn::Interest& interest,
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())));
}
}
}

1
src/hello-protocol.hpp

@ -41,6 +41,7 @@ private:
private:
Nlsr& m_nlsr;
ndn::KeyChain m_keyChain;
static const std::string INFO_COMPONENT;
};
} //namespace nlsr

46
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 @@ NameLsa::NameLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
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 @@ NameLsa::getData()
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 @@ NameLsa::initializeFromContent(const std::string& content)
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 @@ NameLsa::initializeFromContent(const std::string& content)
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 @@ CoordinateLsa::initializeFromContent(const std::string& content)
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 @@ AdjLsa::AdjLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
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 @@ AdjLsa::getData()
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 @@ AdjLsa::initializeFromContent(const std::string& content)
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 @@ AdjLsa::initializeFromContent(const std::string& content)
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 @@ AdjLsa::initializeFromContent(const std::string& content)
void
AdjLsa::addNptEntries(Nlsr& pnlsr)
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter());
}
}
@ -306,8 +293,7 @@ AdjLsa::addNptEntries(Nlsr& pnlsr)
void
AdjLsa::removeNptEntries(Nlsr& pnlsr)
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter());
}
}
@ -330,7 +316,7 @@ operator<<(std::ostream& os, AdjLsa& aLsa)
{
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;

12
src/lsa.hpp

@ -152,8 +152,7 @@ public:
}
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 @@ public:
double
getCorRadius() const
{
if (m_corRad >= 0)
{
return m_corRad;
}
else
{
return -1;
}
}
void
setCorRadius(double cr)
{
m_corRad = cr;
m_corRad = cr;
}
double

348
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 @@ Lsdb::findNameLsa(const ndn::Name& key)
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 @@ bool
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 @@ Lsdb::installNameLsa(NameLsa& nlsa)
{
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 @@ Lsdb::installNameLsa(NameLsa& nlsa)
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 @@ Lsdb::installNameLsa(NameLsa& nlsa)
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 @@ Lsdb::addNameLsa(NameLsa& nlsa)
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 @@ Lsdb::removeNameLsa(const ndn::Name& key)
{
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 @@ Lsdb::doesNameLsaExist(const ndn::Name& key)
{
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 @@ Lsdb::printNameLsdb()
{
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 @@ Lsdb::findCoordinateLsa(const ndn::Name& key)
{
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 @@ bool
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 @@ Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
{
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 @@ Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
{
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 @@ Lsdb::removeCoordinateLsa(const ndn::Name& key)
{
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 @@ Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
{
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 @@ Lsdb::scheduledAdjLsaBuild()
{
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 @@ Lsdb::scheduledAdjLsaBuild()
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 @@ Lsdb::addAdjLsa(AdjLsa& alsa)
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 @@ Lsdb::findAdjLsa(const ndn::Name& key)
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 @@ bool
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 @@ Lsdb::installAdjLsa(AdjLsa& alsa)
{
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 @@ Lsdb::buildAndInstallOwnAdjLsa()
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 @@ Lsdb::removeAdjLsa(const ndn::Name& key)
{
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 @@ Lsdb::doesAdjLsaExist(const ndn::Name& key)
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 @@ Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
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 @@ Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
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 @@ Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
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 @@ Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
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 @@ Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
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 @@ Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
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 @@ Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
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 @@ Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
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 @@ Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
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 @@ Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
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 @@ Lsdb::processContent(const ndn::Interest& interest, const ndn::Data& data)
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 @@ void
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 @@ void
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 @@ void
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 @@ Lsdb::printAdjLsdb()
{
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 @@ Lsdb::printAdjLsdb()
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;

6
src/lsdb.hpp

@ -39,8 +39,9 @@ public:
bool
isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
//debugging
void
printNameLsdb(); //debugging
printNameLsdb();
//function related to Cor LSDB
bool
@ -58,8 +59,9 @@ public:
bool
isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
//debugging
void
printCorLsdb(); //debugging
printCorLsdb();
//function related to Adj LSDB
void

6
src/main.cpp

@ -30,8 +30,7 @@ main(int32_t argc, char** argv)
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 @@ main(int32_t argc, char** argv)
}
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;

10
src/name-prefix-list.cpp

@ -30,8 +30,7 @@ NamePrefixList::insert(const ndn::Name& name)
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 @@ NamePrefixList::remove(const ndn::Name& name)
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 @@ NamePrefixList::print()
{
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++;
}

34
src/nlsr.cpp

@ -4,6 +4,7 @@
#include <cstdio>
#include "nlsr.hpp"
#include "adjacent.hpp"
namespace nlsr {
@ -18,6 +19,10 @@ Nlsr::registrationFailed(const ndn::Name& name)
throw Error("Error: Prefix registration failed");
}
void
Nlsr::onRegistrationSuccess(const ndn::Name& name)
{
}
void
Nlsr::setInfoInterestFilter()
@ -26,22 +31,42 @@ Nlsr::setInfoInterestFilter()
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()
{
@ -56,11 +81,12 @@ Nlsr::initialize()
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);

9
src/nlsr.hpp

@ -58,6 +58,9 @@ public:
void
registrationFailed(const ndn::Name& name);
void
onRegistrationSuccess(const ndn::Name& name);
void
setInfoInterestFilter();
@ -172,7 +175,7 @@ public:
m_adjBuildCount = abc;
}
int
bool
getIsBuildAdjLsaSheduled()
{
return m_isBuildAdjLsaSheduled;
@ -230,6 +233,10 @@ public:
void
initialize();
private:
void
registerPrefixes();
private:
ndn::Face m_nlsrFace;
ndn::Scheduler m_scheduler;

115
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

15
src/route/fib-entry.cpp

@ -9,25 +9,20 @@ using namespace std;
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;
}
}

206
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 @@ Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum)
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 @@ Fib::remove(const ndn::Name& name)
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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList)
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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList)
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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList)
(*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
it->getSeqNo(), m_refreshTime));
}
else
{
else {
remove(name);
}
}
@ -181,33 +168,27 @@ void
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 @@ Fib::getNumberOfFacesForName(NexthopList& nextHopList,
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 @@ Fib::removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
}
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 @@ Fib::print()
{
cout << "-------------------FIB-----------------------------" << endl;
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
++it)
{
++it) {
cout << (*it);
}
}

25
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 @@ public:
, m_table()
, m_refreshTime(0)
, m_controller(face)
, m_faceMap()
{
}
~Fib()
@ -47,7 +48,7 @@ public:
private:
void
removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
const ndn::Name& name);
int
@ -63,12 +64,25 @@ private:
void
refreshEntry(const ndn::Name& name, int32_t feSeqNum);
public:
void
registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
uint64_t faceCost, uint64_t timeout);
void
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
registerPrefixInNfd(const ndn::Name& namePrefix, uint64_t faceId,
uint64_t faceCost);
unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
void
unregisterPrefixFromNfd(const ndn::Name& namePrefix, uint64_t faceId);
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 @@ private:
std::list<FibEntry> m_table;
int32_t m_refreshTime;
ndn::nfd::Controller m_controller;
FaceMap m_faceMap;
};
}//namespace nlsr

34
src/route/map.cpp

@ -27,8 +27,7 @@ void
Map::addEntry(const ndn::Name& rtrName)
{
MapEntry me(rtrName, m_mappingIndex);
if (addEntry(me))
{
if (addEntry(me)) {
m_mappingIndex++;
}
}
@ -39,9 +38,9 @@ Map::addEntry(MapEntry& mpe)
//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 @@ Map::getRouterNameByMappingNo(int32_t mn)
{
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 @@ Map::getMappingNoByRouterName(const ndn::Name& rName)
{
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 @@ Map::createFromAdjLsdb(Nlsr& pnlsr)
{
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 @@ operator<<(ostream& os, Map& map)
{
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;

6
src/route/name-prefix-table-entry.cpp

@ -59,8 +59,7 @@ NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
(*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 @@ operator<<(ostream& os, NamePrefixTableEntry& npte)
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();

6
src/route/name-prefix-table-entry.hpp

@ -37,11 +37,9 @@ public:
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();
}
}

57
src/route/name-prefix-table.cpp

@ -25,30 +25,26 @@ void
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 @@ void
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 @@ NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte)
(!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 @@ NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
//
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 @@ NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
//
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 @@ void
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 @@ NamePrefixTable::print()
std::cout << "----------------NPT----------------------" << std::endl;
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
it != m_table.end();
++it)
{
++it) {
cout << (*it) << endl;
}
}

20
src/route/nexthop-list.cpp

@ -9,13 +9,13 @@ using namespace std;
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 @@ NexthopList::addNextHop(NextHop& nh)
{
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 @@ NexthopList::removeNextHop(NextHop& nh)
{
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 @@ operator<<(ostream& os, NexthopList& nhl)
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;

13
src/route/nexthop.cpp

@ -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

27
src/route/nexthop.hpp

@ -9,27 +9,27 @@ class NextHop
{
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 @@ public:
}
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

173
src/route/routing-table-calculator.cpp

@ -15,8 +15,7 @@ void
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 @@ RoutingTableCalculator::allocateAdjMatrix()
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 @@ RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
{
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 @@ RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
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 @@ RoutingTableCalculator::printAdjMatrix()
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 @@ int
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 @@ RoutingTableCalculator::getLinksFromAdjMatrix(int* links,
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 @@ RoutingTableCalculator::getLinksFromAdjMatrix(int* links,
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 @@ LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
//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 @@ LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
// 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 @@ LinkStateRoutingTableCalculator::doDijkstraPathCalculation(int sourceRouter)
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::addAllLsNextHopsToRoutingTable(Nlsr& pnlsr,
"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 @@ int
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 @@ LinkStateRoutingTableCalculator::printAllLsPath(int sourceRouter)
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 @@ LinkStateRoutingTableCalculator::printAllLsPath(int sourceRouter)
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 @@ void
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 @@ LinkStateRoutingTableCalculator::isNotExplored(int* Q,
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 @@ HypRoutingTableCalculator::calculatePath(Map& pMap,
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 @@ void
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 @@ HypRoutingTableCalculator::getHyperbolicDistance(Nlsr& pnlsr,
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 @@ HypRoutingTableCalculator::getHyperbolicDistance(Nlsr& pnlsr,
void
HypRoutingTableCalculator::allocateLinkFaces()
{
m_linkFaces = new int[vNoLink];
m_linkFaceUris.reserve(vNoLink);
}
void
@ -495,7 +452,7 @@ HypRoutingTableCalculator::allocateDistFromNbrToDest()
void
HypRoutingTableCalculator::freeLinkFaces()
{
delete [] m_linkFaces;
m_linkFaceUris.clear();
}
void

2
src/route/routing-table-calculator.hpp

@ -189,7 +189,7 @@ private:
private:
bool m_isDryRun;
int* m_linkFaces;
std::vector<std::string> m_linkFaceUris;
double* m_distanceToNeighbor;
double* m_distFromNbrToDest;

3
src/route/routing-table-entry.hpp

@ -48,8 +48,7 @@ operator<<(std::ostream& os, RoutingTableEntry& rte)
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;

87
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 @@ RoutingTable::calculate(Nlsr& pnlsr)
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 @@ RoutingTable::calculate(Nlsr& pnlsr)
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 @@ RoutingTable::calculate(Nlsr& pnlsr)
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 @@ RoutingTable::calculateLsRoutingTable(Nlsr& pnlsr)
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 @@ RoutingTable::calculateHypRoutingTable(Nlsr& pnlsr)
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 @@ RoutingTable::calculateHypDryRoutingTable(Nlsr& pnlsr)
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 @@ void
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 @@ RoutingTable::findRoutingTableEntry(const ndn::Name& destRouter)
{
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 @@ RoutingTable::printRoutingTable()
{
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 @@ RoutingTable::addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh)
{
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 @@ RoutingTable::printDryRoutingTable()
{
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 @@ RoutingTable::printDryRoutingTable()
void
RoutingTable::clearRoutingTable()
{
if (m_rTable.size() > 0)
{
if (m_rTable.size() > 0) {
m_rTable.clear();
}
}
@ -221,8 +209,7 @@ RoutingTable::clearRoutingTable()
void
RoutingTable::clearDryRoutingTable()
{
if (m_dryTable.size() > 0)
{
if (m_dryTable.size() > 0) {
m_dryTable.clear();
}
}

12
src/sequencing-manager.cpp

@ -42,8 +42,7 @@ SequencingManager::initiateSeqNoFromFile()
{
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 @@ SequencingManager::initiateSeqNoFromFile()
combineSequenceNo();
inputFile.close();
}
else
{
else {
splittSequenceNo(0);
}
}
@ -62,8 +60,7 @@ void
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 @@ string
SequencingManager::getUserHomeDirectory()
{
string homeDirPath(getpwuid(getuid())->pw_dir);
if (homeDirPath.empty())
{
if (homeDirPath.empty()) {
homeDirPath = getenv("HOME");
}
return homeDirPath;

9
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 @@ getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
{
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;
}
}

111
src/utility/tokenizer.cpp

@ -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

117
src/utility/tokenizer.hpp

@ -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

61
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 @@ BOOST_AUTO_TEST_CASE(ConfFileProcessorSample)
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 @@ BOOST_AUTO_TEST_CASE(ConfFileProcessorSample)
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);

41
tests/test-conf-parameter.cpp

@ -28,8 +28,6 @@ BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
cp1.setNetwork(NETWORK);
cp1.setRootKeyPrefix("adminRootKey");
cp1.setInterestRetryNumber(2);
cp1.setInterestResendTime(1000);
@ -40,29 +38,12 @@ BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
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_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
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_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
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);
}

2
tests/test-lsdb.cpp

@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
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);

4
tests/test-nexthop.cpp

@ -16,11 +16,11 @@ BOOST_AUTO_TEST_CASE(NexthopSetAndGet)
{
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);
}

34
tests/test-tokenizer.cpp

@ -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

2
wscript

@ -46,7 +46,7 @@ def configure(conf):
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);

Loading…
Cancel
Save