blob: 89741e7ddde6cd325320226acef847fc5d48d9b2 [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 **/
akmhoque53353462014-04-22 08:43:45 -050023#ifndef NLSR_NEXTHOP_HPP
24#define NLSR_NEXTHOP_HPP
25
Vince Lehman20fe4a92014-09-09 15:57:59 -050026#include "test-access-control.hpp"
27
akmhoque53353462014-04-22 08:43:45 -050028#include <iostream>
akmhoque102aea42014-08-04 10:22:12 -050029#include <cmath>
akmhoquefdbddb12014-05-02 18:35:19 -050030#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33class NextHop
34{
35public:
36 NextHop()
akmhoque157b0a42014-05-13 00:26:37 -050037 : m_connectingFaceUri()
akmhoque53353462014-04-22 08:43:45 -050038 , m_routeCost(0)
Vince Lehman20fe4a92014-09-09 15:57:59 -050039 , m_isHyperbolic(false)
akmhoque53353462014-04-22 08:43:45 -050040 {
41 }
42
akmhoque157b0a42014-05-13 00:26:37 -050043 NextHop(const std::string& cfu, double rc)
Vince Lehman20fe4a92014-09-09 15:57:59 -050044 : m_isHyperbolic(false)
akmhoque53353462014-04-22 08:43:45 -050045 {
akmhoque157b0a42014-05-13 00:26:37 -050046 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050047 m_routeCost = rc;
48 }
49
akmhoque157b0a42014-05-13 00:26:37 -050050 const std::string&
51 getConnectingFaceUri() const
akmhoque53353462014-04-22 08:43:45 -050052 {
akmhoque157b0a42014-05-13 00:26:37 -050053 return m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -050054 }
55
56 void
akmhoque157b0a42014-05-13 00:26:37 -050057 setConnectingFaceUri(const std::string& cfu)
akmhoque53353462014-04-22 08:43:45 -050058 {
akmhoque157b0a42014-05-13 00:26:37 -050059 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050060 }
61
akmhoque102aea42014-08-04 10:22:12 -050062 uint64_t
Vince Lehman145064a2014-08-23 11:44:16 -050063 getRouteCostAsAdjustedInteger() const
64 {
Vince Lehman20fe4a92014-09-09 15:57:59 -050065 if (m_isHyperbolic) {
66 // Round the cost to better preserve decimal cost differences
67 // e.g. Without rounding: 12.3456 > 12.3454 -> 12345 = 12345
68 // With rounding: 12.3456 > 12.3454 -> 12346 > 12345
69 return static_cast<uint64_t>(round(m_routeCost*HYPERBOLIC_COST_ADJUSTMENT_FACTOR));
70 }
71 else {
72 return static_cast<uint64_t>(m_routeCost);
73 }
Vince Lehman145064a2014-08-23 11:44:16 -050074 }
75
76 double
akmhoque53353462014-04-22 08:43:45 -050077 getRouteCost() const
78 {
Vince Lehman145064a2014-08-23 11:44:16 -050079 return m_routeCost;
akmhoque53353462014-04-22 08:43:45 -050080 }
81
82 void
83 setRouteCost(double rc)
84 {
85 m_routeCost = rc;
86 }
87
Vince Lehman20fe4a92014-09-09 15:57:59 -050088 void
89 setHyperbolic(bool b)
90 {
91 m_isHyperbolic = b;
92 }
93
94 bool
95 isHyperbolic() const
96 {
97 return m_isHyperbolic;
98 }
99
akmhoque53353462014-04-22 08:43:45 -0500100private:
akmhoque157b0a42014-05-13 00:26:37 -0500101 std::string m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -0500102 double m_routeCost;
Vince Lehman20fe4a92014-09-09 15:57:59 -0500103 bool m_isHyperbolic;
104
105PUBLIC_WITH_TESTS_ELSE_PRIVATE:
106 /** \brief Used to adjust floating point route costs to integers
107 * Since NFD uses integer route costs in the FIB, hyperbolic paths with similar route costs
108 * will be rounded to integers and installed with identical nexthop costs.
109 *
110 * e.g. costs 12.34 and 12.35 will be equal in NFD's FIB
111 *
112 * This multiplier is used to differentiate similar route costs in the FIB.
113 *
114 * e.g costs 12.34 and 12.35 will be installed into NFD's FIB as 12340 and 12350
115 */
116 static const uint64_t HYPERBOLIC_COST_ADJUSTMENT_FACTOR = 1000;
akmhoque53353462014-04-22 08:43:45 -0500117};
118
Vince Lehman9a709032014-09-13 16:28:07 -0500119std::ostream&
120operator<<(std::ostream& os, const NextHop& hop);
121
akmhoque53353462014-04-22 08:43:45 -0500122}//namespace nlsr
123
124#endif //NLSR_NEXTHOP_HPP