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:
44  {
45  }
46  RoutingTableCalculator(size_t nRouters)
47  {
48  m_nRouters = nRouters;
49  }
50 protected:
52  void
54 
56  void
57  initMatrix();
58 
63  void
64  makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap);
65 
66  void
67  writeAdjMatrixLog(const Map& map) const;
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, ConfParameter& confParam,
141  const std::list<AdjLsa>& adjLsaList);
142 
143 private:
147  void
148  doDijkstraPathCalculation(int sourceRouter);
149 
159  void
160  sortQueueByDistance(int* Q, double* dist, int start, int element);
161 
168  int
169  isNotExplored(int* Q, int u, int start, int element);
170 
171  void
172  addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
173  Map& pMap, uint32_t sourceRouter);
174 
179  int
180  getLsNextHop(int dest, int source);
181 
182  void
183  allocateParent();
184 
185  void
186  allocateDistance();
187 
188  void
189  freeParent();
190 
191  void
192  freeDistance();
193 
194 private:
195  int* m_parent;
196  double* m_distance;
197 
198  const int EMPTY_PARENT;
199  const double INF_DISTANCE;
200  const int NO_MAPPING_NUM;
201  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
void writeAdjMatrixLog(const Map &map) const
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()
Zero 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.