blob: cebc927e924ef259ccd4117081e8019c8b4d63a9 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberryb49313d2017-12-24 20:22:27 -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_TRANSPORT_HPP
27#define NFD_DAEMON_FACE_TRANSPORT_HPP
28
Davide Pesaventocb425e82019-07-14 21:48:22 -040029#include "face-common.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040030#include "common/counter.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070031
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::face {
Eric Newberrya98bf932015-09-21 00:58:47 -070033
Teng Liangd94b7b32022-07-10 21:29:37 +080034/**
35 * \brief Indicates the state of a transport.
Eric Newberrya98bf932015-09-21 00:58:47 -070036 */
37enum class TransportState {
38 NONE,
Davide Pesavento68ab43d2017-07-02 13:37:35 -040039 UP, ///< the transport is up and can transmit packets
40 DOWN, ///< the transport is temporarily down, and is being recovered
41 CLOSING, ///< the transport is being closed gracefully, either by the peer or by a call to close()
Eric Newberrya98bf932015-09-21 00:58:47 -070042 FAILED, ///< the transport is being closed due to a failure
43 CLOSED ///< the transport is closed, and can be safely deallocated
44};
45
46std::ostream&
47operator<<(std::ostream& os, TransportState state);
48
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040049/** \brief Counters provided by a transport.
50 * \note The type name TransportCounters is an implementation detail.
51 * Use Transport::Counters in public API.
Junxiao Shi57df2882015-11-11 06:12:35 -070052 */
53class TransportCounters
54{
55public:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040056 /** \brief Count of incoming packets.
Junxiao Shi57df2882015-11-11 06:12:35 -070057 *
58 * A 'packet' typically means a top-level TLV block.
59 * For a datagram-based transport, an incoming packet that cannot be parsed as TLV
60 * would not be counted.
61 */
62 PacketCounter nInPackets;
63
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040064 /** \brief Count of outgoing packets.
Junxiao Shi57df2882015-11-11 06:12:35 -070065 *
66 * A 'packet' typically means a top-level TLV block.
67 * This counter is incremented only if transport is UP.
68 */
69 PacketCounter nOutPackets;
70
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040071 /** \brief Total incoming bytes.
Junxiao Shi57df2882015-11-11 06:12:35 -070072 *
73 * This counter includes headers imposed by NFD (such as NDNLP),
74 * but excludes overhead of underlying protocol (such as IP header).
75 * For a datagram-based transport, an incoming packet that cannot be parsed as TLV
76 * would not be counted.
77 */
78 ByteCounter nInBytes;
79
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040080 /** \brief Total outgoing bytes.
Junxiao Shi57df2882015-11-11 06:12:35 -070081 *
82 * This counter includes headers imposed by NFD (such as NDNLP),
83 * but excludes overhead of underlying protocol (such as IP header).
84 * This counter is increased only if transport is UP.
85 */
86 ByteCounter nOutBytes;
87};
88
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040089/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040090 * \brief Indicates that the transport has no limit on payload size.
Junxiao Shi13546112015-10-14 19:33:07 -070091 */
Davide Pesavento20d94f62022-09-26 03:30:53 -040092inline constexpr ssize_t MTU_UNLIMITED = -1;
Junxiao Shi13546112015-10-14 19:33:07 -070093
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040094/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040095 * \brief (for internal use) Indicates that the MTU field is unset.
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070096 */
Davide Pesavento20d94f62022-09-26 03:30:53 -040097inline constexpr ssize_t MTU_INVALID = -2;
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070098
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040099/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400100 * \brief Indicates that the transport does not support reading the queue capacity/length.
Eric Newberryb49313d2017-12-24 20:22:27 -0700101 */
Davide Pesavento20d94f62022-09-26 03:30:53 -0400102inline constexpr ssize_t QUEUE_UNSUPPORTED = -1;
Eric Newberryb49313d2017-12-24 20:22:27 -0700103
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400104/**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400105 * \brief Indicates that the transport was unable to retrieve the queue capacity/length.
Eric Newberryb49313d2017-12-24 20:22:27 -0700106 */
Davide Pesavento20d94f62022-09-26 03:30:53 -0400107inline constexpr ssize_t QUEUE_ERROR = -2;
Eric Newberryb49313d2017-12-24 20:22:27 -0700108
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400109/**
110 * \brief The lower half of a Face.
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400111 * \sa Face, LinkService
Eric Newberrya98bf932015-09-21 00:58:47 -0700112 */
Junxiao Shi57df2882015-11-11 06:12:35 -0700113class Transport : protected virtual TransportCounters, noncopyable
Eric Newberrya98bf932015-09-21 00:58:47 -0700114{
115public:
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400116 /** \brief Counters provided by a transport.
117 * \sa TransportCounters
Eric Newberrya98bf932015-09-21 00:58:47 -0700118 */
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400119 using Counters = TransportCounters;
Eric Newberrya98bf932015-09-21 00:58:47 -0700120
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400121 /** \brief Default constructor.
Junxiao Shi5b8a2b22015-10-22 17:20:44 -0700122 *
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400123 * This constructor initializes static properties to invalid values.
Junxiao Shi5b8a2b22015-10-22 17:20:44 -0700124 * Subclass constructor must explicitly set every static property.
125 *
126 * This constructor initializes TransportState to UP;
127 * subclass constructor can rely on this default value.
128 */
Eric Newberrya98bf932015-09-21 00:58:47 -0700129 Transport();
130
131 virtual
132 ~Transport();
133
134public:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400135 /**
136 * \brief Set Face and LinkService for this transport.
137 * \pre setFaceAndLinkService() has not been called.
Eric Newberrya98bf932015-09-21 00:58:47 -0700138 */
139 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400140 setFaceAndLinkService(Face& face, LinkService& service) noexcept;
Eric Newberrya98bf932015-09-21 00:58:47 -0700141
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400142 /**
143 * \brief Returns the Face to which this transport is attached.
Eric Newberrya98bf932015-09-21 00:58:47 -0700144 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700145 const Face*
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400146 getFace() const noexcept
147 {
148 return m_face;
149 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700150
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400151 /**
152 * \brief Returns the LinkService to which this transport is attached.
Eric Newberrya98bf932015-09-21 00:58:47 -0700153 */
154 const LinkService*
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400155 getLinkService() const noexcept
156 {
157 return m_service;
158 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700159
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400160 /**
161 * \brief Returns the LinkService to which this transport is attached.
Eric Newberrya98bf932015-09-21 00:58:47 -0700162 */
163 LinkService*
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400164 getLinkService() noexcept
165 {
166 return m_service;
167 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700168
Junxiao Shi57df2882015-11-11 06:12:35 -0700169 virtual const Counters&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400170 getCounters() const
171 {
172 return *this;
173 }
Junxiao Shi57df2882015-11-11 06:12:35 -0700174
Eric Newberrya98bf932015-09-21 00:58:47 -0700175public: // upper interface
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400176 /** \brief Request the transport to be closed.
Eric Newberrya98bf932015-09-21 00:58:47 -0700177 *
178 * This operation is effective only if transport is in UP or DOWN state,
179 * otherwise it has no effect.
180 * The transport changes state to CLOSING, and performs cleanup procedure.
181 * The state will be changed to CLOSED when cleanup is complete, which may
182 * happen synchronously or asynchronously.
183 */
184 void
185 close();
186
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400187 /** \brief Send a link-layer packet.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400188 * \param packet the packet to be sent, must be a valid and well-formed TLV block
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400189 * \note This operation has no effect if getState() is neither UP nor DOWN
190 * \warning Behavior is undefined if packet size exceeds the MTU limit
Eric Newberrya98bf932015-09-21 00:58:47 -0700191 */
192 void
Teng Liang13d582a2020-07-21 20:23:11 -0700193 send(const Block& packet);
Eric Newberrya98bf932015-09-21 00:58:47 -0700194
Eric Newberrya98bf932015-09-21 00:58:47 -0700195public: // static properties
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400196 /**
197 * \brief Returns a FaceUri representing the local endpoint.
Eric Newberrya98bf932015-09-21 00:58:47 -0700198 */
199 FaceUri
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400200 getLocalUri() const noexcept
201 {
202 return m_localUri;
203 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700204
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400205 /**
206 * \brief Returns a FaceUri representing the remote endpoint.
Eric Newberrya98bf932015-09-21 00:58:47 -0700207 */
208 FaceUri
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400209 getRemoteUri() const noexcept
210 {
211 return m_remoteUri;
212 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700213
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400214 /**
215 * \brief Returns whether the transport is local or non-local for scope control purposes.
Eric Newberrya98bf932015-09-21 00:58:47 -0700216 */
217 ndn::nfd::FaceScope
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400218 getScope() const noexcept
219 {
220 return m_scope;
221 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700222
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400223 /**
224 * \brief Returns the current persistency setting of the transport.
Eric Newberrya98bf932015-09-21 00:58:47 -0700225 */
226 ndn::nfd::FacePersistency
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400227 getPersistency() const noexcept
228 {
229 return m_persistency;
230 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700231
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400232 /**
233 * \brief Check whether the persistency can be changed to \p newPersistency.
Yanbiao Li32dab972016-11-27 12:26:09 +0800234 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400235 * This function serves as the external API, and invokes the protected function
236 * canChangePersistencyToImpl() to perform further checks if \p newPersistency differs
237 * from the current persistency.
Yanbiao Li32dab972016-11-27 12:26:09 +0800238 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400239 * \return true if the change can be performed, false otherwise
Yanbiao Li32dab972016-11-27 12:26:09 +0800240 */
241 bool
242 canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const;
243
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400244 /**
245 * \brief Changes the persistency setting of the transport.
Eric Newberrya98bf932015-09-21 00:58:47 -0700246 */
247 void
Davide Pesavento32065652017-01-15 01:52:21 -0500248 setPersistency(ndn::nfd::FacePersistency newPersistency);
Eric Newberrya98bf932015-09-21 00:58:47 -0700249
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400250 /**
251 * \brief Returns the link type of the transport.
Eric Newberrya98bf932015-09-21 00:58:47 -0700252 */
253 ndn::nfd::LinkType
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400254 getLinkType() const noexcept
255 {
256 return m_linkType;
257 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700258
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400259 /**
260 * \brief Returns the maximum payload size.
261 * \retval MTU_UNLIMITED The transport has no limit on payload size.
Junxiao Shi13546112015-10-14 19:33:07 -0700262 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400263 * This size is the maximum packet size that can be sent or received through this transport.
Junxiao Shi13546112015-10-14 19:33:07 -0700264 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400265 * For a datagram-based transport, this is typically the Maximum Transmission Unit (MTU),
266 * after the overhead of headers introduced by the transport has been accounted for.
267 * For a stream-based transport, this is typically unlimited (MTU_UNLIMITED).
Junxiao Shi13546112015-10-14 19:33:07 -0700268 */
269 ssize_t
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400270 getMtu() const noexcept
271 {
272 return m_mtu;
273 }
Junxiao Shi13546112015-10-14 19:33:07 -0700274
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400275 /**
276 * \brief Returns the capacity of the send queue (in bytes).
277 * \retval QUEUE_UNSUPPORTED The transport does not support queue capacity retrieval.
278 * \retval QUEUE_ERROR The transport was unable to retrieve the queue capacity.
Eric Newberryb49313d2017-12-24 20:22:27 -0700279 */
280 ssize_t
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400281 getSendQueueCapacity() const noexcept
282 {
283 return m_sendQueueCapacity;
284 }
Eric Newberryb49313d2017-12-24 20:22:27 -0700285
Eric Newberrya98bf932015-09-21 00:58:47 -0700286public: // dynamic properties
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400287 /**
288 * \brief Returns the current transport state.
Eric Newberrya98bf932015-09-21 00:58:47 -0700289 */
290 TransportState
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400291 getState() const noexcept
292 {
293 return m_state;
294 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700295
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400296 /**
297 * \brief Signals when the transport state changes.
Eric Newberrya98bf932015-09-21 00:58:47 -0700298 */
299 signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange;
300
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400301 /**
302 * \brief Returns the expiration time of the transport.
303 * \retval time::steady_clock::time_point::max() The transport has an indefinite lifetime.
Eric Newberryc64d30a2015-12-26 11:07:27 -0700304 */
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400305 time::steady_clock::time_point
306 getExpirationTime() const noexcept
307 {
308 return m_expirationTime;
309 }
Eric Newberryc64d30a2015-12-26 11:07:27 -0700310
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400311 /**
312 * \brief Returns the current send queue length of the transport (in octets).
313 * \retval QUEUE_UNSUPPORTED The transport does not support queue length retrieval.
314 * \retval QUEUE_ERROR The transport was unable to retrieve the queue length.
Eric Newberryb49313d2017-12-24 20:22:27 -0700315 */
316 virtual ssize_t
Eric Newberry812d6152018-06-06 15:06:01 -0700317 getSendQueueLength()
318 {
319 return QUEUE_UNSUPPORTED;
320 }
321
322protected: // upper interface to be invoked by subclass
Teng Liangd94b7b32022-07-10 21:29:37 +0800323 /**
324 * \brief Pass a received link-layer packet to the upper layer for further processing.
325 * \param packet The received packet, must be a valid and well-formed TLV block
326 * \param endpoint The source endpoint, optional for unicast transports
327 * \warning Behavior is undefined if packet size exceeds the MTU limit.
Eric Newberry812d6152018-06-06 15:06:01 -0700328 */
329 void
Teng Liangd94b7b32022-07-10 21:29:37 +0800330 receive(const Block& packet, const EndpointId& endpoint = {});
Eric Newberryb49313d2017-12-24 20:22:27 -0700331
Eric Newberrya98bf932015-09-21 00:58:47 -0700332protected: // properties to be set by subclass
333 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400334 setLocalUri(const FaceUri& uri) noexcept
335 {
336 m_localUri = uri;
337 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700338
339 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400340 setRemoteUri(const FaceUri& uri) noexcept
341 {
342 m_remoteUri = uri;
343 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700344
345 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400346 setScope(ndn::nfd::FaceScope scope) noexcept
347 {
348 m_scope = scope;
349 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700350
351 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400352 setLinkType(ndn::nfd::LinkType linkType) noexcept
353 {
354 m_linkType = linkType;
355 }
Eric Newberrya98bf932015-09-21 00:58:47 -0700356
Junxiao Shi13546112015-10-14 19:33:07 -0700357 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400358 setMtu(ssize_t mtu) noexcept;
Junxiao Shi13546112015-10-14 19:33:07 -0700359
Eric Newberryb49313d2017-12-24 20:22:27 -0700360 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400361 setSendQueueCapacity(ssize_t sendQueueCapacity) noexcept
362 {
363 m_sendQueueCapacity = sendQueueCapacity;
364 }
Eric Newberryb49313d2017-12-24 20:22:27 -0700365
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400366 /** \brief Set transport state.
Eric Newberrya98bf932015-09-21 00:58:47 -0700367 *
368 * Only the following transitions are valid:
369 * UP->DOWN, DOWN->UP, UP/DOWN->CLOSING/FAILED, CLOSING/FAILED->CLOSED
370 *
371 * \throw std::runtime_error transition is invalid.
372 */
373 void
374 setState(TransportState newState);
375
Eric Newberryc64d30a2015-12-26 11:07:27 -0700376 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400377 setExpirationTime(const time::steady_clock::time_point& expirationTime) noexcept
378 {
379 m_expirationTime = expirationTime;
380 }
Eric Newberryc64d30a2015-12-26 11:07:27 -0700381
Eric Newberrya98bf932015-09-21 00:58:47 -0700382protected: // to be overridden by subclass
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400383 /** \brief Invoked by canChangePersistencyTo to perform the check.
Yanbiao Li32dab972016-11-27 12:26:09 +0800384 *
385 * Base class implementation returns false.
386 *
387 * \param newPersistency the new persistency, guaranteed to be different from current persistency
388 */
389 virtual bool
390 canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const;
391
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400392 /** \brief Invoked after the persistency has been changed.
Yanbiao Li32dab972016-11-27 12:26:09 +0800393 *
394 * The base class implementation does nothing.
395 * When overridden in a subclass, the function should update internal states
396 * after persistency setting has been changed.
Eric Newberrya98bf932015-09-21 00:58:47 -0700397 */
398 virtual void
Yanbiao Li32dab972016-11-27 12:26:09 +0800399 afterChangePersistency(ndn::nfd::FacePersistency oldPersistency);
Eric Newberrya98bf932015-09-21 00:58:47 -0700400
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400401 /** \brief Performs Transport specific operations to close the transport.
Eric Newberrya98bf932015-09-21 00:58:47 -0700402 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400403 * This is invoked once by close() after changing state to CLOSING.
Junxiao Shi13546112015-10-14 19:33:07 -0700404 * It will not be invoked by Transport class if the transport is already CLOSING or CLOSED.
405 *
Eric Newberrya98bf932015-09-21 00:58:47 -0700406 * When the cleanup procedure is complete, this method should change state to CLOSED.
Junxiao Shi13546112015-10-14 19:33:07 -0700407 * This transition can happen synchronously or asynchronously.
Eric Newberrya98bf932015-09-21 00:58:47 -0700408 */
409 virtual void
410 doClose() = 0;
411
412private: // to be overridden by subclass
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400413 /** \brief Performs Transport specific operations to send a packet.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400414 * \param packet the packet to be sent, can be assumed to be valid and well-formed
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400415 * \pre transport state is either UP or DOWN
Eric Newberrya98bf932015-09-21 00:58:47 -0700416 */
417 virtual void
Teng Liang13d582a2020-07-21 20:23:11 -0700418 doSend(const Block& packet) = 0;
Eric Newberrya98bf932015-09-21 00:58:47 -0700419
420private:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400421 Face* m_face = nullptr;
422 LinkService* m_service = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -0700423 FaceUri m_localUri;
424 FaceUri m_remoteUri;
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400425 ndn::nfd::FaceScope m_scope = ndn::nfd::FACE_SCOPE_NONE;
426 ndn::nfd::FacePersistency m_persistency = ndn::nfd::FACE_PERSISTENCY_NONE;
427 ndn::nfd::LinkType m_linkType = ndn::nfd::LINK_TYPE_NONE;
428 ssize_t m_mtu = MTU_INVALID;
429 ssize_t m_sendQueueCapacity = QUEUE_UNSUPPORTED;
430 TransportState m_state = TransportState::UP;
431 time::steady_clock::time_point m_expirationTime = time::steady_clock::time_point::max();
Eric Newberrya98bf932015-09-21 00:58:47 -0700432};
433
Eric Newberrya98bf932015-09-21 00:58:47 -0700434std::ostream&
435operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
436
437template<typename T>
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400438std::enable_if_t<std::is_base_of_v<Transport, T> && !std::is_same_v<Transport, T>,
439 std::ostream&>
Eric Newberrya98bf932015-09-21 00:58:47 -0700440operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
441{
442 return os << FaceLogHelper<Transport>(flh.obj);
443}
444
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400445} // namespace nfd::face
Eric Newberrya98bf932015-09-21 00:58:47 -0700446
447#endif // NFD_DAEMON_FACE_TRANSPORT_HPP