akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 1 | #include<iostream> |
| 2 | #include<string> |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame^] | 3 | #include<list> |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 4 | |
| 5 | #include "nlsr_rt.hpp" |
| 6 | #include "nlsr.hpp" |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame^] | 7 | #include "nlsr_map.hpp" |
| 8 | #include "nlsr_rtc.hpp" |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 9 | |
| 10 | using namespace std; |
| 11 | |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame^] | 12 | void |
| 13 | RoutingTable::calculate(nlsr& pnlsr) |
| 14 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 15 | |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame^] | 16 | if ( pnlsr.getIsRoutingTableCalculating() == 0 ) |
| 17 | { |
| 18 | pnlsr.setIsRoutingTableCalculating(1); //setting routing table calculation |
| 19 | |
| 20 | if ( pnlsr.getLsdb().doesLsaExist( |
| 21 | pnlsr.getConfParameter().getRouterPrefix()+"/"+"2",2) ) |
| 22 | { |
| 23 | if(pnlsr.getIsBuildAdjLsaSheduled() != 1) |
| 24 | { |
| 25 | clearRoutingTable(); |
| 26 | clearDryRoutingTable(); // for dry run options |
| 27 | // calculate Link State routing |
| 28 | if( (pnlsr.getConfParameter().getIsHyperbolicCalc() == 0 ) |
| 29 | || (pnlsr.getConfParameter().getIsHyperbolicCalc() == 2 ) ) |
| 30 | { |
| 31 | calculateLsRoutingTable(pnlsr); |
| 32 | } |
| 33 | //calculate hyperbolic routing |
| 34 | if ( pnlsr.getConfParameter().getIsHyperbolicCalc() == 1 ) |
| 35 | { |
| 36 | calculateHypRoutingTable(pnlsr); |
| 37 | } |
| 38 | //calculate dry hyperbolic routing |
| 39 | if ( pnlsr.getConfParameter().getIsHyperbolicCalc() == 2 ) |
| 40 | { |
| 41 | calculateHypDryRoutingTable(pnlsr); |
| 42 | } |
| 43 | |
| 44 | //need to update NPT here |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | cout<<"Adjacency building is scheduled, so "; |
| 49 | cout<<"routing table can not be calculated :("<<endl; |
| 50 | } |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | cout<<"No Adj LSA of router itself,"; |
| 55 | cout<< " so Routint table can not be calculated :("<<endl; |
| 56 | clearRoutingTable(); |
| 57 | clearDryRoutingTable(); // for dry run options |
| 58 | // need to update NPT here |
| 59 | } |
| 60 | |
| 61 | pnlsr.setIsRouteCalculationScheduled(0); //clear scheduled flag |
| 62 | pnlsr.setIsRoutingTableCalculating(0); //unsetting routing table calculation |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15), |
| 67 | ndn::bind(&RoutingTable::calculate,this,boost::ref(pnlsr))); |
| 68 | pnlsr.setIsRouteCalculationScheduled(1); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | void |
| 74 | RoutingTable::calculateLsRoutingTable(nlsr& pnlsr) |
| 75 | { |
| 76 | Map vMap; |
| 77 | vMap.createMapFromAdjLsdb(pnlsr); |
| 78 | int numOfRouter=vMap.getMapSize(); |
| 79 | |
| 80 | LinkStateRoutingTableCalculator lsrtc(numOfRouter); |
| 81 | lsrtc.allocateAdjMatrix(); |
| 82 | lsrtc.makeAdjMatrix(pnlsr,vMap); |
| 83 | lsrtc.calculatePath(vMap,boost::ref(*this),pnlsr); |
| 84 | lsrtc.freeAdjMatrix(); |
| 85 | |
| 86 | |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | RoutingTable::calculateHypRoutingTable(nlsr& pnlsr) |
| 91 | { |
| 92 | |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | RoutingTable::calculateHypDryRoutingTable(nlsr&pnlsr) |
| 97 | { |
| 98 | |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | RoutingTable::clearRoutingTable() |
| 103 | { |
| 104 | rTable.clear(); |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | RoutingTable::clearDryRoutingTable() |
| 109 | { |
| 110 | dryTable.clear(); |
| 111 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 112 | |