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-2022, 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 namespace nlsr {
31 
32 class Map;
33 class RoutingTable;
34 
36 {
37 public:
38  RoutingTableCalculator(size_t nRouters)
39  {
40  m_nRouters = nRouters;
41  }
42 
43 protected:
45  void
47 
50  void
51  initMatrix();
52 
57  void
58  makeAdjMatrix(const Lsdb& lsdb, Map& pMap);
59 
63  void
64  writeAdjMatrixLog(const Map& map) const;
65 
69  int
70  getNumOfLinkfromAdjMatrix(int sRouter);
71 
72  void
73  freeAdjMatrix();
79  void
80  adjustAdMatrix(int source, int link, double linkCost);
81 
93  void
94  getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
95 
97  void
98  allocateLinks();
99 
100  void
102 
103  void
104  freeLinks();
105 
106  void
107  freeLinksCosts();
108 
109  void
110  setNoLink(int nl)
111  {
112  vNoLink = nl;
113  }
114 
115 protected:
116  double** adjMatrix;
117  size_t m_nRouters;
118 
119  int vNoLink;
120  int* links;
121  double* linkCosts;
122 
123 };
124 
126 {
127 public:
129  : RoutingTableCalculator(nRouters)
130  {
131  }
132 
133  void
134  calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
135  const Lsdb& lsdb);
136 
137 private:
141  void
142  doDijkstraPathCalculation(int sourceRouter);
143 
156  void
157  sortQueueByDistance(int* Q, double* dist, int start, int element);
158 
165  int
166  isNotExplored(int* Q, int u, int start, int element);
167 
168  void
169  addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
170  Map& pMap, uint32_t sourceRouter);
171 
176  int
177  getLsNextHop(int dest, int source);
178 
179  void
180  allocateParent();
181 
182  void
183  allocateDistance();
184 
185  void
186  freeParent();
187 
188  void
189  freeDistance();
190 
191 private:
192  int* m_parent;
193  double* m_distance;
194 };
195 
196 class AdjacencyList;
197 class Lsdb;
198 
200 {
201 public:
202  HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
203  : m_nRouters(nRouters)
204  , m_isDryRun(isDryRun)
205  , m_thisRouterName(thisRouterName)
206  {
207  }
208 
209  void
210  calculatePath(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
211 
212 private:
213  double
214  getHyperbolicDistance(Lsdb& lsdb, ndn::Name src, ndn::Name dest);
215 
216  void
217  addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt);
218 
219  double
220  calculateHyperbolicDistance(double rI, double rJ, double deltaTheta);
221 
222  double
223  calculateAngularDistance(std::vector<double> angleVectorI,
224  std::vector<double> angleVectorJ);
225 
226 private:
227  const size_t m_nRouters;
228  const bool m_isDryRun;
229  const ndn::Name m_thisRouterName;
230 };
231 
232 } // namespace nlsr
233 
234 #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.
@ RoutingTable
Definition: tlv-nlsr.hpp:47
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.