blob: 9d2368b67b5562d64ab00560b7d0519822b0d2b8 [file] [log] [blame]
Junxiao Shi32bfeb32014-01-25 18:22:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi08d07a72014-06-09 23:17:57 -07003 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shi32bfeb32014-01-25 18:22:02 -070025
26#include "face.hpp"
Junxiao Shi16b8bc92014-02-17 22:24:55 -070027#include "core/logger.hpp"
Junxiao Shi32bfeb32014-01-25 18:22:02 -070028
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080029namespace nfd {
Junxiao Shi32bfeb32014-01-25 18:22:02 -070030
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000031static inline void
Junxiao Shi79494162014-04-02 18:25:11 -070032increaseCounter(FaceCounter& counter)
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000033{
34 ++counter;
35}
36
Junxiao Shi79494162014-04-02 18:25:11 -070037Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070038 : m_id(INVALID_FACEID)
Davide Pesavento0ff10db2014-02-28 03:12:27 +010039 , m_isLocal(isLocal)
Junxiao Shi79494162014-04-02 18:25:11 -070040 , m_remoteUri(remoteUri)
41 , m_localUri(localUri)
Alexander Afanasyev355c0662014-03-20 18:08:17 -070042 , m_isOnDemand(false)
Junxiao Shi08d07a72014-06-09 23:17:57 -070043 , m_isFailed(false)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070044{
Alexander Afanasyevf6980282014-05-13 18:28:40 -070045 onReceiveInterest += bind(&increaseCounter, ref(m_counters.getNInInterests()));
46 onReceiveData += bind(&increaseCounter, ref(m_counters.getNInDatas()));
47 onSendInterest += bind(&increaseCounter, ref(m_counters.getNOutInterests()));
48 onSendData += bind(&increaseCounter, ref(m_counters.getNOutDatas()));
Junxiao Shi32bfeb32014-01-25 18:22:02 -070049}
50
51Face::~Face()
52{
53}
54
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055FaceId
56Face::getId() const
57{
58 return m_id;
59}
60
Alexander Afanasyev46f66472014-01-31 16:50:58 -080061// this method is private and should be used only by the Forwarder
62void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070063Face::setId(FaceId faceId)
64{
65 m_id = faceId;
66}
67
Junxiao Shi32bfeb32014-01-25 18:22:02 -070068void
69Face::setDescription(const std::string& description)
70{
71 m_description = description;
72}
73
74const std::string&
75Face::getDescription() const
76{
77 return m_description;
78}
79
80bool
81Face::isMultiAccess() const
82{
83 return false;
84}
85
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080086bool
Davide Pesavento0ff10db2014-02-28 03:12:27 +010087Face::isUp() const
88{
89 return true;
90}
91
92bool
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080093Face::decodeAndDispatchInput(const Block& element)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070094{
Alexander Afanasyev650028d2014-04-25 18:39:10 -070095 try {
96 /// \todo Ensure lazy field decoding process
Alexander Afanasyev355c0662014-03-20 18:08:17 -070097
Alexander Afanasyev650028d2014-04-25 18:39:10 -070098 if (element.type() == tlv::Interest)
99 {
100 shared_ptr<Interest> i = make_shared<Interest>();
101 i->wireDecode(element);
102 this->onReceiveInterest(*i);
103 }
104 else if (element.type() == tlv::Data)
105 {
106 shared_ptr<Data> d = make_shared<Data>();
107 d->wireDecode(element);
108 this->onReceiveData(*d);
109 }
110 else
111 return false;
112
113 return true;
114 }
115 catch (tlv::Error&) {
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800116 return false;
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700117 }
Junxiao Shi16b8bc92014-02-17 22:24:55 -0700118}
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700119
Junxiao Shi08d07a72014-06-09 23:17:57 -0700120void
121Face::fail(const std::string& reason)
122{
123 if (m_isFailed) {
124 return;
125 }
126
127 m_isFailed = true;
128 this->onFail(reason);
129}
130
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800131} //namespace nfd