blob: 46dbcf64062b90e97d193364368dc0b3d89e8ea5 [file] [log] [blame]
Junxiao Shi32bfeb32014-01-25 18:22:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
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 Shi32bfeb32014-01-25 18:22:02 -070024
25#include "face.hpp"
Junxiao Shi16b8bc92014-02-17 22:24:55 -070026#include "core/logger.hpp"
Junxiao Shi32bfeb32014-01-25 18:22:02 -070027
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080028namespace nfd {
Junxiao Shi32bfeb32014-01-25 18:22:02 -070029
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000030static inline void
Junxiao Shi79494162014-04-02 18:25:11 -070031increaseCounter(FaceCounter& counter)
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000032{
33 ++counter;
34}
35
Junxiao Shi79494162014-04-02 18:25:11 -070036Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037 : m_id(INVALID_FACEID)
Davide Pesavento0ff10db2014-02-28 03:12:27 +010038 , m_isLocal(isLocal)
Junxiao Shi79494162014-04-02 18:25:11 -070039 , m_remoteUri(remoteUri)
40 , m_localUri(localUri)
Alexander Afanasyev355c0662014-03-20 18:08:17 -070041 , m_isOnDemand(false)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070042{
Junxiao Shi6e694322014-04-03 10:27:13 -070043 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 Shi32bfeb32014-01-25 18:22:02 -070047}
48
49Face::~Face()
50{
51}
52
Junxiao Shi8c8d2182014-01-30 22:33:00 -070053FaceId
54Face::getId() const
55{
56 return m_id;
57}
58
Alexander Afanasyev46f66472014-01-31 16:50:58 -080059// this method is private and should be used only by the Forwarder
60void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070061Face::setId(FaceId faceId)
62{
63 m_id = faceId;
64}
65
Junxiao Shi32bfeb32014-01-25 18:22:02 -070066void
67Face::setDescription(const std::string& description)
68{
69 m_description = description;
70}
71
72const std::string&
73Face::getDescription() const
74{
75 return m_description;
76}
77
78bool
79Face::isMultiAccess() const
80{
81 return false;
82}
83
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080084bool
Davide Pesavento0ff10db2014-02-28 03:12:27 +010085Face::isUp() const
86{
87 return true;
88}
89
90bool
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080091Face::decodeAndDispatchInput(const Block& element)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070092{
Alexander Afanasyev650028d2014-04-25 18:39:10 -070093 try {
94 /// \todo Ensure lazy field decoding process
Alexander Afanasyev355c0662014-03-20 18:08:17 -070095
Alexander Afanasyev650028d2014-04-25 18:39:10 -070096 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 Afanasyevbd220a02014-02-20 00:29:56 -0800114 return false;
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700115 }
Junxiao Shi16b8bc92014-02-17 22:24:55 -0700116}
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700117
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800118} //namespace nfd