NFD: Named Data Networking Forwarding Daemon 24.07-28-gdcc0e6e0
Loading...
Searching...
No Matches
link-service.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, 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#ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP
27#define NFD_DAEMON_FACE_LINK_SERVICE_HPP
28
29#include "face-common.hpp"
30#include "transport.hpp"
31#include "common/counter.hpp"
32
33namespace nfd::face {
34
58
63class LinkService : protected virtual LinkServiceCounters, noncopyable
64{
65public:
70
71public:
72 virtual
74
79 void
80 setFaceAndTransport(Face& face, Transport& transport) noexcept;
81
85 const Face*
86 getFace() const noexcept
87 {
88 return m_face;
89 }
90
94 const Transport*
95 getTransport() const noexcept
96 {
97 return m_transport;
98 }
99
103 Transport*
104 getTransport() noexcept
105 {
106 return m_transport;
107 }
108
109 virtual const Counters&
111 {
112 return *this;
113 }
114
115 virtual ssize_t
117 {
118 return m_transport->getMtu();
119 }
120
121public: // upper interface to be used by forwarding
126 void
127 sendInterest(const Interest& interest);
128
133 void
134 sendData(const Data& data);
135
140 void
141 sendNack(const ndn::lp::Nack& nack);
142
146 signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest;
147
151 signal::Signal<LinkService, Data, EndpointId> afterReceiveData;
152
156 signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack;
157
162 signal::Signal<LinkService, Interest> onDroppedInterest;
163
164public: // lower interface to be invoked by Transport
168 void
169 receivePacket(const Block& packet, const EndpointId& endpoint)
170 {
171 doReceivePacket(packet, endpoint);
172 }
173
174protected: // upper interface to be invoked in subclass (receive path termination)
178 void
179 receiveInterest(const Interest& interest, const EndpointId& endpoint);
180
184 void
185 receiveData(const Data& data, const EndpointId& endpoint);
186
190 void
191 receiveNack(const lp::Nack& nack, const EndpointId& endpoint);
192
193protected: // lower interface to be invoked in subclass (send path termination)
197 void
198 sendPacket(const Block& packet)
199 {
200 m_transport->send(packet);
201 }
202
203protected:
204 void
205 notifyDroppedInterest(const Interest& packet);
206
207private: // upper interface to be overridden in subclass (send path entrypoint)
211 virtual void
212 doSendInterest(const Interest& interest) = 0;
213
217 virtual void
218 doSendData(const Data& data) = 0;
219
223 virtual void
224 doSendNack(const lp::Nack& nack) = 0;
225
226private: // lower interface to be overridden in subclass
227 virtual void
228 doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0;
229
230private:
231 Face* m_face = nullptr;
232 Transport* m_transport = nullptr;
233};
234
235std::ostream&
236operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
237
238template<typename T>
239std::enable_if_t<std::is_base_of_v<LinkService, T> && !std::is_same_v<LinkService, T>,
240 std::ostream&>
241operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
242{
243 return os << FaceLogHelper<LinkService>(flh.obj);
244}
245
246} // namespace nfd::face
247
248#endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
Represents a counter of number of packets.
Definition counter.hpp:71
Generalization of a network interface.
Definition face.hpp:118
For internal use by FaceLogging macros.
The lower half of a Face.
ssize_t getMtu() const noexcept
Returns the maximum payload size.
void send(const Block &packet)
Send a link-layer packet.
Definition transport.cpp:80
std::ostream & operator<<(std::ostream &os, const FaceLogHelper< Face > &flh)
Definition face.cpp:63
std::variant< std::monostate, ethernet::Address, udp::Endpoint > EndpointId
Identifies a remote endpoint on the link.