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