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