Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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/>. |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face.hpp" |
| 27 | |
Davide Pesavento | be40fb1 | 2015-02-23 21:09:34 +0100 | [diff] [blame] | 28 | #include <ndn-cxx/management/nfd-face-event-notification.hpp> |
| 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 | |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame^] | 32 | Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal, bool isMultiAccess) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 33 | : m_id(INVALID_FACEID) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 34 | , m_remoteUri(remoteUri) |
| 35 | , m_localUri(localUri) |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame^] | 36 | , m_isLocal(isLocal) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 37 | , m_isOnDemand(false) |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame^] | 38 | , m_isMultiAccess(isMultiAccess) |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 39 | , m_isFailed(false) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 40 | { |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 41 | onReceiveInterest.connect([this] (const ndn::Interest&) { ++m_counters.getNInInterests(); }); |
| 42 | onReceiveData .connect([this] (const ndn::Data&) { ++m_counters.getNInDatas(); }); |
| 43 | onSendInterest .connect([this] (const ndn::Interest&) { ++m_counters.getNOutInterests(); }); |
| 44 | onSendData .connect([this] (const ndn::Data&) { ++m_counters.getNOutDatas(); }); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | Face::~Face() |
| 48 | { |
| 49 | } |
| 50 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 51 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 52 | Face::isUp() const |
| 53 | { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 58 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 59 | { |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 60 | try { |
| 61 | /// \todo Ensure lazy field decoding process |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 63 | if (element.type() == tlv::Interest) |
| 64 | { |
| 65 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 66 | i->wireDecode(element); |
| 67 | this->onReceiveInterest(*i); |
| 68 | } |
| 69 | else if (element.type() == tlv::Data) |
| 70 | { |
| 71 | shared_ptr<Data> d = make_shared<Data>(); |
| 72 | d->wireDecode(element); |
| 73 | this->onReceiveData(*d); |
| 74 | } |
| 75 | else |
| 76 | return false; |
| 77 | |
| 78 | return true; |
| 79 | } |
Davide Pesavento | 66ff098 | 2015-01-29 22:39:00 +0100 | [diff] [blame] | 80 | catch (const tlv::Error&) { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 81 | return false; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 82 | } |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 83 | } |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 84 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 85 | void |
| 86 | Face::fail(const std::string& reason) |
| 87 | { |
| 88 | if (m_isFailed) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | m_isFailed = true; |
| 93 | this->onFail(reason); |
| 94 | } |
| 95 | |
Chengyu Fan | f9c2bb1 | 2014-10-06 11:52:44 -0600 | [diff] [blame] | 96 | template<typename FaceTraits> |
| 97 | void |
| 98 | Face::copyStatusTo(FaceTraits& traits) const |
| 99 | { |
| 100 | traits.setFaceId(getId()) |
Davide Pesavento | 13b76f0 | 2015-02-26 03:59:54 +0100 | [diff] [blame] | 101 | .setRemoteUri(getRemoteUri().toString()) |
| 102 | .setLocalUri(getLocalUri().toString()) |
| 103 | .setFaceScope(isLocal() ? ndn::nfd::FACE_SCOPE_LOCAL |
| 104 | : ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 105 | .setFacePersistency(isOnDemand() ? ndn::nfd::FACE_PERSISTENCY_ON_DEMAND |
| 106 | : ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 107 | .setLinkType(isMultiAccess() ? ndn::nfd::LINK_TYPE_MULTI_ACCESS |
| 108 | : ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
Chengyu Fan | f9c2bb1 | 2014-10-06 11:52:44 -0600 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | template void |
| 112 | Face::copyStatusTo<ndn::nfd::FaceStatus>(ndn::nfd::FaceStatus&) const; |
| 113 | |
| 114 | template void |
| 115 | Face::copyStatusTo<ndn::nfd::FaceEventNotification>(ndn::nfd::FaceEventNotification&) const; |
| 116 | |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 117 | ndn::nfd::FaceStatus |
| 118 | Face::getFaceStatus() const |
| 119 | { |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 120 | ndn::nfd::FaceStatus status; |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 121 | |
Davide Pesavento | 13b76f0 | 2015-02-26 03:59:54 +0100 | [diff] [blame] | 122 | copyStatusTo(status); |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 123 | this->getCounters().copyTo(status); |
Alexander Afanasyev | e515f0a | 2014-06-30 15:28:10 -0700 | [diff] [blame] | 124 | |
| 125 | return status; |
| 126 | } |
| 127 | |
Davide Pesavento | 13b76f0 | 2015-02-26 03:59:54 +0100 | [diff] [blame] | 128 | } // namespace nfd |