From f6991e1a61623bec74129f6db49bb7919587c46b Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Mon, 8 Jan 2018 20:58:50 -0500 Subject: [PATCH] chunks: print summary by default Introduce -q/--quiet option to suppress all output. Change-Id: Ib529849cb1ca8975d11ce6689e2d88708291d1c4 Refs: #4421 --- tests/chunks/consumer.t.cpp | 8 ++++---- tests/chunks/pipeline-interests-aimd.t.cpp | 15 ++++++++------- .../pipeline-interests-fixed-window.t.cpp | 19 ++++++++----------- tools/chunks/catchunks/consumer.cpp | 9 ++------- tools/chunks/catchunks/consumer.hpp | 6 +++--- tools/chunks/catchunks/ndncatchunks.cpp | 18 +++++++++++++----- tools/chunks/catchunks/options.hpp | 3 ++- .../catchunks/pipeline-interests-aimd.cpp | 2 +- .../pipeline-interests-fixed-window.cpp | 4 ++-- 9 files changed, 43 insertions(+), 41 deletions(-) diff --git a/tests/chunks/consumer.t.cpp b/tests/chunks/consumer.t.cpp index 14c7036..3662f24 100644 --- a/tests/chunks/consumer.t.cpp +++ b/tests/chunks/consumer.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(OutputDataSequential) util::DummyClientFace face; output_test_stream output(""); - Consumer cons(security::v2::getAcceptAllValidator(), false, output); + Consumer cons(security::v2::getAcceptAllValidator(), output); auto interest = makeInterest(name); @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(OutputDataUnordered) util::DummyClientFace face; output_test_stream output(""); - Consumer cons(security::v2::getAcceptAllValidator(), false, output); + Consumer cons(security::v2::getAcceptAllValidator(), output); auto interest = makeInterest(name); std::vector> dataStore; @@ -197,7 +197,7 @@ BOOST_FIXTURE_TEST_CASE(RunBasic, UnitTestTimeFixture) { boost::asio::io_service io; util::DummyClientFace face(io); - Consumer consumer(security::v2::getAcceptAllValidator(), false); + Consumer consumer(security::v2::getAcceptAllValidator()); Name prefix("/ndn/chunks/test"); auto discover = make_unique(prefix, face, Options()); diff --git a/tests/chunks/pipeline-interests-aimd.t.cpp b/tests/chunks/pipeline-interests-aimd.t.cpp index d235bb1..98ba9ea 100644 --- a/tests/chunks/pipeline-interests-aimd.t.cpp +++ b/tests/chunks/pipeline-interests-aimd.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -36,12 +36,11 @@ namespace tests { using namespace ndn::tests; -class PipelineInterestAimdFixture : public ndn::chunks::tests::PipelineInterestsFixture +class PipelineInterestAimdFixture : public chunks::tests::PipelineInterestsFixture { public: PipelineInterestAimdFixture() - : PipelineInterestsFixture() - , opt(makePipelineOptions()) + : opt(makePipelineOptions()) , rttEstimator(makeRttEstimatorOptions()) { createPipeline(); @@ -56,10 +55,12 @@ public: } private: - static PipelineInterestsAimdOptions + static PipelineInterestsAimd::Options makePipelineOptions() { - PipelineInterestsAimdOptions pipelineOptions; + PipelineInterestsAimd::Options pipelineOptions; + pipelineOptions.isQuiet = true; + pipelineOptions.isVerbose = false; pipelineOptions.disableCwa = false; pipelineOptions.ignoreCongMarks = false; pipelineOptions.resetCwndToInit = false; @@ -83,7 +84,7 @@ private: } protected: - PipelineInterestsAimdOptions opt; + PipelineInterestsAimd::Options opt; RttEstimator rttEstimator; PipelineInterestsAimd* aimdPipeline; static constexpr double MARGIN = 0.01; diff --git a/tests/chunks/pipeline-interests-fixed-window.t.cpp b/tests/chunks/pipeline-interests-fixed-window.t.cpp index ef3cfc5..c4d4aad 100644 --- a/tests/chunks/pipeline-interests-fixed-window.t.cpp +++ b/tests/chunks/pipeline-interests-fixed-window.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -34,31 +34,28 @@ namespace tests { class PipelineInterestFixedWindowFixture : public PipelineInterestsFixture { -public: - typedef PipelineInterestsFixedWindowOptions Options; - public: PipelineInterestFixedWindowFixture() - : PipelineInterestsFixture() - , opt(makeOptions()) + : opt(makeOptions()) { setPipeline(make_unique(face, PipelineInterestsFixedWindow::Options(opt))); } -protected: - Options opt; - private: - static Options + static PipelineInterestsFixedWindow::Options makeOptions() { - Options options; + PipelineInterestsFixedWindow::Options options; + options.isQuiet = true; options.isVerbose = false; options.interestLifetime = time::seconds(1); options.maxRetriesOnTimeoutOrNack = 3; options.maxPipelineSize = 5; return options; } + +protected: + PipelineInterestsFixedWindow::Options opt; }; BOOST_AUTO_TEST_SUITE(Chunks) diff --git a/tools/chunks/catchunks/consumer.cpp b/tools/chunks/catchunks/consumer.cpp index ce01583..974e8e0 100644 --- a/tools/chunks/catchunks/consumer.cpp +++ b/tools/chunks/catchunks/consumer.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -30,11 +30,10 @@ namespace ndn { namespace chunks { -Consumer::Consumer(security::v2::Validator& validator, bool isVerbose, std::ostream& os) +Consumer::Consumer(security::v2::Validator& validator, std::ostream& os) : m_validator(validator) , m_outputStream(os) , m_nextToPrint(0) - , m_isVerbose(isVerbose) { } @@ -65,10 +64,6 @@ Consumer::handleData(const Data& data) m_validator.validate(data, [this, dataPtr] (const Data& data) { if (data.getContentType() == ndn::tlv::ContentType_Nack) { - if (m_isVerbose) { - std::cerr << "Application level NACK: " << data << std::endl; - } - m_pipeline->cancel(); BOOST_THROW_EXCEPTION(ApplicationNackError(data)); } diff --git a/tools/chunks/catchunks/consumer.hpp b/tools/chunks/catchunks/consumer.hpp index 633d05b..10008c9 100644 --- a/tools/chunks/catchunks/consumer.hpp +++ b/tools/chunks/catchunks/consumer.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -70,7 +70,8 @@ public: /** * @brief Create the consumer */ - Consumer(security::v2::Validator& validator, bool isVerbose, std::ostream& os = std::cout); + explicit + Consumer(security::v2::Validator& validator, std::ostream& os = std::cout); /** * @brief Run the consumer @@ -92,7 +93,6 @@ private: unique_ptr m_discover; unique_ptr m_pipeline; uint64_t m_nextToPrint; - bool m_isVerbose; PUBLIC_WITH_TESTS_ELSE_PRIVATE: std::map> m_bufferedData; diff --git a/tools/chunks/catchunks/ndncatchunks.cpp b/tools/chunks/catchunks/ndncatchunks.cpp index 768dd7a..497197f 100644 --- a/tools/chunks/catchunks/ndncatchunks.cpp +++ b/tools/chunks/catchunks/ndncatchunks.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -78,7 +78,8 @@ main(int argc, char** argv) "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)") - ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output") + ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors") + ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information") ("version,V", "print program version and exit") ; @@ -208,9 +209,13 @@ main(int argc, char** argv) 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; + return 2; + } + try { Face face; @@ -288,8 +293,7 @@ main(int argc, char** argv) return 2; } - Consumer consumer(security::v2::getAcceptAllValidator(), options.isVerbose); - + Consumer consumer(security::v2::getAcceptAllValidator()); BOOST_ASSERT(discover != nullptr); BOOST_ASSERT(pipeline != nullptr); consumer.run(std::move(discover), std::move(pipeline)); @@ -299,6 +303,10 @@ main(int argc, char** argv) std::cerr << "ERROR: " << e.what() << std::endl; return 3; } + catch (const Consumer::DataValidationError& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + return 5; + } catch (const std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; diff --git a/tools/chunks/catchunks/options.hpp b/tools/chunks/catchunks/options.hpp index 4034744..b078277 100644 --- a/tools/chunks/catchunks/options.hpp +++ b/tools/chunks/catchunks/options.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -38,6 +38,7 @@ struct Options time::milliseconds interestLifetime = ndn::DEFAULT_INTEREST_LIFETIME; int maxRetriesOnTimeoutOrNack = 3; bool mustBeFresh = false; + bool isQuiet = false; bool isVerbose = false; }; diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.cpp b/tools/chunks/catchunks/pipeline-interests-aimd.cpp index fceb90b..bf530ff 100644 --- a/tools/chunks/catchunks/pipeline-interests-aimd.cpp +++ b/tools/chunks/catchunks/pipeline-interests-aimd.cpp @@ -292,7 +292,7 @@ PipelineInterestsAimd::handleData(const Interest& interest, const Data& data) if (m_hasFinalBlockId && static_cast(m_nReceived - 1) >= m_lastSegmentNo) { // all segments have been received cancel(); - if (m_options.isVerbose) { + if (!m_options.isQuiet) { printSummary(); } } diff --git a/tools/chunks/catchunks/pipeline-interests-fixed-window.cpp b/tools/chunks/catchunks/pipeline-interests-fixed-window.cpp index 40a4417..69f9dc9 100644 --- a/tools/chunks/catchunks/pipeline-interests-fixed-window.cpp +++ b/tools/chunks/catchunks/pipeline-interests-fixed-window.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2016-2017, Regents of the University of California, + * Copyright (c) 2016-2018, Regents of the University of California, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University. * @@ -143,7 +143,7 @@ PipelineInterestsFixedWindow::handleData(const Interest& interest, const Data& d BOOST_ASSERT(m_nReceived > 0); if (m_hasFinalBlockId && static_cast(m_nReceived - 1) >= m_lastSegmentNo) { // all segments have been received - if (m_options.isVerbose) { + if (!m_options.isQuiet) { printSummary(); } }