blob: 630594bb85030f986bf7e01d49300a8e296a42f9 [file] [log] [blame]
Chavoosh Ghasemid8f9af22019-02-28 09:47:26 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2016-2019, 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 Chavoosh Ghasemi
24 */
25
26#include "tools/chunks/catchunks/discover-version-realtime.hpp"
27
28#include "discover-version-fixture.hpp"
29#include "tests/identity-management-fixture.hpp"
30
31#include <ndn-cxx/metadata-object.hpp>
32
33
34namespace ndn {
35namespace chunks {
36namespace tests {
37
38class DiscoverVersionRealtimeFixture : public DiscoverVersionFixture,
39 public IdentityManagementFixture,
40 protected DiscoverVersionRealtimeOptions
41{
42public:
43 typedef DiscoverVersionRealtimeOptions Options;
44
45public:
46 explicit
47 DiscoverVersionRealtimeFixture(const Options& opt = makeOptionsRealtime())
48 : chunks::Options(opt)
49 , DiscoverVersionFixture(opt)
50 , Options(opt)
51 {
52 setDiscover(make_unique<DiscoverVersionRealtime>(Name(name), face, opt));
53 }
54
55protected:
56 static Options
57 makeOptionsRealtime()
58 {
59 Options options;
60 options.isVerbose = false;
61 options.maxRetriesOnTimeoutOrNack = 3;
62 return options;
63 }
64};
65
66BOOST_AUTO_TEST_SUITE(Chunks)
67BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersionRealtime, DiscoverVersionRealtimeFixture)
68
69BOOST_AUTO_TEST_CASE(Success)
70{
71 // issue a discovery Interest to learn Data version
72 discover->run();
73 advanceClocks(io, time::nanoseconds(1), 1);
74
75 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
76
77 Interest discoveryInterest = MetadataObject::makeDiscoveryInterest(name);
78 auto lastInterest = face.sentInterests.back();
79 BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
80
81 // Send back a metadata packet with a valid versioned name
82 uint64_t version = 1449241767037;
83
84 MetadataObject mobject;
85 mobject.setVersionedName(Name(name).appendVersion(version));
86 face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
87 advanceClocks(io, time::nanoseconds(1), 1);
88
89 BOOST_CHECK(isDiscoveryFinished);
90 BOOST_CHECK_EQUAL(discoveredVersion, version);
91}
92
93BOOST_AUTO_TEST_CASE(InvalidVersionedName)
94{
95 // issue a discovery Interest to learn Data version
96 discover->run();
97 advanceClocks(io, time::nanoseconds(1), 1);
98
99 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
100
101 // Send back a metadata packet with an invalid versioned name
102 MetadataObject mobject;
103 mobject.setVersionedName(name);
104 face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
105
106 // finish discovery process without a resolved version number
107 BOOST_CHECK(isDiscoveryFinished);
108 BOOST_CHECK_EQUAL(discoveredVersion, 0);
109}
110
111BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
112{
113 // issue a discovery Interest to learn Data version
114 discover->run();
115 advanceClocks(io, time::nanoseconds(1), 1);
116
117 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
118
119 // Send back an invalid metadata packet
120 Data data(face.sentInterests.back().getName());
121 data.setContentType(tlv::ContentType_Key);
122 face.receive(signData(data));
123
124 // finish discovery process without a resolved version number
125 BOOST_CHECK(isDiscoveryFinished);
126 BOOST_CHECK_EQUAL(discoveredVersion, 0);
127}
128
129BOOST_AUTO_TEST_CASE(Timeout)
130{
131 // issue a discovery Interest to learn Data version
132 discover->run();
133 advanceClocks(io, time::nanoseconds(1), 1);
134
135 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
136
137 // timeout discovery Interests
138 for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) {
139 advanceClocks(io, interestLifetime, 1);
140
141 BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
142 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
143 }
144
145 // timeout the last sent Interest
146 advanceClocks(io, interestLifetime, 1);
147
148 // finish discovery process without a resolved version number
149 BOOST_CHECK(isDiscoveryFinished);
150 BOOST_CHECK_EQUAL(discoveredVersion, 0);
151}
152
153BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionRealtime
154BOOST_AUTO_TEST_SUITE_END() // Chunks
155
156} // namespace tests
157} // namespace chunks
158} // namespace ndn