akmhoque | 95b7c8c | 2014-01-31 15:53:09 -0600 | [diff] [blame] | 1 | #include<iostream> |
| 2 | #include<cstdlib> |
| 3 | |
| 4 | |
| 5 | |
| 6 | #include "nlsr.hpp" |
| 7 | #include "nlsr_dm.hpp" |
| 8 | #include "nlsr_tokenizer.hpp" |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 9 | #include "nlsr_lsdb.hpp" |
akmhoque | 95b7c8c | 2014-01-31 15:53:09 -0600 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
| 12 | using namespace ndn; |
| 13 | |
| 14 | void |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 15 | DataManager::processContent(nlsr& pnlsr, |
akmhoque | 95b7c8c | 2014-01-31 15:53:09 -0600 | [diff] [blame] | 16 | 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; |
akmhoque | 95b7c8c | 2014-01-31 15:53:09 -0600 | [diff] [blame] | 21 | |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 22 | 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 | |
| 36 | void |
| 37 | DataManager::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); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 44 | int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor); |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 45 | int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor); |
| 46 | //debugging purpose start |
| 47 | cout <<"Before Updates: " <<endl; |
| 48 | cout <<"Neighbor : "<<neighbor<<endl; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 49 | cout<<"Status: "<< oldStatus << endl; |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 50 | 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 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 56 | int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor); |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 57 | infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor); |
| 58 | |
| 59 | //debugging purpose |
| 60 | cout <<"After Updates: " <<endl; |
| 61 | cout <<"Neighbor : "<<neighbor<<endl; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 62 | cout<<"Status: "<< newStatus << endl; |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 63 | cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl; |
| 64 | //debugging purpose end |
| 65 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame^] | 66 | 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 | |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 82 | |
akmhoque | 95b7c8c | 2014-01-31 15:53:09 -0600 | [diff] [blame] | 83 | } |