LSA refreshing/Expiration, Fib Refreshing Added
diff --git a/nlsr.cpp b/nlsr.cpp
index 5a873df..a92f8cb 100644
--- a/nlsr.cpp
+++ b/nlsr.cpp
@@ -91,7 +91,12 @@
{
return EXIT_FAILURE;
}
+
nlsr.getConfParameter().buildRouterPrefix();
+ nlsr.getLsdb().setLsaRefreshTime(nlsr.getConfParameter().getLsaRefreshTime());
+ nlsr.getFib().setFibEntryRefreshTime(2*nlsr.getConfParameter().getLsaRefreshTime());
+ nlsr.getFib().scheduleFibRefreshing(nlsr, 60);
+ nlsr.getLsdb().setThisRouterPrefix(nlsr.getConfParameter().getRouterPrefix());
/* debugging purpose start */
cout << nlsr.getConfParameter();
diff --git a/nlsr_fe.cpp b/nlsr_fe.cpp
index 350270e..1b9621f 100644
--- a/nlsr_fe.cpp
+++ b/nlsr_fe.cpp
@@ -39,6 +39,7 @@
operator<<(ostream& os, FibEntry& fe)
{
os<<"Name Prefix: "<<fe.getName()<<endl;
+ os<<"Time to Refresh: "<<fe.getTimeToRefresh()<<endl;
os<<fe.getNhl()<<endl;
return os;
}
diff --git a/nlsr_fe.hpp b/nlsr_fe.hpp
index c3af73b..8392dfb 100644
--- a/nlsr_fe.hpp
+++ b/nlsr_fe.hpp
@@ -14,6 +14,7 @@
public:
FibEntry()
: name()
+ , timeToRefresh(0)
{
}
@@ -32,10 +33,21 @@
return nhl;
}
+ int getTimeToRefresh()
+ {
+ return timeToRefresh;
+ }
+
+ void setTimeToRefresh(int ttr)
+ {
+ timeToRefresh=ttr;
+ }
+
bool isEqualNextHops(Nhl &nhlOther);
private:
string name;
+ int timeToRefresh;
Nhl nhl;
};
diff --git a/nlsr_fib.cpp b/nlsr_fib.cpp
index 2bfc568..399584f 100644
--- a/nlsr_fib.cpp
+++ b/nlsr_fib.cpp
@@ -2,6 +2,7 @@
#include "nlsr_fe.hpp"
#include "nlsr_fib.hpp"
#include "nlsr_nhl.hpp"
+#include "nlsr.hpp"
using namespace std;
@@ -29,13 +30,6 @@
}
}
-/**
-If NHL is equal for current FIB and NPT then to change
-Otherwise
- Add the first Nexthop to FIB
- remove all old nexthop from FIB
- And add all other Nexthop to FIB
-*/
void
Fib::updateFib(string name, Nhl& nextHopList, int maxFacesPerPrefix)
@@ -46,6 +40,7 @@
fibTable.end(), bind(&fibEntryNameCompare, _1, name));
if( it != fibTable.end() )
{
+ nextHopList.sortNhl();
if ( !(*it).isEqualNextHops(nextHopList) )
{
std::list<NextHop>::iterator nhit=nextHopList.getNextHopList().begin();
@@ -57,22 +52,56 @@
{
(*it).getNhl().addNextHop((*nhit));
}
+
+ (*it).setTimeToRefresh(fibEntryRefreshTime);
}
(*it).getNhl().sortNhl();
+ //update NDN-FIB
}
else
{
+ nextHopList.sortNhl();
FibEntry newEntry(name);
- for(std::list<NextHop>::iterator nhit=nextHopList.getNextHopList().begin();
- nhit!=nextHopList.getNextHopList().end();++nhit)
+ std::list<NextHop>::iterator nhit=nextHopList.getNextHopList().begin();
+ for(int i=startFace; i< endFace ; i++)
{
newEntry.getNhl().addNextHop((*nhit));
+ ++nhit;
}
newEntry.getNhl().sortNhl();
+ newEntry.setTimeToRefresh(fibEntryRefreshTime);
fibTable.push_back(newEntry);
+ //Update NDN-FIB
}
}
+void
+Fib::refreshFib(nlsr& pnlsr)
+{
+ for ( std::list<FibEntry >::iterator it = fibTable.begin() ;
+ it != fibTable.end() ; ++it)
+ {
+ (*it).setTimeToRefresh((*it).getTimeToRefresh()-60);
+ if( (*it).getTimeToRefresh() < 0 )
+ {
+ cout<<"Refreshing FIB entry : "<<endl;
+ cout<<(*it)<<endl;
+ (*it).setTimeToRefresh(fibEntryRefreshTime);
+ //update NDN-FIB
+ }
+ }
+
+ printFib();
+ scheduleFibRefreshing(pnlsr,60);
+}
+
+void
+Fib::scheduleFibRefreshing(nlsr& pnlsr, int refreshTime)
+{
+ pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
+ ndn::bind(&Fib::refreshFib,this,boost::ref(pnlsr)));
+}
+
void Fib::cleanFib()
{
for( std::list<FibEntry >::iterator it=fibTable.begin(); it != fibTable.end();
@@ -93,12 +122,12 @@
void
-Fib::removeFibEntryHop(Nhl& nl, int doNotRemoveHop)
+Fib::removeFibEntryHop(Nhl& nl, int doNotRemoveHopFaceId)
{
for( std::list<NextHop >::iterator it=nl.getNextHopList().begin();
it != nl.getNextHopList().end(); ++it)
{
- if ( (*it).getConnectingFace() != doNotRemoveHop )
+ if ( (*it).getConnectingFace() != doNotRemoveHopFaceId )
{
nl.getNextHopList().erase(it);
}
@@ -129,7 +158,6 @@
for(std::list<FibEntry>::iterator it = fibTable.begin(); it!=fibTable.end();
++it)
{
- //(*it).getNhl().sortNhl();
cout<<(*it);
}
}
diff --git a/nlsr_fib.hpp b/nlsr_fib.hpp
index f1f54ed..453b7db 100644
--- a/nlsr_fib.hpp
+++ b/nlsr_fib.hpp
@@ -17,15 +17,23 @@
void removeFromFib(string name);
void updateFib(string name, Nhl& nextHopList, int maxFacesPerPrefix);
+ void scheduleFibRefreshing(nlsr& pnlsr, int refreshTime);
void cleanFib();
+ void setFibEntryRefreshTime(int fert)
+ {
+ fibEntryRefreshTime=fert;
+ }
+
void printFib();
private:
- void removeFibEntryHop(Nhl& nl, int doNotRemoveHop);
+ void removeFibEntryHop(Nhl& nl, int doNotRemoveHopFaceId);
int getNumberOfFacesForName(Nhl& nextHopList, int maxFacesPerPrefix);
+ void refreshFib(nlsr& pnlsr);
private:
std::list<FibEntry> fibTable;
+ int fibEntryRefreshTime;
};
#endif
diff --git a/nlsr_lsdb.cpp b/nlsr_lsdb.cpp
index da7d86e..9e3ffe7 100644
--- a/nlsr_lsdb.cpp
+++ b/nlsr_lsdb.cpp
@@ -42,10 +42,18 @@
}
+void
+Lsdb::scheduleNameLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime)
+{
+ pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
+ ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
+ this,boost::ref(pnlsr), key, seqNo));
+}
bool
Lsdb::installNameLsa(nlsr& pnlsr, NameLsa &nlsa)
{
+ int timeToExpire=lsaRefreshTime;
std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(nlsa.getNameLsaKey());
if ( !chkNameLsa.second )
{
@@ -62,7 +70,14 @@
pnlsr.getNpt().addNpte((*it),nlsa.getOrigRouter(),pnlsr);
}
}
- }
+ }
+
+ if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
+ {
+ timeToExpire=nlsa.getLifeTime();
+ }
+ scheduleNameLsaExpiration( pnlsr, nlsa.getNameLsaKey(),
+ nlsa.getLsSeqNo(), timeToExpire);
}
else
{
@@ -110,8 +125,14 @@
pnlsr.getNpt().removeNpte((*it),nlsa.getOrigRouter(),pnlsr);
}
}
- }
-
+ }
+
+ if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
+ {
+ timeToExpire=nlsa.getLifeTime();
+ }
+ scheduleNameLsaExpiration( pnlsr, nlsa.getNameLsaKey(),
+ nlsa.getLsSeqNo(), timeToExpire);
}
}
@@ -122,8 +143,7 @@
Lsdb::addNameLsa(NameLsa &nlsa)
{
std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
- nameLsdb.end(),
- bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey()));
+ nameLsdb.end(), bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey()));
if( it == nameLsdb.end())
{
@@ -222,9 +242,18 @@
return std::make_pair(boost::ref(clsa),false);
}
+void
+Lsdb::scheduleCorLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime)
+{
+ pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
+ ndn::bind(&Lsdb::exprireOrRefreshCorLsa,
+ this,boost::ref(pnlsr),key,seqNo));
+}
+
bool
Lsdb::installCorLsa(nlsr& pnlsr, CorLsa &clsa)
{
+ int timeToExpire=lsaRefreshTime;
std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(clsa.getCorLsaKey());
if ( !chkCorLsa.second )
{
@@ -236,14 +265,15 @@
}
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
{
- if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
- {
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate,
- &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
- }
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
+
+ if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
+ {
+ timeToExpire=clsa.getLifeTime();
+ }
+ scheduleCorLsaExpiration(pnlsr,clsa.getCorLsaKey(),
+ clsa.getLsSeqNo(), timeToExpire);
}
else
@@ -259,16 +289,17 @@
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
{
- if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
- {
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate,
- &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
- }
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
}
+
+ if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
+ {
+ timeToExpire=clsa.getLifeTime();
+ }
+ scheduleCorLsaExpiration(pnlsr,clsa.getCorLsaKey(),
+ clsa.getLsSeqNo(), timeToExpire);
}
}
@@ -337,12 +368,7 @@
// Adj LSA and LSDB related function starts here
-/*
-static bool
-adjLsaCompare(AdjLsa& alsa1, AdjLsa& alsa2){
- return alsa1.getLsaKey()==alsa1.getLsaKey();
-}
-*/
+
static bool
adjLsaCompareByKey(AdjLsa& alsa, string& key){
return alsa.getAdjLsaKey()==key;
@@ -366,10 +392,9 @@
}
else
{
- //remove if there is any adj lsa in LSDB
string key=pnlsr.getConfParameter().getRouterPrefix()+"/2";
removeAdjLsa(pnlsr,key);
- // Remove alll fib entries as per NPT
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount);
}
@@ -378,7 +403,7 @@
{
pnlsr.setIsBuildAdjLsaSheduled(1);
int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()*
- pnlsr.getConfParameter().getInterestRetryNumber();
+ pnlsr.getConfParameter().getInterestResendTime();
pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
boost::ref(pnlsr)));
@@ -417,21 +442,34 @@
return std::make_pair(boost::ref(alsa),false);
}
+
+
+void
+Lsdb::scheduleAdjLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime)
+{
+ pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
+ ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
+ this,boost::ref(pnlsr),key,seqNo));
+}
+
bool
Lsdb::installAdjLsa(nlsr& pnlsr, AdjLsa &alsa)
{
+ int timeToExpire=lsaRefreshTime;
std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(alsa.getAdjLsaKey());
if ( !chkAdjLsa.second )
{
addAdjLsa(alsa);
alsa.addNptEntriesForAdjLsa(pnlsr);
- if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
+
+ if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
{
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate,
- &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
+ timeToExpire=alsa.getLifeTime();
}
+ scheduleAdjLsaExpiration(pnlsr,alsa.getAdjLsaKey(),
+ alsa.getLsSeqNo(),timeToExpire);
+
}
else
{
@@ -444,14 +482,15 @@
{
chkAdjLsa.first.getAdl().resetAdl();
chkAdjLsa.first.getAdl().addAdjacentsFromAdl(alsa.getAdl());
- if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
- {
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate,
- &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
- }
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
+
+ if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
+ {
+ timeToExpire=alsa.getLifeTime();
+ }
+ scheduleAdjLsaExpiration(pnlsr,alsa.getAdjLsaKey(),
+ alsa.getLsSeqNo(),timeToExpire);
}
}
@@ -510,6 +549,107 @@
return adjLsdb;
}
+void
+Lsdb::setLsaRefreshTime(int lrt)
+{
+ lsaRefreshTime=lrt;
+}
+
+void
+Lsdb::setThisRouterPrefix(string trp)
+{
+ thisRouterPrefix=trp;
+}
+
+void
+Lsdb::exprireOrRefreshNameLsa(nlsr& pnlsr, string lsaKey, int seqNo)
+{
+ cout<<"Lsdb::exprireOrRefreshNameLsa Called "<<endl;
+ cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
+ std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(lsaKey);
+ if( chkNameLsa.second )
+ {
+ cout<<" LSA Exists with seq no: "<<chkNameLsa.first.getLsSeqNo()<<endl;
+ if ( chkNameLsa.first.getLsSeqNo() == seqNo )
+ {
+ if(chkNameLsa.first.getOrigRouter() == thisRouterPrefix )
+ {
+ cout<<"Own Name LSA, so refreshing name LSA"<<endl;
+ chkNameLsa.first.setLsSeqNo(chkNameLsa.first.getLsSeqNo()+1);
+ pnlsr.getSm().setNameLsaSeq(chkNameLsa.first.getLsSeqNo());
+ // publish routing update
+ }
+ else
+ {
+ cout<<"Other's Name LSA, so removing form LSDB"<<endl;
+ removeNameLsa(pnlsr, lsaKey);
+ }
+ }
+ }
+}
+
+void
+Lsdb::exprireOrRefreshAdjLsa(nlsr& pnlsr, string lsaKey, int seqNo)
+{
+ cout<<"Lsdb::exprireOrRefreshAdjLsa Called "<<endl;
+ cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
+ std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(lsaKey);
+ if( chkAdjLsa.second )
+ {
+ cout<<" LSA Exists with seq no: "<<chkAdjLsa.first.getLsSeqNo()<<endl;
+ if ( chkAdjLsa.first.getLsSeqNo() == seqNo )
+ {
+ if(chkAdjLsa.first.getOrigRouter() == thisRouterPrefix )
+ {
+ cout<<"Own Adj LSA, so refreshing Adj LSA"<<endl;
+ chkAdjLsa.first.setLsSeqNo(chkAdjLsa.first.getLsSeqNo()+1);
+ pnlsr.getSm().setAdjLsaSeq(chkAdjLsa.first.getLsSeqNo());
+ // publish routing update
+ }
+ else
+ {
+ cout<<"Other's Adj LSA, so removing form LSDB"<<endl;
+ removeAdjLsa(pnlsr, lsaKey);
+ }
+
+ // schedule Routing table calculaiton
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
+ }
+ }
+}
+
+void
+Lsdb::exprireOrRefreshCorLsa(nlsr& pnlsr, string lsaKey, int seqNo)
+{
+ cout<<"Lsdb::exprireOrRefreshCorLsa Called "<<endl;
+ cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
+ std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(lsaKey);
+ if( chkCorLsa.second )
+ {
+ cout<<" LSA Exists with seq no: "<<chkCorLsa.first.getLsSeqNo()<<endl;
+ if ( chkCorLsa.first.getLsSeqNo() == seqNo )
+ {
+ if(chkCorLsa.first.getOrigRouter() == thisRouterPrefix )
+ {
+ cout<<"Own Cor LSA, so refreshing Cor LSA"<<endl;
+ chkCorLsa.first.setLsSeqNo(chkCorLsa.first.getLsSeqNo()+1);
+ pnlsr.getSm().setCorLsaSeq(chkCorLsa.first.getLsSeqNo());
+ // publish routing update
+ }
+ else
+ {
+ cout<<"Other's Cor LSA, so removing form LSDB"<<endl;
+ removeCorLsa(pnlsr, lsaKey);
+ }
+
+ if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
+ {
+ pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
+ }
+ }
+ }
+}
+
void
Lsdb::printAdjLsdb()
diff --git a/nlsr_lsdb.hpp b/nlsr_lsdb.hpp
index 9ba0729..62c91ee 100644
--- a/nlsr_lsdb.hpp
+++ b/nlsr_lsdb.hpp
@@ -11,6 +11,7 @@
class Lsdb{
public:
Lsdb()
+ : lsaRefreshTime(0)
{
}
@@ -38,6 +39,10 @@
std::pair<AdjLsa& , bool> getAdjLsa(string key);
std::list<AdjLsa>& getAdjLsdb();
void printAdjLsdb();
+
+ //void scheduleRefreshLsdb(nlsr& pnlsr, int interval);
+ void setLsaRefreshTime(int lrt);
+ void setThisRouterPrefix(string trp);
private:
bool addNameLsa(NameLsa &nlsa);
@@ -49,6 +54,13 @@
bool addAdjLsa(AdjLsa &alsa);
bool doesAdjLsaExist(string key);
+
+ void scheduleNameLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime);
+ void exprireOrRefreshNameLsa(nlsr& pnlsr, string lsaKey, int seqNo);
+ void scheduleAdjLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime);
+ void exprireOrRefreshAdjLsa(nlsr& pnlsr, string lsaKey, int seqNo);
+ void scheduleCorLsaExpiration(nlsr& pnlsr, string key, int seqNo, int expTime);
+ void exprireOrRefreshCorLsa(nlsr& pnlsr, string lsaKey, int seqNo);
private:
@@ -56,6 +68,9 @@
std::list<AdjLsa> adjLsdb;
std::list<CorLsa> corLsdb;
+ int lsaRefreshTime;
+ string thisRouterPrefix;
+
};
#endif
diff --git a/nlsr_rt.cpp b/nlsr_rt.cpp
index ae7fc88..efa423a 100644
--- a/nlsr_rt.cpp
+++ b/nlsr_rt.cpp
@@ -81,9 +81,7 @@
}
else
{
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
- ndn::bind(&RoutingTable::calculate,this,boost::ref(pnlsr)));
- pnlsr.setIsRouteCalculationScheduled(1);
+ scheduleRoutingTableCalculation(pnlsr);
}
}
@@ -121,6 +119,17 @@
hrtc.calculatePath(vMap,boost::ref(*this),pnlsr);
}
+void
+RoutingTable::scheduleRoutingTableCalculation(nlsr& pnlsr)
+{
+ if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
+ {
+ pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
+ ndn::bind(&RoutingTable::calculate,this,boost::ref(pnlsr)));
+ pnlsr.setIsRouteCalculationScheduled(1);
+ }
+}
+
static bool
routingTableEntryCompare(RoutingTableEntry& rte, string& destRouter){
return rte.getDestination()==destRouter;
diff --git a/nlsr_rt.hpp b/nlsr_rt.hpp
index 8585184..ef54742 100644
--- a/nlsr_rt.hpp
+++ b/nlsr_rt.hpp
@@ -26,6 +26,7 @@
void addNextHopToDryTable(string destRouter, NextHop& nh);
void printDryRoutingTable();
std::pair<RoutingTableEntry&, bool> findRoutingTableEntry(string destRouter);
+ void scheduleRoutingTableCalculation(nlsr& pnlsr);
private:
void calculateLsRoutingTable(nlsr& pnlsr);