blob: 1ff75559744533d3e2cc891b4f427e2ce9c2db07 [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
akmhoquea8cd6b92014-01-31 20:13:26 -060015DataManager::processContent(nlsr& pnlsr,
akmhoque95b7c8c2014-01-31 15:53:09 -060016 const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
17 const ndn::ptr_lib::shared_ptr<ndn::Data> &data)
18{
19
20 cout << "I: " << interest->toUri() << endl;
akmhoque95b7c8c2014-01-31 15:53:09 -060021
akmhoquea8cd6b92014-01-31 20:13:26 -060022 string dataName(data->getName().toUri());
23 string dataContent((char *)data->getContent().value());
24
25 cout << "D: " << dataName << endl;
26 cout << "Data Content: " << dataContent << endl;
27
28 nlsrTokenizer nt(dataName,"/");
29 string chkString("info");
30 if( nt.doesTokenExist(chkString) ){
31 processContentInfo(pnlsr,dataName,dataContent);
32 }
33
34}
35
36void
37DataManager::processContentInfo(nlsr& pnlsr, string& dataName,
38 string& dataContent)
39{
40 nlsrTokenizer nt(dataName,"/");
41 string chkString("info");
42 string neighbor="/" + nt.getFirstToken()
43 +nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
akmhoquecd552472014-02-01 21:22:16 -060044 int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
akmhoquea8cd6b92014-01-31 20:13:26 -060045 int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
46 //debugging purpose start
47 cout <<"Before Updates: " <<endl;
48 cout <<"Neighbor : "<<neighbor<<endl;
akmhoquecd552472014-02-01 21:22:16 -060049 cout<<"Status: "<< oldStatus << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060050 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
51 //debugging purpose end
52
53 pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
54 pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);
55
akmhoquecd552472014-02-01 21:22:16 -060056 int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
akmhoquea8cd6b92014-01-31 20:13:26 -060057 infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
58
59 //debugging purpose
60 cout <<"After Updates: " <<endl;
61 cout <<"Neighbor : "<<neighbor<<endl;
akmhoquecd552472014-02-01 21:22:16 -060062 cout<<"Status: "<< newStatus << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060063 cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
64 //debugging purpose end
65
akmhoquecd552472014-02-01 21:22:16 -060066 if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
67 {
68 pnlsr.incrementAdjBuildCount();
69 /* Need to schedule event for Adjacency LSA building */
70 if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
71 {
72 pnlsr.setIsBuildAdjLsaSheduled(1);
73 // event here
74 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
75 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
76 boost::ref(pnlsr)));
77 }
78
79 }
80
81
akmhoquea8cd6b92014-01-31 20:13:26 -060082
akmhoque95b7c8c2014-01-31 15:53:09 -060083}