chunks: show correct packet loss stats in AIMD pipeline output

Besides, AIMD pipeline prints a proper message when no RTT
measurements are available.

Change-Id: I9cbda88a005ba33cba753468f8f60f0d39281ab7
refs: #4437, #4551
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.cpp b/tools/chunks/catchunks/pipeline-interests-aimd.cpp
index bf530ff..cdf502d 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.cpp
@@ -51,6 +51,7 @@
   , m_nLossEvents(0)
   , m_nRetransmitted(0)
   , m_nCongMarks(0)
+  , m_nSent(0)
   , m_cwnd(m_options.initCwnd)
   , m_ssthresh(m_options.initSsthresh)
   , m_hasFailure(false)
@@ -162,6 +163,7 @@
                                            bind(&PipelineInterestsAimd::handleNack, this, _1, _2),
                                            bind(&PipelineInterestsAimd::handleLifetimeExpiration, this, _1));
   m_nInFlight++;
+  m_nSent++;
 
   if (isRetransmission) {
     SegmentInfo& segInfo = m_segmentInfo[segNo];
@@ -437,15 +439,23 @@
 PipelineInterestsAimd::printSummary() const
 {
   PipelineInterests::printSummary();
-  std::cerr << "Total # of packet loss events: " << m_nLossEvents << "\n"
+  std::cerr << "Total # of lost/retransmitted segments: " << m_nRetransmitted
+            << " (caused " << m_nLossEvents << " window decreases)\n"
             << "Packet loss rate: "
-            << static_cast<double>(m_nLossEvents) / static_cast<double>(m_nReceived) << "\n"
-            << "Total # of retransmitted segments: " << m_nRetransmitted << "\n"
+            << (static_cast<double>(m_nRetransmitted) / static_cast<double>(m_nSent)) * 100 << "%\n"
             << "Total # of received congestion marks: " << m_nCongMarks << "\n"
-            << "RTT min/avg/max = " << std::fixed << std::setprecision(3)
-                                    << m_rttEstimator.getMinRtt() << "/"
-                                    << m_rttEstimator.getAvgRtt() << "/"
-                                    << m_rttEstimator.getMaxRtt() << " ms\n";
+            << "RTT ";
+
+  if (m_rttEstimator.getMinRtt() == std::numeric_limits<double>::max() ||
+      m_rttEstimator.getMaxRtt() == std::numeric_limits<double>::min()) {
+     std::cerr << "stats unavailable\n";
+   }
+   else {
+     std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3)
+                                   << m_rttEstimator.getMinRtt() << "/"
+                                   << m_rttEstimator.getAvgRtt() << "/"
+                                   << m_rttEstimator.getMaxRtt() << " ms\n";
+  }
 }
 
 std::ostream&
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.hpp b/tools/chunks/catchunks/pipeline-interests-aimd.hpp
index bbc9940..0257e7b 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.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.
  *
@@ -184,6 +184,7 @@
   void
   cancelInFlightSegmentsGreaterThan(uint64_t segNo);
 
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   void
   printSummary() const final;
 
@@ -203,6 +204,7 @@
   int64_t m_nLossEvents; ///< # of loss events occurred
   int64_t m_nRetransmitted; ///< # of segments retransmitted
   int64_t m_nCongMarks; ///< # of data packets with congestion mark
+  int64_t m_nSent; ///< # of interest packets sent out (including retransmissions)
 
   double m_cwnd; ///< current congestion window size (in segments)
   double m_ssthresh; ///< current slow start threshold