Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [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 | #include "lp-reliability.hpp" |
| 27 | #include "generic-link-service.hpp" |
| 28 | #include "transport.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 29 | #include "common/global.hpp" |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace face { |
| 33 | |
| 34 | LpReliability::LpReliability(const LpReliability::Options& options, GenericLinkService* linkService) |
| 35 | : m_options(options) |
| 36 | , m_linkService(linkService) |
| 37 | , m_firstUnackedFrag(m_unackedFrags.begin()) |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 38 | , m_lastTxSeqNo(-1) // set to "-1" to start TxSequence numbers at 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 39 | { |
| 40 | BOOST_ASSERT(m_linkService != nullptr); |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 41 | BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void |
| 45 | LpReliability::setOptions(const Options& options) |
| 46 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 47 | BOOST_ASSERT(options.idleAckTimerPeriod > 0_ns); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 48 | |
| 49 | if (m_options.isEnabled && !options.isEnabled) { |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 50 | m_idleAckTimer.cancel(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | m_options = options; |
| 54 | } |
| 55 | |
| 56 | const GenericLinkService* |
| 57 | LpReliability::getLinkService() const |
| 58 | { |
| 59 | return m_linkService; |
| 60 | } |
| 61 | |
| 62 | void |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 63 | LpReliability::handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 64 | { |
| 65 | BOOST_ASSERT(m_options.isEnabled); |
| 66 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 67 | auto unackedFragsIt = m_unackedFrags.begin(); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 68 | auto sendTime = time::steady_clock::now(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 69 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 70 | auto netPkt = make_shared<NetPkt>(std::move(pkt), isInterest); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 71 | netPkt->unackedFrags.reserve(frags.size()); |
| 72 | |
| 73 | for (lp::Packet& frag : frags) { |
| 74 | // Assign TxSequence number |
| 75 | lp::Sequence txSeq = assignTxSequence(frag); |
| 76 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 77 | // Store LpPacket for future retransmissions |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 78 | unackedFragsIt = m_unackedFrags.emplace_hint(unackedFragsIt, |
| 79 | std::piecewise_construct, |
| 80 | std::forward_as_tuple(txSeq), |
| 81 | std::forward_as_tuple(frag)); |
| 82 | unackedFragsIt->second.sendTime = sendTime; |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 83 | unackedFragsIt->second.rtoTimer = getScheduler().schedule(m_rttEst.getEstimatedRto(), |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 84 | [=] { onLpPacketLost(txSeq); }); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 85 | unackedFragsIt->second.netPkt = netPkt; |
| 86 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 87 | if (m_unackedFrags.size() == 1) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 88 | m_firstUnackedFrag = m_unackedFrags.begin(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 89 | } |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 90 | |
| 91 | // Add to associated NetPkt |
| 92 | netPkt->unackedFrags.push_back(unackedFragsIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | LpReliability::processIncomingPacket(const lp::Packet& pkt) |
| 98 | { |
| 99 | BOOST_ASSERT(m_options.isEnabled); |
| 100 | |
| 101 | auto now = time::steady_clock::now(); |
| 102 | |
| 103 | // Extract and parse Acks |
| 104 | for (lp::Sequence ackSeq : pkt.list<lp::AckField>()) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 105 | auto fragIt = m_unackedFrags.find(ackSeq); |
| 106 | if (fragIt == m_unackedFrags.end()) { |
| 107 | // Ignore an Ack for an unknown TxSequence number |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 108 | continue; |
| 109 | } |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 110 | auto& frag = fragIt->second; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 111 | |
| 112 | // Cancel the RTO timer for the acknowledged fragment |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 113 | frag.rtoTimer.cancel(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 114 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 115 | if (frag.retxCount == 0) { |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 116 | // This sequence had no retransmissions, so use it to estimate the RTO |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 117 | m_rttEst.addMeasurement(now - frag.sendTime); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 120 | // Look for frags with TxSequence numbers < ackSeq (allowing for wraparound) and consider them |
| 121 | // lost if a configurable number of Acks containing greater TxSequence numbers have been |
| 122 | // received. |
| 123 | auto lostLpPackets = findLostLpPackets(fragIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 124 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 125 | // Remove the fragment from the map of unacknowledged fragments and from its associated network |
| 126 | // packet. Potentially increment the start of the window. |
| 127 | onLpPacketAcknowledged(fragIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 128 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 129 | // This set contains TxSequences that have been removed by onLpPacketLost below because they |
| 130 | // were part of a network packet that was removed due to a fragment exceeding retx, as well as |
| 131 | // any other TxSequences removed by onLpPacketLost. This prevents onLpPacketLost from being |
| 132 | // called later for an invalid iterator. |
| 133 | std::set<lp::Sequence> removedLpPackets; |
| 134 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 135 | // Resend or fail fragments considered lost. Potentially increment the start of the window. |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 136 | for (lp::Sequence txSeq : lostLpPackets) { |
| 137 | if (removedLpPackets.find(txSeq) == removedLpPackets.end()) { |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 138 | auto removedThisTxSeq = onLpPacketLost(txSeq); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 139 | for (auto removedTxSeq : removedThisTxSeq) { |
| 140 | removedLpPackets.insert(removedTxSeq); |
| 141 | } |
| 142 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 146 | // If packet has Fragment and TxSequence fields, extract TxSequence and add to AckQueue |
| 147 | if (pkt.has<lp::FragmentField>() && pkt.has<lp::TxSequenceField>()) { |
| 148 | m_ackQueue.push(pkt.get<lp::TxSequenceField>()); |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 149 | startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | LpReliability::piggyback(lp::Packet& pkt, ssize_t mtu) |
| 155 | { |
| 156 | BOOST_ASSERT(m_options.isEnabled); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 157 | BOOST_ASSERT(pkt.wireEncode().type() == lp::tlv::LpPacket); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 158 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 159 | // up to 2 extra octets reserved for potential TLV-LENGTH size increases |
| 160 | ssize_t pktSize = pkt.wireEncode().size(); |
| 161 | ssize_t reservedSpace = tlv::sizeOfVarNumber(ndn::MAX_NDN_PACKET_SIZE) - |
| 162 | tlv::sizeOfVarNumber(pktSize); |
| 163 | ssize_t remainingSpace = (mtu == MTU_UNLIMITED ? ndn::MAX_NDN_PACKET_SIZE : mtu) - reservedSpace; |
| 164 | remainingSpace -= pktSize; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 165 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 166 | while (!m_ackQueue.empty()) { |
| 167 | lp::Sequence ackSeq = m_ackQueue.front(); |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 168 | // Ack size = Ack TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets) |
Junxiao Shi | 21e0193 | 2018-04-21 10:39:05 +0000 | [diff] [blame] | 169 | const ssize_t ackSize = tlv::sizeOfVarNumber(lp::tlv::Ack) + |
| 170 | tlv::sizeOfVarNumber(sizeof(lp::Sequence)) + |
| 171 | sizeof(lp::Sequence); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 172 | |
| 173 | if (ackSize > remainingSpace) { |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | pkt.add<lp::AckField>(ackSeq); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 178 | m_ackQueue.pop(); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 179 | remainingSpace -= ackSize; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 183 | lp::Sequence |
| 184 | LpReliability::assignTxSequence(lp::Packet& frag) |
| 185 | { |
| 186 | lp::Sequence txSeq = ++m_lastTxSeqNo; |
| 187 | frag.set<lp::TxSequenceField>(txSeq); |
| 188 | if (m_unackedFrags.size() > 0 && m_lastTxSeqNo == m_firstUnackedFrag->first) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 189 | NDN_THROW(std::length_error("TxSequence range exceeded")); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 190 | } |
| 191 | return m_lastTxSeqNo; |
| 192 | } |
| 193 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 194 | void |
| 195 | LpReliability::startIdleAckTimer() |
| 196 | { |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 197 | if (m_idleAckTimer) { |
| 198 | // timer is already running, do nothing |
| 199 | return; |
| 200 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 201 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 202 | m_idleAckTimer = getScheduler().schedule(m_options.idleAckTimerPeriod, [this] { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 203 | while (!m_ackQueue.empty()) { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 204 | m_linkService->requestIdlePacket(0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 205 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 206 | }); |
| 207 | } |
| 208 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 209 | std::vector<lp::Sequence> |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 210 | LpReliability::findLostLpPackets(LpReliability::UnackedFrags::iterator ackIt) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 211 | { |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 212 | std::vector<lp::Sequence> lostLpPackets; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 213 | |
| 214 | for (auto it = m_firstUnackedFrag; ; ++it) { |
| 215 | if (it == m_unackedFrags.end()) { |
| 216 | it = m_unackedFrags.begin(); |
| 217 | } |
| 218 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 219 | if (it->first == ackIt->first) { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | |
| 223 | auto& unackedFrag = it->second; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 224 | unackedFrag.nGreaterSeqAcks++; |
| 225 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 226 | if (unackedFrag.nGreaterSeqAcks >= m_options.seqNumLossThreshold) { |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 227 | lostLpPackets.push_back(it->first); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | return lostLpPackets; |
| 232 | } |
| 233 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 234 | std::vector<lp::Sequence> |
| 235 | LpReliability::onLpPacketLost(lp::Sequence txSeq) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 236 | { |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 237 | BOOST_ASSERT(m_unackedFrags.count(txSeq) > 0); |
| 238 | auto txSeqIt = m_unackedFrags.find(txSeq); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 239 | |
| 240 | auto& txFrag = txSeqIt->second; |
| 241 | txFrag.rtoTimer.cancel(); |
| 242 | auto netPkt = txFrag.netPkt; |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 243 | std::vector<lp::Sequence> removedThisTxSeq; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 244 | |
| 245 | // Check if maximum number of retransmissions exceeded |
| 246 | if (txFrag.retxCount >= m_options.maxRetx) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 247 | // Delete all LpPackets of NetPkt from m_unackedFrags (except this one) |
| 248 | for (size_t i = 0; i < netPkt->unackedFrags.size(); i++) { |
| 249 | if (netPkt->unackedFrags[i] != txSeqIt) { |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 250 | removedThisTxSeq.push_back(netPkt->unackedFrags[i]->first); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 251 | deleteUnackedFrag(netPkt->unackedFrags[i]); |
| 252 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 253 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 254 | |
| 255 | ++m_linkService->nRetxExhausted; |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 256 | |
| 257 | // Notify strategy of dropped Interest (if any) |
| 258 | if (netPkt->isInterest) { |
| 259 | BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>()); |
| 260 | ndn::Buffer::const_iterator fragBegin, fragEnd; |
| 261 | std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>(); |
| 262 | Block frag(&*fragBegin, std::distance(fragBegin, fragEnd)); |
| 263 | onDroppedInterest(Interest(frag)); |
| 264 | } |
| 265 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 266 | removedThisTxSeq.push_back(txSeqIt->first); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 267 | deleteUnackedFrag(txSeqIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 268 | } |
| 269 | else { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 270 | // Assign new TxSequence |
| 271 | lp::Sequence newTxSeq = assignTxSequence(txFrag.pkt); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 272 | netPkt->didRetx = true; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 273 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 274 | // Move fragment to new TxSequence mapping |
| 275 | auto newTxFragIt = m_unackedFrags.emplace_hint( |
| 276 | m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq |
| 277 | ? m_firstUnackedFrag |
| 278 | : m_unackedFrags.end(), |
| 279 | std::piecewise_construct, |
| 280 | std::forward_as_tuple(newTxSeq), |
| 281 | std::forward_as_tuple(txFrag.pkt)); |
| 282 | auto& newTxFrag = newTxFragIt->second; |
| 283 | newTxFrag.retxCount = txFrag.retxCount + 1; |
| 284 | newTxFrag.netPkt = netPkt; |
| 285 | |
| 286 | // Update associated NetPkt |
| 287 | auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), txSeqIt); |
| 288 | BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end()); |
| 289 | *fragInNetPkt = newTxFragIt; |
| 290 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 291 | removedThisTxSeq.push_back(txSeqIt->first); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 292 | deleteUnackedFrag(txSeqIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 293 | |
| 294 | // Retransmit fragment |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 295 | m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 296 | |
| 297 | // Start RTO timer for this sequence |
Davide Pesavento | f190cfa | 2019-07-17 20:14:11 -0400 | [diff] [blame] | 298 | newTxFrag.rtoTimer = getScheduler().schedule(m_rttEst.getEstimatedRto(), |
| 299 | [=] { onLpPacketLost(newTxSeq); }); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 300 | } |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 301 | |
| 302 | return removedThisTxSeq; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 306 | LpReliability::onLpPacketAcknowledged(UnackedFrags::iterator fragIt) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 307 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 308 | auto netPkt = fragIt->second.netPkt; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 309 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 310 | // Remove from NetPkt unacked fragment list |
| 311 | auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), fragIt); |
| 312 | BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end()); |
| 313 | *fragInNetPkt = netPkt->unackedFrags.back(); |
| 314 | netPkt->unackedFrags.pop_back(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 315 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 316 | // Check if network-layer packet completely received. If so, increment counters |
| 317 | if (netPkt->unackedFrags.empty()) { |
| 318 | if (netPkt->didRetx) { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 319 | ++m_linkService->nRetransmitted; |
| 320 | } |
| 321 | else { |
| 322 | ++m_linkService->nAcknowledged; |
| 323 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 324 | } |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 325 | |
| 326 | deleteUnackedFrag(fragIt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 329 | void |
| 330 | LpReliability::deleteUnackedFrag(UnackedFrags::iterator fragIt) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 331 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 332 | lp::Sequence firstUnackedTxSeq = m_firstUnackedFrag->first; |
| 333 | lp::Sequence currentTxSeq = fragIt->first; |
| 334 | auto nextFragIt = m_unackedFrags.erase(fragIt); |
| 335 | |
| 336 | if (!m_unackedFrags.empty() && firstUnackedTxSeq == currentTxSeq) { |
| 337 | // If "first" fragment in send window (allowing for wraparound), increment window begin |
| 338 | if (nextFragIt == m_unackedFrags.end()) { |
| 339 | m_firstUnackedFrag = m_unackedFrags.begin(); |
| 340 | } |
| 341 | else { |
| 342 | m_firstUnackedFrag = nextFragIt; |
| 343 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 344 | } |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 345 | else if (m_unackedFrags.empty()) { |
| 346 | m_firstUnackedFrag = m_unackedFrags.end(); |
| 347 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | LpReliability::UnackedFrag::UnackedFrag(lp::Packet pkt) |
| 351 | : pkt(std::move(pkt)) |
| 352 | , sendTime(time::steady_clock::now()) |
| 353 | , retxCount(0) |
| 354 | , nGreaterSeqAcks(0) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 355 | { |
| 356 | } |
| 357 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 358 | LpReliability::NetPkt::NetPkt(lp::Packet&& pkt, bool isInterest) |
| 359 | : pkt(std::move(pkt)) |
| 360 | , isInterest(isInterest) |
| 361 | , didRetx(false) |
| 362 | { |
| 363 | } |
| 364 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 365 | } // namespace face |
| 366 | } // namespace nfd |