blob: 9dbce3014d4af1515993f4426e2f4e1a84aa54ec [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05003 * Copyright (c) 2014-2016, The University of Memphis,
4 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoquefdbddb12014-05-02 18:35:19 -050023#ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
24#define NLSR_ROUTING_TABLE_CALCULATOR_HPP
akmhoque53353462014-04-22 08:43:45 -050025
26#include <list>
27#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -050028#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050029
Vince Lehman9a709032014-09-13 16:28:07 -050030#include <ndn-cxx/name.hpp>
31
akmhoque53353462014-04-22 08:43:45 -050032namespace nlsr {
33
34class Map;
35class RoutingTable;
36class Nlsr;
37
38class RoutingTableCalculator
39{
40public:
41 RoutingTableCalculator()
42 {
43 }
Vince Lehman9a709032014-09-13 16:28:07 -050044 RoutingTableCalculator(size_t nRouters)
akmhoque53353462014-04-22 08:43:45 -050045 {
Vince Lehman9a709032014-09-13 16:28:07 -050046 m_nRouters = nRouters;
akmhoque53353462014-04-22 08:43:45 -050047 }
48protected:
49 void
50 allocateAdjMatrix();
51
52 void
53 initMatrix();
54
55 void
56 makeAdjMatrix(Nlsr& pnlsr, Map pMap);
Vince Lehman9a709032014-09-13 16:28:07 -050057
akmhoque2f423352014-06-03 11:49:35 -050058 void
59 writeAdjMatrixLog();
akmhoque53353462014-04-22 08:43:45 -050060
61 int
62 getNumOfLinkfromAdjMatrix(int sRouter);
63
64 void
65 freeAdjMatrix();
66
67 void
68 adjustAdMatrix(int source, int link, double linkCost);
69
70 void
71 getLinksFromAdjMatrix(int* links, double* linkCosts, int source);
72
73 void
74 allocateLinks();
75
76 void
77 allocateLinkCosts();
78
79 void
80 freeLinks();
81
82 void
83 freeLinksCosts();
84
85 void
86 setNoLink(int nl)
87 {
88 vNoLink = nl;
89 }
90
91protected:
92 double** adjMatrix;
Vince Lehman9a709032014-09-13 16:28:07 -050093 size_t m_nRouters;
akmhoque53353462014-04-22 08:43:45 -050094
95 int vNoLink;
96 int* links;
97 double* linkCosts;
98};
99
100class LinkStateRoutingTableCalculator: public RoutingTableCalculator
101{
102public:
Vince Lehman9a709032014-09-13 16:28:07 -0500103 LinkStateRoutingTableCalculator(size_t nRouters)
104 : RoutingTableCalculator(nRouters)
105 , EMPTY_PARENT(-12345)
akmhoque53353462014-04-22 08:43:45 -0500106 , INF_DISTANCE(2147483647)
107 , NO_MAPPING_NUM(-1)
108 , NO_NEXT_HOP(-12345)
109 {
akmhoque53353462014-04-22 08:43:45 -0500110 }
111
akmhoque53353462014-04-22 08:43:45 -0500112 void
113 calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
114
akmhoque53353462014-04-22 08:43:45 -0500115private:
116 void
117 doDijkstraPathCalculation(int sourceRouter);
118
119 void
120 sortQueueByDistance(int* Q, double* dist, int start, int element);
121
122 int
123 isNotExplored(int* Q, int u, int start, int element);
124
125 void
akmhoque53353462014-04-22 08:43:45 -0500126 addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
Vince Lehman9a709032014-09-13 16:28:07 -0500127 Map& pMap, uint32_t sourceRouter);
akmhoque53353462014-04-22 08:43:45 -0500128
129 int
130 getLsNextHop(int dest, int source);
131
132 void
133 allocateParent();
134
135 void
136 allocateDistance();
137
138 void
139 freeParent();
140
141 void
142 freeDistance();
143
akmhoque53353462014-04-22 08:43:45 -0500144private:
145 int* m_parent;
146 double* m_distance;
147
akmhoque53353462014-04-22 08:43:45 -0500148 const int EMPTY_PARENT;
149 const double INF_DISTANCE;
150 const int NO_MAPPING_NUM;
151 const int NO_NEXT_HOP;
152
153};
154
Vince Lehman9a709032014-09-13 16:28:07 -0500155class AdjacencyList;
156class Lsdb;
157
158class HyperbolicRoutingCalculator
akmhoque53353462014-04-22 08:43:45 -0500159{
160public:
Vince Lehman9a709032014-09-13 16:28:07 -0500161 HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName)
162 : m_nRouters(nRouters)
163 , m_isDryRun(isDryRun)
164 , m_thisRouterName(thisRouterName)
akmhoque53353462014-04-22 08:43:45 -0500165 {
akmhoque53353462014-04-22 08:43:45 -0500166 }
167
168 void
Vince Lehman9a709032014-09-13 16:28:07 -0500169 calculatePaths(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
akmhoque53353462014-04-22 08:43:45 -0500170
171private:
akmhoque53353462014-04-22 08:43:45 -0500172 double
Vince Lehman9a709032014-09-13 16:28:07 -0500173 getHyperbolicDistance(Map& map, Lsdb& lsdb, ndn::Name src, ndn::Name dest);
akmhoque53353462014-04-22 08:43:45 -0500174
175 void
Vince Lehman9a709032014-09-13 16:28:07 -0500176 addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt);
akmhoque53353462014-04-22 08:43:45 -0500177
178private:
Vince Lehman9a709032014-09-13 16:28:07 -0500179 const size_t m_nRouters;
180 const bool m_isDryRun;
181 const ndn::Name m_thisRouterName;
akmhoque53353462014-04-22 08:43:45 -0500182
Vince Lehman9a709032014-09-13 16:28:07 -0500183 static const double MATH_PI;
184 static const double UNKNOWN_DISTANCE;
185 static const double UNKNOWN_RADIUS;
186 static const int32_t ROUTER_NOT_FOUND;
akmhoque53353462014-04-22 08:43:45 -0500187};
188
189}//namespace nlsr
190
akmhoquefdbddb12014-05-02 18:35:19 -0500191#endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP