blob: c4d4aad1a2ddd1cea36919911094cdd8e4470dd9 [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/*
Davide Pesaventof6991e12018-01-08 20:58:50 -05003 * Copyright (c) 2016-2018, 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
24 */
25
Weiwei Liue4765012016-06-01 00:10:29 -070026#include "tools/chunks/catchunks/pipeline-interests-fixed-window.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010027#include "tools/chunks/catchunks/data-fetcher.hpp"
28
Weiwei Liue4765012016-06-01 00:10:29 -070029#include "pipeline-interests-fixture.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010030
31namespace ndn {
32namespace chunks {
33namespace tests {
34
Weiwei Liue4765012016-06-01 00:10:29 -070035class PipelineInterestFixedWindowFixture : public PipelineInterestsFixture
Andrea Tosatto672b9a72016-01-05 16:18:20 +010036{
37public:
Weiwei Liue4765012016-06-01 00:10:29 -070038 PipelineInterestFixedWindowFixture()
Davide Pesaventof6991e12018-01-08 20:58:50 -050039 : opt(makeOptions())
Andrea Tosatto672b9a72016-01-05 16:18:20 +010040 {
Weiwei Liue4765012016-06-01 00:10:29 -070041 setPipeline(make_unique<PipelineInterestsFixedWindow>(face, PipelineInterestsFixedWindow::Options(opt)));
Andrea Tosatto672b9a72016-01-05 16:18:20 +010042 }
Davide Pesaventoe9c69852017-11-04 18:08:37 -040043
Andrea Tosatto672b9a72016-01-05 16:18:20 +010044private:
Davide Pesaventof6991e12018-01-08 20:58:50 -050045 static PipelineInterestsFixedWindow::Options
Andrea Tosatto672b9a72016-01-05 16:18:20 +010046 makeOptions()
47 {
Davide Pesaventof6991e12018-01-08 20:58:50 -050048 PipelineInterestsFixedWindow::Options options;
49 options.isQuiet = true;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010050 options.isVerbose = false;
51 options.interestLifetime = time::seconds(1);
52 options.maxRetriesOnTimeoutOrNack = 3;
53 options.maxPipelineSize = 5;
54 return options;
55 }
Davide Pesaventof6991e12018-01-08 20:58:50 -050056
57protected:
58 PipelineInterestsFixedWindow::Options opt;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010059};
60
61BOOST_AUTO_TEST_SUITE(Chunks)
Davide Pesaventoe9c69852017-11-04 18:08:37 -040062BOOST_FIXTURE_TEST_SUITE(TestPipelineInterestsFixedWindow, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010063
Davide Pesaventoe9c69852017-11-04 18:08:37 -040064BOOST_AUTO_TEST_CASE(FewerSegmentsThanPipelineCapacity)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010065{
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 Pesaventoe9c69852017-11-04 18:08:37 -040073 for (uint64_t i = 1; i < nDataSegments - 1; ++i) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010074 face.receive(*makeDataWithSegment(i));
75 advanceClocks(io, time::nanoseconds(1), 1);
76
Davide Pesaventoe9c69852017-11-04 18:08:37 -040077 BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010078 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), nDataSegments - 1);
79 // check if the interest for the segment i+1 is well formed
Davide Pesaventobf1c0692017-01-15 19:15:09 -050080 const auto& sentInterest = face.sentInterests[i];
Andrea Tosatto672b9a72016-01-05 16:18:20 +010081 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 Pesaventobf1c0692017-01-15 19:15:09 -050085 BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i + 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010086 }
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 Pesaventoe9c69852017-11-04 18:08:37 -040094BOOST_AUTO_TEST_CASE(FullPipeline)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010095{
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 Pesaventoe9c69852017-11-04 18:08:37 -0400106 BOOST_CHECK_EQUAL(pipeline->m_nReceived, i + 2);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100107
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 Pesaventobf1c0692017-01-15 19:15:09 -0500111 const auto& sentInterest = face.sentInterests[i];
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100112 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 Pesaventobf1c0692017-01-15 19:15:09 -0500116 BOOST_CHECK_EQUAL(getSegmentFromPacket(sentInterest), i);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100117 }
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 Pesaventoe9c69852017-11-04 18:08:37 -0400127BOOST_AUTO_TEST_CASE(TimeoutAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100128{
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 Pesaventoe9c69852017-11-04 18:08:37 -0400139 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100140
141 // A single retry for every pipeline element
142 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
Davide Pesaventobf1c0692017-01-15 19:15:09 -0500143 const auto& interest = face.sentInterests[(opt.maxPipelineSize * (i + 1)) + j];
144 BOOST_CHECK_EQUAL(static_cast<size_t>(getSegmentFromPacket(interest)), j);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100145 }
146 }
147
148 advanceClocks(io, opt.interestLifetime, 1);
149 BOOST_CHECK_EQUAL(hasFailed, true);
150}
151
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400152BOOST_AUTO_TEST_CASE(TimeoutAfterFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100153{
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 Pesaventoe9c69852017-11-04 18:08:37 -0400197BOOST_AUTO_TEST_CASE(TimeoutBeforeFinalBlockIdReceived)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100198{
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 Pesaventobf1c0692017-01-15 19:15:09 -0500214 const auto& lastInterest = face.sentInterests.back();
215 BOOST_CHECK_EQUAL(getSegmentFromPacket(lastInterest), opt.maxPipelineSize + i - 2);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100216 }
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 Pesaventoe9c69852017-11-04 18:08:37 -0400246 BOOST_CHECK_EQUAL(pipeline->m_nReceived, nDataSegments - 1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100247 BOOST_CHECK_EQUAL(hasFailed, true);
248}
249
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400250BOOST_AUTO_TEST_CASE(SegmentReceivedAfterTimeout)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100251{
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 Pesaventoe9c69852017-11-04 18:08:37 -0400279 BOOST_CHECK_EQUAL(pipeline->m_nReceived, 2);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100280 BOOST_CHECK_EQUAL(hasFailed, true);
281}
282
Davide Pesaventoe9c69852017-11-04 18:08:37 -0400283BOOST_AUTO_TEST_CASE(CongestionAllSegments)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100284{
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 Pesaventobf1c0692017-01-15 19:15:09 -0500311 const auto& interest = face.sentInterests[(opt.maxPipelineSize * i) + j];
312 BOOST_CHECK_LT(static_cast<size_t>(getSegmentFromPacket(interest)), opt.maxPipelineSize);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100313 }
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
326BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterests
327BOOST_AUTO_TEST_SUITE_END() // Chunks
328
329} // namespace tests
330} // namespace chunks
331} // namespace ndn