Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 2 | /* |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 4 | * |
| 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" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 23 | #include "lp/nack-header.hpp" |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 24 | #include "data.hpp" |
| 25 | #include "encoding/block.hpp" |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 26 | |
| 27 | #include "boost-test.hpp" |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 28 | #include "util/dummy-client-face.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 29 | #include "../identity-management-time-fixture.hpp" |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 30 | #include "../make-interest-data.hpp" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 31 | #include "../../dummy-validator.hpp" |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
| 34 | namespace util { |
| 35 | namespace tests { |
| 36 | |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 37 | using namespace ndn::tests; |
| 38 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Util) |
| 40 | BOOST_AUTO_TEST_SUITE(TestSegmentFetcher) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 42 | class Fixture : public IdentityManagementTimeFixture |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | Fixture() |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 46 | : face(io, m_keyChain) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 47 | , nErrors(0) |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 48 | , nData(0) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 49 | , dataSize(0) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | shared_ptr<Data> |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 54 | makeDataSegment(const Name& baseName, uint64_t segment, bool isFinal) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 55 | { |
| 56 | const uint8_t buffer[] = "Hello, world!"; |
| 57 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 58 | auto data = make_shared<Data>(Name(baseName).appendSegment(segment)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 59 | data->setContent(buffer, sizeof(buffer)); |
| 60 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 61 | if (isFinal) { |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 62 | data->setFinalBlockId(data->getName()[-1]); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 63 | } |
| 64 | data = signData(data); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 65 | |
| 66 | return data; |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | onError(uint32_t errorCode) |
| 71 | { |
| 72 | ++nErrors; |
| 73 | lastError = errorCode; |
| 74 | } |
| 75 | |
| 76 | void |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 77 | onComplete(const ConstBufferPtr& data) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 78 | { |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 79 | ++nData; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 80 | dataSize = data->size(); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 81 | dataString = std::string(reinterpret_cast<const char*>(data->get())); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 84 | void |
| 85 | nackLastInterest(lp::NackReason nackReason) |
| 86 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 87 | const Interest& lastInterest = face.sentInterests.back(); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 88 | lp::Nack nack = makeNack(lastInterest, nackReason); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 89 | face.receive(nack); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 90 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 91 | } |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 92 | |
| 93 | public: |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 94 | DummyClientFace face; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 95 | |
| 96 | uint32_t nErrors; |
| 97 | uint32_t lastError; |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 98 | uint32_t nData; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 99 | size_t dataSize; |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 100 | std::string dataString; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | BOOST_FIXTURE_TEST_CASE(Timeout, Fixture) |
| 104 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 105 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 106 | SegmentFetcher::fetch(face, Interest("/hello/world", time::milliseconds(100)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 107 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 108 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 109 | bind(&Fixture::onError, this, _1)); |
| 110 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 111 | advanceClocks(time::milliseconds(1)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 112 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 113 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 114 | const Interest& interest = face.sentInterests[0]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 115 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world"); |
| 116 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true); |
| 117 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 1); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 118 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 119 | advanceClocks(time::milliseconds(98)); |
| 120 | BOOST_CHECK_EQUAL(nErrors, 0); |
| 121 | BOOST_CHECK_EQUAL(nData, 0); |
| 122 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 123 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 124 | advanceClocks(time::milliseconds(1), 2); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 125 | BOOST_CHECK_EQUAL(nErrors, 1); |
| 126 | BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::INTEREST_TIMEOUT)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 127 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 128 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | |
| 132 | BOOST_FIXTURE_TEST_CASE(Basic, Fixture) |
| 133 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 134 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 135 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 136 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 137 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 138 | bind(&Fixture::onError, this, _1)); |
| 139 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 140 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 142 | face.receive(*makeDataSegment("/hello/world/version0", 0, true)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 143 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 144 | |
| 145 | BOOST_CHECK_EQUAL(nErrors, 0); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 146 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 147 | |
| 148 | BOOST_CHECK_EQUAL(dataSize, 14); |
| 149 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 150 | const uint8_t buffer[] = "Hello, world!"; |
| 151 | std::string bufferString = std::string(reinterpret_cast<const char*>(buffer)); |
| 152 | |
| 153 | BOOST_CHECK_EQUAL(dataString, bufferString); |
| 154 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 155 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 156 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 157 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 158 | const Interest& interest = face.sentInterests[0]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world"); |
| 160 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true); |
| 161 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 1); |
| 162 | } |
| 163 | |
| 164 | BOOST_FIXTURE_TEST_CASE(NoSegmentInData, Fixture) |
| 165 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 166 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 167 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 168 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 169 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 170 | bind(&Fixture::onError, this, _1)); |
| 171 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 172 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 173 | |
| 174 | const uint8_t buffer[] = "Hello, world!"; |
| 175 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 176 | shared_ptr<Data> data = makeData("/hello/world/version0/no-segment"); |
| 177 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 178 | data->setContent(buffer, sizeof(buffer)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 179 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 180 | face.receive(*data); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 181 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 182 | |
| 183 | BOOST_CHECK_EQUAL(nErrors, 1); |
| 184 | BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::DATA_HAS_NO_SEGMENT)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(nData, 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 188 | BOOST_FIXTURE_TEST_CASE(SegmentValidationFailure, Fixture) |
| 189 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 190 | DummyValidator rejectValidator(false); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 191 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 192 | rejectValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 193 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 194 | bind(&Fixture::onError, this, _1)); |
| 195 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 196 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 197 | face.receive(*makeDataSegment("/hello/world/version0", 0, true)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 198 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 199 | |
| 200 | BOOST_CHECK_EQUAL(nErrors, 1); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::SEGMENT_VALIDATION_FAIL)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 202 | BOOST_CHECK_EQUAL(nData, 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 205 | BOOST_FIXTURE_TEST_CASE(Triple, Fixture) |
| 206 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 207 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 208 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 209 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 210 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 211 | bind(&Fixture::onError, this, _1)); |
| 212 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 213 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 214 | face.receive(*makeDataSegment("/hello/world/version0", 0, false)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 215 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 216 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 217 | face.receive(*makeDataSegment("/hello/world/version0", 1, false)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 218 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 219 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 220 | face.receive(*makeDataSegment("/hello/world/version0", 2, true)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 221 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 222 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 223 | |
| 224 | BOOST_CHECK_EQUAL(nErrors, 0); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 226 | |
| 227 | BOOST_CHECK_EQUAL(dataSize, 42); |
| 228 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 229 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 3); |
| 230 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 231 | |
| 232 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 233 | const Interest& interest = face.sentInterests[0]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 234 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world"); |
| 235 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true); |
| 236 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 1); |
| 237 | } |
| 238 | |
| 239 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 240 | const Interest& interest = face.sentInterests[1]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 241 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%01"); |
| 242 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false); |
| 243 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 0); |
| 244 | } |
| 245 | |
| 246 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 247 | const Interest& interest = face.sentInterests[2]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 248 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%02"); |
| 249 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false); |
| 250 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 0); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | BOOST_FIXTURE_TEST_CASE(TripleWithInitialSegmentFetching, Fixture) |
| 255 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 256 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 257 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 258 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 259 | bind(&Fixture::onComplete, this, _1), |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 260 | bind(&Fixture::onError, this, _1)); |
| 261 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 262 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 263 | face.receive(*makeDataSegment("/hello/world/version0", 1, false)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 264 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 265 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 266 | face.receive(*makeDataSegment("/hello/world/version0", 0, false)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 267 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 268 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 269 | face.receive(*makeDataSegment("/hello/world/version0", 1, false)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 270 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 271 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 272 | face.receive(*makeDataSegment("/hello/world/version0", 2, true)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 273 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 274 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 275 | |
| 276 | BOOST_CHECK_EQUAL(nErrors, 0); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 278 | |
| 279 | BOOST_CHECK_EQUAL(dataSize, 42); |
| 280 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 281 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 4); |
| 282 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 283 | |
| 284 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 285 | const Interest& interest = face.sentInterests[0]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 286 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world"); |
| 287 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true); |
| 288 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 1); |
| 289 | } |
| 290 | |
| 291 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 292 | const Interest& interest = face.sentInterests[1]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%00"); |
| 294 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false); |
| 295 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 0); |
| 296 | } |
| 297 | |
| 298 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 299 | const Interest& interest = face.sentInterests[2]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 300 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%01"); |
| 301 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false); |
| 302 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 0); |
| 303 | } |
| 304 | |
| 305 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 306 | const Interest& interest = face.sentInterests[3]; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 307 | BOOST_CHECK_EQUAL(interest.getName(), "/hello/world/version0/%00%02"); |
| 308 | BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false); |
| 309 | BOOST_CHECK_EQUAL(interest.getChildSelector(), 0); |
| 310 | } |
| 311 | } |
| 312 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 313 | BOOST_FIXTURE_TEST_CASE(MultipleSegmentFetching, Fixture) |
| 314 | { |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 315 | DummyValidator acceptValidator; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 316 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 317 | acceptValidator, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 318 | bind(&Fixture::onComplete, this, _1), |
| 319 | bind(&Fixture::onError, this, _1)); |
| 320 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 321 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 322 | |
| 323 | for (uint64_t i = 0; i < 400; i++) { |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 324 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 325 | face.receive(*makeDataSegment("/hello/world/version0", i, false)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 326 | } |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 327 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 328 | face.receive(*makeDataSegment("/hello/world/version0", 400, true)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 329 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 330 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 331 | |
| 332 | BOOST_CHECK_EQUAL(nErrors, 0); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 333 | BOOST_CHECK_EQUAL(nData, 1); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 334 | } |
| 335 | |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 336 | BOOST_FIXTURE_TEST_CASE(DuplicateNack, Fixture) |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 337 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 338 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 339 | make_shared<DummyValidator>(true), |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 340 | bind(&Fixture::onComplete, this, _1), |
| 341 | bind(&Fixture::onError, this, _1)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 342 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 343 | |
| 344 | // receive nack for the original interest |
| 345 | nackLastInterest(lp::NackReason::DUPLICATE); |
| 346 | |
| 347 | // receive nack due to Duplication for the reexpressed interests |
| 348 | for (uint32_t i = 1; i <= SegmentFetcher::MAX_INTEREST_REEXPRESS; ++i) { |
| 349 | nackLastInterest(lp::NackReason::DUPLICATE); |
| 350 | } |
| 351 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 352 | BOOST_CHECK_EQUAL(face.sentInterests.size(), (SegmentFetcher::MAX_INTEREST_REEXPRESS + 1)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 353 | BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::NACK_ERROR)); |
| 354 | } |
| 355 | |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 356 | BOOST_FIXTURE_TEST_CASE(CongestionNack, Fixture) |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 357 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 358 | SegmentFetcher::fetch(face, Interest("/hello/world", time::seconds(1000)), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 359 | make_shared<DummyValidator>(true), |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 360 | bind(&Fixture::onComplete, this, _1), |
| 361 | bind(&Fixture::onError, this, _1)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 362 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 363 | |
| 364 | // receive nack for the original interest |
| 365 | nackLastInterest(lp::NackReason::CONGESTION); |
| 366 | |
| 367 | // receive nack due to Congestion for the reexpressed interests |
| 368 | for (uint32_t i = 1; i <= SegmentFetcher::MAX_INTEREST_REEXPRESS; ++i) { |
| 369 | nackLastInterest(lp::NackReason::CONGESTION); |
| 370 | } |
| 371 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 372 | BOOST_CHECK_EQUAL(face.sentInterests.size(), (SegmentFetcher::MAX_INTEREST_REEXPRESS + 1)); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(lastError, static_cast<uint32_t>(SegmentFetcher::NACK_ERROR)); |
| 374 | } |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 375 | |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 376 | BOOST_FIXTURE_TEST_CASE(SegmentZero, Fixture) |
| 377 | { |
| 378 | int nNacks = 2; |
| 379 | |
| 380 | ndn::Name interestName("ndn:/A"); |
| 381 | SegmentFetcher::fetch(face, |
| 382 | Interest(interestName), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 383 | make_shared<DummyValidator>(true), |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 384 | bind(&Fixture::onComplete, this, _1), |
| 385 | bind(&Fixture::onError, this, _1)); |
| 386 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 387 | advanceClocks(time::milliseconds(1000)); |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 388 | |
| 389 | for (uint64_t segmentNo = 0; segmentNo <= 3; segmentNo++) { |
| 390 | if (segmentNo == 1) { |
| 391 | while (nNacks--) { |
| 392 | nackLastInterest(lp::NackReason::CONGESTION); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 393 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | auto data = makeDataSegment(interestName, segmentNo, segmentNo == 3); |
| 398 | face.receive(*data); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 399 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // Total number of sent interests should be 6: one interest for segment zero and segment one each, |
| 403 | // two re-expressed interests for segment one after getting nack twice, and two interests for |
| 404 | // segment two and three |
| 405 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 6); |
| 406 | |
| 407 | BOOST_CHECK_EQUAL(face.sentInterests[0].getName(), ndn::Name("ndn:/A")); |
| 408 | BOOST_CHECK_EQUAL(face.sentInterests[1].getName(), ndn::Name("ndn:/A/%00%01")); |
| 409 | BOOST_CHECK_EQUAL(face.sentInterests[2].getName(), ndn::Name("ndn:/A/%00%01")); |
| 410 | BOOST_CHECK_EQUAL(face.sentInterests[3].getName(), ndn::Name("ndn:/A/%00%01")); |
| 411 | BOOST_CHECK_EQUAL(face.sentInterests[4].getName(), ndn::Name("ndn:/A/%00%02")); |
| 412 | BOOST_CHECK_EQUAL(face.sentInterests[5].getName(), ndn::Name("ndn:/A/%00%03")); |
| 413 | } |
| 414 | |
| 415 | BOOST_FIXTURE_TEST_CASE(ZeroComponentName, Fixture) |
| 416 | { |
| 417 | SegmentFetcher::fetch(face, Interest("ndn:/"), |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame^] | 418 | make_shared<DummyValidator>(true), |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 419 | bind(&Fixture::onComplete, this, _1), |
| 420 | bind(&Fixture::onError, this, _1)); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 421 | advanceClocks(time::milliseconds(10)); |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 422 | nackLastInterest(lp::NackReason::DUPLICATE); |
| 423 | face.receive(*makeDataSegment("/hello/world", 0, true)); |
| 424 | |
| 425 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 2); |
| 426 | BOOST_CHECK_EQUAL(face.sentInterests[0].getName(), ndn::Name("ndn:/")); |
| 427 | BOOST_CHECK_EQUAL(face.sentInterests[1].getName(), ndn::Name("ndn:/")); |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 428 | BOOST_REQUIRE_EQUAL(nData, 1); |
Muktadir R Chowdhury | 2bc2df0 | 2016-04-05 16:55:41 -0500 | [diff] [blame] | 429 | } |
| 430 | |
Junxiao Shi | d5827ce | 2016-07-14 20:49:37 +0000 | [diff] [blame] | 431 | BOOST_AUTO_TEST_SUITE_END() // TestSegmentFetcher |
| 432 | BOOST_AUTO_TEST_SUITE_END() // Util |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 433 | |
| 434 | } // namespace tests |
| 435 | } // namespace util |
| 436 | } // namespace ndn |