routing-table-calculator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2021, The 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 
21 #ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
22 #define NLSR_ROUTING_TABLE_CALCULATOR_HPP
23 
24 #include "common.hpp"
25 #include "lsa/lsa.hpp"
26 #include "lsa/adj-lsa.hpp"
27 #include "lsdb.hpp"
28 #include "conf-parameter.hpp"
29 
30 #include <list>
31 
32 namespace nlsr {
33 
34 class Map;
35 class RoutingTable;
36 
38 {
39 public:
40  RoutingTableCalculator(size_t nRouters)
41  {
42  m_nRouters = nRouters;
43  }
44 
45 protected:
47  void
49 
52  void
53  initMatrix();
54 
59  void
60  makeAdjMatrix(const Lsdb& lsdb, Map& pMap);
61 
65  void
66  writeAdjMatrixLog(const Map& map) const;
67 
71  int
72  getNumOfLinkfromAdjMatrix(int sRouter);
73 
74  void
75  freeAdjMatrix();
81  void
82  adjustAdMatrix(int source, int link, double linkCost);
83 
95  void
96  getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
97 
99  void
100  allocateLinks();
101 
102  void
104 
105  void
106  freeLinks();
107 
108  void
109  freeLinksCosts();
110 
111  void
112  setNoLink(int nl)
113  {
114  vNoLink = nl;
115  }
116 
117 protected:
118  double** adjMatrix;
119  size_t m_nRouters;
120 
121  int vNoLink;
122  int* links;
123  double* linkCosts;
124 
125 };
126 
128 {
129 public:
131  : RoutingTableCalculator(nRouters)
132  {
133  }
134 
135  void
136  calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
137  const Lsdb& lsdb);
138 
139 private:
143  void
144  doDijkstraPathCalculation(int sourceRouter);
145 
158  void
159  sortQueueByDistance(int* Q, double* dist, int start, int element);
160 
167  int
168  isNotExplored(int* Q, int u, int start, int element);
169 
170  void
171  addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
172  Map& pMap, uint32_t sourceRouter);
173 
178  int
179  getLsNextHop(int dest, int source);
180 
181  void
182  allocateParent();
183 
184  void
185  allocateDistance();
186 
187  void
188  freeParent();
189 
190  void
191  freeDistance();
192 
193 private:
194  int* m_parent;
195  double* m_distance;
196 
197  static const int EMPTY_PARENT;
198  static const double INF_DISTANCE;
199  static const int NO_MAPPING_NUM;
200 public:
201  static const int NO_NEXT_HOP;
202 
203 };
204 
205 class AdjacencyList;
206 class Lsdb;
207 
209 {
210 public:
211  HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
212  : m_nRouters(nRouters)
213  , m_isDryRun(isDryRun)
214  , m_thisRouterName(thisRouterName)
215  {
216  }
217 
218  void
219  calculatePath(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
220 
221 private:
222  double
223  getHyperbolicDistance(Lsdb& lsdb, ndn::Name src, ndn::Name dest);
224 
225  void
226  addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt);
227 
228  double
229  calculateHyperbolicDistance(double rI, double rJ, double deltaTheta);
230 
231  double
232  calculateAngularDistance(std::vector<double> angleVectorI,
233  std::vector<double> angleVectorJ);
234 
235 private:
236  const size_t m_nRouters;
237  const bool m_isDryRun;
238  const ndn::Name m_thisRouterName;
239 
240  static const double MATH_PI;
241  static const double UNKNOWN_DISTANCE;
242  static const double UNKNOWN_RADIUS;
243 };
244 
245 } // namespace nlsr
246 
247 #endif // NLSR_ROUTING_TABLE_CALCULATOR_HPP
A class to house all the configuration parameters for NLSR.
void calculatePath(Map &map, RoutingTable &rt, Lsdb &lsdb, AdjacencyList &adjacencies)
HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
void initMatrix()
set NON_ADJACENT_COST i.e. -12345 to every cell of the matrix to ensure that the memory is safe....
int getNumOfLinkfromAdjMatrix(int sRouter)
Returns how many links a router in the matrix has.
void adjustAdMatrix(int source, int link, double linkCost)
Adjust a link cost in the adj. matrix.
void allocateAdjMatrix()
Allocate the space needed for the adj. matrix.
void makeAdjMatrix(const Lsdb &lsdb, Map &pMap)
Constructs an adj. matrix to calculate with.
void writeAdjMatrixLog(const Map &map) const
Writes a formated adjacent matrix to DEBUG log.
void getLinksFromAdjMatrix(int *links, double *linkCosts, int source)
Populates temp. variables with the link costs for some router.
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...