blob: 46b278dc52188b37bfb34b20ce19cd2d5cae3745 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<iostream>
2#include<cstdlib>
3
4
5
6#include "nlsr.hpp"
7#include "nlsr_dm.hpp"
8#include "nlsr_tokenizer.hpp"
9#include "nlsr_lsdb.hpp"
10
11using namespace std;
12using namespace ndn;
13
14void
15DataManager::processContent(nlsr& pnlsr, const ndn::Interest &interest,
16 const ndn::Data & data)
17{
18
19 cout << "I: " << interest.toUri() << endl;
20
21 string dataName(data.getName().toUri());
22 string dataContent((char *)data.getContent().value());
23
24 cout << "D: " << dataName << endl;
25 cout << "Data Content: " << dataContent << endl;
26
27 nlsrTokenizer nt(dataName,"/");
28 string chkString("info");
29 if( nt.doesTokenExist(chkString) ){
30 processContentInfo(pnlsr,dataName,dataContent);
31 }
32
33}
34
35void
36DataManager::processContentInfo(nlsr& pnlsr, string& dataName,
37 string& dataContent)
38{
39 nlsrTokenizer nt(dataName,"/");
40 string chkString("info");
41 string neighbor="/" + nt.getFirstToken()
42 +nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
43 int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
44 int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
45 //debugging purpose start
46 cout <<"Before Updates: " <<endl;
47 cout <<"Neighbor : "<<neighbor<<endl;
48 cout<<"Status: "<< oldStatus << endl;
49 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
50 //debugging purpose end
51
52 pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
53 pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);
54
55 int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
56 infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
57
58 //debugging purpose
59 cout <<"After Updates: " <<endl;
60 cout <<"Neighbor : "<<neighbor<<endl;
61 cout<<"Status: "<< newStatus << endl;
62 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
63 //debugging purpose end
64
65 if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
66 {
67 pnlsr.incrementAdjBuildCount();
68 /* Need to schedule event for Adjacency LSA building */
69 if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
70 {
71 pnlsr.setIsBuildAdjLsaSheduled(1);
72 // event here
73 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
74 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
75 boost::ref(pnlsr)));
76 }
77
78 }
79
80
81
82}