Own Name LSA installation
diff --git a/nlsr.cpp b/nlsr.cpp
index 99552b0..194fbe9 100644
--- a/nlsr.cpp
+++ b/nlsr.cpp
@@ -7,6 +7,7 @@
#include "nlsr.hpp"
#include "nlsr_conf_param.hpp"
#include "nlsr_conf_processor.hpp"
+#include "nlsr_lsdb.hpp"
using namespace ndn;
@@ -58,10 +59,15 @@
ConfFileProcessor cfp(nlsr.getConfFileName());
cfp.processConfFile(nlsr);
nlsr.getConfParameter().buildRouterPrefix();
+
+ nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr);
+
+
/* debugging purpose start */
cout << nlsr.getConfParameter(); ;
nlsr.getAdl().printAdl();
nlsr.getNpl().printNpl();
+ nlsr.getLsdb().printNameLsdb();
/* debugging purpose end */
nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
nlsr.getIm().scheduleInfoInterest(nlsr,1);
diff --git a/nlsr.hpp b/nlsr.hpp
index a041738..c78caac 100644
--- a/nlsr.hpp
+++ b/nlsr.hpp
@@ -10,6 +10,7 @@
#include "nlsr_npl.hpp"
#include "nlsr_im.hpp"
#include "nlsr_dm.hpp"
+#include "nlsr_lsdb.hpp"
using namespace ndn;
@@ -28,11 +29,34 @@
, npl()
, im()
, dm()
+ , nlsrLsdb()
+ , nameLsaSeq(0)
+ , adjLsaSeq(0)
+ , corLsaSeq(0)
{
isDaemonProcess=false;
configFileName="nlsr.conf";
}
+ nlsr(string confFile, uint32_t nlsn, uint32_t alsn, uint32_t clsn)
+ : io(ndn::make_shared<boost::asio::io_service>())
+ , nlsrFace(io)
+ , scheduler(*io)
+ , configFileName()
+ , confParam()
+ , adl()
+ , npl()
+ , im()
+ , dm()
+ , nlsrLsdb()
+ {
+ isDaemonProcess=false;
+ configFileName=confFile;
+ nameLsaSeq=nlsn;
+ adjLsaSeq=alsn;
+ corLsaSeq=clsn;
+ }
+
void nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&);
void setInterestFilterNlsr(const string& name);
@@ -96,6 +120,37 @@
DataManager& getDm(){
return dm;
}
+
+ Lsdb& getLsdb(){
+ return nlsrLsdb;
+ }
+
+ uint32_t getNameLsaSeq()
+ {
+ return nameLsaSeq;
+ }
+
+ void setNameLsaSeq(uint32_t nlsn){
+ nameLsaSeq=nlsn;
+ }
+
+ uint32_t getAdjLsaSeq()
+ {
+ return adjLsaSeq;
+ }
+
+ void setAdjLsaSeq(uint32_t alsn){
+ adjLsaSeq=alsn;
+ }
+
+ uint32_t getCorLsaSeq()
+ {
+ return corLsaSeq;
+ }
+
+ void setCorLsaSeq(uint32_t clsn){
+ corLsaSeq=clsn;
+ }
private:
ConfParameter confParam;
@@ -109,6 +164,11 @@
DataManager dm;
bool isDaemonProcess;
string configFileName;
+ Lsdb nlsrLsdb;
+ uint32_t nameLsaSeq;
+ uint32_t adjLsaSeq;
+ uint32_t corLsaSeq;
+
};
diff --git a/nlsr_conf_param.hpp b/nlsr_conf_param.hpp
index f8290d2..ce56c72 100644
--- a/nlsr_conf_param.hpp
+++ b/nlsr_conf_param.hpp
@@ -94,7 +94,7 @@
routerDeadInterval=rdt;
}
- long int setRouterDeadInterval(){
+ long int getRouterDeadInterval(){
return routerDeadInterval;
}
diff --git a/nlsr_lsa.cpp b/nlsr_lsa.cpp
index b6ba605..dfc25e4 100644
--- a/nlsr_lsa.cpp
+++ b/nlsr_lsa.cpp
@@ -3,6 +3,7 @@
#include<algorithm>
#include "nlsr_lsa.hpp"
+#include "nlsr_npl.hpp"
using namespace std;
@@ -10,11 +11,26 @@
Lsa::getLsaKey()
{
string key;
- key=origRouter + "/" + boost::lexical_cast<std::string>(lsType) + "/"
- + boost::lexical_cast<std::string>(lsSeqNo);
+ key=origRouter + "/" + boost::lexical_cast<std::string>(lsType);
return key;
}
+NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl& npl)
+{
+ origRouter=origR;
+ lsType=lst;
+ lsSeqNo=lsn;
+ lifeTime=lt;
+
+ std::list<string> nl=npl.getNameList();
+ for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
+ {
+ addNameToLsa((*it));
+ }
+
+
+}
+
string
NameLsa::getNameLsaData()
{
@@ -35,3 +51,21 @@
return nameLsaData;
}
+std::ostream&
+operator<<(std::ostream& os, NameLsa& nLsa)
+{
+ os<<"Name Lsa: "<<endl;
+ os<<" Origination Router: "<<nLsa.getOrigRouter()<<endl;
+ os<<" Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl;
+ os<<" Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl;
+ os<<" Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl;
+ os<<" Names: "<<endl;
+ int i=1;
+ std::list<string> nl=nLsa.getNpl().getNameList();
+ for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
+ {
+ os<<" Name "<<i<<": "<<(*it)<<endl;
+ }
+
+ return os;
+}
diff --git a/nlsr_lsa.hpp b/nlsr_lsa.hpp
index 4c252e6..0dd00c6 100644
--- a/nlsr_lsa.hpp
+++ b/nlsr_lsa.hpp
@@ -64,7 +64,7 @@
uint32_t lifeTime;
};
-class NameLsa:Lsa{
+class NameLsa:public Lsa{
public:
NameLsa()
: Lsa()
@@ -73,6 +73,7 @@
setLsType(1);
}
+ NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl& npl);
Npl& getNpl(){
return npl;
@@ -90,7 +91,10 @@
};
-class AdjLsa:Lsa{
+std::ostream&
+operator<<(std::ostream& os, NameLsa& nLsa);
+
+class AdjLsa: public Lsa{
public:
AdjLsa()
: Lsa()
@@ -103,7 +107,7 @@
Adl adl;
};
-class CorLsa:Lsa{
+class CorLsa:public Lsa{
public:
CorLsa()
:Lsa()
diff --git a/nlsr_lsdb.cpp b/nlsr_lsdb.cpp
new file mode 100644
index 0000000..a82c8a3
--- /dev/null
+++ b/nlsr_lsdb.cpp
@@ -0,0 +1,145 @@
+#include<string>
+#include "nlsr_lsdb.hpp"
+#include "nlsr.hpp"
+
+using namespace std;
+
+
+
+
+
+bool
+Lsdb::doesLsaExist(string key, int lsType)
+{
+ if ( lsType == 1)
+ {
+ return doesNameLsaExist(key);
+ }
+ else if ( lsType == 2)
+ {
+ return doesAdjLsaExist(key);
+ }
+ else if ( lsType == 3)
+ {
+ return doesCorLsaExist(key);
+ }
+
+ return false;
+
+}
+
+static bool
+nameLsaCompare(NameLsa& nlsa1, NameLsa& nlsa2){
+ return nlsa1.getLsaKey()==nlsa1.getLsaKey();
+}
+
+static bool
+nameLsaCompareByKey(NameLsa& nlsa1, string& key){
+ return nlsa1.getLsaKey()==key;
+}
+
+
+bool
+Lsdb::buildAndInstallOwnNameLsa(nlsr& pnlsr)
+{
+ NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix()
+ , 1
+ , pnlsr.getNameLsaSeq()+1
+ , pnlsr.getConfParameter().getRouterDeadInterval()
+ , pnlsr.getNpl() );
+ pnlsr.setNameLsaSeq(pnlsr.getNameLsaSeq()+1);
+ cout<<nameLsa;
+ return installNameLsa(nameLsa);
+
+}
+
+NameLsa&
+Lsdb::getNameLsa(string key)
+{
+ std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
+ nameLsdb.end(),
+ bind(nameLsaCompareByKey, _1, key));
+
+ if( it != nameLsdb.end()){
+ return (*it);
+ }
+}
+
+
+
+bool
+Lsdb::installNameLsa(NameLsa &nlsa)
+{
+ bool doesLsaExist_ = doesNameLsaExist(nlsa.getLsaKey());
+ if ( !doesLsaExist_ )
+ {
+ // add name LSA
+ addNameLsa(nlsa);
+ // update NPT and FIB
+ }
+ else
+ {
+ // check for newer name LSA
+ NameLsa oldNameLsa=getNameLsa(nlsa.getLsaKey());
+ // Discard or Update Name lsa, NPT, FIB
+ }
+
+ return true;
+}
+
+bool
+Lsdb::addNameLsa(NameLsa &nlsa)
+{
+ std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
+ nameLsdb.end(),
+ bind(nameLsaCompare, _1, nlsa));
+
+ if( it == nameLsdb.end()){
+ nameLsdb.push_back(nlsa);
+ return true;
+ }
+ return false;
+}
+
+bool
+Lsdb::removeNameLsa(string& key)
+{
+ return false;
+}
+
+void
+Lsdb::printNameLsdb()
+{
+ for( std::list<NameLsa>::iterator it=nameLsdb.begin();
+ it!= nameLsdb.end() ; it++)
+ {
+ cout<< (*it) <<endl;
+ }
+}
+
+bool
+Lsdb::doesNameLsaExist(string key)
+{
+ std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
+ nameLsdb.end(),
+ bind(nameLsaCompareByKey, _1, key));
+
+ if( it == nameLsdb.end()){
+ return false;
+ }
+
+ return true;
+}
+
+
+bool
+Lsdb::doesAdjLsaExist(string key)
+{
+ return false;
+}
+
+bool
+Lsdb::doesCorLsaExist(string key)
+{
+ return false;
+}
diff --git a/nlsr_lsdb.hpp b/nlsr_lsdb.hpp
new file mode 100644
index 0000000..4c37fb0
--- /dev/null
+++ b/nlsr_lsdb.hpp
@@ -0,0 +1,45 @@
+#ifndef NLSR_LSDB_HPP
+#define NLSR_LSDB_HPP
+
+#include "nlsr_lsa.hpp"
+
+using namespace std;
+
+class nlsr;
+
+class Lsdb{
+public:
+ Lsdb()
+ {
+ }
+
+
+ bool doesLsaExist(string key, int lsType);
+ // function related to Name LSDB
+ bool buildAndInstallOwnNameLsa(nlsr& nlsr);
+ NameLsa& getNameLsa(string key);
+ bool installNameLsa(NameLsa &nlsa);
+ bool removeNameLsa(string& key);
+ void printNameLsdb(); //debugging
+
+ //function related to Cor LSDB
+ bool buildAndInstallOwnCorLsa(nlsr& nlsr);
+ CorLsa& getCorLsa(string key);
+ bool installCorLsa(CorLsa &nlsa);
+ bool removeCorLsa(string& key);
+ void printCorLsdb(); //debugging
+
+private:
+ bool addNameLsa(NameLsa &nlsa);
+ bool doesNameLsaExist(string key);
+ bool doesAdjLsaExist(string key);
+ bool doesCorLsaExist(string key);
+
+private:
+ std::list<NameLsa> nameLsdb;
+ std::list<AdjLsa> adjLsdb;
+ std::list<CorLsa> corLsdb;
+
+};
+
+#endif
diff --git a/nlsr_npl.cpp b/nlsr_npl.cpp
index 1f9ae3d..251c647 100644
--- a/nlsr_npl.cpp
+++ b/nlsr_npl.cpp
@@ -35,7 +35,9 @@
void
Npl::printNpl(){
+ int i=1;
for( std::list<string>::iterator it=nameList.begin(); it != nameList.end(); it++){
- cout<<"Name : "<<(*it)<<endl;
+ cout<<"Name "<<i<<" : "<<(*it)<<endl;
+ i++;
}
}