ping: set CanBePrefix=false

This commit also sets CanBePrefix in ndndump and ndnpoke tests.

refs #4581

Change-Id: Ie91839426acc02f1879495312ad7ef131e8dac57
diff --git a/tests/chunks/consumer.t.cpp b/tests/chunks/consumer.t.cpp
index 37e9abe..ebedd61 100644
--- a/tests/chunks/consumer.t.cpp
+++ b/tests/chunks/consumer.t.cpp
@@ -67,7 +67,7 @@
   output_test_stream output("");
   Consumer cons(security::v2::getAcceptAllValidator(), output);
 
-  auto interest = makeInterest(name);
+  auto interest = makeInterest(name, true);
 
   for (size_t i = 0; i < testStrings.size(); ++i) {
     output.flush();
@@ -106,7 +106,7 @@
   output_test_stream output("");
   Consumer cons(security::v2::getAcceptAllValidator(), output);
 
-  auto interest = makeInterest(name);
+  auto interest = makeInterest(name, true);
   std::vector<shared_ptr<Data>> dataStore;
 
   for (size_t i = 0; i < testStrings.size(); ++i) {
@@ -149,7 +149,7 @@
   {
     isDiscoverRunning = true;
 
-    auto interest = makeInterest(m_prefix);
+    auto interest = makeInterest(m_prefix, true);
     expressInterest(*interest, 1, 1);
   }
 
diff --git a/tests/chunks/producer.t.cpp b/tests/chunks/producer.t.cpp
index c508abc..eea82ca 100644
--- a/tests/chunks/producer.t.cpp
+++ b/tests/chunks/producer.t.cpp
@@ -107,7 +107,7 @@
   size_t nSegments = std::ceil(static_cast<double>(testString.str().size()) / options.maxSegmentSize);
 
   // version request
-  face.receive(*makeInterest(prefix));
+  face.receive(*makeInterest(prefix, true));
   face.processEvents();
 
   BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
@@ -123,7 +123,7 @@
   nameWithVersion.append(lastData.getName()[-2]);
   size_t requestSegmentNo = 1;
 
-  face.receive(*makeInterest(nameWithVersion.appendSegment(requestSegmentNo)));
+  face.receive(*makeInterest(nameWithVersion.appendSegment(requestSegmentNo), true));
   face.processEvents();
 
   BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
@@ -142,7 +142,7 @@
   size_t nSegments = std::ceil(static_cast<double>(testString.str().size()) / options.maxSegmentSize);
 
   // version request
-  face.receive(*makeInterest(prefix));
+  face.receive(*makeInterest(prefix, true));
   face.processEvents();
 
   BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
@@ -158,7 +158,7 @@
   Name nameWithVersion(prefix);
   size_t requestSegmentNo = 1;
 
-  face.receive(*makeInterest(nameWithVersion.appendSegment(requestSegmentNo)));
+  face.receive(*makeInterest(nameWithVersion.appendSegment(requestSegmentNo), true));
   face.processEvents();
 
   BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
@@ -178,7 +178,7 @@
   size_t nSegments = std::ceil(static_cast<double>(testString.str().size()) / options.maxSegmentSize);
 
   // version request
-  face.receive(*makeInterest(prefix));
+  face.receive(*makeInterest(prefix, true));
   face.processEvents();
 
   BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
@@ -192,7 +192,7 @@
   // segment request
   Name nameWithVersion(prefix);
   nameWithVersion.append(lastData.getName()[-2]);
-  face.receive(*makeInterest(nameWithVersion.appendSegment(nSegments)));
+  face.receive(*makeInterest(nameWithVersion.appendSegment(nSegments), true));
   face.processEvents();
 
   // no new data
diff --git a/tests/dump/ndndump.t.cpp b/tests/dump/ndndump.t.cpp
index 771de00..8facd0e 100644
--- a/tests/dump/ndndump.t.cpp
+++ b/tests/dump/ndndump.t.cpp
@@ -167,36 +167,25 @@
 
 BOOST_AUTO_TEST_CASE(Interest)
 {
-  ndn::Interest interest("/test");
-  interest.setNonce(0);
-
-  this->receive(interest);
-
-  BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?ndn.Nonce=0\n"));
+  this->receive(*makeInterest("/test", true, DEFAULT_INTEREST_LIFETIME, 1));
+  BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?ndn.Nonce=1\n"));
 }
 
 BOOST_AUTO_TEST_CASE(Data)
 {
-  ndn::Data data("/test");
-  m_keyChain.sign(data);
-
-  this->receive(data);
-
+  this->receive(*makeData("/test"));
   BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
 }
 
 BOOST_AUTO_TEST_CASE(Nack)
 {
-  ndn::Interest interest("/test");
-  interest.setNonce(0);
-  lp::Nack nack(interest);
-  nack.setReason(lp::NackReason::DUPLICATE);
-  lp::Packet lpPacket(interest.wireEncode());
+  auto interest = makeInterest("/test", true, DEFAULT_INTEREST_LIFETIME, 1);
+  auto nack = makeNack(*interest, lp::NackReason::DUPLICATE);
+  lp::Packet lpPacket(interest->wireEncode());
   lpPacket.add<lp::NackField>(nack.getHeader());
 
   this->receive(lpPacket);
-
-  BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?ndn.Nonce=0\n"));
+  BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?ndn.Nonce=1\n"));
 }
 
 BOOST_AUTO_TEST_CASE(LpFragment)
@@ -214,16 +203,13 @@
   lpPacket.add<lp::SequenceField>(1000);
 
   this->receive(lpPacket);
-
   BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n"));
 }
 
 BOOST_AUTO_TEST_CASE(LpIdle)
 {
   lp::Packet lpPacket;
-
   this->receive(lpPacket);
-
   BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n"));
 }
 
@@ -237,21 +223,17 @@
     0x0a, 0x04, // Nonce
       0x00, 0x00, 0x00, 0x01
   };
-
   EncodingBuffer buffer;
   buffer.prependByteArray(interest, 4);
 
   this->receiveEthernet(buffer);
-
   BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n"));
 }
 
 BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket)
 {
   EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name));
-
   this->receiveEthernet(buffer);
-
   BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n"));
 }
 
@@ -262,7 +244,6 @@
   endian::native_to_big_inplace(type);
 
   this->receiveEthernet(pkt, type);
-
   BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n"));
 }
 
diff --git a/tests/peek/ndnpoke.t.cpp b/tests/peek/ndnpoke.t.cpp
index d8bbb69..f569f03 100644
--- a/tests/peek/ndnpoke.t.cpp
+++ b/tests/peek/ndnpoke.t.cpp
@@ -84,8 +84,7 @@
   BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
   BOOST_CHECK_EQUAL(face.sentInterests.front().getName().getPrefix(4), "/localhost/nfd/rib/register");
 
-  Interest interest("/poke/test");
-  face.receive(interest);
+  face.receive(*makeInterest("/poke/test"));
   this->advanceClocks(io, 1_ms, 10);
   io.run();
 
@@ -112,8 +111,7 @@
 
   this->advanceClocks(io, 1_ms, 10);
 
-  Interest interest("/poke/test/123");
-  face.receive(interest);
+  face.receive(*makeInterest("/poke/test/123"));
   this->advanceClocks(io, 1_ms, 10);
   io.run();
 
@@ -136,8 +134,7 @@
 
   this->advanceClocks(io, 1_ms, 10);
 
-  Interest interest("/poke/test");
-  face.receive(interest);
+  face.receive(*makeInterest("/poke/test"));
   this->advanceClocks(io, 1_ms, 10);
   io.run();
 
@@ -159,8 +156,7 @@
 
   this->advanceClocks(io, 1_ms, 10);
 
-  Interest interest("/poke/test");
-  face.receive(interest);
+  face.receive(*makeInterest("/poke/test"));
   this->advanceClocks(io, 1_ms, 10);
   io.run();
 
@@ -203,8 +199,7 @@
 
   this->advanceClocks(io, 1_ms, 10);
 
-  Interest interest("/poke/test");
-  face.receive(interest);
+  face.receive(*makeInterest("/poke/test"));
   BOOST_CHECK_THROW(face.processEvents(), Face::OversizedPacketError);
 
   // We can't check wasDataSent() correctly here because it will be set to true, even if put failed
diff --git a/tests/ping/server/ping-server.t.cpp b/tests/ping/server/ping-server.t.cpp
index 84e967f..1fe5b35 100644
--- a/tests/ping/server/ping-server.t.cpp
+++ b/tests/ping/server/ping-server.t.cpp
@@ -52,6 +52,7 @@
         .append(to_string(seq));
 
     return Interest(name)
+           .setCanBePrefix(false)
            .setMustBeFresh(true)
            .setInterestLifetime(2_s);
   }
diff --git a/tests/test-common.cpp b/tests/test-common.cpp
index fe45dd9..f180a5e 100644
--- a/tests/test-common.cpp
+++ b/tests/test-common.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,
@@ -75,9 +75,10 @@
 }
 
 shared_ptr<Interest>
-makeInterest(const Name& name, uint32_t nonce)
+makeInterest(const Name& name, bool canBePrefix, time::milliseconds lifetime, uint32_t nonce)
 {
-  auto interest = make_shared<Interest>(name);
+  auto interest = make_shared<Interest>(name, lifetime);
+  interest->setCanBePrefix(canBePrefix);
   if (nonce != 0) {
     interest->setNonce(nonce);
   }
@@ -109,13 +110,5 @@
   return nack;
 }
 
-lp::Nack
-makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
-{
-  Interest interest(name);
-  interest.setNonce(nonce);
-  return makeNack(interest, reason);
-}
-
 } // namespace tests
 } // namespace ndn
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index c0052e2..39fe434 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -75,11 +75,13 @@
 
 /** \brief create an Interest
  *  \param name Interest name
- *  \param nonce if non-zero, set Nonce to this value
- *               (useful for creating Nack with same Nonce)
+ *  \param canBePrefix CanBePrefix setting
+ *  \param lifetime InterestLifetime
+ *  \param nonce if non-zero, set Nonce to this value (useful for creating Nack with same Nonce)
  */
 shared_ptr<Interest>
-makeInterest(const Name& name, uint32_t nonce = 0);
+makeInterest(const Name& name, bool canBePrefix = false,
+             time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME, uint32_t nonce = 0);
 
 /** \brief create a Data with fake signature
  *  \note Data may be modified afterwards without losing the fake signature.
@@ -96,7 +98,7 @@
 /** \brief add a fake signature to Data
  */
 inline shared_ptr<Data>
-signData(shared_ptr<Data> data)
+signData(const shared_ptr<Data>& data)
 {
   signData(*data);
   return data;
@@ -109,14 +111,6 @@
 lp::Nack
 makeNack(const Interest& interest, lp::NackReason reason);
 
-/** \brief create a Nack
- *  \param name Interest name
- *  \param nonce Interest nonce
- *  \param reason Nack reason
- */
-lp::Nack
-makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
-
 } // namespace tests
 } // namespace ndn
 
diff --git a/tools/ping/README.md b/tools/ping/README.md
index 8c0c513..8df5adc 100644
--- a/tools/ping/README.md
+++ b/tools/ping/README.md
@@ -67,8 +67,10 @@
 one or more printable characters only, to make it easier for a human operator to read the logs.
 A client implementation MAY restrict this field to be non-empty and have printable characters only.
 
-The probe Interest SHOULD carry MustBeFresh selector by default.
-A client implementation MAY allow the operator to turn off MustBeFresh selector.
+The probe Interest SHOULD NOT carry CanBePrefix element.
+
+The probe Interest SHOULD carry MustBeFresh element.
+A client implementation MAY allow the operator to remove MustBeFresh element.
 
 ### Reply Data
 
diff --git a/tools/ping/client/ping.cpp b/tools/ping/client/ping.cpp
index c6290b0..7f2e2a4 100644
--- a/tools/ping/client/ping.cpp
+++ b/tools/ping/client/ping.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.
@@ -62,6 +62,7 @@
   Name pingPacketName = makePingName(m_nextSeq);
 
   Interest interest(pingPacketName);
+  interest.setCanBePrefix(false);
   interest.setMustBeFresh(!m_options.shouldAllowStaleData);
   interest.setInterestLifetime(m_options.timeout);