blob: 1ff75559744533d3e2cc891b4f427e2ce9c2db07 [file] [log] [blame]
#include<iostream>
#include<cstdlib>
#include "nlsr.hpp"
#include "nlsr_dm.hpp"
#include "nlsr_tokenizer.hpp"
#include "nlsr_lsdb.hpp"
using namespace std;
using namespace ndn;
void
DataManager::processContent(nlsr& pnlsr,
const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
const ndn::ptr_lib::shared_ptr<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)));
}
}
}