blob: f5516869a8bb7bd7f702b7b4e365aa428816bb15 [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)
akmhoquec04e7272014-07-02 11:00:14 -050046 , m_faceId(0)
akmhoque157b0a42014-05-13 00:26:37 -050047{
48}
49
50Adjacent::Adjacent(const ndn::Name& an)
51 : m_name(an)
52 , m_connectingFaceUri()
53 , m_linkCost(DEFAULT_LINK_COST)
54 , m_status(ADJACENT_STATUS_INACTIVE)
55 , m_interestTimedOutNo(0)
akmhoquec04e7272014-07-02 11:00:14 -050056 , m_faceId(0)
akmhoque157b0a42014-05-13 00:26:37 -050057 {
58 }
59
60Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
akmhoquec04e7272014-07-02 11:00:14 -050061 uint32_t s, uint32_t iton, uint64_t faceId)
62 : m_name(an)
63 , m_connectingFaceUri(cfu)
64 , m_linkCost(lc)
65 , m_status(s)
66 , m_interestTimedOutNo(iton)
67 , m_faceId(faceId)
68 {
69
70 }
akmhoque53353462014-04-22 08:43:45 -050071
72bool
akmhoquefdbddb12014-05-02 18:35:19 -050073Adjacent::operator==(const Adjacent& adjacent) const
akmhoque53353462014-04-22 08:43:45 -050074{
akmhoquefdbddb12014-05-02 18:35:19 -050075 return (m_name == adjacent.getName()) &&
akmhoque157b0a42014-05-13 00:26:37 -050076 (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
akmhoquefdbddb12014-05-02 18:35:19 -050077 (std::abs(m_linkCost - adjacent.getLinkCost()) <
akmhoque53353462014-04-22 08:43:45 -050078 std::numeric_limits<double>::epsilon()) ;
79}
80
akmhoque674b0b12014-05-20 14:33:28 -050081void
82Adjacent::writeLog()
83{
84 _LOG_DEBUG("Adjacent : " << m_name);
85 _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri);
86 _LOG_DEBUG("Link Cost: " << m_linkCost);
87 _LOG_DEBUG("Status: " << m_status);
88 _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo);
89}
90
akmhoque53353462014-04-22 08:43:45 -050091} //namespace nlsr