peek: add --app-params and --app-params-file options
Change-Id: Ic1afb118d2e1a58d99d046e072a9df439e0020b3
This commit is contained in:
1 parent
5e3773dd5a
commit
9602823383
5 files changed
+94
-13
No files matched your search
+14
-2
@@ -4,7 +4,7 @@ ndnpeek
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
**ndnpeek** [-h] [-P] [-f] [-l *lifetime*] [-p] [-w *timeout*] [-v] [-V] *name*
|
||||
**ndnpeek** [-h] [-P] [-f] [-l *lifetime*] [-A *parameters*] [-p] [-w *timeout*] [-v] [-V] *name*
|
||||
|
||||
Description
|
||||
-----------
|
||||
@@ -33,6 +33,12 @@ Options
|
||||
``-l, --lifetime <lifetime>``
|
||||
Set ``lifetime`` (in milliseconds) as the ``InterestLifetime``.
|
||||
|
||||
``-A, --app-params <parameters>``
|
||||
Set the Interest's ``ApplicationParameters`` from a base64-encoded string.
|
||||
|
||||
``--app-params-file <file>``
|
||||
Set the Interest's ``ApplicationParameters`` from the specified file.
|
||||
|
||||
``-p, --payload``
|
||||
If specified, print the received payload only, not the full packet.
|
||||
|
||||
@@ -61,6 +67,12 @@ Exit Status
|
||||
Example
|
||||
-------
|
||||
|
||||
Send Interest for ``/app1/video`` and print the received payload only::
|
||||
Send an Interest for ``/app1/video`` and print the received payload only::
|
||||
|
||||
ndnpeek -p /app1/video
|
||||
|
||||
Send an Interest for ``/app2/foo``, requesting fresh content, with an InterestLifetime
|
||||
of 8 seconds, and with the ApplicationParameters containing the ASCII string "hello";
|
||||
print the performed operations verbosely but discard the received Data packet::
|
||||
|
||||
ndnpeek -vf -l 8000 -A "aGVsbG8=" /app2/foo >/dev/null
|
||||
+39
-10
@@ -50,11 +50,19 @@ private:
|
||||
std::streambuf* m_originalBuf;
|
||||
};
|
||||
|
||||
static PeekOptions
|
||||
makeDefaultOptions()
|
||||
{
|
||||
PeekOptions opt;
|
||||
opt.name = "/peek/test";
|
||||
return opt;
|
||||
}
|
||||
|
||||
class NdnPeekFixture : public UnitTestTimeFixture
|
||||
{
|
||||
protected:
|
||||
void
|
||||
initialize(const PeekOptions& opts)
|
||||
initialize(const PeekOptions& opts = makeDefaultOptions())
|
||||
{
|
||||
peek = make_unique<NdnPeek>(face, opts);
|
||||
}
|
||||
@@ -66,15 +74,6 @@ protected:
|
||||
unique_ptr<NdnPeek> peek;
|
||||
};
|
||||
|
||||
static PeekOptions
|
||||
makeDefaultOptions()
|
||||
{
|
||||
PeekOptions opt;
|
||||
opt.name = "ndn:/peek/test";
|
||||
opt.timeout = 200_ms;
|
||||
return opt;
|
||||
}
|
||||
|
||||
class OutputFull
|
||||
{
|
||||
public:
|
||||
@@ -227,6 +226,24 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ReceiveNackWithoutReason, OutputCheck, OutputCheck
|
||||
BOOST_CHECK(peek->getResult() == NdnPeek::Result::NACK);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ApplicationParameters)
|
||||
{
|
||||
auto options = makeDefaultOptions();
|
||||
options.applicationParameters = make_shared<Buffer>("hello", 5);
|
||||
initialize(options);
|
||||
|
||||
peek->start();
|
||||
this->advanceClocks(io, 25_ms, 4);
|
||||
|
||||
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_EQUAL(face.sentInterests.back().hasApplicationParameters(), true);
|
||||
BOOST_CHECK_EQUAL(face.sentInterests.back().getApplicationParameters(), "2405 68656C6C6F"_block);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NoTimeout)
|
||||
{
|
||||
auto options = makeDefaultOptions();
|
||||
@@ -282,6 +299,18 @@ BOOST_AUTO_TEST_CASE(TimeoutGreaterThanLifetime)
|
||||
BOOST_CHECK(peek->getResult() == NdnPeek::Result::TIMEOUT);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OversizedPacket)
|
||||
{
|
||||
auto options = makeDefaultOptions();
|
||||
options.applicationParameters = make_shared<Buffer>(MAX_NDN_PACKET_SIZE);
|
||||
initialize(options);
|
||||
|
||||
peek->start();
|
||||
BOOST_CHECK_THROW(this->advanceClocks(io, 1_ms, 10), Face::OversizedPacketError);
|
||||
|
||||
BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // TestNdnPeek
|
||||
BOOST_AUTO_TEST_SUITE_END() // Peek
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*
|
||||
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
|
||||
* @author Zhuo Li <zhuoli@email.arizona.edu>
|
||||
* @author Davide Pesavento <davidepesa@gmail.com>
|
||||
*/
|
||||
|
||||
#include "ndnpeek.hpp"
|
||||
@@ -83,6 +84,8 @@ main(int argc, char* argv[])
|
||||
("link-file", po::value<std::string>(), "set ForwardingHint from a raw binary file")
|
||||
("lifetime,l", po::value<time::milliseconds::rep>()->default_value(options.interestLifetime.count()),
|
||||
"set InterestLifetime, in milliseconds")
|
||||
("app-params,A", po::value<std::string>(), "set ApplicationParameters from a base64-encoded string")
|
||||
("app-params-file", po::value<std::string>(), "set ApplicationParameters from a file")
|
||||
;
|
||||
|
||||
po::options_description visibleOptDesc;
|
||||
@@ -159,6 +162,37 @@ main(int argc, char* argv[])
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (vm.count("app-params") > 0) {
|
||||
if (vm.count("app-params-file") > 0) {
|
||||
std::cerr << "ERROR: cannot specify both '--app-params' and '--app-params-file'" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
std::istringstream is(vm["app-params"].as<std::string>());
|
||||
try {
|
||||
options.applicationParameters = io::loadBuffer(is, io::BASE64);
|
||||
}
|
||||
catch (const io::Error& e) {
|
||||
std::cerr << "ERROR: invalid ApplicationParameters string: " << e.what() << std::endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.count("app-params-file") > 0) {
|
||||
auto filename = vm["app-params-file"].as<std::string>();
|
||||
std::ifstream paramsFile = openBinaryFile(filename);
|
||||
if (!paramsFile) {
|
||||
return 2;
|
||||
}
|
||||
try {
|
||||
options.applicationParameters = io::loadBuffer(paramsFile, io::NO_ENCODING);
|
||||
}
|
||||
catch (const io::Error& e) {
|
||||
std::cerr << "ERROR: cannot read ApplicationParameters from file '" << filename
|
||||
<< "': " << e.what() << std::endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Face face;
|
||||
NdnPeek program(face, options);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*
|
||||
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
|
||||
* @author Zhuo Li <zhuoli@email.arizona.edu>
|
||||
* @author Davide Pesavento <davidepesa@gmail.com>
|
||||
*/
|
||||
|
||||
#include "ndnpeek.hpp"
|
||||
@@ -66,6 +67,9 @@ NdnPeek::createInterest() const
|
||||
if (m_options.link) {
|
||||
interest.setForwardingHint(m_options.link->getDelegationList());
|
||||
}
|
||||
if (m_options.applicationParameters) {
|
||||
interest.setApplicationParameters(m_options.applicationParameters);
|
||||
}
|
||||
|
||||
if (m_options.isVerbose) {
|
||||
std::cerr << "INTEREST: " << interest << std::endl;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*
|
||||
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
|
||||
* @author Zhuo Li <zhuoli@email.arizona.edu>
|
||||
* @author Davide Pesavento <davidepesa@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef NDN_TOOLS_NDNPEEK_NDNPEEK_HPP
|
||||
@@ -48,6 +49,7 @@ struct PeekOptions
|
||||
bool mustBeFresh = false;
|
||||
shared_ptr<Link> link;
|
||||
time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME;
|
||||
shared_ptr<Buffer> applicationParameters;
|
||||
|
||||
// program behavior options
|
||||
bool isVerbose = false;
|
||||
@@ -107,7 +109,7 @@ private:
|
||||
onTimeout();
|
||||
|
||||
private:
|
||||
const PeekOptions& m_options;
|
||||
const PeekOptions m_options;
|
||||
Face& m_face;
|
||||
Scheduler m_scheduler;
|
||||
time::steady_clock::TimePoint m_sendTime;
|
||||
|
||||
Reference in new issue
Block a user