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