blob: 93507e082bc91931e46debae13471fe352bda4db [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)
Eric Newberrya98bf932015-09-21 00:58:47 -070038{
39}
40
41LinkService::~LinkService()
42{
43}
44
45void
46LinkService::setFaceAndTransport(LpFace& face, Transport& transport)
47{
48 BOOST_ASSERT(m_face == nullptr);
49 BOOST_ASSERT(m_transport == nullptr);
50
51 m_face = &face;
52 m_transport = &transport;
Eric Newberrya98bf932015-09-21 00:58:47 -070053}
54
55void
56LinkService::sendInterest(const Interest& interest)
57{
58 BOOST_ASSERT(m_transport != nullptr);
59 NFD_LOG_FACE_TRACE(__func__);
60
Junxiao Shi57df2882015-11-11 06:12:35 -070061 ++this->nOutInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070062
63 doSendInterest(interest);
64}
65
66void
67LinkService::sendData(const Data& data)
68{
69 BOOST_ASSERT(m_transport != nullptr);
70 NFD_LOG_FACE_TRACE(__func__);
71
Junxiao Shi57df2882015-11-11 06:12:35 -070072 ++this->nOutData;
Eric Newberrya98bf932015-09-21 00:58:47 -070073
74 doSendData(data);
75}
76
77void
78LinkService::sendNack(const ndn::lp::Nack& nack)
79{
80 BOOST_ASSERT(m_transport != nullptr);
81 NFD_LOG_FACE_TRACE(__func__);
82
Junxiao Shi57df2882015-11-11 06:12:35 -070083 ++this->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070084
85 doSendNack(nack);
86}
87
88void
89LinkService::receiveInterest(const Interest& interest)
90{
91 NFD_LOG_FACE_TRACE(__func__);
92
Junxiao Shi57df2882015-11-11 06:12:35 -070093 ++this->nInInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070094
95 afterReceiveInterest(interest);
96}
97
98void
99LinkService::receiveData(const Data& data)
100{
101 NFD_LOG_FACE_TRACE(__func__);
102
Junxiao Shi57df2882015-11-11 06:12:35 -0700103 ++this->nInData;
Eric Newberrya98bf932015-09-21 00:58:47 -0700104
105 afterReceiveData(data);
106}
107
108void
109LinkService::receiveNack(const ndn::lp::Nack& nack)
110{
111 NFD_LOG_FACE_TRACE(__func__);
112
Junxiao Shi57df2882015-11-11 06:12:35 -0700113 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700114
115 afterReceiveNack(nack);
116}
117
118std::ostream&
119operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
120{
121 const LpFace* face = flh.obj.getFace();
122 if (face == nullptr) {
123 os << "[id=0,local=unknown,remote=unknown] ";
124 }
125 else {
126 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
127 << ",remote=" << face->getRemoteUri() << "] ";
128 }
129 return os;
130}
131
132} // namespace face
133} // namespace nfd