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