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 
27 #include <list>
28 #include <iostream>
29 #include <boost/cstdint.hpp>
30 
31 #include <ndn-cxx/name.hpp>
32 
33 namespace nlsr {
34 
35 class Map;
36 class RoutingTable;
37 class Nlsr;
38 
40 {
41 public:
43  {
44  }
45  RoutingTableCalculator(size_t nRouters)
46  {
47  m_nRouters = nRouters;
48  }
49 protected:
51  void
53 
55  void
56  initMatrix();
57 
63  void
64  makeAdjMatrix(Nlsr& pnlsr, Map pMap);
65 
66  void
68 
72  int
73  getNumOfLinkfromAdjMatrix(int sRouter);
74 
75  void
76  freeAdjMatrix();
82  void
83  adjustAdMatrix(int source, int link, double linkCost);
84 
96  void
97  getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
98 
100  void
101  allocateLinks();
102 
103  void
105 
106  void
107  freeLinks();
108 
109  void
110  freeLinksCosts();
111 
112  void
113  setNoLink(int nl)
114  {
115  vNoLink = nl;
116  }
117 
118 protected:
119  double** adjMatrix;
120  size_t m_nRouters;
121 
122  int vNoLink;
123  int* links;
124  double* linkCosts;
125 };
126 
128 {
129 public:
131  : RoutingTableCalculator(nRouters)
132  , EMPTY_PARENT(-12345)
133  , INF_DISTANCE(2147483647)
134  , NO_MAPPING_NUM(-1)
135  , NO_NEXT_HOP(-12345)
136  {
137  }
138 
139  void
140  calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
141 
142 private:
146  void
147  doDijkstraPathCalculation(int sourceRouter);
148 
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(Nlsr& pnlsr, 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  const int EMPTY_PARENT;
198  const double INF_DISTANCE;
199  const int NO_MAPPING_NUM;
200  const int NO_NEXT_HOP;
201 
202 };
203 
204 class AdjacencyList;
205 class Lsdb;
206 
208 {
209 public:
210  HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
211  : m_nRouters(nRouters)
212  , m_isDryRun(isDryRun)
213  , m_thisRouterName(thisRouterName)
214  {
215  }
216 
217  void
218  calculatePaths(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
219 
220 private:
221  double
222  getHyperbolicDistance(Map& map, Lsdb& lsdb, ndn::Name src, ndn::Name dest);
223 
224  void
225  addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt);
226 
227  double
228  calculateHyperbolicDistance(double rI, double rJ, double deltaTheta);
229 
230  double
231  calculateAngularDistance(std::vector<double> angleVectorI,
232  std::vector<double> angleVectorJ);
233 
234 private:
235  const size_t m_nRouters;
236  const bool m_isDryRun;
237  const ndn::Name m_thisRouterName;
238 
239  static const double MATH_PI;
240  static const double UNKNOWN_DISTANCE;
241  static const double UNKNOWN_RADIUS;
242 };
243 
244 } // namespace nlsr
245 
246 #endif // NLSR_ROUTING_TABLE_CALCULATOR_HPP
void getLinksFromAdjMatrix(int *links, double *linkCosts, int source)
Populates temp. variables with the link costs for some router.
void makeAdjMatrix(Nlsr &pnlsr, Map pMap)
Constructs an adj. matrix to calculate with.
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-2017, The University of Memphis, Regents of the University of California.
void initMatrix()
Zero every cell of the matrix to ensure that the memory is safe.
Copyright (c) 2014-2017, 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.