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