Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 11fc3eb | 2024-01-26 01:46:56 -0500 | [diff] [blame] | 3 | * Copyright (c) 2016-2024, Regents of the University of California, |
Davide Pesavento | cd65c2c | 2017-01-15 16:10:38 -0500 | [diff] [blame] | 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 9 | * |
| 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 22 | * |
| 23 | * @author Shuo Yang |
| 24 | * @author Weiwei Liu |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 25 | * @author Chavoosh Ghasemi |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 26 | * @author Klaus Schneider |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 29 | #include "pipeline-interests-adaptive.hpp" |
Davide Pesavento | 44b3b23 | 2017-12-23 16:58:25 -0500 | [diff] [blame] | 30 | #include "data-fetcher.hpp" |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 31 | |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 32 | #include <boost/lexical_cast.hpp> |
Chavoosh Ghasemi | 3dae109 | 2017-12-21 12:39:08 -0700 | [diff] [blame] | 33 | #include <iomanip> |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 34 | #include <iostream> |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 36 | namespace ndn::chunks { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame] | 38 | PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face, |
| 39 | RttEstimatorWithStats& rttEstimator, |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 40 | const Options& opts) |
| 41 | : PipelineInterests(face, opts) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 42 | , m_cwnd(m_options.initCwnd) |
| 43 | , m_ssthresh(m_options.initSsthresh) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 44 | , m_rttEstimator(rttEstimator) |
Davide Pesavento | 7e9d7e4 | 2023-11-11 15:00:03 -0500 | [diff] [blame] | 45 | , m_scheduler(m_face.getIoContext()) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 46 | { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 47 | } |
| 48 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 49 | PipelineInterestsAdaptive::~PipelineInterestsAdaptive() |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 50 | { |
| 51 | cancel(); |
| 52 | } |
| 53 | |
| 54 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 55 | PipelineInterestsAdaptive::doRun() |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 56 | { |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 57 | if (allSegmentsReceived()) { |
| 58 | cancel(); |
| 59 | if (!m_options.isQuiet) { |
| 60 | printSummary(); |
| 61 | } |
| 62 | return; |
| 63 | } |
| 64 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 65 | // schedule the event to check retransmission timer |
Davide Pesavento | bf2c517 | 2019-03-20 19:08:09 -0400 | [diff] [blame] | 66 | m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); }); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 67 | |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 68 | schedulePackets(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 72 | PipelineInterestsAdaptive::doCancel() |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 73 | { |
Davide Pesavento | cd65c2c | 2017-01-15 16:10:38 -0500 | [diff] [blame] | 74 | m_checkRtoEvent.cancel(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 75 | m_segmentInfo.clear(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 79 | PipelineInterestsAdaptive::checkRto() |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 80 | { |
| 81 | if (isStopping()) |
| 82 | return; |
| 83 | |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 84 | bool hasTimeout = false; |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 85 | uint64_t highTimeoutSeg = 0; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 86 | |
| 87 | for (auto& entry : m_segmentInfo) { |
| 88 | SegmentInfo& segInfo = entry.second; |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 89 | if (segInfo.state != SegmentState::InRetxQueue) { // skip segments already in the retx queue |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 90 | auto timeElapsed = time::steady_clock::now() - segInfo.timeSent; |
| 91 | if (timeElapsed > segInfo.rto) { // timer expired? |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 92 | m_nTimeouts++; |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 93 | hasTimeout = true; |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 94 | highTimeoutSeg = std::max(highTimeoutSeg, entry.first); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 95 | enqueueForRetransmission(entry.first); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 100 | if (hasTimeout) { |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 101 | recordTimeout(highTimeoutSeg); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 102 | schedulePackets(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // schedule the next check after predefined interval |
Davide Pesavento | bf2c517 | 2019-03-20 19:08:09 -0400 | [diff] [blame] | 106 | m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); }); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 110 | PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 111 | { |
| 112 | if (isStopping()) |
| 113 | return; |
| 114 | |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 115 | if (m_hasFinalBlockId && segNo > m_lastSegmentNo) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 116 | return; |
| 117 | |
| 118 | if (!isRetransmission && m_hasFailure) |
| 119 | return; |
| 120 | |
| 121 | if (m_options.isVerbose) { |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 122 | std::cerr << (isRetransmission ? "Retransmitting" : "Requesting") |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 123 | << " segment #" << segNo << "\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (isRetransmission) { |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 127 | // keep track of retx count for this segment |
| 128 | auto ret = m_retxCount.emplace(segNo, 1); |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 129 | if (!ret.second) { // not the first retransmission |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 130 | m_retxCount[segNo] += 1; |
Davide Pesavento | 44b3b23 | 2017-12-23 16:58:25 -0500 | [diff] [blame] | 131 | if (m_options.maxRetriesOnTimeoutOrNack != DataFetcher::MAX_RETRIES_INFINITE && |
| 132 | m_retxCount[segNo] > m_options.maxRetriesOnTimeoutOrNack) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 133 | return handleFail(segNo, "Reached the maximum number of retries (" + |
Davide Pesavento | 11fc3eb | 2024-01-26 01:46:56 -0500 | [diff] [blame] | 134 | std::to_string(m_options.maxRetriesOnTimeoutOrNack) + |
| 135 | ") while retrieving segment #" + std::to_string(segNo)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (m_options.isVerbose) { |
| 139 | std::cerr << "# of retries for segment #" << segNo |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 140 | << " is " << m_retxCount[segNo] << "\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Davide Pesavento | 84d8477 | 2019-04-07 14:40:07 -0400 | [diff] [blame] | 145 | auto interest = Interest() |
| 146 | .setName(Name(m_prefix).appendSegment(segNo)) |
Davide Pesavento | 84d8477 | 2019-04-07 14:40:07 -0400 | [diff] [blame] | 147 | .setMustBeFresh(m_options.mustBeFresh) |
| 148 | .setInterestLifetime(m_options.interestLifetime); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 149 | |
Junxiao Shi | 06d008c | 2019-02-04 08:26:59 +0000 | [diff] [blame] | 150 | SegmentInfo& segInfo = m_segmentInfo[segNo]; |
| 151 | segInfo.interestHdl = m_face.expressInterest(interest, |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 152 | FORWARD_TO_MEM_FN(handleData), |
| 153 | FORWARD_TO_MEM_FN(handleNack), |
| 154 | FORWARD_TO_MEM_FN(handleLifetimeExpiration)); |
Junxiao Shi | 06d008c | 2019-02-04 08:26:59 +0000 | [diff] [blame] | 155 | segInfo.timeSent = time::steady_clock::now(); |
| 156 | segInfo.rto = m_rttEstimator.getEstimatedRto(); |
| 157 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 158 | m_nInFlight++; |
Chavoosh Ghasemi | 75309ae | 2018-03-26 14:46:24 -0400 | [diff] [blame] | 159 | m_nSent++; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 160 | |
| 161 | if (isRetransmission) { |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 162 | segInfo.state = SegmentState::Retransmitted; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 163 | m_nRetransmitted++; |
| 164 | } |
| 165 | else { |
| 166 | m_highInterest = segNo; |
Junxiao Shi | 06d008c | 2019-02-04 08:26:59 +0000 | [diff] [blame] | 167 | segInfo.state = SegmentState::FirstTimeSent; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 172 | PipelineInterestsAdaptive::schedulePackets() |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 173 | { |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 174 | BOOST_ASSERT(m_nInFlight >= 0); |
| 175 | auto availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nInFlight; |
| 176 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 177 | while (availableWindowSize > 0) { |
| 178 | if (!m_retxQueue.empty()) { // do retransmission first |
| 179 | uint64_t retxSegNo = m_retxQueue.front(); |
| 180 | m_retxQueue.pop(); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 181 | if (m_segmentInfo.count(retxSegNo) == 0) { |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 182 | m_nSkippedRetx++; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 183 | continue; |
| 184 | } |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 185 | // the segment is still in the map, that means it needs to be retransmitted |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 186 | sendInterest(retxSegNo, true); |
| 187 | } |
| 188 | else { // send next segment |
| 189 | sendInterest(getNextSegmentNo(), false); |
| 190 | } |
| 191 | availableWindowSize--; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 196 | PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 197 | { |
| 198 | if (isStopping()) |
| 199 | return; |
| 200 | |
Davide Pesavento | 84d8477 | 2019-04-07 14:40:07 -0400 | [diff] [blame] | 201 | // Interest was expressed with CanBePrefix=false |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 202 | BOOST_ASSERT(data.getName().equals(interest.getName())); |
| 203 | |
Davide Pesavento | 969cd5a | 2018-04-20 16:27:47 -0400 | [diff] [blame] | 204 | if (!m_hasFinalBlockId && data.getFinalBlock()) { |
| 205 | m_lastSegmentNo = data.getFinalBlock()->toSegment(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 206 | m_hasFinalBlockId = true; |
| 207 | cancelInFlightSegmentsGreaterThan(m_lastSegmentNo); |
| 208 | if (m_hasFailure && m_lastSegmentNo >= m_failedSegNo) { |
| 209 | // previously failed segment is part of the content |
| 210 | return onFailure(m_failureReason); |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 211 | } |
| 212 | else { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 213 | m_hasFailure = false; |
| 214 | } |
| 215 | } |
| 216 | |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 217 | uint64_t recvSegNo = getSegmentFromPacket(data); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 218 | auto segIt = m_segmentInfo.find(recvSegNo); |
| 219 | if (segIt == m_segmentInfo.end()) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 220 | return; // ignore already-received segment |
| 221 | } |
| 222 | |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 223 | SegmentInfo& segInfo = segIt->second; |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 224 | time::nanoseconds rtt = time::steady_clock::now() - segInfo.timeSent; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 225 | if (m_options.isVerbose) { |
| 226 | std::cerr << "Received segment #" << recvSegNo |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 227 | << ", rtt=" << rtt.count() / 1e6 << "ms" |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 228 | << ", rto=" << segInfo.rto.count() / 1e6 << "ms\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 231 | m_highData = std::max(m_highData, recvSegNo); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 232 | |
| 233 | // for segments in retx queue, we must not decrement m_nInFlight |
| 234 | // because it was already decremented when the segment timed out |
| 235 | if (segInfo.state != SegmentState::InRetxQueue) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 236 | m_nInFlight--; |
| 237 | } |
| 238 | |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 239 | // upon finding congestion mark, decrease the window size |
| 240 | // without retransmitting any packet |
| 241 | if (data.getCongestionMark() > 0) { |
| 242 | m_nCongMarks++; |
| 243 | if (!m_options.ignoreCongMarks) { |
| 244 | if (m_options.disableCwa || m_highData > m_recPoint) { |
| 245 | m_recPoint = m_highInterest; // react to only one congestion event (timeout or congestion mark) |
| 246 | // per RTT (conservative window adaptation) |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 247 | m_nMarkDecr++; |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 248 | decreaseWindow(); |
| 249 | |
| 250 | if (m_options.isVerbose) { |
| 251 | std::cerr << "Received congestion mark, value = " << data.getCongestionMark() |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 252 | << ", new cwnd = " << m_cwnd << "\n"; |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | } |
| 256 | else { |
| 257 | increaseWindow(); |
| 258 | } |
| 259 | } |
| 260 | else { |
| 261 | increaseWindow(); |
| 262 | } |
| 263 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 264 | onData(data); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 265 | |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 266 | // do not sample RTT for retransmitted segments |
| 267 | if ((segInfo.state == SegmentState::FirstTimeSent || |
| 268 | segInfo.state == SegmentState::InRetxQueue) && |
| 269 | m_retxCount.count(recvSegNo) == 0) { |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 270 | auto nExpectedSamples = std::max<int64_t>((m_nInFlight + 1) >> 1, 1); |
| 271 | BOOST_ASSERT(nExpectedSamples > 0); |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame] | 272 | m_rttEstimator.addMeasurement(rtt, static_cast<size_t>(nExpectedSamples)); |
| 273 | afterRttMeasurement({recvSegNo, rtt, |
| 274 | m_rttEstimator.getSmoothedRtt(), |
| 275 | m_rttEstimator.getRttVariation(), |
| 276 | m_rttEstimator.getEstimatedRto()}); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 279 | // remove the entry associated with the received segment |
| 280 | m_segmentInfo.erase(segIt); |
| 281 | |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 282 | if (allSegmentsReceived()) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 283 | cancel(); |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 284 | if (!m_options.isQuiet) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 285 | printSummary(); |
| 286 | } |
| 287 | } |
| 288 | else { |
| 289 | schedulePackets(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 294 | PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack& nack) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 295 | { |
| 296 | if (isStopping()) |
| 297 | return; |
| 298 | |
| 299 | if (m_options.isVerbose) |
| 300 | std::cerr << "Received Nack with reason " << nack.getReason() |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 301 | << " for Interest " << interest << "\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 302 | |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 303 | uint64_t segNo = getSegmentFromPacket(interest); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 304 | |
| 305 | switch (nack.getReason()) { |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 306 | case lp::NackReason::DUPLICATE: |
| 307 | // ignore duplicates |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 308 | break; |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 309 | case lp::NackReason::CONGESTION: |
| 310 | // treated the same as timeout for now |
| 311 | enqueueForRetransmission(segNo); |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 312 | recordTimeout(segNo); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 313 | schedulePackets(); |
| 314 | break; |
| 315 | default: |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 316 | handleFail(segNo, "Could not retrieve data for " + interest.getName().toUri() + |
| 317 | ", reason: " + boost::lexical_cast<std::string>(nack.getReason())); |
| 318 | break; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 323 | PipelineInterestsAdaptive::handleLifetimeExpiration(const Interest& interest) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 324 | { |
| 325 | if (isStopping()) |
| 326 | return; |
| 327 | |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 328 | m_nTimeouts++; |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 329 | |
| 330 | uint64_t segNo = getSegmentFromPacket(interest); |
| 331 | enqueueForRetransmission(segNo); |
| 332 | recordTimeout(segNo); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 333 | schedulePackets(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | void |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 337 | PipelineInterestsAdaptive::recordTimeout(uint64_t segNo) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 338 | { |
Sichen Song | 40eae03 | 2022-05-01 16:33:00 -0700 | [diff] [blame] | 339 | if (m_options.disableCwa || segNo > m_recPoint) { |
| 340 | // interests that are still outstanding during a timeout event |
| 341 | // should not trigger another window decrease later (bug #5202) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 342 | m_recPoint = m_highInterest; |
| 343 | |
| 344 | decreaseWindow(); |
| 345 | m_rttEstimator.backoffRto(); |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 346 | m_nLossDecr++; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 347 | |
| 348 | if (m_options.isVerbose) { |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 349 | std::cerr << "Packet loss event, new cwnd = " << m_cwnd |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 350 | << ", ssthresh = " << m_ssthresh << "\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 353 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 354 | |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 355 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 356 | PipelineInterestsAdaptive::enqueueForRetransmission(uint64_t segNo) |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 357 | { |
| 358 | BOOST_ASSERT(m_nInFlight > 0); |
| 359 | m_nInFlight--; |
| 360 | m_retxQueue.push(segNo); |
| 361 | m_segmentInfo.at(segNo).state = SegmentState::InRetxQueue; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 365 | PipelineInterestsAdaptive::handleFail(uint64_t segNo, const std::string& reason) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 366 | { |
| 367 | if (isStopping()) |
| 368 | return; |
| 369 | |
| 370 | // if the failed segment is definitely part of the content, raise a fatal error |
| 371 | if (m_hasFinalBlockId && segNo <= m_lastSegmentNo) |
| 372 | return onFailure(reason); |
| 373 | |
| 374 | if (!m_hasFinalBlockId) { |
| 375 | m_segmentInfo.erase(segNo); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 376 | m_nInFlight--; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 377 | |
| 378 | if (m_segmentInfo.empty()) { |
| 379 | onFailure("Fetching terminated but no final segment number has been found"); |
| 380 | } |
| 381 | else { |
| 382 | cancelInFlightSegmentsGreaterThan(segNo); |
| 383 | m_hasFailure = true; |
| 384 | m_failedSegNo = segNo; |
| 385 | m_failureReason = reason; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 391 | PipelineInterestsAdaptive::cancelInFlightSegmentsGreaterThan(uint64_t segNo) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 392 | { |
| 393 | for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) { |
| 394 | // cancel fetching all segments that follow |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 395 | if (it->first > segNo) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 396 | it = m_segmentInfo.erase(it); |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 397 | m_nInFlight--; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 398 | } |
| 399 | else { |
| 400 | ++it; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | void |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 406 | PipelineInterestsAdaptive::printOptions() const |
| 407 | { |
| 408 | PipelineInterests::printOptions(); |
| 409 | std::cerr |
| 410 | << "\tInitial congestion window size = " << m_options.initCwnd << "\n" |
| 411 | << "\tInitial slow start threshold = " << m_options.initSsthresh << "\n" |
| 412 | << "\tAdditive increase step = " << m_options.aiStep << "\n" |
| 413 | << "\tMultiplicative decrease factor = " << m_options.mdCoef << "\n" |
| 414 | << "\tRTO check interval = " << m_options.rtoCheckInterval << "\n" |
| 415 | << "\tReact to congestion marks = " << (m_options.ignoreCongMarks ? "no" : "yes") << "\n" |
| 416 | << "\tConservative window adaptation = " << (m_options.disableCwa ? "no" : "yes") << "\n" |
| 417 | << "\tResetting window to " << (m_options.resetCwndToInit ? |
| 418 | "initial value" : "ssthresh") << " upon loss event\n"; |
| 419 | } |
| 420 | |
| 421 | void |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 422 | PipelineInterestsAdaptive::printSummary() const |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 423 | { |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 424 | PipelineInterests::printSummary(); |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 425 | std::cerr << "Congestion marks: " << m_nCongMarks << " (caused " << m_nMarkDecr << " window decreases)\n" |
| 426 | << "Timeouts: " << m_nTimeouts << " (caused " << m_nLossDecr << " window decreases)\n" |
| 427 | << "Retransmitted segments: " << m_nRetransmitted |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 428 | << " (" << (m_nSent == 0 ? 0 : (m_nRetransmitted * 100.0 / m_nSent)) << "%)" |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 429 | << ", skipped: " << m_nSkippedRetx << "\n" |
Chavoosh Ghasemi | 75309ae | 2018-03-26 14:46:24 -0400 | [diff] [blame] | 430 | << "RTT "; |
| 431 | |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 432 | if (m_rttEstimator.getMinRtt() == time::nanoseconds::max() || |
| 433 | m_rttEstimator.getMaxRtt() == time::nanoseconds::min()) { |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 434 | std::cerr << "stats unavailable\n"; |
| 435 | } |
| 436 | else { |
| 437 | std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3) |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 438 | << m_rttEstimator.getMinRtt().count() / 1e6 << "/" |
| 439 | << m_rttEstimator.getAvgRtt().count() / 1e6 << "/" |
| 440 | << m_rttEstimator.getMaxRtt().count() / 1e6 << " ms\n"; |
Chavoosh Ghasemi | 75309ae | 2018-03-26 14:46:24 -0400 | [diff] [blame] | 441 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | std::ostream& |
| 445 | operator<<(std::ostream& os, SegmentState state) |
| 446 | { |
| 447 | switch (state) { |
| 448 | case SegmentState::FirstTimeSent: |
| 449 | os << "FirstTimeSent"; |
| 450 | break; |
| 451 | case SegmentState::InRetxQueue: |
| 452 | os << "InRetxQueue"; |
| 453 | break; |
| 454 | case SegmentState::Retransmitted: |
| 455 | os << "Retransmitted"; |
| 456 | break; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 457 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 458 | return os; |
| 459 | } |
| 460 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 461 | } // namespace ndn::chunks |