LSA refreshing/Expiration, Fib Refreshing Added
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);
}
}