First commit:CPP
diff --git a/adjacent.cpp b/adjacent.cpp
new file mode 100644
index 0000000..8f7fa6d
--- /dev/null
+++ b/adjacent.cpp
@@ -0,0 +1,24 @@
+#include<iostream>
+#include<string>
+
+#include "adjacent.hpp"
+
+using namespace std;
+
+Adjacent::Adjacent(const string& an, int cf, double lc, int s, int iton){
+ adjacentName=an;
+ connectingFace=cf;
+ linkCost=lc;
+ status=s;
+ interestTimedOutNo=iton;
+}
+
+std::ostream&
+operator << (std::ostream &os, Adjacent &adj){
+ cout<<"Adjacent : "<< adj.getAdjacentName() << endl;
+ cout<<"Connecting Face: "<<adj.getConnectingFace()<<endl;
+ cout<<"Link Cost: "<<adj.getLinkCost()<<endl;
+ cout<<"Status: "<<adj.getStatus()<<endl;
+ cout<<"Interest Timed out: "<<adj.getInterestTimedOutNo()<<endl;
+ return os;
+}
diff --git a/adjacent.hpp b/adjacent.hpp
new file mode 100644
index 0000000..09eef16
--- /dev/null
+++ b/adjacent.hpp
@@ -0,0 +1,79 @@
+#ifndef ADJACENT_HPP
+#define ADJACENT_HPP
+
+using namespace std;
+
+class Adjacent{
+
+ public:
+ Adjacent()
+ :adjacentName()
+ ,connectingFace(0)
+ ,linkCost(0.0)
+ ,status(0)
+ ,interestTimedOutNo(0)
+ {
+ }
+
+ Adjacent(const string& an)
+ :connectingFace(0)
+ ,linkCost(0.0)
+ ,status(0)
+ ,interestTimedOutNo(0)
+ {
+ adjacentName=an;
+ }
+
+ Adjacent(const string& an, int cf, double lc, int s, int iton);
+
+ string getAdjacentName(){
+ return adjacentName;
+ }
+
+ void setAdjacentName(const string& an){
+ adjacentName=an;
+ }
+
+ int getConnectingFace(){
+ return connectingFace;
+ }
+
+ void getConnectingFace(int cf){
+ connectingFace=cf;
+ }
+
+ double getLinkCost(){
+ return linkCost;
+ }
+
+ void setLinkCost(double lc){
+ linkCost=lc;
+ }
+
+ int getStatus(){
+ return status;
+ }
+
+ void setStatus(int s){
+ status=s;
+ }
+
+ int getInterestTimedOutNo(){
+ return interestTimedOutNo;
+ }
+
+ void setInterestTimedOutNo(int iton){
+ interestTimedOutNo=iton;
+ }
+ private:
+ string adjacentName;
+ int connectingFace;
+ double linkCost;
+ int status;
+ int interestTimedOutNo;
+};
+
+std::ostream&
+operator << (std::ostream &os, Adjacent &adj);
+
+#endif
diff --git a/adl.cpp b/adl.cpp
new file mode 100644
index 0000000..f8969e1
--- /dev/null
+++ b/adl.cpp
@@ -0,0 +1,76 @@
+#include<iostream>
+#include<algorithm>
+
+#include "adl.hpp"
+#include "adjacent.hpp"
+
+Adl::Adl(){
+}
+
+Adl::~Adl(){
+
+}
+
+static bool
+adjacent_compare(Adjacent& adj1, Adjacent& adj2){
+ return adj1.getAdjacentName()==adj2.getAdjacentName();
+}
+
+int
+Adl::insert(Adjacent& adj){
+ std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
+ adjList.end(),
+ bind(&adjacent_compare, _1, adj));
+ if ( it != adjList.end() ){
+ return -1;
+ }
+ adjList.push_back(adj);
+ return 0;
+}
+int
+Adl::updateAdjacentStatus(string adjName, int s){
+ Adjacent adj(adjName);
+
+ std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
+ adjList.end(),
+ bind(&adjacent_compare, _1, adj));
+
+ if( it == adjList.end()){
+ return -1;
+ }
+
+ (*it).setStatus(s);
+ return 0;
+
+
+}
+
+int
+Adl::updateAdjacentLinkCost(string adjName, double lc){
+ Adjacent adj(adjName);
+
+ std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
+ adjList.end(),
+ bind(&adjacent_compare, _1, adj));
+
+ if( it == adjList.end()){
+ return -1;
+ }
+
+ (*it).setLinkCost(lc);
+ return 0;
+
+}
+
+std::list<Adjacent>
+Adl::getAdjList(){
+ return adjList;
+}
+
+// used for debugging purpose
+void
+Adl::printAdl(){
+ for( std::list<Adjacent>::iterator it=adjList.begin(); it!= adjList.end() ; it++){
+ cout<< (*it) <<endl;
+ }
+}
diff --git a/adl.hpp b/adl.hpp
new file mode 100644
index 0000000..1547407
--- /dev/null
+++ b/adl.hpp
@@ -0,0 +1,26 @@
+#ifndef ADL_HPP
+#define ADL_HPP
+
+#include <ndn-cpp-dev/face.hpp>
+#include "adjacent.hpp"
+#include<list>
+
+using namespace std;
+
+class Adl{
+
+public:
+ Adl();
+ ~Adl();
+ int insert(Adjacent& adj);
+ int updateAdjacentStatus(string adjName, int s);
+ int updateAdjacentLinkCost(string adjName, double lc);
+ void printAdl();
+ std::list<Adjacent> getAdjList();
+
+
+private:
+ std::list< Adjacent > adjList;
+};
+
+#endif
diff --git a/conf_param.cpp b/conf_param.cpp
new file mode 100644
index 0000000..14696e3
--- /dev/null
+++ b/conf_param.cpp
@@ -0,0 +1,33 @@
+#include<iostream>
+#include "conf_param.hpp"
+
+using namespace std;
+
+ostream&
+operator << (ostream &os, ConfParameter& cfp){
+ os <<"Router Name: "<< cfp.getRouterName()<<endl;
+ os <<"Site Name: "<< cfp.getSiteName()<<endl;
+ os <<"Network: "<< cfp.getNetwork()<<endl;
+
+ os <<"Router Prefix: "<< cfp.getRouterPrefix()<<endl;
+
+ os <<"ChronoSync sync Prifex: "<< cfp.getChronosyncSyncPrefix()<<endl;
+
+ os <<"Interest Retry number: "<< cfp.getInterestRetryNumber()<<endl;
+ os <<"Interest Resend second: "<< cfp.getInterestResendTime()<<endl;
+ os <<"Info Interest Interval: "<<cfp.getInfoInterestInterval()<<endl;
+ os <<"LSA refresh time: "<< cfp.getLsaRefreshTime()<<endl;
+
+ os <<"Max Faces Per Prefix: "<< cfp.getMaxFacesPerPrefix()<<endl;
+ os <<"Log Dir: "<< cfp.getLogDir()<<endl;
+ os <<"Detalied logging: "<< cfp.getDetailedLogging()<<endl;
+ os <<"Debugging: "<< cfp.getDebugging()<<endl;
+
+ os <<"Hyperbolic ROuting: "<< cfp.getIsHyperbolicCalc()<<endl;
+ os <<"Hyp R: "<< cfp.getCorR()<<endl;
+ os <<"Hyp theta: "<< cfp.getCorTheta()<<endl;
+
+ os <<"Tunnel Type: "<< cfp.getTunnelType()<<endl;
+
+ return os;
+}
diff --git a/conf_param.hpp b/conf_param.hpp
new file mode 100644
index 0000000..69d2eff
--- /dev/null
+++ b/conf_param.hpp
@@ -0,0 +1,225 @@
+#ifndef CONF_PARAM_HPP
+#define CONF_PARAM_HPP
+
+#include<iostream>
+
+using namespace std;
+
+class ConfParameter{
+
+ public:
+ ConfParameter()
+ :chronosyncSyncPrefix("ndn/nlsr/sync")
+ ,chronosyncLsaPrefix("/ndn/nlsr/LSA")
+ {
+ adjBuildFlag=0;
+ adjBuildCount=0;
+ isBuildAdjLsaSheduled=0;
+ isRouteCalculationScheduled=0;
+ isRoutingTableCalculating=0;
+ isStrictHierchicalKeyCheck=0;
+
+ interestRetryNumber=3;
+ interestResendTime=5;
+ infoInterestInterval=60;
+ lsaRefreshTime=1800;
+ routerDeadInterval=3600;
+ maxFacesPerPrefix=0;
+ tunnelType=0;
+ detailedLogging=0;
+ debugging=0;
+ isHyperbolicCalc=0;
+
+
+ }
+
+ void setRouterName(const string& rn){
+ routerName=rn;
+ }
+
+ string getRouterName(){
+ return routerName;
+ }
+
+ void setSiteName(const string& sn){
+ siteName=sn;
+ }
+
+ string getSiteName(){
+ return siteName;
+ }
+
+ void setNetwork(const string& nn){
+ network=nn;
+ }
+
+ string getNetwork(){
+ return network;
+ }
+
+ void buildRouterPrefix(){
+ routerPrefix="/"+network+"/"+siteName+"/"+routerName;
+ }
+
+ string getRouterPrefix(){
+ return routerPrefix;
+ }
+
+ void setInterestRetryNumber(int irn){
+ interestRetryNumber=irn;
+ }
+
+ int getInterestRetryNumber(){
+ return interestRetryNumber;
+ }
+
+ void setInterestResendTime(int irt){
+ interestResendTime=irt;
+ }
+
+ int getInterestResendTime(){
+ return interestResendTime;
+ }
+
+ void setLsaRefreshTime(int lrt){
+ lsaRefreshTime=lrt;
+ routerDeadInterval=2*lsaRefreshTime;
+ }
+
+ int getLsaRefreshTime(){
+ return lsaRefreshTime;
+ }
+
+ void setRouterDeadInterval(int rdt){
+ routerDeadInterval=rdt;
+ }
+
+ long int setRouterDeadInterval(){
+ return routerDeadInterval;
+ }
+
+ void setMaxFacesPerPrefix(int mfpp){
+ maxFacesPerPrefix=mfpp;
+ }
+
+ int getMaxFacesPerPrefix(){
+ return maxFacesPerPrefix;
+ }
+
+ void setLogDir(string ld){
+ logDir=ld;
+ }
+
+ string getLogDir(){
+ return logDir;
+ }
+
+ void setDetailedLogging(int dl){
+ detailedLogging=dl;
+ }
+
+ int getDetailedLogging(){
+ return detailedLogging;
+ }
+
+ void setDebugging(int d){
+ debugging=d;
+ }
+
+ int getDebugging(){
+ return debugging;
+ }
+
+ void setIsHyperbolicCalc(int ihc){
+ isHyperbolicCalc=ihc;
+ }
+
+ int getIsHyperbolicCalc(){
+ return isHyperbolicCalc;
+ }
+
+ void setCorR(double cr){
+ corR=cr;
+ }
+
+ double getCorR(){
+ return corR;
+ }
+
+ void setCorTheta(double ct){
+ corTheta=ct;
+ }
+
+ double getCorTheta(){
+ return corTheta;
+ }
+
+ void setTunnelType(int tt){
+ tunnelType=tt;
+ }
+
+ int getTunnelType(){
+ return tunnelType;
+ }
+
+ void setChronosyncSyncPrefix(const string& csp){
+ chronosyncSyncPrefix=csp;
+ }
+
+ string getChronosyncSyncPrefix(){
+ return chronosyncSyncPrefix;
+ }
+
+ int getInfoInterestInterval(){
+ return infoInterestInterval;
+ }
+
+ void setInfoInterestInterval(int iii){
+ infoInterestInterval=iii;
+ }
+
+ private:
+ string routerName;
+ string siteName;
+ string network;
+
+ string routerPrefix;
+ string lsaRouterPrefix;
+
+ string chronosyncSyncPrefix;
+ string chronosyncLsaPrefix;
+
+ int interestRetryNumber;
+ int interestResendTime;
+ int infoInterestInterval;
+ int lsaRefreshTime;
+ int routerDeadInterval;
+
+ int maxFacesPerPrefix;
+ string logDir;
+ string logFile;
+ int detailedLogging;
+ int debugging;
+
+ int isHyperbolicCalc;
+ double corR;
+ double corTheta;
+
+ int tunnelType;
+
+ int adjBuildFlag;
+ long int adjBuildCount;
+ int isBuildAdjLsaSheduled;
+ int isRouteCalculationScheduled;
+
+ int isRoutingTableCalculating;
+ int isStrictHierchicalKeyCheck;
+
+
+
+};
+
+std::ostream&
+operator << (std::ostream &os, ConfParameter &cfp);
+
+#endif
diff --git a/conf_processor.cpp b/conf_processor.cpp
new file mode 100644
index 0000000..e3be824
--- /dev/null
+++ b/conf_processor.cpp
@@ -0,0 +1,367 @@
+#include<iostream>
+#include<fstream>
+#include<string>
+#include<cstdlib>
+#include <sstream>
+
+#include "conf_processor.hpp"
+#include "conf_param.hpp"
+#include "nlsr_tokenizer.hpp"
+#include "adjacent.hpp"
+
+
+using namespace std;
+
+int
+ConfFileProcessor::processConfFile(nlsr& pnlsr){
+ int ret=0;
+
+ if ( !confFileName.empty()){
+ std::ifstream inputFile(confFileName.c_str());
+ for( string line; getline( inputFile, line ); ){
+ if (!line.empty() ){
+ if(line[0]!= '#' && line[0]!='!'){
+ ret=processConfCommand(pnlsr, line);
+ if( ret == -1 ){
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return ret;
+}
+
+
+int
+ConfFileProcessor::processConfCommand(nlsr& pnlsr, string command){
+ int ret=0;
+ nlsrTokenizer nt(command," ");
+ if( (nt.getFirstToken() == "network")){
+ ret=processConfCommandNetwork(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "site-name")){
+ ret=processConfCommandSiteName(pnlsr,nt.getRestOfLine());
+ }
+ else if ( (nt.getFirstToken() == "router-name")){
+ ret=processConfCommandRouterName(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "ndnneighbor") ){
+ ret=processConfCommandNdnNeighbor(pnlsr, nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "link-cost")){
+ ret=processConfCommandLinkCost(pnlsr, nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "ndnname") ){
+ ret=processConfCommandNdnName(pnlsr, nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "interest-retry-num")){
+ processConfCommandInterestRetryNumber(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "interest-resend-time")){
+ processConfCommandInterestResendTime(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "lsa-refresh-time")){
+ processConfCommandLsaRefreshTime(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "max-faces-per-prefix")){
+ processConfCommandMaxFacesPerPrefix(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "logdir")){
+ processConfCommandLogDir(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "detailed-logging") ){
+ processConfCommandDetailedLogging(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "debugging") ){
+ processConfCommandDebugging(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "chronosync-sync-prefix") ){
+ processConfCommandChronosyncSyncPrefix(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "hyperbolic-cordinate") ){
+ processConfCommandHyperbolicCordinate(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "hyperbolic-routing")){
+ processConfCommandIsHyperbolicCalc(pnlsr,nt.getRestOfLine());
+ }
+ else if( (nt.getFirstToken() == "tunnel-type")){
+ processConfCommandTunnelType(pnlsr,nt.getRestOfLine());
+ }
+ else {
+ cout << "Wrong configuration Command: "<< nt.getFirstToken()<<endl;
+ }
+
+ return ret;
+}
+
+int
+ConfFileProcessor::processConfCommandNetwork(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Network can not be null or empty :( !"<<endl;
+ return -1;
+ }else{
+ if(command[command.size()-1] == '/' ){
+ command.erase(command.size() - 1);
+ }
+ if(command[0] == '/' ){
+ command.erase(0,1);
+ }
+ pnlsr.confParam.setNetwork(command);
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandSiteName(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<"Site name can not be null or empty :( !"<<endl;
+ return -1;
+ }else{
+ if(command[command.size()-1] == '/' ){
+ command.erase(command.size() - 1);
+ }
+ if(command[0] == '/' ){
+ command.erase(0,1);
+ }
+ pnlsr.confParam.setSiteName(command);
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandRouterName(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Router name can not be null or empty :( !"<<endl;
+ return -1;
+ }else{
+ if(command[command.size()-1] == '/' ){
+ command.erase(command.size() - 1);
+ }
+ if(command[0] == '/' ){
+ command.erase(0,1);
+ }
+ pnlsr.confParam.setRouterName(command);
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandInterestRetryNumber(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [interest-retry-num n]"<<endl;
+ }else{
+ int irn;
+ stringstream ss(command.c_str());
+ ss>>irn;
+ if ( irn >=1 && irn <=5){
+ pnlsr.confParam.setInterestRetryNumber(irn);
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandInterestResendTime(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [interest-resend-time s]"<<endl;
+ }else{
+ int irt;
+ stringstream ss(command.c_str());
+ ss>>irt;
+ if( irt>=1 && irt <=20){
+ pnlsr.confParam.setInterestResendTime(irt);
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandLsaRefreshTime(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [interest-resend-time s]"<<endl;
+ }else{
+ int lrt;
+ stringstream ss(command.c_str());
+ ss>>lrt;
+ if ( lrt>= 240 && lrt<=7200){
+ pnlsr.confParam.setLsaRefreshTime(lrt);
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandMaxFacesPerPrefix(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [max-faces-per-prefix n]"<<endl;
+ }else{
+ int mfpp;
+ stringstream ss(command.c_str());
+ ss>>mfpp;
+ if ( mfpp>=0 && mfpp<=60){
+ pnlsr.confParam.setMaxFacesPerPrefix(mfpp);
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandTunnelType(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [tunnel-type tcp/udp]!"<<endl;
+ }else{
+ if(command == "tcp" || command == "TCP" ){
+ pnlsr.confParam.setTunnelType(1);
+ }
+ else if(command == "udp" || command == "UDP"){
+ pnlsr.confParam.setTunnelType(0);
+ }else{
+ cerr <<" Wrong command format ! [tunnel-type tcp/udp]!"<<endl;
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandChronosyncSyncPrefix(nlsr& pnlsr,
+ string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [chronosync-sync-prefix name/prefix]!"<<endl;
+ }else{
+ pnlsr.confParam.setChronosyncSyncPrefix(command);
+ }
+ return 0;
+}
+
+
+int
+ConfFileProcessor::processConfCommandLogDir(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [log-dir /path/to/log/dir]!"<<endl;
+ }else{
+ pnlsr.confParam.setLogDir(command);
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandDebugging(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [debugging on/of]!"<<endl;
+ }else{
+ if(command == "on" || command == "ON" ){
+ pnlsr.confParam.setDebugging(1);
+ }
+ else if(command == "off" || command == "off"){
+ pnlsr.confParam.setDebugging(0);
+ }else{
+ cerr <<" Wrong command format ! [debugging on/off]!"<<endl;
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandDetailedLogging(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [detailed-logging on/off]!"<<endl;
+ }else{
+ if(command == "on" || command == "ON" ){
+ pnlsr.confParam.setDetailedLogging(1);
+ }
+ else if(command == "off" || command == "off"){
+ pnlsr.confParam.setDetailedLogging(0);
+ }else{
+ cerr <<" Wrong command format ! [detailed-logging on/off]!"<<endl;
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandIsHyperbolicCalc(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [hyperbolic-routing on/off/dry-run]!"<<endl;
+ }else{
+ if(command == "on" || command == "ON" ){
+ pnlsr.confParam.setIsHyperbolicCalc(1);
+ }
+ else if(command == "dry-run" || command == "DRY-RUN"){
+ pnlsr.confParam.setIsHyperbolicCalc(2);
+ }
+ else if(command == "off" || command == "off"){
+ pnlsr.confParam.setIsHyperbolicCalc(0);
+ }else{
+ cerr <<" Wrong command format ! [hyperbolic-routing on/off/dry-run]!"<<endl;
+ }
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandHyperbolicCordinate(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [hyperbolic-cordinate r 0]!"<<endl;
+ if (pnlsr.confParam.getIsHyperbolicCalc() > 0 ){
+ return -1;
+ }
+ }else{
+ nlsrTokenizer nt(command," ");
+ stringstream ssr(nt.getFirstToken().c_str());
+ stringstream sst(nt.getRestOfLine().c_str());
+
+ double r,theta;
+ ssr>>r;
+ sst>>theta;
+
+ pnlsr.confParam.setCorR(r);
+ pnlsr.confParam.setCorTheta(theta);
+ }
+ return 0;
+}
+
+
+int
+ConfFileProcessor::processConfCommandNdnNeighbor(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [ndnneighbor /nbr/name/]!"<<endl;
+ }else{
+ nlsrTokenizer nt(command," ");
+ Adjacent adj(nt.getFirstToken(),0,0.0,0,0);
+ pnlsr.adl.insert(adj);
+ }
+ return 0;
+}
+
+int
+ConfFileProcessor::processConfCommandNdnName(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [ndnname name/prefix]!"<<endl;
+ }else{
+ pnlsr.npl.insertIntoNpl(command);
+ }
+ return 0;
+}
+
+
+int
+ConfFileProcessor::processConfCommandLinkCost(nlsr& pnlsr, string command){
+ if(command.empty() ){
+ cerr <<" Wrong command format ! [link-cost nbr/name cost]!"<<endl;
+ if (pnlsr.confParam.getIsHyperbolicCalc() > 0 ){
+ return -1;
+ }
+ }else{
+ nlsrTokenizer nt(command," ");
+ stringstream sst(nt.getRestOfLine().c_str());
+
+ double cost;
+ sst>>cost;
+
+ pnlsr.adl.updateAdjacentLinkCost(nt.getFirstToken(),cost);
+ }
+ return 0;
+}
+
diff --git a/conf_processor.hpp b/conf_processor.hpp
new file mode 100644
index 0000000..1a1ff8a
--- /dev/null
+++ b/conf_processor.hpp
@@ -0,0 +1,46 @@
+#ifndef CONF_PROCESSOR_HPP
+#define CONF_PROCESSOR_HPP
+
+#include "nlsr.hpp"
+
+using namespace std;
+
+class ConfFileProcessor{
+ public:
+ ConfFileProcessor()
+ :confFileName()
+ {
+ }
+ ConfFileProcessor(const string& cfile){
+ confFileName=cfile;
+ }
+
+ int processConfFile(nlsr& pnlsr);
+ int processConfCommand(nlsr& pnlsr, string command);
+ int processConfCommandNetwork(nlsr& pnlsr, string command);
+ int processConfCommandSiteName(nlsr& pnlsr, string command);
+ int processConfCommandRouterName(nlsr& pnlsr, string command);
+ int processConfCommandInterestRetryNumber(nlsr& pnlsr, string command);
+ int processConfCommandInterestResendTime(nlsr& pnlsr, string command);
+ int processConfCommandLsaRefreshTime(nlsr& pnlsr, string command);
+ int processConfCommandMaxFacesPerPrefix(nlsr& pnlsr, string command);
+ int processConfCommandTunnelType(nlsr& pnlsr, string command);
+
+ int processConfCommandChronosyncSyncPrefix(nlsr& pnlsr, string command);
+ int processConfCommandLogDir(nlsr& pnlsr, string command);
+ int processConfCommandDebugging(nlsr& pnlsr, string command);
+ int processConfCommandDetailedLogging(nlsr& pnlsr, string command);
+ int processConfCommandIsHyperbolicCalc(nlsr& pnlsr, string command);
+
+ int processConfCommandHyperbolicCordinate(nlsr& pnlsr, string command);
+
+ int processConfCommandNdnNeighbor(nlsr& pnlsr, string command);
+ int processConfCommandNdnName(nlsr& pnlsr, string command);
+ int processConfCommandLinkCost(nlsr& pnlsr, string command);
+
+
+ private:
+ string confFileName;
+};
+
+#endif
diff --git a/nlsr.cpp b/nlsr.cpp
new file mode 100644
index 0000000..248382e
--- /dev/null
+++ b/nlsr.cpp
@@ -0,0 +1,155 @@
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/key-chain.hpp>
+#include <ndn-cpp-dev/util/scheduler.hpp>
+
+#include <cstdlib>
+
+#include "nlsr.hpp"
+#include "conf_processor.hpp"
+#include "conf_param.hpp"
+#include "nlsr_tokenizer.hpp"
+#include "adl.hpp"
+#include "adjacent.hpp"
+
+
+using namespace ndn;
+using namespace std;
+
+void
+nlsr::processInterest(const ptr_lib::shared_ptr<const Name> &name,
+ const ptr_lib::shared_ptr<const Interest> &interest)
+{
+
+ cout << "<< I: " << *interest << endl;
+
+ Data data(ndn::Name(interest->getName()).append("testApp").appendVersion());
+ data.setFreshnessPeriod(1000); // 10 sec
+
+ data.setContent((const uint8_t*)"HELLO KITTY", sizeof("HELLO KITTY"));
+
+ kChain.sign(data);
+
+ cout << ">> D: " << data << endl;
+ nlsrFace.put(data);
+}
+
+void
+nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&)
+{
+ cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
+ nlsrFace.shutdown();
+}
+
+void
+nlsr::processContent(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
+ const ndn::ptr_lib::shared_ptr<ndn::Data> &data)
+{
+
+ cout << "I: " << interest->toUri() << endl;
+ cout << "D: " << data->getName().toUri() << endl;
+ cout << "Data Content: " << data->getContent() << endl;
+
+}
+
+void
+nlsr::processInterestTimedOut(
+ const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest)
+{
+ cout << "Timed out interest : " << interest->getName().toUri() << endl;
+ string intName= interest->getName().toUri();
+ cout << intName <<endl;
+ nlsrTokenizer nt(intName,"/");
+ string chkString("info");
+ if( nt.doesTokenExist(chkString) ){
+ string nbr=nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
+ cout<<"Neighbor :"<<nbr<<endl;
+ }
+
+}
+
+void
+nlsr::setInterestFilterNlsr(const string& name){
+ nlsrFace.setInterestFilter(name,
+ func_lib::bind(&nlsr::processInterest, this, _1, _2),
+ func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
+}
+
+void
+nlsr::expressInterest(const string& interestNamePrefix, int scope, int seconds)
+{
+ Interest i((ndn::Name(interestNamePrefix)));
+ //i.setScope(scope);
+ i.setInterestLifetime(seconds*1000);
+ i.setMustBeFresh(true);
+
+ nlsrFace.expressInterest(i,
+ ndn::func_lib::bind(&nlsr::processContent, this, _1, _2),
+ ndn::func_lib::bind(&nlsr::processInterestTimedOut, this, _1));
+
+}
+
+
+void
+nlsr::scheduleInfoInterest(int seconds){
+ scheduler.scheduleEvent(ndn::time::seconds(seconds),
+ ndn::bind(&nlsr::sendScheduledInfoInterest, this,seconds));
+}
+
+void
+nlsr::sendScheduledInfoInterest(int seconds){
+
+ std::list<Adjacent> adjList=adl.getAdjList();
+ for(std::list<Adjacent>::iterator it =adjList.begin(); it!= adjList.end(); ++it){
+ string adjName=(*it).getAdjacentName()+"/"+"info"+confParam.getRouterPrefix();
+ expressInterest( adjName,2,confParam.getInterestResendTime());
+ }
+
+ scheduleInfoInterest(confParam.getInfoInterestInterval());
+}
+
+void
+nlsr::startEventLoop(){
+ nlsrFace.processEvents();
+}
+
+int
+nlsr::usage(const string& progname){
+
+ cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
+ cout << " NDN routing...." << endl;
+ cout << " -d, --daemon Run in daemon mode" << endl;
+ cout << " -f, --config_file Specify configuration file name" <<endl;
+ cout << " -p, --api_port port where api client will connect" <<endl;
+ cout << " -h, --help Display this help message" << endl;
+
+ exit(EXIT_FAILURE);
+}
+
+int
+main(){
+
+ nlsr nlsr;
+ nlsr.setConfFileName("nlsr.conf");
+ ConfFileProcessor cfp(nlsr.getConfFileName());
+ cfp.processConfFile(nlsr);
+ nlsr.confParam.buildRouterPrefix();
+/* debugging purpose start */
+ cout << nlsr.confParam ;
+ nlsr.adl.printAdl();
+ nlsr.npl.printNpl();
+/* debugging purpose end */
+ nlsr.setInterestFilterNlsr("/ndn/memphis.edu/cs/pollux/");
+
+ nlsr.scheduleInfoInterest(1);
+
+
+
+
+ try{
+ nlsr.startEventLoop();
+ }catch(std::exception &e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
+
+ return 0;
+}
diff --git a/nlsr.hpp b/nlsr.hpp
new file mode 100644
index 0000000..c9f1032
--- /dev/null
+++ b/nlsr.hpp
@@ -0,0 +1,81 @@
+#ifndef NLSR_HPP
+#define NLSR_HPP
+
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/key-chain.hpp>
+#include <ndn-cpp-dev/util/scheduler.hpp>
+
+#include "conf_param.hpp"
+#include "adl.hpp"
+#include "npl.hpp"
+
+
+using namespace ndn;
+using namespace std;
+
+class nlsr
+{
+ public:
+ nlsr()
+ : io(ndn::make_shared<boost::asio::io_service>())
+ , nlsrFace(io)
+ , scheduler(*io)
+ , configFileName()
+ , confParam()
+ , adl()
+ , npl()
+ {
+ isDaemonProcess=false;
+ configFileName="nlsr.conf";
+ }
+
+ void processInterest(const ptr_lib::shared_ptr<const Name> &name,
+ const ptr_lib::shared_ptr<const Interest> &interest);
+ void processContent(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
+ const ndn::ptr_lib::shared_ptr<ndn::Data> &data);
+ void nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&);
+ void processInterestTimedOut(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest);
+
+ void setInterestFilterNlsr(const string& name);
+
+ void expressInterest(const string& interestNamePrefix, int scope, int seconds);
+
+ //void scheduleSomeInterest(const string& interestName);
+
+ void sendScheduledInfoInterest(int seconds);
+ void scheduleInfoInterest(int seconds);
+
+ void startEventLoop();
+
+ int usage(const string& progname);
+
+ string getConfFileName(){
+ return configFileName;
+ }
+
+ void setConfFileName(const string& fileName){
+ configFileName=fileName;
+ }
+
+ bool isSetDaemonProcess(){
+ return isDaemonProcess;
+ }
+
+ void setIsDaemonProcess(bool value){
+ isDaemonProcess=value;
+ }
+
+ ConfParameter confParam;
+ Adl adl;
+ Npl npl;
+ private:
+ ndn::shared_ptr<boost::asio::io_service> io;
+ ndn::Scheduler scheduler;
+ ndn::Face nlsrFace;
+ ndn::KeyChain kChain;
+ bool isDaemonProcess;
+ string configFileName;
+
+};
+
+#endif
diff --git a/nlsr_params.hpp b/nlsr_params.hpp
new file mode 100644
index 0000000..a5f11c5
--- /dev/null
+++ b/nlsr_params.hpp
@@ -0,0 +1,12 @@
+#ifndef NLSR_PARAMS_HPP
+#define NLSR_PARAMS_HPP
+
+class nlsrParams{
+
+
+
+
+
+};
+
+#endif
diff --git a/nlsr_tokenizer.cpp b/nlsr_tokenizer.cpp
new file mode 100644
index 0000000..7c82ecd
--- /dev/null
+++ b/nlsr_tokenizer.cpp
@@ -0,0 +1,114 @@
+#include <iostream>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
+#include <string>
+#include <algorithm>
+
+#include "nlsr_tokenizer.hpp"
+
+using namespace std;
+using namespace boost;
+
+void
+nlsrTokenizer::makeToken(){
+ char_separator<char> sep(seps.c_str());
+ tokenizer< char_separator<char> >tokens(originalString, sep);
+ tokenizer< char_separator<char> >::iterator tok_iter = tokens.begin();
+
+ string ft(*tok_iter);
+ firstToken=ft;
+ ++tok_iter;
+
+ for ( ;tok_iter != tokens.end(); ++tok_iter){
+ string oneToken(*tok_iter);
+ this->insertToken(oneToken);
+ restOfTheLine+=oneToken;
+ restOfTheLine+=seps;
+ }
+
+ trim(restOfTheLine);
+}
+
+void
+nlsrTokenizer::insertToken(const string& token){
+ tokenList.push_back(token);
+}
+
+int
+nlsrTokenizer::getTokenPosition(string& token){
+ int pos=-1;
+ int i=1;
+
+ for(std::list<string>::iterator it=tokenList.begin();it!=tokenList.end();it++){
+ if( (*it) == token ){
+ break;
+ }
+ i++;
+ }
+
+ if( i < tokenList.size() ){
+ pos=i;
+ }
+
+ return pos;
+}
+
+string
+nlsrTokenizer::getTokenString(int from , int to){
+ string returnString;
+ if ( from >=0 && to < tokenList.size()){
+ int i=1;
+ for(std::list<string>::iterator it=tokenList.begin();
+ it!=tokenList.end();it++){
+ if( i >= from && i<= to ){
+ string oneToken((*it));
+ returnString+=seps;
+ returnString+=oneToken;
+
+ }
+ i++;
+ }
+ }
+
+ trim(returnString);
+ return returnString;
+}
+
+string
+nlsrTokenizer::getTokenString(int from){
+ string returnString;
+ if ( from >=0 && from < tokenList.size()){
+ int i=1;
+ for(std::list<string>::iterator it=tokenList.begin();
+ it!=tokenList.end();it++){
+ if( i >= from){
+ string oneToken((*it));
+ returnString+=seps;
+ returnString+=oneToken;
+
+ }
+ i++;
+ }
+ }
+
+ trim(returnString);
+ return returnString;
+}
+
+static bool
+tokenCompare(string& s1, string& s2){
+ return s1==s2;
+}
+
+bool
+nlsrTokenizer::doesTokenExist(string token){
+ std::list<string >::iterator it = std::find_if( tokenList.begin(),
+ tokenList.end(),
+ bind(&tokenCompare, _1 , token));
+
+ if( it != tokenList.end() ){
+ return true;
+ }
+
+ return false;
+}
diff --git a/nlsr_tokenizer.hpp b/nlsr_tokenizer.hpp
new file mode 100644
index 0000000..9363462
--- /dev/null
+++ b/nlsr_tokenizer.hpp
@@ -0,0 +1,59 @@
+#ifndef NLSR_TOKENIZER_HPP
+#define NLSR_TOKENIZER_HPP
+
+#include <iostream>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
+#include <string>
+#include <list>
+#include <ndn-cpp-dev/face.hpp>
+
+using namespace std;
+using namespace boost;
+
+class nlsrTokenizer{
+ public:
+ nlsrTokenizer(const string& inputString)
+ :firstToken(),
+ restOfTheLine()
+ {
+ seps = " ";
+ originalString = inputString;
+ makeToken();
+ }
+
+ nlsrTokenizer(const string& inputString, const string& separator)
+ :firstToken(),
+ restOfTheLine()
+ {
+ seps = separator;
+ originalString = inputString;
+ makeToken();
+ }
+
+ string getFirstToken(){
+ return firstToken;
+ }
+
+ string getRestOfLine(){
+ return restOfTheLine;
+ }
+
+ int getTokenPosition(string& token);
+ string getTokenString(int from , int to);
+ string getTokenString(int from);
+ bool doesTokenExist(string token);
+
+ private:
+
+ void makeToken();
+ void insertToken(const string& token);
+
+ string seps;
+ string originalString;
+ string firstToken;
+ string restOfTheLine;
+ std::list<string> tokenList;
+};
+
+#endif
diff --git a/npl.cpp b/npl.cpp
new file mode 100644
index 0000000..df898d4
--- /dev/null
+++ b/npl.cpp
@@ -0,0 +1,41 @@
+#include<iostream>
+#include<algorithm>
+
+#include "npl.hpp"
+
+using namespace std;
+
+Npl::Npl(){
+
+}
+
+Npl::~Npl(){
+
+}
+
+static bool
+nameCompare(string& s1, string& s2){
+ return s1==s2;
+}
+
+int
+Npl::insertIntoNpl(string& name){
+ std::list<string >::iterator it = std::find_if( nameList.begin(),
+ nameList.end(),
+ bind(&nameCompare, _1 , name));
+
+ if( it != nameList.end() ){
+ return -1;
+ }
+
+ nameList.push_back(name);
+ return 0;
+
+}
+
+void
+Npl::printNpl(){
+ for( std::list<string>::iterator it=nameList.begin(); it != nameList.end(); it++){
+ cout<<"Name : "<<(*it)<<endl;
+ }
+}
diff --git a/npl.hpp b/npl.hpp
new file mode 100644
index 0000000..da4bda7
--- /dev/null
+++ b/npl.hpp
@@ -0,0 +1,24 @@
+#ifndef NPL_HPP
+#define NPL_HPP
+
+#include<list>
+#include<string>
+#include <ndn-cpp-dev/face.hpp>
+
+using namespace std;
+
+class Npl{
+
+public:
+ Npl();
+ ~Npl();
+
+ int insertIntoNpl(string& name);
+ void printNpl();
+
+private:
+ std::list<string> nameList;
+
+};
+
+#endif