blob: 8ae21626a1debee5a71821050bf01535dfca1d7d [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
35namespace ndn {
36namespace chunks {
Weiwei Liu245d7912016-07-28 00:04:25 -070037
schneiderklausd8197df2019-03-16 11:31:40 -070038constexpr double PipelineInterestsAdaptive::MIN_SSTHRESH;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000039
Davide Pesavento5e3773d2019-08-22 15:35:08 -040040PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face,
41 RttEstimatorWithStats& rttEstimator,
schneiderklausd8197df2019-03-16 11:31:40 -070042 const Options& options)
Weiwei Liu245d7912016-07-28 00:04:25 -070043 : PipelineInterests(face)
44 , m_options(options)
Klaus Schneider9e5122b2019-03-19 17:03:25 -070045 , m_cwnd(m_options.initCwnd)
46 , m_ssthresh(m_options.initSsthresh)
Weiwei Liu245d7912016-07-28 00:04:25 -070047 , m_rttEstimator(rttEstimator)
48 , m_scheduler(m_face.getIoService())
Weiwei Liu245d7912016-07-28 00:04:25 -070049 , m_highData(0)
50 , m_highInterest(0)
51 , m_recPoint(0)
52 , m_nInFlight(0)
schneiderklaus8ff3abd2019-03-12 22:15:12 -070053 , m_nLossDecr(0)
54 , m_nMarkDecr(0)
55 , m_nTimeouts(0)
56 , m_nSkippedRetx(0)
Weiwei Liu245d7912016-07-28 00:04:25 -070057 , m_nRetransmitted(0)
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000058 , m_nCongMarks(0)
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -040059 , m_nSent(0)
Weiwei Liu245d7912016-07-28 00:04:25 -070060 , m_hasFailure(false)
61 , m_failedSegNo(0)
62{
Weiwei Liu245d7912016-07-28 00:04:25 -070063}
64
schneiderklausd8197df2019-03-16 11:31:40 -070065PipelineInterestsAdaptive::~PipelineInterestsAdaptive()
Weiwei Liu245d7912016-07-28 00:04:25 -070066{
67 cancel();
68}
69
70void
schneiderklausd8197df2019-03-16 11:31:40 -070071PipelineInterestsAdaptive::doRun()
Weiwei Liu245d7912016-07-28 00:04:25 -070072{
Ryan Wickman034f30f2018-06-06 11:11:11 -050073 if (allSegmentsReceived()) {
74 cancel();
75 if (!m_options.isQuiet) {
76 printSummary();
77 }
78 return;
79 }
80
Weiwei Liu245d7912016-07-28 00:04:25 -070081 // schedule the event to check retransmission timer
Davide Pesaventobf2c5172019-03-20 19:08:09 -040082 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -070083
Davide Pesavento958896e2017-01-19 00:52:04 -050084 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -070085}
86
87void
schneiderklausd8197df2019-03-16 11:31:40 -070088PipelineInterestsAdaptive::doCancel()
Weiwei Liu245d7912016-07-28 00:04:25 -070089{
Davide Pesaventocd65c2c2017-01-15 16:10:38 -050090 m_checkRtoEvent.cancel();
Weiwei Liu245d7912016-07-28 00:04:25 -070091 m_segmentInfo.clear();
Weiwei Liu245d7912016-07-28 00:04:25 -070092}
93
94void
schneiderklausd8197df2019-03-16 11:31:40 -070095PipelineInterestsAdaptive::checkRto()
Weiwei Liu245d7912016-07-28 00:04:25 -070096{
97 if (isStopping())
98 return;
99
Davide Pesavento958896e2017-01-19 00:52:04 -0500100 bool hasTimeout = false;
Weiwei Liu245d7912016-07-28 00:04:25 -0700101
102 for (auto& entry : m_segmentInfo) {
103 SegmentInfo& segInfo = entry.second;
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500104 if (segInfo.state != SegmentState::InRetxQueue) { // skip segments already in the retx queue
Davide Pesavento70576402019-06-07 16:42:21 -0400105 auto timeElapsed = time::steady_clock::now() - segInfo.timeSent;
106 if (timeElapsed > segInfo.rto) { // timer expired?
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700107 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -0500108 hasTimeout = true;
109 enqueueForRetransmission(entry.first);
Weiwei Liu245d7912016-07-28 00:04:25 -0700110 }
111 }
112 }
113
Davide Pesavento958896e2017-01-19 00:52:04 -0500114 if (hasTimeout) {
115 recordTimeout();
116 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700117 }
118
119 // schedule the next check after predefined interval
Davide Pesaventobf2c5172019-03-20 19:08:09 -0400120 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -0700121}
122
123void
schneiderklausd8197df2019-03-16 11:31:40 -0700124PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
Weiwei Liu245d7912016-07-28 00:04:25 -0700125{
126 if (isStopping())
127 return;
128
Ryan Wickman034f30f2018-06-06 11:11:11 -0500129 if (m_hasFinalBlockId && segNo > m_lastSegmentNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700130 return;
131
132 if (!isRetransmission && m_hasFailure)
133 return;
134
135 if (m_options.isVerbose) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500136 std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
137 << " segment #" << segNo << std::endl;
Weiwei Liu245d7912016-07-28 00:04:25 -0700138 }
139
140 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500141 // keep track of retx count for this segment
142 auto ret = m_retxCount.emplace(segNo, 1);
Weiwei Liu245d7912016-07-28 00:04:25 -0700143 if (ret.second == false) { // not the first retransmission
144 m_retxCount[segNo] += 1;
Davide Pesavento44b3b232017-12-23 16:58:25 -0500145 if (m_options.maxRetriesOnTimeoutOrNack != DataFetcher::MAX_RETRIES_INFINITE &&
146 m_retxCount[segNo] > m_options.maxRetriesOnTimeoutOrNack) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700147 return handleFail(segNo, "Reached the maximum number of retries (" +
148 to_string(m_options.maxRetriesOnTimeoutOrNack) +
149 ") while retrieving segment #" + to_string(segNo));
150 }
151
152 if (m_options.isVerbose) {
153 std::cerr << "# of retries for segment #" << segNo
154 << " is " << m_retxCount[segNo] << std::endl;
155 }
156 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700157 }
158
Davide Pesavento84d84772019-04-07 14:40:07 -0400159 auto interest = Interest()
160 .setName(Name(m_prefix).appendSegment(segNo))
161 .setCanBePrefix(false)
162 .setMustBeFresh(m_options.mustBeFresh)
163 .setInterestLifetime(m_options.interestLifetime);
Weiwei Liu245d7912016-07-28 00:04:25 -0700164
Junxiao Shi06d008c2019-02-04 08:26:59 +0000165 SegmentInfo& segInfo = m_segmentInfo[segNo];
166 segInfo.interestHdl = m_face.expressInterest(interest,
schneiderklausd8197df2019-03-16 11:31:40 -0700167 bind(&PipelineInterestsAdaptive::handleData, this, _1, _2),
168 bind(&PipelineInterestsAdaptive::handleNack, this, _1, _2),
169 bind(&PipelineInterestsAdaptive::handleLifetimeExpiration, this, _1));
Junxiao Shi06d008c2019-02-04 08:26:59 +0000170 segInfo.timeSent = time::steady_clock::now();
171 segInfo.rto = m_rttEstimator.getEstimatedRto();
172
Weiwei Liu245d7912016-07-28 00:04:25 -0700173 m_nInFlight++;
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400174 m_nSent++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700175
176 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500177 segInfo.state = SegmentState::Retransmitted;
Weiwei Liu245d7912016-07-28 00:04:25 -0700178 m_nRetransmitted++;
179 }
180 else {
181 m_highInterest = segNo;
Junxiao Shi06d008c2019-02-04 08:26:59 +0000182 segInfo.state = SegmentState::FirstTimeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700183 }
184}
185
186void
schneiderklausd8197df2019-03-16 11:31:40 -0700187PipelineInterestsAdaptive::schedulePackets()
Weiwei Liu245d7912016-07-28 00:04:25 -0700188{
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500189 BOOST_ASSERT(m_nInFlight >= 0);
190 auto availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nInFlight;
191
Weiwei Liu245d7912016-07-28 00:04:25 -0700192 while (availableWindowSize > 0) {
193 if (!m_retxQueue.empty()) { // do retransmission first
194 uint64_t retxSegNo = m_retxQueue.front();
195 m_retxQueue.pop();
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500196 if (m_segmentInfo.count(retxSegNo) == 0) {
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700197 m_nSkippedRetx++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700198 continue;
199 }
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500200 // the segment is still in the map, that means it needs to be retransmitted
Weiwei Liu245d7912016-07-28 00:04:25 -0700201 sendInterest(retxSegNo, true);
202 }
203 else { // send next segment
204 sendInterest(getNextSegmentNo(), false);
205 }
206 availableWindowSize--;
207 }
208}
209
210void
schneiderklausd8197df2019-03-16 11:31:40 -0700211PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data)
Weiwei Liu245d7912016-07-28 00:04:25 -0700212{
213 if (isStopping())
214 return;
215
Davide Pesavento84d84772019-04-07 14:40:07 -0400216 // Interest was expressed with CanBePrefix=false
Weiwei Liu245d7912016-07-28 00:04:25 -0700217 BOOST_ASSERT(data.getName().equals(interest.getName()));
218
Davide Pesavento969cd5a2018-04-20 16:27:47 -0400219 if (!m_hasFinalBlockId && data.getFinalBlock()) {
220 m_lastSegmentNo = data.getFinalBlock()->toSegment();
Weiwei Liu245d7912016-07-28 00:04:25 -0700221 m_hasFinalBlockId = true;
222 cancelInFlightSegmentsGreaterThan(m_lastSegmentNo);
223 if (m_hasFailure && m_lastSegmentNo >= m_failedSegNo) {
224 // previously failed segment is part of the content
225 return onFailure(m_failureReason);
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000226 }
227 else {
Weiwei Liu245d7912016-07-28 00:04:25 -0700228 m_hasFailure = false;
229 }
230 }
231
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500232 uint64_t recvSegNo = getSegmentFromPacket(data);
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500233 auto segIt = m_segmentInfo.find(recvSegNo);
234 if (segIt == m_segmentInfo.end()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700235 return; // ignore already-received segment
236 }
237
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500238 SegmentInfo& segInfo = segIt->second;
Davide Pesaventoba560662019-06-26 22:45:44 -0400239 time::nanoseconds rtt = time::steady_clock::now() - segInfo.timeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700240 if (m_options.isVerbose) {
241 std::cerr << "Received segment #" << recvSegNo
Davide Pesaventoba560662019-06-26 22:45:44 -0400242 << ", rtt=" << rtt.count() / 1e6 << "ms"
243 << ", rto=" << segInfo.rto.count() / 1e6 << "ms" << std::endl;
Weiwei Liu245d7912016-07-28 00:04:25 -0700244 }
245
Davide Pesavento958896e2017-01-19 00:52:04 -0500246 if (m_highData < recvSegNo) {
247 m_highData = recvSegNo;
248 }
249
250 // for segments in retx queue, we must not decrement m_nInFlight
251 // because it was already decremented when the segment timed out
252 if (segInfo.state != SegmentState::InRetxQueue) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700253 m_nInFlight--;
254 }
255
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000256 // upon finding congestion mark, decrease the window size
257 // without retransmitting any packet
258 if (data.getCongestionMark() > 0) {
259 m_nCongMarks++;
260 if (!m_options.ignoreCongMarks) {
261 if (m_options.disableCwa || m_highData > m_recPoint) {
262 m_recPoint = m_highInterest; // react to only one congestion event (timeout or congestion mark)
263 // per RTT (conservative window adaptation)
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700264 m_nMarkDecr++;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000265 decreaseWindow();
266
267 if (m_options.isVerbose) {
268 std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
269 << ", new cwnd = " << m_cwnd << std::endl;
270 }
271 }
272 }
273 else {
274 increaseWindow();
275 }
276 }
277 else {
278 increaseWindow();
279 }
280
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400281 onData(data);
Weiwei Liu245d7912016-07-28 00:04:25 -0700282
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500283 // do not sample RTT for retransmitted segments
284 if ((segInfo.state == SegmentState::FirstTimeSent ||
285 segInfo.state == SegmentState::InRetxQueue) &&
286 m_retxCount.count(recvSegNo) == 0) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500287 auto nExpectedSamples = std::max<int64_t>((m_nInFlight + 1) >> 1, 1);
288 BOOST_ASSERT(nExpectedSamples > 0);
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400289 m_rttEstimator.addMeasurement(rtt, static_cast<size_t>(nExpectedSamples));
290 afterRttMeasurement({recvSegNo, rtt,
291 m_rttEstimator.getSmoothedRtt(),
292 m_rttEstimator.getRttVariation(),
293 m_rttEstimator.getEstimatedRto()});
Weiwei Liu245d7912016-07-28 00:04:25 -0700294 }
295
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500296 // remove the entry associated with the received segment
297 m_segmentInfo.erase(segIt);
298
Ryan Wickman034f30f2018-06-06 11:11:11 -0500299 if (allSegmentsReceived()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700300 cancel();
Davide Pesaventof6991e12018-01-08 20:58:50 -0500301 if (!m_options.isQuiet) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700302 printSummary();
303 }
304 }
305 else {
306 schedulePackets();
307 }
308}
309
310void
schneiderklausd8197df2019-03-16 11:31:40 -0700311PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack& nack)
Weiwei Liu245d7912016-07-28 00:04:25 -0700312{
313 if (isStopping())
314 return;
315
316 if (m_options.isVerbose)
317 std::cerr << "Received Nack with reason " << nack.getReason()
318 << " for Interest " << interest << std::endl;
319
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500320 uint64_t segNo = getSegmentFromPacket(interest);
Weiwei Liu245d7912016-07-28 00:04:25 -0700321
322 switch (nack.getReason()) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500323 case lp::NackReason::DUPLICATE:
324 // ignore duplicates
Weiwei Liu245d7912016-07-28 00:04:25 -0700325 break;
Davide Pesavento958896e2017-01-19 00:52:04 -0500326 case lp::NackReason::CONGESTION:
327 // treated the same as timeout for now
328 enqueueForRetransmission(segNo);
329 recordTimeout();
330 schedulePackets();
331 break;
332 default:
Weiwei Liu245d7912016-07-28 00:04:25 -0700333 handleFail(segNo, "Could not retrieve data for " + interest.getName().toUri() +
334 ", reason: " + boost::lexical_cast<std::string>(nack.getReason()));
335 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700336 }
337}
338
339void
schneiderklausd8197df2019-03-16 11:31:40 -0700340PipelineInterestsAdaptive::handleLifetimeExpiration(const Interest& interest)
Weiwei Liu245d7912016-07-28 00:04:25 -0700341{
342 if (isStopping())
343 return;
344
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700345 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -0500346 enqueueForRetransmission(getSegmentFromPacket(interest));
347 recordTimeout();
348 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700349}
350
351void
schneiderklausd8197df2019-03-16 11:31:40 -0700352PipelineInterestsAdaptive::recordTimeout()
Weiwei Liu245d7912016-07-28 00:04:25 -0700353{
Weiwei Liu245d7912016-07-28 00:04:25 -0700354 if (m_options.disableCwa || m_highData > m_recPoint) {
355 // react to only one timeout per RTT (conservative window adaptation)
356 m_recPoint = m_highInterest;
357
358 decreaseWindow();
359 m_rttEstimator.backoffRto();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700360 m_nLossDecr++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700361
362 if (m_options.isVerbose) {
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000363 std::cerr << "Packet loss event, new cwnd = " << m_cwnd
Weiwei Liu245d7912016-07-28 00:04:25 -0700364 << ", ssthresh = " << m_ssthresh << std::endl;
365 }
366 }
Davide Pesavento958896e2017-01-19 00:52:04 -0500367}
Weiwei Liu245d7912016-07-28 00:04:25 -0700368
Davide Pesavento958896e2017-01-19 00:52:04 -0500369void
schneiderklausd8197df2019-03-16 11:31:40 -0700370PipelineInterestsAdaptive::enqueueForRetransmission(uint64_t segNo)
Davide Pesavento958896e2017-01-19 00:52:04 -0500371{
372 BOOST_ASSERT(m_nInFlight > 0);
373 m_nInFlight--;
374 m_retxQueue.push(segNo);
375 m_segmentInfo.at(segNo).state = SegmentState::InRetxQueue;
Weiwei Liu245d7912016-07-28 00:04:25 -0700376}
377
378void
schneiderklausd8197df2019-03-16 11:31:40 -0700379PipelineInterestsAdaptive::handleFail(uint64_t segNo, const std::string& reason)
Weiwei Liu245d7912016-07-28 00:04:25 -0700380{
381 if (isStopping())
382 return;
383
384 // if the failed segment is definitely part of the content, raise a fatal error
385 if (m_hasFinalBlockId && segNo <= m_lastSegmentNo)
386 return onFailure(reason);
387
388 if (!m_hasFinalBlockId) {
389 m_segmentInfo.erase(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500390 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700391
392 if (m_segmentInfo.empty()) {
393 onFailure("Fetching terminated but no final segment number has been found");
394 }
395 else {
396 cancelInFlightSegmentsGreaterThan(segNo);
397 m_hasFailure = true;
398 m_failedSegNo = segNo;
399 m_failureReason = reason;
400 }
401 }
402}
403
404void
schneiderklausd8197df2019-03-16 11:31:40 -0700405PipelineInterestsAdaptive::cancelInFlightSegmentsGreaterThan(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700406{
407 for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) {
408 // cancel fetching all segments that follow
Davide Pesavento958896e2017-01-19 00:52:04 -0500409 if (it->first > segNo) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700410 it = m_segmentInfo.erase(it);
Davide Pesavento958896e2017-01-19 00:52:04 -0500411 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700412 }
413 else {
414 ++it;
415 }
416 }
417}
418
419void
schneiderklausd8197df2019-03-16 11:31:40 -0700420PipelineInterestsAdaptive::printSummary() const
Weiwei Liu245d7912016-07-28 00:04:25 -0700421{
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000422 PipelineInterests::printSummary();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700423 std::cerr << "Congestion marks: " << m_nCongMarks << " (caused " << m_nMarkDecr << " window decreases)\n"
424 << "Timeouts: " << m_nTimeouts << " (caused " << m_nLossDecr << " window decreases)\n"
425 << "Retransmitted segments: " << m_nRetransmitted
Davide Pesaventoba560662019-06-26 22:45:44 -0400426 << " (" << (m_nSent == 0 ? 0 : (m_nRetransmitted * 100.0 / m_nSent)) << "%)"
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700427 << ", skipped: " << m_nSkippedRetx << "\n"
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400428 << "RTT ";
429
Davide Pesaventoba560662019-06-26 22:45:44 -0400430 if (m_rttEstimator.getMinRtt() == time::nanoseconds::max() ||
431 m_rttEstimator.getMaxRtt() == time::nanoseconds::min()) {
Davide Pesavento70576402019-06-07 16:42:21 -0400432 std::cerr << "stats unavailable\n";
433 }
434 else {
435 std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3)
Davide Pesaventoba560662019-06-26 22:45:44 -0400436 << m_rttEstimator.getMinRtt().count() / 1e6 << "/"
437 << m_rttEstimator.getAvgRtt().count() / 1e6 << "/"
438 << m_rttEstimator.getMaxRtt().count() / 1e6 << " ms\n";
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400439 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700440}
441
442std::ostream&
443operator<<(std::ostream& os, SegmentState state)
444{
445 switch (state) {
446 case SegmentState::FirstTimeSent:
447 os << "FirstTimeSent";
448 break;
449 case SegmentState::InRetxQueue:
450 os << "InRetxQueue";
451 break;
452 case SegmentState::Retransmitted:
453 os << "Retransmitted";
454 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700455 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700456 return os;
457}
458
459std::ostream&
schneiderklausd8197df2019-03-16 11:31:40 -0700460operator<<(std::ostream& os, const PipelineInterestsAdaptiveOptions& options)
Weiwei Liu245d7912016-07-28 00:04:25 -0700461{
schneiderklausd8197df2019-03-16 11:31:40 -0700462 os << "Adaptive pipeline parameters:\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700463 << "\tInitial congestion window size = " << options.initCwnd << "\n"
464 << "\tInitial slow start threshold = " << options.initSsthresh << "\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700465 << "\tAdditive increase step = " << options.aiStep << "\n"
Davide Pesavento958896e2017-01-19 00:52:04 -0500466 << "\tMultiplicative decrease factor = " << options.mdCoef << "\n"
Weiwei Liu245d7912016-07-28 00:04:25 -0700467 << "\tRTO check interval = " << options.rtoCheckInterval << "\n"
Davide Pesavento44b3b232017-12-23 16:58:25 -0500468 << "\tMax retries on timeout or Nack = " << (options.maxRetriesOnTimeoutOrNack == DataFetcher::MAX_RETRIES_INFINITE ?
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500469 "infinite" : to_string(options.maxRetriesOnTimeoutOrNack)) << "\n"
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700470 << "\tReact to congestion marks = " << (options.ignoreCongMarks ? "no" : "yes") << "\n"
471 << "\tConservative window adaptation = " << (options.disableCwa ? "no" : "yes") << "\n"
472 << "\tResetting window to " << (options.resetCwndToInit ? "initCwnd" : "ssthresh") << " upon loss event\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700473 return os;
474}
475
Weiwei Liu245d7912016-07-28 00:04:25 -0700476} // namespace chunks
477} // namespace ndn