blob: c6291ddf38bc794460f906519887e81ec964007a [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2016, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
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 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 typedef PipelineInterestsFixedWindowOptions Options;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010039
40public:
Weiwei Liue4765012016-06-01 00:10:29 -070041 PipelineInterestFixedWindowFixture()
42 : PipelineInterestsFixture()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010043 , opt(makeOptions())
Andrea Tosatto672b9a72016-01-05 16:18:20 +010044 {
Weiwei Liue4765012016-06-01 00:10:29 -070045 setPipeline(make_unique<PipelineInterestsFixedWindow>(face, PipelineInterestsFixedWindow::Options(opt)));
Andrea Tosatto672b9a72016-01-05 16:18:20 +010046 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +010047protected:
Weiwei Liue4765012016-06-01 00:10:29 -070048 Options opt;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010049
50private:
Andrea Tosatto672b9a72016-01-05 16:18:20 +010051 static Options
52 makeOptions()
53 {
54 Options options;
55 options.isVerbose = false;
56 options.interestLifetime = time::seconds(1);
57 options.maxRetriesOnTimeoutOrNack = 3;
58 options.maxPipelineSize = 5;
59 return options;
60 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +010061};
62
63BOOST_AUTO_TEST_SUITE(Chunks)
Weiwei Liue4765012016-06-01 00:10:29 -070064BOOST_AUTO_TEST_SUITE(TestPipelineInterestsFixedWindow)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010065
Weiwei Liue4765012016-06-01 00:10:29 -070066BOOST_FIXTURE_TEST_CASE(FewerSegmentsThanPipelineCapacity, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010067{
68 nDataSegments = 3;
69 BOOST_ASSERT(nDataSegments <= opt.maxPipelineSize);
70
71 runWithData(*makeDataWithSegment(0));
72 advanceClocks(io, time::nanoseconds(1), 1);
73 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), nDataSegments - 1);
74
75 for (uint64_t i = 0; i < nDataSegments - 1; ++i) {
76 face.receive(*makeDataWithSegment(i));
77 advanceClocks(io, time::nanoseconds(1), 1);
78
79 BOOST_CHECK_EQUAL(nReceivedSegments, i);
80 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), nDataSegments - 1);
81 // check if the interest for the segment i+1 is well formed
82 auto sentInterest = face.sentInterests[i];
83 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);
87 BOOST_CHECK_EQUAL(sentInterest.getName()[-1].toSegment(), i + 1);
88 }
89
90 BOOST_CHECK_EQUAL(hasFailed, false);
91
92 advanceClocks(io, ndn::DEFAULT_INTEREST_LIFETIME, opt.maxRetriesOnTimeoutOrNack + 1);
93 BOOST_CHECK_EQUAL(hasFailed, true);
94}
95
Weiwei Liue4765012016-06-01 00:10:29 -070096BOOST_FIXTURE_TEST_CASE(FullPipeline, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010097{
98 nDataSegments = 13;
99 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
100
101 runWithData(*makeDataWithSegment(nDataSegments - 1));
102 advanceClocks(io, time::nanoseconds(1), 1);
103 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
104
105 for (uint64_t i = 0; i < nDataSegments - 1; ++i) {
106 face.receive(*makeDataWithSegment(i));
107 advanceClocks(io, time::nanoseconds(1), 1);
108 BOOST_CHECK_EQUAL(nReceivedSegments, i + 1);
109
110 if (i < nDataSegments - opt.maxPipelineSize - 1) {
111 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize + i + 1);
112 // check if the interest for the segment i+1 is well formed
113 auto sentInterest = face.sentInterests[i];
114 BOOST_CHECK_EQUAL(sentInterest.getExclude().size(), 0);
115 BOOST_CHECK_EQUAL(sentInterest.getMaxSuffixComponents(), 1);
116 BOOST_CHECK_EQUAL(sentInterest.getMustBeFresh(), opt.mustBeFresh);
117 BOOST_CHECK_EQUAL(Name(name).isPrefixOf(sentInterest.getName()), true);
118 BOOST_CHECK_EQUAL(sentInterest.getName()[-1].toSegment(), i);
119 }
120 else {
121 // all the interests have been sent for all the segments
122 BOOST_CHECK_EQUAL(face.sentInterests.size(), nDataSegments - 1);
123 }
124 }
125
126 BOOST_CHECK_EQUAL(hasFailed, false);
127}
128
Weiwei Liue4765012016-06-01 00:10:29 -0700129BOOST_FIXTURE_TEST_CASE(TimeoutAllSegments, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100130{
131 nDataSegments = 13;
132 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
133
134 runWithData(*makeDataWithSegment(nDataSegments - 1));
135 advanceClocks(io, time::nanoseconds(1), 1);
136 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
137
138 for (int i = 0; i < opt.maxRetriesOnTimeoutOrNack; ++i) {
139 advanceClocks(io, opt.interestLifetime, 1);
140 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i + 2));
141 BOOST_CHECK_EQUAL(nReceivedSegments, 0);
142
143 // A single retry for every pipeline element
144 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
145 auto interest = face.sentInterests[(opt.maxPipelineSize * (i + 1)) + j];
146 BOOST_CHECK_EQUAL(static_cast<size_t>(interest.getName()[-1].toSegment()), j);
147 }
148 }
149
150 advanceClocks(io, opt.interestLifetime, 1);
151 BOOST_CHECK_EQUAL(hasFailed, true);
152}
153
Weiwei Liue4765012016-06-01 00:10:29 -0700154BOOST_FIXTURE_TEST_CASE(TimeoutAfterFinalBlockIdReceived, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100155{
156 // the FinalBlockId is sent with the first segment, after the first segment failure the pipeline
157 // should fail
158
159 nDataSegments = 18;
160 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
161
162 runWithData(*makeDataWithSegment(nDataSegments - 1));
163 advanceClocks(io, time::nanoseconds(1), 1);
164 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
165
166 // send a single segment for each pipeline element but not the first element
167 advanceClocks(io, opt.interestLifetime, 1);
168 for (uint64_t i = 1; i < opt.maxPipelineSize; ++i) {
169 face.receive(*makeDataWithSegment(i));
170 advanceClocks(io, time::nanoseconds(1), 1);
171 }
172
173 // send a single data packet for each pipeline element
174 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
175 for (uint64_t i = 0; i < opt.maxPipelineSize - 1; ++i) {
176 face.receive(*makeDataWithSegment(opt.maxPipelineSize + i));
177 advanceClocks(io, time::nanoseconds(1), 1);
178 }
179 advanceClocks(io, opt.interestLifetime, 1);
180
181 size_t interestAfterFailure = face.sentInterests.size();
182
183 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
184 BOOST_CHECK_EQUAL(hasFailed, true);
185
186 // these new segments should not generate new interests
187 advanceClocks(io, opt.interestLifetime, 1);
188 for (uint64_t i = 0; i < opt.maxPipelineSize - 1; ++i) {
189 face.receive(*makeDataWithSegment(opt.maxPipelineSize * 2 + i - 1));
190 advanceClocks(io, time::nanoseconds(1), 1);
191 }
192
193 // no more interests after a failure
194 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
195 BOOST_CHECK_EQUAL(interestAfterFailure, face.sentInterests.size());
196 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
197}
198
Weiwei Liue4765012016-06-01 00:10:29 -0700199BOOST_FIXTURE_TEST_CASE(TimeoutBeforeFinalBlockIdReceived, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100200{
201 // the FinalBlockId is sent only with the last segment, all segments are sent except for the
202 // second one (segment #1); all segments are received correctly until the FinalBlockId is received
203
204 nDataSegments = 22;
205 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
206
207 runWithData(*makeDataWithSegment(nDataSegments - 1, false));
208 advanceClocks(io, time::nanoseconds(1), 1);
209 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
210
211 advanceClocks(io, opt.interestLifetime, 1);
212 for (uint64_t i = 2; i < opt.maxPipelineSize; ++i) {
213 face.receive(*makeDataWithSegment(i, false));
214 advanceClocks(io, time::nanoseconds(1), 1);
215
216 auto lastInterest = face.sentInterests.back();
217 BOOST_CHECK_EQUAL(lastInterest.getName()[-1].toSegment(), opt.maxPipelineSize + i - 2);
218 }
219 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * 3 - 2);
220
221 // nack for the first pipeline element (segment #0)
222 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
223 nack->setReason(lp::NackReason::DUPLICATE);
224 face.receive(*nack);
225
226 // all the pipeline elements are two retries near the timeout error, but not the
227 // second (segment #1) that is only one retry near the timeout
228 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack - 1);
229 BOOST_CHECK_EQUAL(hasFailed, false);
230
231 // data for the first pipeline element (segment #0)
232 face.receive(*makeDataWithSegment(0, false));
233 BOOST_CHECK_EQUAL(hasFailed, false);
234
235 // data for all the pipeline element, but not the second (segment #1)
236 for (uint64_t i = opt.maxPipelineSize; i < nDataSegments - 1; ++i) {
237 if (i == nDataSegments - 2) {
238 face.receive(*makeDataWithSegment(i, true));
239 }
240 else {
241 face.receive(*makeDataWithSegment(i, false));
242 }
243 advanceClocks(io, time::nanoseconds(1), 1);
244 }
245 // timeout for the second pipeline element (segment #1), this should trigger an error
246 advanceClocks(io, opt.interestLifetime, 1);
247
248 BOOST_CHECK_EQUAL(nReceivedSegments, nDataSegments - 2);
249 BOOST_CHECK_EQUAL(hasFailed, true);
250}
251
Weiwei Liue4765012016-06-01 00:10:29 -0700252BOOST_FIXTURE_TEST_CASE(SegmentReceivedAfterTimeout, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100253{
254 // the FinalBlockId is never sent, all the pipeline elements with a segment number greater than
255 // segment #0 will fail, after this failure also segment #0 fail and this should trigger an error
256
257 nDataSegments = 22;
258 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
259
260 runWithData(*makeDataWithSegment(nDataSegments - 1, false));
261 advanceClocks(io, time::nanoseconds(1), 1);
262 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
263
264 advanceClocks(io, opt.interestLifetime, 1);
265
266 // nack for the first pipeline element (segment #0)
267 auto nack = make_shared<lp::Nack>(face.sentInterests[opt.maxPipelineSize]);
268 nack->setReason(lp::NackReason::DUPLICATE);
269 face.receive(*nack);
270 BOOST_CHECK_EQUAL(hasFailed, false);
271
272 // timeout for all the pipeline elements, but not the first (segment #0)
273 advanceClocks(io, opt.interestLifetime, opt.maxRetriesOnTimeoutOrNack);
274 BOOST_CHECK_EQUAL(hasFailed, false);
275
276 // data for the first pipeline element (segment #0), this should trigger an error because the
277 // others pipeline elements failed
278 face.receive(*makeDataWithSegment(0, false));
279 advanceClocks(io, time::nanoseconds(1), 1);
280
281 BOOST_CHECK_EQUAL(nReceivedSegments, 1);
282 BOOST_CHECK_EQUAL(hasFailed, true);
283}
284
Weiwei Liue4765012016-06-01 00:10:29 -0700285BOOST_FIXTURE_TEST_CASE(CongestionAllSegments, PipelineInterestFixedWindowFixture)
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100286{
287 nDataSegments = 13;
288 BOOST_ASSERT(nDataSegments > opt.maxPipelineSize);
289
290 runWithData(*makeDataWithSegment(nDataSegments - 1));
291 advanceClocks(io, time::nanoseconds(1), 1);
292 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize);
293
294 // send nack for all the pipeline elements first interest
295 for (size_t j = 0; j < opt.maxPipelineSize; j++) {
296 auto nack = make_shared<lp::Nack>(face.sentInterests[j]);
297 nack->setReason(lp::NackReason::CONGESTION);
298 face.receive(*nack);
299 advanceClocks(io, time::nanoseconds(1), 1);
300 }
301
302 // send nack for all the pipeline elements interests after the first
303 for (int i = 1; i <= opt.maxRetriesOnTimeoutOrNack; ++i) {
304 time::milliseconds backoffTime(static_cast<uint64_t>(std::pow(2, i)));
305 if (backoffTime > DataFetcher::MAX_CONGESTION_BACKOFF_TIME)
306 backoffTime = DataFetcher::MAX_CONGESTION_BACKOFF_TIME;
307
308 advanceClocks(io, backoffTime, 1);
309 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), opt.maxPipelineSize * (i +1));
310
311 // A single retry for every pipeline element
312 for (size_t j = 0; j < opt.maxPipelineSize; ++j) {
313 auto interest = face.sentInterests[(opt.maxPipelineSize * i) + j];
314 BOOST_CHECK_LT(static_cast<size_t>(interest.getName()[-1].toSegment()), opt.maxPipelineSize);
315 }
316
317 for (size_t j = 0; j < opt.maxPipelineSize; j++) {
318 auto nack = make_shared<lp::Nack>(face.sentInterests[(opt.maxPipelineSize * i) + j]);
319 nack->setReason(lp::NackReason::CONGESTION);
320 face.receive(*nack);
321 advanceClocks(io, time::nanoseconds(1), 1);
322 }
323 }
324
325 BOOST_CHECK_EQUAL(hasFailed, true);
326}
327
328BOOST_AUTO_TEST_SUITE_END() // TestPipelineInterests
329BOOST_AUTO_TEST_SUITE_END() // Chunks
330
331} // namespace tests
332} // namespace chunks
333} // namespace ndn