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 + +#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 * Chaoyi Bian - * Alexander Afanasyev + * Alexander Afanasyev */ #ifndef SYNC_DIGEST_H #define SYNC_DIGEST_H #include -#include #include #include +#include "openssl.h" namespace Sync { @@ -47,7 +47,7 @@ public: */ bool empty () const; - + /** * @brief Reset digest to the initial state */ @@ -84,7 +84,7 @@ public: bool operator != (const Digest &digest) const { return ! (*this == digest); } - + /** * @brief Add existing digest to digest calculation @@ -116,11 +116,11 @@ public: */ 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 @@ private: friend std::istream & operator >> (std::istream &is, Digest &digest); - + private: EVP_MD_CTX *m_context; std::vector 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 @@ AdjacencyList::~AdjacencyList() { } -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::iterator it = find(adj.getName()); + std::list::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::iterator it = adl.getAdjList().begin(); it != adl.getAdjList().end(); ++it) @@ -44,8 +40,8 @@ AdjacencyList::addAdjacentsFromAdl(AdjacencyList& adl) } } -int -AdjacencyList::updateAdjacentStatus(const string& adjName, int s) +int32_t +AdjacencyList::updateAdjacentStatus(const string& adjName, int32_t s) { std::list::iterator it = find(adjName); if (it == m_adjList.end()) @@ -68,24 +64,29 @@ AdjacencyList::getAdjacent(const string& adjName) 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 adjList2 = adl.getAdjList(); + m_adjList.sort(compareAdjacent); + adl.getAdjList().sort(compareAdjacent); + uint32_t equalAdjCount = 0; + std::list& adjList2 = adl.getAdjList(); std::list::iterator it1; std::list::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 @@ AdjacencyList::isEqual(AdjacencyList& adl) return equalAdjCount == getSize(); } - -int +int32_t AdjacencyList::updateAdjacentLinkCost(const string& adjName, double lc) { std::list::iterator it = find(adjName); @@ -130,7 +130,7 @@ AdjacencyList::incrementTimedOutInterestCount(const string& neighbor) } void -AdjacencyList::setTimedOutInterestCount(const string& neighbor, int count) +AdjacencyList::setTimedOutInterestCount(const string& neighbor, uint32_t count) { std::list::iterator it = find(neighbor); if (it != m_adjList.end()) @@ -139,7 +139,7 @@ AdjacencyList::setTimedOutInterestCount(const string& neighbor, int count) } } -int +int32_t AdjacencyList::getTimedOutInterestCount(const string& neighbor) { std::list::iterator it = find(neighbor); @@ -150,7 +150,7 @@ AdjacencyList::getTimedOutInterestCount(const string& neighbor) return (*it).getInterestTimedOutNo(); } -int +uint32_t AdjacencyList::getStatusOfNeighbor(const string& neighbor) { std::list::iterator it = find(neighbor); @@ -162,7 +162,7 @@ AdjacencyList::getStatusOfNeighbor(const string& neighbor) } void -AdjacencyList::setStatusOfNeighbor(const string& neighbor, int status) +AdjacencyList::setStatusOfNeighbor(const string& neighbor, int32_t status) { std::list::iterator it = find(neighbor); if (it != m_adjList.end()) @@ -204,10 +204,10 @@ AdjacencyList::isAdjLsaBuildable(Nlsr& pnlsr) return false; } -int +int32_t AdjacencyList::getNumOfActiveNeighbor() { - int actNbrCount = 0; + int32_t actNbrCount = 0; for (std::list::iterator it = m_adjList.begin(); it != m_adjList.end(); it++) { @@ -225,7 +225,7 @@ AdjacencyList::find(std::string adjName) Adjacent adj(adjName); std::list::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 #include +#include +#include #include "adjacent.hpp" @@ -16,13 +17,13 @@ public: 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& @@ -34,34 +35,34 @@ public: 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 @@ private: }; } //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 #include + #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 @@ Adjacent::Adjacent(const string& an, int cf, double lc, int s, int iton) } 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::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 +#include -#ifndef ADJACENT_HPP -#define ADJACENT_HPP +#ifndef NLSR_ADJACENT_HPP +#define NLSR_ADJACENT_HPP namespace nlsr { class Adjacent @@ -26,10 +27,10 @@ public: 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 @@ public: 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 @@ public: 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 @@ DataManager::processContentInfo(const string& dataName, 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 @@ DataManager::processContentInfo(const string& dataName, 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 #include #include @@ -50,4 +52,4 @@ private: }//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 #include - #include #include @@ -55,7 +54,7 @@ InterestManager::processInterestInfo(const string& neighbor, // 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 @@ InterestManager::processInterestForNameLsa(const ndn::Interest& interest, // 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 @@ InterestManager::processInterestForAdjLsa(const ndn::Interest& interest, // 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 @@ InterestManager::processInterestForCorLsa(const ndn::Interest& interest, // 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 @@ InterestManager::processInterestTimedOutInfo(const string& neighbor, { 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 @@ InterestManager::processInterestTimedOutLsa(const ndn::Interest& interest) 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 adjList = m_nlsr.getAdjacencyList().getAdjList(); for (std::list::iterator it = adjList.begin(); it != adjList.end(); @@ -325,7 +323,7 @@ InterestManager::sendScheduledInfoInterest(int seconds) } 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 #include #include @@ -51,13 +53,13 @@ public: 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 @@ private: }//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 @@ SyncLogicHandler::nsyncUpdateCallBack(const vector& v, 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 @@ SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr) } 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 @@ SyncLogicHandler::processUpdateFromSync(std::string updateName, } 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 @@ SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName, void SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm, - string updatePrefix) + const string& updatePrefix) { sm.writeSeqNoToFile(); publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo()); @@ -136,13 +139,13 @@ SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm, // } 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 +#include #include #include @@ -24,7 +25,7 @@ namespace nlsr { class SyncLogicHandler { public: - SyncLogicHandler(ndn::shared_ptr ioService) + SyncLogicHandler(boost::asio::io_service& ioService) : m_validator(new ndn::ValidatorNull()) , m_syncFace(new ndn::Face(ioService)) {} @@ -34,26 +35,26 @@ public: createSyncSocket(Nlsr& pnlsr); void - nsyncUpdateCallBack(const vector& v, + nsyncUpdateCallBack(const std::vector& 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 @@ public: 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 m_validator; @@ -82,4 +83,4 @@ private: } //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 #include "nlsr.hpp" namespace nlsr { @@ -8,7 +9,7 @@ namespace nlsr { 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 @@ public: 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 +#include namespace nlsr { class ConfParameter @@ -34,7 +35,7 @@ public: m_routerName = rn; } - std::string + const std::string& getRouterName() { return m_routerName; @@ -46,7 +47,7 @@ public: m_siteName = sn; } - std::string + const std::string& getSiteName() { return m_siteName; @@ -58,7 +59,7 @@ public: m_network = nn; } - std::string + const std::string& getNetwork() { return m_network; @@ -70,13 +71,13 @@ public: 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 @@ public: } 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 @@ public: } 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 @@ public: } 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 @@ public: m_tunnelType = tt; } - int + int32_t getTunnelType() { return m_tunnelType; @@ -263,32 +264,32 @@ public: 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 @@ private: 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 @@ operator<<(std::ostream& os, ConfParameter& cfp); } // 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::getKey() const } 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 @@ CoordinateLsa::getKey() const } bool -CoordinateLsa::isEqual(const CoordinateLsa& clsa) +CoordinateLsa::isEqualContent(const CoordinateLsa& clsa) { return (std::abs(m_corRad - clsa.getCorRadius()) < std::numeric_limits::epsilon()) && @@ -192,7 +192,7 @@ operator<<(std::ostream& os, const CoordinateLsa& cLsa) 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 @@ AdjLsa::getKey() } bool -AdjLsa::isEqual(AdjLsa& alsa) +AdjLsa::isEqualContent(AdjLsa& alsa) { - return m_adl.isEqual(alsa.getAdl()); + return m_adl == alsa.getAdl(); } @@ -291,7 +291,7 @@ AdjLsa::addNptEntries(Nlsr& pnlsr) { if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) { - pnlsr.getNamePrefixTable().addNpteByDestName(getOrigRouter(), getOrigRouter(), + pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter(), pnlsr); } } @@ -302,7 +302,7 @@ AdjLsa::removeNptEntries(Nlsr& pnlsr) { 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 #include #include "adjacent.hpp" #include "name-prefix-list.hpp" @@ -98,7 +99,7 @@ public: } NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt, - NamePrefixList npl); + NamePrefixList& npl); NamePrefixList& getNpl() @@ -149,7 +150,7 @@ public: } 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 @@ public: } bool - isEqual(AdjLsa& alsa); + isEqualContent(AdjLsa& alsa); void addNptEntries(Nlsr& pnlsr); @@ -250,7 +251,7 @@ public: } 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 @@ namespace nlsr { 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 @@ nameLsaCompareByKey(const NameLsa& nlsa1, const string& key) 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 @@ Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa) 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 nameList = nlsa.getNpl().getNameList(); for (std::list::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 @@ Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa) { if ((*it) != pnlsr.getConfParameter().getRouterPrefix()) { - pnlsr.getNamePrefixTable().addNpteByDestName((*it), nlsa.getOrigRouter(), - pnlsr); + pnlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter(), pnlsr); } } } @@ -149,7 +145,7 @@ Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa) { if ((*it) != pnlsr.getConfParameter().getRouterPrefix()) { - pnlsr.getNamePrefixTable().removeNpte((*it), nlsa.getOrigRouter(), pnlsr); + pnlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter(), pnlsr); } } } @@ -195,14 +191,14 @@ Lsdb::removeNameLsa(Nlsr& pnlsr, string& key) (*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::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 @@ corLsaCompareByKey(const CoordinateLsa& clsa, const string& key) 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 @@ Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa) 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 @@ Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa) { 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 @@ Lsdb::removeCoordinateLsa(Nlsr& pnlsr, const string& key) { 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 @@ Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa) { 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 @@ Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa) 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 @@ Lsdb::exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo) 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 @@ Lsdb::exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo) 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 @@ Lsdb::exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const string& lsaKey, 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 +#include + #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 . **/ - +#include #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 @@ main(int argc, char** argv) break; case 'p': { - stringstream sst(optarg); + std::stringstream sst(optarg); int ap; sst >> ap; nlsr.setApiPort(ap); @@ -55,7 +55,7 @@ main(int argc, char** argv) } } 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 @@ main(int argc, char** argv) 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 @@ nameCompare(const string& s1, const string& s2) return s1 == s2; } -int -NamePrefixList::insert(string& name) +int32_t +NamePrefixList::insert(const string& name) { std::list::iterator it = std::find_if(m_nameList.begin(), m_nameList.end(), @@ -37,8 +37,8 @@ NamePrefixList::insert(string& name) return 0; } -int -NamePrefixList::remove(string& name) +int32_t +NamePrefixList::remove(const string& name) { std::list::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 #include +#include namespace nlsr { @@ -14,16 +15,16 @@ public: ~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 @@ private: }//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 @@ using namespace std; 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 @@ Nlsr::initialize() /* 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 @@ Nlsr::initialize() 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 @@ Nlsr::usage(const string& progname) 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 +#include + #include #include #include @@ -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(&*m_io, - &NullDeleter))) - , m_scheduler(*m_io) + : m_scheduler(m_nlsrFace.getIoService()) , m_confParam() , m_adjacencyList() , m_namePrefixList() @@ -51,30 +55,30 @@ public: , 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 @@ public: return m_namePrefixList; } - ndn::shared_ptr& - getIo() - { - return m_io; - } - ndn::Scheduler& getScheduler() { return m_scheduler; } - ndn::shared_ptr + ndn::Face& getNlsrFace() { return m_nlsrFace; @@ -189,7 +187,7 @@ public: } void - setAdjBuildCount(long int abc) + setAdjBuildCount(int64_t abc) { m_adjBuildCount = abc; } @@ -208,12 +206,12 @@ public: void - setApiPort(int ap) + setApiPort(int32_t ap) { m_apiPort = ap; } - int + int32_t getApiPort() { return m_apiPort; @@ -253,8 +251,7 @@ public: initialize(); private: - ndn::shared_ptr m_io; - ndn::shared_ptr m_nlsrFace; + ndn::Face m_nlsrFace; ndn::Scheduler m_scheduler; ConfParameter m_confParam; AdjacencyList m_adjacencyList; @@ -264,25 +261,17 @@ private: 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 @@ using namespace std; 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::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 @@ FibEntry::isEqualNextHops(NexthopList& nhlOther) break; } } - return nhCount == m_nhl.getSize(); + return nhCount == m_nexthopList.getSize(); } } @@ -40,7 +40,7 @@ operator<<(ostream& os, FibEntry fe) { 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 #include +#include + #include #include "nexthop.hpp" @@ -10,8 +12,6 @@ namespace nlsr { -using namespace std; - class FibEntry { public: @@ -19,38 +19,38 @@ public: : 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 @@ public: } void - setSeqNo(int fsn) + setSeqNo(int32_t fsn) { m_seqNo = fsn; } - int + int32_t getSeqNo() { return m_seqNo; @@ -84,10 +84,10 @@ public: 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 @@ operator<<(std::ostream& os, FibEntry fe); } //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 +#include #include "nlsr.hpp" -#include "fib-entry.hpp" -#include "fib.hpp" #include "nexthop-list.hpp" +#include "fib.hpp" + @@ -13,9 +14,9 @@ using namespace std; 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 @@ Fib::cancelScheduledExpiringEvent(Nlsr& pnlsr, EventId eid) 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::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::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::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::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 @@ Fib::remove(Nlsr& pnlsr, string name) 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 @@ Fib::update(Nlsr& pnlsr, string name, NexthopList& nextHopList) { nextHopList.sort(); FibEntry newEntry(name); - std::list nhl = nextHopList.getNextHopList(); + std::list nhl = nextHopList.getNextHops(); std::list::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 @@ Fib::update(Nlsr& pnlsr, string name, NexthopList& nextHopList) nextHopList.sort(); if (!it->isEqualNextHops(nextHopList)) { - std::list nhl = nextHopList.getNextHopList(); + std::list nhl = nextHopList.getNextHops(); std::list::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 @@ Fib::clean(Nlsr& pnlsr) for (std::list::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::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 @@ Fib::clean(Nlsr& pnlsr) } int -Fib::getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix) +Fib::getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix) { int endFace = 0; if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) @@ -163,18 +229,78 @@ Fib::getNumberOfFacesForName(NexthopList& nextHopList, int maxFacesPerPrefix) } 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::iterator it = nl.getNextHopList().begin(); - it != nl.getNextHopList().end(); ++it) + for (std::list::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(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(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() { 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 +#include + +#include + #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 @@ public: 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 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 + +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 @@ namespace nlsr { 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::iterator it = std::find_if(m_table.begin(), @@ -57,7 +49,7 @@ Map::addElement(MapEntry& mpe) } string -Map::getRouterNameByMappingNo(int mn) +Map::getRouterNameByMappingNo(int32_t mn) { std::list::iterator it = std::find_if(m_table.begin(), m_table.end(), @@ -70,7 +62,7 @@ Map::getRouterNameByMappingNo(int mn) return ""; } -int +int32_t Map::getMappingNoByRouterName(string& rName) { std::list::iterator it = std::find_if(m_table.begin(), @@ -92,13 +84,13 @@ Map::createFromAdjLsdb(Nlsr& pnlsr) it != adjLsdb.end() ; it++) { string linkStartRouter = (*it).getOrigRouter(); - addElement(linkStartRouter); + addEntry(linkStartRouter); std::list adl = (*it).getAdl().getAdjList(); for (std::list::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 #include +#include -#include +#include + +#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 @@ public: 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 @@ public: private: bool - addElement(MapEntry& mpe); + addEntry(MapEntry& mpe); - int m_mappingIndex; + int32_t m_mappingIndex; std::list 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 @@ using namespace std; void NamePrefixTableEntry::generateNhlfromRteList() { - m_nhl.reset(); + m_nexthopList.reset(); for (std::list::iterator it = m_rteList.begin(); it != m_rteList.end(); ++it) { for (std::list::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 @@ NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte) } else { - (*it).getNhl().reset(); // reseting existing routing table's next hop - for (std::list::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::iterator nhit = rte.getNexthopList().getNextHops().begin(); + nhit != rte.getNexthopList().getNextHops().end(); ++nhit) { - (*it).getNhl().addNextHop((*nhit)); + (*it).getNexthopList().addNextHop((*nhit)); } } } @@ -76,7 +76,7 @@ operator<<(ostream& os, NamePrefixTableEntry& npte) { 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 #include +#include + #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 @@ public: for (std::list::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 @@ public: private: std::string m_namePrefix; std::list m_rteList; - NexthopList m_nhl; + NexthopList m_nexthopList; }; std::ostream& @@ -81,4 +79,4 @@ operator<<(std::ostream& os, NamePrefixTableEntry& npte); }//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 @@ namespace nlsr { using namespace std; static bool -npteCompare(NamePrefixTableEntry& npte, string& name) +npteCompare(NamePrefixTableEntry& npte, const string& name) { return npte.getNamePrefix() == name; } @@ -21,46 +21,46 @@ npteCompare(NamePrefixTableEntry& npte, string& name) void -NamePrefixTable::addNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr) +NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr) { - std::list::iterator it = std::find_if(m_npteList.begin(), - m_npteList.end(), bind(&npteCompare, _1, name)); - if (it == m_npteList.end()) + std::list::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::iterator it = std::find_if(m_npteList.begin(), - m_npteList.end(), bind(&npteCompare, _1, name)); - if (it != m_npteList.end()) + std::list::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 @@ NamePrefixTable::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr) (!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::iterator it = m_npteList.begin(); - it != m_npteList.end(); - ++it) + for (std::list::iterator it = m_table.begin(); + it != m_table.end(); ++it) { std::list rteList = (*it).getRteList(); for (std::list::iterator rteit = rteList.begin(); @@ -128,12 +127,12 @@ NamePrefixTable::updateWithNewRoute(Nlsr& pnlsr) 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 @@ void NamePrefixTable::print() { std::cout << "----------------NPT----------------------" << std::endl; - for (std::list::iterator it = m_npteList.begin(); - it != m_npteList.end(); + for (std::list::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 +#include + #include "name-prefix-table-entry.hpp" #include "routing-table-entry.hpp" @@ -14,11 +16,12 @@ public: 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 @@ public: 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 m_npteList; + std::list 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 @@ NexthopList::sort() ostream& operator<<(ostream& os, NexthopList& nhl) { - std::list nexthopList = nhl.getNextHopList(); + std::list nexthopList = nhl.getNextHops(); int i = 1; for (std::list::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 #include #include +#include + +#include #include "nexthop.hpp" #include "adjacent.hpp" @@ -14,13 +16,13 @@ class NexthopList { public: NexthopList() - : m_nexthopList() { } ~NexthopList() { } + void addNextHop(NextHop& nh); @@ -30,7 +32,7 @@ public: void sort(); - int + size_t getSize() { return m_nexthopList.size(); @@ -39,14 +41,11 @@ public: void reset() { - if (m_nexthopList.size() > 0) - { - m_nexthopList.clear(); - } + m_nexthopList.clear(); } std::list& - getNextHopList() + getNextHops() { return m_nexthopList; } @@ -60,4 +59,4 @@ operator<<(std::ostream& os, NexthopList& nhl); }//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 +#include namespace nlsr { class NextHop @@ -13,20 +14,20 @@ public: { } - 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 @@ public: } 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 #include +#include namespace nlsr { @@ -198,4 +199,4 @@ private: }//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 -#include - -#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 nhl = rte.getNhl().getNextHopList(); - for (std::list::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 @@ -11,8 +11,6 @@ class RoutingTableEntry { public: RoutingTableEntry() - : m_destination() - , m_nhl() { } @@ -20,8 +18,7 @@ public: { } - RoutingTableEntry(std::string dest) - : m_nhl() + RoutingTableEntry(const std::string& dest) { m_destination = dest; } @@ -33,19 +30,31 @@ public: } 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 nhl = rte.getNexthopList().getNextHops(); + for (std::list::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 @@ RoutingTable::addNextHop(string destRouter, NextHop& nh) 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 @@ RoutingTable::addNextHopToDryTable(string destRouter, NextHop& nh) 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 #include #include +#include #include "routing-table-entry.hpp" @@ -70,4 +71,4 @@ private: }//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 #include +#include + #include namespace nlsr { @@ -70,6 +72,27 @@ public: combineSequenceNo(); } + void + increaseNameLsaSeq() + { + m_nameLsaSeq++; + combineSequenceNo(); + } + + void + increaseAdjLsaSeq() + { + m_adjLsaSeq++; + combineSequenceNo(); + } + + void + increaseCorLsaSeq() + { + m_corLsaSeq++; + combineSequenceNo(); + } + uint64_t getCombinedSeqNo() const { @@ -95,7 +118,6 @@ private: void combineSequenceNo(); - private: uint64_t m_nameLsaSeq; uint64_t m_adjLsaSeq; @@ -109,4 +131,4 @@ std::ostream& 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 -#include -#include -#include -#include -#include - -#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 file_sink; - shared_ptr 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - - - -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 @@ Tokenizer::insertToken(const string& token) uint32_t Tokenizer::getTokenPosition(string& token) { - int pos = -1; - int i = 0; + uint32_t pos = -1; + uint32_t i = 0; for (std::list::iterator it = m_tokenList.begin(); it != m_tokenList.end(); it++) { @@ -67,7 +67,7 @@ Tokenizer::getTokenString(uint32_t from , uint32_t to) 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 @@ BOOST_AUTO_TEST_CASE(AdjacenctListBasic) 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 @@ BOOST_AUTO_TEST_CASE(AdjacenctBasic) 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 @@ BOOST_AUTO_TEST_CASE(ConfFileProcessorSample) "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_AUTO_TEST_CASE(ConfParameterSettersAndGetters) 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 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic) 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 @@ BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters) 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_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters) 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 @@ BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists) 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 @@ BOOST_AUTO_TEST_CASE(MapAddElementAndSize) 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 @@ BOOST_AUTO_TEST_CASE(NhlAddNextHop) 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 @@ BOOST_AUTO_TEST_CASE(NexthopSetAndGet) 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 @@ BOOST_AUTO_TEST_CASE(SequencingManagerBasic) 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 @@ def configure(conf): 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 @@ def configure(conf): 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