Schedule Adj LSA build and installation
diff --git a/nlsr_lsdb.cpp b/nlsr_lsdb.cpp
index c6ae523..f62d12b 100644
--- a/nlsr_lsdb.cpp
+++ b/nlsr_lsdb.cpp
@@ -148,7 +148,7 @@
bool
Lsdb::buildAndInstallOwnCorLsa(nlsr& pnlsr){
CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
- , 1
+ , 3
, pnlsr.getCorLsaSeq()+1
, pnlsr.getConfParameter().getRouterDeadInterval()
, pnlsr.getConfParameter().getCorR()
@@ -248,7 +248,109 @@
}
+void
+Lsdb::scheduledAdjLsaBuild(nlsr& pnlsr)
+{
+ cout<<"scheduledAdjLsaBuild Called"<<endl;
+ pnlsr.setIsBuildAdjLsaSheduled(0);
+ if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr))
+ {
+ int adjBuildCount=pnlsr.getAdjBuildCount();
+ if(adjBuildCount>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<AdjLsa >::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<AdjLsa >::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 @@
return true;
}
+void
+Lsdb::printAdjLsdb()
+{
+ for( std::list<AdjLsa>::iterator it=adjLsdb.begin();
+ it!= adjLsdb.end() ; it++)
+ {
+ cout<< (*it) <<endl;
+ }
+}