chunks: print summary by default

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

Change-Id: Ib529849cb1ca8975d11ce6689e2d88708291d1c4
Refs: #4421
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();
     }
   }