route/nexthop.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef NLSR_NEXTHOP_HPP
21 #define NLSR_NEXTHOP_HPP
22 
23 #include "test-access-control.hpp"
24 
25 #include <iostream>
26 #include <cmath>
27 #include <boost/cstdint.hpp>
28 
29 namespace nlsr {
30 class NextHop
31 {
32 public:
34  : m_connectingFaceUri()
35  , m_routeCost(0)
36  , m_isHyperbolic(false)
37  {
38  }
39 
40  NextHop(const std::string& cfu, double rc)
41  : m_isHyperbolic(false)
42  {
43  m_connectingFaceUri = cfu;
44  m_routeCost = rc;
45  }
46 
47  const std::string&
49  {
50  return m_connectingFaceUri;
51  }
52 
53  void
54  setConnectingFaceUri(const std::string& cfu)
55  {
56  m_connectingFaceUri = cfu;
57  }
58 
59  uint64_t
61  {
62  if (m_isHyperbolic) {
63  // Round the cost to better preserve decimal cost differences
64  // e.g. Without rounding: 12.3456 > 12.3454 -> 12345 = 12345
65  // With rounding: 12.3456 > 12.3454 -> 12346 > 12345
66  return static_cast<uint64_t>(round(m_routeCost*HYPERBOLIC_COST_ADJUSTMENT_FACTOR));
67  }
68  else {
69  return static_cast<uint64_t>(m_routeCost);
70  }
71  }
72 
73  double
74  getRouteCost() const
75  {
76  return m_routeCost;
77  }
78 
79  void
80  setRouteCost(const double rc)
81  {
82  m_routeCost = rc;
83  }
84 
85  void
86  setHyperbolic(bool b)
87  {
88  m_isHyperbolic = b;
89  }
90 
91  bool
92  isHyperbolic() const
93  {
94  return m_isHyperbolic;
95  }
96 
97 private:
98  std::string m_connectingFaceUri;
99  double m_routeCost;
100  bool m_isHyperbolic;
101 
113  static const uint64_t HYPERBOLIC_COST_ADJUSTMENT_FACTOR = 1000;
114 };
115 
116 bool
117 operator==(const NextHop& lhs, const NextHop& rhs);
118 
119 std::ostream&
120 operator<<(std::ostream& os, const NextHop& hop);
121 
122 } // namespace nlsr
123 
124 #endif //NLSR_NEXTHOP_HPP
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:84
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
bool operator==(const NamePrefixTableEntry &lhs, const NamePrefixTableEntry &rhs)
NextHop(const std::string &cfu, double rc)
void setRouteCost(const double rc)
const std::string & getConnectingFaceUri() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
bool isHyperbolic() const
void setConnectingFaceUri(const std::string &cfu)
void setHyperbolic(bool b)
uint64_t getRouteCostAsAdjustedInteger() const
double getRouteCost() const