blob: e53cc0f7f981dd089e54d0c9d45eb4709bec26b9 [file] [log] [blame]
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "util/segment-fetcher.hpp"
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050023#include "security/validator-null.hpp"
24#include "security/validator.hpp"
25#include "data.hpp"
26#include "encoding/block.hpp"
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070027
28#include "boost-test.hpp"
Junxiao Shia60d9362014-11-12 09:38:21 -070029#include "util/dummy-client-face.hpp"
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070030#include "security/key-chain.hpp"
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050031#include "lp/nack-header.hpp"
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080032#include "../unit-test-time-fixture.hpp"
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050033#include "../make-interest-data.hpp"
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070034
35namespace ndn {
36namespace util {
37namespace tests {
38
39BOOST_AUTO_TEST_SUITE(UtilSegmentFetcher)
40
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050041class ValidatorFailed : public Validator
42{
43protected:
44 virtual void
45 checkPolicy(const Data& data,
46 int nSteps,
47 const OnDataValidated& onValidated,
48 const OnDataValidationFailed& onValidationFailed,
49 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
50 {
51 onValidationFailed(data.shared_from_this(), "Data validation failed.");
52 }
53
54 virtual void
55 checkPolicy(const Interest& interest,
56 int nSteps,
57 const OnInterestValidated& onValidated,
58 const OnInterestValidationFailed& onValidationFailed,
59 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
60 {
61 onValidationFailed(interest.shared_from_this(), "Interest validation failed.");
62 }
63};
64
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080065class Fixture : public ndn::tests::UnitTestTimeFixture
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070066{
67public:
68 Fixture()
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080069 : face(makeDummyClientFace(io))
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070070 , nErrors(0)
71 , nDatas(0)
72 , dataSize(0)
73 {
74 }
75
76 shared_ptr<Data>
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050077 makeDataSegment(const Name& baseName, uint64_t segment, bool isFinal)
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070078 {
79 const uint8_t buffer[] = "Hello, world!";
80
81 shared_ptr<Data> data = make_shared<Data>(Name(baseName).appendSegment(segment));
82 data->setContent(buffer, sizeof(buffer));
83
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050084 if (isFinal) {
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070085 data->setFinalBlockId(data->getName()[-1]);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -050086 }
87 data = signData(data);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -070088
89 return data;
90 }
91
92 void
93 onError(uint32_t errorCode)
94 {
95 ++nErrors;
96 lastError = errorCode;
97 }
98
99 void
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500100 onComplete(const ConstBufferPtr& data)
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700101 {
102 ++nDatas;
103 dataSize = data->size();
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500104 dataString = std::string(reinterpret_cast<const char*>(data->get()));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700105 }
106
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500107 void
108 nackLastInterest(lp::NackReason nackReason)
109 {
110 const Interest& lastInterest = face->sentInterests.back();
111 lp::Nack nack = makeNack(lastInterest, nackReason);
112 face->receive(nack);
113 advanceClocks(time::milliseconds(1), 10);
114 }
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700115
116public:
Junxiao Shia60d9362014-11-12 09:38:21 -0700117 shared_ptr<DummyClientFace> face;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700118 KeyChain keyChain;
119
120 uint32_t nErrors;
121 uint32_t lastError;
122 uint32_t nDatas;
123 size_t dataSize;
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500124 std::string dataString;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700125};
126
127BOOST_FIXTURE_TEST_CASE(Timeout, Fixture)
128{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500129 ValidatorNull nullValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700130 SegmentFetcher::fetch(*face, Interest("/hello/world", time::milliseconds(100)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500131 nullValidator,
132 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700133 bind(&Fixture::onError, this, _1));
134
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800135 advanceClocks(time::milliseconds(1), 99);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700136
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800137 BOOST_CHECK_EQUAL(nErrors, 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700138 BOOST_CHECK_EQUAL(nDatas, 0);
Junxiao Shia60d9362014-11-12 09:38:21 -0700139 BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
140 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700141
Junxiao Shia60d9362014-11-12 09:38:21 -0700142 const Interest& interest = face->sentInterests[0];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700143 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world");
144 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true);
145 BOOST_CHECK_EQUAL(interest.getChildSelector(), 1);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800146
147 advanceClocks(time::milliseconds(1), 2);
148
149 BOOST_CHECK_EQUAL(nErrors, 1);
150 BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::INTEREST_TIMEOUT));
151 BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
152 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700153}
154
155
156BOOST_FIXTURE_TEST_CASE(Basic, Fixture)
157{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500158 ValidatorNull nullValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700159 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500160 nullValidator,
161 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700162 bind(&Fixture::onError, this, _1));
163
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800164 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700165
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500166 face->receive(*makeDataSegment("/hello/world/version0", 0, true));
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800167 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700168
169 BOOST_CHECK_EQUAL(nErrors, 0);
170 BOOST_CHECK_EQUAL(nDatas, 1);
171
172 BOOST_CHECK_EQUAL(dataSize, 14);
173
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500174 const uint8_t buffer[] = "Hello, world!";
175 std::string bufferString = std::string(reinterpret_cast<const char*>(buffer));
176
177 BOOST_CHECK_EQUAL(dataString, bufferString);
178
Junxiao Shia60d9362014-11-12 09:38:21 -0700179 BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
180 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700181
Junxiao Shia60d9362014-11-12 09:38:21 -0700182 const Interest& interest = face->sentInterests[0];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700183 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world");
184 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true);
185 BOOST_CHECK_EQUAL(interest.getChildSelector(), 1);
186}
187
188BOOST_FIXTURE_TEST_CASE(NoSegmentInData, Fixture)
189{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500190 ValidatorNull nullValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700191 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500192 nullValidator,
193 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700194 bind(&Fixture::onError, this, _1));
195
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800196 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700197
198 const uint8_t buffer[] = "Hello, world!";
199
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500200 shared_ptr<Data> data = makeData("/hello/world/version0/no-segment");
201
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700202 data->setContent(buffer, sizeof(buffer));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700203
204 face->receive(*data);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800205 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700206
207 BOOST_CHECK_EQUAL(nErrors, 1);
208 BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::DATA_HAS_NO_SEGMENT));
209 BOOST_CHECK_EQUAL(nDatas, 0);
210}
211
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700212BOOST_FIXTURE_TEST_CASE(SegmentValidationFailure, Fixture)
213{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500214 ValidatorFailed failedValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700215 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500216 failedValidator,
217 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700218 bind(&Fixture::onError, this, _1));
219
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800220 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500221 face->receive(*makeDataSegment("/hello/world/version0", 0, true));
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800222 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700223
224 BOOST_CHECK_EQUAL(nErrors, 1);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500225 BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::SEGMENT_VALIDATION_FAIL));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700226 BOOST_CHECK_EQUAL(nDatas, 0);
227}
228
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700229BOOST_FIXTURE_TEST_CASE(Triple, Fixture)
230{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500231 ValidatorNull nullValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700232 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500233 nullValidator,
234 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700235 bind(&Fixture::onError, this, _1));
236
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800237 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500238 face->receive(*makeDataSegment("/hello/world/version0", 0, false));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700239
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800240 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500241 face->receive(*makeDataSegment("/hello/world/version0", 1, false));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700242
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800243 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500244 face->receive(*makeDataSegment("/hello/world/version0", 2, true));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700245
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800246 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700247
248 BOOST_CHECK_EQUAL(nErrors, 0);
249 BOOST_CHECK_EQUAL(nDatas, 1);
250
251 BOOST_CHECK_EQUAL(dataSize, 42);
252
Junxiao Shia60d9362014-11-12 09:38:21 -0700253 BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 3);
254 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700255
256 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700257 const Interest& interest = face->sentInterests[0];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700258 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world");
259 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true);
260 BOOST_CHECK_EQUAL(interest.getChildSelector(), 1);
261 }
262
263 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700264 const Interest& interest = face->sentInterests[1];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700265 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%01");
266 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
267 BOOST_CHECK_EQUAL(interest.getChildSelector(), 0);
268 }
269
270 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700271 const Interest& interest = face->sentInterests[2];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700272 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%02");
273 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
274 BOOST_CHECK_EQUAL(interest.getChildSelector(), 0);
275 }
276}
277
278BOOST_FIXTURE_TEST_CASE(TripleWithInitialSegmentFetching, Fixture)
279{
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500280 ValidatorNull nullValidator;
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700281 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500282 nullValidator,
283 bind(&Fixture::onComplete, this, _1),
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700284 bind(&Fixture::onError, this, _1));
285
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800286 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500287 face->receive(*makeDataSegment("/hello/world/version0", 1, false));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700288
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800289 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500290 face->receive(*makeDataSegment("/hello/world/version0", 0, false));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700291
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800292 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500293 face->receive(*makeDataSegment("/hello/world/version0", 1, false));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700294
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800295 advanceClocks(time::milliseconds(1), 10);
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500296 face->receive(*makeDataSegment("/hello/world/version0", 2, true));
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700297
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800298 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700299
300 BOOST_CHECK_EQUAL(nErrors, 0);
301 BOOST_CHECK_EQUAL(nDatas, 1);
302
303 BOOST_CHECK_EQUAL(dataSize, 42);
304
Junxiao Shia60d9362014-11-12 09:38:21 -0700305 BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 4);
306 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700307
308 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700309 const Interest& interest = face->sentInterests[0];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700310 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world");
311 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true);
312 BOOST_CHECK_EQUAL(interest.getChildSelector(), 1);
313 }
314
315 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700316 const Interest& interest = face->sentInterests[1];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700317 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%00");
318 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
319 BOOST_CHECK_EQUAL(interest.getChildSelector(), 0);
320 }
321
322 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700323 const Interest& interest = face->sentInterests[2];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700324 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%01");
325 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
326 BOOST_CHECK_EQUAL(interest.getChildSelector(), 0);
327 }
328
329 {
Junxiao Shia60d9362014-11-12 09:38:21 -0700330 const Interest& interest = face->sentInterests[3];
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700331 BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%02");
332 BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
333 BOOST_CHECK_EQUAL(interest.getChildSelector(), 0);
334 }
335}
336
Muktadir R Chowdhuryf58f8f42015-09-02 11:56:49 -0500337BOOST_FIXTURE_TEST_CASE(MultipleSegmentFetching, Fixture)
338{
339 ValidatorNull nullValidator;
340 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
341 nullValidator,
342 bind(&Fixture::onComplete, this, _1),
343 bind(&Fixture::onError, this, _1));
344
345 advanceClocks(time::milliseconds(1), 10);
346
347 for (uint64_t i = 0; i < 400; i++) {
348 advanceClocks(time::milliseconds(1), 10);
349 face->receive(*makeDataSegment("/hello/world/version0", i, false));
350 }
351 advanceClocks(time::milliseconds(1), 10);
352 face->receive(*makeDataSegment("/hello/world/version0", 400, true));
353
354 advanceClocks(time::milliseconds(1), 10);
355
356 BOOST_CHECK_EQUAL(nErrors, 0);
357 BOOST_CHECK_EQUAL(nDatas, 1);
358}
359
360BOOST_FIXTURE_TEST_CASE(SegmentFetcherDuplicateNack, Fixture)
361{
362 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
363 make_shared<ValidatorNull>(),
364 bind(&Fixture::onComplete, this, _1),
365 bind(&Fixture::onError, this, _1));
366 advanceClocks(time::milliseconds(1), 10);
367
368 // receive nack for the original interest
369 nackLastInterest(lp::NackReason::DUPLICATE);
370
371 // receive nack due to Duplication for the reexpressed interests
372 for (uint32_t i = 1; i <= SegmentFetcher::MAX_INTEREST_REEXPRESS; ++i) {
373 nackLastInterest(lp::NackReason::DUPLICATE);
374 }
375
376 BOOST_CHECK_EQUAL(face->sentInterests.size(), (SegmentFetcher::MAX_INTEREST_REEXPRESS + 1));
377 BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::NACK_ERROR));
378}
379
380BOOST_FIXTURE_TEST_CASE(SegmentFetcherCongestionNack, Fixture)
381{
382 SegmentFetcher::fetch(*face, Interest("/hello/world", time::seconds(1000)),
383 make_shared<ValidatorNull>(),
384 bind(&Fixture::onComplete, this, _1),
385 bind(&Fixture::onError, this, _1));
386 advanceClocks(time::milliseconds(1), 10);
387
388 // receive nack for the original interest
389 nackLastInterest(lp::NackReason::CONGESTION);
390
391 // receive nack due to Congestion for the reexpressed interests
392 for (uint32_t i = 1; i <= SegmentFetcher::MAX_INTEREST_REEXPRESS; ++i) {
393 nackLastInterest(lp::NackReason::CONGESTION);
394 }
395
396 BOOST_CHECK_EQUAL(face->sentInterests.size(), (SegmentFetcher::MAX_INTEREST_REEXPRESS + 1));
397 BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::NACK_ERROR));
398}
Alexander Afanasyevf3cfab52014-08-17 22:15:25 -0700399
400BOOST_AUTO_TEST_SUITE_END()
401
402} // namespace tests
403} // namespace util
404} // namespace ndn