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