blob: a88951b072a4c1f8c9564e4f4664922758440b8e [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<iostream>
2#include<cstdlib>
3
akmhoque298385a2014-02-13 14:13:09 -06004#include "nlsr.hpp"
5#include "nlsr_dm.hpp"
6#include "nlsr_tokenizer.hpp"
7#include "nlsr_lsdb.hpp"
8
akmhoque1fd8c1e2014-02-19 19:41:49 -06009namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -060010{
11
akmhoque1fd8c1e2014-02-19 19:41:49 -060012 using namespace std;
13 using namespace ndn;
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque1fd8c1e2014-02-19 19:41:49 -060015 void
16 DataManager::processContent(Nlsr& pnlsr, const ndn::Interest &interest,
17 const ndn::Data & data)
18 {
akmhoque1fd8c1e2014-02-19 19:41:49 -060019 cout << "I: " << interest.toUri() << endl;
akmhoque1fd8c1e2014-02-19 19:41:49 -060020 string dataName(data.getName().toUri());
21 string dataContent((char *)data.getContent().value());
akmhoque1fd8c1e2014-02-19 19:41:49 -060022 cout << "D: " << dataName << endl;
23 cout << "Data Content: " << dataContent << endl;
akmhoque1fd8c1e2014-02-19 19:41:49 -060024 nlsrTokenizer nt(dataName,"/");
25 string chkString("info");
26 if( nt.doesTokenExist(chkString) )
27 {
28 processContentInfo(pnlsr,dataName,dataContent);
29 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060030 }
akmhoque298385a2014-02-13 14:13:09 -060031
akmhoque1fd8c1e2014-02-19 19:41:49 -060032 void
33 DataManager::processContentInfo(Nlsr& pnlsr, string& dataName,
34 string& dataContent)
35 {
36 nlsrTokenizer nt(dataName,"/");
37 string chkString("info");
38 string neighbor="/" + nt.getFirstToken()
39 +nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
40 int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
41 int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
42 //debugging purpose start
43 cout <<"Before Updates: " <<endl;
44 cout <<"Neighbor : "<<neighbor<<endl;
45 cout<<"Status: "<< oldStatus << endl;
46 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
47 //debugging purpose end
akmhoque1fd8c1e2014-02-19 19:41:49 -060048 pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
49 pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);
akmhoque1fd8c1e2014-02-19 19:41:49 -060050 int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
51 infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
akmhoque1fd8c1e2014-02-19 19:41:49 -060052 //debugging purpose
53 cout <<"After Updates: " <<endl;
54 cout <<"Neighbor : "<<neighbor<<endl;
55 cout<<"Status: "<< newStatus << endl;
56 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
57 //debugging purpose end
akmhoque1fd8c1e2014-02-19 19:41:49 -060058 if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
59 {
60 pnlsr.incrementAdjBuildCount();
61 /* Need to schedule event for Adjacency LSA building */
62 if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
63 {
64 pnlsr.setIsBuildAdjLsaSheduled(1);
65 // event here
66 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
67 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
68 boost::ref(pnlsr)));
69 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060070 }
71 }
akmhoqueb1710aa2014-02-19 17:13:36 -060072
73}//namespace nlsr