blob: e75b4a2de435183cc3f36f76a6e175e1f51fea83 [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
Weiwei Liue4765012016-06-01 00:10:29 -070027#include "tools/chunks/catchunks/pipeline-interests-fixed-window.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
Weiwei Liue4765012016-06-01 00:10:29 -070036class PipelineInterestFixedWindowFixture : public PipelineInterestsFixture
Andrea Tosatto672b9a72016-01-05 16:18:20 +010037{
38public:
Weiwei Liue4765012016-06-01 00:10:29 -070039 PipelineInterestFixedWindowFixture()
Davide Pesaventof6991e12018-01-08 20:58:50 -050040 : opt(makeOptions())
Andrea Tosatto672b9a72016-01-05 16:18:20 +010041 {
Weiwei Liue4765012016-06-01 00:10:29 -070042 setPipeline(make_unique<PipelineInterestsFixedWindow>(face, PipelineInterestsFixedWindow::Options(opt)));
Andrea Tosatto672b9a72016-01-05 16:18:20 +010043 }
Davide Pesaventoe9c69852017-11-04 18:08:37 -040044
Andrea Tosatto672b9a72016-01-05 16:18:20 +010045private:
Davide Pesaventof6991e12018-01-08 20:58:50 -050046 static PipelineInterestsFixedWindow::Options
Andrea Tosatto672b9a72016-01-05 16:18:20 +010047 makeOptions()
48 {
Davide Pesaventof6991e12018-01-08 20:58:50 -050049 PipelineInterestsFixedWindow::Options options;
50 options.isQuiet = true;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010051 options.isVerbose = false;
52 options.interestLifetime = time::seconds(1);
53 options.maxRetriesOnTimeoutOrNack = 3;
54 options.maxPipelineSize = 5;
55 return options;
56 }
Davide Pesaventof6991e12018-01-08 20:58:50 -050057
58protected:
59 PipelineInterestsFixedWindow::Options opt;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010060};
61
62BOOST_AUTO_TEST_SUITE(Chunks)
Davide Pesaventoe9c69852017-11-04 18:08:37 -040063BOOST_FIXTURE_TEST_SUITE(TestPipelineInterestsFixedWindow, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010064
Davide Pesaventoe9c69852017-11-04 18:08:37 -040065BOOST_AUTO_TEST_CASE(FullPipeline)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010066{
67 nDataSegments = 13;
68 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
69
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080070 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010071 advanceClocks(io, time::nanoseconds(1), 1);
72 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
73
74 for (uint64_t i = 0; i < nDataSegments - 1; ++i) {
75 face.receive(*makeDataWithSegment(i));
76 advanceClocks(io, time::nanoseconds(1), 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080077 BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010078
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080079 if (i < nDataSegments - opt.maxPipelineSize) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010080 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize + i + 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080081 // check if the interest for the segment i is well formed
Davide Pesaventobf1c0692017-01-15 19:15:09 -050082 const auto& sentInterest = face.sentInterests[i];
Andrea Tosatto672b9a72016-01-05 16:18:20 +010083 BOOST_CHECK_EQUAL(sentInterest.getExclude().size(), 0);
84 BOOST_CHECK_EQUAL(sentInterest.getMaxSuffixComponents(), 1);
85 BOOST_CHECK_EQUAL(sentInterest.getMustBeFresh(), opt.mustBeFresh);
86 BOOST_CHECK_EQUAL(Name(name).isPrefixOf(sentInterest.getName()), true);
Davide Pesaventobf1c0692017-01-15 19:15:09 -050087 BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010088 }
89 else {
90 // all the interests have been sent for all the segments
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080091 BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010092 }
93 }
94
95 BOOST_CHECK_EQUAL(hasFailed, false);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080096
97 advanceClocks(io, ndn::DEFAULT_INTEREST_LIFETIME, opt.maxRetriesOnTimeoutOrNack + 1);
98 BOOST_CHECK_EQUAL(hasFailed, true);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010099}
100
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400101BOOST_AUTO_TEST_CASE(TimeoutAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100102{
103 nDataSegments = 13;
104 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
105
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800106 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100107 advanceClocks(io, time::nanoseconds(1), 1);
108 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
109
110 for (int i = 0; i < opt.maxRetriesOnTimeoutOrNack; ++i) {
111 advanceClocks(io, opt.interestLifetime, 1);
112 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i + 2));
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800113 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 0);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100114
115 // A single retry for every pipeline element
116 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500117 const auto& interest = face.sentInterests[(opt.maxPipelineSize * (i + 1)) + j];
118 BOOST_CHECK_EQUAL(static_cast<size_t>(getSegmentFromPacket(interest)), j);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100119 }
120 }
121
122 advanceClocks(io, opt.interestLifetime, 1);
123 BOOST_CHECK_EQUAL(hasFailed, true);
124}
125
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400126BOOST_AUTO_TEST_CASE(TimeoutAfterFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100127{
128 // the FinalBlockId is sent with the first segment, after the first segment failure the pipeline
129 // should fail
130
131 nDataSegments = 18;
132 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
133
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800134 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100135 advanceClocks(io, time::nanoseconds(1), 1);
136 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
137
138 // send a single segment for each pipeline element but not the first element
139 advanceClocks(io, opt.interestLifetime, 1);
140 for (uint64_t i = 1; i < opt.maxPipelineSize; ++i) {
141 face.receive(*makeDataWithSegment(i));
142 advanceClocks(io, time::nanoseconds(1), 1);
143 }
144
145 // send a single data packet for each pipeline element
146 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800147 for (uint64_t i = 0; i < opt.maxPipelineSize; ++i) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100148 face.receive(*makeDataWithSegment(opt.maxPipelineSize + i));
149 advanceClocks(io, time::nanoseconds(1), 1);
150 }
151 advanceClocks(io, opt.interestLifetime, 1);
152
153 size_t interestAfterFailure = face.sentInterests.size();
154
155 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
156 BOOST_CHECK_EQUAL(hasFailed, true);
157
158 // these new segments should not generate new interests
159 advanceClocks(io, opt.interestLifetime, 1);
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800160 for (uint64_t i = 0; i < opt.maxPipelineSize; ++i) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100161 face.receive(*makeDataWithSegment(opt.maxPipelineSize * 2 + i - 1));
162 advanceClocks(io, time::nanoseconds(1), 1);
163 }
164
165 // no more interests after a failure
166 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
167 BOOST_CHECK_EQUAL(interestAfterFailure, face.sentInterests.size());
168 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
169}
170
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400171BOOST_AUTO_TEST_CASE(TimeoutBeforeFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100172{
173 // the FinalBlockId is sent only with the last segment, all segments are sent except for the
174 // second one (segment #1); all segments are received correctly until the FinalBlockId is received
175
176 nDataSegments = 22;
177 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
178
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800179 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100180 advanceClocks(io, time::nanoseconds(1), 1);
181 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
182
183 advanceClocks(io, opt.interestLifetime, 1);
184 for (uint64_t i = 2; i < opt.maxPipelineSize; ++i) {
185 face.receive(*makeDataWithSegment(i, false));
186 advanceClocks(io, time::nanoseconds(1), 1);
187
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500188 const auto& lastInterest = face.sentInterests.back();
189 BOOST_CHECK_EQUAL(getSegmentFromPacket(lastInterest), opt.maxPipelineSize + i - 2);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100190 }
191 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * 3 - 2);
192
193 // nack for the first pipeline element (segment #0)
194 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
195 nack->setReason(lp::NackReason::DUPLICATE);
196 face.receive(*nack);
197
198 // all the pipeline elements are two retries near the timeout error, but not the
199 // second (segment #1) that is only one retry near the timeout
200 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
201 BOOST_CHECK_EQUAL(hasFailed, false);
202
203 // data for the first pipeline element (segment #0)
204 face.receive(*makeDataWithSegment(0, false));
205 BOOST_CHECK_EQUAL(hasFailed, false);
206
207 // data for all the pipeline element, but not the second (segment #1)
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800208 for (uint64_t i = opt.maxPipelineSize; i < nDataSegments; ++i) {
209 if (i == nDataSegments - 1) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100210 face.receive(*makeDataWithSegment(i, true));
211 }
212 else {
213 face.receive(*makeDataWithSegment(i, false));
214 }
215 advanceClocks(io, time::nanoseconds(1), 1);
216 }
217 // timeout for the second pipeline element (segment #1), this should trigger an error
218 advanceClocks(io, opt.interestLifetime, 1);
219
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400220 BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100221 BOOST_CHECK_EQUAL(hasFailed, true);
222}
223
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400224BOOST_AUTO_TEST_CASE(SegmentReceivedAfterTimeout)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100225{
226 // the FinalBlockId is never sent, all the pipeline elements with a segment number greater than
227 // segment #0 will fail, after this failure also segment #0 fail and this should trigger an error
228
229 nDataSegments = 22;
230 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
231
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800232 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100233 advanceClocks(io, time::nanoseconds(1), 1);
234 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
235
236 advanceClocks(io, opt.interestLifetime, 1);
237
238 // nack for the first pipeline element (segment #0)
239 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
240 nack->setReason(lp::NackReason::DUPLICATE);
241 face.receive(*nack);
242 BOOST_CHECK_EQUAL(hasFailed, false);
243
244 // timeout for all the pipeline elements, but not the first (segment #0)
245 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
246 BOOST_CHECK_EQUAL(hasFailed, false);
247
248 // data for the first pipeline element (segment #0), this should trigger an error because the
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800249 // other pipeline elements failed
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100250 face.receive(*makeDataWithSegment(0, false));
251 advanceClocks(io, time::nanoseconds(1), 1);
252
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800253 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100254 BOOST_CHECK_EQUAL(hasFailed, true);
255}
256
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400257BOOST_AUTO_TEST_CASE(CongestionAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100258{
259 nDataSegments = 13;
260 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
261
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800262 run(name);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100263 advanceClocks(io, time::nanoseconds(1), 1);
264 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
265
266 // send nack for all the pipeline elements first interest
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -0800267 for (size_t i = 0; i < opt.maxPipelineSize; i++) {
268 auto nack = make_shared<lp::Nack>(face.sentInterests[i]);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100269 nack->setReason(lp::NackReason::CONGESTION);
270 face.receive(*nack);
271 advanceClocks(io, time::nanoseconds(1), 1);
272 }
273
274 // send nack for all the pipeline elements interests after the first
275 for (int i = 1; i <= opt.maxRetriesOnTimeoutOrNack; ++i) {
276 time::milliseconds backoffTime(static_cast<uint64_t>(std::pow(2, i)));
277 if (backoffTime > DataFetcher::MAX_CONGESTION_BACKOFF_TIME)
278 backoffTime = DataFetcher::MAX_CONGESTION_BACKOFF_TIME;
279
280 advanceClocks(io, backoffTime, 1);
281 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i +1));
282
283 // A single retry for every pipeline element
284 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500285 const auto& interest = face.sentInterests[(opt.maxPipelineSize * i) + j];
286 BOOST_CHECK_LT(static_cast<size_t>(getSegmentFromPacket(interest)), opt.maxPipelineSize);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100287 }
288
289 for (size_t j = 0; j < opt.maxPipelineSize; j++) {
290 auto nack = make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]);
291 nack->setReason(lp::NackReason::CONGESTION);
292 face.receive(*nack);
293 advanceClocks(io, time::nanoseconds(1), 1);
294 }
295 }
296
297 BOOST_CHECK_EQUAL(hasFailed, true);
298}
299
300BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterests
301BOOST_AUTO_TEST_SUITE_END() // Chunks
302
303} // namespace tests
304} // namespace chunks
305} // namespace ndn