Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [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 | /* |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2016-2018, Regents of the University of California, |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [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 Andrea Tosatto |
| 24 | */ |
| 25 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 26 | #include "tools/chunks/catchunks/pipeline-interests-fixed-window.hpp" |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 27 | #include "tools/chunks/catchunks/data-fetcher.hpp" |
| 28 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 29 | #include "pipeline-interests-fixture.hpp" |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
| 32 | namespace chunks { |
| 33 | namespace tests { |
| 34 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 35 | class PipelineInterestFixedWindowFixture : public PipelineInterestsFixture |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 36 | { |
| 37 | public: |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 38 | PipelineInterestFixedWindowFixture() |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame^] | 39 | : opt(makeOptions()) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 40 | { |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 41 | setPipeline(make_unique<PipelineInterestsFixedWindow>(face, PipelineInterestsFixedWindow::Options(opt))); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 42 | } |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 43 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 44 | private: |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame^] | 45 | static PipelineInterestsFixedWindow::Options |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 46 | makeOptions() |
| 47 | { |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame^] | 48 | PipelineInterestsFixedWindow::Options options; |
| 49 | options.isQuiet = true; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 50 | options.isVerbose = false; |
| 51 | options.interestLifetime = time::seconds(1); |
| 52 | options.maxRetriesOnTimeoutOrNack = 3; |
| 53 | options.maxPipelineSize = 5; |
| 54 | return options; |
| 55 | } |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame^] | 56 | |
| 57 | protected: |
| 58 | PipelineInterestsFixedWindow::Options opt; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | BOOST_AUTO_TEST_SUITE(Chunks) |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 62 | BOOST_FIXTURE_TEST_SUITE(TestPipelineInterestsFixedWindow, PipelineInterestFixedWindowFixture) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 63 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 64 | BOOST_AUTO_TEST_CASE(FewerSegmentsThanPipelineCapacity) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 65 | { |
| 66 | nDataSegments = 3; |
| 67 | BOOST_ASSERT(nDataSegments <= opt.maxPipelineSize); |
| 68 | |
| 69 | runWithData(*makeDataWithSegment(0)); |
| 70 | advanceClocks(io, time::nanoseconds(1), 1); |
| 71 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), nDataSegments - 1); |
| 72 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 73 | for (uint64_t i = 1; i < nDataSegments - 1; ++i) { |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 74 | face.receive(*makeDataWithSegment(i)); |
| 75 | advanceClocks(io, time::nanoseconds(1), 1); |
| 76 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 1); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 78 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), nDataSegments - 1); |
| 79 | // check if the interest for the segment i+1 is well formed |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 80 | const auto& sentInterest = face.sentInterests[i]; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(sentInterest.getExclude().size(), 0); |
| 82 | BOOST_CHECK_EQUAL(sentInterest.getMaxSuffixComponents(), 1); |
| 83 | BOOST_CHECK_EQUAL(sentInterest.getMustBeFresh(), opt.mustBeFresh); |
| 84 | BOOST_CHECK_EQUAL(Name(name).isPrefixOf(sentInterest.getName()), true); |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 85 | BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i + 1); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 89 | |
| 90 | advanceClocks(io, ndn::DEFAULT_INTEREST_LIFETIME, opt.maxRetriesOnTimeoutOrNack + 1); |
| 91 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 92 | } |
| 93 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 94 | BOOST_AUTO_TEST_CASE(FullPipeline) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 95 | { |
| 96 | nDataSegments = 13; |
| 97 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 98 | |
| 99 | runWithData(*makeDataWithSegment(nDataSegments - 1)); |
| 100 | advanceClocks(io, time::nanoseconds(1), 1); |
| 101 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 102 | |
| 103 | for (uint64_t i = 0; i < nDataSegments - 1; ++i) { |
| 104 | face.receive(*makeDataWithSegment(i)); |
| 105 | advanceClocks(io, time::nanoseconds(1), 1); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 106 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 2); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 107 | |
| 108 | if (i < nDataSegments - opt.maxPipelineSize - 1) { |
| 109 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize + i + 1); |
| 110 | // check if the interest for the segment i+1 is well formed |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 111 | const auto& sentInterest = face.sentInterests[i]; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 112 | BOOST_CHECK_EQUAL(sentInterest.getExclude().size(), 0); |
| 113 | BOOST_CHECK_EQUAL(sentInterest.getMaxSuffixComponents(), 1); |
| 114 | BOOST_CHECK_EQUAL(sentInterest.getMustBeFresh(), opt.mustBeFresh); |
| 115 | BOOST_CHECK_EQUAL(Name(name).isPrefixOf(sentInterest.getName()), true); |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 117 | } |
| 118 | else { |
| 119 | // all the interests have been sent for all the segments |
| 120 | BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments - 1); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 125 | } |
| 126 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(TimeoutAllSegments) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 128 | { |
| 129 | nDataSegments = 13; |
| 130 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 131 | |
| 132 | runWithData(*makeDataWithSegment(nDataSegments - 1)); |
| 133 | advanceClocks(io, time::nanoseconds(1), 1); |
| 134 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 135 | |
| 136 | for (int i = 0; i < opt.maxRetriesOnTimeoutOrNack; ++i) { |
| 137 | advanceClocks(io, opt.interestLifetime, 1); |
| 138 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i + 2)); |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 1); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 140 | |
| 141 | // A single retry for every pipeline element |
| 142 | for (size_t j = 0; j < opt.maxPipelineSize; ++j) { |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 143 | const auto& interest = face.sentInterests[(opt.maxPipelineSize * (i + 1)) + j]; |
| 144 | BOOST_CHECK_EQUAL(static_cast<size_t>(getSegmentFromPacket(interest)), j); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | advanceClocks(io, opt.interestLifetime, 1); |
| 149 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 150 | } |
| 151 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 152 | BOOST_AUTO_TEST_CASE(TimeoutAfterFinalBlockIdReceived) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 153 | { |
| 154 | // the FinalBlockId is sent with the first segment, after the first segment failure the pipeline |
| 155 | // should fail |
| 156 | |
| 157 | nDataSegments = 18; |
| 158 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 159 | |
| 160 | runWithData(*makeDataWithSegment(nDataSegments - 1)); |
| 161 | advanceClocks(io, time::nanoseconds(1), 1); |
| 162 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 163 | |
| 164 | // send a single segment for each pipeline element but not the first element |
| 165 | advanceClocks(io, opt.interestLifetime, 1); |
| 166 | for (uint64_t i = 1; i < opt.maxPipelineSize; ++i) { |
| 167 | face.receive(*makeDataWithSegment(i)); |
| 168 | advanceClocks(io, time::nanoseconds(1), 1); |
| 169 | } |
| 170 | |
| 171 | // send a single data packet for each pipeline element |
| 172 | advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1); |
| 173 | for (uint64_t i = 0; i < opt.maxPipelineSize - 1; ++i) { |
| 174 | face.receive(*makeDataWithSegment(opt.maxPipelineSize + i)); |
| 175 | advanceClocks(io, time::nanoseconds(1), 1); |
| 176 | } |
| 177 | advanceClocks(io, opt.interestLifetime, 1); |
| 178 | |
| 179 | size_t interestAfterFailure = face.sentInterests.size(); |
| 180 | |
| 181 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
| 182 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 183 | |
| 184 | // these new segments should not generate new interests |
| 185 | advanceClocks(io, opt.interestLifetime, 1); |
| 186 | for (uint64_t i = 0; i < opt.maxPipelineSize - 1; ++i) { |
| 187 | face.receive(*makeDataWithSegment(opt.maxPipelineSize * 2 + i - 1)); |
| 188 | advanceClocks(io, time::nanoseconds(1), 1); |
| 189 | } |
| 190 | |
| 191 | // no more interests after a failure |
| 192 | advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack); |
| 193 | BOOST_CHECK_EQUAL(interestAfterFailure, face.sentInterests.size()); |
| 194 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
| 195 | } |
| 196 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(TimeoutBeforeFinalBlockIdReceived) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 198 | { |
| 199 | // the FinalBlockId is sent only with the last segment, all segments are sent except for the |
| 200 | // second one (segment #1); all segments are received correctly until the FinalBlockId is received |
| 201 | |
| 202 | nDataSegments = 22; |
| 203 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 204 | |
| 205 | runWithData(*makeDataWithSegment(nDataSegments - 1, false)); |
| 206 | advanceClocks(io, time::nanoseconds(1), 1); |
| 207 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 208 | |
| 209 | advanceClocks(io, opt.interestLifetime, 1); |
| 210 | for (uint64_t i = 2; i < opt.maxPipelineSize; ++i) { |
| 211 | face.receive(*makeDataWithSegment(i, false)); |
| 212 | advanceClocks(io, time::nanoseconds(1), 1); |
| 213 | |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 214 | const auto& lastInterest = face.sentInterests.back(); |
| 215 | BOOST_CHECK_EQUAL(getSegmentFromPacket(lastInterest), opt.maxPipelineSize + i - 2); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 216 | } |
| 217 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * 3 - 2); |
| 218 | |
| 219 | // nack for the first pipeline element (segment #0) |
| 220 | auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]); |
| 221 | nack->setReason(lp::NackReason::DUPLICATE); |
| 222 | face.receive(*nack); |
| 223 | |
| 224 | // all the pipeline elements are two retries near the timeout error, but not the |
| 225 | // second (segment #1) that is only one retry near the timeout |
| 226 | advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1); |
| 227 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 228 | |
| 229 | // data for the first pipeline element (segment #0) |
| 230 | face.receive(*makeDataWithSegment(0, false)); |
| 231 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 232 | |
| 233 | // data for all the pipeline element, but not the second (segment #1) |
| 234 | for (uint64_t i = opt.maxPipelineSize; i < nDataSegments - 1; ++i) { |
| 235 | if (i == nDataSegments - 2) { |
| 236 | face.receive(*makeDataWithSegment(i, true)); |
| 237 | } |
| 238 | else { |
| 239 | face.receive(*makeDataWithSegment(i, false)); |
| 240 | } |
| 241 | advanceClocks(io, time::nanoseconds(1), 1); |
| 242 | } |
| 243 | // timeout for the second pipeline element (segment #1), this should trigger an error |
| 244 | advanceClocks(io, opt.interestLifetime, 1); |
| 245 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 246 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 248 | } |
| 249 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 250 | BOOST_AUTO_TEST_CASE(SegmentReceivedAfterTimeout) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 251 | { |
| 252 | // the FinalBlockId is never sent, all the pipeline elements with a segment number greater than |
| 253 | // segment #0 will fail, after this failure also segment #0 fail and this should trigger an error |
| 254 | |
| 255 | nDataSegments = 22; |
| 256 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 257 | |
| 258 | runWithData(*makeDataWithSegment(nDataSegments - 1, false)); |
| 259 | advanceClocks(io, time::nanoseconds(1), 1); |
| 260 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 261 | |
| 262 | advanceClocks(io, opt.interestLifetime, 1); |
| 263 | |
| 264 | // nack for the first pipeline element (segment #0) |
| 265 | auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]); |
| 266 | nack->setReason(lp::NackReason::DUPLICATE); |
| 267 | face.receive(*nack); |
| 268 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 269 | |
| 270 | // timeout for all the pipeline elements, but not the first (segment #0) |
| 271 | advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack); |
| 272 | BOOST_CHECK_EQUAL(hasFailed, false); |
| 273 | |
| 274 | // data for the first pipeline element (segment #0), this should trigger an error because the |
| 275 | // others pipeline elements failed |
| 276 | face.receive(*makeDataWithSegment(0, false)); |
| 277 | advanceClocks(io, time::nanoseconds(1), 1); |
| 278 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 280 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 281 | } |
| 282 | |
Davide Pesavento | e9c6985 | 2017-11-04 18:08:37 -0400 | [diff] [blame] | 283 | BOOST_AUTO_TEST_CASE(CongestionAllSegments) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 284 | { |
| 285 | nDataSegments = 13; |
| 286 | BOOST_ASSERT(nDataSegments > opt.maxPipelineSize); |
| 287 | |
| 288 | runWithData(*makeDataWithSegment(nDataSegments - 1)); |
| 289 | advanceClocks(io, time::nanoseconds(1), 1); |
| 290 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize); |
| 291 | |
| 292 | // send nack for all the pipeline elements first interest |
| 293 | for (size_t j = 0; j < opt.maxPipelineSize; j++) { |
| 294 | auto nack = make_shared<lp::Nack>(face.sentInterests[j]); |
| 295 | nack->setReason(lp::NackReason::CONGESTION); |
| 296 | face.receive(*nack); |
| 297 | advanceClocks(io, time::nanoseconds(1), 1); |
| 298 | } |
| 299 | |
| 300 | // send nack for all the pipeline elements interests after the first |
| 301 | for (int i = 1; i <= opt.maxRetriesOnTimeoutOrNack; ++i) { |
| 302 | time::milliseconds backoffTime(static_cast<uint64_t>(std::pow(2, i))); |
| 303 | if (backoffTime > DataFetcher::MAX_CONGESTION_BACKOFF_TIME) |
| 304 | backoffTime = DataFetcher::MAX_CONGESTION_BACKOFF_TIME; |
| 305 | |
| 306 | advanceClocks(io, backoffTime, 1); |
| 307 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i +1)); |
| 308 | |
| 309 | // A single retry for every pipeline element |
| 310 | for (size_t j = 0; j < opt.maxPipelineSize; ++j) { |
Davide Pesavento | bf1c069 | 2017-01-15 19:15:09 -0500 | [diff] [blame] | 311 | const auto& interest = face.sentInterests[(opt.maxPipelineSize * i) + j]; |
| 312 | BOOST_CHECK_LT(static_cast<size_t>(getSegmentFromPacket(interest)), opt.maxPipelineSize); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | for (size_t j = 0; j < opt.maxPipelineSize; j++) { |
| 316 | auto nack = make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]); |
| 317 | nack->setReason(lp::NackReason::CONGESTION); |
| 318 | face.receive(*nack); |
| 319 | advanceClocks(io, time::nanoseconds(1), 1); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | BOOST_CHECK_EQUAL(hasFailed, true); |
| 324 | } |
| 325 | |
| 326 | BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterests |
| 327 | BOOST_AUTO_TEST_SUITE_END() // Chunks |
| 328 | |
| 329 | } // namespace tests |
| 330 | } // namespace chunks |
| 331 | } // namespace ndn |