catchunks: adapt to recent RttEstimator API changes

Refs: #4887
Change-Id: Ie39a1c5f7ad8b225397f41bb0f3c4d7c2a9cdb2a
diff --git a/tests/chunks/pipeline-interests-aimd.t.cpp b/tests/chunks/pipeline-interests-aimd.t.cpp
index c990654..0f18f70 100644
--- a/tests/chunks/pipeline-interests-aimd.t.cpp
+++ b/tests/chunks/pipeline-interests-aimd.t.cpp
@@ -78,8 +78,10 @@
     rttOptions.alpha = 0.125;
     rttOptions.beta = 0.25;
     rttOptions.k = 4;
-    rttOptions.minRto = RttEstimator::MillisecondsDouble(200);
-    rttOptions.maxRto = RttEstimator::MillisecondsDouble(4000);
+    rttOptions.initialRto = 1_s;
+    rttOptions.minRto = 200_ms;
+    rttOptions.maxRto = 4_s;
+    rttOptions.rtoBackoffMultiplier = 2;
     return rttOptions;
   }
 
@@ -87,7 +89,7 @@
   PipelineInterestsAdaptive::Options opt;
   RttEstimator rttEstimator;
   PipelineInterestsAdaptive* pipeline;
-  static constexpr double MARGIN = 0.01;
+  static constexpr double MARGIN = 0.001;
 };
 
 constexpr double PipelineInterestAimdFixture::MARGIN;
diff --git a/tests/chunks/pipeline-interests-cubic.t.cpp b/tests/chunks/pipeline-interests-cubic.t.cpp
index fa3aac8..03e3f9d 100644
--- a/tests/chunks/pipeline-interests-cubic.t.cpp
+++ b/tests/chunks/pipeline-interests-cubic.t.cpp
@@ -80,8 +80,10 @@
     rttOptions.alpha = 0.125;
     rttOptions.beta = 0.25;
     rttOptions.k = 8;
-    rttOptions.minRto = RttEstimator::MillisecondsDouble(200);
-    rttOptions.maxRto = RttEstimator::MillisecondsDouble(4000);
+    rttOptions.initialRto = 1_s;
+    rttOptions.minRto = 200_ms;
+    rttOptions.maxRto = 4_s;
+    rttOptions.rtoBackoffMultiplier = 2;
     return rttOptions;
   }
 
@@ -89,7 +91,7 @@
   PipelineInterestsCubic::Options opt;
   RttEstimator rttEstimator;
   PipelineInterestsCubic* pipeline;
-  static constexpr double MARGIN = 0.01;
+  static constexpr double MARGIN = 0.001;
 };
 
 constexpr double PipelineInterestCubicFixture::MARGIN;
diff --git a/tools/chunks/catchunks/main.cpp b/tools/chunks/catchunks/main.cpp
index 9ec1973..a24d39e 100644
--- a/tools/chunks/catchunks/main.cpp
+++ b/tools/chunks/catchunks/main.cpp
@@ -53,13 +53,12 @@
   size_t maxPipelineSize(1);
   std::string uri;
 
-  // congestion control parameters, CWA refers to conservative window adaptation,
-  // i.e. only reduce window size at most once per RTT
+  // congestion control parameters
   bool disableCwa(false), resetCwndToInit(false),
        ignoreCongMarks(false), enableFastConv(false);
-  double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), minRto(200.0), maxRto(4000.0),
-         aimdBeta(0.5), cubicBeta(0.7);
   int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(8);
+  double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), aimdBeta(0.5), cubicBeta(0.7);
+  int64_t minRto(200), maxRto(60000);
   std::string cwndPath, rttPath;
 
   namespace po = boost::program_options;
@@ -67,7 +66,7 @@
   basicDesc.add_options()
     ("help,h",      "print this help message and exit")
     ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
-                         "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
+                        "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
     ("fresh,f",     po::bool_switch(&options.mustBeFresh), "only return fresh content")
     ("lifetime,l",  po::value<int64_t>()->default_value(options.interestLifetime.count()),
                     "lifetime of expressed Interests, in milliseconds")
@@ -103,15 +102,15 @@
     ("aimd-beta", po::value<double>(&aimdBeta)->default_value(aimdBeta),
                   "multiplicative decrease factor (AIMD)")
     ("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
-                  "alpha value for rto calculation")
+                  "alpha value for RTO calculation")
     ("rto-beta",  po::value<double>(&rtoBeta)->default_value(rtoBeta),
-                  "beta value for rto calculation")
+                  "beta value for RTO calculation")
     ("rto-k",     po::value<int>(&k)->default_value(k),
-                  "k value for rto calculation")
-    ("min-rto",   po::value<double>(&minRto)->default_value(minRto),
-                  "minimum rto value in milliseconds")
-    ("max-rto",   po::value<double>(&maxRto)->default_value(maxRto),
-                  "maximum rto value in milliseconds")
+                  "k value for RTO calculation")
+    ("min-rto",   po::value<int64_t>(&minRto)->default_value(minRto),
+                  "minimum RTO value in milliseconds")
+    ("max-rto",   po::value<int64_t>(&maxRto)->default_value(maxRto),
+                  "maximum RTO value in milliseconds")
     ("log-cwnd",  po::value<std::string>(&cwndPath), "log file for congestion window stats")
     ("log-rtt",   po::value<std::string>(&rttPath), "log file for round-trip time stats")
     ;
@@ -165,11 +164,11 @@
   }
 
   if (vm.count("discover-version") > 0) {
-    std::cout << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
+    std::cerr << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
   }
 
   if (vm.count("discovery-timeout") > 0) {
-    std::cout << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
+    std::cerr << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
   }
 
   if (vm.count("version") > 0) {
@@ -223,18 +222,21 @@
       optionsRttEst.alpha = rtoAlpha;
       optionsRttEst.beta = rtoBeta;
       optionsRttEst.k = k;
-      optionsRttEst.minRto = RttEstimator::MillisecondsDouble(minRto);
-      optionsRttEst.maxRto = RttEstimator::MillisecondsDouble(maxRto);
+      optionsRttEst.initialRto = 1_s;
+      optionsRttEst.minRto = time::milliseconds(minRto);
+      optionsRttEst.maxRto = time::milliseconds(maxRto);
+      optionsRttEst.rtoBackoffMultiplier = 2;
       rttEstimator = make_unique<RttEstimator>(optionsRttEst);
 
       if (options.isVerbose) {
+        using namespace ndn::time;
         std::cerr << "RTT estimator parameters:\n"
                   << "\tAlpha = " << optionsRttEst.alpha << "\n"
                   << "\tBeta = " << optionsRttEst.beta << "\n"
                   << "\tK = " << optionsRttEst.k << "\n"
-                  << "\tInitial RTO = " << optionsRttEst.initialRto << "\n"
-                  << "\tMin RTO = " << optionsRttEst.minRto << "\n"
-                  << "\tMax RTO = " << optionsRttEst.maxRto << "\n"
+                  << "\tInitial RTO = " << duration_cast<milliseconds>(optionsRttEst.initialRto) << "\n"
+                  << "\tMin RTO = " << duration_cast<milliseconds>(optionsRttEst.minRto) << "\n"
+                  << "\tMax RTO = " << duration_cast<milliseconds>(optionsRttEst.maxRto) << "\n"
                   << "\tBackoff multiplier = " << optionsRttEst.rtoBackoffMultiplier << "\n";
       }
 
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
index fd28829..cde5e40 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
@@ -235,11 +235,11 @@
   }
 
   SegmentInfo& segInfo = segIt->second;
-  RttEstimator::MillisecondsDouble rtt = time::steady_clock::now() - segInfo.timeSent;
+  time::nanoseconds rtt = time::steady_clock::now() - segInfo.timeSent;
   if (m_options.isVerbose) {
     std::cerr << "Received segment #" << recvSegNo
-              << ", rtt=" << rtt.count() << "ms"
-              << ", rto=" << segInfo.rto.count() << "ms" << std::endl;
+              << ", rtt=" << rtt.count() / 1e6 << "ms"
+              << ", rto=" << segInfo.rto.count() / 1e6 << "ms" << std::endl;
   }
 
   if (m_highData < recvSegNo) {
@@ -418,19 +418,19 @@
   std::cerr << "Congestion marks: " << m_nCongMarks << " (caused " << m_nMarkDecr << " window decreases)\n"
             << "Timeouts: " << m_nTimeouts << " (caused " << m_nLossDecr << " window decreases)\n"
             << "Retransmitted segments: " << m_nRetransmitted
-            << " (" << (m_nSent == 0 ? 0 : (static_cast<double>(m_nRetransmitted) / m_nSent * 100.0))  << "%)"
+            << " (" << (m_nSent == 0 ? 0 : (m_nRetransmitted * 100.0 / m_nSent)) << "%)"
             << ", skipped: " << m_nSkippedRetx << "\n"
             << "RTT ";
 
-  if (m_rttEstimator.getMinRtt().count() == std::numeric_limits<double>::max() ||
-      m_rttEstimator.getMaxRtt().count() == std::numeric_limits<double>::min()) {
+  if (m_rttEstimator.getMinRtt() == time::nanoseconds::max() ||
+      m_rttEstimator.getMaxRtt() == time::nanoseconds::min()) {
     std::cerr << "stats unavailable\n";
   }
   else {
     std::cerr << "min/avg/max = " << std::fixed << std::setprecision(3)
-              << m_rttEstimator.getMinRtt().count() << "/"
-              << m_rttEstimator.getAvgRtt().count() << "/"
-              << m_rttEstimator.getMaxRtt().count() << " ms\n";
+              << m_rttEstimator.getMinRtt().count() / 1e6 << "/"
+              << m_rttEstimator.getAvgRtt().count() / 1e6 << "/"
+              << m_rttEstimator.getMaxRtt().count() / 1e6 << " ms\n";
   }
 }
 
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
index 8ecc45b..94fadf3 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
@@ -84,7 +84,7 @@
 {
   ScopedPendingInterestHandle interestHdl;
   time::steady_clock::TimePoint timeSent;
-  RttEstimator::MillisecondsDouble rto;
+  time::nanoseconds rto;
   SegmentState state;
 };
 
diff --git a/tools/chunks/catchunks/pipeline-interests.cpp b/tools/chunks/catchunks/pipeline-interests.cpp
index 3b0bff9..e32ad7d 100644
--- a/tools/chunks/catchunks/pipeline-interests.cpp
+++ b/tools/chunks/catchunks/pipeline-interests.cpp
@@ -133,13 +133,13 @@
 PipelineInterests::printSummary() const
 {
   using namespace ndn::time;
-  duration<double, milliseconds::period> timeElapsed = steady_clock::now() - getStartTime();
-  double throughput = (8 * m_receivedSize * 1000) / timeElapsed.count();
+  duration<double, seconds::period> timeElapsed = steady_clock::now() - getStartTime();
+  double throughput = 8 * m_receivedSize / timeElapsed.count();
 
   std::cerr << "\n\nAll segments have been received.\n"
             << "Time elapsed: " << timeElapsed << "\n"
             << "Segments received: " << m_nReceived << "\n"
-            << "Total size: " << static_cast<double>(m_receivedSize) / 1000 << "kB" << "\n"
+            << "Transferred size: " << m_receivedSize / 1e3 << " kB" << "\n"
             << "Goodput: " << formatThroughput(throughput) << "\n";
 }
 
diff --git a/tools/chunks/catchunks/statistics-collector.cpp b/tools/chunks/catchunks/statistics-collector.cpp
index 8984e78..2a65025 100644
--- a/tools/chunks/catchunks/statistics-collector.cpp
+++ b/tools/chunks/catchunks/statistics-collector.cpp
@@ -42,10 +42,10 @@
   rttEstimator.afterMeasurement.connect(
     [this] (const RttEstimator::Sample& sample) {
       m_osRtt << *sample.segNum << '\t'
-              << sample.rtt.count() << '\t'
-              << sample.rttVar.count() << '\t'
-              << sample.sRtt.count() << '\t'
-              << sample.rto.count() << '\n';
+              << sample.rtt.count() / 1e6 << '\t'
+              << sample.rttVar.count() / 1e6 << '\t'
+              << sample.sRtt.count() / 1e6 << '\t'
+              << sample.rto.count() / 1e6 << '\n';
     });
 }