src: Renaming class to spell out them (Adl, Nhl, Npl, Npt, Npte)
Refs: #1534
Change-Id: If4a205e8ad2419505cc796027a5c863471ef5439
diff --git a/nsync/openssl.h b/nsync/openssl.h
new file mode 100644
index 0000000..a8707a9
--- /dev/null
+++ b/nsync/openssl.h
@@ -0,0 +1,21 @@
+#ifndef NSYNC_OPENSSL_H
+#define NSYNC_OPENSSL_H
+
+// suppress deprecation warnings in OSX >= 10.7
+
+#if defined(__APPLE__)
+
+#ifdef __clang__
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif // __clang__
+
+#ifdef __GNUC__
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif // __GNUC__
+
+#endif
+
+
+#include <openssl/evp.h>
+
+#endif // NSYNC_OPENSSL_H
diff --git a/nsync/sync-digest.h b/nsync/sync-digest.h
index ecc8522..da45758 100644
--- a/nsync/sync-digest.h
+++ b/nsync/sync-digest.h
@@ -17,16 +17,16 @@
*
* 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>
*/
#ifndef SYNC_DIGEST_H
#define SYNC_DIGEST_H
#include <boost/exception/all.hpp>
-#include <openssl/evp.h>
#include <boost/cstdint.hpp>
#include <vector>
+#include "openssl.h"
namespace Sync {
@@ -47,7 +47,7 @@
*/
bool
empty () const;
-
+
/**
* @brief Reset digest to the initial state
*/
@@ -84,7 +84,7 @@
bool
operator != (const Digest &digest) const
{ return ! (*this == digest); }
-
+
/**
* @brief Add existing digest to digest calculation
@@ -116,11 +116,11 @@
*/
bool
isZero () const;
-
+
private:
Digest &
operator = (Digest &digest) { (void)digest; return *this; }
-
+
/**
* @brief Add size bytes of buffer to the hash
*/
@@ -132,7 +132,7 @@
friend std::istream &
operator >> (std::istream &is, Digest &digest);
-
+
private:
EVP_MD_CTX *m_context;
std::vector<uint8_t> m_buffer;
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index 7f21a80..a529b17 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -8,6 +8,8 @@
namespace nlsr {
+using namespace std;
+
AdjacencyList::AdjacencyList()
{
}
@@ -16,26 +18,20 @@
{
}
-static bool
-adjacent_compare(Adjacent& adj1, Adjacent& adj2)
+int32_t
+AdjacencyList::insert(Adjacent& adjacent)
{
- return adj1.getName() == adj2.getName();
-}
-
-int
-AdjacencyList::insert(Adjacent& adj)
-{
- std::list<Adjacent>::iterator it = find(adj.getName());
+ std::list<Adjacent>::iterator it = find(adjacent.getName());
if (it != m_adjList.end())
{
return -1;
}
- m_adjList.push_back(adj);
+ m_adjList.push_back(adjacent);
return 0;
}
void
-AdjacencyList::addAdjacentsFromAdl(AdjacencyList& adl)
+AdjacencyList::addAdjacents(AdjacencyList& adl)
{
for (std::list<Adjacent>::iterator it = adl.getAdjList().begin();
it != adl.getAdjList().end(); ++it)
@@ -44,8 +40,8 @@
}
}
-int
-AdjacencyList::updateAdjacentStatus(const string& adjName, int s)
+int32_t
+AdjacencyList::updateAdjacentStatus(const string& adjName, int32_t s)
{
std::list<Adjacent>::iterator it = find(adjName);
if (it == m_adjList.end())
@@ -68,24 +64,29 @@
return adj;
}
+static bool
+compareAdjacent(const Adjacent& adjacent1, const Adjacent& adjacent2)
+{
+ return adjacent1.getName() < adjacent2.getName();
+}
bool
-AdjacencyList::isEqual(AdjacencyList& adl)
+AdjacencyList::operator==(AdjacencyList& adl)
{
if (getSize() != adl.getSize())
{
return false;
}
- m_adjList.sort(adjacent_compare);
- adl.getAdjList().sort(adjacent_compare);
- int equalAdjCount = 0;
- std::list<Adjacent> adjList2 = adl.getAdjList();
+ m_adjList.sort(compareAdjacent);
+ adl.getAdjList().sort(compareAdjacent);
+ uint32_t equalAdjCount = 0;
+ std::list<Adjacent>& adjList2 = adl.getAdjList();
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).isEqual((*it2)))
+ if (!((*it1) == (*it2)))
{
break;
}
@@ -94,8 +95,7 @@
return equalAdjCount == getSize();
}
-
-int
+int32_t
AdjacencyList::updateAdjacentLinkCost(const string& adjName, double lc)
{
std::list<Adjacent>::iterator it = find(adjName);
@@ -130,7 +130,7 @@
}
void
-AdjacencyList::setTimedOutInterestCount(const string& neighbor, int count)
+AdjacencyList::setTimedOutInterestCount(const string& neighbor, uint32_t count)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it != m_adjList.end())
@@ -139,7 +139,7 @@
}
}
-int
+int32_t
AdjacencyList::getTimedOutInterestCount(const string& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
@@ -150,7 +150,7 @@
return (*it).getInterestTimedOutNo();
}
-int
+uint32_t
AdjacencyList::getStatusOfNeighbor(const string& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
@@ -162,7 +162,7 @@
}
void
-AdjacencyList::setStatusOfNeighbor(const string& neighbor, int status)
+AdjacencyList::setStatusOfNeighbor(const string& neighbor, int32_t status)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it != m_adjList.end())
@@ -204,10 +204,10 @@
return false;
}
-int
+int32_t
AdjacencyList::getNumOfActiveNeighbor()
{
- int actNbrCount = 0;
+ int32_t actNbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin();
it != m_adjList.end(); it++)
{
@@ -225,7 +225,7 @@
Adjacent adj(adjName);
std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
m_adjList.end(),
- bind(&adjacent_compare, _1, adj));
+ bind(&Adjacent::compareName, &adj, _1));
return it;
}
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index 45123df..a88a6ba 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -1,8 +1,9 @@
-#ifndef NLSR_ADL_HPP
-#define NLSR_ADL_HPP
+#ifndef NLSR_ADJACENCY_LIST_HPP
+#define NLSR_ADJACENCY_LIST_HPP
-#include <ndn-cxx/common.hpp>
#include <list>
+#include <boost/cstdint.hpp>
+#include <ndn-cxx/common.hpp>
#include "adjacent.hpp"
@@ -16,13 +17,13 @@
AdjacencyList();
~AdjacencyList();
- int
- insert(Adjacent& adj);
+ int32_t
+ insert(Adjacent& adjacent);
- int
- updateAdjacentStatus(const std::string& adjName, int s);
+ int32_t
+ updateAdjacentStatus(const std::string& adjName, int32_t s);
- int
+ int32_t
updateAdjacentLinkCost(const std::string& adjName, double lc);
std::list<Adjacent>&
@@ -34,34 +35,34 @@
void
incrementTimedOutInterestCount(const std::string& neighbor);
- int
+ int32_t
getTimedOutInterestCount(const std::string& neighbor);
- int
+ uint32_t
getStatusOfNeighbor(const std::string& neighbor);
void
- setStatusOfNeighbor(const std::string& neighbor, int status);
+ setStatusOfNeighbor(const std::string& neighbor, int32_t status);
void
- setTimedOutInterestCount(const std::string& neighbor, int count);
+ setTimedOutInterestCount(const std::string& neighbor, uint32_t count);
void
- addAdjacentsFromAdl(AdjacencyList& adl);
+ addAdjacents(AdjacencyList& adl);
bool
isAdjLsaBuildable(Nlsr& pnlsr);
- int
+ int32_t
getNumOfActiveNeighbor();
Adjacent
getAdjacent(const std::string& adjName);
bool
- isEqual(AdjacencyList& adl);
+ operator==(AdjacencyList& adl);
- int
+ size_t
getSize()
{
return m_adjList.size();
@@ -88,4 +89,4 @@
};
} //namespace nlsr
-#endif //NLSR_ADL_HPP
+#endif //NLSR_ADJACENCY_LIST_HPP
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index 3212c1e..f5a2c8e 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -3,13 +3,14 @@
#include <cmath>
#include <limits>
+
#include "adjacent.hpp"
namespace nlsr {
using namespace std;
-Adjacent::Adjacent(const string& an, int cf, double lc, int s, int iton)
+Adjacent::Adjacent(const string& an, uint32_t cf, double lc, uint32_t s, uint32_t iton)
{
m_name = an;
m_connectingFace = cf;
@@ -19,18 +20,24 @@
}
bool
-Adjacent::isEqual(Adjacent& adj)
+Adjacent::operator==(const Adjacent& adjacent) const
{
- return (m_name == adj.getName()) &&
- (m_connectingFace == adj.getConnectingFace()) &&
- (std::abs(m_linkCost - adj.getLinkCost()) <
+ return (m_name == adjacent.getName()) &&
+ (m_connectingFace == adjacent.getConnectingFace()) &&
+ (std::abs(m_linkCost - adjacent.getLinkCost()) <
std::numeric_limits<double>::epsilon()) ;
}
-std::ostream&
-operator<<(std::ostream& os, Adjacent& adj)
+bool
+Adjacent::compareName(const Adjacent& adjacent)
{
- os << "Adjacent : " << adj.getName() << endl;
+ return m_name == adjacent.getName();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const Adjacent& adj)
+{
+ os << "Adjacent : " << adj.getName() << endl;
os << "Connecting Face: " << adj.getConnectingFace() << endl;
os << "Link Cost: " << adj.getLinkCost() << endl;
os << "Status: " << adj.getStatus() << endl;
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index 22066d1..b8b6695 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -1,7 +1,8 @@
#include <string>
+#include <boost/cstdint.hpp>
-#ifndef ADJACENT_HPP
-#define ADJACENT_HPP
+#ifndef NLSR_ADJACENT_HPP
+#define NLSR_ADJACENT_HPP
namespace nlsr {
class Adjacent
@@ -26,10 +27,10 @@
m_name = an;
}
- Adjacent(const std::string& an, int cf, double lc, int s, int iton);
+ Adjacent(const std::string& an, uint32_t cf, double lc, uint32_t s, uint32_t iton);
std::string
- getName()
+ getName() const
{
return m_name;
}
@@ -40,20 +41,20 @@
m_name = an;
}
- int
- getConnectingFace()
+ uint32_t
+ getConnectingFace() const
{
return m_connectingFace;
}
void
- setConnectingFace(int cf)
+ setConnectingFace(uint32_t cf)
{
m_connectingFace = cf;
}
double
- getLinkCost()
+ getLinkCost() const
{
return m_linkCost;
}
@@ -64,44 +65,47 @@
m_linkCost = lc;
}
- int
- getStatus()
+ uint32_t
+ getStatus() const
{
return m_status;
}
void
- setStatus(int s)
+ setStatus(uint32_t s)
{
m_status = s;
}
- int
- getInterestTimedOutNo()
+ uint32_t
+ getInterestTimedOutNo() const
{
return m_interestTimedOutNo;
}
void
- setInterestTimedOutNo(int iton)
+ setInterestTimedOutNo(uint32_t iton)
{
m_interestTimedOutNo = iton;
}
bool
- isEqual(Adjacent& adj);
+ operator==(const Adjacent& adjacent) const;
+ bool
+ compareName(const Adjacent& adjacent);
+
private:
std::string m_name;
- int m_connectingFace;
+ uint32_t m_connectingFace;
double m_linkCost;
- int m_status;
- int m_interestTimedOutNo;
+ uint32_t m_status;
+ uint32_t m_interestTimedOutNo;
};
std::ostream&
-operator<<(std::ostream& os, Adjacent& adj);
+operator<<(std::ostream& os, const Adjacent& adj);
} // namespace nlsr
-#endif //ADJACENT_HPP
+#endif //NLSR_ADJACENT_HPP
diff --git a/src/communication/data-manager.cpp b/src/communication/data-manager.cpp
index 8525ce7..3a153a3 100644
--- a/src/communication/data-manager.cpp
+++ b/src/communication/data-manager.cpp
@@ -61,8 +61,7 @@
string chkString("info");
string neighbor = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
- int infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
- neighbor);
+ int infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
//debugging purpose start
std::cout << "Before Updates: " << std::endl;
std::cout << "Neighbor : " << neighbor << std::endl;
@@ -72,8 +71,7 @@
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1);
m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
- infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
- neighbor);
+ infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
//debugging purpose
std::cout << "After Updates: " << std::endl;
std::cout << "Neighbor : " << neighbor << std::endl;
diff --git a/src/communication/data-manager.hpp b/src/communication/data-manager.hpp
index 86c2e42..ce10b88 100644
--- a/src/communication/data-manager.hpp
+++ b/src/communication/data-manager.hpp
@@ -1,5 +1,7 @@
-#ifndef NLSR_DM_HPP
-#define NLSR_DM_HPP
+#ifndef NLSR_DATA_MANAGER_HPP
+#define NLSR_DATA_MANAGER_HPP
+
+#include <boost/cstdint.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
@@ -50,4 +52,4 @@
}//namespace nlsr
-#endif //NLSR_DM_HPP
+#endif //NLSR_DATA_MANAGER_HPP
diff --git a/src/communication/interest-manager.cpp b/src/communication/interest-manager.cpp
index edcfec7..23ce579 100644
--- a/src/communication/interest-manager.cpp
+++ b/src/communication/interest-manager.cpp
@@ -1,7 +1,6 @@
#include <iostream>
#include <cstdlib>
-
#include <ndn-cxx/security/identity-certificate.hpp>
#include <ndn-cxx/util/io.hpp>
@@ -55,7 +54,7 @@
// m_nlsr.getKeyManager().signData(data);
m_keyChain.sign(data);
cout << ">> D: " << data << endl;
- m_nlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace().put(data);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
if (status == 0)
{
@@ -129,7 +128,7 @@
// m_nlsr.getKeyManager().signData(data);
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
- m_nlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace().put(data);
}
}
}
@@ -150,7 +149,7 @@
// m_nlsr.getKeyManager().signData(data);
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
- m_nlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace().put(data);
}
}
}
@@ -171,7 +170,7 @@
// m_nlsr.getKeyManager().signData(data);
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
- m_nlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace().put(data);
}
}
}
@@ -258,8 +257,7 @@
{
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
- int infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
- neighbor);
+ uint32_t infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
std::cout << "Neighbor: " << neighbor << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
@@ -294,23 +292,23 @@
void
InterestManager::expressInterest(const string& interestNamePrefix,
- int scope, int seconds)
+ int32_t scope, int32_t seconds)
{
std::cout << "Expressing Interest :" << interestNamePrefix << std::endl;
ndn::Interest i((ndn::Name(interestNamePrefix)));
i.setInterestLifetime(time::seconds(seconds));
i.setMustBeFresh(true);
- m_nlsr.getNlsrFace()->expressInterest(i,
- ndn::bind(&DataManager::processContent,
- &m_nlsr.getDataManager(),
- _1, _2, boost::ref(*this)),
- ndn::bind(&InterestManager::processInterestTimedOut,
- this, _1));
+ m_nlsr.getNlsrFace().expressInterest(i,
+ ndn::bind(&DataManager::processContent,
+ &m_nlsr.getDataManager(),
+ _1, _2, boost::ref(*this)),
+ ndn::bind(&InterestManager::processInterestTimedOut,
+ this, _1));
}
void
-InterestManager::sendScheduledInfoInterest(int seconds)
+InterestManager::sendScheduledInfoInterest(int32_t seconds)
{
std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
@@ -325,7 +323,7 @@
}
void
-InterestManager::scheduleInfoInterest(int seconds)
+InterestManager::scheduleInfoInterest(int32_t seconds)
{
EventId eid = m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
diff --git a/src/communication/interest-manager.hpp b/src/communication/interest-manager.hpp
index 7fe7655..00c798b 100644
--- a/src/communication/interest-manager.hpp
+++ b/src/communication/interest-manager.hpp
@@ -1,5 +1,7 @@
-#ifndef NLSR_IM_HPP
-#define NLSR_IM_HPP
+#ifndef NLSR_INTEREST_MANAGER_HPP
+#define NLSR_INTEREST_MANAGER_HPP
+
+#include <boost/cstdint.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
@@ -51,13 +53,13 @@
processInterestTimedOutLsa(const ndn::Interest& interest);
void
- expressInterest(const std::string& interestNamePrefix, int scope, int seconds);
+ expressInterest(const std::string& interestNamePrefix, int32_t scope, int32_t seconds);
void
- sendScheduledInfoInterest(int seconds);
+ sendScheduledInfoInterest(int32_t seconds);
void
- scheduleInfoInterest(int seconds);
+ scheduleInfoInterest(int32_t seconds);
private:
Nlsr& m_nlsr;
@@ -67,4 +69,4 @@
}//namespace nlsr
-#endif //NLSR_IM_HPP
+#endif //NLSR_INTEREST_MANAGER_HPP
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 51ec319..c8b5ec9 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -6,6 +6,9 @@
namespace nlsr {
+using namespace ndn;
+using namespace std;
+
void
SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
{
@@ -24,8 +27,8 @@
Sync::SyncSocket* socket, Nlsr& pnlsr)
{
std::cout << "nsyncUpdateCallBack called ...." << std::endl;
- int n = v.size();
- for (int i = 0; i < n; i++)
+ int32_t n = v.size();
+ for (int32_t i = 0; i < n; i++)
{
std::cout << "Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq() <<
endl;
@@ -40,12 +43,12 @@
}
void
-SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix)
+SyncLogicHandler::removeRouterFromSyncing(const string& routerPrefix)
{
}
void
-SyncLogicHandler::processUpdateFromSync(std::string updateName,
+SyncLogicHandler::processUpdateFromSync(const std::string& updateName,
uint64_t seqNo, Nlsr& pnlsr)
{
Tokenizer nt(updateName, "/");
@@ -66,7 +69,7 @@
}
void
-SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName,
+SyncLogicHandler::processRoutingUpdateFromSync(const std::string& routerName,
uint64_t seqNo, Nlsr& pnlsr)
{
if (routerName != pnlsr.getConfParameter().getRouterPrefix())
@@ -123,7 +126,7 @@
void
SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
- string updatePrefix)
+ const string& updatePrefix)
{
sm.writeSeqNoToFile();
publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo());
@@ -136,13 +139,13 @@
// }
void
-SyncLogicHandler::publishIdentityUpdate(string identityName)
+SyncLogicHandler::publishIdentityUpdate(const string& identityName)
{
publishSyncUpdate(identityName, 0);
}
void
-SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo)
+SyncLogicHandler::publishSyncUpdate(const string& updatePrefix, uint64_t seqNo)
{
std::cout << "Publishing Sync Update ......" << std::endl;
std::cout << "Update in prefix: " << updatePrefix << std::endl;
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 1896484..9f6badd 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -1,7 +1,8 @@
-#ifndef NLSR_SLH_HPP
-#define NLSR_SLH_HPP
+#ifndef NLSR_SYNC_LOGIC_HANDLER_HPP
+#define NLSR_SYNC_LOGIC_HANDLER_HPP
#include <iostream>
+#include <boost/cstdint.hpp>
#include <ndn-cxx/face.hpp>
#include <nsync/sync-socket.h>
@@ -24,7 +25,7 @@
class SyncLogicHandler
{
public:
- SyncLogicHandler(ndn::shared_ptr<boost::asio::io_service> ioService)
+ SyncLogicHandler(boost::asio::io_service& ioService)
: m_validator(new ndn::ValidatorNull())
, m_syncFace(new ndn::Face(ioService))
{}
@@ -34,26 +35,26 @@
createSyncSocket(Nlsr& pnlsr);
void
- nsyncUpdateCallBack(const vector<Sync::MissingDataInfo>& v,
+ nsyncUpdateCallBack(const std::vector<Sync::MissingDataInfo>& v,
Sync::SyncSocket* socket, Nlsr& pnlsr);
void
- nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr);
+ nsyncRemoveCallBack(const std::string& prefix, Nlsr& pnlsr);
void
- removeRouterFromSyncing(string& routerPrefix);
+ removeRouterFromSyncing(const std::string& routerPrefix);
void
- publishRoutingUpdate(SequencingManager& sm, string updatePrefix);
+ publishRoutingUpdate(SequencingManager& sm, const std::string& updatePrefix);
// void
// publishKeyUpdate(KeyManager& km);
void
- publishIdentityUpdate(string identityName);
+ publishIdentityUpdate(const std::string& identityName);
void
- setSyncPrefix(string sp)
+ setSyncPrefix(const std::string& sp)
{
m_syncPrefix.clear();
m_syncPrefix.set(sp);
@@ -61,17 +62,17 @@
private:
void
- processUpdateFromSync(std::string updateName, uint64_t seqNo, Nlsr& pnlsr);
+ processUpdateFromSync(const std::string& updateName, uint64_t seqNo, Nlsr& pnlsr);
void
- processRoutingUpdateFromSync(std::string routerName, uint64_t seqNo,
+ processRoutingUpdateFromSync(const std::string& routerName, uint64_t seqNo,
Nlsr& pnlsr);
// void
// processKeysUpdateFromSync(std::string certName, uint64_t seqNo, Nlsr& pnlsr);
void
- publishSyncUpdate(string updatePrefix, uint64_t seqNo);
+ publishSyncUpdate(const std::string& updatePrefix, uint64_t seqNo);
private:
ndn::shared_ptr<ndn::ValidatorNull> m_validator;
@@ -82,4 +83,4 @@
} //namespace nlsr
-#endif //NLSR_SLH_HPP
+#endif //NLSR_SYNC_LOGIC_HANDLER_HPP
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index c4015a3..61265b7 100644
--- a/src/conf-file-processor.hpp
+++ b/src/conf-file-processor.hpp
@@ -1,6 +1,7 @@
-#ifndef CONF_PROCESSOR_HPP
-#define CONF_PROCESSOR_HPP
+#ifndef CONF_FILE_PROCESSOR_HPP
+#define CONF_FILE_PROCESSOR_HPP
+#include <boost/cstdint.hpp>
#include "nlsr.hpp"
namespace nlsr {
@@ -8,7 +9,7 @@
class ConfFileProcessor
{
public:
- ConfFileProcessor(Nlsr& nlsr, const string& cfile)
+ ConfFileProcessor(Nlsr& nlsr, const std::string& cfile)
: m_confFileName(cfile)
, m_nlsr(nlsr)
{
@@ -18,70 +19,70 @@
private:
int
- processConfCommand(string command);
+ processConfCommand(std::string command);
int
- processConfCommandNetwork(string command);
+ processConfCommandNetwork(std::string command);
int
- processConfCommandSiteName(string command);
+ processConfCommandSiteName(std::string command);
int
- processConfCommandRootKeyPrefix(string command);
+ processConfCommandRootKeyPrefix(std::string command);
int
- processConfCommandRouterName(string command);
+ processConfCommandRouterName(std::string command);
int
- processConfCommandInterestRetryNumber(string command);
+ processConfCommandInterestRetryNumber(std::string command);
int
- processConfCommandInterestResendTime(string command);
+ processConfCommandInterestResendTime(std::string command);
int
- processConfCommandLsaRefreshTime(string command);
+ processConfCommandLsaRefreshTime(std::string command);
int
- processConfCommandMaxFacesPerPrefix(string command);
+ processConfCommandMaxFacesPerPrefix(std::string command);
int
- processConfCommandTunnelType(string command);
+ processConfCommandTunnelType(std::string command);
int
- processConfCommandChronosyncSyncPrefix(string command);
+ processConfCommandChronosyncSyncPrefix(std::string command);
int
- processConfCommandLogDir(string command);
+ processConfCommandLogDir(std::string command);
int
- processConfCommandCertDir(string command);
+ processConfCommandCertDir(std::string command);
int
- processConfCommandDebugging(string command);
+ processConfCommandDebugging(std::string command);
int
- processConfCommandDetailedLogging(string command);
+ processConfCommandDetailedLogging(std::string command);
int
- processConfCommandIsHyperbolicCalc(string command);
+ processConfCommandIsHyperbolicCalc(std::string command);
int
- processConfCommandHyperbolicCordinate(string command);
+ processConfCommandHyperbolicCordinate(std::string command);
int
- processConfCommandNdnNeighbor(string command);
+ processConfCommandNdnNeighbor(std::string command);
int
- processConfCommandNdnName(string command);
+ processConfCommandNdnName(std::string command);
int
- processConfCommandLinkCost(string command);
+ processConfCommandLinkCost(std::string command);
private:
- string m_confFileName;
+ std::string m_confFileName;
Nlsr& m_nlsr;
};
} //namespace nlsr
-#endif //CONF_PROCESSOR_HPP
+#endif //CONF_FILE_PROCESSOR_HPP
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 7dc8c76..49a8a4d 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -1,7 +1,8 @@
-#ifndef CONF_PARAM_HPP
-#define CONF_PARAM_HPP
+#ifndef CONF_PARAMETER_HPP
+#define CONF_PARAMETER_HPP
#include <iostream>
+#include <boost/cstdint.hpp>
namespace nlsr {
class ConfParameter
@@ -34,7 +35,7 @@
m_routerName = rn;
}
- std::string
+ const std::string&
getRouterName()
{
return m_routerName;
@@ -46,7 +47,7 @@
m_siteName = sn;
}
- std::string
+ const std::string&
getSiteName()
{
return m_siteName;
@@ -58,7 +59,7 @@
m_network = nn;
}
- std::string
+ const std::string&
getNetwork()
{
return m_network;
@@ -70,13 +71,13 @@
m_routerPrefix = "/" + m_network + "/" + m_siteName + "/" + m_routerName;
}
- std::string
+ const std::string&
getRouterPrefix()
{
return m_routerPrefix;
}
- std::string
+ const std::string&
getRootKeyPrefix()
{
return m_rootKeyPrefix;
@@ -89,68 +90,68 @@
}
void
- setInterestRetryNumber(int irn)
+ setInterestRetryNumber(uint32_t irn)
{
m_interestRetryNumber = irn;
}
- int
+ uint32_t
getInterestRetryNumber()
{
return m_interestRetryNumber;
}
void
- setInterestResendTime(int irt)
+ setInterestResendTime(int32_t irt)
{
m_interestResendTime = irt;
}
- int
+ int32_t
getInterestResendTime()
{
return m_interestResendTime;
}
void
- setLsaRefreshTime(int lrt)
+ setLsaRefreshTime(int32_t lrt)
{
m_lsaRefreshTime = lrt;
m_routerDeadInterval = 2 * m_lsaRefreshTime;
}
- int
+ int32_t
getLsaRefreshTime()
{
return m_lsaRefreshTime;
}
void
- setRouterDeadInterval(int rdt)
+ setRouterDeadInterval(int64_t rdt)
{
m_routerDeadInterval = rdt;
}
- long int
+ int64_t
getRouterDeadInterval()
{
return m_routerDeadInterval;
}
void
- setMaxFacesPerPrefix(int mfpp)
+ setMaxFacesPerPrefix(int32_t mfpp)
{
m_maxFacesPerPrefix = mfpp;
}
- int
+ int32_t
getMaxFacesPerPrefix()
{
return m_maxFacesPerPrefix;
}
void
- setLogDir(std::string ld)
+ setLogDir(const std::string& ld)
{
m_logDir = ld;
}
@@ -162,24 +163,24 @@
}
void
- setCertDir(std::string cd)
+ setCertDir(const std::string& cd)
{
m_certDir = cd;
}
- std::string
+ const std::string&
getCertDir()
{
return m_certDir;
}
void
- setSeqFileDir(std::string ssfd)
+ setSeqFileDir(const std::string& ssfd)
{
m_seqFileDir = ssfd;
}
- std::string
+ const std::string&
getSeqFileDir()
{
return m_seqFileDir;
@@ -198,24 +199,24 @@
}
void
- setDebugging(int d)
+ setDebugging(int32_t d)
{
m_debugging = d;
}
- int
+ int32_t
getDebugging()
{
return m_debugging;
}
void
- setIsHyperbolicCalc(int ihc)
+ setIsHyperbolicCalc(int32_t ihc)
{
m_isHyperbolicCalc = ihc;
}
- int
+ int32_t
getIsHyperbolicCalc()
{
return m_isHyperbolicCalc;
@@ -251,7 +252,7 @@
m_tunnelType = tt;
}
- int
+ int32_t
getTunnelType()
{
return m_tunnelType;
@@ -263,32 +264,32 @@
m_chronosyncSyncPrefix = csp;
}
- std::string
+ const std::string&
getChronosyncSyncPrefix()
{
return m_chronosyncSyncPrefix;
}
void
- setChronosyncLsaPrefix(std::string clp)
+ setChronosyncLsaPrefix(const std::string& clp)
{
m_chronosyncLsaPrefix = clp;
}
- std::string
+ const std::string&
getChronosyncLsaPrefix()
{
return m_chronosyncLsaPrefix;
}
- int
+ int32_t
getInfoInterestInterval()
{
return m_infoInterestInterval;
}
void
- setInfoInterestInterval(int iii)
+ setInfoInterestInterval(int32_t iii)
{
m_infoInterestInterval = iii;
}
@@ -305,21 +306,21 @@
std::string m_chronosyncLsaPrefix;
std::string m_rootKeyPrefix;
- int m_interestRetryNumber;
- int m_interestResendTime;
- int m_infoInterestInterval;
- int m_lsaRefreshTime;
- int m_routerDeadInterval;
+ uint32_t m_interestRetryNumber;
+ int32_t m_interestResendTime;
+ int32_t m_infoInterestInterval;
+ int32_t m_lsaRefreshTime;
+ int64_t m_routerDeadInterval;
- int m_maxFacesPerPrefix;
- int m_tunnelType;
- int m_detailedLogging;
+ int32_t m_maxFacesPerPrefix;
+ int32_t m_tunnelType;
+ int32_t m_detailedLogging;
std::string m_certDir;
- int m_debugging;
+ int32_t m_debugging;
std::string m_seqFileDir;
- int m_isHyperbolicCalc;
+ int32_t m_isHyperbolicCalc;
double m_corR;
double m_corTheta;
@@ -333,4 +334,4 @@
} // namespace nlsr
-#endif //CONF_PARAM_HPP
+#endif //CONF_PARAMETER_HPP
diff --git a/src/lsa.cpp b/src/lsa.cpp
index dac54a2..5f76eda 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -26,7 +26,7 @@
}
NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
- NamePrefixList npl)
+ NamePrefixList& npl)
{
m_origRouter = origR;
m_lsType = lst;
@@ -132,7 +132,7 @@
}
bool
-CoordinateLsa::isEqual(const CoordinateLsa& clsa)
+CoordinateLsa::isEqualContent(const CoordinateLsa& clsa)
{
return (std::abs(m_corRad - clsa.getCorRadius()) <
std::numeric_limits<double>::epsilon()) &&
@@ -192,7 +192,7 @@
AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
- uint32_t nl , AdjacencyList adl)
+ uint32_t nl , AdjacencyList& adl)
{
m_origRouter = origR;
m_lsType = lst;
@@ -218,9 +218,9 @@
}
bool
-AdjLsa::isEqual(AdjLsa& alsa)
+AdjLsa::isEqualContent(AdjLsa& alsa)
{
- return m_adl.isEqual(alsa.getAdl());
+ return m_adl == alsa.getAdl();
}
@@ -291,7 +291,7 @@
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().addNpteByDestName(getOrigRouter(), getOrigRouter(),
+ pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter(),
pnlsr);
}
}
@@ -302,7 +302,7 @@
{
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().removeNpte(getOrigRouter(), getOrigRouter(), pnlsr);
+ pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter(), pnlsr);
}
}
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 1db70d7..3a86c09 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -1,6 +1,7 @@
#ifndef NLSR_LSA_HPP
#define NLSR_LSA_HPP
+#include <boost/cstdint.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include "adjacent.hpp"
#include "name-prefix-list.hpp"
@@ -98,7 +99,7 @@
}
NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
- NamePrefixList npl);
+ NamePrefixList& npl);
NamePrefixList&
getNpl()
@@ -149,7 +150,7 @@
}
AdjLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
- uint32_t nl , AdjacencyList adl);
+ uint32_t nl , AdjacencyList& adl);
AdjacencyList&
getAdl()
@@ -179,7 +180,7 @@
}
bool
- isEqual(AdjLsa& alsa);
+ isEqualContent(AdjLsa& alsa);
void
addNptEntries(Nlsr& pnlsr);
@@ -250,7 +251,7 @@
}
bool
- isEqual(const CoordinateLsa& clsa);
+ isEqualContent(const CoordinateLsa& clsa);
private:
double m_corRad;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index a96cecb..7cdd4b6 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -8,7 +8,7 @@
using namespace std;
void
-Lsdb::cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, EventId eid)
+Lsdb::cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, ndn::EventId eid)
{
pnlsr.getScheduler().cancelEvent(eid);
}
@@ -23,13 +23,12 @@
bool
Lsdb::buildAndInstallOwnNameLsa(Nlsr& pnlsr)
{
- NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix()
- , 1
- , pnlsr.getSequencingManager().getNameLsaSeq() + 1
- , pnlsr.getConfParameter().getRouterDeadInterval()
- , pnlsr.getNamePrefixList());
- pnlsr.getSequencingManager().setNameLsaSeq(
- pnlsr.getSequencingManager().getNameLsaSeq() + 1);
+ NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix(),
+ 1,
+ pnlsr.getSequencingManager().getNameLsaSeq() + 1,
+ pnlsr.getConfParameter().getRouterDeadInterval(),
+ pnlsr.getNamePrefixList());
+ pnlsr.getSequencingManager().increaseNameLsaSeq();
return installNameLsa(pnlsr, nameLsa);
}
@@ -84,17 +83,15 @@
printNameLsdb();
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().addNpteByDestName(nlsa.getOrigRouter(),
- nlsa.getOrigRouter(),
- pnlsr);
+ pnlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
+ nlsa.getOrigRouter(), pnlsr);
std::list<string> nameList = nlsa.getNpl().getNameList();
for (std::list<string>::iterator it = nameList.begin(); it != nameList.end();
it++)
{
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().addNpteByDestName((*it), nlsa.getOrigRouter(),
- pnlsr);
+ pnlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter(), pnlsr);
}
}
}
@@ -130,8 +127,7 @@
{
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().addNpteByDestName((*it), nlsa.getOrigRouter(),
- pnlsr);
+ pnlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter(), pnlsr);
}
}
}
@@ -149,7 +145,7 @@
{
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().removeNpte((*it), nlsa.getOrigRouter(), pnlsr);
+ pnlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter(), pnlsr);
}
}
}
@@ -195,14 +191,14 @@
(*it).writeLog();
if ((*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().removeNpte((*it).getOrigRouter(),
- (*it).getOrigRouter(), pnlsr);
+ pnlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
+ (*it).getOrigRouter(), pnlsr);
for (std::list<string>::iterator nit = (*it).getNpl().getNameList().begin();
nit != (*it).getNpl().getNameList().end(); ++nit)
{
if ((*nit) != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().removeNpte((*nit), (*it).getOrigRouter(), pnlsr);
+ pnlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter(), pnlsr);
}
}
}
@@ -248,14 +244,13 @@
bool
Lsdb::buildAndInstallOwnCoordinateLsa(Nlsr& pnlsr)
{
- CoordinateLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
- , 3
- , pnlsr.getSequencingManager().getCorLsaSeq() + 1
- , pnlsr.getConfParameter().getRouterDeadInterval()
- , pnlsr.getConfParameter().getCorR()
- , pnlsr.getConfParameter().getCorTheta());
- pnlsr.getSequencingManager().setCorLsaSeq(
- pnlsr.getSequencingManager().getCorLsaSeq() + 1);
+ CoordinateLsa corLsa(pnlsr.getConfParameter().getRouterPrefix(),
+ 3,
+ pnlsr.getSequencingManager().getCorLsaSeq() + 1,
+ pnlsr.getConfParameter().getRouterDeadInterval(),
+ pnlsr.getConfParameter().getCorR(),
+ pnlsr.getConfParameter().getCorTheta());
+ pnlsr.getSequencingManager().increaseCorLsaSeq();
installCoordinateLsa(pnlsr, corLsa);
return true;
}
@@ -312,9 +307,8 @@
printCorLsdb(); //debugging purpose
if (clsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().addNpteByDestName(clsa.getOrigRouter(),
- clsa.getOrigRouter(),
- pnlsr);
+ pnlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
+ clsa.getOrigRouter(), pnlsr);
}
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
{
@@ -333,7 +327,7 @@
{
chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
chkCorLsa->setLifeTime(clsa.getLifeTime());
- if (!chkCorLsa->isEqual(clsa))
+ if (!chkCorLsa->isEqualContent(clsa))
{
chkCorLsa->setCorRadius(clsa.getCorRadius());
chkCorLsa->setCorTheta(clsa.getCorTheta());
@@ -382,8 +376,8 @@
{
if ((*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
- pnlsr.getNamePrefixTable().removeNpte((*it).getOrigRouter(),
- (*it).getOrigRouter(), pnlsr);
+ pnlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
+ (*it).getOrigRouter(), pnlsr);
}
m_corLsdb.erase(it);
return true;
@@ -540,10 +534,10 @@
{
chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
chkAdjLsa->setLifeTime(alsa.getLifeTime());
- if (!chkAdjLsa->isEqual(alsa))
+ if (!chkAdjLsa->isEqualContent(alsa))
{
chkAdjLsa->getAdl().reset();
- chkAdjLsa->getAdl().addAdjacentsFromAdl(alsa.getAdl());
+ chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
if (alsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
@@ -563,16 +557,15 @@
bool
Lsdb::buildAndInstallOwnAdjLsa(Nlsr& pnlsr)
{
- AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix()
- , 2
- , pnlsr.getSequencingManager().getAdjLsaSeq() + 1
- , pnlsr.getConfParameter().getRouterDeadInterval()
- , pnlsr.getAdjacencyList().getNumOfActiveNeighbor()
- , pnlsr.getAdjacencyList());
- pnlsr.getSequencingManager().setAdjLsaSeq(
- pnlsr.getSequencingManager().getAdjLsaSeq() + 1);
- string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
- + pnlsr.getConfParameter().getRouterPrefix();
+ AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix(),
+ 2,
+ pnlsr.getSequencingManager().getAdjLsaSeq() + 1,
+ pnlsr.getConfParameter().getRouterDeadInterval(),
+ pnlsr.getAdjacencyList().getNumOfActiveNeighbor(),
+ pnlsr.getAdjacencyList());
+ pnlsr.getSequencingManager().increaseAdjLsaSeq();
+ string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix() +
+ pnlsr.getConfParameter().getRouterPrefix();
pnlsr.getSyncLogicHandler().publishRoutingUpdate(pnlsr.getSequencingManager(),
lsaPrefix);
return pnlsr.getLsdb().installAdjLsa(pnlsr, adjLsa);
@@ -642,6 +635,11 @@
chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
pnlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
chkNameLsa->writeLog();
+ // schedule refreshing event again
+ chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
+ chkNameLsa->getKey(),
+ chkNameLsa->getLsSeqNo(),
+ m_lsaRefreshTime));
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
@@ -673,6 +671,11 @@
cout << "Own Adj LSA, so refreshing Adj LSA" << endl;
chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
pnlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
+ // schedule refreshing event again
+ chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
+ chkAdjLsa->getKey(),
+ chkAdjLsa->getLsSeqNo(),
+ m_lsaRefreshTime));
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
@@ -707,6 +710,11 @@
cout << "Own Cor LSA, so refreshing Cor LSA" << endl;
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
pnlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
+ // schedule refreshing event again
+ chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(pnlsr,
+ chkCorLsa->getKey(),
+ chkCorLsa->getLsSeqNo(),
+ m_lsaRefreshTime));
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 9814034..9e8c207 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -2,6 +2,8 @@
#define NLSR_LSDB_HPP
#include <utility>
+#include <boost/cstdint.hpp>
+
#include "lsa.hpp"
namespace nlsr {
diff --git a/src/main.cpp b/src/main.cpp
index b6c4b5c..d7657fa 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -17,19 +17,19 @@
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
-
+#include <boost/cstdint.hpp>
#include "nlsr.hpp"
#include "conf-file-processor.hpp"
using namespace nlsr;
-int
-main(int argc, char** argv)
+int32_t
+main(int32_t argc, char** argv)
{
nlsr::Nlsr nlsr;
- string programName(argv[0]);
+ std::string programName(argv[0]);
nlsr.setConfFileName("nlsr.conf");
- int opt;
+ int32_t opt;
while ((opt = getopt(argc, argv, "df:p:h")) != -1)
{
switch (opt)
@@ -42,7 +42,7 @@
break;
case 'p':
{
- stringstream sst(optarg);
+ std::stringstream sst(optarg);
int ap;
sst >> ap;
nlsr.setApiPort(ap);
@@ -55,7 +55,7 @@
}
}
ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
- int res = cfp.processConfFile();
+ int32_t res = cfp.processConfFile();
if (res < 0)
{
std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
@@ -63,13 +63,12 @@
return EXIT_FAILURE;
}
nlsr.initialize();
- try
- {
+ try {
nlsr.startEventLoop();
}
- catch (std::exception& e)
- {
+ catch (std::exception& e){
std::cerr << "ERROR: " << e.what() << std::endl;
+ nlsr.getFib().clean(nlsr);
}
return EXIT_SUCCESS;
}
diff --git a/src/name-prefix-list.cpp b/src/name-prefix-list.cpp
index 763fc0d..496a0e7 100644
--- a/src/name-prefix-list.cpp
+++ b/src/name-prefix-list.cpp
@@ -23,8 +23,8 @@
return s1 == s2;
}
-int
-NamePrefixList::insert(string& name)
+int32_t
+NamePrefixList::insert(const string& name)
{
std::list<string>::iterator it = std::find_if(m_nameList.begin(),
m_nameList.end(),
@@ -37,8 +37,8 @@
return 0;
}
-int
-NamePrefixList::remove(string& name)
+int32_t
+NamePrefixList::remove(const string& name)
{
std::list<string>::iterator it = std::find_if(m_nameList.begin(),
m_nameList.end(),
diff --git a/src/name-prefix-list.hpp b/src/name-prefix-list.hpp
index 9d32dde..dda4508 100644
--- a/src/name-prefix-list.hpp
+++ b/src/name-prefix-list.hpp
@@ -1,8 +1,9 @@
-#ifndef NPL_HPP
-#define NPL_HPP
+#ifndef NLSR_NAME_PREFIX_LIST_HPP
+#define NLSR_NAME_PREFIX_LIST_HPP
#include <list>
#include <string>
+#include <boost/cstdint.hpp>
namespace nlsr {
@@ -14,16 +15,16 @@
~NamePrefixList();
- int
- insert(std::string& name);
+ int32_t
+ insert(const std::string& name);
- int
- remove(std::string& name);
+ int32_t
+ remove(const std::string& name);
void
sort();
- int
+ int32_t
getSize()
{
return m_nameList.size();
@@ -45,4 +46,4 @@
}//namespace nlsr
-#endif //NPL_HPP
+#endif //NLSR_NAME_PREFIX_LIST_HPP
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index f4616ce..22e7dc8 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -14,17 +14,18 @@
void
Nlsr::registrationFailed(const ndn::Name& name)
{
- cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
- getNlsrFace()->shutdown();
+ std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
+ throw Error("Error: Prefix registration failed");
}
void
-Nlsr::setInterestFilterNlsr(const string& name)
+Nlsr::setInterestFilter(const string& name)
{
- getNlsrFace()->setInterestFilter(name,
- ndn::bind(&InterestManager::processInterest, &m_interestManager, _1, _2),
- ndn::bind(&Nlsr::registrationFailed, this, _1));
+ getNlsrFace().setInterestFilter(name,
+ ndn::bind(&InterestManager::processInterest,
+ &m_interestManager, _1, _2),
+ ndn::bind(&Nlsr::registrationFailed, this, _1));
}
void
@@ -47,10 +48,10 @@
/* debugging purpose end */
m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
- setInterestFilterNlsr(m_confParam.getRouterPrefix());
- setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() +
- m_confParam.getRouterPrefix());
- setInterestFilterNlsr(m_confParam.getRootKeyPrefix());
+ setInterestFilter(m_confParam.getRouterPrefix());
+ setInterestFilter(m_confParam.getChronosyncLsaPrefix() +
+ m_confParam.getRouterPrefix());
+ setInterestFilter(m_confParam.getRootKeyPrefix());
m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
m_syncLogicHandler.createSyncSocket(boost::ref(*this));
// m_slh.publishKeyUpdate(m_km);
@@ -60,10 +61,10 @@
void
Nlsr::startEventLoop()
{
- m_io->run();
+ m_nlsrFace.processEvents();
}
-int
+void
Nlsr::usage(const string& progname)
{
cout << "Usage: " << progname << " [OPTIONS...]" << endl;
@@ -72,7 +73,6 @@
cout << " -f, --config_file Specify configuration file name" << endl;
cout << " -p, --api_port port where api client will connect" << endl;
cout << " -h, --help Display this help message" << endl;
- exit(EXIT_FAILURE);
}
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index f6e3ba0..0e59adc 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -1,6 +1,9 @@
#ifndef NLSR_HPP
#define NLSR_HPP
+#include <boost/cstdint.hpp>
+#include <stdexcept>
+
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/scheduler.hpp>
@@ -21,20 +24,21 @@
namespace nlsr {
-inline static void
-NullDeleter(boost::asio::io_service* variable)
-{
- // do nothing
-}
-
class Nlsr
{
+ class Error : public std::runtime_error
+ {
+ public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+ };
+
public:
Nlsr()
- : m_io(new boost::asio::io_service)
- , m_nlsrFace(new Face(ndn::shared_ptr<boost::asio::io_service>(&*m_io,
- &NullDeleter)))
- , m_scheduler(*m_io)
+ : m_scheduler(m_nlsrFace.getIoService())
, m_confParam()
, m_adjacencyList()
, m_namePrefixList()
@@ -51,30 +55,30 @@
, m_isRoutingTableCalculating(false)
, m_routingTable()
, m_namePrefixTable()
- , m_fib()
- , m_syncLogicHandler(m_io)
+ , m_fib(m_nlsrFace)
+ , m_syncLogicHandler(m_nlsrFace.getIoService())
{}
void
registrationFailed(const ndn::Name& name);
void
- setInterestFilterNlsr(const string& name);
+ setInterestFilter(const std::string& name);
void
startEventLoop();
- int
- usage(const string& progname);
+ void
+ usage(const std::string& progname);
std::string
- getConfFileName()
+ getConfFileName() const
{
return m_configFileName;
}
void
- setConfFileName(const string& fileName)
+ setConfFileName(const std::string& fileName)
{
m_configFileName = fileName;
}
@@ -109,19 +113,13 @@
return m_namePrefixList;
}
- ndn::shared_ptr<boost::asio::io_service>&
- getIo()
- {
- return m_io;
- }
-
ndn::Scheduler&
getScheduler()
{
return m_scheduler;
}
- ndn::shared_ptr<ndn::Face>
+ ndn::Face&
getNlsrFace()
{
return m_nlsrFace;
@@ -189,7 +187,7 @@
}
void
- setAdjBuildCount(long int abc)
+ setAdjBuildCount(int64_t abc)
{
m_adjBuildCount = abc;
}
@@ -208,12 +206,12 @@
void
- setApiPort(int ap)
+ setApiPort(int32_t ap)
{
m_apiPort = ap;
}
- int
+ int32_t
getApiPort()
{
return m_apiPort;
@@ -253,8 +251,7 @@
initialize();
private:
- ndn::shared_ptr<boost::asio::io_service> m_io;
- ndn::shared_ptr<ndn::Face> m_nlsrFace;
+ ndn::Face m_nlsrFace;
ndn::Scheduler m_scheduler;
ConfParameter m_confParam;
AdjacencyList m_adjacencyList;
@@ -264,25 +261,17 @@
SequencingManager m_sequencingManager;
// KeyManager m_km;
bool m_isDaemonProcess;
- string m_configFileName;
-
-
+ std::string m_configFileName;
Lsdb m_nlsrLsdb;
-
-
- long int m_adjBuildCount;
+ int64_t m_adjBuildCount;
bool m_isBuildAdjLsaSheduled;
bool m_isRouteCalculationScheduled;
bool m_isRoutingTableCalculating;
-
RoutingTable m_routingTable;
NamePrefixTable m_namePrefixTable;
Fib m_fib;
SyncLogicHandler m_syncLogicHandler;
-
- int m_apiPort;
-
-
+ int32_t m_apiPort;
};
} //namespace nlsr
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index 05bee41..524b04c 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -9,17 +9,17 @@
bool
FibEntry::isEqualNextHops(NexthopList& nhlOther)
{
- if (m_nhl.getSize() != nhlOther.getSize())
+ if (m_nexthopList.getSize() != nhlOther.getSize())
{
return false;
}
else
{
- int nhCount = 0;
+ uint32_t nhCount = 0;
std::list<NextHop>::iterator it1, it2;
- for (it1 = m_nhl.getNextHopList().begin(),
- it2 = nhlOther.getNextHopList().begin() ;
- it1 != m_nhl.getNextHopList().end() ; it1++, it2++)
+ for (it1 = m_nexthopList.getNextHops().begin(),
+ it2 = nhlOther.getNextHops().begin() ;
+ it1 != m_nexthopList.getNextHops().end() ; it1++, it2++)
{
if (it1->getConnectingFace() == it2->getConnectingFace())
{
@@ -31,7 +31,7 @@
break;
}
}
- return nhCount == m_nhl.getSize();
+ return nhCount == m_nexthopList.getSize();
}
}
@@ -40,7 +40,7 @@
{
os << "Name Prefix: " << fe.getName() << endl;
os << "Time to Refresh: " << fe.getTimeToRefresh() << endl;
- os << fe.getNhl() << endl;
+ os << fe.getNexthopList() << endl;
return os;
}
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index d320c9a..88de53e 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.hpp
@@ -1,8 +1,10 @@
-#ifndef NLSR_FE_HPP
-#define NLSR_FE_HPP
+#ifndef NLSR_FIB_ENTRY_HPP
+#define NLSR_FIB_ENTRY_HPP
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
+
#include <ndn-cxx/util/scheduler.hpp>
#include "nexthop.hpp"
@@ -10,8 +12,6 @@
namespace nlsr {
-using namespace std;
-
class FibEntry
{
public:
@@ -19,38 +19,38 @@
: m_name()
, m_timeToRefresh(0)
, m_seqNo(0)
- , m_nhl()
+ , m_nexthopList()
{
}
- FibEntry(string n)
+ FibEntry(const std::string& name)
: m_timeToRefresh(0)
, m_seqNo(0)
- , m_nhl()
+ , m_nexthopList()
{
- m_name = n;
+ m_name = name;
}
- std::string
+ const std::string&
getName() const
{
return m_name;
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
- int
+ int32_t
getTimeToRefresh() const
{
return m_timeToRefresh;
}
void
- setTimeToRefresh(int ttr)
+ setTimeToRefresh(int32_t ttr)
{
m_timeToRefresh = ttr;
}
@@ -68,12 +68,12 @@
}
void
- setSeqNo(int fsn)
+ setSeqNo(int32_t fsn)
{
m_seqNo = fsn;
}
- int
+ int32_t
getSeqNo()
{
return m_seqNo;
@@ -84,10 +84,10 @@
private:
std::string m_name;
- int m_timeToRefresh;
+ int32_t m_timeToRefresh;
ndn::EventId m_expiringEventId;
- int m_seqNo;
- NexthopList m_nhl;
+ int32_t m_seqNo;
+ NexthopList m_nexthopList;
};
std::ostream&
@@ -95,4 +95,4 @@
} //namespace nlsr
-#endif //NLSR_FE_HPP
+#endif //NLSR_FIB_ENTRY_HPP
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 1d7582b..1272ab1 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -1,9 +1,10 @@
#include <list>
+#include <cmath>
#include "nlsr.hpp"
-#include "fib-entry.hpp"
-#include "fib.hpp"
#include "nexthop-list.hpp"
+#include "fib.hpp"
+
@@ -13,9 +14,9 @@
using namespace ndn;
static bool
-fibEntryNameCompare(FibEntry& fe, string name)
+fibEntryNameCompare(const FibEntry& fibEntry, const string& name)
{
- return fe.getName() == name ;
+ return fibEntry.getName() == name ;
}
void
@@ -26,32 +27,78 @@
ndn::EventId
-Fib::scheduleEntryRefreshing(Nlsr& pnlsr, string name, int feSeqNum,
- int refreshTime)
+Fib::scheduleEntryRefreshing(Nlsr& pnlsr, const string& name, int32_t feSeqNum,
+ int32_t refreshTime)
{
+ std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl;
+ std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
- ndn::bind(&Fib::refreshEntry, this, name, feSeqNum));
+ ndn::bind(&Fib::refreshEntry, this,
+ boost::ref(pnlsr),
+ name, feSeqNum));
}
void
-Fib::refreshEntry(string name, int feSeqNum)
+Fib::refreshEntry(Nlsr& nlsr, const string& name, int32_t feSeqNum)
{
+ std::cout << "Fib::refreshEntry Called" << std::endl;
+ std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
+ std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(),
+ bind(&fibEntryNameCompare, _1, name));
+ if (it != m_table.end())
+ {
+ std::cout << "Entry found with Seq Num: " << feSeqNum << std::endl;
+ if (it->getSeqNo() == feSeqNum)
+ {
+ std::cout << "Refreshing the FIB entry" << std::endl;
+ for (std::list<NextHop>::iterator nhit =
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
+ {
+ // add entry to NDN-FIB
+ registerPrefixInNfd(it->getName(), nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
+ }
+
+ // increase sequence number and schedule refresh again
+ it->setSeqNo(feSeqNum + 1);
+ it->setExpiringEventId(scheduleEntryRefreshing(nlsr,
+ it->getName() ,
+ it->getSeqNo(),
+ m_refreshTime));
+
+ }
+ }
}
void
-Fib::remove(Nlsr& pnlsr, string name)
+Fib::remove(Nlsr& pnlsr, const std::string& name)
{
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
- m_table.end(),
+ m_table.end(),
bind(&fibEntryNameCompare, _1, name));
if (it != m_table.end())
{
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
{
//remove entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
+ nhit->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ }
}
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
m_table.erase(it);
}
@@ -59,7 +106,7 @@
void
-Fib::update(Nlsr& pnlsr, string name, NexthopList& nextHopList)
+Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
{
std::cout << "Fib::updateFib Called" << std::endl;
int startFace = 0;
@@ -74,14 +121,15 @@
{
nextHopList.sort();
FibEntry newEntry(name);
- std::list<NextHop> nhl = nextHopList.getNextHopList();
+ std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
{
- newEntry.getNhl().addNextHop((*nhit));
+ newEntry.getNexthopList().addNextHop((*nhit));
//Add entry to NDN-FIB
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
}
- newEntry.getNhl().sort();
+ newEntry.getNexthopList().sort();
newEntry.setTimeToRefresh(m_refreshTime);
newEntry.setSeqNo(1);
newEntry.setExpiringEventId(scheduleEntryRefreshing(pnlsr,
@@ -97,21 +145,25 @@
nextHopList.sort();
if (!it->isEqualNextHops(nextHopList))
{
- std::list<NextHop> nhl = nextHopList.getNextHopList();
+ std::list<NextHop> nhl = nextHopList.getNextHops();
std::list<NextHop>::iterator nhit = nhl.begin();
// Add first Entry to NDN-FIB
- removeHop(pnlsr, it->getNhl(), nhit->getConnectingFace());
- it->getNhl().reset();
- it->getNhl().addNextHop((*nhit));
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
+ removeHop(pnlsr, it->getNexthopList(), nhit->getConnectingFace(), name);
+ it->getNexthopList().reset();
+ it->getNexthopList().addNextHop((*nhit));
++startFace;
++nhit;
for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++)
{
- it->getNhl().addNextHop((*nhit));
+ it->getNexthopList().addNextHop((*nhit));
//Add Entry to NDN_FIB
+ registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
}
}
it->setTimeToRefresh(m_refreshTime);
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
cancelScheduledExpiringEvent(pnlsr, it->getExpiringEventId());
it->setSeqNo(it->getSeqNo() + 1);
(*it).setExpiringEventId(scheduleEntryRefreshing(pnlsr,
@@ -133,12 +185,26 @@
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
++it)
{
+ std::cout << "Cancellling Scheduled event" << std::endl;
+ std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() << std::endl;
+ cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
{
- cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
//Remove entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
+ nhit->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
+ }
+ }
}
}
if (m_table.size() > 0)
@@ -148,7 +214,7 @@
}
int
-Fib::getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix)
+Fib::getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix)
{
int endFace = 0;
if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix))
@@ -163,19 +229,79 @@
}
void
-Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, int doNotRemoveHopFaceId)
+Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+ const std::string& name)
{
- for (std::list<NextHop>::iterator it = nl.getNextHopList().begin();
- it != nl.getNextHopList().end(); ++it)
+ for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
+ it != nl.getNextHops().end(); ++it)
{
if (it->getConnectingFace() != doNotRemoveHopFaceId)
{
//Remove FIB Entry from NDN-FIB
+ if (!pnlsr.getAdjacencyList().isNeighbor(name))
+ {
+ unregisterPrefixFromNfd(name, it->getConnectingFace());
+ }
+ else
+ {
+ if(pnlsr.getAdjacencyList().getAdjacent(name).getConnectingFace() !=
+ it->getConnectingFace())
+ {
+ unregisterPrefixFromNfd(name, it->getConnectingFace());
+ }
+ }
}
}
}
void
+Fib::registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost)
+{
+ ndn::nfd::ControlParameters controlParameters;
+ controlParameters
+ .setName(namePrefix)
+ .setCost(faceCost)
+ .setFaceId(faceId)
+ .setExpirationPeriod(ndn::time::milliseconds(m_refreshTime*1000))
+ .setOrigin(128);
+
+ m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
+ ndn::bind(&Fib::onSuccess, this, _1,
+ "Successful in name registration"),
+ ndn::bind(&Fib::onFailure, this, _1, _2,
+ "Failed in name registration"));
+}
+
+void
+Fib::unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId)
+{
+ ndn::nfd::ControlParameters controlParameters;
+ controlParameters
+ .setName(namePrefix)
+ .setFaceId(faceId)
+ .setOrigin(128);
+
+ m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
+ ndn::bind(&Fib::onSuccess, this, _1,
+ "Successful in unregistering name"),
+ ndn::bind(&Fib::onFailure, this, _1, _2,
+ "Failed in unregistering name"));
+}
+
+void
+Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message)
+{
+ std::cout << message << ": " << commandSuccessResult << std::endl;
+}
+
+void
+Fib::onFailure(uint32_t code, const std::string& error, const std::string& message)
+{
+ std::cout << message << ": " << error << " (code: " << code << ")";
+}
+
+
+void
Fib::print()
{
cout << "-------------------FIB-----------------------------" << endl;
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 4a80c48..2a90fc1 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -2,35 +2,41 @@
#define NLSR_FIB_HPP
#include <list>
+#include <boost/cstdint.hpp>
+
+#include <ndn-cxx/management/nfd-controller.hpp>
+
#include "fib-entry.hpp"
namespace nlsr {
class Nlsr;
-using namespace std;
-using namespace ndn;
class Fib
{
public:
- Fib()
+ Fib(ndn::Face& face)
: m_table()
, m_refreshTime(0)
+ , m_controller(face)
+ {
+ }
+ ~Fib()
{
}
void
- remove(Nlsr& pnlsr, string name);
+ remove(Nlsr& pnlsr, const std::string& name);
void
- update(Nlsr& pnlsr, string name, NexthopList& nextHopList);
+ update(Nlsr& pnlsr, const std::string& name, NexthopList& nextHopList);
void
clean(Nlsr& pnlsr);
void
- setEntryRefreshTime(int fert)
+ setEntryRefreshTime(int32_t fert)
{
m_refreshTime = fert;
}
@@ -40,23 +46,38 @@
private:
void
- removeHop(Nlsr& pnlsr, NexthopList& nl, int doNotRemoveHopFaceId);
+ removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
+ const std::string& name);
int
- getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix);
+ getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
ndn::EventId
- scheduleEntryRefreshing(Nlsr& pnlsr, string name, int feSeqNum,
- int refreshTime);
- void
- cancelScheduledExpiringEvent(Nlsr& pnlsr, EventId eid);
+ scheduleEntryRefreshing(Nlsr& pnlsr, const std::string& name, int32_t feSeqNum,
+ int32_t refreshTime);
void
- refreshEntry(string name, int feSeqNum);
+ cancelScheduledExpiringEvent(Nlsr& pnlsr, ndn::EventId eid);
+
+ void
+ refreshEntry(Nlsr& nlsr, const std::string& name, int32_t feSeqNum);
+
+ void
+ registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost);
+
+ void
+ unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId);
+
+ void
+ onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message);
+
+ void
+ onFailure(uint32_t code, const std::string& error, const std::string& message);
private:
std::list<FibEntry> m_table;
- int m_refreshTime;
+ int32_t m_refreshTime;
+ ndn::nfd::Controller m_controller;
};
}//namespace nlsr
diff --git a/src/route/map-entry.hpp b/src/route/map-entry.hpp
new file mode 100644
index 0000000..9174345
--- /dev/null
+++ b/src/route/map-entry.hpp
@@ -0,0 +1,54 @@
+#ifndef NLSR_MAP_ENTRY_HPP
+#define NLSR_MAP_ENTRY_HPP
+
+#include <boost/cstdint.hpp>
+
+namespace nlsr{
+
+class MapEntry
+{
+public:
+ MapEntry()
+ : m_router()
+ , m_mappingNumber(-1)
+ {
+ }
+
+ ~MapEntry()
+ {
+ }
+
+ MapEntry(const std::string& rtr, int32_t mn)
+ {
+ m_router = rtr;
+ m_mappingNumber = mn;
+ }
+
+ const std::string&
+ getRouter() const
+ {
+ return m_router;
+ }
+
+ int32_t
+ getMappingNumber() const
+ {
+ return m_mappingNumber;
+ }
+
+private:
+ std::string m_router;
+ int32_t m_mappingNumber;
+};
+
+inline std::ostream&
+operator<<(std::ostream& os, const MapEntry& mpe)
+{
+ os << "MapEntry: ( Router: " << mpe.getRouter() << " Mapping No: ";
+ os << mpe.getMappingNumber() << " )" << std::endl;
+ return os;
+}
+
+} // namespace nlsr
+
+#endif // NLSR_MAP_ENTRY_HPP
diff --git a/src/route/map.cpp b/src/route/map.cpp
index e7ab979..4701a05 100644
--- a/src/route/map.cpp
+++ b/src/route/map.cpp
@@ -11,38 +11,30 @@
using namespace std;
-ostream&
-operator<< (ostream& os, MapEntry& mpe)
-{
- os << "MapEntry: ( Router: " << mpe.getRouter() << " Mapping No: ";
- os << mpe.getMappingNumber() << " )" << endl;
- return os;
-}
-
static bool
-mapEntryCompareByRouter(MapEntry& mpe1, string& rtrName)
+mapEntryCompareByRouter(MapEntry& mpe1, const string& rtrName)
{
return mpe1.getRouter() == rtrName;
}
static bool
-mapEntryCompareByMappingNo(MapEntry& mpe1, int mappingNo)
+mapEntryCompareByMappingNo(MapEntry& mpe1, int32_t mappingNo)
{
return mpe1.getMappingNumber() == mappingNo;
}
void
-Map::addElement(string& rtrName)
+Map::addEntry(const string& rtrName)
{
MapEntry me(rtrName, m_mappingIndex);
- if (addElement(me))
+ if (addEntry(me))
{
m_mappingIndex++;
}
}
bool
-Map::addElement(MapEntry& mpe)
+Map::addEntry(MapEntry& mpe)
{
//cout << mpe;
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
@@ -57,7 +49,7 @@
}
string
-Map::getRouterNameByMappingNo(int mn)
+Map::getRouterNameByMappingNo(int32_t mn)
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
@@ -70,7 +62,7 @@
return "";
}
-int
+int32_t
Map::getMappingNoByRouterName(string& rName)
{
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
@@ -92,13 +84,13 @@
it != adjLsdb.end() ; it++)
{
string linkStartRouter = (*it).getOrigRouter();
- addElement(linkStartRouter);
+ addEntry(linkStartRouter);
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
for (std::list<Adjacent>::iterator itAdl = adl.begin();
itAdl != adl.end() ; itAdl++)
{
string linkEndRouter = (*itAdl).getName();
- addElement(linkEndRouter);
+ addEntry(linkEndRouter);
}
}
}
diff --git a/src/route/map.hpp b/src/route/map.hpp
index bdacd4d..cc08771 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -3,52 +3,16 @@
#include <iostream>
#include <list>
+#include <boost/cstdint.hpp>
-#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/common.hpp>
+
+#include "map-entry.hpp"
namespace nlsr {
class Nlsr;
-class MapEntry
-{
-public:
- MapEntry()
- : m_router()
- , m_mappingNumber(-1)
- {
- }
-
- ~MapEntry()
- {
- }
-
- MapEntry(std::string rtr, int mn)
- {
- m_router = rtr;
- m_mappingNumber = mn;
- }
-
- std::string
- getRouter() const
- {
- return m_router;
- }
-
- int
- getMappingNumber() const
- {
- return m_mappingNumber;
- }
-
-private:
- std::string m_router;
- int m_mappingNumber;
-};
-
-std::ostream&
-operator<<(std::ostream& os, MapEntry& mpe);
-
class Map
{
public:
@@ -59,15 +23,15 @@
void
- addElement(std::string& rtrName);
+ addEntry(const std::string& rtrName);
void
createFromAdjLsdb(Nlsr& pnlsr);
std::string
- getRouterNameByMappingNo(int mn);
+ getRouterNameByMappingNo(int32_t mn);
- int
+ int32_t
getMappingNoByRouterName(std::string& rName);
void
@@ -88,9 +52,9 @@
private:
bool
- addElement(MapEntry& mpe);
+ addEntry(MapEntry& mpe);
- int m_mappingIndex;
+ int32_t m_mappingIndex;
std::list<MapEntry> m_table;
};
diff --git a/src/route/name-prefix-table-entry.cpp b/src/route/name-prefix-table-entry.cpp
index 4389373..01eea0d 100644
--- a/src/route/name-prefix-table-entry.cpp
+++ b/src/route/name-prefix-table-entry.cpp
@@ -11,15 +11,15 @@
void
NamePrefixTableEntry::generateNhlfromRteList()
{
- m_nhl.reset();
+ m_nexthopList.reset();
for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
it != m_rteList.end(); ++it)
{
for (std::list<NextHop>::iterator nhit =
- (*it).getNhl().getNextHopList().begin();
- nhit != (*it).getNhl().getNextHopList().end(); ++nhit)
+ (*it).getNexthopList().getNextHops().begin();
+ nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
{
- m_nhl.addNextHop((*nhit));
+ m_nexthopList.addNextHop((*nhit));
}
}
}
@@ -56,11 +56,11 @@
}
else
{
- (*it).getNhl().reset(); // reseting existing routing table's next hop
- for (std::list<NextHop>::iterator nhit = rte.getNhl().getNextHopList().begin();
- nhit != rte.getNhl().getNextHopList().end(); ++nhit)
+ (*it).getNexthopList().reset(); // reseting existing routing table's next hop
+ for (std::list<NextHop>::iterator nhit = rte.getNexthopList().getNextHops().begin();
+ nhit != rte.getNexthopList().getNextHops().end(); ++nhit)
{
- (*it).getNhl().addNextHop((*nhit));
+ (*it).getNexthopList().addNextHop((*nhit));
}
}
}
@@ -76,7 +76,7 @@
{
cout << (*it);
}
- os << npte.getNhl();
+ os << npte.getNexthopList();
return os;
}
diff --git a/src/route/name-prefix-table-entry.hpp b/src/route/name-prefix-table-entry.hpp
index 7f4f83a..0ee28fa 100644
--- a/src/route/name-prefix-table-entry.hpp
+++ b/src/route/name-prefix-table-entry.hpp
@@ -1,31 +1,29 @@
-#ifndef NLSR_NPTE_HPP
-#define NLSR_NPTE_HPP
+#ifndef NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
+#define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
#include <list>
#include <utility>
+#include <boost/cstdint.hpp>
+
#include "routing-table-entry.hpp"
namespace nlsr {
-using namespace std;
-
class NamePrefixTableEntry
{
public:
NamePrefixTableEntry()
- : m_namePrefix()
- , m_nhl()
{
}
- NamePrefixTableEntry(string np)
- : m_nhl()
+ NamePrefixTableEntry(const std::string& namePrefix)
+ : m_nexthopList()
{
- m_namePrefix = np;
+ m_namePrefix = namePrefix;
}
- std::string
- getNamePrefix()
+ const std::string&
+ getNamePrefix() const
{
return m_namePrefix;
}
@@ -44,21 +42,21 @@
for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
it != m_rteList.end(); ++it)
{
- (*it).getNhl().reset();
+ (*it).getNexthopList().reset();
}
}
}
- int
+ size_t
getRteListSize()
{
return m_rteList.size();
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
void
@@ -73,7 +71,7 @@
private:
std::string m_namePrefix;
std::list<RoutingTableEntry> m_rteList;
- NexthopList m_nhl;
+ NexthopList m_nexthopList;
};
std::ostream&
@@ -81,4 +79,4 @@
}//namespace nlsr
-#endif //NLSR_NPTE_HPP
+#endif //NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index e37751b..e6a7ccf 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.cpp
@@ -13,7 +13,7 @@
using namespace std;
static bool
-npteCompare(NamePrefixTableEntry& npte, string& name)
+npteCompare(NamePrefixTableEntry& npte, const string& name)
{
return npte.getNamePrefix() == name;
}
@@ -21,46 +21,46 @@
void
-NamePrefixTable::addNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
{
- std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_npteList.begin(),
- m_npteList.end(), bind(&npteCompare, _1, name));
- if (it == m_npteList.end())
+ std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(), bind(&npteCompare, _1, name));
+ if (it == m_table.end())
{
NamePrefixTableEntry newEntry(name);
newEntry.addRoutingTableEntry(rte);
newEntry.generateNhlfromRteList();
- newEntry.getNhl().sort();
- m_npteList.push_back(newEntry);
- if (rte.getNhl().getSize() > 0)
+ newEntry.getNexthopList().sort();
+ m_table.push_back(newEntry);
+ if (rte.getNexthopList().getSize() > 0)
{
- pnlsr.getFib().update(pnlsr, name, newEntry.getNhl());
+ pnlsr.getFib().update(pnlsr, name, newEntry.getNexthopList());
}
}
else
{
- if (rte.getNhl().getSize() > 0)
+ if (rte.getNexthopList().getSize() > 0)
{
(*it).addRoutingTableEntry(rte);
(*it).generateNhlfromRteList();
- (*it).getNhl().sort();
- pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ (*it).getNexthopList().sort();
+ pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
}
else
{
(*it).resetRteListNextHop();
- (*it).getNhl().reset();
+ (*it).getNexthopList().reset();
pnlsr.getFib().remove(pnlsr, name);
}
}
}
void
-NamePrefixTable::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+NamePrefixTable::removeEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
{
- std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_npteList.begin(),
- m_npteList.end(), bind(&npteCompare, _1, name));
- if (it != m_npteList.end())
+ std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
+ m_table.end(), bind(&npteCompare, _1, name));
+ if (it != m_table.end())
{
string destRouter = rte.getDestination();
(*it).removeRoutingTableEntry(rte);
@@ -69,56 +69,55 @@
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/2", 2)) &&
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/3", 3)))
{
- m_npteList.erase(it);
+ m_table.erase(it);
pnlsr.getFib().remove(pnlsr, name);
}
else
{
(*it).generateNhlfromRteList();
- pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
}
}
}
void
-NamePrefixTable::addNpteByDestName(string name, string destRouter, Nlsr& pnlsr)
+NamePrefixTable::addEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
{
RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0)
{
- addNpte(name, *(rteCheck) , pnlsr);
+ addEntry(name, *(rteCheck) , pnlsr);
}
else
{
RoutingTableEntry rte(destRouter);
- addNpte(name, rte, pnlsr);
+ addEntry(name, rte, pnlsr);
}
}
void
-NamePrefixTable::removeNpte(string name, string destRouter, Nlsr& pnlsr)
+NamePrefixTable::removeEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
{
RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
if (rteCheck != 0)
{
- removeNpte(name, *(rteCheck), pnlsr);
+ removeEntry(name, *(rteCheck), pnlsr);
}
else
{
RoutingTableEntry rte(destRouter);
- removeNpte(name, rte, pnlsr);
+ removeEntry(name, rte, pnlsr);
}
}
void
NamePrefixTable::updateWithNewRoute(Nlsr& pnlsr)
{
- for (std::list<NamePrefixTableEntry>::iterator it = m_npteList.begin();
- it != m_npteList.end();
- ++it)
+ for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
+ it != m_table.end(); ++it)
{
std::list<RoutingTableEntry> rteList = (*it).getRteList();
for (std::list<RoutingTableEntry>::iterator rteit = rteList.begin();
@@ -128,12 +127,12 @@
pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
if (rteCheck != 0)
{
- addNpte((*it).getNamePrefix(), *(rteCheck), pnlsr);
+ addEntry((*it).getNamePrefix(), *(rteCheck), pnlsr);
}
else
{
RoutingTableEntry rte((*rteit).getDestination());
- addNpte((*it).getNamePrefix(), rte, pnlsr);
+ addEntry((*it).getNamePrefix(), rte, pnlsr);
}
}
}
@@ -143,8 +142,8 @@
NamePrefixTable::print()
{
std::cout << "----------------NPT----------------------" << std::endl;
- for (std::list<NamePrefixTableEntry>::iterator it = m_npteList.begin();
- it != m_npteList.end();
+ for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
+ it != m_table.end();
++it)
{
cout << (*it) << endl;
diff --git a/src/route/name-prefix-table.hpp b/src/route/name-prefix-table.hpp
index 1a59af2..4f7fbb4 100644
--- a/src/route/name-prefix-table.hpp
+++ b/src/route/name-prefix-table.hpp
@@ -1,7 +1,9 @@
-#ifndef NLSR_NPT_HPP
-#define NLSR_NPT_HPP
+#ifndef NLSR_NAME_PREFIX_TABLE_HPP
+#define NLSR_NAME_PREFIX_TABLE_HPP
#include <list>
+#include <boost/cstdint.hpp>
+
#include "name-prefix-table-entry.hpp"
#include "routing-table-entry.hpp"
@@ -14,11 +16,12 @@
NamePrefixTable()
{
}
- void
- addNpteByDestName(std::string name, std::string destRouter, Nlsr& pnlsr);
void
- removeNpte(std::string name, std::string destRouter, Nlsr& pnlsr);
+ addEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
+
+ void
+ removeEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
void
updateWithNewRoute(Nlsr& pnlsr);
@@ -28,15 +31,15 @@
private:
void
- addNpte(std::string name, RoutingTableEntry& rte, Nlsr& pnlsr);
+ addEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
void
- removeNpte(std::string name, RoutingTableEntry& rte, Nlsr& pnlsr);
+ removeEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
private:
- std::list<NamePrefixTableEntry> m_npteList;
+ std::list<NamePrefixTableEntry> m_table;
};
}//namespace nlsr
-#endif //NLSR_NPT_HPP
+#endif //NLSR_NAME_PREFIX_TABLE_HPP
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 7edb96e..5468b40 100644
--- a/src/route/nexthop-list.cpp
+++ b/src/route/nexthop-list.cpp
@@ -75,7 +75,7 @@
ostream&
operator<<(ostream& os, NexthopList& nhl)
{
- std::list<NextHop> nexthopList = nhl.getNextHopList();
+ std::list<NextHop> nexthopList = nhl.getNextHops();
int i = 1;
for (std::list<NextHop>::iterator it = nexthopList.begin();
it != nexthopList.end() ; it++, i++)
diff --git a/src/route/nexthop-list.hpp b/src/route/nexthop-list.hpp
index a8ebe7b..2607218 100644
--- a/src/route/nexthop-list.hpp
+++ b/src/route/nexthop-list.hpp
@@ -1,9 +1,11 @@
-#ifndef NLSR_NHL_HPP
-#define NLSR_NHL_HPP
+#ifndef NLSR_NEXTHOP_LIST_HPP
+#define NLSR_NEXTHOP_LIST_HPP
-#include <ndn-cxx/face.hpp>
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
+
+#include <ndn-cxx/face.hpp>
#include "nexthop.hpp"
#include "adjacent.hpp"
@@ -14,13 +16,13 @@
{
public:
NexthopList()
- : m_nexthopList()
{
}
~NexthopList()
{
}
+
void
addNextHop(NextHop& nh);
@@ -30,7 +32,7 @@
void
sort();
- int
+ size_t
getSize()
{
return m_nexthopList.size();
@@ -39,14 +41,11 @@
void
reset()
{
- if (m_nexthopList.size() > 0)
- {
- m_nexthopList.clear();
- }
+ m_nexthopList.clear();
}
std::list<NextHop>&
- getNextHopList()
+ getNextHops()
{
return m_nexthopList;
}
@@ -60,4 +59,4 @@
}//namespace nlsr
-#endif //NLSR_NLH_HPP
+#endif //NLSR_NEXTHOP_LIST_HPP
diff --git a/src/route/nexthop.hpp b/src/route/nexthop.hpp
index 7153e0f..ed8d319 100644
--- a/src/route/nexthop.hpp
+++ b/src/route/nexthop.hpp
@@ -2,6 +2,7 @@
#define NLSR_NEXTHOP_HPP
#include <iostream>
+#include <boost/cstdint.hpp>
namespace nlsr {
class NextHop
@@ -13,20 +14,20 @@
{
}
- NextHop(int cf, double rc)
+ NextHop(uint32_t cf, double rc)
{
m_connectingFace = cf;
m_routeCost = rc;
}
- int
+ uint32_t
getConnectingFace() const
{
return m_connectingFace;
}
void
- setConnectingFace(int cf)
+ setConnectingFace(uint32_t cf)
{
m_connectingFace = cf;
}
@@ -44,7 +45,7 @@
}
private:
- int m_connectingFace;
+ uint32_t m_connectingFace;
double m_routeCost;
};
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index b248b15..544896c 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -1,8 +1,9 @@
-#ifndef NLSR_RTC_HPP
-#define NLSR_RTC_HPP
+#ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
+#define NLSR_ROUTING_TABLE_CALCULATOR_HPP
#include <list>
#include <iostream>
+#include <boost/cstdint.hpp>
namespace nlsr {
@@ -198,4 +199,4 @@
}//namespace nlsr
-#endif //NLSR_RTC_HPP
+#endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP
diff --git a/src/route/routing-table-entry.cpp b/src/route/routing-table-entry.cpp
deleted file mode 100644
index 5222cb9..0000000
--- a/src/route/routing-table-entry.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <iostream>
-#include <string>
-
-#include "routing-table-entry.hpp"
-
-namespace nlsr {
-
-using namespace std;
-
-ostream&
-operator<<(ostream& os, RoutingTableEntry& rte)
-{
- os << "Destination: " << rte.getDestination() << endl;
- os << "Nexthops: " << endl;
- int i = 1;
- std::list<NextHop> nhl = rte.getNhl().getNextHopList();
- for (std::list<NextHop>::iterator it = nhl.begin();
- it != nhl.end() ; it++, i++)
- {
- os << " Nexthop " << i << ": " << (*it) << endl;
- }
- return os;
-}
-
-}//namespace nlsr
diff --git a/src/route/routing-table-entry.hpp b/src/route/routing-table-entry.hpp
index 8877275..0d0b662 100644
--- a/src/route/routing-table-entry.hpp
+++ b/src/route/routing-table-entry.hpp
@@ -1,5 +1,5 @@
-#ifndef NLSR_RTE_HPP
-#define NLSR_RTE_HPP
+#ifndef NLSR_ROUTING_TABLE_ENTRY_HPP
+#define NLSR_ROUTING_TABLE_ENTRY_HPP
#include <iostream>
@@ -11,8 +11,6 @@
{
public:
RoutingTableEntry()
- : m_destination()
- , m_nhl()
{
}
@@ -20,8 +18,7 @@
{
}
- RoutingTableEntry(std::string dest)
- : m_nhl()
+ RoutingTableEntry(const std::string& dest)
{
m_destination = dest;
}
@@ -33,19 +30,31 @@
}
NexthopList&
- getNhl()
+ getNexthopList()
{
- return m_nhl;
+ return m_nexthopList;
}
private:
std::string m_destination;
- NexthopList m_nhl;
+ NexthopList m_nexthopList;
};
-std::ostream&
-operator<<(std::ostream& os, RoutingTableEntry& rte);
+inline std::ostream&
+operator<<(std::ostream& os, RoutingTableEntry& rte)
+{
+ os << "Destination: " << rte.getDestination() << std::endl;
+ os << "Nexthops: " << std::endl;
+ int32_t i = 1;
+ std::list<NextHop> nhl = rte.getNexthopList().getNextHops();
+ for (std::list<NextHop>::iterator it = nhl.begin();
+ it != nhl.end() ; it++, i++)
+ {
+ os << " Nexthop " << i << ": " << (*it) << std::endl;
+ }
+ return os;
+}
} //namespace nlsr
-#endif //NLSR_RTE_HPP
+#endif //NLSR_ROUTING_TABLE_ENTRY_HPP
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 2bc827c..bb7d3fa 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -144,12 +144,12 @@
if (rteChk == 0)
{
RoutingTableEntry rte(destRouter);
- rte.getNhl().addNextHop(nh);
+ rte.getNexthopList().addNextHop(nh);
m_rTable.push_back(rte);
}
else
{
- rteChk->getNhl().addNextHop(nh);
+ rteChk->getNexthopList().addNextHop(nh);
}
}
@@ -188,12 +188,12 @@
if (it == m_dryTable.end())
{
RoutingTableEntry rte(destRouter);
- rte.getNhl().addNextHop(nh);
+ rte.getNexthopList().addNextHop(nh);
m_dryTable.push_back(rte);
}
else
{
- (*it).getNhl().addNextHop(nh);
+ (*it).getNexthopList().addNextHop(nh);
}
}
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index 8518b12..35f563e 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -1,9 +1,10 @@
-#ifndef NLSR_RT_HPP
-#define NLSR_RT_HPP
+#ifndef NLSR_ROUTING_TABLE_HPP
+#define NLSR_ROUTING_TABLE_HPP
#include <iostream>
#include <utility>
#include <string>
+#include <boost/cstdint.hpp>
#include "routing-table-entry.hpp"
@@ -70,4 +71,4 @@
}//namespace nlsr
-#endif //NLSR_RT_HPP
+#endif //NLSR_ROUTING_TABLE_HPP
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index e933567..8bc009a 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -1,8 +1,10 @@
-#ifndef NLSR_SM_HPP
-#define NLSR_SM_HPP
+#ifndef NLSR_SEQUENCING_MANAGER_HPP
+#define NLSR_SEQUENCING_MANAGER_HPP
#include <list>
#include <string>
+#include <boost/cstdint.hpp>
+
#include <ndn-cxx/face.hpp>
namespace nlsr {
@@ -70,6 +72,27 @@
combineSequenceNo();
}
+ void
+ increaseNameLsaSeq()
+ {
+ m_nameLsaSeq++;
+ combineSequenceNo();
+ }
+
+ void
+ increaseAdjLsaSeq()
+ {
+ m_adjLsaSeq++;
+ combineSequenceNo();
+ }
+
+ void
+ increaseCorLsaSeq()
+ {
+ m_corLsaSeq++;
+ combineSequenceNo();
+ }
+
uint64_t
getCombinedSeqNo() const
{
@@ -95,7 +118,6 @@
void
combineSequenceNo();
-
private:
uint64_t m_nameLsaSeq;
uint64_t m_adjLsaSeq;
@@ -109,4 +131,4 @@
operator<<(std::ostream& os, const SequencingManager& sm);
}//namespace nlsr
-#endif //NLSR_SM_HPP
+#endif //NLSR_SEQUENCING_MANAGER_HPP
diff --git a/src/utility/boost-log.hpp b/src/utility/boost-log.hpp
deleted file mode 100644
index 53743ae..0000000
--- a/src/utility/boost-log.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014 University of Memphis,
- * Regents of the University of California
- *
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NLSR_UTIL_BOOST_LOG_HPP
-#define NLSR_UTIL_BOOST_LOG_HPP
-
-// suppress boost::log warnings
-#pragma GCC system_header
-#pragma clang system_header
-
-#include <boost/log/common.hpp>
-#include <boost/log/expressions.hpp>
-#include <boost/log/attributes.hpp>
-#include <boost/log/sources/logger.hpp>
-#include <boost/log/sinks/sync_frontend.hpp>
-#include <boost/log/sinks/text_file_backend.hpp>
-
-#endif // NLSR_UTIL_BOOST_LOG_HPP
diff --git a/src/utility/logger.cpp b/src/utility/logger.cpp
deleted file mode 100644
index 3d9a804..0000000
--- a/src/utility/logger.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "logger.hpp"
-
-namespace nlsr {
-
-string
-Logger::getEpochTime()
-{
- std::stringstream ss;
- boost::posix_time::ptime time_t_epoch(boost::gregorian::date(1970, 1, 1));
- boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
- boost::posix_time::time_duration diff = now - time_t_epoch;
- ss << diff.total_seconds() << "." << boost::format("%06i") %
- (diff.total_microseconds()
- % 1000000);
- return ss.str();
-}
-
-string
-Logger::getUserHomeDirectory()
-{
- string homeDirPath(getpwuid(getuid())->pw_dir);
- if (homeDirPath.empty())
- {
- homeDirPath = getenv("HOME");
- }
- return homeDirPath;
-}
-
-void
-Logger::initialize(std::string dirPath)
-{
- string logDirPath(dirPath);
- if (dirPath.empty())
- {
- logDirPath = getUserHomeDirectory() + "/nlsrLog";
- }
- cout << "Log Dir Path: " << logDirPath << endl;
- typedef sinks::synchronous_sink<sinks::text_file_backend> file_sink;
- shared_ptr<file_sink> sink(new file_sink(
- keywords::file_name = logDirPath
- + "/NLSR%Y%m%d%H%M%S_%3N.log",
- keywords::rotation_size = 16 * 1024 * 1024,
- keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0),
- keywords::auto_flush = true
- ));
- sink->locked_backend()->set_file_collector(sinks::file::make_collector(
- keywords::target = logDirPath,
- //keywords::max_size = 512 * 1024 * 1024,
- keywords::min_free_space = 64 * 1024 * 1024
- ));
- sink->set_formatter(
- expr::format("%1% %2%")
- % getEpochTime()
- % expr::smessage
- );
- logging::core::get()->add_sink(sink);
-}
-
-}//namespace nlsr
diff --git a/src/utility/logger.hpp b/src/utility/logger.hpp
deleted file mode 100644
index 97b8df4..0000000
--- a/src/utility/logger.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef NLSR_LOGGER_HPP
-#define NLSR_LOGGER_HPP
-
-#define BOOST_LOG_DYN_LINK 1
-#include "boost-log.hpp"
-
-#include <stdexcept>
-#include <string>
-#include <iostream>
-#include <sstream>
-#include <pwd.h>
-#include <cstdlib>
-#include <string>
-#include <unistd.h>
-#include <boost/format.hpp>
-#include <boost/smart_ptr/shared_ptr.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/date_time/local_time/local_time.hpp>
-
-
-
-
-namespace nlsr {
-
-namespace logging = boost::log;
-namespace attrs = boost::log::attributes;
-namespace src = boost::log::sources;
-namespace sinks = boost::log::sinks;
-namespace expr = boost::log::expressions;
-namespace keywords = boost::log::keywords;
-
-using boost::shared_ptr;
-using namespace std;
-
-
-class Logger
-{
-public:
- Logger()
- {
- }
-
- void
- initialize(std::string dirPath);
-
- src::logger&
- getLogger()
- {
- return m_Logger;
- }
-
-private:
- string
- getEpochTime();
-
- string
- getUserHomeDirectory();
-
-private:
- src::logger m_Logger;
-};
-
-}//namespace nlsr
-#endif //NLSR_LOGGER_HPP
diff --git a/src/utility/tokenizer.cpp b/src/utility/tokenizer.cpp
index 52473b2..095e55d 100644
--- a/src/utility/tokenizer.cpp
+++ b/src/utility/tokenizer.cpp
@@ -42,8 +42,8 @@
uint32_t
Tokenizer::getTokenPosition(string& token)
{
- int pos = -1;
- int i = 0;
+ uint32_t pos = -1;
+ uint32_t i = 0;
for (std::list<string>::iterator it = m_tokenList.begin();
it != m_tokenList.end(); it++)
{
@@ -67,7 +67,7 @@
if ((to < m_tokenList.size()) &&
(to >= from && to < m_tokenList.size()))
{
- for (int i = from; i <= to; i++)
+ for (uint32_t i = from; i <= to; i++)
{
returnString += m_seps;
returnString += m_vTokenList[i];
diff --git a/tests/test-adjacency-list.cpp b/tests/test-adjacency-list.cpp
index 757c145..f4c0f27 100644
--- a/tests/test-adjacency-list.cpp
+++ b/tests/test-adjacency-list.cpp
@@ -33,17 +33,17 @@
adjacentList1.insert(adjacent1);
adjacentList2.insert(adjacent2);
- BOOST_CHECK_EQUAL(adjacentList1.getSize(), 1);
- BOOST_CHECK_EQUAL(adjacentList1.isEqual(adjacentList2), false);
+ BOOST_CHECK_EQUAL(adjacentList1.getSize(), (uint32_t)1);
+ BOOST_CHECK_EQUAL(adjacentList1 == adjacentList2, false);
BOOST_CHECK(adjacentList1.isNeighbor("testname"));
BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false);
string n1 = "testname";
- BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), 0);
+ BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), (uint32_t)0);
adjacentList1.setStatusOfNeighbor(n1, 1);
- BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), 1);
+ BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), (uint32_t)1);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-adjacent.cpp b/tests/test-adjacent.cpp
index 90be869..e10e30b 100644
--- a/tests/test-adjacent.cpp
+++ b/tests/test-adjacent.cpp
@@ -21,7 +21,7 @@
Adjacent adjacent1(ADJ_NAME_1);
Adjacent adjacent2(ADJ_NAME_2);
- BOOST_CHECK(adjacent1.isEqual(adjacent2));
+ BOOST_CHECK(adjacent1 == adjacent2);
adjacent1.setLinkCost(10.5);
BOOST_CHECK_CLOSE(adjacent1.getLinkCost(), 10.5, 0.0001);
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 7b87fac..8ec3a4e 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -29,12 +29,12 @@
"ndnname /ndn/memphis.edu/cs/macbook/name2\n\n\n"
;
- ofstream config;
+ std::ofstream config;
config.open("unit-test-nlsr.conf");
config << CONFIG;
config.close();
- const string CONFIG_FILE = "unit-test-nlsr.conf";
+ const std::string CONFIG_FILE = "unit-test-nlsr.conf";
ConfFileProcessor cfp1(nlsr1, CONFIG_FILE);
diff --git a/tests/test-conf-parameter.cpp b/tests/test-conf-parameter.cpp
index e376084..95ae19e 100644
--- a/tests/test-conf-parameter.cpp
+++ b/tests/test-conf-parameter.cpp
@@ -77,7 +77,7 @@
BOOST_CHECK_EQUAL(cp1.getRootKeyPrefix(), "adminRootKey");
- BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), 2);
+ BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), (uint32_t)2);
BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);
diff --git a/tests/test-lsa.cpp b/tests/test-lsa.cpp
index 715d19e..e7326b4 100644
--- a/tests/test-lsa.cpp
+++ b/tests/test-lsa.cpp
@@ -27,7 +27,7 @@
NameLsa nlsa1("router1", 1, 12, 1800, npl1);
NameLsa nlsa2("router2", 1, 12, 1500, npl1);
- BOOST_CHECK_EQUAL(nlsa1.getLsType(), 1);
+ BOOST_CHECK_EQUAL(nlsa1.getLsType(), (uint8_t)1);
BOOST_CHECK(nlsa1.getLifeTime() != nlsa2.getLifeTime());
@@ -47,12 +47,12 @@
AdjLsa alsa1("router1", 2, 12, 1800, 1, adjList);
AdjLsa alsa2("router1", 2, 12, 1800, 1, adjList);
- BOOST_CHECK_EQUAL(alsa1.getLsType(), 2);
- BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), 12);
- BOOST_CHECK_EQUAL(alsa1.getLifeTime(), 1800);
- BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
+ BOOST_CHECK_EQUAL(alsa1.getLsType(), (uint8_t)2);
+ BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
+ BOOST_CHECK_EQUAL(alsa1.getLifeTime(), (uint32_t)1800);
+ BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
- BOOST_CHECK(alsa1.isEqual(alsa2));
+ BOOST_CHECK(alsa1.isEqualContent(alsa2));
alsa1.addAdjacent(adj2);
@@ -69,7 +69,7 @@
BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
- BOOST_CHECK(clsa1.isEqual(clsa2));
+ BOOST_CHECK(clsa1.isEqualContent(clsa2));
BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
}
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index efc6f4a..7511fdb 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -21,9 +21,9 @@
NamePrefixList npl1;
- string s1 = "name1";
- string s2 = "name2";
- string router1 = "router1/1";
+ std::string s1 = "name1";
+ std::string s2 = "name2";
+ std::string router1 = "router1/1";
npl1.insert(s1);
npl1.insert(s2);
diff --git a/tests/test-map.cpp b/tests/test-map.cpp
index ebbfb15..1d5d4d2 100644
--- a/tests/test-map.cpp
+++ b/tests/test-map.cpp
@@ -19,8 +19,8 @@
std::string router1 = "r1";
std::string router2 = "r2";
- map1.addElement(router1);
- map1.addElement(router2);
+ map1.addEntry(router1);
+ map1.addEntry(router2);
BOOST_CHECK_EQUAL(map1.getMapSize(), 2);
}
diff --git a/tests/test-nexthop-list.cpp b/tests/test-nexthop-list.cpp
index 10222e8..cdf0c3e 100644
--- a/tests/test-nexthop-list.cpp
+++ b/tests/test-nexthop-list.cpp
@@ -20,10 +20,10 @@
NexthopList nhl1;
nhl1.addNextHop(np1);
- BOOST_CHECK_EQUAL(nhl1.getSize(), 1);
+ BOOST_CHECK_EQUAL(nhl1.getSize(), (uint32_t)1);
nhl1.removeNextHop(np1);
- BOOST_CHECK_EQUAL(nhl1.getSize(), 0);
+ BOOST_CHECK_EQUAL(nhl1.getSize(), (uint32_t)0);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-nexthop.cpp b/tests/test-nexthop.cpp
index b0bb90d..0cdf23c 100644
--- a/tests/test-nexthop.cpp
+++ b/tests/test-nexthop.cpp
@@ -20,7 +20,7 @@
np1.setRouteCost(10.5);
- BOOST_CHECK_EQUAL(np1.getConnectingFace(), 1);
+ BOOST_CHECK_EQUAL(np1.getConnectingFace(), (uint32_t)1);
BOOST_CHECK_CLOSE(np1.getRouteCost(), 10.5, 0.0001);
}
diff --git a/tests/test-sequencing-manager.cpp b/tests/test-sequencing-manager.cpp
index 9ae9d55..bdf19b2 100644
--- a/tests/test-sequencing-manager.cpp
+++ b/tests/test-sequencing-manager.cpp
@@ -18,11 +18,11 @@
SequencingManager sm2(sm1.getCombinedSeqNo());
- BOOST_CHECK_EQUAL(sm2.getNameLsaSeq(), 120);
+ BOOST_CHECK_EQUAL(sm2.getNameLsaSeq(), (uint32_t)120);
- BOOST_CHECK_EQUAL(sm2.getAdjLsaSeq(), 121);
+ BOOST_CHECK_EQUAL(sm2.getAdjLsaSeq(), (uint32_t)121);
- BOOST_CHECK_EQUAL(sm2.getCorLsaSeq(), 122);
+ BOOST_CHECK_EQUAL(sm2.getCorLsaSeq(), (uint32_t)122);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/wscript b/wscript
index 43159f4..146b5e8 100644
--- a/wscript
+++ b/wscript
@@ -46,7 +46,7 @@
conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
uselib_store='NDN_CPP', mandatory=True)
- boost_libs = 'system chrono program_options log iostreams thread'
+ boost_libs = 'system chrono program_options iostreams thread'
if conf.options.with_tests:
conf.env['WITH_TESTS'] = 1
conf.define('WITH_TESTS', 1);
@@ -55,7 +55,7 @@
conf.check_boost(lib=boost_libs)
if conf.env.BOOST_VERSION_NUMBER < 104800:
- Logs.error("Minimum required boost version is 1.54.0")
+ Logs.error("Minimum required boost version is 1.48.0")
Logs.error("Please upgrade your distribution or install custom boost libraries")
return