blob: d7f17d64625acaf6061059bf30b07e86ade4a9c2 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe9c69852017-11-04 18:08:37 -04002/*
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -08003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesaventobf1c0692017-01-15 19:15:09 -05004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Andrea Tosatto672b9a72016-01-05 16:18:20 +01006 *
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 Ghasemi5cb67012019-02-15 09:56:57 -080024 * @author Chavoosh Ghasemi
Andrea Tosatto672b9a72016-01-05 16:18:20 +010025 */
26
schneiderklausd8197df2019-03-16 11:31:40 -070027#include "tools/chunks/catchunks/pipeline-interests-fixed.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010028#include "tools/chunks/catchunks/data-fetcher.hpp"
29
Weiwei Liue4765012016-06-01 00:10:29 -070030#include "pipeline-interests-fixture.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010031
32namespace ndn {
33namespace chunks {
34namespace tests {
35
schneiderklausd8197df2019-03-16 11:31:40 -070036class PipelineInterestFixedFixture : public PipelineInterestsFixture
Andrea Tosatto672b9a72016-01-05 16:18:20 +010037{
38public:
schneiderklausd8197df2019-03-16 11:31:40 -070039 PipelineInterestFixedFixture()
Davide Pesaventof6991e12018-01-08 20:58:50 -050040 : opt(makeOptions())
Andrea Tosatto672b9a72016-01-05 16:18:20 +010041 {
schneiderklausd8197df2019-03-16 11:31:40 -070042 createPipeline();
43 }
44
45 void
46 createPipeline()
47 {
48 auto pline = make_unique<PipelineInterestsFixed>(face, opt);
49 pipeline = pline.get();
50 setPipeline(std::move(pline));
Andrea Tosatto672b9a72016-01-05 16:18:20 +010051 }
Davide Pesaventoe9c69852017-11-04 18:08:37 -040052
Andrea Tosatto672b9a72016-01-05 16:18:20 +010053private:
schneiderklausd8197df2019-03-16 11:31:40 -070054 static PipelineInterestsFixed::Options
Andrea Tosatto672b9a72016-01-05 16:18:20 +010055 makeOptions()
56 {
schneiderklausd8197df2019-03-16 11:31:40 -070057 PipelineInterestsFixed::Options options;
Davide Pesaventof6991e12018-01-08 20:58:50 -050058 options.isQuiet = true;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010059 options.isVerbose = false;
60 options.interestLifetime = time::seconds(1);
61 options.maxRetriesOnTimeoutOrNack = 3;
62 options.maxPipelineSize = 5;
63 return options;
64 }
Davide Pesaventof6991e12018-01-08 20:58:50 -050065
66protected:
schneiderklausd8197df2019-03-16 11:31:40 -070067 PipelineInterestsFixed::Options opt;
68 PipelineInterestsFixed* pipeline;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010069};
70
71BOOST_AUTO_TEST_SUITE(Chunks)
schneiderklausd8197df2019-03-16 11:31:40 -070072BOOST_FIXTURE_TEST_SUITE(TestPipelineInterestsFixed, PipelineInterestFixedFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010073
Davide Pesaventoe9c69852017-11-04 18:08:37 -040074BOOST_AUTO_TEST_CASE(FullPipeline)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010075{
76 nDataSegments = 13;
77 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
78
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080079 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010080 advanceClocks(io, time::nanoseconds(1), 1);
81 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
82
83 for (uint64_t i = 0; i < nDataSegments - 1; ++i) {
84 face.receive(*makeDataWithSegment(i));
85 advanceClocks(io, time::nanoseconds(1), 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080086 BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010087
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080088 if (i < nDataSegments - opt.maxPipelineSize) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010089 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize + i + 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080090 // check if the interest for the segment i is well formed
Davide Pesaventobf1c0692017-01-15 19:15:09 -050091 const auto& sentInterest = face.sentInterests[i];
Andrea Tosatto672b9a72016-01-05 16:18:20 +010092 BOOST_CHECK_EQUAL(sentInterest.getExclude().size(), 0);
93 BOOST_CHECK_EQUAL(sentInterest.getMaxSuffixComponents(), 1);
94 BOOST_CHECK_EQUAL(sentInterest.getMustBeFresh(), opt.mustBeFresh);
95 BOOST_CHECK_EQUAL(Name(name).isPrefixOf(sentInterest.getName()), true);
Davide Pesaventobf1c0692017-01-15 19:15:09 -050096 BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010097 }
98 else {
99 // all the interests have been sent for all the segments
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800100 BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100101 }
102 }
103
104 BOOST_CHECK_EQUAL(hasFailed, false);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800105
106 advanceClocks(io, ndn::DEFAULT_INTEREST_LIFETIME, opt.maxRetriesOnTimeoutOrNack + 1);
107 BOOST_CHECK_EQUAL(hasFailed, true);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100108}
109
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400110BOOST_AUTO_TEST_CASE(TimeoutAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100111{
112 nDataSegments = 13;
113 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
114
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800115 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100116 advanceClocks(io, time::nanoseconds(1), 1);
117 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
118
119 for (int i = 0; i < opt.maxRetriesOnTimeoutOrNack; ++i) {
120 advanceClocks(io, opt.interestLifetime, 1);
121 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i + 2));
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800122 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 0);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100123
124 // A single retry for every pipeline element
125 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500126 const auto& interest = face.sentInterests[(opt.maxPipelineSize * (i + 1)) + j];
127 BOOST_CHECK_EQUAL(static_cast<size_t>(getSegmentFromPacket(interest)), j);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100128 }
129 }
130
131 advanceClocks(io, opt.interestLifetime, 1);
132 BOOST_CHECK_EQUAL(hasFailed, true);
133}
134
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400135BOOST_AUTO_TEST_CASE(TimeoutAfterFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100136{
137 // the FinalBlockId is sent with the first segment, after the first segment failure the pipeline
138 // should fail
139
140 nDataSegments = 18;
141 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
142
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800143 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100144 advanceClocks(io, time::nanoseconds(1), 1);
145 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
146
147 // send a single segment for each pipeline element but not the first element
148 advanceClocks(io, opt.interestLifetime, 1);
149 for (uint64_t i = 1; i < opt.maxPipelineSize; ++i) {
150 face.receive(*makeDataWithSegment(i));
151 advanceClocks(io, time::nanoseconds(1), 1);
152 }
153
154 // send a single data packet for each pipeline element
155 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800156 for (uint64_t i = 0; i < opt.maxPipelineSize; ++i) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100157 face.receive(*makeDataWithSegment(opt.maxPipelineSize + i));
158 advanceClocks(io, time::nanoseconds(1), 1);
159 }
160 advanceClocks(io, opt.interestLifetime, 1);
161
162 size_t interestAfterFailure = face.sentInterests.size();
163
164 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
165 BOOST_CHECK_EQUAL(hasFailed, true);
166
167 // these new segments should not generate new interests
168 advanceClocks(io, opt.interestLifetime, 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800169 for (uint64_t i = 0; i < opt.maxPipelineSize; ++i) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100170 face.receive(*makeDataWithSegment(opt.maxPipelineSize * 2 + i - 1));
171 advanceClocks(io, time::nanoseconds(1), 1);
172 }
173
174 // no more interests after a failure
175 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
176 BOOST_CHECK_EQUAL(interestAfterFailure, face.sentInterests.size());
177 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
178}
179
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400180BOOST_AUTO_TEST_CASE(TimeoutBeforeFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100181{
182 // the FinalBlockId is sent only with the last segment, all segments are sent except for the
183 // second one (segment #1); all segments are received correctly until the FinalBlockId is received
184
185 nDataSegments = 22;
186 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
187
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800188 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100189 advanceClocks(io, time::nanoseconds(1), 1);
190 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
191
192 advanceClocks(io, opt.interestLifetime, 1);
193 for (uint64_t i = 2; i < opt.maxPipelineSize; ++i) {
194 face.receive(*makeDataWithSegment(i, false));
195 advanceClocks(io, time::nanoseconds(1), 1);
196
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500197 const auto& lastInterest = face.sentInterests.back();
198 BOOST_CHECK_EQUAL(getSegmentFromPacket(lastInterest), opt.maxPipelineSize + i - 2);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100199 }
200 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * 3 - 2);
201
202 // nack for the first pipeline element (segment #0)
203 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
204 nack->setReason(lp::NackReason::DUPLICATE);
205 face.receive(*nack);
206
207 // all the pipeline elements are two retries near the timeout error, but not the
208 // second (segment #1) that is only one retry near the timeout
209 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
210 BOOST_CHECK_EQUAL(hasFailed, false);
211
212 // data for the first pipeline element (segment #0)
213 face.receive(*makeDataWithSegment(0, false));
214 BOOST_CHECK_EQUAL(hasFailed, false);
215
216 // data for all the pipeline element, but not the second (segment #1)
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800217 for (uint64_t i = opt.maxPipelineSize; i < nDataSegments; ++i) {
218 if (i == nDataSegments - 1) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100219 face.receive(*makeDataWithSegment(i, true));
220 }
221 else {
222 face.receive(*makeDataWithSegment(i, false));
223 }
224 advanceClocks(io, time::nanoseconds(1), 1);
225 }
226 // timeout for the second pipeline element (segment #1), this should trigger an error
227 advanceClocks(io, opt.interestLifetime, 1);
228
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400229 BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100230 BOOST_CHECK_EQUAL(hasFailed, true);
231}
232
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400233BOOST_AUTO_TEST_CASE(SegmentReceivedAfterTimeout)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100234{
235 // the FinalBlockId is never sent, all the pipeline elements with a segment number greater than
236 // segment #0 will fail, after this failure also segment #0 fail and this should trigger an error
237
238 nDataSegments = 22;
239 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
240
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800241 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100242 advanceClocks(io, time::nanoseconds(1), 1);
243 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
244
245 advanceClocks(io, opt.interestLifetime, 1);
246
247 // nack for the first pipeline element (segment #0)
248 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
249 nack->setReason(lp::NackReason::DUPLICATE);
250 face.receive(*nack);
251 BOOST_CHECK_EQUAL(hasFailed, false);
252
253 // timeout for all the pipeline elements, but not the first (segment #0)
254 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
255 BOOST_CHECK_EQUAL(hasFailed, false);
256
257 // data for the first pipeline element (segment #0), this should trigger an error because the
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800258 // other pipeline elements failed
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100259 face.receive(*makeDataWithSegment(0, false));
260 advanceClocks(io, time::nanoseconds(1), 1);
261
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800262 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100263 BOOST_CHECK_EQUAL(hasFailed, true);
264}
265
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400266BOOST_AUTO_TEST_CASE(CongestionAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100267{
268 nDataSegments = 13;
269 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
270
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800271 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100272 advanceClocks(io, time::nanoseconds(1), 1);
273 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
274
275 // send nack for all the pipeline elements first interest
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800276 for (size_t i = 0; i < opt.maxPipelineSize; i++) {
277 auto nack = make_shared<lp::Nack>(face.sentInterests[i]);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100278 nack->setReason(lp::NackReason::CONGESTION);
279 face.receive(*nack);
280 advanceClocks(io, time::nanoseconds(1), 1);
281 }
282
283 // send nack for all the pipeline elements interests after the first
284 for (int i = 1; i <= opt.maxRetriesOnTimeoutOrNack; ++i) {
285 time::milliseconds backoffTime(static_cast<uint64_t>(std::pow(2, i)));
286 if (backoffTime > DataFetcher::MAX_CONGESTION_BACKOFF_TIME)
287 backoffTime = DataFetcher::MAX_CONGESTION_BACKOFF_TIME;
288
289 advanceClocks(io, backoffTime, 1);
290 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i +1));
291
292 // A single retry for every pipeline element
293 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500294 const auto& interest = face.sentInterests[(opt.maxPipelineSize * i) + j];
295 BOOST_CHECK_LT(static_cast<size_t>(getSegmentFromPacket(interest)), opt.maxPipelineSize);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100296 }
297
298 for (size_t j = 0; j < opt.maxPipelineSize; j++) {
299 auto nack = make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]);
300 nack->setReason(lp::NackReason::CONGESTION);
301 face.receive(*nack);
302 advanceClocks(io, time::nanoseconds(1), 1);
303 }
304 }
305
306 BOOST_CHECK_EQUAL(hasFailed, true);
307}
308
309BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterests
310BOOST_AUTO_TEST_SUITE_END() // Chunks
311
312} // namespace tests
313} // namespace chunks
314} // namespace ndn