Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 969cd5a | 2018-04-20 16:27:47 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016-2018, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 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 | |
| 26 | #include "tools/chunks/catchunks/discover-version-fixed.hpp" |
| 27 | |
| 28 | #include "discover-version-fixture.hpp" |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace chunks { |
| 32 | namespace tests { |
| 33 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 34 | class DiscoverVersionFixedFixture : public DiscoverVersionFixture |
| 35 | { |
| 36 | public: |
| 37 | DiscoverVersionFixedFixture() |
| 38 | : DiscoverVersionFixture(makeOptions()) |
| 39 | , version(1449227841747) |
| 40 | { |
| 41 | setDiscover(make_unique<DiscoverVersionFixed>(Name(name).appendVersion(version), |
| 42 | face, makeOptions())); |
| 43 | } |
| 44 | |
| 45 | protected: |
Davide Pesavento | 969cd5a | 2018-04-20 16:27:47 -0400 | [diff] [blame] | 46 | uint64_t version; // version to find |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | BOOST_AUTO_TEST_SUITE(Chunks) |
| 50 | BOOST_AUTO_TEST_SUITE(TestDiscoverVersionFixed) |
| 51 | |
| 52 | BOOST_FIXTURE_TEST_CASE(RequestedVersionAvailable, DiscoverVersionFixedFixture) |
| 53 | { |
| 54 | discover->run(); |
| 55 | advanceClocks(io, time::nanoseconds(1), 1); |
| 56 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 57 | |
| 58 | face.receive(*makeDataWithVersion(version)); |
| 59 | |
| 60 | advanceClocks(io, time::nanoseconds(1), 1); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(isDiscoveryFinished, true); |
| 63 | BOOST_CHECK_EQUAL(discoveredVersion, version); |
| 64 | |
| 65 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 66 | auto lastInterest = face.sentInterests.back(); |
| 67 | BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0); |
| 68 | BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2); |
| 69 | BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2); |
| 70 | BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh); |
| 71 | } |
| 72 | |
| 73 | BOOST_FIXTURE_TEST_CASE(NoVersionsAvailable, DiscoverVersionFixedFixture) |
| 74 | { |
| 75 | discover->run(); |
| 76 | advanceClocks(io, time::nanoseconds(1), 1); |
| 77 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 78 | |
| 79 | for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) { |
| 80 | advanceClocks(io, interestLifetime, 1); |
| 81 | BOOST_CHECK_EQUAL(isDiscoveryFinished, false); |
| 82 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 2 + retries); |
| 83 | } |
| 84 | |
| 85 | for (const auto& lastInterest : face.sentInterests) { |
| 86 | BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0); |
| 87 | BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2); |
| 88 | BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2); |
| 89 | BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh); |
| 90 | BOOST_CHECK_EQUAL(lastInterest.getName().equals(Name(name).appendVersion(version)), true); |
| 91 | } |
| 92 | |
| 93 | advanceClocks(io, interestLifetime, 1); |
| 94 | BOOST_CHECK_EQUAL(isDiscoveryFinished, true); |
| 95 | // check if discovered version is the default value |
| 96 | BOOST_CHECK_EQUAL(discoveredVersion, 0); |
| 97 | BOOST_CHECK_EQUAL(face.sentInterests.size(), maxRetriesOnTimeoutOrNack + 1); |
| 98 | } |
| 99 | |
| 100 | BOOST_FIXTURE_TEST_CASE(DataNotSegment, DiscoverVersionFixedFixture) |
| 101 | { |
| 102 | discover->run(); |
| 103 | advanceClocks(io, time::nanoseconds(1), 1); |
| 104 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 105 | |
| 106 | std::vector<std::string> randomStrings { |
| 107 | "", |
| 108 | "abcdefg", |
| 109 | "12345", |
| 110 | "qr%67a3%4e" |
| 111 | }; |
| 112 | |
| 113 | Exclude expectedExclude; |
| 114 | for (size_t retries = 0; retries < randomStrings.size(); ++retries) { |
| 115 | auto data = make_shared<Data>(Name(name).appendVersion(version).append(randomStrings[retries])); |
Davide Pesavento | 969cd5a | 2018-04-20 16:27:47 -0400 | [diff] [blame] | 116 | data->setFinalBlock(name::Component::fromSegment(0)); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 117 | data = signData(data); |
| 118 | |
| 119 | face.receive(*data); |
| 120 | advanceClocks(io, time::nanoseconds(1), 1); |
| 121 | |
| 122 | BOOST_CHECK_EQUAL(isDiscoveryFinished, false); |
| 123 | |
| 124 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1 + retries); |
| 125 | auto lastInterest = face.sentInterests.back(); |
| 126 | if (randomStrings[retries] != "") |
| 127 | expectedExclude.excludeOne(name::Component::fromEscapedString(randomStrings[retries])); |
| 128 | BOOST_CHECK_EQUAL(lastInterest.getExclude(), expectedExclude); |
| 129 | BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2); |
| 130 | BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2); |
| 131 | BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh); |
| 132 | } |
| 133 | |
| 134 | advanceClocks(io, interestLifetime, maxRetriesOnTimeoutOrNack + 1); |
| 135 | BOOST_CHECK_EQUAL(isDiscoveryFinished, true); |
| 136 | // check if discovered version is the default value |
| 137 | BOOST_CHECK_EQUAL(discoveredVersion, 0); |
| 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionFixed |
| 141 | BOOST_AUTO_TEST_SUITE_END() // Chunks |
| 142 | |
| 143 | } // namespace tests |
| 144 | } // namespace chunks |
| 145 | } // namespace ndn |