blob: 8252423a7429905aa7f13c1df7890ce5d2f97161 [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 {
akmhoque298385a2014-02-13 14:13:09 -060019
akmhoque1fd8c1e2014-02-19 19:41:49 -060020 cout << "I: " << interest.toUri() << endl;
akmhoque298385a2014-02-13 14:13:09 -060021
akmhoque1fd8c1e2014-02-19 19:41:49 -060022 string dataName(data.getName().toUri());
23 string dataContent((char *)data.getContent().value());
akmhoque298385a2014-02-13 14:13:09 -060024
akmhoque1fd8c1e2014-02-19 19:41:49 -060025 cout << "D: " << dataName << endl;
26 cout << "Data Content: " << dataContent << endl;
akmhoque298385a2014-02-13 14:13:09 -060027
akmhoque1fd8c1e2014-02-19 19:41:49 -060028 nlsrTokenizer nt(dataName,"/");
29 string chkString("info");
30 if( nt.doesTokenExist(chkString) )
31 {
32 processContentInfo(pnlsr,dataName,dataContent);
33 }
akmhoque298385a2014-02-13 14:13:09 -060034
akmhoque1fd8c1e2014-02-19 19:41:49 -060035 }
akmhoque298385a2014-02-13 14:13:09 -060036
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 void
38 DataManager::processContentInfo(Nlsr& pnlsr, string& dataName,
39 string& dataContent)
40 {
41 nlsrTokenizer nt(dataName,"/");
42 string chkString("info");
43 string neighbor="/" + nt.getFirstToken()
44 +nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
45 int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
46 int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
47 //debugging purpose start
48 cout <<"Before Updates: " <<endl;
49 cout <<"Neighbor : "<<neighbor<<endl;
50 cout<<"Status: "<< oldStatus << endl;
51 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
52 //debugging purpose end
akmhoque298385a2014-02-13 14:13:09 -060053
akmhoque1fd8c1e2014-02-19 19:41:49 -060054 pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
55 pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);
56
57 int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
58 infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
59
60 //debugging purpose
61 cout <<"After Updates: " <<endl;
62 cout <<"Neighbor : "<<neighbor<<endl;
63 cout<<"Status: "<< newStatus << endl;
64 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
65 //debugging purpose end
66
67 if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
68 {
69 pnlsr.incrementAdjBuildCount();
70 /* Need to schedule event for Adjacency LSA building */
71 if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
72 {
73 pnlsr.setIsBuildAdjLsaSheduled(1);
74 // event here
75 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
76 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
77 boost::ref(pnlsr)));
78 }
79
80 }
81 }
akmhoqueb1710aa2014-02-19 17:13:36 -060082
83}//namespace nlsr