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