catchunks: remove modular version discovery
refs: #4832, #4556
Change-Id: I99b4f42d1457c74321c9b6ae84f793a93c4c1436
diff --git a/tests/chunks/consumer.t.cpp b/tests/chunks/consumer.t.cpp
index f6d3e8a..84dcb5b 100644
--- a/tests/chunks/consumer.t.cpp
+++ b/tests/chunks/consumer.t.cpp
@@ -133,43 +133,6 @@
BOOST_CHECK(output.is_equal(testStrings[2]));
}
-class DiscoverVersionDummy : public DiscoverVersion
-{
-public:
- DiscoverVersionDummy(const Name& prefix, Face& face, const Options& options)
- : Options(options)
- , DiscoverVersion(prefix, face)
- , isDiscoverRunning(false)
- , m_prefix(prefix)
- {
- }
-
- void
- run() final
- {
- isDiscoverRunning = true;
-
- auto interest = makeInterest(m_prefix, true);
- expressInterest(*interest, 1, 1);
- }
-
-private:
- void
- handleData(const Interest& interest, const Data& data) final
- {
- if (!data.getName().empty() && data.getName()[-1].isVersion())
- this->emitSignal(onDiscoverySuccess, data.getName());
- else
- this->emitSignal(onDiscoveryFailure, "Invalid versioned name");
- }
-
-public:
- bool isDiscoverRunning;
-
-private:
- Name m_prefix;
-};
-
class PipelineInterestsDummy : public PipelineInterests
{
public:
@@ -201,17 +164,16 @@
util::DummyClientFace face(io);
Consumer consumer(security::v2::getAcceptAllValidator());
- Name prefix("/ndn/chunks/test");
- auto discover = make_unique<DiscoverVersionDummy>(prefix, face, Options());
+ Name prefix = Name("/ndn/chunks/test").appendVersion(1);
+ auto discover = make_unique<DiscoverVersion>(prefix, face, Options());
auto pipeline = make_unique<PipelineInterestsDummy>(face);
- auto discoverPtr = discover.get();
auto pipelinePtr = pipeline.get();
consumer.run(std::move(discover), std::move(pipeline));
- BOOST_CHECK_EQUAL(discoverPtr->isDiscoverRunning, true);
this->advanceClocks(io, time::nanoseconds(1));
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+ // no discovery interest is issued
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
// this Data packet answers the discovery Interest, so it must end with a version number
auto data = makeData(prefix.appendVersion(0));
diff --git a/tests/chunks/discover-version-fixed.t.cpp b/tests/chunks/discover-version-fixed.t.cpp
deleted file mode 100644
index 2017c52..0000000
--- a/tests/chunks/discover-version-fixed.t.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2018, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#include "tools/chunks/catchunks/discover-version-fixed.hpp"
-
-#include "discover-version-fixture.hpp"
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-class DiscoverVersionFixedFixture : public DiscoverVersionFixture
-{
-public:
- DiscoverVersionFixedFixture()
- : DiscoverVersionFixture(makeOptions())
- , version(1449227841747)
- {
- setDiscover(make_unique<DiscoverVersionFixed>(Name(name).appendVersion(version),
- face, makeOptions()));
- }
-
-protected:
- uint64_t version; // version to find
-};
-
-BOOST_AUTO_TEST_SUITE(Chunks)
-BOOST_AUTO_TEST_SUITE(TestDiscoverVersionFixed)
-
-BOOST_FIXTURE_TEST_CASE(RequestedVersionAvailable, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- face.receive(*makeDataWithVersion(version));
-
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- BOOST_CHECK_EQUAL(discoveredVersion, version);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- auto lastInterest = face.sentInterests.back();
- BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
-}
-
-BOOST_FIXTURE_TEST_CASE(NoVersionsAvailable, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, interestLifetime, 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 2 + retries);
- }
-
- for (const auto& lastInterest : face.sentInterests) {
- BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
- BOOST_CHECK_EQUAL(lastInterest.getName().equals(Name(name).appendVersion(version)), true);
- }
-
- advanceClocks(io, interestLifetime, 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- // check if discovered version is the default value
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
- BOOST_CHECK_EQUAL(face.sentInterests.size(), maxRetriesOnTimeoutOrNack + 1);
-}
-
-BOOST_FIXTURE_TEST_CASE(DataNotSegment, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- std::vector<std::string> randomStrings {
- "",
- "abcdefg",
- "12345",
- "qr%67a3%4e"
- };
-
- Exclude expectedExclude;
- for (size_t retries = 0; retries < randomStrings.size(); ++retries) {
- auto data = make_shared<Data>(Name(name).appendVersion(version).append(randomStrings[retries]));
- data->setFinalBlock(name::Component::fromSegment(0));
- data = signData(data);
-
- face.receive(*data);
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1 + retries);
- auto lastInterest = face.sentInterests.back();
- if (randomStrings[retries] != "")
- expectedExclude.excludeOne(name::Component::fromEscapedString(randomStrings[retries]));
- BOOST_CHECK_EQUAL(lastInterest.getExclude(), expectedExclude);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
- }
-
- advanceClocks(io, interestLifetime, maxRetriesOnTimeoutOrNack + 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- // check if discovered version is the default value
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionFixed
-BOOST_AUTO_TEST_SUITE_END() // Chunks
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
diff --git a/tests/chunks/discover-version-fixture.hpp b/tests/chunks/discover-version-fixture.hpp
deleted file mode 100644
index d42429a..0000000
--- a/tests/chunks/discover-version-fixture.hpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#ifndef NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
-#define NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
-
-#include "tools/chunks/catchunks/discover-version.hpp"
-
-#include "tests/test-common.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-using namespace ndn::tests;
-
-class DiscoverVersionFixture : public UnitTestTimeFixture, virtual protected Options
-{
-public:
- DiscoverVersionFixture(const Options& options)
- : Options(options)
- , face(io)
- , name("/ndn/chunks/test")
- , discoveredVersion(0)
- , isDiscoveryFinished(false)
- {
- }
-
- virtual
- ~DiscoverVersionFixture() = default;
-
-protected:
- void
- setDiscover(unique_ptr<DiscoverVersion> disc)
- {
- discover = std::move(disc);
- discover->onDiscoverySuccess.connect(bind(&DiscoverVersionFixture::onSuccess, this, _1));
- discover->onDiscoveryFailure.connect(bind(&DiscoverVersionFixture::onFailure, this, _1));
- }
-
- shared_ptr<Data>
- makeDataWithVersion(uint64_t version) const
- {
- auto data = make_shared<Data>(Name(name).appendVersion(version).appendSegment(0));
- data->setFinalBlock(name::Component::fromSegment(0));
- return signData(data);
- }
-
- static Options
- makeOptions()
- {
- Options options;
- options.isVerbose = false;
- options.interestLifetime = time::seconds(1);
- options.maxRetriesOnTimeoutOrNack = 15;
- return options;
- }
-
- virtual void
- onSuccess(const Name& versionedName)
- {
- isDiscoveryFinished = true;
-
- BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
- discoveredVersion = versionedName[-1].toVersion();
- }
-
- virtual void
- onFailure(const std::string& reason)
- {
- isDiscoveryFinished = true;
- }
-
-protected:
- boost::asio::io_service io;
- util::DummyClientFace face;
- Name name;
- unique_ptr<DiscoverVersion> discover;
- uint64_t discoveredVersion;
- bool isDiscoveryFinished;
-};
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
-
-#endif // NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
diff --git a/tests/chunks/discover-version-realtime.t.cpp b/tests/chunks/discover-version-realtime.t.cpp
deleted file mode 100644
index 5bfcfce..0000000
--- a/tests/chunks/discover-version-realtime.t.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Chavoosh Ghasemi
- */
-
-#include "tools/chunks/catchunks/discover-version-realtime.hpp"
-
-#include "discover-version-fixture.hpp"
-#include "tests/identity-management-fixture.hpp"
-
-#include <ndn-cxx/metadata-object.hpp>
-
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-class DiscoverVersionRealtimeFixture : public DiscoverVersionFixture,
- public IdentityManagementFixture,
- protected DiscoverVersionRealtimeOptions
-{
-public:
- typedef DiscoverVersionRealtimeOptions Options;
-
-public:
- explicit
- DiscoverVersionRealtimeFixture(const Options& opt = makeOptionsRealtime())
- : chunks::Options(opt)
- , DiscoverVersionFixture(opt)
- , Options(opt)
- {
- setDiscover(make_unique<DiscoverVersionRealtime>(Name(name), face, opt));
- }
-
-protected:
- static Options
- makeOptionsRealtime()
- {
- Options options;
- options.isVerbose = false;
- options.maxRetriesOnTimeoutOrNack = 15;
- return options;
- }
-};
-
-BOOST_AUTO_TEST_SUITE(Chunks)
-BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersionRealtime, DiscoverVersionRealtimeFixture)
-
-BOOST_AUTO_TEST_CASE(Success)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- Interest discoveryInterest = MetadataObject::makeDiscoveryInterest(name);
- auto lastInterest = face.sentInterests.back();
- BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
-
- // Send back a metadata packet with a valid versioned name
- uint64_t version = 1449241767037;
-
- MetadataObject mobject;
- mobject.setVersionedName(Name(name).appendVersion(version));
- face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, version);
-}
-
-BOOST_AUTO_TEST_CASE(InvalidVersionedName)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // Send back a metadata packet with an invalid versioned name
- MetadataObject mobject;
- mobject.setVersionedName(name);
- face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // Send back an invalid metadata packet
- Data data(face.sentInterests.back().getName());
- data.setContentType(tlv::ContentType_Key);
- face.receive(signData(data));
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_CASE(Timeout)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // timeout discovery Interests
- for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, interestLifetime, 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
- }
-
- // timeout the last sent Interest
- advanceClocks(io, interestLifetime, 1);
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionRealtime
-BOOST_AUTO_TEST_SUITE_END() // Chunks
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
diff --git a/tests/chunks/discover-version.t.cpp b/tests/chunks/discover-version.t.cpp
new file mode 100644
index 0000000..266bcf5
--- /dev/null
+++ b/tests/chunks/discover-version.t.cpp
@@ -0,0 +1,206 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2016-2019, Regents of the University of California,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University.
+ *
+ * This file is part of ndn-tools (Named Data Networking Essential Tools).
+ * See AUTHORS.md for complete list of ndn-tools authors and contributors.
+ *
+ * ndn-tools is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Chavoosh Ghasemi
+ */
+
+#include "tools/chunks/catchunks/discover-version.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/metadata-object.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace ndn {
+namespace chunks {
+namespace tests {
+
+using namespace ndn::tests;
+
+class DiscoverVersionFixture : public UnitTestTimeFixture,
+ public IdentityManagementFixture
+{
+public:
+ DiscoverVersionFixture()
+ : face(io)
+ , name("/ndn/chunks/test")
+ , isDiscoveryFinished(false)
+ , version(1449227841747)
+ {
+ opt.interestLifetime = ndn::DEFAULT_INTEREST_LIFETIME;
+ opt.maxRetriesOnTimeoutOrNack = 15;
+ opt.isVerbose = false;
+ }
+
+ void
+ run(const Name& prefix)
+ {
+ BOOST_REQUIRE(!prefix.empty());
+ discover = make_unique<DiscoverVersion>(prefix, face, opt);
+ discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
+ isDiscoveryFinished = true;
+ BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
+ discoveredVersion = versionedName[-1].toVersion();
+ });
+ discover->onDiscoveryFailure.connect([this] (const std::string& reason) {
+ isDiscoveryFinished = true;
+ });
+
+ discover->run();
+ advanceClocks(io, time::nanoseconds(1));
+ }
+
+protected:
+ boost::asio::io_service io;
+ util::DummyClientFace face;
+ Name name;
+ unique_ptr<DiscoverVersion> discover;
+ optional<uint64_t> discoveredVersion;
+ bool isDiscoveryFinished;
+ uint64_t version;
+ Options opt;
+};
+
+BOOST_AUTO_TEST_SUITE(Chunks)
+BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersion, DiscoverVersionFixture)
+
+BOOST_AUTO_TEST_CASE(VersionNumberIsProvided)
+{
+ run(Name(name).appendVersion(version));
+
+ // no version discovery interest is expressed
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_CASE(DiscoverySuccess)
+{
+ // express a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ Interest discoveryInterest = MetadataObject::makeDiscoveryInterest(name);
+ auto lastInterest = face.sentInterests.back();
+ BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
+
+ // Send back a metadata packet with a valid versioned name
+ MetadataObject mobject;
+ mobject.setVersionedName(Name(name).appendVersion(version));
+ face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
+ advanceClocks(io, time::nanoseconds(1));
+
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_CASE(InvalidDiscoveredVersionedName)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // Send back a metadata packet with an invalid versioned name
+ MetadataObject mobject;
+ mobject.setVersionedName(name);
+ face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // Send back an invalid metadata packet
+ Data data(face.sentInterests.back().getName());
+ data.setContentType(tlv::ContentType_Key);
+ face.receive(signData(data));
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(Timeout1)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // timeout discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
+ advanceClocks(io, opt.interestLifetime);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
+ }
+
+ // timeout the last sent Interest
+ advanceClocks(io, opt.interestLifetime);
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(Timeout2)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // timeout discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
+ advanceClocks(io, opt.interestLifetime);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
+ }
+
+ // satisfy the last Interest with a valid metadata packet
+ MetadataObject mobject;
+ mobject.setVersionedName(Name(name).appendVersion(version));
+ face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
+ advanceClocks(io, time::nanoseconds(1));
+
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersion
+BOOST_AUTO_TEST_SUITE_END() // Chunks
+
+} // namespace tests
+} // namespace chunks
+} // namespace ndn
diff --git a/tools/chunks/README.md b/tools/chunks/README.md
index f1cf967..d92710f 100644
--- a/tools/chunks/README.md
+++ b/tools/chunks/README.md
@@ -11,22 +11,15 @@
discovering the latest version of the file, and writes the content of the retrieved file to
the standard output.
-## Version discovery methods in ndncatchunks
+## Version discovery in ndncatchunks
-* `fixed` : sends an Interest attempting to find a data packet with the
- specified prefix and version number. A version component must be present at the
- end of the user-specified NDN name.
-
-* `realtime` : sends discovery Interests to fetch metadata of the solicited content from which
- the data version will be resolved.
- The version number of the solicited content is included in the name of returned
- metadata data packet.
- For more information about the packet format and naming convention of interest and
- data packets for realtime version discovery, please refer to:
+If a version component is present at the end of the user-specified NDN name, the provided version
+number will be used, without any version discovery process. Otherwise, discovery Interest(s) will
+be sent out to fetch metadata of the solicited content from which the Data version will be resolved.
+For more information about the packet format and naming convention of Interest and Data packets of
+version discovery in ndncatchunks, please refer to:
[Realtime Data Retrieval (RDR) protocol wiki page](https://redmine.named-data.net/projects/ndn-tlv/wiki/RDR)
-The default discovery method is `realtime`.
-
## Interest pipeline types in ndncatchunks
* `fixed`: maintains a fixed-size window of Interests in flight; the window size is configurable
@@ -50,40 +43,35 @@
The following command will publish the text of the GPL-3 license under the `/localhost/demo/gpl3`
prefix:
- ndnputchunks ndn:/localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3
+ ndnputchunks /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3
To find the published version you have to start ndnputchunks with the `-p` command line option,
for example:
- ndnputchunks -p ndn:/localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3
+ ndnputchunks -p /localhost/demo/gpl3 < /usr/share/common-licenses/GPL-3
This command will print the published version to the standard output.
-To publish data with a specific version, you must append a version component to the end of the
+To publish Data with a specific version, you must append a version component to the end of the
prefix. The version component must follow the aforementioned NDN naming conventions.
For example, the following command will publish the version `%FD%00%00%01Qc%CF%17v` of the
`/localhost/demo/gpl3` prefix:
- ndnputchunks ndn:/localhost/demo/gpl3/%FD%00%00%01Qc%CF%17v < /usr/share/common-licenses/GPL-3
+ ndnputchunks /localhost/demo/gpl3/%FD%00%00%01Qc%CF%17v < /usr/share/common-licenses/GPL-3
If the version component is not valid, a new well-formed version will be generated and appended
to the supplied NDN name.
-
### Retrieval
To retrieve the latest version of a published file, the following command can be used:
- ndncatchunks ndn:/localhost/demo/gpl3
+ ndncatchunks /localhost/demo/gpl3
-This command will use the realtime method to discover the version number of the file.
+To fetch a specific version of a published file, you can specify the version number at the end of
+the name. For example, if the version is known to be `%FD%00%00%01Qc%CF%17v`, the following command
+will fetch that exact version of the file (without version discovery):
-To fetch a specific version of a published file, you can use the `fixed` version discovery method.
-In this case the version needs to be supplied as part of the name. For example, if the version
-is known to be `%FD%00%00%01Qc%CF%17v`, the following command will fetch that exact version of the
-file:
-
- ndncatchunks -d fixed ndn:/localhost/demo/gpl3/%FD%00%00%01Qc%CF%17v
-
+ ndncatchunks /localhost/demo/gpl3/%FD%00%00%01Qc%CF%17v
For more information, run the programs with `--help` as argument.
diff --git a/tools/chunks/catchunks/discover-version-fixed.cpp b/tools/chunks/catchunks/discover-version-fixed.cpp
deleted file mode 100644
index c122d2f..0000000
--- a/tools/chunks/catchunks/discover-version-fixed.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#include "discover-version-fixed.hpp"
-
-namespace ndn {
-namespace chunks {
-
-DiscoverVersionFixed::DiscoverVersionFixed(const Name& prefix, Face& face, const Options& options)
- : Options(options)
- , DiscoverVersion(prefix, face)
-{
-}
-
-void
-DiscoverVersionFixed::run()
-{
- Interest interest(m_prefix);
- interest.setInterestLifetime(interestLifetime);
- interest.setMustBeFresh(mustBeFresh);
- interest.setMaxSuffixComponents(2);
- interest.setMinSuffixComponents(2);
-
- expressInterest(interest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
-}
-
-void
-DiscoverVersionFixed::handleData(const Interest& interest, const Data& data)
-{
- if (isVerbose)
- std::cerr << "Data: " << data << std::endl;
-
- // data name must end with a segment number, preceded by a version number
- if (data.getName().size() >= 2 &&
- data.getName()[-1].isSegment() &&
- data.getName()[-2].isVersion()) {
- if (isVerbose)
- std::cerr << "Found data with the requested version: " << data.getName()[-2] << std::endl;
-
- this->emitSignal(onDiscoverySuccess, data.getName().getPrefix(-1));
- }
- else {
- // data isn't a valid segment, add to the exclude list
- m_strayExcludes.excludeOne(data.getName()[-1]);
- Interest newInterest(interest);
- newInterest.refreshNonce();
- newInterest.setExclude(m_strayExcludes);
-
- expressInterest(newInterest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
- }
-}
-
-} // namespace chunks
-} // namespace ndn
diff --git a/tools/chunks/catchunks/discover-version-fixed.hpp b/tools/chunks/catchunks/discover-version-fixed.hpp
deleted file mode 100644
index 2514098..0000000
--- a/tools/chunks/catchunks/discover-version-fixed.hpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2017, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_FIXED_HPP
-#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_FIXED_HPP
-
-#include "discover-version.hpp"
-
-namespace ndn {
-namespace chunks {
-
-/**
- * @brief Service to retrieve a specific version segment. The version is specified in the prefix
- *
- * Send a request of a specific version and expect to be answered with one segment.
- *
- * The received name component after version can be an invalid segment number, this component will
- * be excluded in the next interests. In the unlikely case that there are too many excluded
- * components such that the Interest cannot fit in ndn::MAX_NDN_PACKET_SIZE, the discovery
- * procedure will throw Face::Error.
- *
- * DiscoverVersionFixed's user is notified once after one segment with the user specified version
- * is found or on failure to find any Data version.
- */
-class DiscoverVersionFixed : public DiscoverVersion
-{
-public:
- /**
- * @brief create a DiscoverVersionFixed service
- */
- DiscoverVersionFixed(const Name& prefix, Face& face, const Options& options);
-
- /**
- * @brief identify the latest Data version published.
- */
- void
- run() final;
-
-private:
- void
- handleData(const Interest& interest, const Data& data) final;
-
-private:
- Exclude m_strayExcludes;
-};
-
-} // namespace chunks
-} // namespace ndn
-
-#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_FIXED_HPP
diff --git a/tools/chunks/catchunks/discover-version-realtime.cpp b/tools/chunks/catchunks/discover-version-realtime.cpp
deleted file mode 100644
index 7175211..0000000
--- a/tools/chunks/catchunks/discover-version-realtime.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Chavoosh Ghasemi <chghasemi@cs.arizona.edu>
- */
-
-#include "discover-version-realtime.hpp"
-
-#include <ndn-cxx/metadata-object.hpp>
-
-namespace ndn {
-namespace chunks {
-
-DiscoverVersionRealtime::DiscoverVersionRealtime(const Name& prefix,
- Face& face,
- const Options& options)
- : chunks::Options(options)
- , DiscoverVersion(prefix, face)
- , Options(options)
-{
-}
-
-void
-DiscoverVersionRealtime::run()
-{
- expressInterest(MetadataObject::makeDiscoveryInterest(m_prefix)
- .setInterestLifetime(discoveryTimeout),
- maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
-}
-
-void
-DiscoverVersionRealtime::handleData(const Interest& interest, const Data& data)
-{
- if (isVerbose)
- std::cerr << "Data: " << data << std::endl;
-
- // make a metadata object from received metadata packet
- MetadataObject mobject;
- try {
- mobject = MetadataObject(data);
- }
- catch (const tlv::Error& e) {
- this->emitSignal(onDiscoveryFailure, "Invalid metadata packet: "s + e.what());
- return;
- }
-
- if (mobject.getVersionedName().empty() || !mobject.getVersionedName()[-1].isVersion()) {
- this->emitSignal(onDiscoveryFailure, mobject.getVersionedName().toUri() +
- " is not a valid versioned name");
- return;
- }
-
- if (isVerbose) {
- std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1].toVersion() << std::endl;
- }
- this->emitSignal(onDiscoverySuccess, mobject.getVersionedName());
-}
-
-} // namespace chunks
-} // namespace ndn
diff --git a/tools/chunks/catchunks/discover-version-realtime.hpp b/tools/chunks/catchunks/discover-version-realtime.hpp
deleted file mode 100644
index 2e3f975..0000000
--- a/tools/chunks/catchunks/discover-version-realtime.hpp
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Chavoosh Ghasemi <chghasemi@cs.arizona.edu>
- */
-
-#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_REALTIME_HPP
-#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_REALTIME_HPP
-
-#include "discover-version.hpp"
-
-namespace ndn {
-namespace chunks {
-
-/**
- * @brief Options for discover version realtime
- *
- * The canonical name to use is DiscoverVersionRealtime::Options
- */
-class DiscoverVersionRealtimeOptions : public virtual Options
-{
-public:
- explicit
- DiscoverVersionRealtimeOptions(const Options& opts = Options())
- : Options(opts)
- {
- }
-
-public:
- time::milliseconds discoveryTimeout{DEFAULT_INTEREST_LIFETIME}; ///< timeout for version discovery
-};
-
-/**
- * @brief Service for discovering Data version by sending discovery interests
- *
- * This service employs RDR-style metadata class for version discovery.
- * @see https://redmine.named-data.net/projects/ndn-tlv/wiki/RDR
- */
-class DiscoverVersionRealtime : public DiscoverVersion, protected DiscoverVersionRealtimeOptions
-{
-public:
- typedef DiscoverVersionRealtimeOptions Options;
-
-public:
- /**
- * @param prefix Name of solicited data
- * @param face The face through which discovery Interests are expressed
- * @param options Additional information about the service
- */
- DiscoverVersionRealtime(const Name& prefix, Face& face, const Options& options);
-
- /**
- * @brief Send a discovery Interest out
- */
- void
- run() final;
-
-private:
- void
- handleData(const Interest& interest, const Data& data) final;
-};
-
-} // namespace chunks
-} // namespace ndn
-
-#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_REALTIME_HPP
diff --git a/tools/chunks/catchunks/discover-version.cpp b/tools/chunks/catchunks/discover-version.cpp
index 3a4309c..7ac5195 100644
--- a/tools/chunks/catchunks/discover-version.cpp
+++ b/tools/chunks/catchunks/discover-version.cpp
@@ -23,42 +23,73 @@
* @author Wentao Shang
* @author Steve DiBenedetto
* @author Andrea Tosatto
+ * @author Chavoosh Ghasemi
*/
#include "discover-version.hpp"
#include "data-fetcher.hpp"
+#include <ndn-cxx/metadata-object.hpp>
+
namespace ndn {
namespace chunks {
-DiscoverVersion::DiscoverVersion(const Name& prefix, Face& face)
- : m_prefix(prefix)
+DiscoverVersion::DiscoverVersion(const Name& prefix, Face& face, const Options& options)
+ : chunks::Options(options)
+ , m_prefix(prefix)
, m_face(face)
{
}
-DiscoverVersion::~DiscoverVersion() = default;
-
void
-DiscoverVersion::expressInterest(const Interest& interest, int maxRetriesNack, int maxRetriesTimeout)
+DiscoverVersion::run()
{
- fetcher = DataFetcher::fetch(m_face, interest, maxRetriesNack, maxRetriesTimeout,
- bind(&DiscoverVersion::handleData, this, _1, _2),
- bind(&DiscoverVersion::handleNack, this, _1, _2),
- bind(&DiscoverVersion::handleTimeout, this, _1, _2),
- isVerbose);
+ if (!m_prefix.empty() && m_prefix[-1].isVersion()) {
+ onDiscoverySuccess(m_prefix);
+ return;
+ }
+
+ Interest interest = MetadataObject::makeDiscoveryInterest(m_prefix)
+ .setInterestLifetime(interestLifetime);
+
+ m_fetcher = DataFetcher::fetch(m_face, interest,
+ maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack,
+ bind(&DiscoverVersion::handleData, this, _1, _2),
+ [this] (const Interest& interest, const std::string& reason) {
+ onDiscoveryFailure(reason);
+ },
+ [this] (const Interest& interest, const std::string& reason) {
+ onDiscoveryFailure(reason);
+ },
+ isVerbose);
}
void
-DiscoverVersion::handleNack(const Interest& interest, const std::string& reason)
+DiscoverVersion::handleData(const Interest& interest, const Data& data)
{
- onDiscoveryFailure(reason);
-}
+ if (isVerbose)
+ std::cerr << "Data: " << data << std::endl;
-void
-DiscoverVersion::handleTimeout(const Interest& interest, const std::string& reason)
-{
- onDiscoveryFailure(reason);
+ // make a metadata object from received metadata packet
+ MetadataObject mobject;
+ try {
+ mobject = MetadataObject(data);
+ }
+ catch (const tlv::Error& e) {
+ onDiscoveryFailure("Invalid metadata packet: "s + e.what());
+ return;
+ }
+
+ if (mobject.getVersionedName().empty() || !mobject.getVersionedName()[-1].isVersion()) {
+ onDiscoveryFailure(mobject.getVersionedName().toUri() + " is not a valid versioned name");
+ return;
+ }
+
+ if (isVerbose) {
+ std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << std::endl;
+ }
+
+ onDiscoverySuccess(mobject.getVersionedName());
}
} // namespace chunks
diff --git a/tools/chunks/catchunks/discover-version.hpp b/tools/chunks/catchunks/discover-version.hpp
index d29f94a..5049cc2 100644
--- a/tools/chunks/catchunks/discover-version.hpp
+++ b/tools/chunks/catchunks/discover-version.hpp
@@ -23,6 +23,7 @@
* @author Wentao Shang
* @author Steve DiBenedetto
* @author Andrea Tosatto
+ * @author Chavoosh Ghasemi
*/
#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP
@@ -53,43 +54,28 @@
/**
* @brief Signal emitted when a failure occurs.
*/
- signal::Signal<DiscoverVersion, const std::string&> onDiscoveryFailure;
-
- DECLARE_SIGNAL_EMIT(onDiscoverySuccess)
- DECLARE_SIGNAL_EMIT(onDiscoveryFailure)
+ signal::Signal<DiscoverVersion, std::string> onDiscoveryFailure;
public:
/**
* @brief create a DiscoverVersion service
*/
- DiscoverVersion(const Name& prefix, Face& face);
-
- virtual
- ~DiscoverVersion();
+ DiscoverVersion(const Name& prefix, Face& face, const Options& options);
/**
* @brief identify the latest Data version published.
*/
- virtual void
- run() = 0;
-
-protected:
void
- expressInterest(const Interest& interest, int maxRetriesNack, int maxRetriesTimeout);
+ run();
- virtual void
- handleData(const Interest& interest, const Data& data) = 0;
+private:
+ void
+ handleData(const Interest& interest, const Data& data);
- virtual void
- handleNack(const Interest& interest, const std::string& reason);
-
- virtual void
- handleTimeout(const Interest& interest, const std::string& reason);
-
-protected:
+private:
const Name m_prefix;
Face& m_face;
- shared_ptr<DataFetcher> fetcher;
+ shared_ptr<DataFetcher> m_fetcher;
};
} // namespace chunks
diff --git a/tools/chunks/catchunks/main.cpp b/tools/chunks/catchunks/main.cpp
index 718fb49..af345cf 100644
--- a/tools/chunks/catchunks/main.cpp
+++ b/tools/chunks/catchunks/main.cpp
@@ -30,8 +30,7 @@
*/
#include "consumer.hpp"
-#include "discover-version-fixed.hpp"
-#include "discover-version-realtime.hpp"
+#include "discover-version.hpp"
#include "options.hpp"
#include "pipeline-interests-aimd.hpp"
#include "pipeline-interests-cubic.hpp"
@@ -51,10 +50,8 @@
{
std::string programName(argv[0]);
Options options;
- std::string discoverType("realtime");
std::string pipelineType("cubic");
size_t maxPipelineSize(1);
- int64_t discoveryTimeoutMs(DEFAULT_INTEREST_LIFETIME.count());
std::string uri;
// congestion control parameters, CWA refers to conservative window adaptation,
@@ -70,8 +67,6 @@
po::options_description basicDesc("Basic Options");
basicDesc.add_options()
("help,h", "print this help message and exit")
- ("discover-version,d", po::value<std::string>(&discoverType)->default_value(discoverType),
- "version discovery algorithm to use; valid values are: 'fixed', 'realtime'")
("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
"type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
@@ -84,11 +79,6 @@
("version,V", "print program version and exit")
;
- po::options_description realDiscoveryDesc("Realtime version discovery options");
- realDiscoveryDesc.add_options()
- ("discovery-timeout,t", po::value<int64_t>(&discoveryTimeoutMs)->default_value(discoveryTimeoutMs),
- "discovery timeout (in milliseconds)");
-
po::options_description fixedPipeDesc("Fixed pipeline options");
fixedPipeDesc.add_options()
("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
@@ -136,7 +126,6 @@
po::options_description visibleDesc;
visibleDesc.add(basicDesc)
- .add(realDiscoveryDesc)
.add(fixedPipeDesc)
.add(adaptivePipeDesc)
.add(cubicPipeDesc);
@@ -145,11 +134,16 @@
hiddenDesc.add_options()
("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
+ po::options_description deprecatedDesc;
+ deprecatedDesc.add_options()
+ ("discover-version,d", po::value<std::string>(), "version discovery algorithm to use")
+ ("discovery-timeout,t", po::value<int64_t>(), "discovery timeout (in milliseconds)");
+
po::positional_options_description p;
p.add("ndn-name", -1);
po::options_description optDesc;
- optDesc.add(visibleDesc).add(hiddenDesc);
+ optDesc.add(visibleDesc).add(hiddenDesc).add(deprecatedDesc);
po::variables_map vm;
try {
@@ -171,6 +165,14 @@
return 0;
}
+ if (vm.count("discover-version") > 0) {
+ std::cout << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
+ }
+
+ if (vm.count("discovery-timeout") > 0) {
+ std::cout << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
+ }
+
if (vm.count("version") > 0) {
std::cout << "ndncatchunks " << tools::VERSION << std::endl;
return 0;
@@ -182,13 +184,6 @@
return 2;
}
- Name prefix(uri);
- if (discoverType == "fixed" && (prefix.empty() || !prefix[-1].isVersion())) {
- std::cerr << "ERROR: The specified name must contain a version component when using "
- "fixed version discovery" << std::endl;
- return 2;
- }
-
if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
return 2;
@@ -199,11 +194,6 @@
return 2;
}
- if (discoveryTimeoutMs < 0) {
- std::cerr << "ERROR: timeout cannot be negative" << std::endl;
- return 2;
- }
-
if (vm["lifetime"].as<int64_t>() < 0) {
std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
return 2;
@@ -218,19 +208,7 @@
try {
Face face;
- unique_ptr<DiscoverVersion> discover;
- if (discoverType == "fixed") {
- discover = make_unique<DiscoverVersionFixed>(prefix, face, options);
- }
- else if (discoverType == "realtime") {
- DiscoverVersionRealtime::Options optionsRealtime(options);
- optionsRealtime.discoveryTimeout = time::milliseconds(discoveryTimeoutMs);
- discover = make_unique<DiscoverVersionRealtime>(prefix, face, optionsRealtime);
- }
- else {
- std::cerr << "ERROR: discover version type not valid" << std::endl;
- return 2;
- }
+ auto discover = make_unique<DiscoverVersion>(Name(uri), face, options);
unique_ptr<PipelineInterests> pipeline;
unique_ptr<StatisticsCollector> statsCollector;