blob: f27c4b84ce0c4aa202c6992f4a70f13b51009ad2 [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"
8
9namespace nlsr {
10
11using namespace std;
12
akmhoque157b0a42014-05-13 00:26:37 -050013const float Adjacent::DEFAULT_LINK_COST = 10.0;
14
15Adjacent::Adjacent()
16 : m_name()
17 , m_connectingFaceUri()
18 , m_linkCost(DEFAULT_LINK_COST)
19 , m_status(ADJACENT_STATUS_INACTIVE)
20 , m_interestTimedOutNo(0)
21{
22}
23
24Adjacent::Adjacent(const ndn::Name& an)
25 : m_name(an)
26 , m_connectingFaceUri()
27 , m_linkCost(DEFAULT_LINK_COST)
28 , m_status(ADJACENT_STATUS_INACTIVE)
29 , m_interestTimedOutNo(0)
30 {
31 }
32
33Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
34 uint32_t s, uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -050035{
36 m_name = an;
akmhoque157b0a42014-05-13 00:26:37 -050037 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050038 m_linkCost = lc;
39 m_status = s;
40 m_interestTimedOutNo = iton;
41}
42
43bool
akmhoquefdbddb12014-05-02 18:35:19 -050044Adjacent::operator==(const Adjacent& adjacent) const
akmhoque53353462014-04-22 08:43:45 -050045{
akmhoquefdbddb12014-05-02 18:35:19 -050046 return (m_name == adjacent.getName()) &&
akmhoque157b0a42014-05-13 00:26:37 -050047 (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
akmhoquefdbddb12014-05-02 18:35:19 -050048 (std::abs(m_linkCost - adjacent.getLinkCost()) <
akmhoque53353462014-04-22 08:43:45 -050049 std::numeric_limits<double>::epsilon()) ;
50}
51
akmhoquefdbddb12014-05-02 18:35:19 -050052bool
akmhoque31d1d4b2014-05-05 22:08:14 -050053Adjacent::compare(const ndn::Name& adjacencyName)
akmhoque53353462014-04-22 08:43:45 -050054{
akmhoque31d1d4b2014-05-05 22:08:14 -050055 return m_name == adjacencyName;
akmhoquefdbddb12014-05-02 18:35:19 -050056}
57
58std::ostream&
59operator<<(std::ostream& os, const Adjacent& adj)
60{
61 os << "Adjacent : " << adj.getName() << endl;
akmhoque157b0a42014-05-13 00:26:37 -050062 os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl;
akmhoque53353462014-04-22 08:43:45 -050063 os << "Link Cost: " << adj.getLinkCost() << endl;
64 os << "Status: " << adj.getStatus() << endl;
65 os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl;
66 return os;
67}
68
69} //namespace nlsr