blob: 95b138d638f1f23c4dd8c0be9ef9e2a19aa787b1 [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 {
akmhoque3fdf7612014-02-04 21:18:23 -060025 cout<<"CLearing old routing table ....."<<endl;
akmhoque79d355f2014-02-04 15:11:16 -060026 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,";
akmhoque3fdf7612014-02-04 21:18:23 -060056 cout<< " so Routing table can not be calculated :("<<endl;
akmhoque79d355f2014-02-04 15:11:16 -060057 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
74void
75RoutingTable::calculateLsRoutingTable(nlsr& pnlsr)
76{
akmhoque3fdf7612014-02-04 21:18:23 -060077 cout<<"RoutingTable::calculateLsRoutingTable Called"<<endl;
akmhoque79d355f2014-02-04 15:11:16 -060078 Map vMap;
79 vMap.createMapFromAdjLsdb(pnlsr);
80 int numOfRouter=vMap.getMapSize();
81
82 LinkStateRoutingTableCalculator lsrtc(numOfRouter);
akmhoque79d355f2014-02-04 15:11:16 -060083 lsrtc.calculatePath(vMap,boost::ref(*this),pnlsr);
akmhoque79d355f2014-02-04 15:11:16 -060084
85
86}
87
88void
89RoutingTable::calculateHypRoutingTable(nlsr& pnlsr)
90{
91
92}
93
94void
95RoutingTable::calculateHypDryRoutingTable(nlsr&pnlsr)
96{
97
98}
99
100void
101RoutingTable::clearRoutingTable()
102{
akmhoque3fdf7612014-02-04 21:18:23 -0600103 if( rTable.size() > 0 )
104 {
105 rTable.clear();
106 }
akmhoque79d355f2014-02-04 15:11:16 -0600107}
108
109void
110RoutingTable::clearDryRoutingTable()
111{
akmhoque3fdf7612014-02-04 21:18:23 -0600112 if (dryTable.size()>0 )
113 {
114 dryTable.clear();
115 }
akmhoque79d355f2014-02-04 15:11:16 -0600116}
akmhoquedfa4a5b2014-02-03 20:12:29 -0600117