blob: 7e394ef8b2a4ad52a02110396c66871ba1a4d0d9 [file] [log] [blame]
Davide Pesaventobf1c0692017-01-15 19:15:09 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +00002/*
Junxiao Shi7664b122019-01-23 16:45:17 +00003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesaventocd65c2c2017-01-15 16:10:38 -05004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Weiwei Liu245d7912016-07-28 00:04:25 -07006 *
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 Ghasemi4d36ed52017-10-31 22:26:25 +000025 * @author Chavoosh Ghasemi
schneiderklausd8197df2019-03-16 11:31:40 -070026 * @author Klaus Schneider
Weiwei Liu245d7912016-07-28 00:04:25 -070027 */
28
schneiderklausd8197df2019-03-16 11:31:40 -070029#include "pipeline-interests-adaptive.hpp"
Davide Pesavento44b3b232017-12-23 16:58:25 -050030#include "data-fetcher.hpp"
Weiwei Liu245d7912016-07-28 00:04:25 -070031
32#include <cmath>
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070033#include <iomanip>
Weiwei Liu245d7912016-07-28 00:04:25 -070034
schneiderklausd8197df2019-03-16 11:31:40 -070035
Weiwei Liu245d7912016-07-28 00:04:25 -070036namespace ndn {
37namespace chunks {
Weiwei Liu245d7912016-07-28 00:04:25 -070038
schneiderklausd8197df2019-03-16 11:31:40 -070039constexpr double PipelineInterestsAdaptive::MIN_SSTHRESH;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000040
schneiderklausd8197df2019-03-16 11:31:40 -070041PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face, RttEstimator& rttEstimator,
42 const Options& options)
Weiwei Liu245d7912016-07-28 00:04:25 -070043 : PipelineInterests(face)
44 , m_options(options)
45 , m_rttEstimator(rttEstimator)
46 , m_scheduler(m_face.getIoService())
Weiwei Liu245d7912016-07-28 00:04:25 -070047 , m_highData(0)
48 , m_highInterest(0)
49 , m_recPoint(0)
50 , m_nInFlight(0)
schneiderklaus8ff3abd2019-03-12 22:15:12 -070051 , m_nLossDecr(0)
52 , m_nMarkDecr(0)
53 , m_nTimeouts(0)
54 , m_nSkippedRetx(0)
Weiwei Liu245d7912016-07-28 00:04:25 -070055 , m_nRetransmitted(0)
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000056 , m_nCongMarks(0)
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -040057 , m_nSent(0)
Weiwei Liu245d7912016-07-28 00:04:25 -070058 , m_cwnd(m_options.initCwnd)
59 , m_ssthresh(m_options.initSsthresh)
60 , m_hasFailure(false)
61 , m_failedSegNo(0)
62{
63 if (m_options.isVerbose) {
64 std::cerr << m_options;
65 }
66}
67
schneiderklausd8197df2019-03-16 11:31:40 -070068PipelineInterestsAdaptive::~PipelineInterestsAdaptive()
Weiwei Liu245d7912016-07-28 00:04:25 -070069{
70 cancel();
71}
72
73void
schneiderklausd8197df2019-03-16 11:31:40 -070074PipelineInterestsAdaptive::doRun()
Weiwei Liu245d7912016-07-28 00:04:25 -070075{
Ryan Wickman034f30f2018-06-06 11:11:11 -050076 if (allSegmentsReceived()) {
77 cancel();
78 if (!m_options.isQuiet) {
79 printSummary();
80 }
81 return;
82 }
83
Weiwei Liu245d7912016-07-28 00:04:25 -070084 // schedule the event to check retransmission timer
Davide Pesaventocd65c2c2017-01-15 16:10:38 -050085 m_checkRtoEvent = m_scheduler.scheduleEvent(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -070086
Davide Pesavento958896e2017-01-19 00:52:04 -050087 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -070088}
89
90void
schneiderklausd8197df2019-03-16 11:31:40 -070091PipelineInterestsAdaptive::doCancel()
Weiwei Liu245d7912016-07-28 00:04:25 -070092{
Davide Pesaventocd65c2c2017-01-15 16:10:38 -050093 m_checkRtoEvent.cancel();
Weiwei Liu245d7912016-07-28 00:04:25 -070094 m_segmentInfo.clear();
Weiwei Liu245d7912016-07-28 00:04:25 -070095}
96
97void
schneiderklausd8197df2019-03-16 11:31:40 -070098PipelineInterestsAdaptive::checkRto()
Weiwei Liu245d7912016-07-28 00:04:25 -070099{
100 if (isStopping())
101 return;
102
Davide Pesavento958896e2017-01-19 00:52:04 -0500103 bool hasTimeout = false;
Weiwei Liu245d7912016-07-28 00:04:25 -0700104
105 for (auto& entry : m_segmentInfo) {
106 SegmentInfo& segInfo = entry.second;
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500107 if (segInfo.state != SegmentState::InRetxQueue) { // skip segments already in the retx queue
Weiwei Liu245d7912016-07-28 00:04:25 -0700108 Milliseconds timeElapsed = time::steady_clock::now() - segInfo.timeSent;
109 if (timeElapsed.count() > segInfo.rto.count()) { // timer expired?
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700110 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -0500111 hasTimeout = true;
112 enqueueForRetransmission(entry.first);
Weiwei Liu245d7912016-07-28 00:04:25 -0700113 }
114 }
115 }
116
Davide Pesavento958896e2017-01-19 00:52:04 -0500117 if (hasTimeout) {
118 recordTimeout();
119 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700120 }
121
122 // schedule the next check after predefined interval
Davide Pesaventocd65c2c2017-01-15 16:10:38 -0500123 m_checkRtoEvent = m_scheduler.scheduleEvent(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -0700124}
125
126void
schneiderklausd8197df2019-03-16 11:31:40 -0700127PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
Weiwei Liu245d7912016-07-28 00:04:25 -0700128{
129 if (isStopping())
130 return;
131
Ryan Wickman034f30f2018-06-06 11:11:11 -0500132 if (m_hasFinalBlockId && segNo > m_lastSegmentNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700133 return;
134
135 if (!isRetransmission && m_hasFailure)
136 return;
137
138 if (m_options.isVerbose) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500139 std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
140 << " segment #" << segNo << std::endl;
Weiwei Liu245d7912016-07-28 00:04:25 -0700141 }
142
143 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500144 // keep track of retx count for this segment
145 auto ret = m_retxCount.emplace(segNo, 1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700146 if (ret.second == false) { // not the first retransmission
147 m_retxCount[segNo] += 1;
Davide Pesavento44b3b232017-12-23 16:58:25 -0500148 if (m_options.maxRetriesOnTimeoutOrNack != DataFetcher::MAX_RETRIES_INFINITE &&
149 m_retxCount[segNo] > m_options.maxRetriesOnTimeoutOrNack) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700150 return handleFail(segNo, "Reached the maximum number of retries (" +
151 to_string(m_options.maxRetriesOnTimeoutOrNack) +
152 ") while retrieving segment #" + to_string(segNo));
153 }
154
155 if (m_options.isVerbose) {
156 std::cerr << "# of retries for segment #" << segNo
157 << " is " << m_retxCount[segNo] << std::endl;
158 }
159 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700160 }
161
162 Interest interest(Name(m_prefix).appendSegment(segNo));
163 interest.setInterestLifetime(m_options.interestLifetime);
164 interest.setMustBeFresh(m_options.mustBeFresh);
165 interest.setMaxSuffixComponents(1);
166
Junxiao Shi06d008c2019-02-04 08:26:59 +0000167 SegmentInfo& segInfo = m_segmentInfo[segNo];
168 segInfo.interestHdl = m_face.expressInterest(interest,
schneiderklausd8197df2019-03-16 11:31:40 -0700169 bind(&PipelineInterestsAdaptive::handleData, this, _1, _2),
170 bind(&PipelineInterestsAdaptive::handleNack, this, _1, _2),
171 bind(&PipelineInterestsAdaptive::handleLifetimeExpiration, this, _1));
Junxiao Shi06d008c2019-02-04 08:26:59 +0000172 segInfo.timeSent = time::steady_clock::now();
173 segInfo.rto = m_rttEstimator.getEstimatedRto();
174
Weiwei Liu245d7912016-07-28 00:04:25 -0700175 m_nInFlight++;
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400176 m_nSent++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700177
178 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500179 segInfo.state = SegmentState::Retransmitted;
Weiwei Liu245d7912016-07-28 00:04:25 -0700180 m_nRetransmitted++;
181 }
182 else {
183 m_highInterest = segNo;
Junxiao Shi06d008c2019-02-04 08:26:59 +0000184 segInfo.state = SegmentState::FirstTimeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700185 }
186}
187
188void
schneiderklausd8197df2019-03-16 11:31:40 -0700189PipelineInterestsAdaptive::schedulePackets()
Weiwei Liu245d7912016-07-28 00:04:25 -0700190{
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500191 BOOST_ASSERT(m_nInFlight >= 0);
192 auto availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nInFlight;
193
Weiwei Liu245d7912016-07-28 00:04:25 -0700194 while (availableWindowSize > 0) {
195 if (!m_retxQueue.empty()) { // do retransmission first
196 uint64_t retxSegNo = m_retxQueue.front();
197 m_retxQueue.pop();
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500198 if (m_segmentInfo.count(retxSegNo) == 0) {
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700199 m_nSkippedRetx++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700200 continue;
201 }
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500202 // the segment is still in the map, that means it needs to be retransmitted
Weiwei Liu245d7912016-07-28 00:04:25 -0700203 sendInterest(retxSegNo, true);
204 }
205 else { // send next segment
206 sendInterest(getNextSegmentNo(), false);
207 }
208 availableWindowSize--;
209 }
210}
211
212void
schneiderklausd8197df2019-03-16 11:31:40 -0700213PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data)
Weiwei Liu245d7912016-07-28 00:04:25 -0700214{
215 if (isStopping())
216 return;
217
218 // Data name will not have extra components because MaxSuffixComponents is set to 1
219 BOOST_ASSERT(data.getName().equals(interest.getName()));
220
Davide Pesavento969cd5a2018-04-20 16:27:47 -0400221 if (!m_hasFinalBlockId && data.getFinalBlock()) {
222 m_lastSegmentNo = data.getFinalBlock()->toSegment();
Weiwei Liu245d7912016-07-28 00:04:25 -0700223 m_hasFinalBlockId = true;
224 cancelInFlightSegmentsGreaterThan(m_lastSegmentNo);
225 if (m_hasFailure && m_lastSegmentNo >= m_failedSegNo) {
226 // previously failed segment is part of the content
227 return onFailure(m_failureReason);
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000228 }
229 else {
Weiwei Liu245d7912016-07-28 00:04:25 -0700230 m_hasFailure = false;
231 }
232 }
233
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500234 uint64_t recvSegNo = getSegmentFromPacket(data);
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500235 auto segIt = m_segmentInfo.find(recvSegNo);
236 if (segIt == m_segmentInfo.end()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700237 return; // ignore already-received segment
238 }
239
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500240 SegmentInfo& segInfo = segIt->second;
Weiwei Liu245d7912016-07-28 00:04:25 -0700241 Milliseconds rtt = time::steady_clock::now() - segInfo.timeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700242 if (m_options.isVerbose) {
243 std::cerr << "Received segment #" << recvSegNo
244 << ", rtt=" << rtt.count() << "ms"
245 << ", rto=" << segInfo.rto.count() << "ms" << std::endl;
246 }
247
Davide Pesavento958896e2017-01-19 00:52:04 -0500248 if (m_highData < recvSegNo) {
249 m_highData = recvSegNo;
250 }
251
252 // for segments in retx queue, we must not decrement m_nInFlight
253 // because it was already decremented when the segment timed out
254 if (segInfo.state != SegmentState::InRetxQueue) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700255 m_nInFlight--;
256 }
257
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000258 // upon finding congestion mark, decrease the window size
259 // without retransmitting any packet
260 if (data.getCongestionMark() > 0) {
261 m_nCongMarks++;
262 if (!m_options.ignoreCongMarks) {
263 if (m_options.disableCwa || m_highData > m_recPoint) {
264 m_recPoint = m_highInterest; // react to only one congestion event (timeout or congestion mark)
265 // per RTT (conservative window adaptation)
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700266 m_nMarkDecr++;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000267 decreaseWindow();
268
269 if (m_options.isVerbose) {
270 std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
271 << ", new cwnd = " << m_cwnd << std::endl;
272 }
273 }
274 }
275 else {
276 increaseWindow();
277 }
278 }
279 else {
280 increaseWindow();
281 }
282
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400283 onData(data);
Weiwei Liu245d7912016-07-28 00:04:25 -0700284
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500285 // do not sample RTT for retransmitted segments
286 if ((segInfo.state == SegmentState::FirstTimeSent ||
287 segInfo.state == SegmentState::InRetxQueue) &&
288 m_retxCount.count(recvSegNo) == 0) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500289 auto nExpectedSamples = std::max<int64_t>((m_nInFlight + 1) >> 1, 1);
290 BOOST_ASSERT(nExpectedSamples > 0);
291 m_rttEstimator.addMeasurement(recvSegNo, rtt, static_cast<size_t>(nExpectedSamples));
Weiwei Liu245d7912016-07-28 00:04:25 -0700292 }
293
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500294 // remove the entry associated with the received segment
295 m_segmentInfo.erase(segIt);
296
Ryan Wickman034f30f2018-06-06 11:11:11 -0500297 if (allSegmentsReceived()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700298 cancel();
Davide Pesaventof6991e12018-01-08 20:58:50 -0500299 if (!m_options.isQuiet) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700300 printSummary();
301 }
302 }
303 else {
304 schedulePackets();
305 }
306}
307
308void
schneiderklausd8197df2019-03-16 11:31:40 -0700309PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack& nack)
Weiwei Liu245d7912016-07-28 00:04:25 -0700310{
311 if (isStopping())
312 return;
313
314 if (m_options.isVerbose)
315 std::cerr << "Received Nack with reason " << nack.getReason()
316 << " for Interest " << interest << std::endl;
317
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500318 uint64_t segNo = getSegmentFromPacket(interest);
Weiwei Liu245d7912016-07-28 00:04:25 -0700319
320 switch (nack.getReason()) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500321 case lp::NackReason::DUPLICATE:
322 // ignore duplicates
Weiwei Liu245d7912016-07-28 00:04:25 -0700323 break;
Davide Pesavento958896e2017-01-19 00:52:04 -0500324 case lp::NackReason::CONGESTION:
325 // treated the same as timeout for now
326 enqueueForRetransmission(segNo);
327 recordTimeout();
328 schedulePackets();
329 break;
330 default:
Weiwei Liu245d7912016-07-28 00:04:25 -0700331 handleFail(segNo, "Could not retrieve data for " + interest.getName().toUri() +
332 ", reason: " + boost::lexical_cast<std::string>(nack.getReason()));
333 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700334 }
335}
336
337void
schneiderklausd8197df2019-03-16 11:31:40 -0700338PipelineInterestsAdaptive::handleLifetimeExpiration(const Interest& interest)
Weiwei Liu245d7912016-07-28 00:04:25 -0700339{
340 if (isStopping())
341 return;
342
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700343 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -0500344 enqueueForRetransmission(getSegmentFromPacket(interest));
345 recordTimeout();
346 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700347}
348
349void
schneiderklausd8197df2019-03-16 11:31:40 -0700350PipelineInterestsAdaptive::recordTimeout()
Weiwei Liu245d7912016-07-28 00:04:25 -0700351{
Weiwei Liu245d7912016-07-28 00:04:25 -0700352 if (m_options.disableCwa || m_highData > m_recPoint) {
353 // react to only one timeout per RTT (conservative window adaptation)
354 m_recPoint = m_highInterest;
355
356 decreaseWindow();
357 m_rttEstimator.backoffRto();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700358 m_nLossDecr++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700359
360 if (m_options.isVerbose) {
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000361 std::cerr << "Packet loss event, new cwnd = " << m_cwnd
Weiwei Liu245d7912016-07-28 00:04:25 -0700362 << ", ssthresh = " << m_ssthresh << std::endl;
363 }
364 }
Davide Pesavento958896e2017-01-19 00:52:04 -0500365}
Weiwei Liu245d7912016-07-28 00:04:25 -0700366
Davide Pesavento958896e2017-01-19 00:52:04 -0500367void
schneiderklausd8197df2019-03-16 11:31:40 -0700368PipelineInterestsAdaptive::enqueueForRetransmission(uint64_t segNo)
Davide Pesavento958896e2017-01-19 00:52:04 -0500369{
370 BOOST_ASSERT(m_nInFlight > 0);
371 m_nInFlight--;
372 m_retxQueue.push(segNo);
373 m_segmentInfo.at(segNo).state = SegmentState::InRetxQueue;
Weiwei Liu245d7912016-07-28 00:04:25 -0700374}
375
376void
schneiderklausd8197df2019-03-16 11:31:40 -0700377PipelineInterestsAdaptive::handleFail(uint64_t segNo, const std::string& reason)
Weiwei Liu245d7912016-07-28 00:04:25 -0700378{
379 if (isStopping())
380 return;
381
382 // if the failed segment is definitely part of the content, raise a fatal error
383 if (m_hasFinalBlockId && segNo <= m_lastSegmentNo)
384 return onFailure(reason);
385
386 if (!m_hasFinalBlockId) {
387 m_segmentInfo.erase(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500388 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700389
390 if (m_segmentInfo.empty()) {
391 onFailure("Fetching terminated but no final segment number has been found");
392 }
393 else {
394 cancelInFlightSegmentsGreaterThan(segNo);
395 m_hasFailure = true;
396 m_failedSegNo = segNo;
397 m_failureReason = reason;
398 }
399 }
400}
401
402void
schneiderklausd8197df2019-03-16 11:31:40 -0700403PipelineInterestsAdaptive::increaseWindow()
Weiwei Liu245d7912016-07-28 00:04:25 -0700404{
405 if (m_cwnd < m_ssthresh) {
406 m_cwnd += m_options.aiStep; // additive increase
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000407 }
408 else {
Weiwei Liu245d7912016-07-28 00:04:25 -0700409 m_cwnd += m_options.aiStep / std::floor(m_cwnd); // congestion avoidance
410 }
Davide Pesavento958896e2017-01-19 00:52:04 -0500411
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500412 afterCwndChange(time::steady_clock::now() - getStartTime(), m_cwnd);
Weiwei Liu245d7912016-07-28 00:04:25 -0700413}
414
415void
schneiderklausd8197df2019-03-16 11:31:40 -0700416PipelineInterestsAdaptive::decreaseWindow()
Weiwei Liu245d7912016-07-28 00:04:25 -0700417{
418 // please refer to RFC 5681, Section 3.1 for the rationale behind it
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000419 m_ssthresh = std::max(MIN_SSTHRESH, m_cwnd * m_options.mdCoef); // multiplicative decrease
Weiwei Liu245d7912016-07-28 00:04:25 -0700420 m_cwnd = m_options.resetCwndToInit ? m_options.initCwnd : m_ssthresh;
Davide Pesavento958896e2017-01-19 00:52:04 -0500421
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500422 afterCwndChange(time::steady_clock::now() - getStartTime(), m_cwnd);
Weiwei Liu245d7912016-07-28 00:04:25 -0700423}
424
Weiwei Liu245d7912016-07-28 00:04:25 -0700425void
schneiderklausd8197df2019-03-16 11:31:40 -0700426PipelineInterestsAdaptive::cancelInFlightSegmentsGreaterThan(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700427{
428 for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) {
429 // cancel fetching all segments that follow
Davide Pesavento958896e2017-01-19 00:52:04 -0500430 if (it->first > segNo) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700431 it = m_segmentInfo.erase(it);
Davide Pesavento958896e2017-01-19 00:52:04 -0500432 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700433 }
434 else {
435 ++it;
436 }
437 }
438}
439
440void
schneiderklausd8197df2019-03-16 11:31:40 -0700441PipelineInterestsAdaptive::printSummary() const
Weiwei Liu245d7912016-07-28 00:04:25 -0700442{
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000443 PipelineInterests::printSummary();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700444 std::cerr << "Congestion marks: " << m_nCongMarks << " (caused " << m_nMarkDecr << " window decreases)\n"
445 << "Timeouts: " << m_nTimeouts << " (caused " << m_nLossDecr << " window decreases)\n"
446 << "Retransmitted segments: " << m_nRetransmitted
447 << " (" << (m_nSent == 0 ? 0 : (static_cast<double>(m_nRetransmitted) / m_nSent * 100.0)) << "%)"
448 << ", skipped: " << m_nSkippedRetx << "\n"
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400449 << "RTT ";
450
451 if (m_rttEstimator.getMinRtt() == std::numeric_limits<double>::max() ||
452 m_rttEstimator.getMaxRtt() == std::numeric_limits<double>::min()) {
453 std::cerr << "stats unavailable\n";
454 }
455 else {
456 std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3)
457 << m_rttEstimator.getMinRtt() << "/"
458 << m_rttEstimator.getAvgRtt() << "/"
459 << m_rttEstimator.getMaxRtt() << " ms\n";
460 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700461}
462
463std::ostream&
464operator<<(std::ostream& os, SegmentState state)
465{
466 switch (state) {
467 case SegmentState::FirstTimeSent:
468 os << "FirstTimeSent";
469 break;
470 case SegmentState::InRetxQueue:
471 os << "InRetxQueue";
472 break;
473 case SegmentState::Retransmitted:
474 os << "Retransmitted";
475 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700476 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700477 return os;
478}
479
480std::ostream&
schneiderklausd8197df2019-03-16 11:31:40 -0700481operator<<(std::ostream& os, const PipelineInterestsAdaptiveOptions& options)
Weiwei Liu245d7912016-07-28 00:04:25 -0700482{
schneiderklausd8197df2019-03-16 11:31:40 -0700483 os << "Adaptive pipeline parameters:\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700484 << "\tInitial congestion window size = " << options.initCwnd << "\n"
485 << "\tInitial slow start threshold = " << options.initSsthresh << "\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700486 << "\tAdditive increase step = " << options.aiStep << "\n"
Davide Pesavento958896e2017-01-19 00:52:04 -0500487 << "\tMultiplicative decrease factor = " << options.mdCoef << "\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700488 << "\tRTO check interval = " << options.rtoCheckInterval << "\n"
Davide Pesavento44b3b232017-12-23 16:58:25 -0500489 << "\tMax retries on timeout or Nack = " << (options.maxRetriesOnTimeoutOrNack == DataFetcher::MAX_RETRIES_INFINITE ?
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500490 "infinite" : to_string(options.maxRetriesOnTimeoutOrNack)) << "\n"
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000491 << "\tReaction to congestion marks " << (options.ignoreCongMarks ? "disabled" : "enabled") << "\n"
Davide Pesavento44b3b232017-12-23 16:58:25 -0500492 << "\tConservative window adaptation " << (options.disableCwa ? "disabled" : "enabled") << "\n"
Davide Pesavento958896e2017-01-19 00:52:04 -0500493 << "\tResetting cwnd to " << (options.resetCwndToInit ? "initCwnd" : "ssthresh") << " upon loss event\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700494 return os;
495}
496
Weiwei Liu245d7912016-07-28 00:04:25 -0700497} // namespace chunks
498} // namespace ndn