adjacent.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #include "adjacent.hpp"
22 #include "logger.hpp"
23 
24 #include <iostream>
25 #include <string>
26 #include <cmath>
27 #include <limits>
28 
29 namespace nlsr {
30 
31 INIT_LOGGER("Adjacent");
32 
33 const float Adjacent::DEFAULT_LINK_COST = 10.0;
34 
36  : m_name()
37  , m_faceUri()
38  , m_linkCost(DEFAULT_LINK_COST)
39  , m_status(STATUS_INACTIVE)
40  , m_interestTimedOutNo(0)
41  , m_faceId(0)
42 {
43 }
44 
45 Adjacent::Adjacent(const ndn::Name& an)
46  : m_name(an)
47  , m_faceUri()
48  , m_linkCost(DEFAULT_LINK_COST)
49  , m_status(STATUS_INACTIVE)
50  , m_interestTimedOutNo(0)
51  , m_faceId(0)
52  {
53  }
54 
55 Adjacent::Adjacent(const ndn::Name& an, const ndn::FaceUri& faceUri, double lc,
56  Status s, uint32_t iton, uint64_t faceId)
57  : m_name(an)
58  , m_faceUri(faceUri)
59  , m_linkCost(lc)
60  , m_status(s)
61  , m_interestTimedOutNo(iton)
62  , m_faceId(faceId)
63  {
64  }
65 
66 bool
67 Adjacent::operator==(const Adjacent& adjacent) const
68 {
69  return (m_name == adjacent.getName()) &&
70  (m_faceUri == adjacent.getFaceUri()) &&
71  (std::abs(m_linkCost - adjacent.getLinkCost()) <
72  std::numeric_limits<double>::epsilon());
73 }
74 
75 bool
76 Adjacent::operator<(const Adjacent& adjacent) const
77 {
78  return (m_name < adjacent.getName()) ||
79  (m_linkCost < adjacent.getLinkCost());
80 }
81 
82 std::ostream&
83 operator<<(std::ostream& os, const Adjacent& adjacent)
84 {
85  os << "Adjacent: " << adjacent.m_name << "\n Connecting FaceUri: " << adjacent.m_faceUri
86  << "\n Link cost: " << adjacent.m_linkCost << "\n Status: " << adjacent.m_status
87  << "\n Interest Timed Out: " << adjacent.m_interestTimedOutNo << std::endl;
88  return os;
89 }
90 
91 void
93 {
94  NLSR_LOG_DEBUG(*this);
95 }
96 
97 } // namespace nlsr
bool operator==(const Adjacent &adjacent) const
Equality is when name, Face URI, and link cost are all equal.
Definition: adjacent.cpp:67
const ndn::FaceUri & getFaceUri() const
Definition: adjacent.hpp:69
static const float DEFAULT_LINK_COST
Definition: adjacent.hpp:164
friend std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:83
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:41
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Definition: logger.hpp:35
const ndn::Name & getName() const
Definition: adjacent.hpp:57
bool operator<(const Adjacent &adjacent) const
Definition: adjacent.cpp:76
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void writeLog()
Definition: adjacent.cpp:92
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
uint64_t getLinkCost() const
Definition: adjacent.hpp:81