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 | /* |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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 | */ |
| 53 | PacketCounter nDroppedInterests; |
| 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: |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 78 | /** \brief counters provided by LinkService |
| 79 | */ |
| 80 | typedef LinkServiceCounters Counters; |
| 81 | |
| 82 | public: |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 83 | LinkService(); |
| 84 | |
| 85 | virtual |
| 86 | ~LinkService(); |
| 87 | |
| 88 | /** \brief set Face and Transport for LinkService |
| 89 | * \pre setFaceAndTransport has not been called |
| 90 | */ |
| 91 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 92 | setFaceAndTransport(Face& face, Transport& transport); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 93 | |
| 94 | /** \return Face to which this LinkService is attached |
| 95 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 96 | const Face* |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 97 | getFace() const; |
| 98 | |
| 99 | /** \return Transport to which this LinkService is attached |
| 100 | */ |
| 101 | const Transport* |
| 102 | getTransport() const; |
| 103 | |
| 104 | /** \return Transport to which this LinkService is attached |
| 105 | */ |
| 106 | Transport* |
| 107 | getTransport(); |
| 108 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 109 | virtual const Counters& |
| 110 | getCounters() const; |
| 111 | |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 112 | virtual ssize_t |
| 113 | getEffectiveMtu() const; |
| 114 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 115 | public: // upper interface to be used by forwarding |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 116 | /** \brief Send Interest to \p endpoint |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 117 | * \pre setTransport has been called |
| 118 | */ |
| 119 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 120 | sendInterest(const Interest& interest, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 121 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 122 | /** \brief Send Data to \p endpoint |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 123 | * \pre setTransport has been called |
| 124 | */ |
| 125 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 126 | sendData(const Data& data, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 127 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 128 | /** \brief Send Nack to \p endpoint |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 129 | * \pre setTransport has been called |
| 130 | */ |
| 131 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 132 | sendNack(const ndn::lp::Nack& nack, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 133 | |
| 134 | /** \brief signals on Interest received |
| 135 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 136 | signal::Signal<LinkService, Interest, EndpointId> afterReceiveInterest; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 137 | |
| 138 | /** \brief signals on Data received |
| 139 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 140 | signal::Signal<LinkService, Data, EndpointId> afterReceiveData; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 141 | |
| 142 | /** \brief signals on Nack received |
| 143 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 144 | signal::Signal<LinkService, lp::Nack, EndpointId> afterReceiveNack; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 145 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 146 | /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx |
| 147 | */ |
| 148 | signal::Signal<LinkService, Interest> onDroppedInterest; |
| 149 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 150 | public: // lower interface to be invoked by Transport |
| 151 | /** \brief performs LinkService specific operations to receive a lower-layer packet |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 152 | */ |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 153 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 154 | receivePacket(const Block& packet, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 155 | |
| 156 | protected: // upper interface to be invoked in subclass (receive path termination) |
| 157 | /** \brief delivers received Interest to forwarding |
| 158 | */ |
| 159 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 160 | receiveInterest(const Interest& interest, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 161 | |
| 162 | /** \brief delivers received Data to forwarding |
| 163 | */ |
| 164 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 165 | receiveData(const Data& data, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 166 | |
| 167 | /** \brief delivers received Nack to forwarding |
| 168 | */ |
| 169 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 170 | receiveNack(const lp::Nack& nack, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 171 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 172 | protected: // lower interface to be invoked in subclass (send path termination) |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 173 | /** \brief send a lower-layer packet via Transport to \p endpoint |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 174 | */ |
| 175 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 176 | sendPacket(const Block& packet, const EndpointId& endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 177 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 178 | protected: |
| 179 | void |
| 180 | notifyDroppedInterest(const Interest& packet); |
| 181 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 182 | private: // upper interface to be overridden in subclass (send path entrypoint) |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 183 | /** \brief performs LinkService specific operations to send an Interest to \p endpoint |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 184 | */ |
| 185 | virtual void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 186 | doSendInterest(const Interest& interest, const EndpointId& endpoint) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 187 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 188 | /** \brief performs LinkService specific operations to send a Data to \p endpoint |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 189 | */ |
| 190 | virtual void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 191 | doSendData(const Data& data, const EndpointId& endpoint) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 192 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 193 | /** \brief performs LinkService specific operations to send a Nack to \p endpoint |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 194 | */ |
| 195 | virtual void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 196 | doSendNack(const lp::Nack& nack, const EndpointId& endpoint) = 0; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 197 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 198 | private: // lower interface to be overridden in subclass |
| 199 | virtual void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 200 | doReceivePacket(const Block& packet, const EndpointId& endpoint) = 0; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 201 | |
| 202 | private: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 203 | Face* m_face; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 204 | Transport* m_transport; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 207 | inline const Face* |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 208 | LinkService::getFace() const |
| 209 | { |
| 210 | return m_face; |
| 211 | } |
| 212 | |
| 213 | inline const Transport* |
| 214 | LinkService::getTransport() const |
| 215 | { |
| 216 | return m_transport; |
| 217 | } |
| 218 | |
| 219 | inline Transport* |
| 220 | LinkService::getTransport() |
| 221 | { |
| 222 | return m_transport; |
| 223 | } |
| 224 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 225 | inline const LinkService::Counters& |
| 226 | LinkService::getCounters() const |
| 227 | { |
| 228 | return *this; |
| 229 | } |
| 230 | |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 231 | inline ssize_t |
| 232 | LinkService::getEffectiveMtu() const |
| 233 | { |
| 234 | return m_transport->getMtu(); |
| 235 | } |
| 236 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 237 | inline void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 238 | LinkService::receivePacket(const Block& packet, const EndpointId& endpoint) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 239 | { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 240 | doReceivePacket(packet, endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | inline void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 244 | LinkService::sendPacket(const Block& packet, const EndpointId& endpoint) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 245 | { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 246 | m_transport->send(packet, endpoint); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | std::ostream& |
| 250 | operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh); |
| 251 | |
| 252 | template<typename T> |
| 253 | typename std::enable_if<std::is_base_of<LinkService, T>::value && |
| 254 | !std::is_same<LinkService, T>::value, std::ostream&>::type |
| 255 | operator<<(std::ostream& os, const FaceLogHelper<T>& flh) |
| 256 | { |
| 257 | return os << FaceLogHelper<LinkService>(flh.obj); |
| 258 | } |
| 259 | |
| 260 | } // namespace face |
| 261 | } // namespace nfd |
| 262 | |
| 263 | #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP |