blob: d7233d038c52360a845afa5912874d5ea4ea4619 [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/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040029namespace nfd::face {
Eric Newberrya98bf932015-09-21 00:58:47 -070030
Davide Pesaventoa3148082018-04-12 18:21:54 -040031NFD_LOG_INIT(LinkService);
Eric Newberrya98bf932015-09-21 00:58:47 -070032
33LinkService::LinkService()
34 : m_face(nullptr)
35 , m_transport(nullptr)
Eric Newberrya98bf932015-09-21 00:58:47 -070036{
37}
38
39LinkService::~LinkService()
40{
41}
42
43void
Junxiao Shicde37ad2015-12-24 01:02:05 -070044LinkService::setFaceAndTransport(Face& face, Transport& transport)
Eric Newberrya98bf932015-09-21 00:58:47 -070045{
46 BOOST_ASSERT(m_face == nullptr);
47 BOOST_ASSERT(m_transport == nullptr);
48
49 m_face = &face;
50 m_transport = &transport;
Eric Newberrya98bf932015-09-21 00:58:47 -070051}
52
53void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070054LinkService::sendInterest(const Interest& interest)
Eric Newberrya98bf932015-09-21 00:58:47 -070055{
56 BOOST_ASSERT(m_transport != nullptr);
57 NFD_LOG_FACE_TRACE(__func__);
58
Junxiao Shi57df2882015-11-11 06:12:35 -070059 ++this->nOutInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070060
Teng Liangf3bc3ae2020-06-08 10:19:25 -070061 doSendInterest(interest);
Eric Newberrya98bf932015-09-21 00:58:47 -070062}
63
64void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070065LinkService::sendData(const Data& data)
Eric Newberrya98bf932015-09-21 00:58:47 -070066{
67 BOOST_ASSERT(m_transport != nullptr);
68 NFD_LOG_FACE_TRACE(__func__);
69
Junxiao Shi57df2882015-11-11 06:12:35 -070070 ++this->nOutData;
Eric Newberrya98bf932015-09-21 00:58:47 -070071
Teng Liangf3bc3ae2020-06-08 10:19:25 -070072 doSendData(data);
Eric Newberrya98bf932015-09-21 00:58:47 -070073}
74
75void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070076LinkService::sendNack(const ndn::lp::Nack& nack)
Eric Newberrya98bf932015-09-21 00:58:47 -070077{
78 BOOST_ASSERT(m_transport != nullptr);
79 NFD_LOG_FACE_TRACE(__func__);
80
Junxiao Shi57df2882015-11-11 06:12:35 -070081 ++this->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070082
Teng Liangf3bc3ae2020-06-08 10:19:25 -070083 doSendNack(nack);
Eric Newberrya98bf932015-09-21 00:58:47 -070084}
85
86void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040087LinkService::receiveInterest(const Interest& interest, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -070088{
89 NFD_LOG_FACE_TRACE(__func__);
90
Junxiao Shi57df2882015-11-11 06:12:35 -070091 ++this->nInInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070092
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040093 afterReceiveInterest(interest, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -070094}
95
96void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040097LinkService::receiveData(const Data& data, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -070098{
99 NFD_LOG_FACE_TRACE(__func__);
100
Junxiao Shi57df2882015-11-11 06:12:35 -0700101 ++this->nInData;
Eric Newberrya98bf932015-09-21 00:58:47 -0700102
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400103 afterReceiveData(data, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700104}
105
106void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400107LinkService::receiveNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700108{
109 NFD_LOG_FACE_TRACE(__func__);
110
Junxiao Shi57df2882015-11-11 06:12:35 -0700111 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700112
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400113 afterReceiveNack(nack, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700114}
115
Eric Newberry41aba102017-11-01 16:42:13 -0700116void
117LinkService::notifyDroppedInterest(const Interest& interest)
118{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700119 ++this->nInterestsExceededRetx;
Eric Newberry41aba102017-11-01 16:42:13 -0700120 onDroppedInterest(interest);
121}
122
Eric Newberrya98bf932015-09-21 00:58:47 -0700123std::ostream&
124operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
125{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700126 const Face* face = flh.obj.getFace();
Eric Newberrya98bf932015-09-21 00:58:47 -0700127 if (face == nullptr) {
128 os << "[id=0,local=unknown,remote=unknown] ";
129 }
130 else {
131 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
132 << ",remote=" << face->getRemoteUri() << "] ";
133 }
134 return os;
135}
136
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400137} // namespace nfd::face