ndncatchunks: Reduce initial timeout of iterative version discovery

Reduce the default timeout to 300ms.
Provide a parameter '--discovery-timeout' to raise it, if necessary.
Reduce the number of timeouts for version discovery from 2 to 1.

refs: #4291

Change-Id: I459645ab074ed9b15a74baed39f45903fcb31ff1
diff --git a/tools/chunks/catchunks/discover-version-iterative.cpp b/tools/chunks/catchunks/discover-version-iterative.cpp
index 98ca5dd..9d38cfe 100644
--- a/tools/chunks/catchunks/discover-version-iterative.cpp
+++ b/tools/chunks/catchunks/discover-version-iterative.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2016-2017,  Regents of the University of California,
  *                      Colorado State University,
  *                      University Pierre & Marie Curie, Sorbonne University.
  *
@@ -23,6 +23,7 @@
  * @author Wentao Shang
  * @author Steve DiBenedetto
  * @author Andrea Tosatto
+ * @author Klaus Schneider
  */
 
 #include "discover-version-iterative.hpp"
@@ -92,6 +93,7 @@
   Interest newInterest(interest);
   newInterest.refreshNonce();
   newInterest.setExclude(exclude);
+  newInterest.setInterestLifetime(discoveryTimeout);
 
   if (m_foundVersion)
     expressInterest(newInterest, maxRetriesOnTimeoutOrNack, maxRetriesAfterVersionFound);
diff --git a/tools/chunks/catchunks/discover-version-iterative.hpp b/tools/chunks/catchunks/discover-version-iterative.hpp
index 8beb2fb..59652a6 100644
--- a/tools/chunks/catchunks/discover-version-iterative.hpp
+++ b/tools/chunks/catchunks/discover-version-iterative.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2016-2017,  Regents of the University of California,
  *                      Colorado State University,
  *                      University Pierre & Marie Curie, Sorbonne University.
  *
@@ -23,6 +23,7 @@
  * @author Wentao Shang
  * @author Steve DiBenedetto
  * @author Andrea Tosatto
+ * @author Klaus Schneider
  */
 
 #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP
@@ -44,12 +45,14 @@
   explicit
   DiscoverVersionIterativeOptions(const Options& opt = Options())
     : Options(opt)
-    , maxRetriesAfterVersionFound(1)
+    , maxRetriesAfterVersionFound(0)
+    , discoveryTimeout(time::milliseconds(300))
   {
   }
 
 public:
-  int maxRetriesAfterVersionFound;  // used only in timeout handling
+  int maxRetriesAfterVersionFound;      // how many times to retry after a discoveryTimeout
+  time::milliseconds discoveryTimeout;  // timeout for version discovery
 };
 
 /**
diff --git a/tools/chunks/catchunks/ndncatchunks.cpp b/tools/chunks/catchunks/ndncatchunks.cpp
index 9d9b8a8..2242a83 100644
--- a/tools/chunks/catchunks/ndncatchunks.cpp
+++ b/tools/chunks/catchunks/ndncatchunks.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2016-2017, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
@@ -25,6 +25,7 @@
  * @author Andrea Tosatto
  * @author Davide Pesavento
  * @author Weiwei Liu
+ * @author Klaus Schneider
  */
 
 #include "aimd-statistics-collector.hpp"
@@ -51,7 +52,8 @@
   std::string discoverType("iterative");
   std::string pipelineType("fixed");
   size_t maxPipelineSize(1);
-  int maxRetriesAfterVersionFound(1);
+  int maxRetriesAfterVersionFound(0);
+  int64_t discoveryTimeoutMs(300);
   std::string uri;
 
   // congestion control parameters, CWA refers to conservative window adaptation,
@@ -66,12 +68,12 @@
   po::options_description basicDesc("Basic Options");
   basicDesc.add_options()
     ("help,h",      "print this help message and exit")
-    ("discover-version,d",  po::value<std::string>(&discoverType)->default_value(discoverType),
+    ("discover-version,d", po::value<std::string>(&discoverType)->default_value(discoverType),
                             "version discovery algorithm to use; valid values are: 'fixed', 'iterative'")
-    ("pipeline-type,t",  po::value<std::string>(&pipelineType)->default_value(pipelineType),
+    ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
                          "type of Interest pipeline to use; valid values are: 'fixed', 'aimd'")
     ("fresh,f",     po::bool_switch(&options.mustBeFresh), "only return fresh content")
-    ("lifetime,l",  po::value<uint64_t>()->default_value(options.interestLifetime.count()),
+    ("lifetime,l",  po::value<int64_t>()->default_value(options.interestLifetime.count()),
                     "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)")
@@ -84,6 +86,8 @@
     ("retries-iterative,i", po::value<int>(&maxRetriesAfterVersionFound)->default_value(maxRetriesAfterVersionFound),
                             "number of timeouts that have to occur in order to confirm a discovered Data "
                             "version as the latest one")
+    ("discovery-timeout,t", po::value<int64_t>(&discoveryTimeoutMs)->default_value(discoveryTimeoutMs),
+                            "discovery timeout (in milliseconds)")
     ;
 
   po::options_description fixedPipeDesc("Fixed pipeline options");
@@ -190,7 +194,17 @@
     return 2;
   }
 
-  options.interestLifetime = time::milliseconds(vm["lifetime"].as<uint64_t>());
+  if (discoveryTimeoutMs < 0) {
+    std::cerr << "ERROR: timeout cannot be negative" << std::endl;
+    return 2;
+  }
+
+  if (vm["lifetime"].as<int64_t>() < 0) {
+    std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
+    return 2;
+  }
+
+  options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
 
   try {
     Face face;
@@ -202,6 +216,7 @@
     else if (discoverType == "iterative") {
       DiscoverVersionIterative::Options optionsIterative(options);
       optionsIterative.maxRetriesAfterVersionFound = maxRetriesAfterVersionFound;
+      optionsIterative.discoveryTimeout = time::milliseconds(discoveryTimeoutMs);
       discover = make_unique<DiscoverVersionIterative>(prefix, face, optionsIterative);
     }
     else {