blob: 891b94eb40d0a2727169bd3a65c83c8db498ebe3 [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/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2016-2022, 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
Davide Pesaventob3570c62022-02-19 19:19:00 -050035namespace ndn::chunks {
Weiwei Liu245d7912016-07-28 00:04:25 -070036
Davide Pesavento5e3773d2019-08-22 15:35:08 -040037PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face,
38 RttEstimatorWithStats& rttEstimator,
Davide Pesavento97a33b22019-10-17 22:10:47 -040039 const Options& opts)
40 : PipelineInterests(face, opts)
Klaus Schneider9e5122b2019-03-19 17:03:25 -070041 , m_cwnd(m_options.initCwnd)
42 , m_ssthresh(m_options.initSsthresh)
Weiwei Liu245d7912016-07-28 00:04:25 -070043 , m_rttEstimator(rttEstimator)
44 , m_scheduler(m_face.getIoService())
Weiwei Liu245d7912016-07-28 00:04:25 -070045{
Weiwei Liu245d7912016-07-28 00:04:25 -070046}
47
schneiderklausd8197df2019-03-16 11:31:40 -070048PipelineInterestsAdaptive::~PipelineInterestsAdaptive()
Weiwei Liu245d7912016-07-28 00:04:25 -070049{
50 cancel();
51}
52
53void
schneiderklausd8197df2019-03-16 11:31:40 -070054PipelineInterestsAdaptive::doRun()
Weiwei Liu245d7912016-07-28 00:04:25 -070055{
Ryan Wickman034f30f2018-06-06 11:11:11 -050056 if (allSegmentsReceived()) {
57 cancel();
58 if (!m_options.isQuiet) {
59 printSummary();
60 }
61 return;
62 }
63
Weiwei Liu245d7912016-07-28 00:04:25 -070064 // schedule the event to check retransmission timer
Davide Pesaventobf2c5172019-03-20 19:08:09 -040065 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -070066
Davide Pesavento958896e2017-01-19 00:52:04 -050067 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -070068}
69
70void
schneiderklausd8197df2019-03-16 11:31:40 -070071PipelineInterestsAdaptive::doCancel()
Weiwei Liu245d7912016-07-28 00:04:25 -070072{
Davide Pesaventocd65c2c2017-01-15 16:10:38 -050073 m_checkRtoEvent.cancel();
Weiwei Liu245d7912016-07-28 00:04:25 -070074 m_segmentInfo.clear();
Weiwei Liu245d7912016-07-28 00:04:25 -070075}
76
77void
schneiderklausd8197df2019-03-16 11:31:40 -070078PipelineInterestsAdaptive::checkRto()
Weiwei Liu245d7912016-07-28 00:04:25 -070079{
80 if (isStopping())
81 return;
82
Davide Pesavento958896e2017-01-19 00:52:04 -050083 bool hasTimeout = false;
Sichen Song40eae032022-05-01 16:33:00 -070084 uint64_t highTimeoutSeg = 0;
Weiwei Liu245d7912016-07-28 00:04:25 -070085
86 for (auto& entry : m_segmentInfo) {
87 SegmentInfo& segInfo = entry.second;
Ryan Wickman2c9933c2018-06-12 11:51:51 -050088 if (segInfo.state != SegmentState::InRetxQueue) { // skip segments already in the retx queue
Davide Pesavento70576402019-06-07 16:42:21 -040089 auto timeElapsed = time::steady_clock::now() - segInfo.timeSent;
90 if (timeElapsed > segInfo.rto) { // timer expired?
schneiderklaus8ff3abd2019-03-12 22:15:12 -070091 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -050092 hasTimeout = true;
Sichen Song40eae032022-05-01 16:33:00 -070093 highTimeoutSeg = std::max(highTimeoutSeg, entry.first);
Davide Pesavento958896e2017-01-19 00:52:04 -050094 enqueueForRetransmission(entry.first);
Weiwei Liu245d7912016-07-28 00:04:25 -070095 }
96 }
97 }
98
Davide Pesavento958896e2017-01-19 00:52:04 -050099 if (hasTimeout) {
Sichen Song40eae032022-05-01 16:33:00 -0700100 recordTimeout(highTimeoutSeg);
Davide Pesavento958896e2017-01-19 00:52:04 -0500101 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700102 }
103
104 // schedule the next check after predefined interval
Davide Pesaventobf2c5172019-03-20 19:08:09 -0400105 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -0700106}
107
108void
schneiderklausd8197df2019-03-16 11:31:40 -0700109PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
Weiwei Liu245d7912016-07-28 00:04:25 -0700110{
111 if (isStopping())
112 return;
113
Ryan Wickman034f30f2018-06-06 11:11:11 -0500114 if (m_hasFinalBlockId && segNo > m_lastSegmentNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700115 return;
116
117 if (!isRetransmission && m_hasFailure)
118 return;
119
120 if (m_options.isVerbose) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500121 std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400122 << " segment #" << segNo << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700123 }
124
125 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500126 // keep track of retx count for this segment
127 auto ret = m_retxCount.emplace(segNo, 1);
Davide Pesaventob3570c62022-02-19 19:19:00 -0500128 if (!ret.second) { // not the first retransmission
Weiwei Liu245d7912016-07-28 00:04:25 -0700129 m_retxCount[segNo] += 1;
Davide Pesavento44b3b232017-12-23 16:58:25 -0500130 if (m_options.maxRetriesOnTimeoutOrNack != DataFetcher::MAX_RETRIES_INFINITE &&
131 m_retxCount[segNo] > m_options.maxRetriesOnTimeoutOrNack) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700132 return handleFail(segNo, "Reached the maximum number of retries (" +
133 to_string(m_options.maxRetriesOnTimeoutOrNack) +
134 ") while retrieving segment #" + to_string(segNo));
135 }
136
137 if (m_options.isVerbose) {
138 std::cerr << "# of retries for segment #" << segNo
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400139 << " is " << m_retxCount[segNo] << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700140 }
141 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700142 }
143
Davide Pesavento84d84772019-04-07 14:40:07 -0400144 auto interest = Interest()
145 .setName(Name(m_prefix).appendSegment(segNo))
Davide Pesavento84d84772019-04-07 14:40:07 -0400146 .setMustBeFresh(m_options.mustBeFresh)
147 .setInterestLifetime(m_options.interestLifetime);
Weiwei Liu245d7912016-07-28 00:04:25 -0700148
Junxiao Shi06d008c2019-02-04 08:26:59 +0000149 SegmentInfo& segInfo = m_segmentInfo[segNo];
150 segInfo.interestHdl = m_face.expressInterest(interest,
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400151 FORWARD_TO_MEM_FN(handleData),
152 FORWARD_TO_MEM_FN(handleNack),
153 FORWARD_TO_MEM_FN(handleLifetimeExpiration));
Junxiao Shi06d008c2019-02-04 08:26:59 +0000154 segInfo.timeSent = time::steady_clock::now();
155 segInfo.rto = m_rttEstimator.getEstimatedRto();
156
Weiwei Liu245d7912016-07-28 00:04:25 -0700157 m_nInFlight++;
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400158 m_nSent++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700159
160 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500161 segInfo.state = SegmentState::Retransmitted;
Weiwei Liu245d7912016-07-28 00:04:25 -0700162 m_nRetransmitted++;
163 }
164 else {
165 m_highInterest = segNo;
Junxiao Shi06d008c2019-02-04 08:26:59 +0000166 segInfo.state = SegmentState::FirstTimeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700167 }
168}
169
170void
schneiderklausd8197df2019-03-16 11:31:40 -0700171PipelineInterestsAdaptive::schedulePackets()
Weiwei Liu245d7912016-07-28 00:04:25 -0700172{
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500173 BOOST_ASSERT(m_nInFlight >= 0);
174 auto availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nInFlight;
175
Weiwei Liu245d7912016-07-28 00:04:25 -0700176 while (availableWindowSize > 0) {
177 if (!m_retxQueue.empty()) { // do retransmission first
178 uint64_t retxSegNo = m_retxQueue.front();
179 m_retxQueue.pop();
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500180 if (m_segmentInfo.count(retxSegNo) == 0) {
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700181 m_nSkippedRetx++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700182 continue;
183 }
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500184 // the segment is still in the map, that means it needs to be retransmitted
Weiwei Liu245d7912016-07-28 00:04:25 -0700185 sendInterest(retxSegNo, true);
186 }
187 else { // send next segment
188 sendInterest(getNextSegmentNo(), false);
189 }
190 availableWindowSize--;
191 }
192}
193
194void
schneiderklausd8197df2019-03-16 11:31:40 -0700195PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data)
Weiwei Liu245d7912016-07-28 00:04:25 -0700196{
197 if (isStopping())
198 return;
199
Davide Pesavento84d84772019-04-07 14:40:07 -0400200 // Interest was expressed with CanBePrefix=false
Weiwei Liu245d7912016-07-28 00:04:25 -0700201 BOOST_ASSERT(data.getName().equals(interest.getName()));
202
Davide Pesavento969cd5a2018-04-20 16:27:47 -0400203 if (!m_hasFinalBlockId && data.getFinalBlock()) {
204 m_lastSegmentNo = data.getFinalBlock()->toSegment();
Weiwei Liu245d7912016-07-28 00:04:25 -0700205 m_hasFinalBlockId = true;
206 cancelInFlightSegmentsGreaterThan(m_lastSegmentNo);
207 if (m_hasFailure && m_lastSegmentNo >= m_failedSegNo) {
208 // previously failed segment is part of the content
209 return onFailure(m_failureReason);
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000210 }
211 else {
Weiwei Liu245d7912016-07-28 00:04:25 -0700212 m_hasFailure = false;
213 }
214 }
215
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500216 uint64_t recvSegNo = getSegmentFromPacket(data);
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500217 auto segIt = m_segmentInfo.find(recvSegNo);
218 if (segIt == m_segmentInfo.end()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700219 return; // ignore already-received segment
220 }
221
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500222 SegmentInfo& segInfo = segIt->second;
Davide Pesaventoba560662019-06-26 22:45:44 -0400223 time::nanoseconds rtt = time::steady_clock::now() - segInfo.timeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700224 if (m_options.isVerbose) {
225 std::cerr << "Received segment #" << recvSegNo
Davide Pesaventoba560662019-06-26 22:45:44 -0400226 << ", rtt=" << rtt.count() / 1e6 << "ms"
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400227 << ", rto=" << segInfo.rto.count() / 1e6 << "ms\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700228 }
229
Sichen Song40eae032022-05-01 16:33:00 -0700230 m_highData = std::max(m_highData, recvSegNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500231
232 // for segments in retx queue, we must not decrement m_nInFlight
233 // because it was already decremented when the segment timed out
234 if (segInfo.state != SegmentState::InRetxQueue) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700235 m_nInFlight--;
236 }
237
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000238 // upon finding congestion mark, decrease the window size
239 // without retransmitting any packet
240 if (data.getCongestionMark() > 0) {
241 m_nCongMarks++;
242 if (!m_options.ignoreCongMarks) {
243 if (m_options.disableCwa || m_highData > m_recPoint) {
244 m_recPoint = m_highInterest; // react to only one congestion event (timeout or congestion mark)
245 // per RTT (conservative window adaptation)
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700246 m_nMarkDecr++;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000247 decreaseWindow();
248
249 if (m_options.isVerbose) {
250 std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400251 << ", new cwnd = " << m_cwnd << "\n";
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000252 }
253 }
254 }
255 else {
256 increaseWindow();
257 }
258 }
259 else {
260 increaseWindow();
261 }
262
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400263 onData(data);
Weiwei Liu245d7912016-07-28 00:04:25 -0700264
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500265 // do not sample RTT for retransmitted segments
266 if ((segInfo.state == SegmentState::FirstTimeSent ||
267 segInfo.state == SegmentState::InRetxQueue) &&
268 m_retxCount.count(recvSegNo) == 0) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500269 auto nExpectedSamples = std::max<int64_t>((m_nInFlight + 1) >> 1, 1);
270 BOOST_ASSERT(nExpectedSamples > 0);
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400271 m_rttEstimator.addMeasurement(rtt, static_cast<size_t>(nExpectedSamples));
272 afterRttMeasurement({recvSegNo, rtt,
273 m_rttEstimator.getSmoothedRtt(),
274 m_rttEstimator.getRttVariation(),
275 m_rttEstimator.getEstimatedRto()});
Weiwei Liu245d7912016-07-28 00:04:25 -0700276 }
277
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500278 // remove the entry associated with the received segment
279 m_segmentInfo.erase(segIt);
280
Ryan Wickman034f30f2018-06-06 11:11:11 -0500281 if (allSegmentsReceived()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700282 cancel();
Davide Pesaventof6991e12018-01-08 20:58:50 -0500283 if (!m_options.isQuiet) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700284 printSummary();
285 }
286 }
287 else {
288 schedulePackets();
289 }
290}
291
292void
schneiderklausd8197df2019-03-16 11:31:40 -0700293PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack& nack)
Weiwei Liu245d7912016-07-28 00:04:25 -0700294{
295 if (isStopping())
296 return;
297
298 if (m_options.isVerbose)
299 std::cerr << "Received Nack with reason " << nack.getReason()
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400300 << " for Interest " << interest << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700301
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500302 uint64_t segNo = getSegmentFromPacket(interest);
Weiwei Liu245d7912016-07-28 00:04:25 -0700303
304 switch (nack.getReason()) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500305 case lp::NackReason::DUPLICATE:
306 // ignore duplicates
Weiwei Liu245d7912016-07-28 00:04:25 -0700307 break;
Davide Pesavento958896e2017-01-19 00:52:04 -0500308 case lp::NackReason::CONGESTION:
309 // treated the same as timeout for now
310 enqueueForRetransmission(segNo);
Sichen Song40eae032022-05-01 16:33:00 -0700311 recordTimeout(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500312 schedulePackets();
313 break;
314 default:
Weiwei Liu245d7912016-07-28 00:04:25 -0700315 handleFail(segNo, "Could not retrieve data for " + interest.getName().toUri() +
316 ", reason: " + boost::lexical_cast<std::string>(nack.getReason()));
317 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700318 }
319}
320
321void
schneiderklausd8197df2019-03-16 11:31:40 -0700322PipelineInterestsAdaptive::handleLifetimeExpiration(const Interest& interest)
Weiwei Liu245d7912016-07-28 00:04:25 -0700323{
324 if (isStopping())
325 return;
326
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700327 m_nTimeouts++;
Sichen Song40eae032022-05-01 16:33:00 -0700328
329 uint64_t segNo = getSegmentFromPacket(interest);
330 enqueueForRetransmission(segNo);
331 recordTimeout(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500332 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700333}
334
335void
Sichen Song40eae032022-05-01 16:33:00 -0700336PipelineInterestsAdaptive::recordTimeout(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700337{
Sichen Song40eae032022-05-01 16:33:00 -0700338 if (m_options.disableCwa || segNo > m_recPoint) {
339 // interests that are still outstanding during a timeout event
340 // should not trigger another window decrease later (bug #5202)
Weiwei Liu245d7912016-07-28 00:04:25 -0700341 m_recPoint = m_highInterest;
342
343 decreaseWindow();
344 m_rttEstimator.backoffRto();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700345 m_nLossDecr++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700346
347 if (m_options.isVerbose) {
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000348 std::cerr << "Packet loss event, new cwnd = " << m_cwnd
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400349 << ", ssthresh = " << m_ssthresh << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700350 }
351 }
Davide Pesavento958896e2017-01-19 00:52:04 -0500352}
Weiwei Liu245d7912016-07-28 00:04:25 -0700353
Davide Pesavento958896e2017-01-19 00:52:04 -0500354void
schneiderklausd8197df2019-03-16 11:31:40 -0700355PipelineInterestsAdaptive::enqueueForRetransmission(uint64_t segNo)
Davide Pesavento958896e2017-01-19 00:52:04 -0500356{
357 BOOST_ASSERT(m_nInFlight > 0);
358 m_nInFlight--;
359 m_retxQueue.push(segNo);
360 m_segmentInfo.at(segNo).state = SegmentState::InRetxQueue;
Weiwei Liu245d7912016-07-28 00:04:25 -0700361}
362
363void
schneiderklausd8197df2019-03-16 11:31:40 -0700364PipelineInterestsAdaptive::handleFail(uint64_t segNo, const std::string& reason)
Weiwei Liu245d7912016-07-28 00:04:25 -0700365{
366 if (isStopping())
367 return;
368
369 // if the failed segment is definitely part of the content, raise a fatal error
370 if (m_hasFinalBlockId && segNo <= m_lastSegmentNo)
371 return onFailure(reason);
372
373 if (!m_hasFinalBlockId) {
374 m_segmentInfo.erase(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500375 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700376
377 if (m_segmentInfo.empty()) {
378 onFailure("Fetching terminated but no final segment number has been found");
379 }
380 else {
381 cancelInFlightSegmentsGreaterThan(segNo);
382 m_hasFailure = true;
383 m_failedSegNo = segNo;
384 m_failureReason = reason;
385 }
386 }
387}
388
389void
schneiderklausd8197df2019-03-16 11:31:40 -0700390PipelineInterestsAdaptive::cancelInFlightSegmentsGreaterThan(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700391{
392 for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) {
393 // cancel fetching all segments that follow
Davide Pesavento958896e2017-01-19 00:52:04 -0500394 if (it->first > segNo) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700395 it = m_segmentInfo.erase(it);
Davide Pesavento958896e2017-01-19 00:52:04 -0500396 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700397 }
398 else {
399 ++it;
400 }
401 }
402}
403
404void
Davide Pesavento97a33b22019-10-17 22:10:47 -0400405PipelineInterestsAdaptive::printOptions() const
406{
407 PipelineInterests::printOptions();
408 std::cerr
409 << "\tInitial congestion window size = " << m_options.initCwnd << "\n"
410 << "\tInitial slow start threshold = " << m_options.initSsthresh << "\n"
411 << "\tAdditive increase step = " << m_options.aiStep << "\n"
412 << "\tMultiplicative decrease factor = " << m_options.mdCoef << "\n"
413 << "\tRTO check interval = " << m_options.rtoCheckInterval << "\n"
414 << "\tReact to congestion marks = " << (m_options.ignoreCongMarks ? "no" : "yes") << "\n"
415 << "\tConservative window adaptation = " << (m_options.disableCwa ? "no" : "yes") << "\n"
416 << "\tResetting window to " << (m_options.resetCwndToInit ?
417 "initial value" : "ssthresh") << " upon loss event\n";
418}
419
420void
schneiderklausd8197df2019-03-16 11:31:40 -0700421PipelineInterestsAdaptive::printSummary() const
Weiwei Liu245d7912016-07-28 00:04:25 -0700422{
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000423 PipelineInterests::printSummary();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700424 std::cerr << "Congestion marks: " << m_nCongMarks << " (caused " << m_nMarkDecr << " window decreases)\n"
425 << "Timeouts: " << m_nTimeouts << " (caused " << m_nLossDecr << " window decreases)\n"
426 << "Retransmitted segments: " << m_nRetransmitted
Davide Pesaventoba560662019-06-26 22:45:44 -0400427 << " (" << (m_nSent == 0 ? 0 : (m_nRetransmitted * 100.0 / m_nSent)) << "%)"
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700428 << ", skipped: " << m_nSkippedRetx << "\n"
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400429 << "RTT ";
430
Davide Pesaventoba560662019-06-26 22:45:44 -0400431 if (m_rttEstimator.getMinRtt() == time::nanoseconds::max() ||
432 m_rttEstimator.getMaxRtt() == time::nanoseconds::min()) {
Davide Pesavento70576402019-06-07 16:42:21 -0400433 std::cerr << "stats unavailable\n";
434 }
435 else {
436 std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3)
Davide Pesaventoba560662019-06-26 22:45:44 -0400437 << m_rttEstimator.getMinRtt().count() / 1e6 << "/"
438 << m_rttEstimator.getAvgRtt().count() / 1e6 << "/"
439 << m_rttEstimator.getMaxRtt().count() / 1e6 << " ms\n";
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400440 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700441}
442
443std::ostream&
444operator<<(std::ostream& os, SegmentState state)
445{
446 switch (state) {
447 case SegmentState::FirstTimeSent:
448 os << "FirstTimeSent";
449 break;
450 case SegmentState::InRetxQueue:
451 os << "InRetxQueue";
452 break;
453 case SegmentState::Retransmitted:
454 os << "Retransmitted";
455 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700456 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700457 return os;
458}
459
Davide Pesaventob3570c62022-02-19 19:19:00 -0500460} // namespace ndn::chunks