ndnpeek: replace --link-file with --fwhint

refs #4207, #5187

Change-Id: I8213e971520d3edab631634a03bf7950d265dc11
This commit is contained in:
Junxiao Shi committed 2022-01-11 18:20:38 +00:00
1 parent 50882ebf1d
commit fd2d1012c7
7 files changed
+116 -45

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* 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/>.
*/
#include "core/program-options-ext.hpp"
namespace ndn {
void
validate(boost::any& v, const std::vector<std::string>& values, Name*, int)
{
using namespace boost::program_options;
validators::check_first_occurrence(v);
const std::string& s = validators::get_single_string(values);
try {
v = Name(s);
} catch (const Name::Error&) {
throw invalid_option_value(s);
}
}
} // namespace ndn
+42
View File
@@ -0,0 +1,42 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* 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/>.
*/
#ifndef NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP
#define NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP
#include <ndn-cxx/name.hpp>
#include <boost/program_options/value_semantic.hpp>
namespace ndn {
/**
* @brief Provide a Boost.Program_options custom validator for ndn::Name type.
*/
void
validate(boost::any& v, const std::vector<std::string>& values, Name*, int);
} // namespace ndn
#endif // NDN_TOOLS_CORE_PROGRAM_OPTIONS_EXT_HPP
+3 -2
View File
@@ -28,8 +28,9 @@ Options
``-f, --fresh``
If specified, include ``MustBeFresh`` element in the Interest packet.
``--link-file <file>``
Read Link object from ``file`` and add it as ``ForwardingHint`` to the Interest packet.
``-F, --fwhint <name>``
Add a delegation name to the ``ForwardingHint`` of the Interest packet.
This option may be repeated to specify multiple delegation names.
``-l, --lifetime <lifetime>``
Set ``lifetime`` (in milliseconds) as the ``InterestLifetime``.
+17 -13
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, Arizona Board of Regents.
* Copyright (c) 2014-2022, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -155,12 +155,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Default, OutputCheck, OutputChecks)
OutputCheck::checkOutput(output, *data);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), false);
BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), false);
BOOST_CHECK_EQUAL(face.sentInterests.back().getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
BOOST_CHECK(face.sentInterests.back().getHopLimit() == nullopt);
BOOST_CHECK(!face.sentInterests.back().hasApplicationParameters());
const auto& interest = face.sentInterests.back();
BOOST_CHECK_EQUAL(interest.getCanBePrefix(), false);
BOOST_CHECK_EQUAL(interest.getMustBeFresh(), false);
BOOST_CHECK_EQUAL(interest.getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(interest.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
BOOST_CHECK(interest.getHopLimit() == nullopt);
BOOST_CHECK(!interest.hasApplicationParameters());
BOOST_CHECK(peek->getResult() == NdnPeek::Result::DATA);
}
@@ -169,6 +170,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NonDefault, OutputCheck, OutputChecks)
auto options = OutputCheck::makeOptions();
options.canBePrefix = true;
options.mustBeFresh = true;
options.forwardingHint.emplace_back("/fh");
options.interestLifetime = 200_ms;
options.hopLimit = 64;
initialize(options);
@@ -187,12 +189,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NonDefault, OutputCheck, OutputChecks)
OutputCheck::checkOutput(output, *data);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), 200_ms);
BOOST_CHECK(face.sentInterests.back().getHopLimit() == 64);
BOOST_CHECK(!face.sentInterests.back().hasApplicationParameters());
const auto& interest = face.sentInterests.back();
BOOST_CHECK_EQUAL(interest.getCanBePrefix(), true);
BOOST_CHECK_EQUAL(interest.getMustBeFresh(), true);
BOOST_TEST(interest.getForwardingHint() == std::vector<Name>({"/fh"}),
boost::test_tools::per_element());
BOOST_CHECK_EQUAL(interest.getInterestLifetime(), 200_ms);
BOOST_CHECK(interest.getHopLimit() == 64);
BOOST_CHECK(!interest.hasApplicationParameters());
BOOST_CHECK(peek->getResult() == NdnPeek::Result::DATA);
}
+5 -24
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2021, Regents of the University of California,
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,6 +28,7 @@
*/
#include "ndnpeek.hpp"
#include "core/program-options-ext.hpp"
#include "core/version.hpp"
#include <ndn-cxx/util/io.hpp>
@@ -85,7 +86,8 @@ main(int argc, char* argv[])
interestOptDesc.add_options()
("prefix,P", po::bool_switch(&options.canBePrefix), "set CanBePrefix")
("fresh,f", po::bool_switch(&options.mustBeFresh), "set MustBeFresh")
("link-file", po::value<std::string>(), "set ForwardingHint from a raw binary file")
("fwhint,F", po::value<std::vector<Name>>(&options.forwardingHint)->composing(),
"add ForwardingHint delegation name")
("lifetime,l", po::value<time::milliseconds::rep>()->default_value(options.interestLifetime.count()),
"set InterestLifetime, in milliseconds")
("hop-limit,H", po::value<int>(), "set HopLimit")
@@ -98,7 +100,7 @@ main(int argc, char* argv[])
po::options_description hiddenOptDesc;
hiddenOptDesc.add_options()
("name", po::value<std::string>(), "Interest name");
("name", po::value<Name>(&options.name), "Interest name");
po::options_description optDesc;
optDesc.add(visibleOptDesc).add(hiddenOptDesc);
@@ -132,14 +134,6 @@ main(int argc, char* argv[])
return 2;
}
try {
options.name = vm["name"].as<std::string>();
}
catch (const Name::Error& e) {
std::cerr << "ERROR: invalid name: " << e.what() << std::endl;
return 2;
}
if (vm.count("timeout") > 0) {
options.timeout = time::milliseconds(vm["timeout"].as<time::milliseconds::rep>());
if (*options.timeout < 0_ms) {
@@ -148,19 +142,6 @@ main(int argc, char* argv[])
}
}
if (vm.count("link-file") > 0) {
auto filename = vm["link-file"].as<std::string>();
std::ifstream linkFile = openBinaryFile(filename);
if (!linkFile) {
return 2;
}
options.link = io::load<Link>(linkFile, io::NO_ENCODING);
if (!options.link) {
std::cerr << "ERROR: cannot parse a valid Link object from file '" << filename << "'" << std::endl;
return 2;
}
}
options.interestLifetime = time::milliseconds(vm["lifetime"].as<time::milliseconds::rep>());
if (options.interestLifetime < 0_ms) {
std::cerr << "ERROR: InterestLifetime cannot be negative" << std::endl;
+2 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -63,9 +63,7 @@ NdnPeek::createInterest() const
Interest interest(m_options.name);
interest.setCanBePrefix(m_options.canBePrefix);
interest.setMustBeFresh(m_options.mustBeFresh);
if (m_options.link) {
interest.setForwardingHint(m_options.link->getDelegationList());
}
interest.setForwardingHint(m_options.forwardingHint);
interest.setInterestLifetime(m_options.interestLifetime);
interest.setHopLimit(m_options.hopLimit);
if (m_options.applicationParameters) {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2021, Regents of the University of California,
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -47,7 +47,7 @@ struct PeekOptions
Name name;
bool canBePrefix = false;
bool mustBeFresh = false;
shared_ptr<Link> link;
std::vector<Name> forwardingHint;
time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME;
optional<uint8_t> hopLimit;
shared_ptr<Buffer> applicationParameters;