chunks: print summary by default

Introduce -q/--quiet option to suppress all output.

Change-Id: Ib529849cb1ca8975d11ce6689e2d88708291d1c4
Refs: #4421
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 @@
 
   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 @@
 
   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<shared_ptr<Data>> dataStore;
@@ -197,7 +197,7 @@
 {
   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<DiscoverVersionDummy>(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 @@
 
 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 @@
   }
 
 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 @@
   }
 
 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.
  *
@@ -35,30 +35,27 @@
 class PipelineInterestFixedWindowFixture : public PipelineInterestsFixture
 {
 public:
-  typedef PipelineInterestsFixedWindowOptions Options;
-
-public:
   PipelineInterestFixedWindowFixture()
-    : PipelineInterestsFixture()
-    , opt(makeOptions())
+    : opt(makeOptions())
   {
     setPipeline(make_unique<PipelineInterestsFixedWindow>(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 @@
   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 @@
   /**
    * @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 @@
   unique_ptr<DiscoverVersion> m_discover;
   unique_ptr<PipelineInterests> m_pipeline;
   uint64_t m_nextToPrint;
-  bool m_isVerbose;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   std::map<uint64_t, shared_ptr<const Data>> 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 @@
                     "lifetime of expressed Interests, in milliseconds")
     ("retries,r",   po::value<int>(&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 @@
     std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
     return 2;
   }
-
   options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
 
+  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 @@
       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 @@
     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 @@
   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 @@
   if (m_hasFinalBlockId &&
       static_cast<uint64_t>(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 @@
   BOOST_ASSERT(m_nReceived > 0);
   if (m_hasFinalBlockId &&
       static_cast<uint64_t>(m_nReceived - 1) >= m_lastSegmentNo) { // all segments have been received
-    if (m_options.isVerbose) {
+    if (!m_options.isQuiet) {
       printSummary();
     }
   }