routing-table-calculator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
23 #define NLSR_ROUTING_TABLE_CALCULATOR_HPP
24 
25 #include "common.hpp"
26 #include "lsa.hpp"
27 #include "conf-parameter.hpp"
28 
29 #include <list>
30 #include <iostream>
31 #include <boost/cstdint.hpp>
32 
33 #include <ndn-cxx/name.hpp>
34 
35 namespace nlsr {
36 
37 class Map;
38 class RoutingTable;
39 
41 {
42 public:
43  RoutingTableCalculator(size_t nRouters)
44  {
45  m_nRouters = nRouters;
46  }
47 
48 protected:
50  void
52 
55  void
56  initMatrix();
57 
62  void
63  makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap);
64 
68  void
69  writeAdjMatrixLog(const Map& map) const;
70 
74  int
75  getNumOfLinkfromAdjMatrix(int sRouter);
76 
77  void
78  freeAdjMatrix();
84  void
85  adjustAdMatrix(int source, int link, double linkCost);
86 
98  void
99  getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
100 
102  void
103  allocateLinks();
104 
105  void
107 
108  void
109  freeLinks();
110 
111  void
112  freeLinksCosts();
113 
114  void
115  setNoLink(int nl)
116  {
117  vNoLink = nl;
118  }
119 
120 protected:
121  double** adjMatrix;
122  size_t m_nRouters;
123 
124  int vNoLink;
125  int* links;
126  double* linkCosts;
127 
128 };
129 
131 {
132 public:
134  : RoutingTableCalculator(nRouters)
135  {
136  }
137 
138  void
139  calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
140  const std::list<AdjLsa>& adjLsaList);
141 
142 private:
146  void
147  doDijkstraPathCalculation(int sourceRouter);
148 
161  void
162  sortQueueByDistance(int* Q, double* dist, int start, int element);
163 
170  int
171  isNotExplored(int* Q, int u, int start, int element);
172 
173  void
174  addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
175  Map& pMap, uint32_t sourceRouter);
176 
181  int
182  getLsNextHop(int dest, int source);
183 
184  void
185  allocateParent();
186 
187  void
188  allocateDistance();
189 
190  void
191  freeParent();
192 
193  void
194  freeDistance();
195 
196 private:
197  int* m_parent;
198  double* m_distance;
199 
200  static const int EMPTY_PARENT;
201  static const double INF_DISTANCE;
202  static const int NO_MAPPING_NUM;
203  static const int NO_NEXT_HOP;
204 
205 };
206 
207 class AdjacencyList;
208 class Lsdb;
209 
211 {
212 public:
213  HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
214  : m_nRouters(nRouters)
215  , m_isDryRun(isDryRun)
216  , m_thisRouterName(thisRouterName)
217  {
218  }
219 
220  void
221  calculatePath(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
222 
223 private:
224  double
225  getHyperbolicDistance(Lsdb& lsdb, ndn::Name src, ndn::Name dest);
226 
227  void
228  addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt);
229 
230  double
231  calculateHyperbolicDistance(double rI, double rJ, double deltaTheta);
232 
233  double
234  calculateAngularDistance(std::vector<double> angleVectorI,
235  std::vector<double> angleVectorJ);
236 
237 private:
238  const size_t m_nRouters;
239  const bool m_isDryRun;
240  const ndn::Name m_thisRouterName;
241 
242  static const double MATH_PI;
243  static const double UNKNOWN_DISTANCE;
244  static const double UNKNOWN_RADIUS;
245 };
246 
247 } // namespace nlsr
248 
249 #endif // NLSR_ROUTING_TABLE_CALCULATOR_HPP
void writeAdjMatrixLog(const Map &map) const
Writes a formated adjacent matrix to DEBUG log.
A class to house all the configuration parameters for NLSR.
void getLinksFromAdjMatrix(int *links, double *linkCosts, int source)
Populates temp. variables with the link costs for some router.
void allocateAdjMatrix()
Allocate the space needed for the adj. matrix.
void adjustAdMatrix(int source, int link, double linkCost)
Adjust a link cost in the adj. matrix.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void makeAdjMatrix(const std::list< AdjLsa > &adjLsaList, Map &pMap)
Constructs an adj. matrix to calculate with.
void initMatrix()
set NON_ADJACENT_COST i.e. -12345 to every cell of the matrix to ensure that the memory is safe...
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
int getNumOfLinkfromAdjMatrix(int sRouter)
Returns how many links a router in the matrix has.