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