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