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