blob: e03b21e0532962e055ced727c553418cf7be7418 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoquefdbddb12014-05-02 18:35:19 -050023#ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
24#define NLSR_ROUTING_TABLE_CALCULATOR_HPP
akmhoque53353462014-04-22 08:43:45 -050025
26#include <list>
27#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -050028#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050029
30namespace nlsr {
31
32class Map;
33class RoutingTable;
34class Nlsr;
35
36class RoutingTableCalculator
37{
38public:
39 RoutingTableCalculator()
40 {
41 }
42 RoutingTableCalculator(int rn)
43 {
44 numOfRouter = rn;
45 }
46protected:
47 void
48 allocateAdjMatrix();
49
50 void
51 initMatrix();
52
53 void
54 makeAdjMatrix(Nlsr& pnlsr, Map pMap);
55
56 void
57 printAdjMatrix();
58
59 int
60 getNumOfLinkfromAdjMatrix(int sRouter);
61
62 void
63 freeAdjMatrix();
64
65 void
66 adjustAdMatrix(int source, int link, double linkCost);
67
68 void
69 getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
70
71 void
72 allocateLinks();
73
74 void
75 allocateLinkCosts();
76
77 void
78 freeLinks();
79
80 void
81 freeLinksCosts();
82
83 void
84 setNoLink(int nl)
85 {
86 vNoLink = nl;
87 }
88
89protected:
90 double** adjMatrix;
91 int numOfRouter;
92
93 int vNoLink;
94 int* links;
95 double* linkCosts;
96};
97
98class LinkStateRoutingTableCalculator: public RoutingTableCalculator
99{
100public:
101 LinkStateRoutingTableCalculator(int rn)
102 : EMPTY_PARENT(-12345)
103 , INF_DISTANCE(2147483647)
104 , NO_MAPPING_NUM(-1)
105 , NO_NEXT_HOP(-12345)
106 {
107 numOfRouter = rn;
108 }
109
110
111 void
112 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
113
114
115private:
116 void
117 doDijkstraPathCalculation(int sourceRouter);
118
119 void
120 sortQueueByDistance(int* Q, double* dist, int start, int element);
121
122 int
123 isNotExplored(int* Q, int u, int start, int element);
124
125 void
126 printAllLsPath(int sourceRouter);
127
128 void
129 printLsPath(int destRouter);
130
131 void
132 addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
133 Map& pMap, int sourceRouter);
134
135 int
136 getLsNextHop(int dest, int source);
137
138 void
139 allocateParent();
140
141 void
142 allocateDistance();
143
144 void
145 freeParent();
146
147 void
148 freeDistance();
149
150
151
152
153private:
154 int* m_parent;
155 double* m_distance;
156
157
158 const int EMPTY_PARENT;
159 const double INF_DISTANCE;
160 const int NO_MAPPING_NUM;
161 const int NO_NEXT_HOP;
162
163};
164
165class HypRoutingTableCalculator: public RoutingTableCalculator
166{
167public:
168 HypRoutingTableCalculator(int rn)
169 : MATH_PI(3.141592654)
170 {
171 numOfRouter = rn;
172 m_isDryRun = 0;
173 }
174
175 HypRoutingTableCalculator(int rn, int idr)
176 : MATH_PI(3.141592654)
177 {
178 numOfRouter = rn;
179 m_isDryRun = idr;
180 }
181
182 void
183 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
184
185private:
186 void
187 allocateLinkFaces();
188
189 void
190 allocateDistanceToNeighbor();
191
192 void
193 allocateDistFromNbrToDest();
194
195 void
196 freeLinkFaces();
197
198 void
199 freeDistanceToNeighbor();
200
201 void
202 freeDistFromNbrToDest();
203
204 double
205 getHyperbolicDistance(Nlsr& pnlsr, Map& pMap, int src, int dest);
206
207 void
208 addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap,
209 RoutingTable& rt, int noFaces, int dest);
210
211private:
212 bool m_isDryRun;
213
akmhoque157b0a42014-05-13 00:26:37 -0500214 std::vector<std::string> m_linkFaceUris;
akmhoque53353462014-04-22 08:43:45 -0500215 double* m_distanceToNeighbor;
216 double* m_distFromNbrToDest;
217
218 const double MATH_PI;
219
220};
221
222}//namespace nlsr
223
akmhoquefdbddb12014-05-02 18:35:19 -0500224#endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP