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 | a3a7a4e | 2022-05-29 16:06:22 -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_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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 34 | namespace nfd::face { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 36 | /** \brief Counters provided by GenericLinkService. |
| 37 | * \note The type name GenericLinkServiceCounters is an implementation detail. |
| 38 | * Use GenericLinkService::Counters in public API. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 39 | */ |
| 40 | class GenericLinkServiceCounters : public virtual LinkService::Counters |
| 41 | { |
| 42 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 43 | /** \brief Count of failed fragmentations. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 44 | */ |
| 45 | PacketCounter nFragmentationErrors; |
| 46 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 47 | /** \brief Count of outgoing LpPackets dropped due to exceeding MTU limit. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 48 | * |
| 49 | * If this counter is non-zero, the operator should enable fragmentation. |
| 50 | */ |
| 51 | PacketCounter nOutOverMtu; |
| 52 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 53 | /** \brief Count of invalid LpPackets dropped before reassembly. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 54 | */ |
| 55 | PacketCounter nInLpInvalid; |
| 56 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 57 | /** \brief Count of network-layer packets currently being reassembled. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 58 | */ |
| 59 | SizeCounter<LpReassembler> nReassembling; |
| 60 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 61 | /** \brief Count of dropped partial network-layer packets due to reassembly timeout. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 62 | */ |
| 63 | PacketCounter nReassemblyTimeouts; |
| 64 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 65 | /** \brief Count of invalid reassembled network-layer packets dropped. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 66 | */ |
| 67 | PacketCounter nInNetInvalid; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 68 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 69 | /** \brief Count of network-layer packets that did not require retransmission of a fragment. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 70 | */ |
| 71 | PacketCounter nAcknowledged; |
| 72 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 73 | /** \brief Count of network-layer packets that had at least one fragment retransmitted, but were |
| 74 | * eventually received in full. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 75 | */ |
| 76 | PacketCounter nRetransmitted; |
| 77 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 78 | /** \brief Count of network-layer packets dropped because a fragment reached the maximum number |
| 79 | * of retransmissions. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 80 | */ |
| 81 | PacketCounter nRetxExhausted; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 82 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 83 | /** \brief Count of LpPackets dropped due to duplicate Sequence numbers. |
Eric Newberry | 32f7eac | 2020-02-07 14:40:17 -0800 | [diff] [blame] | 84 | */ |
| 85 | PacketCounter nDuplicateSequence; |
| 86 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 87 | /** \brief Count of outgoing LpPackets that were marked with congestion marks. |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 88 | */ |
| 89 | PacketCounter nCongestionMarked; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 92 | /** |
| 93 | * \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol. |
| 94 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 95 | */ |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 96 | class GenericLinkService NFD_FINAL_UNLESS_WITH_TESTS : public LinkService |
| 97 | , protected virtual GenericLinkServiceCounters |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 98 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 99 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 100 | /** \brief %Options that control the behavior of GenericLinkService. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 101 | */ |
| 102 | class Options |
| 103 | { |
| 104 | public: |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 105 | Options() noexcept |
| 106 | { |
| 107 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 108 | |
| 109 | public: |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 110 | /** \brief Enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 111 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 112 | bool allowLocalFields = false; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 113 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 114 | /** \brief Enables fragmentation. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 115 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 116 | bool allowFragmentation = false; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 117 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 118 | /** \brief Options for fragmentation. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 119 | */ |
| 120 | LpFragmenter::Options fragmenterOptions; |
| 121 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 122 | /** \brief Enables reassembly. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 123 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 124 | bool allowReassembly = false; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 125 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 126 | /** \brief Options for reassembly. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 127 | */ |
| 128 | LpReassembler::Options reassemblerOptions; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 129 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 130 | /** \brief Options for reliability. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 131 | */ |
| 132 | LpReliability::Options reliabilityOptions; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 133 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 134 | /** \brief Enables send queue congestion detection and marking. |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 135 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 136 | bool allowCongestionMarking = false; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 137 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 138 | /** \brief Starting value for congestion marking interval. |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 139 | * |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 140 | * Packets are marked if the queue size stays above THRESHOLD for at least one INTERVAL. |
| 141 | * |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 142 | * The default value (100 ms) is taken from RFC 8289 (CoDel). |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 143 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 144 | time::nanoseconds baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 145 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 146 | /** \brief Default congestion threshold in bytes. |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 147 | * |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 148 | * Packets are marked if the queue size stays above THRESHOLD for at least one INTERVAL. |
| 149 | * |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 150 | * The default value (64 KiB) works well for a queue capacity of 200 KiB. |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 151 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 152 | size_t defaultCongestionThreshold = 65536; |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 153 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 154 | /** \brief Enables self-learning forwarding support. |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 155 | */ |
Teng Liang | 39465c2 | 2018-11-12 19:43:04 -0700 | [diff] [blame] | 156 | bool allowSelfLearning = true; |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 157 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 158 | /** \brief Overrides the MTU provided by Transport. |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 159 | * |
| 160 | * This MTU value will be used instead of the MTU provided by the transport if it is less than |
| 161 | * the transport MTU. However, it will not be utilized when the transport MTU is unlimited. |
| 162 | * |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 163 | * Acceptable values for this option are values >= #MIN_MTU, which can be validated before |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 164 | * being set with canOverrideMtuTo(). |
| 165 | */ |
| 166 | ssize_t overrideMtu = std::numeric_limits<ssize_t>::max(); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 169 | /** \brief %Counters provided by GenericLinkService. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 170 | */ |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 171 | using Counters = GenericLinkServiceCounters; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 172 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 173 | explicit |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 174 | GenericLinkService(const Options& options = {}); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 175 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 176 | /** \brief Get the options used by GenericLinkService. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 177 | */ |
| 178 | const Options& |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 179 | getOptions() const |
| 180 | { |
| 181 | return m_options; |
| 182 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 183 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 184 | /** \brief Sets the options used by GenericLinkService. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 185 | */ |
| 186 | void |
| 187 | setOptions(const Options& options); |
| 188 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 189 | const Counters& |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 190 | getCounters() const NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL |
| 191 | { |
| 192 | return *this; |
| 193 | } |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 194 | |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 195 | ssize_t |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 196 | getEffectiveMtu() const NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL; |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 197 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 198 | /** \brief Whether MTU can be overridden to the specified value. |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 199 | * |
| 200 | * If the transport MTU is unlimited, then this will always return false. |
| 201 | */ |
| 202 | bool |
| 203 | canOverrideMtuTo(ssize_t mtu) const; |
| 204 | |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 205 | NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 206 | /** \brief Request an IDLE packet to transmit pending service fields. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 207 | */ |
| 208 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 209 | requestIdlePacket(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 210 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 211 | /** \brief Send an LpPacket. |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 212 | */ |
| 213 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 214 | sendLpPacket(lp::Packet&& pkt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 215 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 216 | void |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 217 | doSendInterest(const Interest& interest) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 218 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 219 | void |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 220 | doSendData(const Data& data) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 221 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 222 | void |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 223 | doSendNack(const ndn::lp::Nack& nack) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 224 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 225 | /** \brief Assign consecutive sequence numbers to LpPackets. |
Eric Newberry | 32f7eac | 2020-02-07 14:40:17 -0800 | [diff] [blame] | 226 | */ |
| 227 | void |
| 228 | assignSequences(std::vector<lp::Packet>& pkts); |
| 229 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 230 | private: // send path |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 231 | /** \brief Encode link protocol fields from tags onto an outgoing LpPacket. |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 232 | * \param netPkt network-layer packet to extract tags from |
| 233 | * \param lpPacket LpPacket to add link protocol fields to |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 234 | */ |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 235 | void |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 236 | encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 237 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 238 | /** \brief Send a complete network layer packet. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 239 | * \param pkt LpPacket containing a complete network layer packet |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 240 | * \param isInterest whether the network layer packet is an Interest |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 241 | */ |
| 242 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 243 | sendNetPacket(lp::Packet&& pkt, bool isInterest); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 244 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 245 | /** \brief If the send queue is found to be congested, add a congestion mark to the packet |
| 246 | * according to CoDel. |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 247 | * \sa https://tools.ietf.org/html/rfc8289 |
| 248 | */ |
| 249 | void |
| 250 | checkCongestionLevel(lp::Packet& pkt); |
| 251 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 252 | private: // receive path |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 253 | void |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 254 | doReceivePacket(const Block& packet, const EndpointId& endpoint) NFD_OVERRIDE_WITH_TESTS_ELSE_FINAL; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 255 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 256 | /** \brief Decode incoming network-layer packet. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 257 | * \param netPkt reassembled network-layer packet |
| 258 | * \param firstPkt LpPacket of first fragment |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 259 | * \param endpointId endpoint of peer who sent the packet |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 260 | * |
| 261 | * If decoding is successful, a receive signal is emitted; |
| 262 | * otherwise, a warning is logged. |
| 263 | */ |
| 264 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 265 | decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 266 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 267 | /** \brief Decode incoming Interest. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 268 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 269 | * \param firstPkt LpPacket of first fragment; must not have Nack field |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 270 | * \param endpointId endpoint of peer who sent the Interest |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 271 | * |
| 272 | * If decoding is successful, receiveInterest signal is emitted; |
| 273 | * otherwise, a warning is logged. |
| 274 | * |
| 275 | * \throw tlv::Error parse error in an LpHeader field |
| 276 | */ |
| 277 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 278 | decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 279 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 280 | /** \brief Decode incoming Interest. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 281 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data |
| 282 | * \param firstPkt LpPacket of first fragment |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 283 | * \param endpointId endpoint of peer who sent the Data |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 284 | * |
| 285 | * If decoding is successful, receiveData signal is emitted; |
| 286 | * otherwise, a warning is logged. |
| 287 | * |
| 288 | * \throw tlv::Error parse error in an LpHeader field |
| 289 | */ |
| 290 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 291 | decodeData(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 292 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 293 | /** \brief Decode incoming Interest. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 294 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 295 | * \param firstPkt LpPacket of first fragment; must have Nack field |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 296 | * \param endpointId endpoint of peer who sent the Nack |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 297 | * |
| 298 | * If decoding is successful, receiveNack signal is emitted; |
| 299 | * otherwise, a warning is logged. |
| 300 | * |
| 301 | * \throw tlv::Error parse error in an LpHeader field |
| 302 | */ |
| 303 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 304 | decodeNack(const Block& netPkt, const lp::Packet& firstPkt, const EndpointId& endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 305 | |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 306 | NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE: |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 307 | Options m_options; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 308 | LpFragmenter m_fragmenter; |
| 309 | LpReassembler m_reassembler; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 310 | LpReliability m_reliability; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 311 | lp::Sequence m_lastSeqNo; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 312 | |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 313 | NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 314 | /// Time to mark next packet due to send queue congestion |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 315 | time::steady_clock::time_point m_nextMarkTime; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 316 | /// number of marked packets in the current incident of congestion |
| 317 | size_t m_nMarkedSinceInMarkingState; |
| 318 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 319 | friend LpReliability; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 322 | } // namespace nfd::face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 323 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 324 | #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |