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 | 9bcbc7c | 2014-04-06 19:37:37 -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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 24 | |
| 25 | #include "face.hpp" |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 26 | #include "core/logger.hpp" |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 28 | namespace nfd { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 30 | static inline void |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 31 | increaseCounter(FaceCounter& counter) |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 32 | { |
| 33 | ++counter; |
| 34 | } |
| 35 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 36 | Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | : m_id(INVALID_FACEID) |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 38 | , m_isLocal(isLocal) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 39 | , m_remoteUri(remoteUri) |
| 40 | , m_localUri(localUri) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 41 | , m_isOnDemand(false) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 42 | { |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 43 | onReceiveInterest += bind(&increaseCounter, boost::ref(m_counters.getNInInterests())); |
| 44 | onReceiveData += bind(&increaseCounter, boost::ref(m_counters.getNInDatas())); |
| 45 | onSendInterest += bind(&increaseCounter, boost::ref(m_counters.getNOutInterests())); |
| 46 | onSendData += bind(&increaseCounter, boost::ref(m_counters.getNOutDatas())); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | Face::~Face() |
| 50 | { |
| 51 | } |
| 52 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 53 | FaceId |
| 54 | Face::getId() const |
| 55 | { |
| 56 | return m_id; |
| 57 | } |
| 58 | |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 59 | // this method is private and should be used only by the Forwarder |
| 60 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 61 | Face::setId(FaceId faceId) |
| 62 | { |
| 63 | m_id = faceId; |
| 64 | } |
| 65 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 66 | void |
| 67 | Face::setDescription(const std::string& description) |
| 68 | { |
| 69 | m_description = description; |
| 70 | } |
| 71 | |
| 72 | const std::string& |
| 73 | Face::getDescription() const |
| 74 | { |
| 75 | return m_description; |
| 76 | } |
| 77 | |
| 78 | bool |
| 79 | Face::isMultiAccess() const |
| 80 | { |
| 81 | return false; |
| 82 | } |
| 83 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 84 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 85 | Face::isUp() const |
| 86 | { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 91 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 92 | { |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame^] | 93 | try { |
| 94 | /// \todo Ensure lazy field decoding process |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame^] | 96 | if (element.type() == tlv::Interest) |
| 97 | { |
| 98 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 99 | i->wireDecode(element); |
| 100 | this->onReceiveInterest(*i); |
| 101 | } |
| 102 | else if (element.type() == tlv::Data) |
| 103 | { |
| 104 | shared_ptr<Data> d = make_shared<Data>(); |
| 105 | d->wireDecode(element); |
| 106 | this->onReceiveData(*d); |
| 107 | } |
| 108 | else |
| 109 | return false; |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | catch (tlv::Error&) { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 114 | return false; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame^] | 115 | } |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 116 | } |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 118 | } //namespace nfd |