peek: drop Selectors support

refs #4571

Change-Id: Iac6d07864746b0decfed6cb9dc3518b4999f83e3
diff --git a/manpages/ndnpeek.rst b/manpages/ndnpeek.rst
index fe7b41a..7ebbf65 100644
--- a/manpages/ndnpeek.rst
+++ b/manpages/ndnpeek.rst
@@ -24,17 +24,14 @@
 ``-h, --help``
   Print help and exit.
 
+``-P, --prefix``
+  If specified, include ``CanBePrefix`` element in the Interest packet.
+
 ``-f, --fresh``
-  If specified, set ``MustBeFresh`` selector in the Interest packet.
+  If specified, include ``MustBeFresh`` element in the Interest packet.
 
-``-r, --rightmost``
-  Set ``ChildSelector=1`` (the rightmost child) selector.
-
-``-m, --minsuffix min``
-  Set ``min`` as the ``MinSuffixComponents`` selector.
-
-``-M, --maxsuffix max``
-  Set ``max`` as the ``MaxSuffixComponents`` selector.
+``--link-file [file]``
+  Read Link object from ``file`` and add it as ``ForwardingHint`` to the Interest packet.
 
 ``-l, --lifetime lifetime``
   Set ``lifetime`` (in milliseconds) as the ``InterestLifetime``.
@@ -51,9 +48,6 @@
 ``-V, --version``
   Print version and exit.
 
-``--link-file [file]``
-  Read Link object from ``file`` and add it to the expressed Interest.
-
 Exit Codes
 ----------
 
diff --git a/tests/peek/ndnpeek.t.cpp b/tests/peek/ndnpeek.t.cpp
index b44e7c5..e3fd5b3 100644
--- a/tests/peek/ndnpeek.t.cpp
+++ b/tests/peek/ndnpeek.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Arizona Board of Regents.
+/*
+ * Copyright (c) 2014-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.
@@ -75,16 +75,9 @@
 makeDefaultOptions()
 {
   PeekOptions opt;
-  opt.prefix = "ndn:/peek/test";
-  opt.minSuffixComponents = -1;
-  opt.maxSuffixComponents = -1;
+  opt.name = "ndn:/peek/test";
   opt.interestLifetime = DEFAULT_INTEREST_LIFETIME;
-  opt.timeout = time::milliseconds(200);
-  opt.link = nullptr;
-  opt.isVerbose = false;
-  opt.mustBeFresh = false;
-  opt.wantRightmostChild = false;
-  opt.wantPayloadOnly = false;
+  opt.timeout = 200_ms;
   return opt;
 }
 
@@ -151,57 +144,51 @@
   auto options = OutputCheck::makeOptions();
   initialize(options);
 
-  auto data = makeData(options.prefix);
+  auto data = makeData(options.name);
   std::string payload = "NdnPeekTest";
   data->setContent(reinterpret_cast<const uint8_t*>(payload.data()), payload.size());
 
   {
     CoutRedirector redir(output);
     peek->start();
-    this->advanceClocks(io, time::milliseconds(25), 4);
+    this->advanceClocks(io, 25_ms, 4);
     face.receive(*data);
   }
 
   OutputCheck::checkOutput(output, *data);
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getMaxSuffixComponents(), -1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getMinSuffixComponents(), -1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
-  BOOST_CHECK(face.sentInterests.back().getForwardingHint().empty());
+  BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), false);
   BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), false);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getChildSelector(), DEFAULT_CHILD_SELECTOR);
+  BOOST_CHECK(face.sentInterests.back().getForwardingHint().empty());
+  BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
   BOOST_CHECK(peek->getResultCode() == ResultCode::DATA);
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(Selectors, OutputCheck, OutputChecks)
+BOOST_AUTO_TEST_CASE_TEMPLATE(NonDefault, OutputCheck, OutputChecks)
 {
   auto options = OutputCheck::makeOptions();
-  options.minSuffixComponents = 1;
-  options.maxSuffixComponents = 1;
-  options.interestLifetime = time::milliseconds(200);
+  options.canBePrefix = true;
   options.mustBeFresh = true;
-  options.wantRightmostChild = true;
+  options.interestLifetime = 200_ms;
   initialize(options);
 
-  auto data = makeData(options.prefix);
+  auto data = makeData(Name(options.name).append("suffix"));
   std::string payload = "NdnPeekTest";
   data->setContent(reinterpret_cast<const uint8_t*>(payload.data()), payload.size());
 
   {
     CoutRedirector redir(output);
     peek->start();
-    this->advanceClocks(io, time::milliseconds(25), 4);
+    this->advanceClocks(io, 25_ms, 4);
     face.receive(*data);
   }
 
   OutputCheck::checkOutput(output, *data);
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getMaxSuffixComponents(), 1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getMinSuffixComponents(), 1);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), time::milliseconds(200));
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getForwardingHint().size(), 0);
+  BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), true);
   BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), true);
-  BOOST_CHECK_EQUAL(face.sentInterests.back().getChildSelector(), 1);
+  BOOST_CHECK(face.sentInterests.back().getForwardingHint().empty());
+  BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), 200_ms);
   BOOST_CHECK(peek->getResultCode() == ResultCode::DATA);
 }
 
@@ -214,7 +201,7 @@
   {
     CoutRedirector redir(output);
     peek->start();
-    this->advanceClocks(io, time::milliseconds(25), 4);
+    this->advanceClocks(io, 25_ms, 4);
     nack = makeNack(face.sentInterests.at(0), lp::NackReason::NO_ROUTE);
     face.receive(nack);
   }
@@ -233,7 +220,7 @@
   {
     CoutRedirector redir(output);
     peek->start();
-    this->advanceClocks(io, time::milliseconds(25), 4);
+    this->advanceClocks(io, 25_ms, 4);
     nack = makeNack(face.sentInterests.at(0), lp::NackReason::NONE);
     face.receive(nack);
   }
@@ -253,7 +240,7 @@
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
 
   peek->start();
-  this->advanceClocks(io, time::milliseconds(25), 4);
+  this->advanceClocks(io, 25_ms, 4);
 
   BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
   BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
@@ -262,14 +249,14 @@
 BOOST_AUTO_TEST_CASE(TimeoutLessThanLifetime)
 {
   auto options = makeDefaultOptions();
-  options.interestLifetime = time::milliseconds(200);
-  options.timeout = time::milliseconds(100);
+  options.interestLifetime = 200_ms;
+  options.timeout = 100_ms;
   initialize(options);
 
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
 
   peek->start();
-  this->advanceClocks(io, time::milliseconds(25), 8);
+  this->advanceClocks(io, 25_ms, 8);
 
   BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
   BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
@@ -278,14 +265,14 @@
 BOOST_AUTO_TEST_CASE(TimeoutGreaterThanLifetime)
 {
   auto options = makeDefaultOptions();
-  options.interestLifetime = time::milliseconds(50);
-  options.timeout = time::milliseconds(200);
+  options.interestLifetime = 50_ms;
+  options.timeout = 200_ms;
   initialize(options);
 
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
 
   peek->start();
-  this->advanceClocks(io, time::milliseconds(25), 4);
+  this->advanceClocks(io, 25_ms, 4);
 
   BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
   BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
diff --git a/tools/peek/ndnpeek/main.cpp b/tools/peek/ndnpeek/main.cpp
index 774d759..f04cec4 100644
--- a/tools/peek/ndnpeek/main.cpp
+++ b/tools/peek/ndnpeek/main.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -50,14 +50,6 @@
 main(int argc, char* argv[])
 {
   PeekOptions options;
-  options.isVerbose = false;
-  options.mustBeFresh = false;
-  options.wantRightmostChild = false;
-  options.wantPayloadOnly = false;
-  options.minSuffixComponents = -1;
-  options.maxSuffixComponents = -1;
-  options.interestLifetime = time::milliseconds(-1);
-  options.timeout = time::milliseconds(-1);
 
   po::options_description genericOptDesc("Generic options");
   genericOptDesc.add_options()
@@ -73,18 +65,14 @@
 
   po::options_description interestOptDesc("Interest construction");
   interestOptDesc.add_options()
+    ("prefix,P", po::bool_switch(&options.canBePrefix),
+        "set CanBePrefix")
     ("fresh,f", po::bool_switch(&options.mustBeFresh),
         "set MustBeFresh")
-    ("rightmost,r", po::bool_switch(&options.wantRightmostChild),
-        "set ChildSelector to rightmost")
-    ("minsuffix,m", po::value<int>(&options.minSuffixComponents),
-        "set MinSuffixComponents")
-    ("maxsuffix,M", po::value<int>(&options.maxSuffixComponents),
-        "set MaxSuffixComponents")
+    ("link-file", po::value<std::string>(),
+        "set ForwardingHint from a file")
     ("lifetime,l", po::value<int>(),
         "set InterestLifetime (in milliseconds)")
-    ("link-file", po::value<std::string>(),
-        "set Link from a file")
   ;
 
   po::options_description visibleOptDesc;
@@ -92,13 +80,13 @@
 
   po::options_description hiddenOptDesc;
   hiddenOptDesc.add_options()
-    ("prefix", po::value<std::string>(), "Interest name");
+    ("name", po::value<std::string>(), "Interest name");
 
   po::options_description optDesc;
   optDesc.add(visibleOptDesc).add(hiddenOptDesc);
 
   po::positional_options_description optPos;
-  optPos.add("prefix", -1);
+  optPos.add("name", -1);
 
   po::variables_map vm;
   try {
@@ -120,8 +108,8 @@
     return 0;
   }
 
-  if (vm.count("prefix") > 0) {
-    options.prefix = vm["prefix"].as<std::string>();
+  if (vm.count("name") > 0) {
+    options.name = vm["name"].as<std::string>();
   }
   else {
     std::cerr << "ERROR: Interest name is missing" << std::endl;
@@ -129,18 +117,6 @@
     return 2;
   }
 
-  if (vm.count("minsuffix") > 0 && options.minSuffixComponents < 0) {
-    std::cerr << "ERROR: MinSuffixComponents must be a non-negative integer" << std::endl;
-    usage(std::cerr, visibleOptDesc);
-    return 2;
-  }
-
-  if (vm.count("maxsuffix") > 0 && options.maxSuffixComponents < 0) {
-    std::cerr << "ERROR: MaxSuffixComponents must be a non-negative integer" << std::endl;
-    usage(std::cerr, visibleOptDesc);
-    return 2;
-  }
-
   if (vm.count("lifetime") > 0) {
     if (vm["lifetime"].as<int>() >= 0) {
       options.interestLifetime = time::milliseconds(vm["lifetime"].as<int>());
diff --git a/tools/peek/ndnpeek/ndnpeek.cpp b/tools/peek/ndnpeek/ndnpeek.cpp
index 372a419..23833f1 100644
--- a/tools/peek/ndnpeek/ndnpeek.cpp
+++ b/tools/peek/ndnpeek/ndnpeek.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -37,8 +37,8 @@
   , m_timeout(options.timeout)
   , m_resultCode(ResultCode::TIMEOUT)
 {
-  if (m_timeout < time::milliseconds::zero()) {
-    m_timeout = m_options.interestLifetime < time::milliseconds::zero() ?
+  if (m_timeout < 0_ms) {
+    m_timeout = m_options.interestLifetime < 0_ms ?
                 DEFAULT_INTEREST_LIFETIME : m_options.interestLifetime;
   }
 }
@@ -68,25 +68,15 @@
 Interest
 NdnPeek::createInterest() const
 {
-  Interest interest(m_options.prefix);
-
-  if (m_options.minSuffixComponents >= 0)
-    interest.setMinSuffixComponents(m_options.minSuffixComponents);
-
-  if (m_options.maxSuffixComponents >= 0)
-    interest.setMaxSuffixComponents(m_options.maxSuffixComponents);
-
-  if (m_options.interestLifetime >= time::milliseconds::zero())
-    interest.setInterestLifetime(m_options.interestLifetime);
-
-  if (m_options.link != nullptr)
+  Interest interest(m_options.name);
+  interest.setCanBePrefix(m_options.canBePrefix);
+  interest.setMustBeFresh(m_options.mustBeFresh);
+  if (m_options.link != nullptr) {
     interest.setForwardingHint(m_options.link->getDelegationList());
-
-  if (m_options.mustBeFresh)
-    interest.setMustBeFresh(true);
-
-  if (m_options.wantRightmostChild)
-    interest.setChildSelector(1);
+  }
+  if (m_options.interestLifetime >= 0_ms) {
+    interest.setInterestLifetime(m_options.interestLifetime);
+  }
 
   if (m_options.isVerbose) {
     std::cerr << "INTEREST: " << interest << std::endl;
diff --git a/tools/peek/ndnpeek/ndnpeek.hpp b/tools/peek/ndnpeek/ndnpeek.hpp
index c8c58b9..4eac8d3 100644
--- a/tools/peek/ndnpeek/ndnpeek.hpp
+++ b/tools/peek/ndnpeek/ndnpeek.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -40,16 +40,17 @@
  */
 struct PeekOptions
 {
-  std::string prefix;
-  int minSuffixComponents;
-  int maxSuffixComponents;
-  time::milliseconds interestLifetime;
-  time::milliseconds timeout;
+  // Interest construction options
+  std::string name;
+  bool canBePrefix = false;
+  bool mustBeFresh = false;
   shared_ptr<Link> link;
-  bool isVerbose;
-  bool mustBeFresh;
-  bool wantRightmostChild;
-  bool wantPayloadOnly;
+  time::milliseconds interestLifetime = -1_ms;
+
+  // output behavior options
+  bool isVerbose = false;
+  time::milliseconds timeout = -1_ms;
+  bool wantPayloadOnly = false;
 };
 
 enum class ResultCode {