blob: 3f1b53fd99eb502c94045538de5d51b830ebcf8f [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);
akmhoque2f423352014-06-03 11:49:35 -050055/*
akmhoque53353462014-04-22 08:43:45 -050056 void
57 printAdjMatrix();
akmhoque2f423352014-06-03 11:49:35 -050058*/
59 void
60 writeAdjMatrixLog();
akmhoque53353462014-04-22 08:43:45 -050061
62 int
63 getNumOfLinkfromAdjMatrix(int sRouter);
64
65 void
66 freeAdjMatrix();
67
68 void
69 adjustAdMatrix(int source, int link, double linkCost);
70
71 void
72 getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
73
74 void
75 allocateLinks();
76
77 void
78 allocateLinkCosts();
79
80 void
81 freeLinks();
82
83 void
84 freeLinksCosts();
85
86 void
87 setNoLink(int nl)
88 {
89 vNoLink = nl;
90 }
91
92protected:
93 double** adjMatrix;
94 int numOfRouter;
95
96 int vNoLink;
97 int* links;
98 double* linkCosts;
99};
100
101class LinkStateRoutingTableCalculator: public RoutingTableCalculator
102{
103public:
104 LinkStateRoutingTableCalculator(int rn)
105 : EMPTY_PARENT(-12345)
106 , INF_DISTANCE(2147483647)
107 , NO_MAPPING_NUM(-1)
108 , NO_NEXT_HOP(-12345)
109 {
110 numOfRouter = rn;
111 }
112
113
114 void
115 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
116
117
118private:
119 void
120 doDijkstraPathCalculation(int sourceRouter);
121
122 void
123 sortQueueByDistance(int* Q, double* dist, int start, int element);
124
125 int
126 isNotExplored(int* Q, int u, int start, int element);
127
128 void
akmhoque53353462014-04-22 08:43:45 -0500129 addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
130 Map& pMap, int sourceRouter);
131
132 int
133 getLsNextHop(int dest, int source);
134
135 void
136 allocateParent();
137
138 void
139 allocateDistance();
140
141 void
142 freeParent();
143
144 void
145 freeDistance();
146
147
148
149
150private:
151 int* m_parent;
152 double* m_distance;
153
154
155 const int EMPTY_PARENT;
156 const double INF_DISTANCE;
157 const int NO_MAPPING_NUM;
158 const int NO_NEXT_HOP;
159
160};
161
162class HypRoutingTableCalculator: public RoutingTableCalculator
163{
164public:
165 HypRoutingTableCalculator(int rn)
166 : MATH_PI(3.141592654)
167 {
168 numOfRouter = rn;
169 m_isDryRun = 0;
170 }
171
172 HypRoutingTableCalculator(int rn, int idr)
173 : MATH_PI(3.141592654)
174 {
175 numOfRouter = rn;
176 m_isDryRun = idr;
177 }
178
179 void
180 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
181
182private:
183 void
184 allocateLinkFaces();
185
186 void
187 allocateDistanceToNeighbor();
188
189 void
190 allocateDistFromNbrToDest();
191
192 void
193 freeLinkFaces();
194
195 void
196 freeDistanceToNeighbor();
197
198 void
199 freeDistFromNbrToDest();
200
201 double
202 getHyperbolicDistance(Nlsr& pnlsr, Map& pMap, int src, int dest);
203
204 void
205 addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap,
206 RoutingTable& rt, int noFaces, int dest);
207
208private:
209 bool m_isDryRun;
210
akmhoque157b0a42014-05-13 00:26:37 -0500211 std::vector<std::string> m_linkFaceUris;
akmhoque53353462014-04-22 08:43:45 -0500212 double* m_distanceToNeighbor;
213 double* m_distFromNbrToDest;
214
215 const double MATH_PI;
216
217};
218
219}//namespace nlsr
220
akmhoquefdbddb12014-05-02 18:35:19 -0500221#endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP