blob: e62c1a30eb644a907e77e4276058593a028e6682 [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 Pesaventob7bfcb92022-05-22 23:55: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#ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP
27#define NFD_DAEMON_FACE_LINK_SERVICE_HPP
28
Davide Pesaventocb425e82019-07-14 21:48:22 -040029#include "face-common.hpp"
Eric Newberry41aba102017-11-01 16:42:13 -070030#include "transport.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040031#include "common/counter.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070032
33namespace nfd {
34namespace face {
35
Junxiao Shi57df2882015-11-11 06:12:35 -070036/** \brief counters provided by LinkService
37 * \note The type name 'LinkServiceCounters' is implementation detail.
38 * Use 'LinkService::Counters' in public API.
39 */
40class LinkServiceCounters
41{
42public:
43 /** \brief count of incoming Interests
44 */
45 PacketCounter nInInterests;
46
47 /** \brief count of outgoing Interests
48 */
49 PacketCounter nOutInterests;
50
Eric Newberry41aba102017-11-01 16:42:13 -070051 /** \brief count of Interests dropped by reliability system for exceeding allowed number of retx
52 */
Eric Newberry9d283ad2020-04-12 23:37:17 -070053 PacketCounter nInterestsExceededRetx;
Eric Newberry41aba102017-11-01 16:42:13 -070054
55 /** \brief count of incoming Data packets
Junxiao Shi57df2882015-11-11 06:12:35 -070056 */
57 PacketCounter nInData;
58
Eric Newberry41aba102017-11-01 16:42:13 -070059 /** \brief count of outgoing Data packets
Junxiao Shi57df2882015-11-11 06:12:35 -070060 */
61 PacketCounter nOutData;
62
63 /** \brief count of incoming Nacks
64 */
65 PacketCounter nInNacks;
66
67 /** \brief count of outgoing Nacks
68 */
69 PacketCounter nOutNacks;
70};
71
Junxiao Shicde37ad2015-12-24 01:02:05 -070072/** \brief the upper part of a Face
73 * \sa Face
Eric Newberrya98bf932015-09-21 00:58:47 -070074 */
Junxiao Shi57df2882015-11-11 06:12:35 -070075class LinkService : protected virtual LinkServiceCounters, noncopyable
Eric Newberrya98bf932015-09-21 00:58:47 -070076{
77public:
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040078 /**
79 * \brief %Counters provided by LinkService.
Junxiao Shi57df2882015-11-11 06:12:35 -070080 */
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040081 using Counters = LinkServiceCounters;
Junxiao Shi57df2882015-11-11 06:12:35 -070082
83public:
Eric Newberrya98bf932015-09-21 00:58:47 -070084 LinkService();
85
86 virtual
87 ~LinkService();
88
89 /** \brief set Face and Transport for LinkService
90 * \pre setFaceAndTransport has not been called
91 */
92 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070093 setFaceAndTransport(Face& face, Transport& transport);
Eric Newberrya98bf932015-09-21 00:58:47 -070094
95 /** \return Face to which this LinkService is attached
96 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070097 const Face*
Eric Newberrya98bf932015-09-21 00:58:47 -070098 getFace() const;
99
100 /** \return Transport to which this LinkService is attached
101 */
102 const Transport*
103 getTransport() const;
104
105 /** \return Transport to which this LinkService is attached
106 */
107 Transport*
108 getTransport();
109
Junxiao Shi57df2882015-11-11 06:12:35 -0700110 virtual const Counters&
111 getCounters() const;
112
Eric Newberrycb6551e2020-03-02 14:12:16 -0800113 virtual ssize_t
114 getEffectiveMtu() const;
115
Eric Newberrya98bf932015-09-21 00:58:47 -0700116public: // upper interface to be used by forwarding
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700117 /** \brief Send Interest
Eric Newberrya98bf932015-09-21 00:58:47 -0700118 * \pre setTransport has been called
119 */
120 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700121 sendInterest(const Interest& interest);
Eric Newberrya98bf932015-09-21 00:58:47 -0700122
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700123 /** \brief Send Data
Eric Newberrya98bf932015-09-21 00:58:47 -0700124 * \pre setTransport has been called
125 */
126 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700127 sendData(const Data& data);
Eric Newberrya98bf932015-09-21 00:58:47 -0700128
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700129 /** \brief Send Nack
Eric Newberrya98bf932015-09-21 00:58:47 -0700130 * \pre setTransport has been called
131 */
132 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700133 sendNack(const ndn::lp::Nack& nack);
Eric Newberrya98bf932015-09-21 00:58:47 -0700134
135 /** \brief signals on Interest received
136 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000137 signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
Eric Newberrya98bf932015-09-21 00:58:47 -0700138
139 /** \brief signals on Data received
140 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000141 signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
Eric Newberrya98bf932015-09-21 00:58:47 -0700142
143 /** \brief signals on Nack received
144 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000145 signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
Eric Newberrya98bf932015-09-21 00:58:47 -0700146
Eric Newberry41aba102017-11-01 16:42:13 -0700147 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
148 */
149 signal::Signal<LinkService, Interest> onDroppedInterest;
150
Junxiao Shi57df2882015-11-11 06:12:35 -0700151public: // lower interface to be invoked by Transport
152 /** \brief performs LinkService specific operations to receive a lower-layer packet
Eric Newberrya98bf932015-09-21 00:58:47 -0700153 */
Junxiao Shi57df2882015-11-11 06:12:35 -0700154 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400155 receivePacket(const Block& packet, const EndpointId& endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700156
157protected: // upper interface to be invoked in subclass (receive path termination)
158 /** \brief delivers received Interest to forwarding
159 */
160 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400161 receiveInterest(const Interest& interest, const EndpointId& endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700162
163 /** \brief delivers received Data to forwarding
164 */
165 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400166 receiveData(const Data& data, const EndpointId& endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700167
168 /** \brief delivers received Nack to forwarding
169 */
170 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400171 receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700172
Eric Newberrya98bf932015-09-21 00:58:47 -0700173protected: // lower interface to be invoked in subclass (send path termination)
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700174 /** \brief send a lower-layer packet via Transport
Eric Newberrya98bf932015-09-21 00:58:47 -0700175 */
176 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700177 sendPacket(const Block& packet);
Eric Newberrya98bf932015-09-21 00:58:47 -0700178
Eric Newberry41aba102017-11-01 16:42:13 -0700179protected:
180 void
181 notifyDroppedInterest(const Interest& packet);
182
Junxiao Shi57df2882015-11-11 06:12:35 -0700183private: // upper interface to be overridden in subclass (send path entrypoint)
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700184 /** \brief performs LinkService specific operations to send an Interest
Junxiao Shi57df2882015-11-11 06:12:35 -0700185 */
186 virtual void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700187 doSendInterest(const Interest& interest) = 0;
Junxiao Shi57df2882015-11-11 06:12:35 -0700188
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700189 /** \brief performs LinkService specific operations to send a Data
Junxiao Shi57df2882015-11-11 06:12:35 -0700190 */
191 virtual void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700192 doSendData(const Data& data) = 0;
Junxiao Shi57df2882015-11-11 06:12:35 -0700193
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700194 /** \brief performs LinkService specific operations to send a Nack
Junxiao Shi57df2882015-11-11 06:12:35 -0700195 */
196 virtual void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700197 doSendNack(const lp::Nack& nack) = 0;
Junxiao Shi57df2882015-11-11 06:12:35 -0700198
Eric Newberrya98bf932015-09-21 00:58:47 -0700199private: // lower interface to be overridden in subclass
200 virtual void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400201 doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
Eric Newberrya98bf932015-09-21 00:58:47 -0700202
203private:
Junxiao Shicde37ad2015-12-24 01:02:05 -0700204 Face* m_face;
Eric Newberrya98bf932015-09-21 00:58:47 -0700205 Transport* m_transport;
Eric Newberrya98bf932015-09-21 00:58:47 -0700206};
207
Junxiao Shicde37ad2015-12-24 01:02:05 -0700208inline const Face*
Eric Newberrya98bf932015-09-21 00:58:47 -0700209LinkService::getFace() const
210{
211 return m_face;
212}
213
214inline const Transport*
215LinkService::getTransport() const
216{
217 return m_transport;
218}
219
220inline Transport*
221LinkService::getTransport()
222{
223 return m_transport;
224}
225
Junxiao Shi57df2882015-11-11 06:12:35 -0700226inline const LinkService::Counters&
227LinkService::getCounters() const
228{
229 return *this;
230}
231
Eric Newberrycb6551e2020-03-02 14:12:16 -0800232inline ssize_t
233LinkService::getEffectiveMtu() const
234{
235 return m_transport->getMtu();
236}
237
Eric Newberrya98bf932015-09-21 00:58:47 -0700238inline void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400239LinkService::receivePacket(const Block& packet, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700240{
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400241 doReceivePacket(packet, endpoint);
Eric Newberrya98bf932015-09-21 00:58:47 -0700242}
243
244inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700245LinkService::sendPacket(const Block& packet)
Eric Newberrya98bf932015-09-21 00:58:47 -0700246{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700247 m_transport->send(packet);
Eric Newberrya98bf932015-09-21 00:58:47 -0700248}
249
250std::ostream&
251operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
252
253template<typename T>
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400254std::enable_if_t<std::is_base_of_v<LinkService, T> && !std::is_same_v<LinkService, T>,
255 std::ostream&>
Eric Newberrya98bf932015-09-21 00:58:47 -0700256operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
257{
258 return os << FaceLogHelper<LinkService>(flh.obj);
259}
260
261} // namespace face
262} // namespace nfd
263
264#endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP