Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 2 | /* |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 3 | * Copyright (c) 2016-2019, Regents of the University of California, |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 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 Weiwei Liu |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 24 | * @author Chavoosh Ghasemi |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 25 | * @author Klaus Schneider |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 28 | #include "tools/chunks/catchunks/pipeline-interests-aimd.hpp" |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 29 | #include "tools/chunks/catchunks/options.hpp" |
| 30 | |
| 31 | #include "pipeline-interests-fixture.hpp" |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace chunks { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
| 37 | using namespace ndn::tests; |
| 38 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 39 | class PipelineInterestAimdFixture : public PipelineInterestsFixture |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 42 | PipelineInterestAimdFixture() |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 43 | : opt(makePipelineOptions()) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 44 | , rttEstimator(makeRttEstimatorOptions()) |
| 45 | { |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 46 | createPipeline(); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | createPipeline() |
| 51 | { |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 52 | auto pline = make_unique<PipelineInterestsAimd>(face, rttEstimator, opt); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 53 | pipeline = pline.get(); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 54 | setPipeline(std::move(pline)); |
| 55 | } |
| 56 | |
| 57 | private: |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 58 | static PipelineInterestsAdaptive::Options |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 59 | makePipelineOptions() |
| 60 | { |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 61 | PipelineInterestsAdaptive::Options pipelineOptions; |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 62 | pipelineOptions.isQuiet = true; |
| 63 | pipelineOptions.isVerbose = false; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 64 | pipelineOptions.disableCwa = false; |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 65 | pipelineOptions.ignoreCongMarks = false; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 66 | pipelineOptions.resetCwndToInit = false; |
| 67 | pipelineOptions.initCwnd = 1.0; |
| 68 | pipelineOptions.aiStep = 1.0; |
| 69 | pipelineOptions.mdCoef = 0.5; |
| 70 | pipelineOptions.initSsthresh = std::numeric_limits<int>::max(); |
| 71 | return pipelineOptions; |
| 72 | } |
| 73 | |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame^] | 74 | static shared_ptr<RttEstimatorWithStats::Options> |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 75 | makeRttEstimatorOptions() |
| 76 | { |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame^] | 77 | auto rttOptions = make_shared<RttEstimatorWithStats::Options>(); |
| 78 | rttOptions->alpha = 0.125; |
| 79 | rttOptions->beta = 0.25; |
| 80 | rttOptions->k = 4; |
| 81 | rttOptions->initialRto = 1_s; |
| 82 | rttOptions->minRto = 200_ms; |
| 83 | rttOptions->maxRto = 4_s; |
| 84 | rttOptions->rtoBackoffMultiplier = 2; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 85 | return rttOptions; |
| 86 | } |
| 87 | |
| 88 | protected: |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 89 | PipelineInterestsAdaptive::Options opt; |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame^] | 90 | RttEstimatorWithStats rttEstimator; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 91 | PipelineInterestsAdaptive* pipeline; |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 92 | static constexpr double MARGIN = 0.001; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 95 | constexpr double PipelineInterestAimdFixture::MARGIN; |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 96 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 97 | BOOST_AUTO_TEST_SUITE(Chunks) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 98 | BOOST_FIXTURE_TEST_SUITE(TestPipelineInterestsAimd, PipelineInterestAimdFixture) |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 99 | |
| 100 | BOOST_AUTO_TEST_CASE(SlowStart) |
| 101 | { |
| 102 | nDataSegments = 4; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 103 | pipeline->m_ssthresh = 8.0; |
| 104 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 105 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 106 | double preCwnd = pipeline->m_cwnd; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 107 | run(name); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 108 | advanceClocks(io, time::nanoseconds(1)); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 109 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 110 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 111 | for (uint64_t i = 0; i < nDataSegments - 1; ++i) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 112 | face.receive(*makeDataWithSegment(i)); |
| 113 | advanceClocks(io, time::nanoseconds(1)); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 114 | BOOST_CHECK_CLOSE(pipeline->m_cwnd - preCwnd, 1, MARGIN); |
| 115 | preCwnd = pipeline->m_cwnd; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 116 | } |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 117 | |
| 118 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | BOOST_AUTO_TEST_CASE(CongestionAvoidance) |
| 122 | { |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 123 | nDataSegments = 7; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 124 | pipeline->m_ssthresh = 4.0; |
| 125 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 126 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 127 | double preCwnd = pipeline->m_cwnd; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 128 | run(name); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 129 | advanceClocks(io, time::nanoseconds(1)); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 131 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 132 | for (uint64_t i = 0; i < pipeline->m_ssthresh; ++i) { // slow start |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 133 | face.receive(*makeDataWithSegment(i)); |
| 134 | advanceClocks(io, time::nanoseconds(1)); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 135 | preCwnd = pipeline->m_cwnd; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 138 | BOOST_CHECK_CLOSE(preCwnd, 4.25, MARGIN); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 139 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 140 | for (uint64_t i = pipeline->m_ssthresh; i < nDataSegments - 1; ++i) { // congestion avoidance |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 141 | face.receive(*makeDataWithSegment(i)); |
| 142 | advanceClocks(io, time::nanoseconds(1)); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 143 | BOOST_CHECK_CLOSE(pipeline->m_cwnd - preCwnd, opt.aiStep / floor(pipeline->m_cwnd), MARGIN); |
| 144 | preCwnd = pipeline->m_cwnd; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 145 | } |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 146 | |
| 147 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_CASE(Timeout) |
| 151 | { |
| 152 | nDataSegments = 8; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 153 | pipeline->m_ssthresh = 4.0; |
| 154 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 155 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 156 | run(name); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 157 | advanceClocks(io, time::nanoseconds(1)); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 158 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 159 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 160 | // receive segment 0, 1, and 2 |
| 161 | for (uint64_t i = 0; i < 3; ++i) { |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 162 | face.receive(*makeDataWithSegment(i)); |
| 163 | advanceClocks(io, time::nanoseconds(1)); |
| 164 | } |
| 165 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 3); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 167 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 4, MARGIN); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 168 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 7); // request for segment 7 has been sent |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 169 | |
| 170 | advanceClocks(io, time::milliseconds(100)); |
| 171 | |
| 172 | // receive segment 4 |
| 173 | face.receive(*makeDataWithSegment(4)); |
| 174 | advanceClocks(io, time::nanoseconds(1)); |
| 175 | |
| 176 | // receive segment 5 |
| 177 | face.receive(*makeDataWithSegment(5)); |
| 178 | advanceClocks(io, time::nanoseconds(1)); |
| 179 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 5); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 181 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 4.5, MARGIN); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments); // all the segment requests have been sent |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 183 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 184 | BOOST_CHECK_EQUAL(pipeline->m_nTimeouts, 0); |
| 185 | BOOST_CHECK_EQUAL(pipeline->m_nLossDecr, 0); |
| 186 | BOOST_CHECK_EQUAL(pipeline->m_nMarkDecr, 0); |
| 187 | BOOST_CHECK_EQUAL(pipeline->m_nRetransmitted, 0); |
| 188 | BOOST_CHECK_EQUAL(pipeline->m_nSkippedRetx, 0); |
| 189 | BOOST_CHECK_EQUAL(pipeline->m_nCongMarks, 0); |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 190 | |
| 191 | // timeout segment 3 & 6 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 192 | advanceClocks(io, time::milliseconds(150)); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(pipeline->m_nTimeouts, 2); |
| 194 | BOOST_CHECK_EQUAL(pipeline->m_nRetransmitted, 1); |
| 195 | BOOST_CHECK_EQUAL(pipeline->m_nLossDecr, 1); |
| 196 | BOOST_CHECK_EQUAL(pipeline->m_nSkippedRetx, 0); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 197 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 5); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 199 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 2.25, MARGIN); // window size drop to 1/2 of previous size |
| 200 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 201 | |
| 202 | // receive segment 6, retransmit 3 |
| 203 | face.receive(*makeDataWithSegment(6)); |
| 204 | advanceClocks(io, time::nanoseconds(1)); |
| 205 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 6); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 207 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 2.75, MARGIN); // congestion avoidance |
| 208 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 0); |
| 209 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[3], 1); |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 210 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(pipeline->m_nTimeouts, 2); |
| 212 | BOOST_CHECK_EQUAL(pipeline->m_nRetransmitted, 2); |
| 213 | BOOST_CHECK_EQUAL(pipeline->m_nTimeouts, |
| 214 | pipeline->m_nRetransmitted + pipeline->m_nSkippedRetx); |
schneiderklaus | 8ff3abd | 2019-03-12 22:15:12 -0700 | [diff] [blame] | 215 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 218 | BOOST_AUTO_TEST_CASE(CongestionMarksWithCwa) |
| 219 | { |
| 220 | nDataSegments = 7; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 221 | pipeline->m_ssthresh = 4.0; |
| 222 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 223 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 224 | run(name); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 225 | advanceClocks(io, time::nanoseconds(1)); |
| 226 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 227 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 228 | // receive segments 0 to 4 |
| 229 | for (uint64_t i = 0; i < 5; ++i) { |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 230 | face.receive(*makeDataWithSegment(i)); |
| 231 | advanceClocks(io, time::nanoseconds(1)); |
| 232 | } |
| 233 | |
| 234 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 5); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 235 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 4.5, MARGIN); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 236 | |
| 237 | // receive segment 5 with congestion mark |
| 238 | face.receive(*makeDataWithSegmentAndCongMark(5)); |
| 239 | advanceClocks(io, time::nanoseconds(1)); |
| 240 | |
| 241 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 6); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 242 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 2.25, MARGIN); // window size drops to 1/2 of previous size |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments); // all interests have been sent |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 244 | |
| 245 | // receive the last segment with congestion mark |
| 246 | face.receive(*makeDataWithSegmentAndCongMark(nDataSegments - 1)); |
| 247 | advanceClocks(io, time::nanoseconds(1)); |
| 248 | |
| 249 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 250 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 2.25, MARGIN); // conservative window adaption (window size should not decrease) |
| 251 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 252 | |
| 253 | // make sure no interest is retransmitted for marked data packets |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 254 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[5], 0); |
| 255 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[nDataSegments - 1], 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 256 | |
| 257 | // check number of received marked data packets |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 258 | BOOST_CHECK_EQUAL(pipeline->m_nCongMarks, 2); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | BOOST_AUTO_TEST_CASE(CongestionMarksWithoutCwa) |
| 262 | { |
| 263 | opt.disableCwa = true; |
| 264 | createPipeline(); |
| 265 | |
| 266 | nDataSegments = 7; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 267 | pipeline->m_ssthresh = 4.0; |
| 268 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 269 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 270 | run(name); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 271 | advanceClocks(io, time::nanoseconds(1)); |
| 272 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 273 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 274 | // receive segments 0 to 4 |
| 275 | for (uint64_t i = 0; i < 5; ++i) { |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 276 | face.receive(*makeDataWithSegment(i)); |
| 277 | advanceClocks(io, time::nanoseconds(1)); |
| 278 | } |
| 279 | |
| 280 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 5); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 281 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 4.5, MARGIN); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 282 | |
| 283 | // receive segment 5 with congestion mark |
| 284 | face.receive(*makeDataWithSegmentAndCongMark(5)); |
| 285 | advanceClocks(io, time::nanoseconds(1)); |
| 286 | |
| 287 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 6); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 288 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 2.25, MARGIN); // window size drops to 1/2 of previous size |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments); // all interests have been sent |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 290 | |
| 291 | // receive the last segment with congestion mark |
| 292 | face.receive(*makeDataWithSegmentAndCongMark(nDataSegments - 1)); |
| 293 | advanceClocks(io, time::nanoseconds(1)); |
| 294 | |
| 295 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 296 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, PipelineInterestsAdaptive::MIN_SSTHRESH, |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 297 | MARGIN); // window size should decrease, as cwa is disabled |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 299 | |
| 300 | // make sure no interest is retransmitted for marked data packets |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 301 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[5], 0); |
| 302 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[nDataSegments - 1], 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 303 | |
| 304 | // check number of received marked data packets |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(pipeline->m_nCongMarks, 2); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | BOOST_AUTO_TEST_CASE(IgnoreCongestionMarks) |
| 309 | { |
| 310 | opt.ignoreCongMarks = true; |
| 311 | createPipeline(); |
| 312 | |
| 313 | nDataSegments = 7; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 314 | pipeline->m_ssthresh = 4.0; |
| 315 | BOOST_REQUIRE_CLOSE(pipeline->m_cwnd, 1, MARGIN); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 316 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 317 | run(name); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 318 | advanceClocks(io, time::nanoseconds(1)); |
| 319 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 320 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 321 | // receive segments 0 to 5 |
| 322 | for (uint64_t i = 0; i < 6; ++i) { |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 323 | face.receive(*makeDataWithSegment(i)); |
| 324 | advanceClocks(io, time::nanoseconds(1)); |
| 325 | } |
| 326 | |
| 327 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 6); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 328 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 4.75, MARGIN); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments); // all interests have been sent |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 330 | |
| 331 | // receive the last segment with congestion mark |
| 332 | face.receive(*makeDataWithSegmentAndCongMark(nDataSegments - 1)); |
| 333 | advanceClocks(io, time::nanoseconds(1)); |
| 334 | |
| 335 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 336 | BOOST_CHECK_CLOSE(pipeline->m_cwnd, 5.0, MARGIN); // window size increases |
| 337 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 338 | |
| 339 | // make sure no interest is retransmitted for marked data packet |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 340 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[nDataSegments - 1], 0); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 341 | |
| 342 | // check number of received marked data packets |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 343 | BOOST_CHECK_EQUAL(pipeline->m_nCongMarks, 1); |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 346 | BOOST_AUTO_TEST_CASE(Nack) |
| 347 | { |
| 348 | nDataSegments = 5; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 349 | pipeline->m_cwnd = 10.0; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 350 | run(name); |
| 351 | advanceClocks(io, time::nanoseconds(1)); |
| 352 | |
| 353 | face.receive(*makeDataWithSegment(0)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 354 | advanceClocks(io, time::nanoseconds(1)); |
| 355 | |
| 356 | face.receive(*makeDataWithSegment(1)); |
| 357 | advanceClocks(io, time::nanoseconds(1)); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 358 | |
| 359 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 360 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 10); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 361 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 362 | // receive a nack with NackReason::DUPLICATE for segment 1 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 363 | auto nack1 = makeNack(face.sentInterests[1], lp::NackReason::DUPLICATE); |
| 364 | face.receive(nack1); |
| 365 | advanceClocks(io, time::nanoseconds(1)); |
| 366 | |
| 367 | // nack1 is ignored |
| 368 | BOOST_CHECK_EQUAL(hasFailed, false); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 369 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 370 | BOOST_CHECK_EQUAL(pipeline->m_retxQueue.size(), 0); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 371 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 372 | // receive a nack with NackReason::CONGESTION for segment 2 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 373 | auto nack2 = makeNack(face.sentInterests[2], lp::NackReason::CONGESTION); |
| 374 | face.receive(nack2); |
| 375 | advanceClocks(io, time::nanoseconds(1)); |
| 376 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 377 | // segment 2 is retransmitted |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 378 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[2], 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 379 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 380 | // receive a nack with NackReason::NONE for segment 3 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 381 | auto nack3 = makeNack(face.sentInterests[3], lp::NackReason::NONE); |
| 382 | face.receive(nack3); |
| 383 | advanceClocks(io, time::nanoseconds(1)); |
| 384 | |
| 385 | // Other types of Nack will trigger a failure |
| 386 | BOOST_CHECK_EQUAL(hasFailed, true); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 387 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | BOOST_AUTO_TEST_CASE(FinalBlockIdNotSetAtBeginning) |
| 391 | { |
| 392 | nDataSegments = 4; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 393 | pipeline->m_cwnd = 4; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 394 | run(name); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 395 | advanceClocks(io, time::nanoseconds(1)); |
| 396 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 397 | // receive segment 0 without FinalBlockId |
| 398 | face.receive(*makeDataWithSegment(0, false)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 399 | advanceClocks(io, time::nanoseconds(1)); |
| 400 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 401 | // interests for segment 0 - 5 have been sent |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 402 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 6); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 1); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 404 | BOOST_CHECK_EQUAL(pipeline->m_hasFinalBlockId, false); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 405 | // pending interests: segment 1, 2, 3, 4, 5 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 406 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 5); |
| 407 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 408 | // receive segment 1 with FinalBlockId |
| 409 | face.receive(*makeDataWithSegment(1)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 410 | advanceClocks(io, time::nanoseconds(1)); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 411 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(pipeline->m_hasFinalBlockId, true); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 413 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 414 | // pending interests for segment 1, 4, 5 haven been removed |
| 415 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 2); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | BOOST_AUTO_TEST_CASE(FailureBeforeFinalBlockIdReceived) |
| 419 | { |
| 420 | // failed to retrieve segNo while the FinalBlockId has not yet been |
| 421 | // set, and later received a FinalBlockId >= segNo, i.e. segNo is |
| 422 | // part of the content. |
| 423 | |
| 424 | nDataSegments = 4; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 425 | pipeline->m_cwnd = 4; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 426 | run(name); |
| 427 | advanceClocks(io, time::nanoseconds(1)); |
| 428 | |
| 429 | // receive segment 0 without FinalBlockId |
| 430 | face.receive(*makeDataWithSegment(0, false)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 431 | advanceClocks(io, time::nanoseconds(1)); |
| 432 | |
| 433 | // receive segment 1 without FinalBlockId |
| 434 | face.receive(*makeDataWithSegment(1, false)); |
| 435 | advanceClocks(io, time::nanoseconds(1)); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 436 | |
| 437 | // interests for segment 0 - 7 have been sent |
| 438 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 8); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 439 | |
| 440 | // receive nack with NackReason::NONE for segment 3 |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 441 | auto nack = makeNack(face.sentInterests[3], lp::NackReason::NONE); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 442 | face.receive(nack); |
| 443 | advanceClocks(io, time::nanoseconds(1)); |
| 444 | |
| 445 | // error not triggered |
| 446 | // pending interests for segment > 3 haven been removed |
| 447 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 448 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 1); |
| 449 | |
| 450 | // receive segment 2 with FinalBlockId |
| 451 | face.receive(*makeDataWithSegment(2)); |
| 452 | advanceClocks(io, time::nanoseconds(1)); |
| 453 | |
| 454 | // error triggered since segment 3 is part of the content |
| 455 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 456 | } |
| 457 | |
| 458 | BOOST_AUTO_TEST_CASE(SpuriousFailureBeforeFinalBlockIdReceived) |
| 459 | { |
| 460 | // failed to retrieve segNo while the FinalBlockId has not yet been |
| 461 | // set, and later received a FinalBlockId < segNo, i.e. segNo is |
| 462 | // not part of the content, and it was actually a spurious failure |
| 463 | |
| 464 | nDataSegments = 4; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 465 | pipeline->m_cwnd = 4; |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 466 | run(name); |
| 467 | advanceClocks(io, time::nanoseconds(1)); |
| 468 | |
| 469 | // receive segment 0 without FinalBlockId |
| 470 | face.receive(*makeDataWithSegment(0, false)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 471 | advanceClocks(io, time::nanoseconds(1)); |
| 472 | |
| 473 | // receive segment 1 without FinalBlockId |
| 474 | face.receive(*makeDataWithSegment(1, false)); |
| 475 | advanceClocks(io, time::nanoseconds(1)); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 476 | |
| 477 | // interests for segment 0 - 7 have been sent |
| 478 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 8); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 479 | |
| 480 | // receive nack with NackReason::NONE for segment 4 |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 481 | auto nack = makeNack(face.sentInterests[4], lp::NackReason::NONE); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 482 | face.receive(nack); |
| 483 | advanceClocks(io, time::nanoseconds(1)); |
| 484 | |
| 485 | // error not triggered |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 486 | // pending interests for segment > 3 have been removed |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 487 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 488 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 2); |
| 489 | |
| 490 | // receive segment 2 with FinalBlockId |
| 491 | face.receive(*makeDataWithSegment(2)); |
| 492 | advanceClocks(io, time::nanoseconds(1)); |
| 493 | |
| 494 | // timeout segment 3 |
Davide Pesavento | 958896e | 2017-01-19 00:52:04 -0500 | [diff] [blame] | 495 | advanceClocks(io, time::seconds(1)); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 496 | |
| 497 | // segment 3 is retransmitted |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 498 | BOOST_CHECK_EQUAL(pipeline->m_retxCount[3], 1); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 499 | |
| 500 | // receive segment 3 |
| 501 | face.receive(*makeDataWithSegment(3)); |
| 502 | advanceClocks(io, time::nanoseconds(1)); |
| 503 | |
| 504 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 505 | } |
| 506 | |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 507 | BOOST_AUTO_TEST_CASE(SegmentInfoMaintenance) |
| 508 | { |
| 509 | // test that m_segmentInfo is properly maintained when |
| 510 | // a segment is received after two consecutive timeouts |
| 511 | |
| 512 | nDataSegments = 3; |
| 513 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 514 | run(name); |
| 515 | advanceClocks(io, time::nanoseconds(1)); |
| 516 | |
| 517 | // receive segment 0 |
| 518 | face.receive(*makeDataWithSegment(0)); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 519 | advanceClocks(io, time::nanoseconds(1)); |
| 520 | |
| 521 | // receive segment 1 |
| 522 | face.receive(*makeDataWithSegment(1)); |
| 523 | advanceClocks(io, time::nanoseconds(1)); |
| 524 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 525 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 3); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 526 | |
| 527 | // check if segment 2's state is FirstTimeSent |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 528 | auto it = pipeline->m_segmentInfo.find(2); |
| 529 | BOOST_REQUIRE(it != pipeline->m_segmentInfo.end()); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 530 | BOOST_CHECK(it->second.state == SegmentState::FirstTimeSent); |
| 531 | |
| 532 | // timeout segment 2 twice |
| 533 | advanceClocks(io, time::milliseconds(400), 3); |
| 534 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 535 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 5); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 536 | |
| 537 | // check if segment 2's state is Retransmitted |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 538 | it = pipeline->m_segmentInfo.find(2); |
| 539 | BOOST_REQUIRE(it != pipeline->m_segmentInfo.end()); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 540 | BOOST_CHECK(it->second.state == SegmentState::Retransmitted); |
| 541 | |
| 542 | // check if segment 2 was retransmitted twice |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 543 | BOOST_CHECK_EQUAL(pipeline->m_retxCount.at(2), 2); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 544 | |
| 545 | // receive segment 2 the first time |
| 546 | face.receive(*makeDataWithSegment(2)); |
| 547 | advanceClocks(io, time::nanoseconds(1)); |
| 548 | |
| 549 | // check if segment 2 was erased from m_segmentInfo |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 550 | it = pipeline->m_segmentInfo.find(2); |
| 551 | BOOST_CHECK(it == pipeline->m_segmentInfo.end()); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 552 | |
| 553 | auto prevRtt = rttEstimator.getAvgRtt(); |
| 554 | auto prevRto = rttEstimator.getEstimatedRto(); |
| 555 | |
| 556 | // receive segment 2 the second time |
| 557 | face.receive(*makeDataWithSegment(2)); |
| 558 | advanceClocks(io, time::nanoseconds(1)); |
| 559 | |
| 560 | // nothing changed |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 561 | it = pipeline->m_segmentInfo.find(2); |
| 562 | BOOST_CHECK(it == pipeline->m_segmentInfo.end()); |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 563 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 5); |
Ryan Wickman | 2c9933c | 2018-06-12 11:51:51 -0500 | [diff] [blame] | 564 | BOOST_CHECK_EQUAL(rttEstimator.getAvgRtt(), prevRtt); |
| 565 | BOOST_CHECK_EQUAL(rttEstimator.getEstimatedRto(), prevRto); |
| 566 | } |
| 567 | |
Chavoosh Ghasemi | 75309ae | 2018-03-26 14:46:24 -0400 | [diff] [blame] | 568 | BOOST_AUTO_TEST_CASE(PrintSummaryWithNoRttMeasurements) |
| 569 | { |
| 570 | // test the console ouptut when no RTT measurement is available, |
| 571 | // to make sure a proper message will be printed out |
| 572 | |
| 573 | std::stringstream ss; |
| 574 | |
| 575 | // change the underlying buffer and save the old buffer |
| 576 | auto oldBuf = std::cerr.rdbuf(ss.rdbuf()); |
| 577 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 578 | pipeline->printSummary(); |
Chavoosh Ghasemi | 75309ae | 2018-03-26 14:46:24 -0400 | [diff] [blame] | 579 | std::string line; |
| 580 | |
| 581 | bool found = false; |
| 582 | while (std::getline(ss, line)) { |
| 583 | if (line == "RTT stats unavailable") { |
| 584 | found = true; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | BOOST_CHECK(found); |
| 589 | std::cerr.rdbuf(oldBuf); // reset |
| 590 | } |
| 591 | |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 592 | BOOST_AUTO_TEST_CASE(StopsWhenFileSizeLessThanChunkSize) |
| 593 | { |
| 594 | // test to see if the program doesn't hang, |
| 595 | // when transfer is complete, for files less than the chunk size |
| 596 | // (i.e. when only one segment is sent/received) |
| 597 | |
| 598 | createPipeline(); |
| 599 | nDataSegments = 1; |
| 600 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 601 | run(name); |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 602 | advanceClocks(io, time::nanoseconds(1)); |
| 603 | |
Chavoosh Ghasemi | 5cb6701 | 2019-02-15 09:56:57 -0800 | [diff] [blame] | 604 | face.receive(*makeDataWithSegment(0)); |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 605 | advanceClocks(io, time::nanoseconds(1)); |
| 606 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 607 | BOOST_CHECK_EQUAL(pipeline->m_hasFinalBlockId, true); |
| 608 | BOOST_CHECK_EQUAL(pipeline->m_segmentInfo.size(), 0); |
Ryan Wickman | 034f30f | 2018-06-06 11:11:11 -0500 | [diff] [blame] | 609 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
| 610 | } |
| 611 | |
| 612 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 613 | BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterestsAimd |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 614 | BOOST_AUTO_TEST_SUITE_END() // Chunks |
| 615 | |
| 616 | } // namespace tests |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 617 | } // namespace chunks |
| 618 | } // namespace ndn |