From 0da1f44c7933d66349d050d971807bc00895b160 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Fri, 26 Jul 2019 17:38:13 -0400 Subject: [PATCH] chunks+peek+ping: use correct underlying type for time::milliseconds Change-Id: I3f46f846401eccc0c11d3abcd1a5ebff89056f7d --- tools/chunks/catchunks/main.cpp | 16 ++++----- tools/chunks/catchunks/options.hpp | 2 +- tools/chunks/putchunks/main.cpp | 2 +- tools/peek/ndnpeek/main.cpp | 26 ++++++-------- tools/peek/ndnpeek/ndnpeek.cpp | 4 +-- tools/peek/ndnpeek/ndnpeek.hpp | 4 +-- tools/peek/ndnpoke/main.cpp | 20 +++++------ tools/ping/client/main.cpp | 55 +++++++++++++----------------- 8 files changed, 56 insertions(+), 73 deletions(-) diff --git a/tools/chunks/catchunks/main.cpp b/tools/chunks/catchunks/main.cpp index 82d10c8..c7deb5c 100644 --- a/tools/chunks/catchunks/main.cpp +++ b/tools/chunks/catchunks/main.cpp @@ -58,7 +58,7 @@ main(int argc, char* argv[]) ignoreCongMarks(false), enableFastConv(false); int initCwnd(1), initSsthresh(std::numeric_limits::max()), k(8); double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), aimdBeta(0.5), cubicBeta(0.7); - int64_t minRto(200), maxRto(60000); + time::milliseconds::rep minRto(200), maxRto(60000); std::string cwndPath, rttPath; namespace po = boost::program_options; @@ -68,7 +68,7 @@ main(int argc, char* argv[]) ("pipeline-type,p", po::value(&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") - ("lifetime,l", po::value()->default_value(options.interestLifetime.count()), + ("lifetime,l", po::value()->default_value(options.interestLifetime.count()), "lifetime of expressed Interests, in milliseconds") ("retries,r", po::value(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack), "maximum number of retries in case of Nack or timeout (-1 = no limit)") @@ -107,10 +107,10 @@ main(int argc, char* argv[]) "beta value for RTO calculation") ("rto-k", po::value(&k)->default_value(k), "k value for RTO calculation") - ("min-rto", po::value(&minRto)->default_value(minRto), - "minimum RTO value in milliseconds") - ("max-rto", po::value(&maxRto)->default_value(maxRto), - "maximum RTO value in milliseconds") + ("min-rto", po::value(&minRto)->default_value(minRto), + "minimum RTO value, in milliseconds") + ("max-rto", po::value(&maxRto)->default_value(maxRto), + "maximum RTO value, in milliseconds") ("log-cwnd", po::value(&cwndPath), "log file for congestion window stats") ("log-rtt", po::value(&rttPath), "log file for round-trip time stats") ; @@ -179,11 +179,11 @@ main(int argc, char* argv[]) return 2; } - if (vm["lifetime"].as() < 0) { + options.interestLifetime = time::milliseconds(vm["lifetime"].as()); + if (options.interestLifetime < 0_ms) { std::cerr << "ERROR: lifetime cannot be negative" << std::endl; return 2; } - options.interestLifetime = time::milliseconds(vm["lifetime"].as()); if (options.isQuiet && options.isVerbose) { std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl; diff --git a/tools/chunks/catchunks/options.hpp b/tools/chunks/catchunks/options.hpp index d3a564e..9400fb6 100644 --- a/tools/chunks/catchunks/options.hpp +++ b/tools/chunks/catchunks/options.hpp @@ -35,7 +35,7 @@ namespace chunks { struct Options { - time::milliseconds interestLifetime = ndn::DEFAULT_INTEREST_LIFETIME; + time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME; int maxRetriesOnTimeoutOrNack = 15; bool mustBeFresh = false; bool isQuiet = false; diff --git a/tools/chunks/putchunks/main.cpp b/tools/chunks/putchunks/main.cpp index c92182e..5e1dd9f 100644 --- a/tools/chunks/putchunks/main.cpp +++ b/tools/chunks/putchunks/main.cpp @@ -109,7 +109,7 @@ main(int argc, char* argv[]) } opts.freshnessPeriod = time::milliseconds(vm["freshness"].as()); - if (opts.freshnessPeriod < time::milliseconds::zero()) { + if (opts.freshnessPeriod < 0_ms) { std::cerr << "ERROR: FreshnessPeriod cannot be negative" << std::endl; return 2; } diff --git a/tools/peek/ndnpeek/main.cpp b/tools/peek/ndnpeek/main.cpp index ead3d70..70977aa 100644 --- a/tools/peek/ndnpeek/main.cpp +++ b/tools/peek/ndnpeek/main.cpp @@ -54,8 +54,9 @@ main(int argc, char* argv[]) po::options_description genericOptDesc("Generic options"); genericOptDesc.add_options() ("help,h", "print help and exit") - ("payload,p", po::bool_switch(&options.wantPayloadOnly), "print payload only, instead of full packet") - ("timeout,w", po::value(), "set timeout (in milliseconds)") + ("payload,p", po::bool_switch(&options.wantPayloadOnly), + "print payload only, instead of full packet") + ("timeout,w", po::value(), "execution timeout, in milliseconds") ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output") ("version,V", "print version and exit") ; @@ -65,7 +66,8 @@ main(int argc, char* argv[]) ("prefix,P", po::bool_switch(&options.canBePrefix), "set CanBePrefix") ("fresh,f", po::bool_switch(&options.mustBeFresh), "set MustBeFresh") ("link-file", po::value(), "set ForwardingHint from a file") - ("lifetime,l", po::value(), "set InterestLifetime (in milliseconds)") + ("lifetime,l", po::value()->default_value(options.interestLifetime.count()), + "set InterestLifetime, in milliseconds") ; po::options_description visibleOptDesc; @@ -115,21 +117,15 @@ main(int argc, char* argv[]) return 2; } - if (vm.count("lifetime") > 0) { - if (vm["lifetime"].as() >= 0) { - options.interestLifetime = time::milliseconds(vm["lifetime"].as()); - } - else { - std::cerr << "ERROR: lifetime cannot be negative" << std::endl; - return 2; - } + options.interestLifetime = time::milliseconds(vm["lifetime"].as()); + if (options.interestLifetime < 0_ms) { + std::cerr << "ERROR: lifetime cannot be negative" << std::endl; + return 2; } if (vm.count("timeout") > 0) { - if (vm["timeout"].as() >= 0) { - options.timeout = time::milliseconds(vm["timeout"].as()); - } - else { + options.timeout = time::milliseconds(vm["timeout"].as()); + if (*options.timeout < 0_ms) { std::cerr << "ERROR: timeout cannot be negative" << std::endl; return 2; } diff --git a/tools/peek/ndnpeek/ndnpeek.cpp b/tools/peek/ndnpeek/ndnpeek.cpp index 8969216..ff7f7a0 100644 --- a/tools/peek/ndnpeek/ndnpeek.cpp +++ b/tools/peek/ndnpeek/ndnpeek.cpp @@ -62,12 +62,10 @@ NdnPeek::createInterest() const Interest interest(m_options.name); interest.setCanBePrefix(m_options.canBePrefix); interest.setMustBeFresh(m_options.mustBeFresh); + interest.setInterestLifetime(m_options.interestLifetime); if (m_options.link) { interest.setForwardingHint(m_options.link->getDelegationList()); } - if (m_options.interestLifetime) { - interest.setInterestLifetime(*m_options.interestLifetime); - } if (m_options.isVerbose) { std::cerr << "INTEREST: " << interest << std::endl; diff --git a/tools/peek/ndnpeek/ndnpeek.hpp b/tools/peek/ndnpeek/ndnpeek.hpp index 0a9f503..d02155f 100644 --- a/tools/peek/ndnpeek/ndnpeek.hpp +++ b/tools/peek/ndnpeek/ndnpeek.hpp @@ -47,9 +47,9 @@ struct PeekOptions bool canBePrefix = false; bool mustBeFresh = false; shared_ptr link; - optional interestLifetime; + time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME; - // output behavior options + // program behavior options bool isVerbose = false; bool wantPayloadOnly = false; optional timeout; diff --git a/tools/peek/ndnpoke/main.cpp b/tools/peek/ndnpoke/main.cpp index 913b0a8..4e8713a 100644 --- a/tools/peek/ndnpoke/main.cpp +++ b/tools/peek/ndnpoke/main.cpp @@ -55,7 +55,7 @@ main(int argc, char* argv[]) ("help,h", "print help and exit") ("unsolicited,u", po::bool_switch(&options.wantUnsolicited), "send the Data packet without waiting for an incoming Interest") - ("timeout,w", po::value(), "set timeout (in milliseconds)") + ("timeout,w", po::value(), "execution timeout, in milliseconds") ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output") ("version,V", "print version and exit") ; @@ -65,7 +65,7 @@ main(int argc, char* argv[]) ("final,F", po::bool_switch(&options.wantFinalBlockId), "set FinalBlockId to the last component of the Data name") ("freshness,x", po::value()->default_value(options.freshnessPeriod.count()), - "set FreshnessPeriod (in milliseconds)") + "set FreshnessPeriod, in milliseconds") ("identity,i", po::value(), "use the specified identity for signing") ("digest,D", po::bool_switch(&wantDigestSha256), "use DigestSha256 signing method instead of SignatureSha256WithRsa") @@ -134,13 +134,10 @@ main(int argc, char* argv[]) return 2; } - if (vm.count("freshness") > 0) { - auto freshness = vm["freshness"].as(); - if (freshness < 0) { - std::cerr << "ERROR: freshness cannot be negative" << std::endl; - return 2; - } - options.freshnessPeriod = time::milliseconds(freshness); + options.freshnessPeriod = time::milliseconds(vm["freshness"].as()); + if (options.freshnessPeriod < 0_ms) { + std::cerr << "ERROR: freshness cannot be negative" << std::endl; + return 2; } if (vm.count("identity") > 0) { @@ -166,12 +163,11 @@ main(int argc, char* argv[]) std::cerr << "ERROR: conflicting '--unsolicited' and '--timeout' options specified" << std::endl; return 2; } - auto timeout = vm["timeout"].as(); - if (timeout < 0) { + options.timeout = time::milliseconds(vm["timeout"].as()); + if (*options.timeout < 0_ms) { std::cerr << "ERROR: timeout cannot be negative" << std::endl; return 2; } - options.timeout = time::milliseconds(timeout); } try { diff --git a/tools/ping/client/main.cpp b/tools/ping/client/main.cpp index 86db7da..76d72ff 100644 --- a/tools/ping/client/main.cpp +++ b/tools/ping/client/main.cpp @@ -160,37 +160,35 @@ main(int argc, char* argv[]) namespace po = boost::program_options; - po::options_description visibleOptDesc("Allowed options"); + po::options_description visibleOptDesc("Options"); visibleOptDesc.add_options() - ("help,h", "print this message and exit") - ("version,V", "display version and exit") - ("interval,i", po::value(), - ("set ping interval in milliseconds (default " + - std::to_string(getDefaultPingInterval().count()) + " ms - minimum " + - std::to_string(getMinimumPingInterval().count()) + " ms)").c_str()) - ("timeout,o", po::value(), - ("set ping timeout in milliseconds (default " + - std::to_string(getDefaultPingTimeoutThreshold().count()) + " ms)").c_str()) - ("count,c", po::value(&options.nPings), "set total number of pings") - ("start,n", po::value(&options.startSeq), - "set the starting seq number, the number is incremented by 1 after each Interest") + ("help,h", "print this message and exit") + ("version,V", "display version and exit") + ("interval,i", po::value()->default_value(getDefaultPingInterval().count()), + "ping interval, in milliseconds") + ("timeout,o", po::value()->default_value(getDefaultPingTimeoutThreshold().count()), + "ping timeout, in milliseconds") + ("count,c", po::value(&options.nPings), "number of pings to send (default = no limit)") + ("start,n", po::value(&options.startSeq), + "set the starting sequence number, the number is incremented by 1 after each Interest") ("identifier,p", po::value(&identifier), - "add identifier to the Interest names before the numbers to avoid conflict") - ("cache,a", "allows routers to return stale Data from cache") + "add identifier to the Interest names before the sequence numbers to avoid conflicts") + ("cache,a", "allow routers to return stale Data from cache") ("timestamp,t", "print timestamp with messages") ; - po::options_description hiddenOptDesc("Hidden options"); + + po::options_description hiddenOptDesc; hiddenOptDesc.add_options() ("prefix", po::value(), "prefix to send pings to") ; - po::options_description optDesc("Allowed options"); + po::options_description optDesc; optDesc.add(visibleOptDesc).add(hiddenOptDesc); - try { - po::positional_options_description optPos; - optPos.add("prefix", -1); + po::positional_options_description optPos; + optPos.add("prefix", -1); + try { po::variables_map optVm; po::store(po::command_line_parser(argc, argv).options(optDesc).positional(optPos).run(), optVm); po::notify(optVm); @@ -212,19 +210,14 @@ main(int argc, char* argv[]) usage(visibleOptDesc); } - if (optVm.count("interval") > 0) { - options.interval = time::milliseconds(optVm["interval"].as()); - - if (options.interval.count() < getMinimumPingInterval().count()) { - std::cerr << "ERROR: Specified ping interval is less than the minimum " << - getMinimumPingInterval() << std::endl; - usage(visibleOptDesc); - } + options.interval = time::milliseconds(optVm["interval"].as()); + if (options.interval < getMinimumPingInterval()) { + std::cerr << "ERROR: Specified ping interval is less than the minimum " << + getMinimumPingInterval() << std::endl; + usage(visibleOptDesc); } - if (optVm.count("timeout") > 0) { - options.timeout = time::milliseconds(optVm["timeout"].as()); - } + options.timeout = time::milliseconds(optVm["timeout"].as()); if (optVm.count("count") > 0) { if (options.nPings <= 0) {