blob: 7d1445e281f97c951ddac308617b1a37d69c70ea [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
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040033LinkService::~LinkService() = default;
Eric Newberrya98bf932015-09-21 00:58:47 -070034
35void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040036LinkService::setFaceAndTransport(Face& face, Transport& transport) noexcept
Eric Newberrya98bf932015-09-21 00:58:47 -070037{
38 BOOST_ASSERT(m_face == nullptr);
39 BOOST_ASSERT(m_transport == nullptr);
40
41 m_face = &face;
42 m_transport = &transport;
Eric Newberrya98bf932015-09-21 00:58:47 -070043}
44
45void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070046LinkService::sendInterest(const Interest& interest)
Eric Newberrya98bf932015-09-21 00:58:47 -070047{
48 BOOST_ASSERT(m_transport != nullptr);
49 NFD_LOG_FACE_TRACE(__func__);
50
Junxiao Shi57df2882015-11-11 06:12:35 -070051 ++this->nOutInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070052
Teng Liangf3bc3ae2020-06-08 10:19:25 -070053 doSendInterest(interest);
Eric Newberrya98bf932015-09-21 00:58:47 -070054}
55
56void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070057LinkService::sendData(const Data& data)
Eric Newberrya98bf932015-09-21 00:58:47 -070058{
59 BOOST_ASSERT(m_transport != nullptr);
60 NFD_LOG_FACE_TRACE(__func__);
61
Junxiao Shi57df2882015-11-11 06:12:35 -070062 ++this->nOutData;
Eric Newberrya98bf932015-09-21 00:58:47 -070063
Teng Liangf3bc3ae2020-06-08 10:19:25 -070064 doSendData(data);
Eric Newberrya98bf932015-09-21 00:58:47 -070065}
66
67void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070068LinkService::sendNack(const ndn::lp::Nack& nack)
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->nOutNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -070074
Teng Liangf3bc3ae2020-06-08 10:19:25 -070075 doSendNack(nack);
Eric Newberrya98bf932015-09-21 00:58:47 -070076}
77
78void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040079LinkService::receiveInterest(const Interest& interest, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -070080{
81 NFD_LOG_FACE_TRACE(__func__);
82
Junxiao Shi57df2882015-11-11 06:12:35 -070083 ++this->nInInterests;
Eric Newberrya98bf932015-09-21 00:58:47 -070084
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040085 afterReceiveInterest(interest, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -070086}
87
88void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040089LinkService::receiveData(const Data& data, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -070090{
91 NFD_LOG_FACE_TRACE(__func__);
92
Junxiao Shi57df2882015-11-11 06:12:35 -070093 ++this->nInData;
Eric Newberrya98bf932015-09-21 00:58:47 -070094
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040095 afterReceiveData(data, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -070096}
97
98void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040099LinkService::receiveNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700100{
101 NFD_LOG_FACE_TRACE(__func__);
102
Junxiao Shi57df2882015-11-11 06:12:35 -0700103 ++this->nInNacks;
Eric Newberrya98bf932015-09-21 00:58:47 -0700104
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400105 afterReceiveNack(nack, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700106}
107
Eric Newberry41aba102017-11-01 16:42:13 -0700108void
109LinkService::notifyDroppedInterest(const Interest& interest)
110{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700111 ++this->nInterestsExceededRetx;
Eric Newberry41aba102017-11-01 16:42:13 -0700112 onDroppedInterest(interest);
113}
114
Eric Newberrya98bf932015-09-21 00:58:47 -0700115std::ostream&
116operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
117{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700118 const Face* face = flh.obj.getFace();
Eric Newberrya98bf932015-09-21 00:58:47 -0700119 if (face == nullptr) {
120 os << "[id=0,local=unknown,remote=unknown] ";
121 }
122 else {
123 os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
124 << ",remote=" << face->getRemoteUri() << "] ";
125 }
126 return os;
127}
128
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400129} // namespace nfd::face