blob: e9a4914709160696a80143454c6d85812061f9a4 [file] [log] [blame]
Eric Newberry185ab292017-03-28 06:45:39 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberry5ab4cf82020-02-03 15:40:16 -08003 * Copyright (c) 2014-2020, Regents of the University of California,
Eric Newberry185ab292017-03-28 06:45:39 +00004 * 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 Pesavento2cae8ca2019-04-18 20:48:05 -040029#include "common/global.hpp"
Eric Newberry185ab292017-03-28 06:45:39 +000030
31namespace nfd {
32namespace face {
33
Eric Newberry5ab4cf82020-02-03 15:40:16 -080034NFD_LOG_INIT(LpReliability);
35
Eric Newberry185ab292017-03-28 06:45:39 +000036LpReliability::LpReliability(const LpReliability::Options& options, GenericLinkService* linkService)
37 : m_options(options)
38 , m_linkService(linkService)
39 , m_firstUnackedFrag(m_unackedFrags.begin())
Eric Newberry7b0071e2017-07-03 17:33:31 +000040 , m_lastTxSeqNo(-1) // set to "-1" to start TxSequence numbers at 0
Eric Newberry185ab292017-03-28 06:45:39 +000041{
42 BOOST_ASSERT(m_linkService != nullptr);
Davide Pesaventoe4b22382018-06-10 14:37:24 -040043 BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns);
Eric Newberry185ab292017-03-28 06:45:39 +000044}
45
46void
47LpReliability::setOptions(const Options& options)
48{
Davide Pesaventoe4b22382018-06-10 14:37:24 -040049 BOOST_ASSERT(options.idleAckTimerPeriod > 0_ns);
Eric Newberry185ab292017-03-28 06:45:39 +000050
51 if (m_options.isEnabled && !options.isEnabled) {
Davide Pesaventof190cfa2019-07-17 20:14:11 -040052 m_idleAckTimer.cancel();
Eric Newberry185ab292017-03-28 06:45:39 +000053 }
54
55 m_options = options;
56}
57
58const GenericLinkService*
59LpReliability::getLinkService() const
60{
61 return m_linkService;
62}
63
64void
Eric Newberry41aba102017-11-01 16:42:13 -070065LpReliability::handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt, bool isInterest)
Eric Newberry185ab292017-03-28 06:45:39 +000066{
67 BOOST_ASSERT(m_options.isEnabled);
68
Eric Newberry185ab292017-03-28 06:45:39 +000069 auto unackedFragsIt = m_unackedFrags.begin();
Eric Newberry7b0071e2017-07-03 17:33:31 +000070 auto sendTime = time::steady_clock::now();
Eric Newberry185ab292017-03-28 06:45:39 +000071
Eric Newberry41aba102017-11-01 16:42:13 -070072 auto netPkt = make_shared<NetPkt>(std::move(pkt), isInterest);
Eric Newberry7b0071e2017-07-03 17:33:31 +000073 netPkt->unackedFrags.reserve(frags.size());
74
75 for (lp::Packet& frag : frags) {
76 // Assign TxSequence number
77 lp::Sequence txSeq = assignTxSequence(frag);
78
Eric Newberry185ab292017-03-28 06:45:39 +000079 // Store LpPacket for future retransmissions
Eric Newberry7b0071e2017-07-03 17:33:31 +000080 unackedFragsIt = m_unackedFrags.emplace_hint(unackedFragsIt,
81 std::piecewise_construct,
82 std::forward_as_tuple(txSeq),
83 std::forward_as_tuple(frag));
84 unackedFragsIt->second.sendTime = sendTime;
Eric Newberry5ab4cf82020-02-03 15:40:16 -080085 auto rto = m_rttEst.getEstimatedRto();
86 NFD_LOG_FACE_TRACE("transmitting txseq=" << txSeq << ", rto=" <<
87 time::duration_cast<time::milliseconds>(rto).count() << "ms");
88 unackedFragsIt->second.rtoTimer = getScheduler().schedule(rto, [=] {
89 NFD_LOG_FACE_TRACE("rto timer expired for txseq=" << txSeq);
90 onLpPacketLost(txSeq);
91 });
Eric Newberry7b0071e2017-07-03 17:33:31 +000092 unackedFragsIt->second.netPkt = netPkt;
93
Eric Newberry185ab292017-03-28 06:45:39 +000094 if (m_unackedFrags.size() == 1) {
Eric Newberry7b0071e2017-07-03 17:33:31 +000095 m_firstUnackedFrag = m_unackedFrags.begin();
Eric Newberry185ab292017-03-28 06:45:39 +000096 }
Eric Newberry7b0071e2017-07-03 17:33:31 +000097
98 // Add to associated NetPkt
99 netPkt->unackedFrags.push_back(unackedFragsIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000100 }
101}
102
103void
104LpReliability::processIncomingPacket(const lp::Packet& pkt)
105{
106 BOOST_ASSERT(m_options.isEnabled);
107
108 auto now = time::steady_clock::now();
109
110 // Extract and parse Acks
111 for (lp::Sequence ackSeq : pkt.list<lp::AckField>()) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000112 auto fragIt = m_unackedFrags.find(ackSeq);
113 if (fragIt == m_unackedFrags.end()) {
114 // Ignore an Ack for an unknown TxSequence number
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800115 NFD_LOG_FACE_DEBUG("received ack for unknown txseq=" << ackSeq);
Eric Newberry185ab292017-03-28 06:45:39 +0000116 continue;
117 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000118 auto& frag = fragIt->second;
Eric Newberry185ab292017-03-28 06:45:39 +0000119
120 // Cancel the RTO timer for the acknowledged fragment
Eric Newberry7b0071e2017-07-03 17:33:31 +0000121 frag.rtoTimer.cancel();
Eric Newberry185ab292017-03-28 06:45:39 +0000122
Eric Newberry7b0071e2017-07-03 17:33:31 +0000123 if (frag.retxCount == 0) {
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800124 NFD_LOG_FACE_TRACE("received ack for txseq=" << ackSeq << ", retx=0, rtt=" <<
125 time::duration_cast<time::milliseconds>(now - frag.sendTime).count() << "ms");
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400126 // This sequence had no retransmissions, so use it to estimate the RTO
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400127 m_rttEst.addMeasurement(now - frag.sendTime);
Eric Newberry185ab292017-03-28 06:45:39 +0000128 }
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800129 else {
130 NFD_LOG_FACE_TRACE("received ack for txseq=" << ackSeq << ", retx=" << frag.retxCount);
131 }
Eric Newberry185ab292017-03-28 06:45:39 +0000132
Eric Newberry7b0071e2017-07-03 17:33:31 +0000133 // Look for frags with TxSequence numbers < ackSeq (allowing for wraparound) and consider them
134 // lost if a configurable number of Acks containing greater TxSequence numbers have been
135 // received.
136 auto lostLpPackets = findLostLpPackets(fragIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000137
Eric Newberry7b0071e2017-07-03 17:33:31 +0000138 // Remove the fragment from the map of unacknowledged fragments and from its associated network
139 // packet. Potentially increment the start of the window.
140 onLpPacketAcknowledged(fragIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000141
Eric Newberry971d9622018-03-30 23:29:26 -0700142 // This set contains TxSequences that have been removed by onLpPacketLost below because they
143 // were part of a network packet that was removed due to a fragment exceeding retx, as well as
144 // any other TxSequences removed by onLpPacketLost. This prevents onLpPacketLost from being
145 // called later for an invalid iterator.
146 std::set<lp::Sequence> removedLpPackets;
147
Eric Newberry7b0071e2017-07-03 17:33:31 +0000148 // Resend or fail fragments considered lost. Potentially increment the start of the window.
Eric Newberry971d9622018-03-30 23:29:26 -0700149 for (lp::Sequence txSeq : lostLpPackets) {
150 if (removedLpPackets.find(txSeq) == removedLpPackets.end()) {
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800151 NFD_LOG_FACE_TRACE("txseq=" << txSeq << " considered lost from acks for more recent txseqs");
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400152 auto removedThisTxSeq = onLpPacketLost(txSeq);
Eric Newberry971d9622018-03-30 23:29:26 -0700153 for (auto removedTxSeq : removedThisTxSeq) {
154 removedLpPackets.insert(removedTxSeq);
155 }
156 }
Eric Newberry185ab292017-03-28 06:45:39 +0000157 }
158 }
159
Eric Newberry7b0071e2017-07-03 17:33:31 +0000160 // If packet has Fragment and TxSequence fields, extract TxSequence and add to AckQueue
161 if (pkt.has<lp::FragmentField>() && pkt.has<lp::TxSequenceField>()) {
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800162 NFD_LOG_FACE_TRACE("queueing ack for remote txseq=" << pkt.get<lp::TxSequenceField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000163 m_ackQueue.push(pkt.get<lp::TxSequenceField>());
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400164 startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000165 }
166}
167
168void
169LpReliability::piggyback(lp::Packet& pkt, ssize_t mtu)
170{
171 BOOST_ASSERT(m_options.isEnabled);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000172 BOOST_ASSERT(pkt.wireEncode().type() == lp::tlv::LpPacket);
Eric Newberry185ab292017-03-28 06:45:39 +0000173
Eric Newberry7b0071e2017-07-03 17:33:31 +0000174 // up to 2 extra octets reserved for potential TLV-LENGTH size increases
175 ssize_t pktSize = pkt.wireEncode().size();
176 ssize_t reservedSpace = tlv::sizeOfVarNumber(ndn::MAX_NDN_PACKET_SIZE) -
177 tlv::sizeOfVarNumber(pktSize);
178 ssize_t remainingSpace = (mtu == MTU_UNLIMITED ? ndn::MAX_NDN_PACKET_SIZE : mtu) - reservedSpace;
179 remainingSpace -= pktSize;
Eric Newberry185ab292017-03-28 06:45:39 +0000180
Eric Newberry7b0071e2017-07-03 17:33:31 +0000181 while (!m_ackQueue.empty()) {
182 lp::Sequence ackSeq = m_ackQueue.front();
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400183 // Ack size = Ack TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
Junxiao Shi21e01932018-04-21 10:39:05 +0000184 const ssize_t ackSize = tlv::sizeOfVarNumber(lp::tlv::Ack) +
185 tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
186 sizeof(lp::Sequence);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000187
188 if (ackSize > remainingSpace) {
189 break;
190 }
191
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800192 NFD_LOG_FACE_TRACE("piggybacking ack for remote txseq=" << ackSeq);
193
Eric Newberry7b0071e2017-07-03 17:33:31 +0000194 pkt.add<lp::AckField>(ackSeq);
Eric Newberry185ab292017-03-28 06:45:39 +0000195 m_ackQueue.pop();
Eric Newberry7b0071e2017-07-03 17:33:31 +0000196 remainingSpace -= ackSize;
Eric Newberry185ab292017-03-28 06:45:39 +0000197 }
198}
199
Eric Newberry7b0071e2017-07-03 17:33:31 +0000200lp::Sequence
201LpReliability::assignTxSequence(lp::Packet& frag)
202{
203 lp::Sequence txSeq = ++m_lastTxSeqNo;
204 frag.set<lp::TxSequenceField>(txSeq);
205 if (m_unackedFrags.size() > 0 && m_lastTxSeqNo == m_firstUnackedFrag->first) {
Davide Pesavento19779d82019-02-14 13:40:04 -0500206 NDN_THROW(std::length_error("TxSequence range exceeded"));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000207 }
208 return m_lastTxSeqNo;
209}
210
Eric Newberry185ab292017-03-28 06:45:39 +0000211void
212LpReliability::startIdleAckTimer()
213{
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400214 if (m_idleAckTimer) {
215 // timer is already running, do nothing
216 return;
217 }
Eric Newberry185ab292017-03-28 06:45:39 +0000218
Davide Pesavento3dade002019-03-19 11:29:56 -0600219 m_idleAckTimer = getScheduler().schedule(m_options.idleAckTimerPeriod, [this] {
Eric Newberry185ab292017-03-28 06:45:39 +0000220 while (!m_ackQueue.empty()) {
ashiqopu075bb7d2019-03-10 01:38:21 +0000221 m_linkService->requestIdlePacket(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000222 }
Eric Newberry185ab292017-03-28 06:45:39 +0000223 });
224}
225
Eric Newberry971d9622018-03-30 23:29:26 -0700226std::vector<lp::Sequence>
Eric Newberry7b0071e2017-07-03 17:33:31 +0000227LpReliability::findLostLpPackets(LpReliability::UnackedFrags::iterator ackIt)
Eric Newberry185ab292017-03-28 06:45:39 +0000228{
Eric Newberry971d9622018-03-30 23:29:26 -0700229 std::vector<lp::Sequence> lostLpPackets;
Eric Newberry185ab292017-03-28 06:45:39 +0000230
231 for (auto it = m_firstUnackedFrag; ; ++it) {
232 if (it == m_unackedFrags.end()) {
233 it = m_unackedFrags.begin();
234 }
235
Eric Newberry7b0071e2017-07-03 17:33:31 +0000236 if (it->first == ackIt->first) {
Eric Newberry185ab292017-03-28 06:45:39 +0000237 break;
238 }
239
240 auto& unackedFrag = it->second;
Eric Newberry185ab292017-03-28 06:45:39 +0000241 unackedFrag.nGreaterSeqAcks++;
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800242 NFD_LOG_FACE_TRACE("received ack=" << ackIt->first << ", out-of-order for txseq=" <<
243 it->first << ", out-of-order count=" << unackedFrag.nGreaterSeqAcks);
Eric Newberry185ab292017-03-28 06:45:39 +0000244
Eric Newberry7b0071e2017-07-03 17:33:31 +0000245 if (unackedFrag.nGreaterSeqAcks >= m_options.seqNumLossThreshold) {
Eric Newberry971d9622018-03-30 23:29:26 -0700246 lostLpPackets.push_back(it->first);
Eric Newberry185ab292017-03-28 06:45:39 +0000247 }
248 }
249
250 return lostLpPackets;
251}
252
Eric Newberry971d9622018-03-30 23:29:26 -0700253std::vector<lp::Sequence>
254LpReliability::onLpPacketLost(lp::Sequence txSeq)
Eric Newberry185ab292017-03-28 06:45:39 +0000255{
Eric Newberry971d9622018-03-30 23:29:26 -0700256 BOOST_ASSERT(m_unackedFrags.count(txSeq) > 0);
257 auto txSeqIt = m_unackedFrags.find(txSeq);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000258
259 auto& txFrag = txSeqIt->second;
260 txFrag.rtoTimer.cancel();
261 auto netPkt = txFrag.netPkt;
Eric Newberry971d9622018-03-30 23:29:26 -0700262 std::vector<lp::Sequence> removedThisTxSeq;
Eric Newberry185ab292017-03-28 06:45:39 +0000263
264 // Check if maximum number of retransmissions exceeded
265 if (txFrag.retxCount >= m_options.maxRetx) {
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800266 NFD_LOG_FACE_DEBUG("txseq=" << txSeq << " exceeded allowed retransmissions: DROP");
Eric Newberry7b0071e2017-07-03 17:33:31 +0000267 // Delete all LpPackets of NetPkt from m_unackedFrags (except this one)
268 for (size_t i = 0; i < netPkt->unackedFrags.size(); i++) {
269 if (netPkt->unackedFrags[i] != txSeqIt) {
Eric Newberry971d9622018-03-30 23:29:26 -0700270 removedThisTxSeq.push_back(netPkt->unackedFrags[i]->first);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000271 deleteUnackedFrag(netPkt->unackedFrags[i]);
272 }
Eric Newberry185ab292017-03-28 06:45:39 +0000273 }
Eric Newberry185ab292017-03-28 06:45:39 +0000274
275 ++m_linkService->nRetxExhausted;
Eric Newberry41aba102017-11-01 16:42:13 -0700276
277 // Notify strategy of dropped Interest (if any)
278 if (netPkt->isInterest) {
279 BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>());
280 ndn::Buffer::const_iterator fragBegin, fragEnd;
281 std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>();
282 Block frag(&*fragBegin, std::distance(fragBegin, fragEnd));
283 onDroppedInterest(Interest(frag));
284 }
285
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800286 // Delete this LpPacket from m_unackedFrags
Eric Newberry971d9622018-03-30 23:29:26 -0700287 removedThisTxSeq.push_back(txSeqIt->first);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000288 deleteUnackedFrag(txSeqIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000289 }
290 else {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000291 // Assign new TxSequence
292 lp::Sequence newTxSeq = assignTxSequence(txFrag.pkt);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700293 netPkt->didRetx = true;
Eric Newberry185ab292017-03-28 06:45:39 +0000294
Eric Newberry7b0071e2017-07-03 17:33:31 +0000295 // Move fragment to new TxSequence mapping
296 auto newTxFragIt = m_unackedFrags.emplace_hint(
297 m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq
298 ? m_firstUnackedFrag
299 : m_unackedFrags.end(),
300 std::piecewise_construct,
301 std::forward_as_tuple(newTxSeq),
302 std::forward_as_tuple(txFrag.pkt));
303 auto& newTxFrag = newTxFragIt->second;
304 newTxFrag.retxCount = txFrag.retxCount + 1;
305 newTxFrag.netPkt = netPkt;
306
307 // Update associated NetPkt
308 auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), txSeqIt);
309 BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end());
310 *fragInNetPkt = newTxFragIt;
311
Eric Newberry971d9622018-03-30 23:29:26 -0700312 removedThisTxSeq.push_back(txSeqIt->first);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000313 deleteUnackedFrag(txSeqIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000314
315 // Retransmit fragment
ashiqopu075bb7d2019-03-10 01:38:21 +0000316 m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000317
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800318 auto rto = m_rttEst.getEstimatedRto();
319 NFD_LOG_FACE_TRACE("retransmitting txseq=" << txSeq << " as " << newTxSeq << ", retx=" <<
320 txFrag.retxCount << ", rto=" <<
321 time::duration_cast<time::milliseconds>(rto).count() << "ms");
322
Eric Newberry7b0071e2017-07-03 17:33:31 +0000323 // Start RTO timer for this sequence
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800324 newTxFrag.rtoTimer = getScheduler().schedule(rto, [=] {
325 NFD_LOG_FACE_TRACE("rto timer expired for txseq=" << newTxSeq);
326 onLpPacketLost(newTxSeq);
327 });
Eric Newberry185ab292017-03-28 06:45:39 +0000328 }
Eric Newberry971d9622018-03-30 23:29:26 -0700329
330 return removedThisTxSeq;
Eric Newberry185ab292017-03-28 06:45:39 +0000331}
332
333void
Eric Newberry7b0071e2017-07-03 17:33:31 +0000334LpReliability::onLpPacketAcknowledged(UnackedFrags::iterator fragIt)
Eric Newberry185ab292017-03-28 06:45:39 +0000335{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000336 auto netPkt = fragIt->second.netPkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000337
Eric Newberry7b0071e2017-07-03 17:33:31 +0000338 // Remove from NetPkt unacked fragment list
339 auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), fragIt);
340 BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end());
341 *fragInNetPkt = netPkt->unackedFrags.back();
342 netPkt->unackedFrags.pop_back();
Eric Newberry185ab292017-03-28 06:45:39 +0000343
Eric Newberry7b0071e2017-07-03 17:33:31 +0000344 // Check if network-layer packet completely received. If so, increment counters
345 if (netPkt->unackedFrags.empty()) {
346 if (netPkt->didRetx) {
Eric Newberry185ab292017-03-28 06:45:39 +0000347 ++m_linkService->nRetransmitted;
348 }
349 else {
350 ++m_linkService->nAcknowledged;
351 }
Eric Newberry185ab292017-03-28 06:45:39 +0000352 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000353
354 deleteUnackedFrag(fragIt);
Eric Newberry185ab292017-03-28 06:45:39 +0000355}
356
Eric Newberry7b0071e2017-07-03 17:33:31 +0000357void
358LpReliability::deleteUnackedFrag(UnackedFrags::iterator fragIt)
Eric Newberry185ab292017-03-28 06:45:39 +0000359{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000360 lp::Sequence firstUnackedTxSeq = m_firstUnackedFrag->first;
361 lp::Sequence currentTxSeq = fragIt->first;
362 auto nextFragIt = m_unackedFrags.erase(fragIt);
363
364 if (!m_unackedFrags.empty() && firstUnackedTxSeq == currentTxSeq) {
365 // If "first" fragment in send window (allowing for wraparound), increment window begin
366 if (nextFragIt == m_unackedFrags.end()) {
367 m_firstUnackedFrag = m_unackedFrags.begin();
368 }
369 else {
370 m_firstUnackedFrag = nextFragIt;
371 }
Eric Newberry185ab292017-03-28 06:45:39 +0000372 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000373 else if (m_unackedFrags.empty()) {
374 m_firstUnackedFrag = m_unackedFrags.end();
375 }
Eric Newberry185ab292017-03-28 06:45:39 +0000376}
377
378LpReliability::UnackedFrag::UnackedFrag(lp::Packet pkt)
379 : pkt(std::move(pkt))
380 , sendTime(time::steady_clock::now())
381 , retxCount(0)
382 , nGreaterSeqAcks(0)
Eric Newberry185ab292017-03-28 06:45:39 +0000383{
384}
385
Eric Newberry41aba102017-11-01 16:42:13 -0700386LpReliability::NetPkt::NetPkt(lp::Packet&& pkt, bool isInterest)
387 : pkt(std::move(pkt))
388 , isInterest(isInterest)
389 , didRetx(false)
390{
391}
392
Eric Newberry5ab4cf82020-02-03 15:40:16 -0800393std::ostream&
394operator<<(std::ostream& os, const FaceLogHelper<LpReliability>& flh)
395{
396 if (flh.obj.getLinkService() == nullptr) {
397 os << "[id=0,local=unknown,remote=unknown] ";
398 }
399 else {
400 os << FaceLogHelper<LinkService>(*flh.obj.getLinkService());
401 }
402 return os;
403}
404
Eric Newberry185ab292017-03-28 06:45:39 +0000405} // namespace face
406} // namespace nfd