blob: a88951b072a4c1f8c9564e4f4664922758440b8e [file] [log] [blame]
#include<iostream>
#include<cstdlib>
#include "nlsr.hpp"
#include "nlsr_dm.hpp"
#include "nlsr_tokenizer.hpp"
#include "nlsr_lsdb.hpp"
namespace nlsr
{
using namespace std;
using namespace ndn;
void
DataManager::processContent(Nlsr& pnlsr, const ndn::Interest &interest,
const ndn::Data & data)
{
cout << "I: " << interest.toUri() << endl;
string dataName(data.getName().toUri());
string dataContent((char *)data.getContent().value());
cout << "D: " << dataName << endl;
cout << "Data Content: " << dataContent << endl;
nlsrTokenizer nt(dataName,"/");
string chkString("info");
if( nt.doesTokenExist(chkString) )
{
processContentInfo(pnlsr,dataName,dataContent);
}
}
void
DataManager::processContentInfo(Nlsr& pnlsr, string& dataName,
string& dataContent)
{
nlsrTokenizer nt(dataName,"/");
string chkString("info");
string neighbor="/" + nt.getFirstToken()
+nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
//debugging purpose start
cout <<"Before Updates: " <<endl;
cout <<"Neighbor : "<<neighbor<<endl;
cout<<"Status: "<< oldStatus << endl;
cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
//debugging purpose end
pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);
int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
//debugging purpose
cout <<"After Updates: " <<endl;
cout <<"Neighbor : "<<neighbor<<endl;
cout<<"Status: "<< newStatus << endl;
cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
//debugging purpose end
if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
{
pnlsr.incrementAdjBuildCount();
/* Need to schedule event for Adjacency LSA building */
if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
{
pnlsr.setIsBuildAdjLsaSheduled(1);
// event here
pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
boost::ref(pnlsr)));
}
}
}
}//namespace nlsr