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 | |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 30 | NFD_LOG_INIT("Face") |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -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 | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 44 | { |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 45 | onReceiveInterest += bind(&increaseCounter, boost::ref(m_counters.getNInInterests())); |
| 46 | onReceiveData += bind(&increaseCounter, boost::ref(m_counters.getNInDatas())); |
| 47 | onSendInterest += bind(&increaseCounter, boost::ref(m_counters.getNOutInterests())); |
| 48 | onSendData += bind(&increaseCounter, boost::ref(m_counters.getNOutDatas())); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | Face::~Face() |
| 52 | { |
| 53 | } |
| 54 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 55 | FaceId |
| 56 | Face::getId() const |
| 57 | { |
| 58 | return m_id; |
| 59 | } |
| 60 | |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 61 | // this method is private and should be used only by the Forwarder |
| 62 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 63 | Face::setId(FaceId faceId) |
| 64 | { |
| 65 | m_id = faceId; |
| 66 | } |
| 67 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 68 | void |
| 69 | Face::setDescription(const std::string& description) |
| 70 | { |
| 71 | m_description = description; |
| 72 | } |
| 73 | |
| 74 | const std::string& |
| 75 | Face::getDescription() const |
| 76 | { |
| 77 | return m_description; |
| 78 | } |
| 79 | |
| 80 | bool |
| 81 | Face::isMultiAccess() const |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 86 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 87 | Face::isUp() const |
| 88 | { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 93 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 94 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 95 | /// \todo Ensure lazy field decoding process |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 97 | if (element.type() == tlv::Interest) |
| 98 | { |
| 99 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 100 | i->wireDecode(element); |
| 101 | this->onReceiveInterest(*i); |
| 102 | } |
| 103 | else if (element.type() == tlv::Data) |
| 104 | { |
| 105 | shared_ptr<Data> d = make_shared<Data>(); |
| 106 | d->wireDecode(element); |
| 107 | this->onReceiveData(*d); |
| 108 | } |
| 109 | else |
| 110 | return false; |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 112 | return true; |
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 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 115 | } //namespace nfd |