chunks: include RTT stats in final summary

Change-Id: I9cc7cba4c8fe1f7d7a2d68c96a7db2c04774bc19
Refs: #4406
diff --git a/tools/chunks/catchunks/aimd-rtt-estimator.cpp b/tools/chunks/catchunks/aimd-rtt-estimator.cpp
index faa9d83..5e88f7c 100644
--- a/tools/chunks/catchunks/aimd-rtt-estimator.cpp
+++ b/tools/chunks/catchunks/aimd-rtt-estimator.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2017, Arizona Board of Regents.
+ * Copyright (c) 2016-2018, Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -20,10 +20,13 @@
  *
  * @author Shuo Yang
  * @author Weiwei Liu
+ * @author Chavoosh Ghasemi
  */
 
 #include "aimd-rtt-estimator.hpp"
+
 #include <cmath>
+#include <limits>
 
 namespace ndn {
 namespace chunks {
@@ -34,6 +37,10 @@
   , m_sRtt(std::numeric_limits<double>::quiet_NaN())
   , m_rttVar(std::numeric_limits<double>::quiet_NaN())
   , m_rto(m_options.initialRto.count())
+  , m_rttMin(std::numeric_limits<double>::max())
+  , m_rttMax(std::numeric_limits<double>::min())
+  , m_rttAvg(0.0)
+  , m_nRttSamples(0)
 {
   if (m_options.isVerbose) {
     std::cerr << m_options;
@@ -45,7 +52,7 @@
 {
   BOOST_ASSERT(nExpectedSamples > 0);
 
-  if (std::isnan(m_sRtt.count())) { // first measurement
+  if (m_nRttSamples == 0) { // first measurement
     m_sRtt = rtt;
     m_rttVar = m_sRtt / 2;
     m_rto = m_sRtt + m_options.k * m_rttVar;
@@ -59,8 +66,12 @@
   }
 
   m_rto = ndn::clamp(m_rto, m_options.minRto, m_options.maxRto);
-
   afterRttMeasurement({segNo, rtt, m_sRtt, m_rttVar, m_rto});
+
+  m_rttAvg = (m_nRttSamples * m_rttAvg + rtt.count()) / (m_nRttSamples + 1);
+  m_rttMax = std::max(rtt.count(), m_rttMax);
+  m_rttMin = std::min(rtt.count(), m_rttMin);
+  m_nRttSamples++;
 }
 
 void
diff --git a/tools/chunks/catchunks/aimd-rtt-estimator.hpp b/tools/chunks/catchunks/aimd-rtt-estimator.hpp
index 292395a..d7d1aca 100644
--- a/tools/chunks/catchunks/aimd-rtt-estimator.hpp
+++ b/tools/chunks/catchunks/aimd-rtt-estimator.hpp
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2016,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2016-2018,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -19,6 +19,7 @@
  *
  * @author Shuo Yang
  * @author Weiwei Liu
+ * @author Chavoosh Ghasemi
  */
 
 #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
@@ -44,7 +45,7 @@
 /**
  * @brief RTT Estimator.
  *
- * This class implements the "Mean--Deviation" RTT estimator, as discussed in RFC6298,
+ * This class implements the "Mean-Deviation" RTT estimator, as discussed in RFC 6298,
  * with the modifications to RTO calculation described in RFC 7323 Appendix G.
  */
 class RttEstimator
@@ -77,7 +78,7 @@
   };
 
   /**
-   * @brief create a RTT Estimator
+   * @brief Create a RTT Estimator
    *
    * Configures the RTT Estimator with the default parameters if an instance of Options
    * is not passed to the constructor.
@@ -88,24 +89,54 @@
   /**
    * @brief Add a new RTT measurement to the estimator for the given received segment.
    *
-   * @note Don't take RTT measurement for retransmitted segments
    * @param segNo the segment number of the received segmented Data
    * @param rtt the sampled rtt
    * @param nExpectedSamples number of expected samples, must be greater than 0.
    *        It should be set to current number of in-flight Interests. Please
    *        refer to Appendix G of RFC 7323 for details.
+   * @note Don't take RTT measurement for retransmitted segments
    */
   void
   addMeasurement(uint64_t segNo, Milliseconds rtt, size_t nExpectedSamples);
 
   /**
-   * @return estimated RTO
+   * @brief Returns the estimated RTO value
    */
   Milliseconds
-  getEstimatedRto() const;
+  getEstimatedRto() const
+  {
+    return m_rto;
+  }
 
   /**
-   * @brief backoff RTO by the factor of RttEstimatorOptions::rtoBackoffMultiplier
+   * @brief Returns the minimum RTT observed
+   */
+  double
+  getMinRtt() const
+  {
+    return m_rttMin;
+  }
+
+  /**
+   * @brief Returns the maximum RTT observed
+   */
+  double
+  getMaxRtt() const
+  {
+    return m_rttMax;
+  }
+
+  /**
+   * @brief Returns the average RTT
+   */
+  double
+  getAvgRtt() const
+  {
+    return m_rttAvg;
+  }
+
+  /**
+   * @brief Backoff RTO by a factor of Options::rtoBackoffMultiplier
    */
   void
   backoffRto();
@@ -120,16 +151,12 @@
   Milliseconds m_sRtt; ///< smoothed round-trip time
   Milliseconds m_rttVar; ///< round-trip time variation
   Milliseconds m_rto; ///< retransmission timeout
-};
 
-/**
- * @brief returns the estimated RTO value
- */
-inline Milliseconds
-RttEstimator::getEstimatedRto() const
-{
-  return m_rto;
-}
+  double m_rttMin;
+  double m_rttMax;
+  double m_rttAvg;
+  int64_t m_nRttSamples; ///< number of RTT samples
+};
 
 std::ostream&
 operator<<(std::ostream& os, const RttEstimator::Options& options);
@@ -138,4 +165,4 @@
 } // namespace chunks
 } // namespace ndn
 
-#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_RTT_ESTIMATOR_HPP
+#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_AIMD_RTT_ESTIMATOR_HPP
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.cpp b/tools/chunks/catchunks/pipeline-interests-aimd.cpp
index a63c9de..fceb90b 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.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.
  *
@@ -29,6 +29,7 @@
 #include "data-fetcher.hpp"
 
 #include <cmath>
+#include <iomanip>
 
 namespace ndn {
 namespace chunks {
@@ -440,7 +441,11 @@
             << "Packet loss rate: "
             << static_cast<double>(m_nLossEvents) / static_cast<double>(m_nReceived) << "\n"
             << "Total # of retransmitted segments: " << m_nRetransmitted << "\n"
-            << "Total # of received congestion marks: " << m_nCongMarks << "\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";
 }
 
 std::ostream&