blob: b248b15cfe96583fa938ff794b9363948aa6c661 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#ifndef NLSR_RTC_HPP
2#define NLSR_RTC_HPP
3
4#include <list>
5#include <iostream>
6
7namespace nlsr {
8
9class Map;
10class RoutingTable;
11class Nlsr;
12
13class RoutingTableCalculator
14{
15public:
16 RoutingTableCalculator()
17 {
18 }
19 RoutingTableCalculator(int rn)
20 {
21 numOfRouter = rn;
22 }
23protected:
24 void
25 allocateAdjMatrix();
26
27 void
28 initMatrix();
29
30 void
31 makeAdjMatrix(Nlsr& pnlsr, Map pMap);
32
33 void
34 printAdjMatrix();
35
36 int
37 getNumOfLinkfromAdjMatrix(int sRouter);
38
39 void
40 freeAdjMatrix();
41
42 void
43 adjustAdMatrix(int source, int link, double linkCost);
44
45 void
46 getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
47
48 void
49 allocateLinks();
50
51 void
52 allocateLinkCosts();
53
54 void
55 freeLinks();
56
57 void
58 freeLinksCosts();
59
60 void
61 setNoLink(int nl)
62 {
63 vNoLink = nl;
64 }
65
66protected:
67 double** adjMatrix;
68 int numOfRouter;
69
70 int vNoLink;
71 int* links;
72 double* linkCosts;
73};
74
75class LinkStateRoutingTableCalculator: public RoutingTableCalculator
76{
77public:
78 LinkStateRoutingTableCalculator(int rn)
79 : EMPTY_PARENT(-12345)
80 , INF_DISTANCE(2147483647)
81 , NO_MAPPING_NUM(-1)
82 , NO_NEXT_HOP(-12345)
83 {
84 numOfRouter = rn;
85 }
86
87
88 void
89 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
90
91
92private:
93 void
94 doDijkstraPathCalculation(int sourceRouter);
95
96 void
97 sortQueueByDistance(int* Q, double* dist, int start, int element);
98
99 int
100 isNotExplored(int* Q, int u, int start, int element);
101
102 void
103 printAllLsPath(int sourceRouter);
104
105 void
106 printLsPath(int destRouter);
107
108 void
109 addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
110 Map& pMap, int sourceRouter);
111
112 int
113 getLsNextHop(int dest, int source);
114
115 void
116 allocateParent();
117
118 void
119 allocateDistance();
120
121 void
122 freeParent();
123
124 void
125 freeDistance();
126
127
128
129
130private:
131 int* m_parent;
132 double* m_distance;
133
134
135 const int EMPTY_PARENT;
136 const double INF_DISTANCE;
137 const int NO_MAPPING_NUM;
138 const int NO_NEXT_HOP;
139
140};
141
142class HypRoutingTableCalculator: public RoutingTableCalculator
143{
144public:
145 HypRoutingTableCalculator(int rn)
146 : MATH_PI(3.141592654)
147 {
148 numOfRouter = rn;
149 m_isDryRun = 0;
150 }
151
152 HypRoutingTableCalculator(int rn, int idr)
153 : MATH_PI(3.141592654)
154 {
155 numOfRouter = rn;
156 m_isDryRun = idr;
157 }
158
159 void
160 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
161
162private:
163 void
164 allocateLinkFaces();
165
166 void
167 allocateDistanceToNeighbor();
168
169 void
170 allocateDistFromNbrToDest();
171
172 void
173 freeLinkFaces();
174
175 void
176 freeDistanceToNeighbor();
177
178 void
179 freeDistFromNbrToDest();
180
181 double
182 getHyperbolicDistance(Nlsr& pnlsr, Map& pMap, int src, int dest);
183
184 void
185 addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap,
186 RoutingTable& rt, int noFaces, int dest);
187
188private:
189 bool m_isDryRun;
190
191 int* m_linkFaces;
192 double* m_distanceToNeighbor;
193 double* m_distFromNbrToDest;
194
195 const double MATH_PI;
196
197};
198
199}//namespace nlsr
200
201#endif //NLSR_RTC_HPP