blob: 46b278dc52188b37bfb34b20ce19cd2d5cae3745 [file] [log] [blame]
akmhoque95b7c8c2014-01-31 15:53:09 -06001#include<iostream>
2#include<cstdlib>
3
4
5
6#include "nlsr.hpp"
7#include "nlsr_dm.hpp"
8#include "nlsr_tokenizer.hpp"
akmhoquecd552472014-02-01 21:22:16 -06009#include "nlsr_lsdb.hpp"
akmhoque95b7c8c2014-01-31 15:53:09 -060010
11using namespace std;
12using namespace ndn;
13
14void
akmhoque9d19a492014-02-11 19:44:29 -060015DataManager::processContent(nlsr& pnlsr, const ndn::Interest &interest,
16 const ndn::Data & data)
akmhoque95b7c8c2014-01-31 15:53:09 -060017{
18
akmhoque9d19a492014-02-11 19:44:29 -060019 cout << "I: " << interest.toUri() << endl;
akmhoque95b7c8c2014-01-31 15:53:09 -060020
akmhoque9d19a492014-02-11 19:44:29 -060021 string dataName(data.getName().toUri());
22 string dataContent((char *)data.getContent().value());
akmhoquea8cd6b92014-01-31 20:13:26 -060023
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);
akmhoquecd552472014-02-01 21:22:16 -060043 int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
akmhoquea8cd6b92014-01-31 20:13:26 -060044 int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
45 //debugging purpose start
46 cout <<"Before Updates: " <<endl;
47 cout <<"Neighbor : "<<neighbor<<endl;
akmhoquecd552472014-02-01 21:22:16 -060048 cout<<"Status: "<< oldStatus << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060049 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
akmhoquecd552472014-02-01 21:22:16 -060055 int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
akmhoquea8cd6b92014-01-31 20:13:26 -060056 infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
57
58 //debugging purpose
59 cout <<"After Updates: " <<endl;
60 cout <<"Neighbor : "<<neighbor<<endl;
akmhoquecd552472014-02-01 21:22:16 -060061 cout<<"Status: "<< newStatus << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060062 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
63 //debugging purpose end
64
akmhoquecd552472014-02-01 21:22:16 -060065 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
akmhoquea8cd6b92014-01-31 20:13:26 -060081
akmhoque95b7c8c2014-01-31 15:53:09 -060082}