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