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