blob: c4f131b9f9f96bdd7ddd96c621bfa157c2db06b6 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
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#include <iostream>
24#include <string>
25#include <cmath>
26#include <limits>
akmhoquec8a10f72014-04-25 18:42:55 -050027
akmhoquefdbddb12014-05-02 18:35:19 -050028
akmhoque53353462014-04-22 08:43:45 -050029#include "adjacent.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("Adjacent");
35
akmhoque53353462014-04-22 08:43:45 -050036using namespace std;
37
akmhoque157b0a42014-05-13 00:26:37 -050038const float Adjacent::DEFAULT_LINK_COST = 10.0;
39
40Adjacent::Adjacent()
41 : m_name()
42 , m_connectingFaceUri()
43 , m_linkCost(DEFAULT_LINK_COST)
44 , m_status(ADJACENT_STATUS_INACTIVE)
45 , m_interestTimedOutNo(0)
46{
47}
48
49Adjacent::Adjacent(const ndn::Name& an)
50 : m_name(an)
51 , m_connectingFaceUri()
52 , m_linkCost(DEFAULT_LINK_COST)
53 , m_status(ADJACENT_STATUS_INACTIVE)
54 , m_interestTimedOutNo(0)
55 {
56 }
57
58Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
59 uint32_t s, uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -050060{
61 m_name = an;
akmhoque157b0a42014-05-13 00:26:37 -050062 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050063 m_linkCost = lc;
64 m_status = s;
65 m_interestTimedOutNo = iton;
66}
67
68bool
akmhoquefdbddb12014-05-02 18:35:19 -050069Adjacent::operator==(const Adjacent& adjacent) const
akmhoque53353462014-04-22 08:43:45 -050070{
akmhoquefdbddb12014-05-02 18:35:19 -050071 return (m_name == adjacent.getName()) &&
akmhoque157b0a42014-05-13 00:26:37 -050072 (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
akmhoquefdbddb12014-05-02 18:35:19 -050073 (std::abs(m_linkCost - adjacent.getLinkCost()) <
akmhoque53353462014-04-22 08:43:45 -050074 std::numeric_limits<double>::epsilon()) ;
75}
76
akmhoquefdbddb12014-05-02 18:35:19 -050077bool
akmhoque31d1d4b2014-05-05 22:08:14 -050078Adjacent::compare(const ndn::Name& adjacencyName)
akmhoque53353462014-04-22 08:43:45 -050079{
akmhoque31d1d4b2014-05-05 22:08:14 -050080 return m_name == adjacencyName;
akmhoquefdbddb12014-05-02 18:35:19 -050081}
82
akmhoque674b0b12014-05-20 14:33:28 -050083void
84Adjacent::writeLog()
85{
86 _LOG_DEBUG("Adjacent : " << m_name);
87 _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri);
88 _LOG_DEBUG("Link Cost: " << m_linkCost);
89 _LOG_DEBUG("Status: " << m_status);
90 _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo);
91}
92
akmhoquefdbddb12014-05-02 18:35:19 -050093std::ostream&
94operator<<(std::ostream& os, const Adjacent& adj)
95{
96 os << "Adjacent : " << adj.getName() << endl;
akmhoque157b0a42014-05-13 00:26:37 -050097 os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl;
akmhoque53353462014-04-22 08:43:45 -050098 os << "Link Cost: " << adj.getLinkCost() << endl;
99 os << "Status: " << adj.getStatus() << endl;
100 os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl;
101 return os;
102}
103
104} //namespace nlsr