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