Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | **/ |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face.hpp" |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame^] | 27 | #include "face-flags.hpp" |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 28 | #include "core/logger.hpp" |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 30 | namespace nfd { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 32 | static inline void |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 33 | increaseCounter(FaceCounter& counter) |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 34 | { |
| 35 | ++counter; |
| 36 | } |
| 37 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 38 | Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 39 | : m_id(INVALID_FACEID) |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 40 | , m_isLocal(isLocal) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 41 | , m_remoteUri(remoteUri) |
| 42 | , m_localUri(localUri) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 43 | , m_isOnDemand(false) |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 44 | , m_isFailed(false) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 45 | { |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 46 | onReceiveInterest += bind(&increaseCounter, ref(m_counters.getNInInterests())); |
| 47 | onReceiveData += bind(&increaseCounter, ref(m_counters.getNInDatas())); |
| 48 | onSendInterest += bind(&increaseCounter, ref(m_counters.getNOutInterests())); |
| 49 | onSendData += bind(&increaseCounter, ref(m_counters.getNOutDatas())); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | Face::~Face() |
| 53 | { |
| 54 | } |
| 55 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 56 | FaceId |
| 57 | Face::getId() const |
| 58 | { |
| 59 | return m_id; |
| 60 | } |
| 61 | |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 62 | // this method is private and should be used only by the Forwarder |
| 63 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 64 | Face::setId(FaceId faceId) |
| 65 | { |
| 66 | m_id = faceId; |
| 67 | } |
| 68 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 69 | void |
| 70 | Face::setDescription(const std::string& description) |
| 71 | { |
| 72 | m_description = description; |
| 73 | } |
| 74 | |
| 75 | const std::string& |
| 76 | Face::getDescription() const |
| 77 | { |
| 78 | return m_description; |
| 79 | } |
| 80 | |
| 81 | bool |
| 82 | Face::isMultiAccess() const |
| 83 | { |
| 84 | return false; |
| 85 | } |
| 86 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 87 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 88 | Face::isUp() const |
| 89 | { |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 94 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 95 | { |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 96 | try { |
| 97 | /// \todo Ensure lazy field decoding process |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 99 | if (element.type() == tlv::Interest) |
| 100 | { |
| 101 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 102 | i->wireDecode(element); |
| 103 | this->onReceiveInterest(*i); |
| 104 | } |
| 105 | else if (element.type() == tlv::Data) |
| 106 | { |
| 107 | shared_ptr<Data> d = make_shared<Data>(); |
| 108 | d->wireDecode(element); |
| 109 | this->onReceiveData(*d); |
| 110 | } |
| 111 | else |
| 112 | return false; |
| 113 | |
| 114 | return true; |
| 115 | } |
| 116 | catch (tlv::Error&) { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 117 | return false; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 118 | } |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 119 | } |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 120 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 121 | void |
| 122 | Face::fail(const std::string& reason) |
| 123 | { |
| 124 | if (m_isFailed) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | m_isFailed = true; |
| 129 | this->onFail(reason); |
| 130 | } |
| 131 | |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame^] | 132 | ndn::nfd::FaceStatus |
| 133 | Face::getFaceStatus() const |
| 134 | { |
| 135 | const FaceCounters& counters = getCounters(); |
| 136 | |
| 137 | ndn::nfd::FaceStatus status; |
| 138 | status.setFaceId(getId()) |
| 139 | .setRemoteUri(getRemoteUri().toString()) |
| 140 | .setLocalUri(getLocalUri().toString()) |
| 141 | .setFlags(getFaceFlags(*this)) |
| 142 | .setNInInterests(counters.getNInInterests()) |
| 143 | .setNInDatas(counters.getNInDatas()) |
| 144 | .setNOutInterests(counters.getNOutInterests()) |
| 145 | .setNOutDatas(counters.getNOutDatas()); |
| 146 | |
| 147 | return status; |
| 148 | } |
| 149 | |
| 150 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 151 | } //namespace nfd |