Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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_GENERIC_LINK_SERVICE_HPP |
| 27 | #define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |
| 28 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 29 | #include "link-service.hpp" |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 30 | #include "lp-fragmenter.hpp" |
| 31 | #include "lp-reassembler.hpp" |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 32 | #include "lp-reliability.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace face { |
| 36 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 37 | /** \brief counters provided by GenericLinkService |
| 38 | * \note The type name 'GenericLinkServiceCounters' is implementation detail. |
| 39 | * Use 'GenericLinkService::Counters' in public API. |
| 40 | */ |
| 41 | class GenericLinkServiceCounters : public virtual LinkService::Counters |
| 42 | { |
| 43 | public: |
| 44 | explicit |
| 45 | GenericLinkServiceCounters(const LpReassembler& reassembler); |
| 46 | |
| 47 | /** \brief count of failed fragmentations |
| 48 | */ |
| 49 | PacketCounter nFragmentationErrors; |
| 50 | |
| 51 | /** \brief count of outgoing LpPackets dropped due to exceeding MTU limit |
| 52 | * |
| 53 | * If this counter is non-zero, the operator should enable fragmentation. |
| 54 | */ |
| 55 | PacketCounter nOutOverMtu; |
| 56 | |
| 57 | /** \brief count of invalid LpPackets dropped before reassembly |
| 58 | */ |
| 59 | PacketCounter nInLpInvalid; |
| 60 | |
| 61 | /** \brief count of network-layer packets currently being reassembled |
| 62 | */ |
| 63 | SizeCounter<LpReassembler> nReassembling; |
| 64 | |
| 65 | /** \brief count of dropped partial network-layer packets due to reassembly timeout |
| 66 | */ |
| 67 | PacketCounter nReassemblyTimeouts; |
| 68 | |
| 69 | /** \brief count of invalid reassembled network-layer packets dropped |
| 70 | */ |
| 71 | PacketCounter nInNetInvalid; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 72 | |
| 73 | /** \brief count of network-layer packets that did not require retransmission of a fragment |
| 74 | */ |
| 75 | PacketCounter nAcknowledged; |
| 76 | |
| 77 | /** \brief count of network-layer packets that had at least one fragment retransmitted, but were |
| 78 | * eventually received in full |
| 79 | */ |
| 80 | PacketCounter nRetransmitted; |
| 81 | |
| 82 | /** \brief count of network-layer packets dropped because a fragment reached the maximum number |
| 83 | * of retransmissions |
| 84 | */ |
| 85 | PacketCounter nRetxExhausted; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 88 | /** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 89 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 90 | * \todo #3941 declare GenericLinkServiceCounters as virtual inheritance |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 91 | */ |
| 92 | class GenericLinkService : public LinkService |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 93 | , protected GenericLinkServiceCounters |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 94 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 95 | public: |
| 96 | /** \brief Options that control the behavior of GenericLinkService |
| 97 | */ |
| 98 | class Options |
| 99 | { |
| 100 | public: |
| 101 | Options(); |
| 102 | |
| 103 | public: |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 104 | /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy |
| 105 | */ |
| 106 | bool allowLocalFields; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 107 | |
| 108 | /** \brief enables fragmentation |
| 109 | */ |
| 110 | bool allowFragmentation; |
| 111 | |
| 112 | /** \brief options for fragmentation |
| 113 | */ |
| 114 | LpFragmenter::Options fragmenterOptions; |
| 115 | |
| 116 | /** \brief enables reassembly |
| 117 | */ |
| 118 | bool allowReassembly; |
| 119 | |
| 120 | /** \brief options for reassembly |
| 121 | */ |
| 122 | LpReassembler::Options reassemblerOptions; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 123 | |
| 124 | /** \brief options for reliability |
| 125 | */ |
| 126 | LpReliability::Options reliabilityOptions; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 129 | /** \brief counters provided by GenericLinkService |
| 130 | */ |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 131 | using Counters = GenericLinkServiceCounters; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 132 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 133 | explicit |
| 134 | GenericLinkService(const Options& options = Options()); |
| 135 | |
| 136 | /** \brief get Options used by GenericLinkService |
| 137 | */ |
| 138 | const Options& |
| 139 | getOptions() const; |
| 140 | |
| 141 | /** \brief sets Options used by GenericLinkService |
| 142 | */ |
| 143 | void |
| 144 | setOptions(const Options& options); |
| 145 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 146 | const Counters& |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 147 | getCounters() const override; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 148 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 149 | PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 150 | /** \brief request an IDLE packet to transmit pending service fields |
| 151 | */ |
| 152 | void |
| 153 | requestIdlePacket(); |
| 154 | |
| 155 | /** \brief send an LpPacket fragment |
| 156 | * \param pkt LpPacket to send |
| 157 | */ |
| 158 | void |
| 159 | sendLpPacket(lp::Packet&& pkt); |
| 160 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 161 | /** \brief send Interest |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 162 | */ |
| 163 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 164 | doSendInterest(const Interest& interest) override; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 165 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 166 | /** \brief send Data |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 167 | */ |
| 168 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 169 | doSendData(const Data& data) override; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 170 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 171 | /** \brief send Nack |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 172 | */ |
| 173 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 174 | doSendNack(const ndn::lp::Nack& nack) override; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 175 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 176 | private: // send path |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 177 | /** \brief encode link protocol fields from tags onto an outgoing LpPacket |
| 178 | * \param netPkt network-layer packet to extract tags from |
| 179 | * \param lpPacket LpPacket to add link protocol fields to |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 180 | */ |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 181 | void |
| 182 | encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 183 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 184 | /** \brief send a complete network layer packet |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 185 | * \param pkt LpPacket containing a complete network layer packet |
| 186 | */ |
| 187 | void |
| 188 | sendNetPacket(lp::Packet&& pkt); |
| 189 | |
| 190 | /** \brief assign a sequence number to an LpPacket |
| 191 | */ |
| 192 | void |
| 193 | assignSequence(lp::Packet& pkt); |
| 194 | |
| 195 | /** \brief assign consecutive sequence numbers to LpPackets |
| 196 | */ |
| 197 | void |
| 198 | assignSequences(std::vector<lp::Packet>& pkts); |
| 199 | |
| 200 | private: // receive path |
| 201 | /** \brief receive Packet from Transport |
| 202 | */ |
| 203 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 204 | doReceivePacket(Transport::Packet&& packet) override; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 205 | |
| 206 | /** \brief decode incoming network-layer packet |
| 207 | * \param netPkt reassembled network-layer packet |
| 208 | * \param firstPkt LpPacket of first fragment |
| 209 | * |
| 210 | * If decoding is successful, a receive signal is emitted; |
| 211 | * otherwise, a warning is logged. |
| 212 | */ |
| 213 | void |
| 214 | decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt); |
| 215 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 216 | /** \brief decode incoming Interest |
| 217 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 218 | * \param firstPkt LpPacket of first fragment; must not have Nack field |
| 219 | * |
| 220 | * If decoding is successful, receiveInterest signal is emitted; |
| 221 | * otherwise, a warning is logged. |
| 222 | * |
| 223 | * \throw tlv::Error parse error in an LpHeader field |
| 224 | */ |
| 225 | void |
| 226 | decodeInterest(const Block& netPkt, const lp::Packet& firstPkt); |
| 227 | |
| 228 | /** \brief decode incoming Interest |
| 229 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data |
| 230 | * \param firstPkt LpPacket of first fragment |
| 231 | * |
| 232 | * If decoding is successful, receiveData signal is emitted; |
| 233 | * otherwise, a warning is logged. |
| 234 | * |
| 235 | * \throw tlv::Error parse error in an LpHeader field |
| 236 | */ |
| 237 | void |
| 238 | decodeData(const Block& netPkt, const lp::Packet& firstPkt); |
| 239 | |
| 240 | /** \brief decode incoming Interest |
| 241 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 242 | * \param firstPkt LpPacket of first fragment; must have Nack field |
| 243 | * |
| 244 | * If decoding is successful, receiveNack signal is emitted; |
| 245 | * otherwise, a warning is logged. |
| 246 | * |
| 247 | * \throw tlv::Error parse error in an LpHeader field |
| 248 | */ |
| 249 | void |
| 250 | decodeNack(const Block& netPkt, const lp::Packet& firstPkt); |
| 251 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 252 | PROTECTED_WITH_TESTS_ELSE_PRIVATE: |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 253 | Options m_options; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 254 | LpFragmenter m_fragmenter; |
| 255 | LpReassembler m_reassembler; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 256 | LpReliability m_reliability; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 257 | lp::Sequence m_lastSeqNo; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 258 | |
| 259 | friend class LpReliability; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 262 | inline const GenericLinkService::Options& |
| 263 | GenericLinkService::getOptions() const |
| 264 | { |
| 265 | return m_options; |
| 266 | } |
| 267 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 268 | inline const GenericLinkService::Counters& |
| 269 | GenericLinkService::getCounters() const |
| 270 | { |
| 271 | return *this; |
| 272 | } |
| 273 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 274 | } // namespace face |
| 275 | } // namespace nfd |
| 276 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 277 | #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |