blob: 1fb1109d85698bd10337a4c499398e50f579ea55 [file] [log] [blame]
Junxiao Shi32bfeb32014-01-25 18:22:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "face.hpp"
Junxiao Shi16b8bc92014-02-17 22:24:55 -07008#include "core/logger.hpp"
Junxiao Shi32bfeb32014-01-25 18:22:02 -07009
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080010namespace nfd {
Junxiao Shi32bfeb32014-01-25 18:22:02 -070011
Davide Pesavento0ff10db2014-02-28 03:12:27 +010012NFD_LOG_INIT("Face")
Junxiao Shi16b8bc92014-02-17 22:24:55 -070013
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000014template<class Packet>
15static inline void
16increaseCounter(const Packet& packet, FaceCounter& counter)
17{
18 ++counter;
19}
20
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000021Face::Face(const FaceUri& uri, bool isLocal)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070022 : m_id(INVALID_FACEID)
Davide Pesavento0ff10db2014-02-28 03:12:27 +010023 , m_isLocal(isLocal)
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000024 , m_uri(uri)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070025{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000026 onReceiveInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getInInterest()));
27 onReceiveData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getInData()));
28 onSendInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getOutInterest()));
29 onSendData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getOutData()));
Junxiao Shi32bfeb32014-01-25 18:22:02 -070030}
31
32Face::~Face()
33{
34}
35
Junxiao Shi8c8d2182014-01-30 22:33:00 -070036FaceId
37Face::getId() const
38{
39 return m_id;
40}
41
Alexander Afanasyev46f66472014-01-31 16:50:58 -080042// this method is private and should be used only by the Forwarder
43void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070044Face::setId(FaceId faceId)
45{
46 m_id = faceId;
47}
48
Junxiao Shi32bfeb32014-01-25 18:22:02 -070049void
50Face::setDescription(const std::string& description)
51{
52 m_description = description;
53}
54
55const std::string&
56Face::getDescription() const
57{
58 return m_description;
59}
60
61bool
62Face::isMultiAccess() const
63{
64 return false;
65}
66
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080067bool
Davide Pesavento0ff10db2014-02-28 03:12:27 +010068Face::isUp() const
69{
70 return true;
71}
72
73bool
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080074Face::decodeAndDispatchInput(const Block& element)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070075{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080076 /// \todo Ensure lazy field decoding process
77
78 if (element.type() == tlv::Interest)
79 {
80 shared_ptr<Interest> i = make_shared<Interest>();
81 i->wireDecode(element);
82 this->onReceiveInterest(*i);
83 }
84 else if (element.type() == tlv::Data)
85 {
86 shared_ptr<Data> d = make_shared<Data>();
87 d->wireDecode(element);
88 this->onReceiveData(*d);
89 }
90 else
91 return false;
92
93 return true;
Junxiao Shi16b8bc92014-02-17 22:24:55 -070094}
Junxiao Shi32bfeb32014-01-25 18:22:02 -070095
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080096} //namespace nfd