blob: 78c4c6e0a0c8709c3b251123574c7bcd03c25fb4 [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 Pesavento11fc3eb2024-01-26 01:46:56 -05003 * Copyright (c) 2016-2024, 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
Chavoosh Ghasemi3dae1092017-12-21 12:39:08 -070032#include <iomanip>
Weiwei Liu245d7912016-07-28 00:04:25 -070033
Davide Pesaventob3570c62022-02-19 19:19:00 -050034namespace ndn::chunks {
Weiwei Liu245d7912016-07-28 00:04:25 -070035
Davide Pesavento5e3773d2019-08-22 15:35:08 -040036PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face,
37 RttEstimatorWithStats& rttEstimator,
Davide Pesavento97a33b22019-10-17 22:10:47 -040038 const Options& opts)
39 : PipelineInterests(face, opts)
Klaus Schneider9e5122b2019-03-19 17:03:25 -070040 , m_cwnd(m_options.initCwnd)
41 , m_ssthresh(m_options.initSsthresh)
Weiwei Liu245d7912016-07-28 00:04:25 -070042 , m_rttEstimator(rttEstimator)
Davide Pesavento7e9d7e42023-11-11 15:00:03 -050043 , m_scheduler(m_face.getIoContext())
Weiwei Liu245d7912016-07-28 00:04:25 -070044{
Weiwei Liu245d7912016-07-28 00:04:25 -070045}
46
schneiderklausd8197df2019-03-16 11:31:40 -070047PipelineInterestsAdaptive::~PipelineInterestsAdaptive()
Weiwei Liu245d7912016-07-28 00:04:25 -070048{
49 cancel();
50}
51
52void
schneiderklausd8197df2019-03-16 11:31:40 -070053PipelineInterestsAdaptive::doRun()
Weiwei Liu245d7912016-07-28 00:04:25 -070054{
Ryan Wickman034f30f2018-06-06 11:11:11 -050055 if (allSegmentsReceived()) {
56 cancel();
57 if (!m_options.isQuiet) {
58 printSummary();
59 }
60 return;
61 }
62
Weiwei Liu245d7912016-07-28 00:04:25 -070063 // schedule the event to check retransmission timer
Davide Pesaventobf2c5172019-03-20 19:08:09 -040064 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -070065
Davide Pesavento958896e2017-01-19 00:52:04 -050066 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -070067}
68
69void
schneiderklausd8197df2019-03-16 11:31:40 -070070PipelineInterestsAdaptive::doCancel()
Weiwei Liu245d7912016-07-28 00:04:25 -070071{
Davide Pesaventocd65c2c2017-01-15 16:10:38 -050072 m_checkRtoEvent.cancel();
Weiwei Liu245d7912016-07-28 00:04:25 -070073 m_segmentInfo.clear();
Weiwei Liu245d7912016-07-28 00:04:25 -070074}
75
76void
schneiderklausd8197df2019-03-16 11:31:40 -070077PipelineInterestsAdaptive::checkRto()
Weiwei Liu245d7912016-07-28 00:04:25 -070078{
79 if (isStopping())
80 return;
81
Davide Pesavento958896e2017-01-19 00:52:04 -050082 bool hasTimeout = false;
Sichen Song40eae032022-05-01 16:33:00 -070083 uint64_t highTimeoutSeg = 0;
Weiwei Liu245d7912016-07-28 00:04:25 -070084
85 for (auto& entry : m_segmentInfo) {
86 SegmentInfo& segInfo = entry.second;
Ryan Wickman2c9933c2018-06-12 11:51:51 -050087 if (segInfo.state != SegmentState::InRetxQueue) { // skip segments already in the retx queue
Davide Pesavento70576402019-06-07 16:42:21 -040088 auto timeElapsed = time::steady_clock::now() - segInfo.timeSent;
89 if (timeElapsed > segInfo.rto) { // timer expired?
schneiderklaus8ff3abd2019-03-12 22:15:12 -070090 m_nTimeouts++;
Davide Pesavento958896e2017-01-19 00:52:04 -050091 hasTimeout = true;
Sichen Song40eae032022-05-01 16:33:00 -070092 highTimeoutSeg = std::max(highTimeoutSeg, entry.first);
Davide Pesavento958896e2017-01-19 00:52:04 -050093 enqueueForRetransmission(entry.first);
Weiwei Liu245d7912016-07-28 00:04:25 -070094 }
95 }
96 }
97
Davide Pesavento958896e2017-01-19 00:52:04 -050098 if (hasTimeout) {
Sichen Song40eae032022-05-01 16:33:00 -070099 recordTimeout(highTimeoutSeg);
Davide Pesavento958896e2017-01-19 00:52:04 -0500100 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700101 }
102
103 // schedule the next check after predefined interval
Davide Pesaventobf2c5172019-03-20 19:08:09 -0400104 m_checkRtoEvent = m_scheduler.schedule(m_options.rtoCheckInterval, [this] { checkRto(); });
Weiwei Liu245d7912016-07-28 00:04:25 -0700105}
106
107void
schneiderklausd8197df2019-03-16 11:31:40 -0700108PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
Weiwei Liu245d7912016-07-28 00:04:25 -0700109{
110 if (isStopping())
111 return;
112
Ryan Wickman034f30f2018-06-06 11:11:11 -0500113 if (m_hasFinalBlockId && segNo > m_lastSegmentNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700114 return;
115
116 if (!isRetransmission && m_hasFailure)
117 return;
118
119 if (m_options.isVerbose) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500120 std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400121 << " segment #" << segNo << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700122 }
123
124 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500125 // keep track of retx count for this segment
126 auto ret = m_retxCount.emplace(segNo, 1);
Davide Pesaventob3570c62022-02-19 19:19:00 -0500127 if (!ret.second) { // not the first retransmission
Weiwei Liu245d7912016-07-28 00:04:25 -0700128 m_retxCount[segNo] += 1;
Davide Pesavento44b3b232017-12-23 16:58:25 -0500129 if (m_options.maxRetriesOnTimeoutOrNack != DataFetcher::MAX_RETRIES_INFINITE &&
130 m_retxCount[segNo] > m_options.maxRetriesOnTimeoutOrNack) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700131 return handleFail(segNo, "Reached the maximum number of retries (" +
Davide Pesavento11fc3eb2024-01-26 01:46:56 -0500132 std::to_string(m_options.maxRetriesOnTimeoutOrNack) +
133 ") while retrieving segment #" + std::to_string(segNo));
Weiwei Liu245d7912016-07-28 00:04:25 -0700134 }
135
136 if (m_options.isVerbose) {
137 std::cerr << "# of retries for segment #" << segNo
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400138 << " is " << m_retxCount[segNo] << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700139 }
140 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700141 }
142
Davide Pesavento84d84772019-04-07 14:40:07 -0400143 auto interest = Interest()
144 .setName(Name(m_prefix).appendSegment(segNo))
Davide Pesavento84d84772019-04-07 14:40:07 -0400145 .setMustBeFresh(m_options.mustBeFresh)
146 .setInterestLifetime(m_options.interestLifetime);
Weiwei Liu245d7912016-07-28 00:04:25 -0700147
Junxiao Shi06d008c2019-02-04 08:26:59 +0000148 SegmentInfo& segInfo = m_segmentInfo[segNo];
149 segInfo.interestHdl = m_face.expressInterest(interest,
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400150 FORWARD_TO_MEM_FN(handleData),
151 FORWARD_TO_MEM_FN(handleNack),
152 FORWARD_TO_MEM_FN(handleLifetimeExpiration));
Junxiao Shi06d008c2019-02-04 08:26:59 +0000153 segInfo.timeSent = time::steady_clock::now();
154 segInfo.rto = m_rttEstimator.getEstimatedRto();
155
Weiwei Liu245d7912016-07-28 00:04:25 -0700156 m_nInFlight++;
Chavoosh Ghasemi75309ae2018-03-26 14:46:24 -0400157 m_nSent++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700158
159 if (isRetransmission) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500160 segInfo.state = SegmentState::Retransmitted;
Weiwei Liu245d7912016-07-28 00:04:25 -0700161 m_nRetransmitted++;
162 }
163 else {
164 m_highInterest = segNo;
Junxiao Shi06d008c2019-02-04 08:26:59 +0000165 segInfo.state = SegmentState::FirstTimeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700166 }
167}
168
169void
schneiderklausd8197df2019-03-16 11:31:40 -0700170PipelineInterestsAdaptive::schedulePackets()
Weiwei Liu245d7912016-07-28 00:04:25 -0700171{
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500172 BOOST_ASSERT(m_nInFlight >= 0);
173 auto availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nInFlight;
174
Weiwei Liu245d7912016-07-28 00:04:25 -0700175 while (availableWindowSize > 0) {
176 if (!m_retxQueue.empty()) { // do retransmission first
177 uint64_t retxSegNo = m_retxQueue.front();
178 m_retxQueue.pop();
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500179 if (m_segmentInfo.count(retxSegNo) == 0) {
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700180 m_nSkippedRetx++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700181 continue;
182 }
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500183 // the segment is still in the map, that means it needs to be retransmitted
Weiwei Liu245d7912016-07-28 00:04:25 -0700184 sendInterest(retxSegNo, true);
185 }
186 else { // send next segment
187 sendInterest(getNextSegmentNo(), false);
188 }
189 availableWindowSize--;
190 }
191}
192
193void
schneiderklausd8197df2019-03-16 11:31:40 -0700194PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data)
Weiwei Liu245d7912016-07-28 00:04:25 -0700195{
196 if (isStopping())
197 return;
198
Davide Pesavento84d84772019-04-07 14:40:07 -0400199 // Interest was expressed with CanBePrefix=false
Weiwei Liu245d7912016-07-28 00:04:25 -0700200 BOOST_ASSERT(data.getName().equals(interest.getName()));
201
Davide Pesavento969cd5a2018-04-20 16:27:47 -0400202 if (!m_hasFinalBlockId && data.getFinalBlock()) {
203 m_lastSegmentNo = data.getFinalBlock()->toSegment();
Weiwei Liu245d7912016-07-28 00:04:25 -0700204 m_hasFinalBlockId = true;
205 cancelInFlightSegmentsGreaterThan(m_lastSegmentNo);
206 if (m_hasFailure && m_lastSegmentNo >= m_failedSegNo) {
207 // previously failed segment is part of the content
208 return onFailure(m_failureReason);
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000209 }
210 else {
Weiwei Liu245d7912016-07-28 00:04:25 -0700211 m_hasFailure = false;
212 }
213 }
214
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500215 uint64_t recvSegNo = getSegmentFromPacket(data);
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500216 auto segIt = m_segmentInfo.find(recvSegNo);
217 if (segIt == m_segmentInfo.end()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700218 return; // ignore already-received segment
219 }
220
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500221 SegmentInfo& segInfo = segIt->second;
Davide Pesaventoba560662019-06-26 22:45:44 -0400222 time::nanoseconds rtt = time::steady_clock::now() - segInfo.timeSent;
Weiwei Liu245d7912016-07-28 00:04:25 -0700223 if (m_options.isVerbose) {
224 std::cerr << "Received segment #" << recvSegNo
Davide Pesaventoba560662019-06-26 22:45:44 -0400225 << ", rtt=" << rtt.count() / 1e6 << "ms"
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400226 << ", rto=" << segInfo.rto.count() / 1e6 << "ms\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700227 }
228
Sichen Song40eae032022-05-01 16:33:00 -0700229 m_highData = std::max(m_highData, recvSegNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500230
231 // for segments in retx queue, we must not decrement m_nInFlight
232 // because it was already decremented when the segment timed out
233 if (segInfo.state != SegmentState::InRetxQueue) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700234 m_nInFlight--;
235 }
236
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000237 // upon finding congestion mark, decrease the window size
238 // without retransmitting any packet
239 if (data.getCongestionMark() > 0) {
240 m_nCongMarks++;
241 if (!m_options.ignoreCongMarks) {
242 if (m_options.disableCwa || m_highData > m_recPoint) {
243 m_recPoint = m_highInterest; // react to only one congestion event (timeout or congestion mark)
244 // per RTT (conservative window adaptation)
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700245 m_nMarkDecr++;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000246 decreaseWindow();
247
248 if (m_options.isVerbose) {
249 std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400250 << ", new cwnd = " << m_cwnd << "\n";
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000251 }
252 }
253 }
254 else {
255 increaseWindow();
256 }
257 }
258 else {
259 increaseWindow();
260 }
261
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400262 onData(data);
Weiwei Liu245d7912016-07-28 00:04:25 -0700263
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500264 // do not sample RTT for retransmitted segments
265 if ((segInfo.state == SegmentState::FirstTimeSent ||
266 segInfo.state == SegmentState::InRetxQueue) &&
267 m_retxCount.count(recvSegNo) == 0) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500268 auto nExpectedSamples = std::max<int64_t>((m_nInFlight + 1) >> 1, 1);
269 BOOST_ASSERT(nExpectedSamples > 0);
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400270 m_rttEstimator.addMeasurement(rtt, static_cast<size_t>(nExpectedSamples));
271 afterRttMeasurement({recvSegNo, rtt,
272 m_rttEstimator.getSmoothedRtt(),
273 m_rttEstimator.getRttVariation(),
274 m_rttEstimator.getEstimatedRto()});
Weiwei Liu245d7912016-07-28 00:04:25 -0700275 }
276
Ryan Wickman2c9933c2018-06-12 11:51:51 -0500277 // remove the entry associated with the received segment
278 m_segmentInfo.erase(segIt);
279
Ryan Wickman034f30f2018-06-06 11:11:11 -0500280 if (allSegmentsReceived()) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700281 cancel();
Davide Pesaventof6991e12018-01-08 20:58:50 -0500282 if (!m_options.isQuiet) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700283 printSummary();
284 }
285 }
286 else {
287 schedulePackets();
288 }
289}
290
291void
schneiderklausd8197df2019-03-16 11:31:40 -0700292PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack& nack)
Weiwei Liu245d7912016-07-28 00:04:25 -0700293{
294 if (isStopping())
295 return;
296
297 if (m_options.isVerbose)
298 std::cerr << "Received Nack with reason " << nack.getReason()
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400299 << " for Interest " << interest << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700300
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500301 uint64_t segNo = getSegmentFromPacket(interest);
Weiwei Liu245d7912016-07-28 00:04:25 -0700302
303 switch (nack.getReason()) {
Davide Pesavento958896e2017-01-19 00:52:04 -0500304 case lp::NackReason::DUPLICATE:
305 // ignore duplicates
Weiwei Liu245d7912016-07-28 00:04:25 -0700306 break;
Davide Pesavento958896e2017-01-19 00:52:04 -0500307 case lp::NackReason::CONGESTION:
308 // treated the same as timeout for now
309 enqueueForRetransmission(segNo);
Sichen Song40eae032022-05-01 16:33:00 -0700310 recordTimeout(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500311 schedulePackets();
312 break;
313 default:
Weiwei Liu245d7912016-07-28 00:04:25 -0700314 handleFail(segNo, "Could not retrieve data for " + interest.getName().toUri() +
315 ", reason: " + boost::lexical_cast<std::string>(nack.getReason()));
316 break;
Weiwei Liu245d7912016-07-28 00:04:25 -0700317 }
318}
319
320void
schneiderklausd8197df2019-03-16 11:31:40 -0700321PipelineInterestsAdaptive::handleLifetimeExpiration(const Interest& interest)
Weiwei Liu245d7912016-07-28 00:04:25 -0700322{
323 if (isStopping())
324 return;
325
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700326 m_nTimeouts++;
Sichen Song40eae032022-05-01 16:33:00 -0700327
328 uint64_t segNo = getSegmentFromPacket(interest);
329 enqueueForRetransmission(segNo);
330 recordTimeout(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500331 schedulePackets();
Weiwei Liu245d7912016-07-28 00:04:25 -0700332}
333
334void
Sichen Song40eae032022-05-01 16:33:00 -0700335PipelineInterestsAdaptive::recordTimeout(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700336{
Sichen Song40eae032022-05-01 16:33:00 -0700337 if (m_options.disableCwa || segNo > m_recPoint) {
338 // interests that are still outstanding during a timeout event
339 // should not trigger another window decrease later (bug #5202)
Weiwei Liu245d7912016-07-28 00:04:25 -0700340 m_recPoint = m_highInterest;
341
342 decreaseWindow();
343 m_rttEstimator.backoffRto();
schneiderklaus8ff3abd2019-03-12 22:15:12 -0700344 m_nLossDecr++;
Weiwei Liu245d7912016-07-28 00:04:25 -0700345
346 if (m_options.isVerbose) {
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000347 std::cerr << "Packet loss event, new cwnd = " << m_cwnd
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400348 << ", ssthresh = " << m_ssthresh << "\n";
Weiwei Liu245d7912016-07-28 00:04:25 -0700349 }
350 }
Davide Pesavento958896e2017-01-19 00:52:04 -0500351}
Weiwei Liu245d7912016-07-28 00:04:25 -0700352
Davide Pesavento958896e2017-01-19 00:52:04 -0500353void
schneiderklausd8197df2019-03-16 11:31:40 -0700354PipelineInterestsAdaptive::enqueueForRetransmission(uint64_t segNo)
Davide Pesavento958896e2017-01-19 00:52:04 -0500355{
356 BOOST_ASSERT(m_nInFlight > 0);
357 m_nInFlight--;
358 m_retxQueue.push(segNo);
359 m_segmentInfo.at(segNo).state = SegmentState::InRetxQueue;
Weiwei Liu245d7912016-07-28 00:04:25 -0700360}
361
362void
schneiderklausd8197df2019-03-16 11:31:40 -0700363PipelineInterestsAdaptive::handleFail(uint64_t segNo, const std::string& reason)
Weiwei Liu245d7912016-07-28 00:04:25 -0700364{
365 if (isStopping())
366 return;
367
368 // if the failed segment is definitely part of the content, raise a fatal error
369 if (m_hasFinalBlockId && segNo <= m_lastSegmentNo)
370 return onFailure(reason);
371
372 if (!m_hasFinalBlockId) {
373 m_segmentInfo.erase(segNo);
Davide Pesavento958896e2017-01-19 00:52:04 -0500374 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700375
376 if (m_segmentInfo.empty()) {
377 onFailure("Fetching terminated but no final segment number has been found");
378 }
379 else {
380 cancelInFlightSegmentsGreaterThan(segNo);
381 m_hasFailure = true;
382 m_failedSegNo = segNo;
383 m_failureReason = reason;
384 }
385 }
386}
387
388void
schneiderklausd8197df2019-03-16 11:31:40 -0700389PipelineInterestsAdaptive::cancelInFlightSegmentsGreaterThan(uint64_t segNo)
Weiwei Liu245d7912016-07-28 00:04:25 -0700390{
391 for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) {
392 // cancel fetching all segments that follow
Davide Pesavento958896e2017-01-19 00:52:04 -0500393 if (it->first > segNo) {
Weiwei Liu245d7912016-07-28 00:04:25 -0700394 it = m_segmentInfo.erase(it);
Davide Pesavento958896e2017-01-19 00:52:04 -0500395 m_nInFlight--;
Weiwei Liu245d7912016-07-28 00:04:25 -0700396 }
397 else {
398 ++it;
399 }
400 }
401}
402
403void
Davide Pesavento97a33b22019-10-17 22:10:47 -0400404PipelineInterestsAdaptive::printOptions() const
405{
406 PipelineInterests::printOptions();
407 std::cerr
408 << "\tInitial congestion window size = " << m_options.initCwnd << "\n"
409 << "\tInitial slow start threshold = " << m_options.initSsthresh << "\n"
410 << "\tAdditive increase step = " << m_options.aiStep << "\n"
411 << "\tMultiplicative decrease factor = " << m_options.mdCoef << "\n"
412 << "\tRTO check interval = " << m_options.rtoCheckInterval << "\n"
413 << "\tReact to congestion marks = " << (m_options.ignoreCongMarks ? "no" : "yes") << "\n"
414 << "\tConservative window adaptation = " << (m_options.disableCwa ? "no" : "yes") << "\n"
415 << "\tResetting window to " << (m_options.resetCwndToInit ?
416 "initial value" : "ssthresh") << " upon loss event\n";
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
Davide Pesaventob3570c62022-02-19 19:19:00 -0500459} // namespace ndn::chunks