akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame^] | 1 | /* -*- 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 | **/ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 23 | #include <iostream> |
| 24 | #include <string> |
| 25 | #include <cmath> |
| 26 | #include <limits> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 27 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 28 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | #include "adjacent.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 30 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | |
| 32 | namespace nlsr { |
| 33 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 34 | INIT_LOGGER("Adjacent"); |
| 35 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | using namespace std; |
| 37 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 38 | const float Adjacent::DEFAULT_LINK_COST = 10.0; |
| 39 | |
| 40 | Adjacent::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 | |
| 49 | Adjacent::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 | |
| 58 | Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc, |
| 59 | uint32_t s, uint32_t iton) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | { |
| 61 | m_name = an; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 62 | m_connectingFaceUri = cfu; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | m_linkCost = lc; |
| 64 | m_status = s; |
| 65 | m_interestTimedOutNo = iton; |
| 66 | } |
| 67 | |
| 68 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 69 | Adjacent::operator==(const Adjacent& adjacent) const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 70 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 71 | return (m_name == adjacent.getName()) && |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 72 | (m_connectingFaceUri == adjacent.getConnectingFaceUri()) && |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 73 | (std::abs(m_linkCost - adjacent.getLinkCost()) < |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | std::numeric_limits<double>::epsilon()) ; |
| 75 | } |
| 76 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 77 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | Adjacent::compare(const ndn::Name& adjacencyName) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 80 | return m_name == adjacencyName; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 81 | } |
| 82 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 83 | void |
| 84 | Adjacent::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 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 93 | std::ostream& |
| 94 | operator<<(std::ostream& os, const Adjacent& adj) |
| 95 | { |
| 96 | os << "Adjacent : " << adj.getName() << endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 97 | os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 98 | 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 |