blob: dd852ba286069338a267458a95125fd2340c5d86 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry41aba102017-11-01 16:42:13 -07002/*
Eric Newberry9d283ad2020-04-12 23:37:17 -07003 * Copyright (c) 2014-2020, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * 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
Davide Pesaventoa3148082018-04-12 18:21:54 -040032NFD_LOG_INIT(LinkService);
Eric Newberrya98bf932015-09-21 00:58:47 -070033
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
Teng Liangf3bc3ae2020-06-08 10:19:25 -070055LinkService::sendInterest(const Interest& interest)
Eric Newberrya98bf932015-09-21 00:58:47 -070056{
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
Teng Liangf3bc3ae2020-06-08 10:19:25 -070062 doSendInterest(interest);
Spyridon Mastorakis97209372016-09-20 19:49:21 -070063
64 afterSendInterest(interest);
Eric Newberrya98bf932015-09-21 00:58:47 -070065}
66
67void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070068LinkService::sendData(const Data& data)
Eric Newberrya98bf932015-09-21 00:58:47 -070069{
70 BOOST_ASSERT(m_transport != nullptr);
71 NFD_LOG_FACE_TRACE(__func__);
72
Junxiao Shi57df2882015-11-11 06:12:35 -070073 ++this->nOutData;
Eric Newberrya98bf932015-09-21 00:58:47 -070074
Teng Liangf3bc3ae2020-06-08 10:19:25 -070075 doSendData(data);
Spyridon Mastorakis97209372016-09-20 19:49:21 -070076
77 afterSendData(data);
Eric Newberrya98bf932015-09-21 00:58:47 -070078}
79
80void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070081LinkService::sendNack(const ndn::lp::Nack& nack)
Eric Newberrya98bf932015-09-21 00:58:47 -070082{
83 BOOST_ASSERT(m_transport != nullptr);
84 NFD_LOG_FACE_TRACE(__func__);
85
Junxiao Shi57df2882015-11-11 06:12:35 -070086 ++this->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070087
Teng Liangf3bc3ae2020-06-08 10:19:25 -070088 doSendNack(nack);
Spyridon Mastorakis97209372016-09-20 19:49:21 -070089
90 afterSendNack(nack);
Eric Newberrya98bf932015-09-21 00:58:47 -070091}
92
93void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040094LinkService::receiveInterest(const Interest& interest, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -070095{
96 NFD_LOG_FACE_TRACE(__func__);
97
Junxiao Shi57df2882015-11-11 06:12:35 -070098 ++this->nInInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070099
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400100 afterReceiveInterest(interest, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700101}
102
103void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400104LinkService::receiveData(const Data& data, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700105{
106 NFD_LOG_FACE_TRACE(__func__);
107
Junxiao Shi57df2882015-11-11 06:12:35 -0700108 ++this->nInData;
Eric Newberrya98bf932015-09-21 00:58:47 -0700109
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400110 afterReceiveData(data, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700111}
112
113void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400114LinkService::receiveNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700115{
116 NFD_LOG_FACE_TRACE(__func__);
117
Junxiao Shi57df2882015-11-11 06:12:35 -0700118 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700119
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400120 afterReceiveNack(nack, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700121}
122
Eric Newberry41aba102017-11-01 16:42:13 -0700123void
124LinkService::notifyDroppedInterest(const Interest& interest)
125{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700126 ++this->nInterestsExceededRetx;
Eric Newberry41aba102017-11-01 16:42:13 -0700127 onDroppedInterest(interest);
128}
129
Eric Newberrya98bf932015-09-21 00:58:47 -0700130std::ostream&
131operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
132{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700133 const Face* face = flh.obj.getFace();
Eric Newberrya98bf932015-09-21 00:58:47 -0700134 if (face == nullptr) {
135 os << "[id=0,local=unknown,remote=unknown] ";
136 }
137 else {
138 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
139 << ",remote=" << face->getRemoteUri() << "] ";
140 }
141 return os;
142}
143
144} // namespace face
145} // namespace nfd