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 | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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_LINK_SERVICE_HPP |
| 27 | #define NFD_DAEMON_FACE_LINK_SERVICE_HPP |
| 28 | |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 29 | #include "face-common.hpp" |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 30 | #include "transport.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 31 | #include "common/counter.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::face { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 35 | /** |
| 36 | * \brief Counters provided by LinkService. |
| 37 | * \note The type name LinkServiceCounters is an implementation detail. |
| 38 | * Use LinkService::Counters in public API. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 39 | */ |
| 40 | class LinkServiceCounters |
| 41 | { |
| 42 | public: |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 43 | /// Count of incoming Interest packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 44 | PacketCounter nInInterests; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 45 | /// Count of outgoing Interest packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 46 | PacketCounter nOutInterests; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 47 | /// Count of Interests dropped by reliability system for exceeding allowed number of retx. |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 48 | PacketCounter nInterestsExceededRetx; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 49 | /// Count of incoming Data packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 50 | PacketCounter nInData; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 51 | /// Count of outgoing Data packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 52 | PacketCounter nOutData; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 53 | /// Count of incoming Nack packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 54 | PacketCounter nInNacks; |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 55 | /// Count of outgoing Nack packets. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 56 | PacketCounter nOutNacks; |
| 57 | }; |
| 58 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 59 | /** |
| 60 | * \brief The upper half of a Face. |
| 61 | * \sa Face, Transport |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 62 | */ |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 63 | class LinkService : protected virtual LinkServiceCounters, noncopyable |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 64 | { |
| 65 | public: |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 66 | /** |
| 67 | * \brief %Counters provided by LinkService. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 68 | */ |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 69 | using Counters = LinkServiceCounters; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 70 | |
| 71 | public: |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 72 | virtual |
| 73 | ~LinkService(); |
| 74 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 75 | /** |
| 76 | * \brief Set Face and Transport for this LinkService. |
| 77 | * \pre setFaceAndTransport() has not been called. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 78 | */ |
| 79 | void |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 80 | setFaceAndTransport(Face& face, Transport& transport) noexcept; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 81 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 82 | /** |
| 83 | * \brief Returns the Face to which this LinkService is attached. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 84 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 85 | const Face* |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 86 | getFace() const noexcept |
| 87 | { |
| 88 | return m_face; |
| 89 | } |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 90 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 91 | /** |
| 92 | * \brief Returns the Transport to which this LinkService is attached. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 93 | */ |
| 94 | const Transport* |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 95 | getTransport() const noexcept |
| 96 | { |
| 97 | return m_transport; |
| 98 | } |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 99 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 100 | /** |
| 101 | * \brief Returns the Transport to which this LinkService is attached. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 102 | */ |
| 103 | Transport* |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 104 | getTransport() noexcept |
| 105 | { |
| 106 | return m_transport; |
| 107 | } |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 109 | virtual const Counters& |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 110 | getCounters() const |
| 111 | { |
| 112 | return *this; |
| 113 | } |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 114 | |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 115 | virtual ssize_t |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 116 | getEffectiveMtu() const |
| 117 | { |
| 118 | return m_transport->getMtu(); |
| 119 | } |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 120 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 121 | public: // upper interface to be used by forwarding |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 122 | /** |
| 123 | * \brief Send Interest. |
| 124 | * \pre setFaceAndTransport() has been called. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 125 | */ |
| 126 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 127 | sendInterest(const Interest& interest); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 128 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 129 | /** |
| 130 | * \brief Send Data. |
| 131 | * \pre setFaceAndTransport() has been called. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 132 | */ |
| 133 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 134 | sendData(const Data& data); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 135 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 136 | /** |
| 137 | * \brief Send Nack. |
| 138 | * \pre setFaceAndTransport() has been called. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 139 | */ |
| 140 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 141 | sendNack(const ndn::lp::Nack& nack); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 142 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 143 | /** |
| 144 | * \brief Called when an Interest packet is received. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 145 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 146 | signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 147 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 148 | /** |
| 149 | * \brief Called when a Data packet is received. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 150 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 151 | signal::Signal<LinkService, Data, EndpointId> afterReceiveData; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 152 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 153 | /** |
| 154 | * \brief Called when a Nack packet is received. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 155 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 156 | signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 157 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 158 | /** |
| 159 | * \brief Called when an Interest is dropped by the reliability system |
| 160 | * for exceeding the allowed number of retransmissions. |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 161 | */ |
| 162 | signal::Signal<LinkService, Interest> onDroppedInterest; |
| 163 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 164 | public: // lower interface to be invoked by Transport |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 165 | /** |
| 166 | * \brief Performs LinkService-specific operations to receive a lower-layer packet. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 167 | */ |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 168 | void |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 169 | receivePacket(const Block& packet, const EndpointId& endpoint) |
| 170 | { |
| 171 | doReceivePacket(packet, endpoint); |
| 172 | } |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 173 | |
| 174 | protected: // upper interface to be invoked in subclass (receive path termination) |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 175 | /** |
| 176 | * \brief Delivers received Interest to forwarding. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 177 | */ |
| 178 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 179 | receiveInterest(const Interest& interest, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 180 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 181 | /** |
| 182 | * \brief Delivers received Data to forwarding. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 183 | */ |
| 184 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 185 | receiveData(const Data& data, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 186 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 187 | /** |
| 188 | * \brief Delivers received Nack to forwarding. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 189 | */ |
| 190 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 191 | receiveNack(const lp::Nack& nack, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 192 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 193 | protected: // lower interface to be invoked in subclass (send path termination) |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 194 | /** |
| 195 | * \brief Send a lower-layer packet via Transport. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 196 | */ |
| 197 | void |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 198 | sendPacket(const Block& packet) |
| 199 | { |
| 200 | m_transport->send(packet); |
| 201 | } |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 202 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 203 | protected: |
| 204 | void |
| 205 | notifyDroppedInterest(const Interest& packet); |
| 206 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 207 | private: // upper interface to be overridden in subclass (send path entrypoint) |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 208 | /** |
| 209 | * \brief Performs LinkService-specific operations to send an Interest. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 210 | */ |
| 211 | virtual void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 212 | doSendInterest(const Interest& interest) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 213 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 214 | /** |
| 215 | * \brief Performs LinkService-specific operations to send a Data. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 216 | */ |
| 217 | virtual void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 218 | doSendData(const Data& data) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 219 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 220 | /** |
| 221 | * \brief Performs LinkService-specific operations to send a Nack. |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 222 | */ |
| 223 | virtual void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 224 | doSendNack(const lp::Nack& nack) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 225 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 226 | private: // lower interface to be overridden in subclass |
| 227 | virtual void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 228 | doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 229 | |
| 230 | private: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 231 | Face* m_face = nullptr; |
| 232 | Transport* m_transport = nullptr; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 233 | }; |
| 234 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 235 | std::ostream& |
| 236 | operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh); |
| 237 | |
| 238 | template<typename T> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 239 | std::enable_if_t<std::is_base_of_v<LinkService, T> && !std::is_same_v<LinkService, T>, |
| 240 | std::ostream&> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 241 | operator<<(std::ostream& os, const FaceLogHelper<T>& flh) |
| 242 | { |
| 243 | return os << FaceLogHelper<LinkService>(flh.obj); |
| 244 | } |
| 245 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 246 | } // namespace nfd::face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 247 | |
| 248 | #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP |