Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 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_TRANSPORT_HPP |
| 27 | #define NFD_DAEMON_FACE_TRANSPORT_HPP |
| 28 | |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 29 | #include "face-common.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 30 | #include "common/counter.hpp" |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 31 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 35 | /** \brief Indicates the state of a transport. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 36 | */ |
| 37 | enum class TransportState { |
| 38 | NONE, |
Davide Pesavento | 68ab43d | 2017-07-02 13:37:35 -0400 | [diff] [blame] | 39 | 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 Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 42 | FAILED, ///< the transport is being closed due to a failure |
| 43 | CLOSED ///< the transport is closed, and can be safely deallocated |
| 44 | }; |
| 45 | |
| 46 | std::ostream& |
| 47 | operator<<(std::ostream& os, TransportState state); |
| 48 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 49 | /** \brief Counters provided by a transport. |
| 50 | * \note The type name TransportCounters is an implementation detail. |
| 51 | * Use Transport::Counters in public API. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 52 | */ |
| 53 | class TransportCounters |
| 54 | { |
| 55 | public: |
| 56 | /** \brief count of incoming packets |
| 57 | * |
| 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 | |
| 64 | /** \brief count of outgoing packets |
| 65 | * |
| 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 | |
| 71 | /** \brief total incoming bytes |
| 72 | * |
| 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 | |
| 80 | /** \brief total outgoing bytes |
| 81 | * |
| 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 Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 89 | /** |
| 90 | * \brief Indicates that the transport has no limit on payload size |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 91 | */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 92 | constexpr ssize_t MTU_UNLIMITED = -1; |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 93 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 94 | /** |
| 95 | * \brief (for internal use) Indicates that the MTU field is unset |
Junxiao Shi | 5b8a2b2 | 2015-10-22 17:20:44 -0700 | [diff] [blame] | 96 | */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 97 | constexpr ssize_t MTU_INVALID = -2; |
Junxiao Shi | 5b8a2b2 | 2015-10-22 17:20:44 -0700 | [diff] [blame] | 98 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 99 | /** |
| 100 | * \brief Indicates that the transport does not support reading the queue capacity/length |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 101 | */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 102 | constexpr ssize_t QUEUE_UNSUPPORTED = -1; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 103 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 104 | /** |
| 105 | * \brief Indicates that the transport was unable to retrieve the queue capacity/length |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 106 | */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 107 | constexpr ssize_t QUEUE_ERROR = -2; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 108 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 109 | /** |
| 110 | * \brief The lower half of a Face. |
| 111 | * \sa Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 112 | */ |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 113 | class Transport : protected virtual TransportCounters, noncopyable |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 114 | { |
| 115 | public: |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 116 | /** \brief Counters provided by a transport. |
| 117 | * \sa TransportCounters |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 118 | */ |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 119 | using Counters = TransportCounters; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 120 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 121 | /** \brief Default constructor. |
Junxiao Shi | 5b8a2b2 | 2015-10-22 17:20:44 -0700 | [diff] [blame] | 122 | * |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 123 | * This constructor initializes static properties to invalid values. |
Junxiao Shi | 5b8a2b2 | 2015-10-22 17:20:44 -0700 | [diff] [blame] | 124 | * 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 Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 129 | Transport(); |
| 130 | |
| 131 | virtual |
| 132 | ~Transport(); |
| 133 | |
| 134 | public: |
| 135 | /** \brief set Face and LinkService for Transport |
| 136 | * \pre setFaceAndLinkService has not been called |
| 137 | */ |
| 138 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 139 | setFaceAndLinkService(Face& face, LinkService& service); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 140 | |
| 141 | /** \return Face to which this Transport is attached |
| 142 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 143 | const Face* |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 144 | getFace() const; |
| 145 | |
| 146 | /** \return LinkService to which this Transport is attached |
| 147 | */ |
| 148 | const LinkService* |
| 149 | getLinkService() const; |
| 150 | |
| 151 | /** \return LinkService to which this Transport is attached |
| 152 | */ |
| 153 | LinkService* |
| 154 | getLinkService(); |
| 155 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 156 | virtual const Counters& |
| 157 | getCounters() const; |
| 158 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 159 | public: // upper interface |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 160 | /** \brief Request the transport to be closed |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 161 | * |
| 162 | * This operation is effective only if transport is in UP or DOWN state, |
| 163 | * otherwise it has no effect. |
| 164 | * The transport changes state to CLOSING, and performs cleanup procedure. |
| 165 | * The state will be changed to CLOSED when cleanup is complete, which may |
| 166 | * happen synchronously or asynchronously. |
| 167 | */ |
| 168 | void |
| 169 | close(); |
| 170 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 171 | /** \brief Send a link-layer packet |
| 172 | * \param packet the packet to be sent, must be a valid and well-formed TLV block |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 173 | * \note This operation has no effect if getState() is neither UP nor DOWN |
| 174 | * \warning Behavior is undefined if packet size exceeds the MTU limit |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 175 | */ |
| 176 | void |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 177 | send(const Block& packet); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 178 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 179 | public: // static properties |
| 180 | /** \return a FaceUri representing local endpoint |
| 181 | */ |
| 182 | FaceUri |
| 183 | getLocalUri() const; |
| 184 | |
| 185 | /** \return a FaceUri representing remote endpoint |
| 186 | */ |
| 187 | FaceUri |
| 188 | getRemoteUri() const; |
| 189 | |
| 190 | /** \return whether face is local or non-local for scope control purpose |
| 191 | */ |
| 192 | ndn::nfd::FaceScope |
| 193 | getScope() const; |
| 194 | |
| 195 | /** \return face persistency setting |
| 196 | */ |
| 197 | ndn::nfd::FacePersistency |
| 198 | getPersistency() const; |
| 199 | |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 200 | /** \brief check whether the face persistency can be changed to \p newPersistency |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 201 | * |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 202 | * This function serves as the external API, and invokes the protected function |
| 203 | * canChangePersistencyToImpl to perform further checks if \p newPersistency differs |
| 204 | * from the current persistency. |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 205 | * |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 206 | * \return true if the change can be performed, false otherwise |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 207 | */ |
| 208 | bool |
| 209 | canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const; |
| 210 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 211 | /** \brief changes face persistency setting |
| 212 | */ |
| 213 | void |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 214 | setPersistency(ndn::nfd::FacePersistency newPersistency); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 215 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 216 | /** \return the link type of the transport |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 217 | */ |
| 218 | ndn::nfd::LinkType |
| 219 | getLinkType() const; |
| 220 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 221 | /** \return maximum payload size |
| 222 | * \retval MTU_UNLIMITED transport has no limit on payload size |
| 223 | * |
| 224 | * This size is the maximum packet size that can be sent or received through this transport. |
| 225 | * |
| 226 | * For a datagram-based transport, this is typically the Maximum Transmission Unit (MTU), |
| 227 | * after the overhead of headers introduced by the transport has been accounted for. |
| 228 | * For a stream-based transport, this is typically unlimited (MTU_UNLIMITED). |
| 229 | */ |
| 230 | ssize_t |
| 231 | getMtu() const; |
| 232 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 233 | /** \return capacity of the send queue (in bytes) |
| 234 | * \retval QUEUE_UNSUPPORTED transport does not support queue capacity retrieval |
| 235 | * \retval QUEUE_ERROR transport was unable to retrieve the queue capacity |
| 236 | */ |
| 237 | ssize_t |
| 238 | getSendQueueCapacity() const; |
| 239 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 240 | public: // dynamic properties |
| 241 | /** \return transport state |
| 242 | */ |
| 243 | TransportState |
| 244 | getState() const; |
| 245 | |
| 246 | /** \brief signals when transport state changes |
| 247 | */ |
| 248 | signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange; |
| 249 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 250 | /** \return expiration time of the transport |
| 251 | * \retval time::steady_clock::TimePoint::max() the transport has indefinite lifetime |
| 252 | */ |
| 253 | time::steady_clock::TimePoint |
| 254 | getExpirationTime() const; |
| 255 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 256 | /** \return current send queue length of the transport (in octets) |
| 257 | * \retval QUEUE_UNSUPPORTED transport does not support queue length retrieval |
| 258 | * \retval QUEUE_ERROR transport was unable to retrieve the queue length |
| 259 | */ |
| 260 | virtual ssize_t |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 261 | getSendQueueLength() |
| 262 | { |
| 263 | return QUEUE_UNSUPPORTED; |
| 264 | } |
| 265 | |
| 266 | protected: // upper interface to be invoked by subclass |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 267 | /** \brief Pass a received link-layer packet to the upper layer for further processing |
| 268 | * \param packet the received packet, must be a valid and well-formed TLV block |
| 269 | * \param endpoint the source endpoint |
| 270 | * \warning Behavior is undefined if packet size exceeds the MTU limit |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 271 | */ |
| 272 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 273 | receive(const Block& packet, const EndpointId& endpoint = 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 274 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 275 | protected: // properties to be set by subclass |
| 276 | void |
| 277 | setLocalUri(const FaceUri& uri); |
| 278 | |
| 279 | void |
| 280 | setRemoteUri(const FaceUri& uri); |
| 281 | |
| 282 | void |
| 283 | setScope(ndn::nfd::FaceScope scope); |
| 284 | |
| 285 | void |
| 286 | setLinkType(ndn::nfd::LinkType linkType); |
| 287 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 288 | void |
| 289 | setMtu(ssize_t mtu); |
| 290 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 291 | void |
| 292 | setSendQueueCapacity(ssize_t sendQueueCapacity); |
| 293 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 294 | /** \brief set transport state |
| 295 | * |
| 296 | * Only the following transitions are valid: |
| 297 | * UP->DOWN, DOWN->UP, UP/DOWN->CLOSING/FAILED, CLOSING/FAILED->CLOSED |
| 298 | * |
| 299 | * \throw std::runtime_error transition is invalid. |
| 300 | */ |
| 301 | void |
| 302 | setState(TransportState newState); |
| 303 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 304 | void |
| 305 | setExpirationTime(const time::steady_clock::TimePoint& expirationTime); |
| 306 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 307 | protected: // to be overridden by subclass |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 308 | /** \brief invoked by canChangePersistencyTo to perform the check |
| 309 | * |
| 310 | * Base class implementation returns false. |
| 311 | * |
| 312 | * \param newPersistency the new persistency, guaranteed to be different from current persistency |
| 313 | */ |
| 314 | virtual bool |
| 315 | canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const; |
| 316 | |
| 317 | /** \brief invoked after the persistency has been changed |
| 318 | * |
| 319 | * The base class implementation does nothing. |
| 320 | * When overridden in a subclass, the function should update internal states |
| 321 | * after persistency setting has been changed. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 322 | */ |
| 323 | virtual void |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 324 | afterChangePersistency(ndn::nfd::FacePersistency oldPersistency); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 325 | |
| 326 | /** \brief performs Transport specific operations to close the transport |
| 327 | * |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 328 | * This is invoked once by \p close() after changing state to CLOSING. |
| 329 | * It will not be invoked by Transport class if the transport is already CLOSING or CLOSED. |
| 330 | * |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 331 | * When the cleanup procedure is complete, this method should change state to CLOSED. |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 332 | * This transition can happen synchronously or asynchronously. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 333 | */ |
| 334 | virtual void |
| 335 | doClose() = 0; |
| 336 | |
| 337 | private: // to be overridden by subclass |
| 338 | /** \brief performs Transport specific operations to send a packet |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 339 | * \param packet the packet to be sent, can be assumed to be valid and well-formed |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 340 | * \pre transport state is either UP or DOWN |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 341 | */ |
| 342 | virtual void |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 343 | doSend(const Block& packet) = 0; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 344 | |
| 345 | private: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 346 | Face* m_face; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 347 | LinkService* m_service; |
| 348 | FaceUri m_localUri; |
| 349 | FaceUri m_remoteUri; |
| 350 | ndn::nfd::FaceScope m_scope; |
| 351 | ndn::nfd::FacePersistency m_persistency; |
| 352 | ndn::nfd::LinkType m_linkType; |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 353 | ssize_t m_mtu; |
Davide Pesavento | 3e7fc83 | 2018-09-08 14:07:29 -0400 | [diff] [blame] | 354 | ssize_t m_sendQueueCapacity; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 355 | TransportState m_state; |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 356 | time::steady_clock::TimePoint m_expirationTime; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 357 | }; |
| 358 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 359 | inline const Face* |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 360 | Transport::getFace() const |
| 361 | { |
| 362 | return m_face; |
| 363 | } |
| 364 | |
| 365 | inline const LinkService* |
| 366 | Transport::getLinkService() const |
| 367 | { |
| 368 | return m_service; |
| 369 | } |
| 370 | |
| 371 | inline LinkService* |
| 372 | Transport::getLinkService() |
| 373 | { |
| 374 | return m_service; |
| 375 | } |
| 376 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 377 | inline const Transport::Counters& |
| 378 | Transport::getCounters() const |
| 379 | { |
| 380 | return *this; |
| 381 | } |
| 382 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 383 | inline FaceUri |
| 384 | Transport::getLocalUri() const |
| 385 | { |
| 386 | return m_localUri; |
| 387 | } |
| 388 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 389 | inline void |
| 390 | Transport::setLocalUri(const FaceUri& uri) |
| 391 | { |
| 392 | m_localUri = uri; |
| 393 | } |
| 394 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 395 | inline FaceUri |
| 396 | Transport::getRemoteUri() const |
| 397 | { |
| 398 | return m_remoteUri; |
| 399 | } |
| 400 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 401 | inline void |
| 402 | Transport::setRemoteUri(const FaceUri& uri) |
| 403 | { |
| 404 | m_remoteUri = uri; |
| 405 | } |
| 406 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 407 | inline ndn::nfd::FaceScope |
| 408 | Transport::getScope() const |
| 409 | { |
| 410 | return m_scope; |
| 411 | } |
| 412 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 413 | inline void |
| 414 | Transport::setScope(ndn::nfd::FaceScope scope) |
| 415 | { |
| 416 | m_scope = scope; |
| 417 | } |
| 418 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 419 | inline ndn::nfd::FacePersistency |
| 420 | Transport::getPersistency() const |
| 421 | { |
| 422 | return m_persistency; |
| 423 | } |
| 424 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 425 | inline ndn::nfd::LinkType |
| 426 | Transport::getLinkType() const |
| 427 | { |
| 428 | return m_linkType; |
| 429 | } |
| 430 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 431 | inline void |
| 432 | Transport::setLinkType(ndn::nfd::LinkType linkType) |
| 433 | { |
| 434 | m_linkType = linkType; |
| 435 | } |
| 436 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 437 | inline ssize_t |
| 438 | Transport::getMtu() const |
| 439 | { |
| 440 | return m_mtu; |
| 441 | } |
| 442 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 443 | inline ssize_t |
| 444 | Transport::getSendQueueCapacity() const |
| 445 | { |
| 446 | return m_sendQueueCapacity; |
| 447 | } |
| 448 | |
| 449 | inline void |
| 450 | Transport::setSendQueueCapacity(ssize_t sendQueueCapacity) |
| 451 | { |
| 452 | m_sendQueueCapacity = sendQueueCapacity; |
| 453 | } |
| 454 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 455 | inline TransportState |
| 456 | Transport::getState() const |
| 457 | { |
| 458 | return m_state; |
| 459 | } |
| 460 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 461 | inline time::steady_clock::TimePoint |
| 462 | Transport::getExpirationTime() const |
| 463 | { |
| 464 | return m_expirationTime; |
| 465 | } |
| 466 | |
| 467 | inline void |
| 468 | Transport::setExpirationTime(const time::steady_clock::TimePoint& expirationTime) |
| 469 | { |
| 470 | m_expirationTime = expirationTime; |
| 471 | } |
| 472 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 473 | std::ostream& |
| 474 | operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh); |
| 475 | |
| 476 | template<typename T> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 477 | std::enable_if_t<std::is_base_of_v<Transport, T> && !std::is_same_v<Transport, T>, |
| 478 | std::ostream&> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 479 | operator<<(std::ostream& os, const FaceLogHelper<T>& flh) |
| 480 | { |
| 481 | return os << FaceLogHelper<Transport>(flh.obj); |
| 482 | } |
| 483 | |
| 484 | } // namespace face |
| 485 | } // namespace nfd |
| 486 | |
| 487 | #endif // NFD_DAEMON_FACE_TRANSPORT_HPP |