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 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 32 | Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 33 | : m_id(INVALID_FACEID) |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 34 | , m_isLocal(isLocal) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 35 | , m_remoteUri(remoteUri) |
| 36 | , m_localUri(localUri) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 37 | , m_isOnDemand(false) |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 38 | , m_isFailed(false) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 39 | { |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 40 | onReceiveInterest += bind(&PacketCounter::operator++, &m_counters.getNInInterests()); |
| 41 | onReceiveData += bind(&PacketCounter::operator++, &m_counters.getNInDatas()); |
| 42 | onSendInterest += bind(&PacketCounter::operator++, &m_counters.getNOutInterests()); |
| 43 | onSendData += bind(&PacketCounter::operator++, &m_counters.getNOutDatas()); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | Face::~Face() |
| 47 | { |
| 48 | } |
| 49 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 50 | FaceId |
| 51 | Face::getId() const |
| 52 | { |
| 53 | return m_id; |
| 54 | } |
| 55 | |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 56 | // this method is private and should be used only by the FaceTable |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 57 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 58 | Face::setId(FaceId faceId) |
| 59 | { |
| 60 | m_id = faceId; |
| 61 | } |
| 62 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 63 | void |
| 64 | Face::setDescription(const std::string& description) |
| 65 | { |
| 66 | m_description = description; |
| 67 | } |
| 68 | |
| 69 | const std::string& |
| 70 | Face::getDescription() const |
| 71 | { |
| 72 | return m_description; |
| 73 | } |
| 74 | |
| 75 | bool |
| 76 | Face::isMultiAccess() const |
| 77 | { |
| 78 | return false; |
| 79 | } |
| 80 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 81 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 82 | Face::isUp() const |
| 83 | { |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 88 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 89 | { |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 90 | try { |
| 91 | /// \todo Ensure lazy field decoding process |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 93 | if (element.type() == tlv::Interest) |
| 94 | { |
| 95 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 96 | i->wireDecode(element); |
| 97 | this->onReceiveInterest(*i); |
| 98 | } |
| 99 | else if (element.type() == tlv::Data) |
| 100 | { |
| 101 | shared_ptr<Data> d = make_shared<Data>(); |
| 102 | d->wireDecode(element); |
| 103 | this->onReceiveData(*d); |
| 104 | } |
| 105 | else |
| 106 | return false; |
| 107 | |
| 108 | return true; |
| 109 | } |
| 110 | catch (tlv::Error&) { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 111 | return false; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 112 | } |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 113 | } |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 114 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 115 | void |
| 116 | Face::fail(const std::string& reason) |
| 117 | { |
| 118 | if (m_isFailed) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | m_isFailed = true; |
| 123 | this->onFail(reason); |
Alexander Afanasyev | 583760b | 2014-06-30 19:27:37 -0700 | [diff] [blame] | 124 | |
| 125 | this->onFail.clear(); |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 128 | ndn::nfd::FaceStatus |
| 129 | Face::getFaceStatus() const |
| 130 | { |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 131 | ndn::nfd::FaceStatus status; |
| 132 | status.setFaceId(getId()) |
| 133 | .setRemoteUri(getRemoteUri().toString()) |
| 134 | .setLocalUri(getLocalUri().toString()) |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 135 | .setFlags(getFaceFlags(*this)); |
| 136 | |
| 137 | this->getCounters().copyTo(status); |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 138 | |
| 139 | return status; |
| 140 | } |
| 141 | |
| 142 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 143 | } //namespace nfd |