blob: 00dd6f057e65ef244217bf356b3cd3f6d5065351 [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"
Junxiao Shicde37ad2015-12-24 01:02:05 -070027#include "face.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070028
29namespace nfd {
30namespace face {
31
32NFD_LOG_INIT("LinkService");
33
34LinkService::LinkService()
35 : m_face(nullptr)
36 , m_transport(nullptr)
Eric Newberrya98bf932015-09-21 00:58:47 -070037{
38}
39
40LinkService::~LinkService()
41{
42}
43
44void
Junxiao Shicde37ad2015-12-24 01:02:05 -070045LinkService::setFaceAndTransport(Face& face, Transport& transport)
Eric Newberrya98bf932015-09-21 00:58:47 -070046{
47 BOOST_ASSERT(m_face == nullptr);
48 BOOST_ASSERT(m_transport == nullptr);
49
50 m_face = &face;
51 m_transport = &transport;
Eric Newberrya98bf932015-09-21 00:58:47 -070052}
53
54void
55LinkService::sendInterest(const Interest& interest)
56{
57 BOOST_ASSERT(m_transport != nullptr);
58 NFD_LOG_FACE_TRACE(__func__);
59
Junxiao Shi57df2882015-11-11 06:12:35 -070060 ++this->nOutInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070061
62 doSendInterest(interest);
63}
64
65void
66LinkService::sendData(const Data& data)
67{
68 BOOST_ASSERT(m_transport != nullptr);
69 NFD_LOG_FACE_TRACE(__func__);
70
Junxiao Shi57df2882015-11-11 06:12:35 -070071 ++this->nOutData;
Eric Newberrya98bf932015-09-21 00:58:47 -070072
73 doSendData(data);
74}
75
76void
77LinkService::sendNack(const ndn::lp::Nack& nack)
78{
79 BOOST_ASSERT(m_transport != nullptr);
80 NFD_LOG_FACE_TRACE(__func__);
81
Junxiao Shi57df2882015-11-11 06:12:35 -070082 ++this->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070083
84 doSendNack(nack);
85}
86
87void
88LinkService::receiveInterest(const Interest& interest)
89{
90 NFD_LOG_FACE_TRACE(__func__);
91
Junxiao Shi57df2882015-11-11 06:12:35 -070092 ++this->nInInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070093
94 afterReceiveInterest(interest);
95}
96
97void
98LinkService::receiveData(const Data& data)
99{
100 NFD_LOG_FACE_TRACE(__func__);
101
Junxiao Shi57df2882015-11-11 06:12:35 -0700102 ++this->nInData;
Eric Newberrya98bf932015-09-21 00:58:47 -0700103
104 afterReceiveData(data);
105}
106
107void
108LinkService::receiveNack(const ndn::lp::Nack& nack)
109{
110 NFD_LOG_FACE_TRACE(__func__);
111
Junxiao Shi57df2882015-11-11 06:12:35 -0700112 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700113
114 afterReceiveNack(nack);
115}
116
117std::ostream&
118operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
119{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700120 const Face* face = flh.obj.getFace();
Eric Newberrya98bf932015-09-21 00:58:47 -0700121 if (face == nullptr) {
122 os << "[id=0,local=unknown,remote=unknown] ";
123 }
124 else {
125 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
126 << ",remote=" << face->getRemoteUri() << "] ";
127 }
128 return os;
129}
130
131} // namespace face
132} // namespace nfd