blob: 45194ddbb286c9aa39ea48730e84100e4005b1d1 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, 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.
10 *
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 */
25
26#include "link-service.hpp"
27#include "lp-face.hpp"
28#include "transport.hpp"
29
30namespace nfd {
31namespace face {
32
33NFD_LOG_INIT("LinkService");
34
35LinkService::LinkService()
36 : m_face(nullptr)
37 , m_transport(nullptr)
Junxiao Shi57df2882015-11-11 06:12:35 -070038 , m_oldCounters(nullptr)
Eric Newberrya98bf932015-09-21 00:58:47 -070039{
40}
41
42LinkService::~LinkService()
43{
44}
45
46void
47LinkService::setFaceAndTransport(LpFace& face, Transport& transport)
48{
49 BOOST_ASSERT(m_face == nullptr);
50 BOOST_ASSERT(m_transport == nullptr);
51
52 m_face = &face;
53 m_transport = &transport;
Junxiao Shi57df2882015-11-11 06:12:35 -070054 m_oldCounters = &m_face->getMutableCounters();
Eric Newberrya98bf932015-09-21 00:58:47 -070055}
56
57void
58LinkService::sendInterest(const Interest& interest)
59{
60 BOOST_ASSERT(m_transport != nullptr);
61 NFD_LOG_FACE_TRACE(__func__);
62
Junxiao Shi57df2882015-11-11 06:12:35 -070063 ++this->nOutInterests;
64 ++m_oldCounters->getNOutInterests();
Eric Newberrya98bf932015-09-21 00:58:47 -070065
66 doSendInterest(interest);
67}
68
69void
70LinkService::sendData(const Data& data)
71{
72 BOOST_ASSERT(m_transport != nullptr);
73 NFD_LOG_FACE_TRACE(__func__);
74
Junxiao Shi57df2882015-11-11 06:12:35 -070075 ++this->nOutData;
76 ++m_oldCounters->getNOutDatas();
Eric Newberrya98bf932015-09-21 00:58:47 -070077
78 doSendData(data);
79}
80
81void
82LinkService::sendNack(const ndn::lp::Nack& nack)
83{
84 BOOST_ASSERT(m_transport != nullptr);
85 NFD_LOG_FACE_TRACE(__func__);
86
Junxiao Shi57df2882015-11-11 06:12:35 -070087 ++this->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070088
89 doSendNack(nack);
90}
91
92void
93LinkService::receiveInterest(const Interest& interest)
94{
95 NFD_LOG_FACE_TRACE(__func__);
96
Junxiao Shi57df2882015-11-11 06:12:35 -070097 ++this->nInInterests;
98 ++m_oldCounters->getNInInterests();
Eric Newberrya98bf932015-09-21 00:58:47 -070099
100 afterReceiveInterest(interest);
101}
102
103void
104LinkService::receiveData(const Data& data)
105{
106 NFD_LOG_FACE_TRACE(__func__);
107
Junxiao Shi57df2882015-11-11 06:12:35 -0700108 ++this->nInData;
109 ++m_oldCounters->getNInDatas();
Eric Newberrya98bf932015-09-21 00:58:47 -0700110
111 afterReceiveData(data);
112}
113
114void
115LinkService::receiveNack(const ndn::lp::Nack& nack)
116{
117 NFD_LOG_FACE_TRACE(__func__);
118
Junxiao Shi57df2882015-11-11 06:12:35 -0700119 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700120
121 afterReceiveNack(nack);
122}
123
124std::ostream&
125operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
126{
127 const LpFace* face = flh.obj.getFace();
128 if (face == nullptr) {
129 os << "[id=0,local=unknown,remote=unknown] ";
130 }
131 else {
132 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
133 << ",remote=" << face->getRemoteUri() << "] ";
134 }
135 return os;
136}
137
138} // namespace face
139} // namespace nfd