blob: b2cc8b923054236889bff7b3e9addc11db0a9a5b [file] [log] [blame]
akmhoquedfa4a5b2014-02-03 20:12:29 -06001#include<iostream>
2#include<string>
akmhoque79d355f2014-02-04 15:11:16 -06003#include<list>
akmhoquedfa4a5b2014-02-03 20:12:29 -06004
5#include "nlsr_rt.hpp"
6#include "nlsr.hpp"
akmhoque79d355f2014-02-04 15:11:16 -06007#include "nlsr_map.hpp"
8#include "nlsr_rtc.hpp"
akmhoquedfa4a5b2014-02-03 20:12:29 -06009
10using namespace std;
11
akmhoque79d355f2014-02-04 15:11:16 -060012void
13RoutingTable::calculate(nlsr& pnlsr)
14{
akmhoquedfa4a5b2014-02-03 20:12:29 -060015
akmhoque79d355f2014-02-04 15:11:16 -060016 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
73void
74RoutingTable::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
89void
90RoutingTable::calculateHypRoutingTable(nlsr& pnlsr)
91{
92
93}
94
95void
96RoutingTable::calculateHypDryRoutingTable(nlsr&pnlsr)
97{
98
99}
100
101void
102RoutingTable::clearRoutingTable()
103{
104 rTable.clear();
105}
106
107void
108RoutingTable::clearDryRoutingTable()
109{
110 dryTable.clear();
111}
akmhoquedfa4a5b2014-02-03 20:12:29 -0600112