blob: 35f979023bbf3bef89d78256aeb55a48a3279b9a [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#include <iostream>
2#include <string>
3#include <cmath>
4#include <limits>
akmhoquec8a10f72014-04-25 18:42:55 -05005
akmhoquefdbddb12014-05-02 18:35:19 -05006
akmhoque53353462014-04-22 08:43:45 -05007#include "adjacent.hpp"
akmhoque674b0b12014-05-20 14:33:28 -05008#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -05009
10namespace nlsr {
11
akmhoque674b0b12014-05-20 14:33:28 -050012INIT_LOGGER("Adjacent");
13
akmhoque53353462014-04-22 08:43:45 -050014using namespace std;
15
akmhoque157b0a42014-05-13 00:26:37 -050016const float Adjacent::DEFAULT_LINK_COST = 10.0;
17
18Adjacent::Adjacent()
19 : m_name()
20 , m_connectingFaceUri()
21 , m_linkCost(DEFAULT_LINK_COST)
22 , m_status(ADJACENT_STATUS_INACTIVE)
23 , m_interestTimedOutNo(0)
24{
25}
26
27Adjacent::Adjacent(const ndn::Name& an)
28 : m_name(an)
29 , m_connectingFaceUri()
30 , m_linkCost(DEFAULT_LINK_COST)
31 , m_status(ADJACENT_STATUS_INACTIVE)
32 , m_interestTimedOutNo(0)
33 {
34 }
35
36Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
37 uint32_t s, uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -050038{
39 m_name = an;
akmhoque157b0a42014-05-13 00:26:37 -050040 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050041 m_linkCost = lc;
42 m_status = s;
43 m_interestTimedOutNo = iton;
44}
45
46bool
akmhoquefdbddb12014-05-02 18:35:19 -050047Adjacent::operator==(const Adjacent& adjacent) const
akmhoque53353462014-04-22 08:43:45 -050048{
akmhoquefdbddb12014-05-02 18:35:19 -050049 return (m_name == adjacent.getName()) &&
akmhoque157b0a42014-05-13 00:26:37 -050050 (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
akmhoquefdbddb12014-05-02 18:35:19 -050051 (std::abs(m_linkCost - adjacent.getLinkCost()) <
akmhoque53353462014-04-22 08:43:45 -050052 std::numeric_limits<double>::epsilon()) ;
53}
54
akmhoquefdbddb12014-05-02 18:35:19 -050055bool
akmhoque31d1d4b2014-05-05 22:08:14 -050056Adjacent::compare(const ndn::Name& adjacencyName)
akmhoque53353462014-04-22 08:43:45 -050057{
akmhoque31d1d4b2014-05-05 22:08:14 -050058 return m_name == adjacencyName;
akmhoquefdbddb12014-05-02 18:35:19 -050059}
60
akmhoque674b0b12014-05-20 14:33:28 -050061void
62Adjacent::writeLog()
63{
64 _LOG_DEBUG("Adjacent : " << m_name);
65 _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri);
66 _LOG_DEBUG("Link Cost: " << m_linkCost);
67 _LOG_DEBUG("Status: " << m_status);
68 _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo);
69}
70
akmhoquefdbddb12014-05-02 18:35:19 -050071std::ostream&
72operator<<(std::ostream& os, const Adjacent& adj)
73{
74 os << "Adjacent : " << adj.getName() << endl;
akmhoque157b0a42014-05-13 00:26:37 -050075 os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl;
akmhoque53353462014-04-22 08:43:45 -050076 os << "Link Cost: " << adj.getLinkCost() << endl;
77 os << "Status: " << adj.getStatus() << endl;
78 os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl;
79 return os;
80}
81
82} //namespace nlsr