blob: ccc61143e1dbc391648d6b790b27072d3258a00d [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, The University of Memphis,
Vince Lehman41b173e2015-05-07 14:13:26 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehman41b173e2015-05-07 14:13:26 -050021
akmhoque53353462014-04-22 08:43:45 -050022#include <iostream>
23#include <cmath>
24#include "lsdb.hpp"
25#include "routing-table-calculator.hpp"
26#include "map.hpp"
27#include "lsa.hpp"
28#include "nexthop.hpp"
29#include "nlsr.hpp"
akmhoque2f423352014-06-03 11:49:35 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
Vince Lehman9a709032014-09-13 16:28:07 -050032#include <boost/math/constants/constants.hpp>
33
akmhoque53353462014-04-22 08:43:45 -050034namespace nlsr {
35
akmhoque2f423352014-06-03 11:49:35 -050036INIT_LOGGER("RoutingTableCalculator");
akmhoque53353462014-04-22 08:43:45 -050037using namespace std;
38
39void
40RoutingTableCalculator::allocateAdjMatrix()
41{
Vince Lehman9a709032014-09-13 16:28:07 -050042 adjMatrix = new double*[m_nRouters];
43
44 for (size_t i = 0; i < m_nRouters; ++i) {
45 adjMatrix[i] = new double[m_nRouters];
akmhoque53353462014-04-22 08:43:45 -050046 }
47}
48
49void
50RoutingTableCalculator::initMatrix()
51{
Vince Lehman9a709032014-09-13 16:28:07 -050052 for (size_t i = 0; i < m_nRouters; i++) {
53 for (size_t j = 0; j < m_nRouters; j++) {
akmhoque53353462014-04-22 08:43:45 -050054 adjMatrix[i][j] = 0;
akmhoque157b0a42014-05-13 00:26:37 -050055 }
akmhoque53353462014-04-22 08:43:45 -050056 }
57}
58
59void
60RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
61{
62 std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
Vince Lehman9a709032014-09-13 16:28:07 -050063 for (std::list<AdjLsa>::iterator it = adjLsdb.begin(); it != adjLsdb.end() ; it++) {
64
65 int32_t row = pMap.getMappingNoByRouterName((*it).getOrigRouter());
66
akmhoque53353462014-04-22 08:43:45 -050067 std::list<Adjacent> adl = (*it).getAdl().getAdjList();
Vince Lehman9a709032014-09-13 16:28:07 -050068 for (std::list<Adjacent>::iterator itAdl = adl.begin(); itAdl != adl.end() ; itAdl++) {
69
70 int32_t col = pMap.getMappingNoByRouterName((*itAdl).getName());
akmhoque53353462014-04-22 08:43:45 -050071 double cost = (*itAdl).getLinkCost();
Vince Lehman9a709032014-09-13 16:28:07 -050072
73 if ((row >= 0 && row < static_cast<int32_t>(m_nRouters)) &&
74 (col >= 0 && col < static_cast<int32_t>(m_nRouters)))
75 {
akmhoque53353462014-04-22 08:43:45 -050076 adjMatrix[row][col] = cost;
77 }
78 }
79 }
Vince Lehman41b173e2015-05-07 14:13:26 -050080
81 // Links that do not have the same cost for both directions should have their
82 // costs corrected:
83 //
84 // If the cost of one side of the link is 0, both sides of the link should have their cost
85 // corrected to 0.
86 //
87 // Otherwise, both sides of the link should use the larger of the two costs.
88 //
89 for (size_t row = 0; row < m_nRouters; ++row) {
90 for (size_t col = 0; col < m_nRouters; ++col) {
91 double toCost = adjMatrix[row][col];
92 double fromCost = adjMatrix[col][row];
93
94 if (fromCost != toCost) {
95 double correctedCost = 0.0;
96
97 if (toCost != 0 && fromCost != 0) {
98 // If both sides of the link are up, use the larger cost
99 correctedCost = std::max(toCost, fromCost);
100 }
101
102 _LOG_WARN("Cost between [" << row << "][" << col << "] and [" << col << "][" << row <<
103 "] are not the same (" << toCost << " != " << fromCost << "). " <<
104 "Correcting to cost: " << correctedCost);
105
106 adjMatrix[row][col] = correctedCost;
107 adjMatrix[col][row] = correctedCost;
108 }
109 }
110 }
akmhoque53353462014-04-22 08:43:45 -0500111}
112
113void
akmhoque2f423352014-06-03 11:49:35 -0500114RoutingTableCalculator::writeAdjMatrixLog()
akmhoque53353462014-04-22 08:43:45 -0500115{
Vince Lehman9a709032014-09-13 16:28:07 -0500116 for (size_t i = 0; i < m_nRouters; i++) {
akmhoque2f423352014-06-03 11:49:35 -0500117 string line="";
Vince Lehman9a709032014-09-13 16:28:07 -0500118 for (size_t j = 0; j < m_nRouters; j++) {
akmhoque2f423352014-06-03 11:49:35 -0500119 line += boost::lexical_cast<std::string>(adjMatrix[i][j]);
120 line += " ";
akmhoque157b0a42014-05-13 00:26:37 -0500121 }
akmhoque2f423352014-06-03 11:49:35 -0500122 _LOG_DEBUG(line);
akmhoque53353462014-04-22 08:43:45 -0500123 }
124}
125
126void
127RoutingTableCalculator::adjustAdMatrix(int source, int link, double linkCost)
128{
Vince Lehman9a709032014-09-13 16:28:07 -0500129 for (int i = 0; i < static_cast<int>(m_nRouters); i++) {
akmhoque157b0a42014-05-13 00:26:37 -0500130 if (i == link) {
akmhoque53353462014-04-22 08:43:45 -0500131 adjMatrix[source][i] = linkCost;
132 }
akmhoque157b0a42014-05-13 00:26:37 -0500133 else {
akmhoque53353462014-04-22 08:43:45 -0500134 adjMatrix[source][i] = 0;
135 }
136 }
137}
138
139int
140RoutingTableCalculator::getNumOfLinkfromAdjMatrix(int sRouter)
141{
142 int noLink = 0;
Vince Lehman9a709032014-09-13 16:28:07 -0500143
144 for (size_t i = 0; i < m_nRouters; i++) {
akmhoque157b0a42014-05-13 00:26:37 -0500145 if (adjMatrix[sRouter][i] > 0) {
akmhoque53353462014-04-22 08:43:45 -0500146 noLink++;
147 }
148 }
149 return noLink;
150}
151
152void
153RoutingTableCalculator::getLinksFromAdjMatrix(int* links,
154 double* linkCosts, int source)
155{
156 int j = 0;
Vince Lehman9a709032014-09-13 16:28:07 -0500157
158 for (size_t i = 0; i < m_nRouters; i++) {
akmhoque157b0a42014-05-13 00:26:37 -0500159 if (adjMatrix[source][i] > 0) {
akmhoque53353462014-04-22 08:43:45 -0500160 links[j] = i;
161 linkCosts[j] = adjMatrix[source][i];
162 j++;
163 }
164 }
165}
166
167void
168RoutingTableCalculator::freeAdjMatrix()
169{
Vince Lehman9a709032014-09-13 16:28:07 -0500170 for (size_t i = 0; i < m_nRouters; ++i) {
akmhoque53353462014-04-22 08:43:45 -0500171 delete [] adjMatrix[i];
172 }
173 delete [] adjMatrix;
174}
175
176
177void
178RoutingTableCalculator::allocateLinks()
179{
180 links = new int[vNoLink];
181}
182
183void
184RoutingTableCalculator::allocateLinkCosts()
185{
186 linkCosts = new double[vNoLink];
187}
188
189
190void
191RoutingTableCalculator::freeLinks()
192{
193 delete [] links;
194}
195void
196RoutingTableCalculator::freeLinksCosts()
197{
198 delete [] linkCosts;
199}
200
201void
202LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
203 RoutingTable& rt, Nlsr& pnlsr)
204{
akmhoque2f423352014-06-03 11:49:35 -0500205 _LOG_DEBUG("LinkStateRoutingTableCalculator::calculatePath Called");
akmhoque53353462014-04-22 08:43:45 -0500206 allocateAdjMatrix();
207 initMatrix();
208 makeAdjMatrix(pnlsr, pMap);
akmhoque2f423352014-06-03 11:49:35 -0500209 writeAdjMatrixLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500210 int sourceRouter = pMap.getMappingNoByRouterName(pnlsr.getConfParameter().getRouterPrefix());
akmhoque53353462014-04-22 08:43:45 -0500211 allocateParent();
212 allocateDistance();
akmhoque157b0a42014-05-13 00:26:37 -0500213 if (pnlsr.getConfParameter().getMaxFacesPerPrefix() == 1) {
akmhoque53353462014-04-22 08:43:45 -0500214 // Single Path
215 doDijkstraPathCalculation(sourceRouter);
akmhoque53353462014-04-22 08:43:45 -0500216 // update routing table
217 addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, sourceRouter);
218 }
akmhoque157b0a42014-05-13 00:26:37 -0500219 else {
akmhoque53353462014-04-22 08:43:45 -0500220 // Multi Path
221 setNoLink(getNumOfLinkfromAdjMatrix(sourceRouter));
222 allocateLinks();
223 allocateLinkCosts();
224 getLinksFromAdjMatrix(links, linkCosts, sourceRouter);
akmhoque157b0a42014-05-13 00:26:37 -0500225 for (int i = 0 ; i < vNoLink; i++) {
akmhoque53353462014-04-22 08:43:45 -0500226 adjustAdMatrix(sourceRouter, links[i], linkCosts[i]);
akmhoque2f423352014-06-03 11:49:35 -0500227 writeAdjMatrixLog();
akmhoque53353462014-04-22 08:43:45 -0500228 doDijkstraPathCalculation(sourceRouter);
akmhoque53353462014-04-22 08:43:45 -0500229 //update routing table
230 addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, sourceRouter);
231 }
232 freeLinks();
233 freeLinksCosts();
234 }
235 freeParent();
236 freeDistance();
237 freeAdjMatrix();
238}
239
240void
241LinkStateRoutingTableCalculator::doDijkstraPathCalculation(int sourceRouter)
242{
243 int i;
244 int v, u;
Vince Lehman9a709032014-09-13 16:28:07 -0500245 int* Q = new int[m_nRouters];
akmhoque53353462014-04-22 08:43:45 -0500246 int head = 0;
247 /* Initiate the Parent */
Vince Lehman9a709032014-09-13 16:28:07 -0500248 for (i = 0 ; i < static_cast<int>(m_nRouters); i++) {
akmhoque53353462014-04-22 08:43:45 -0500249 m_parent[i] = EMPTY_PARENT;
250 m_distance[i] = INF_DISTANCE;
251 Q[i] = i;
252 }
akmhoque157b0a42014-05-13 00:26:37 -0500253 if (sourceRouter != NO_MAPPING_NUM) {
akmhoque53353462014-04-22 08:43:45 -0500254 m_distance[sourceRouter] = 0;
Vince Lehman9a709032014-09-13 16:28:07 -0500255 sortQueueByDistance(Q, m_distance, head, m_nRouters);
256 while (head < static_cast<int>(m_nRouters)) {
akmhoque53353462014-04-22 08:43:45 -0500257 u = Q[head];
akmhoque157b0a42014-05-13 00:26:37 -0500258 if (m_distance[u] == INF_DISTANCE) {
akmhoque53353462014-04-22 08:43:45 -0500259 break;
260 }
Vince Lehman9a709032014-09-13 16:28:07 -0500261 for (v = 0 ; v < static_cast<int>(m_nRouters); v++) {
akmhoque157b0a42014-05-13 00:26:37 -0500262 if (adjMatrix[u][v] > 0) {
Vince Lehman9a709032014-09-13 16:28:07 -0500263 if (isNotExplored(Q, v, head + 1, m_nRouters)) {
akmhoque157b0a42014-05-13 00:26:37 -0500264 if (m_distance[u] + adjMatrix[u][v] < m_distance[v]) {
akmhoque53353462014-04-22 08:43:45 -0500265 m_distance[v] = m_distance[u] + adjMatrix[u][v] ;
266 m_parent[v] = u;
267 }
268 }
269 }
270 }
271 head++;
Vince Lehman9a709032014-09-13 16:28:07 -0500272 sortQueueByDistance(Q, m_distance, head, m_nRouters);
akmhoque53353462014-04-22 08:43:45 -0500273 }
274 }
275 delete [] Q;
276}
277
278void
Vince Lehman9a709032014-09-13 16:28:07 -0500279LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
280 Map& pMap, uint32_t sourceRouter)
akmhoque53353462014-04-22 08:43:45 -0500281{
akmhoque2f423352014-06-03 11:49:35 -0500282 _LOG_DEBUG("LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called");
Vince Lehman9a709032014-09-13 16:28:07 -0500283
akmhoque53353462014-04-22 08:43:45 -0500284 int nextHopRouter = 0;
Vince Lehman9a709032014-09-13 16:28:07 -0500285
286 for (size_t i = 0; i < m_nRouters ; i++) {
akmhoque157b0a42014-05-13 00:26:37 -0500287 if (i != sourceRouter) {
Vince Lehman9a709032014-09-13 16:28:07 -0500288
akmhoque53353462014-04-22 08:43:45 -0500289 nextHopRouter = getLsNextHop(i, sourceRouter);
Vince Lehman9a709032014-09-13 16:28:07 -0500290
akmhoque157b0a42014-05-13 00:26:37 -0500291 if (nextHopRouter != NO_NEXT_HOP) {
Vince Lehman9a709032014-09-13 16:28:07 -0500292
akmhoque53353462014-04-22 08:43:45 -0500293 double routeCost = m_distance[i];
akmhoque31d1d4b2014-05-05 22:08:14 -0500294 ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(nextHopRouter);
akmhoque157b0a42014-05-13 00:26:37 -0500295 std::string nextHopFace =
296 pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFaceUri();
akmhoque53353462014-04-22 08:43:45 -0500297 // Add next hop to routing table
akmhoque157b0a42014-05-13 00:26:37 -0500298 NextHop nh(nextHopFace, routeCost);
akmhoque53353462014-04-22 08:43:45 -0500299 rt.addNextHop(pMap.getRouterNameByMappingNo(i), nh);
300 }
301 }
302 }
303}
304
305int
306LinkStateRoutingTableCalculator::getLsNextHop(int dest, int source)
307{
308 int nextHop = NO_NEXT_HOP;
akmhoque157b0a42014-05-13 00:26:37 -0500309 while (m_parent[dest] != EMPTY_PARENT) {
akmhoque53353462014-04-22 08:43:45 -0500310 nextHop = dest;
311 dest = m_parent[dest];
312 }
akmhoque157b0a42014-05-13 00:26:37 -0500313 if (dest != source) {
akmhoque53353462014-04-22 08:43:45 -0500314 nextHop = NO_NEXT_HOP;
315 }
316 return nextHop;
317}
318
319void
akmhoque53353462014-04-22 08:43:45 -0500320LinkStateRoutingTableCalculator::sortQueueByDistance(int* Q,
akmhoque2f423352014-06-03 11:49:35 -0500321 double* dist,
322 int start, int element)
akmhoque53353462014-04-22 08:43:45 -0500323{
akmhoque157b0a42014-05-13 00:26:37 -0500324 for (int i = start ; i < element ; i++) {
325 for (int j = i + 1; j < element; j++) {
326 if (dist[Q[j]] < dist[Q[i]]) {
akmhoque53353462014-04-22 08:43:45 -0500327 int tempU = Q[j];
328 Q[j] = Q[i];
329 Q[i] = tempU;
330 }
331 }
332 }
333}
334
335int
336LinkStateRoutingTableCalculator::isNotExplored(int* Q,
337 int u, int start, int element)
338{
339 int ret = 0;
akmhoque157b0a42014-05-13 00:26:37 -0500340 for (int i = start; i < element; i++) {
341 if (Q[i] == u) {
akmhoque53353462014-04-22 08:43:45 -0500342 ret = 1;
343 break;
344 }
345 }
346 return ret;
347}
348
349void
350LinkStateRoutingTableCalculator::allocateParent()
351{
Vince Lehman9a709032014-09-13 16:28:07 -0500352 m_parent = new int[m_nRouters];
akmhoque53353462014-04-22 08:43:45 -0500353}
354
355void
356LinkStateRoutingTableCalculator::allocateDistance()
357{
Vince Lehman9a709032014-09-13 16:28:07 -0500358 m_distance = new double[m_nRouters];
akmhoque53353462014-04-22 08:43:45 -0500359}
360
361void
362LinkStateRoutingTableCalculator::freeParent()
363{
364 delete [] m_parent;
365}
366
367void LinkStateRoutingTableCalculator::freeDistance()
368{
369 delete [] m_distance;
370}
371
Vince Lehman9a709032014-09-13 16:28:07 -0500372const double HyperbolicRoutingCalculator::MATH_PI = boost::math::constants::pi<double>();
akmhoque53353462014-04-22 08:43:45 -0500373
Vince Lehman9a709032014-09-13 16:28:07 -0500374const double HyperbolicRoutingCalculator::UNKNOWN_DISTANCE = -1.0;
375const double HyperbolicRoutingCalculator::UNKNOWN_RADIUS = -1.0;
376
377const int32_t HyperbolicRoutingCalculator::ROUTER_NOT_FOUND = -1.0;
akmhoque53353462014-04-22 08:43:45 -0500378
379void
Vince Lehman9a709032014-09-13 16:28:07 -0500380HyperbolicRoutingCalculator::calculatePaths(Map& map, RoutingTable& rt,
381 Lsdb& lsdb, AdjacencyList& adjacencies)
akmhoque53353462014-04-22 08:43:45 -0500382{
Vince Lehman9a709032014-09-13 16:28:07 -0500383 _LOG_TRACE("Calculating hyperbolic paths");
384
385 int thisRouter = map.getMappingNoByRouterName(m_thisRouterName);
386
387 // Iterate over directly connected neighbors
388 std::list<Adjacent> neighbors = adjacencies.getAdjList();
389 for (std::list<Adjacent>::iterator adj = neighbors.begin(); adj != neighbors.end(); ++adj) {
390
391 // Don't calculate nexthops using an inactive router
392 if (adj->getStatus() == Adjacent::STATUS_INACTIVE) {
393 _LOG_TRACE(adj->getName() << " is inactive; not using it as a nexthop");
394 continue;
395 }
396
397 ndn::Name srcRouterName = adj->getName();
398
399 // Don't calculate nexthops for this router to other routers
400 if (srcRouterName == m_thisRouterName) {
401 continue;
402 }
403
404 std::string srcFaceUri = adj->getConnectingFaceUri();
405
406 // Install nexthops for this router to the neighbor; direct neighbors have a 0 cost link
407 addNextHop(srcRouterName, srcFaceUri, 0, rt);
408
409 int src = map.getMappingNoByRouterName(srcRouterName);
410
411 if (src == ROUTER_NOT_FOUND) {
412 _LOG_WARN(adj->getName() << " does not exist in the router map!");
413 continue;
414 }
415
416 // Get hyperbolic distance from direct neighbor to every other router
417 for (int dest = 0; dest < static_cast<int>(m_nRouters); ++dest) {
418 // Don't calculate nexthops to this router or from a router to itself
419 if (dest != thisRouter && dest != src) {
420
421 ndn::Name destRouterName = map.getRouterNameByMappingNo(dest);
422
423 double distance = getHyperbolicDistance(map, lsdb, srcRouterName, destRouterName);
424
425 // Could not compute distance
426 if (distance == UNKNOWN_DISTANCE) {
427 _LOG_WARN("Could not calculate hyperbolic distance from " << srcRouterName << " to " <<
428 destRouterName);
429 continue;
akmhoque53353462014-04-22 08:43:45 -0500430 }
akmhoque53353462014-04-22 08:43:45 -0500431
Vince Lehman9a709032014-09-13 16:28:07 -0500432 addNextHop(destRouterName, srcFaceUri, distance, rt);
433 }
akmhoquedcee9362014-08-05 22:58:01 -0500434 }
akmhoque53353462014-04-22 08:43:45 -0500435 }
436}
437
438double
Vince Lehman9a709032014-09-13 16:28:07 -0500439HyperbolicRoutingCalculator::getHyperbolicDistance(Map& map, Lsdb& lsdb,
440 ndn::Name src, ndn::Name dest)
akmhoque53353462014-04-22 08:43:45 -0500441{
Vince Lehman9a709032014-09-13 16:28:07 -0500442 _LOG_TRACE("Calculating hyperbolic distance from " << src << " to " << dest);
akmhoquedcee9362014-08-05 22:58:01 -0500443
Vince Lehman9a709032014-09-13 16:28:07 -0500444 double distance = UNKNOWN_DISTANCE;
445
446 ndn::Name srcLsaKey = src;
447 srcLsaKey.append("coordinate");
448
449 CoordinateLsa* srcLsa = lsdb.findCoordinateLsa(srcLsaKey);
450
451 ndn::Name destLsaKey = dest;
452 destLsaKey.append("coordinate");
453
454 CoordinateLsa* destLsa = lsdb.findCoordinateLsa(destLsaKey);
455
456 // Coordinate LSAs do not exist for these routers
457 if (srcLsa == NULL || destLsa == NULL) {
458 return UNKNOWN_DISTANCE;
akmhoquedcee9362014-08-05 22:58:01 -0500459 }
460
akmhoquedcee9362014-08-05 22:58:01 -0500461 double srcTheta = srcLsa->getCorTheta();
akmhoquedcee9362014-08-05 22:58:01 -0500462 double destTheta = destLsa->getCorTheta();
463
akmhoque53353462014-04-22 08:43:45 -0500464 double diffTheta = fabs(srcTheta - destTheta);
Vince Lehman9a709032014-09-13 16:28:07 -0500465
akmhoque157b0a42014-05-13 00:26:37 -0500466 if (diffTheta > MATH_PI) {
akmhoque53353462014-04-22 08:43:45 -0500467 diffTheta = 2 * MATH_PI - diffTheta;
468 }
Vince Lehman9a709032014-09-13 16:28:07 -0500469
470 double srcRadius = srcLsa->getCorRadius();
471 double destRadius = destLsa->getCorRadius();
472
473 if (srcRadius == UNKNOWN_RADIUS && destRadius == UNKNOWN_RADIUS) {
474 return UNKNOWN_DISTANCE;
475 }
476
477 if (diffTheta == 0) {
478 distance = fabs(srcRadius - destRadius);
akmhoque53353462014-04-22 08:43:45 -0500479 }
akmhoque157b0a42014-05-13 00:26:37 -0500480 else {
Vince Lehman9a709032014-09-13 16:28:07 -0500481 distance = acosh((cosh(srcRadius) * cosh(destRadius)) -
482 (sinh(srcRadius) * sinh(destRadius) * cos(diffTheta)));
akmhoque53353462014-04-22 08:43:45 -0500483 }
Vince Lehman9a709032014-09-13 16:28:07 -0500484
485 _LOG_TRACE("Distance from " << src << " to " << dest << " is " << distance);
486
akmhoque53353462014-04-22 08:43:45 -0500487 return distance;
488}
489
Vince Lehman9a709032014-09-13 16:28:07 -0500490void HyperbolicRoutingCalculator::addNextHop(ndn::Name dest, std::string faceUri,
491 double cost, RoutingTable& rt)
akmhoque53353462014-04-22 08:43:45 -0500492{
Vince Lehman9a709032014-09-13 16:28:07 -0500493 NextHop hop(faceUri, cost);
Vince Lehman20fe4a92014-09-09 15:57:59 -0500494 hop.setHyperbolic(true);
akmhoque53353462014-04-22 08:43:45 -0500495
Vince Lehman9a709032014-09-13 16:28:07 -0500496 _LOG_TRACE("Calculated " << hop << " for destination: " << dest);
akmhoque53353462014-04-22 08:43:45 -0500497
Vince Lehman9a709032014-09-13 16:28:07 -0500498 if (m_isDryRun) {
499 rt.addNextHopToDryTable(dest, hop);
500 }
501 else {
502 rt.addNextHop(dest, hop);
503 }
akmhoque53353462014-04-22 08:43:45 -0500504}
505
Nick Gordonfad8e252016-08-11 14:21:38 -0500506} // namespace nlsr