diff --git a/nlsr.cpp b/nlsr.cpp index 145fa47..a21aa3f 100644 --- a/nlsr.cpp +++ b/nlsr.cpp @@ -65,7 +65,7 @@ main(){ /* debugging purpose start */ - cout << nlsr.getConfParameter(); ; + cout << nlsr.getConfParameter(); nlsr.getAdl().printAdl(); nlsr.getNpl().printNpl(); nlsr.getLsdb().printNameLsdb(); diff --git a/nlsr.hpp b/nlsr.hpp index c78caac..8b325fe 100644 --- a/nlsr.hpp +++ b/nlsr.hpp @@ -33,6 +33,10 @@ public: , nameLsaSeq(0) , adjLsaSeq(0) , corLsaSeq(0) + , adjBuildCount(0) + , isBuildAdjLsaSheduled(0) + , isRouteCalculationScheduled(0) + , isRoutingTableCalculating(0) { isDaemonProcess=false; configFileName="nlsr.conf"; @@ -49,6 +53,10 @@ public: , im() , dm() , nlsrLsdb() + , adjBuildCount(0) + , isBuildAdjLsaSheduled(0) + , isRouteCalculationScheduled(0) + , isRoutingTableCalculating(0) { isDaemonProcess=false; configFileName=confFile; @@ -151,7 +159,32 @@ public: void setCorLsaSeq(uint32_t clsn){ corLsaSeq=clsn; } - + + long int getAdjBuildCount() + { + return adjBuildCount; + } + + void incrementAdjBuildCount() + { + adjBuildCount++; + } + + void setAdjBuildCount(long int abc) + { + adjBuildCount=abc; + } + + int getIsBuildAdjLsaSheduled() + { + return isBuildAdjLsaSheduled; + } + + void setIsBuildAdjLsaSheduled(int iabls) + { + isBuildAdjLsaSheduled=iabls; + } + private: ConfParameter confParam; Adl adl; @@ -168,6 +201,11 @@ private: uint32_t nameLsaSeq; uint32_t adjLsaSeq; uint32_t corLsaSeq; + + long int adjBuildCount; + int isBuildAdjLsaSheduled; + int isRouteCalculationScheduled; + int isRoutingTableCalculating; }; diff --git a/nlsr_adl.cpp b/nlsr_adl.cpp index 0cbdb4a..0f4be8f 100644 --- a/nlsr_adl.cpp +++ b/nlsr_adl.cpp @@ -3,6 +3,7 @@ #include "nlsr_adl.hpp" #include "nlsr_adjacent.hpp" +#include "nlsr.hpp" Adl::Adl(){ } @@ -151,6 +152,51 @@ Adl::getAdjList(){ return adjList; } +bool +Adl::isAdjLsaBuildable(nlsr& pnlsr) +{ + int nbrCount=0; + for( std::list::iterator it=adjList.begin(); + it!= adjList.end() ; it++) + { + if ( ((*it).getStatus() == 1 ) ) + { + nbrCount++; + } + else + { + if ( (*it).getInterestTimedOutNo() >= + pnlsr.getConfParameter().getInterestRetryNumber()) + { + nbrCount++; + } + } + } + + if( nbrCount == adjList.size()) + { + return true; + } + + return false; +} + +int +Adl::getNumOfActiveNeighbor() +{ + int actNbrCount=0; + for( std::list::iterator it=adjList.begin(); + it!= adjList.end() ; it++) + { + if ( ((*it).getStatus() == 1 ) ) + { + actNbrCount++; + } + } + + return actNbrCount; +} + // used for debugging purpose void Adl::printAdl(){ diff --git a/nlsr_adl.hpp b/nlsr_adl.hpp index 71829c1..d6923e1 100644 --- a/nlsr_adl.hpp +++ b/nlsr_adl.hpp @@ -5,6 +5,8 @@ #include "nlsr_adjacent.hpp" #include +class nlsr; + using namespace std; class Adl{ @@ -23,6 +25,14 @@ public: void setStatusOfNeighbor(string& neighbor, int status); void setTimedOutInterestCount(string& neighbor, int count); + bool isAdjLsaBuildable(nlsr& pnlsr); + int getNumOfActiveNeighbor(); + + int getAdlSize() + { + return adjList.size(); + } + void printAdl(); private: diff --git a/nlsr_conf_param.hpp b/nlsr_conf_param.hpp index ce56c72..817bf2e 100644 --- a/nlsr_conf_param.hpp +++ b/nlsr_conf_param.hpp @@ -7,17 +7,12 @@ using namespace std; class ConfParameter{ - public: - ConfParameter() - :chronosyncSyncPrefix("ndn/nlsr/sync") - ,chronosyncLsaPrefix("/ndn/nlsr/LSA") +public: + ConfParameter() + :chronosyncSyncPrefix("ndn/nlsr/sync") + ,chronosyncLsaPrefix("/ndn/nlsr/LSA") { - adjBuildFlag=0; - adjBuildCount=0; - isBuildAdjLsaSheduled=0; - isRouteCalculationScheduled=0; - isRoutingTableCalculating=0; - isStrictHierchicalKeyCheck=0; + isStrictHierchicalKeyCheck=0; interestRetryNumber=3; interestResendTime=5; @@ -27,10 +22,8 @@ class ConfParameter{ maxFacesPerPrefix=0; tunnelType=0; detailedLogging=0; - debugging=0; - isHyperbolicCalc=0; - - + debugging=0; + isHyperbolicCalc=0; } void setRouterName(const string& rn){ @@ -206,13 +199,6 @@ private: double corTheta; int tunnelType; - - int adjBuildFlag; - long int adjBuildCount; - int isBuildAdjLsaSheduled; - int isRouteCalculationScheduled; - - int isRoutingTableCalculating; int isStrictHierchicalKeyCheck; }; diff --git a/nlsr_dm.cpp b/nlsr_dm.cpp index 7b958de..1ff7555 100644 --- a/nlsr_dm.cpp +++ b/nlsr_dm.cpp @@ -6,6 +6,7 @@ #include "nlsr.hpp" #include "nlsr_dm.hpp" #include "nlsr_tokenizer.hpp" +#include "nlsr_lsdb.hpp" using namespace std; using namespace ndn; @@ -40,28 +41,43 @@ DataManager::processContentInfo(nlsr& pnlsr, string& dataName, string chkString("info"); string neighbor="/" + nt.getFirstToken() +nt.getTokenString(0,nt.getTokenPosition(chkString)-1); - int status=pnlsr.getAdl().getStatusOfNeighbor(neighbor); + int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor); int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor); //debugging purpose start cout <<"Before Updates: " < al=padl.getAdjList(); + for( std::list::iterator it=al.begin(); it != al.end(); it++) + { + if((*it).getStatus()==1) + { + addAdjacentToLsa((*it)); + } + } +} + +string +AdjLsa::getAdjLsaData(){ + string adjLsaData; + adjLsaData=origRouter + "|" + boost::lexical_cast(lsType) + "|" + + boost::lexical_cast(lsSeqNo) + "|" + + boost::lexical_cast(lifeTime); + adjLsaData+="|"; + adjLsaData+=boost::lexical_cast(adl.getAdlSize()); + + std::list al=adl.getAdjList(); + for( std::list::iterator it=al.begin(); it != al.end(); it++) + { + adjLsaData+="|"; + adjLsaData+=(*it).getAdjacentName(); + adjLsaData+="|"; + adjLsaData+=boost::lexical_cast((*it).getConnectingFace()); + adjLsaData+="|"; + adjLsaData+=boost::lexical_cast((*it).getLinkCost()); + + } + return adjLsaData; +} + +std::ostream& +operator<<(std::ostream& os, AdjLsa& aLsa) +{ + os<<"Adj Lsa: "< al=aLsa.getAdl().getAdjList(); + for( std::list::iterator it=al.begin(); it != al.end(); it++) + { + os<<" Adjacent "<0 ) + { + if (pnlsr.getAdl().getNumOfActiveNeighbor()>0) + { + buildAndInstallOwnAdjLsa(pnlsr); + } + else + { + //remove if there is any adj lsa in LSDB + } + pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount); + } + } + else + { + pnlsr.setIsBuildAdjLsaSheduled(1); + int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()* + pnlsr.getConfParameter().getInterestRetryNumber(); + pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime), + ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(), + boost::ref(pnlsr))); + } + +} + + +bool +Lsdb::addAdjLsa(AdjLsa &alsa) +{ + std::list::iterator it = std::find_if( adjLsdb.begin(), + adjLsdb.end(), + bind(adjLsaCompare, _1, alsa)); + + if( it == adjLsdb.end()){ + adjLsdb.push_back(alsa); + return true; + } + return false; + +} + +AdjLsa& +Lsdb::getAdjLsa(string key) +{ + std::list::iterator it = std::find_if( adjLsdb.begin(), + adjLsdb.end(), + bind(adjLsaCompareByKey, _1, key)); + + if( it != adjLsdb.end()){ + return (*it); + } + +} + +bool +Lsdb::installAdjLsa(AdjLsa &alsa) +{ + bool doesLsaExist_ = doesAdjLsaExist(alsa.getLsaKey()); + if ( !doesLsaExist_ ) + { + // add Adj LSA + addAdjLsa(alsa); + // schedule routing table calculation + } + else + { + // check for newer name LSA + AdjLsa oldAdjLsa=getAdjLsa(alsa.getLsaKey()); + + } + + printAdjLsdb(); + + return true; +} + +bool +Lsdb::buildAndInstallOwnAdjLsa(nlsr& pnlsr) +{ + AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix() + , 2 + , pnlsr.getAdjLsaSeq()+1 + , pnlsr.getConfParameter().getRouterDeadInterval() + , pnlsr.getAdl().getNumOfActiveNeighbor() + , pnlsr.getAdl() ); + pnlsr.setAdjLsaSeq(pnlsr.getAdjLsaSeq()+1); + return installAdjLsa(adjLsa); +} + +bool +Lsdb::removeAdjLsa(string& key) +{ + +} bool Lsdb::doesAdjLsaExist(string key) @@ -264,4 +366,13 @@ Lsdb::doesAdjLsaExist(string key) return true; } +void +Lsdb::printAdjLsdb() +{ + for( std::list::iterator it=adjLsdb.begin(); + it!= adjLsdb.end() ; it++) + { + cout<< (*it) < nameLsdb; std::list adjLsdb;