fw+table: use Interest::Nonce instead of uint32_t

Change-Id: I2a4b83696db80d2d0b675121da53a73c309e059c
diff --git a/daemon/fw/algorithm.cpp b/daemon/fw/algorithm.cpp
index 1ed699b..7dada21 100644
--- a/daemon/fw/algorithm.cpp
+++ b/daemon/fw/algorithm.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -75,7 +75,7 @@
 }
 
 int
-findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face)
+findDuplicateNonce(const pit::Entry& pitEntry, Interest::Nonce nonce, const Face& face)
 {
   int dnw = DUPLICATE_NONCE_NONE;
 
diff --git a/daemon/fw/algorithm.hpp b/daemon/fw/algorithm.hpp
index 07a0e01..68d9f14 100644
--- a/daemon/fw/algorithm.hpp
+++ b/daemon/fw/algorithm.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -70,7 +70,7 @@
  *  \return OR'ed DuplicateNonceWhere
  */
 int
-findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face);
+findDuplicateNonce(const pit::Entry& pitEntry, Interest::Nonce nonce, const Face& face);
 
 /** \brief determine whether \p pitEntry has any pending out-records
  *  \return true if there is at least one out-record waiting for Data
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index 3521b51..142ddea 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -87,14 +87,14 @@
 }
 
 bool
-DeadNonceList::has(const Name& name, uint32_t nonce) const
+DeadNonceList::has(const Name& name, Interest::Nonce nonce) const
 {
   Entry entry = DeadNonceList::makeEntry(name, nonce);
   return m_ht.find(entry) != m_ht.end();
 }
 
 void
-DeadNonceList::add(const Name& name, uint32_t nonce)
+DeadNonceList::add(const Name& name, Interest::Nonce nonce)
 {
   Entry entry = DeadNonceList::makeEntry(name, nonce);
   m_queue.push_back(entry);
@@ -103,11 +103,12 @@
 }
 
 DeadNonceList::Entry
-DeadNonceList::makeEntry(const Name& name, uint32_t nonce)
+DeadNonceList::makeEntry(const Name& name, Interest::Nonce nonce)
 {
   Block nameWire = name.wireEncode();
-  return CityHash64WithSeed(reinterpret_cast<const char*>(nameWire.wire()), nameWire.size(),
-                            static_cast<uint64_t>(nonce));
+  uint32_t n;
+  std::memcpy(&n, nonce.data(), sizeof(n));
+  return CityHash64WithSeed(reinterpret_cast<const char*>(nameWire.wire()), nameWire.size(), n);
 }
 
 size_t
diff --git a/daemon/table/dead-nonce-list.hpp b/daemon/table/dead-nonce-list.hpp
index dea1d51..5b49143 100644
--- a/daemon/table/dead-nonce-list.hpp
+++ b/daemon/table/dead-nonce-list.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -67,15 +67,15 @@
   ~DeadNonceList();
 
   /** \brief Determines if name+nonce exists
-   *  \return true if name+nonce exists
+   *  \return true if name+nonce exists, false otherwise
    */
   bool
-  has(const Name& name, uint32_t nonce) const;
+  has(const Name& name, Interest::Nonce nonce) const;
 
   /** \brief Records name+nonce
    */
   void
-  add(const Name& name, uint32_t nonce);
+  add(const Name& name, Interest::Nonce nonce);
 
   /** \return number of stored Nonces
    *  \note The return value does not contain non-Nonce entries in the index, if any.
@@ -95,7 +95,7 @@
   typedef uint64_t Entry;
 
   static Entry
-  makeEntry(const Name& name, uint32_t nonce);
+  makeEntry(const Name& name, Interest::Nonce nonce);
 
   typedef boost::multi_index_container<
     Entry,
diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp
index 7c36ab6..1a68a51 100644
--- a/daemon/table/pit-face-record.hpp
+++ b/daemon/table/pit-face-record.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -51,7 +51,7 @@
     return m_face;
   }
 
-  uint32_t
+  Interest::Nonce
   getLastNonce() const
   {
     return m_lastNonce;
@@ -79,7 +79,7 @@
 
 private:
   Face& m_face;
-  uint32_t m_lastNonce = 0;
+  Interest::Nonce m_lastNonce{0, 0, 0, 0};
   time::steady_clock::TimePoint m_lastRenewed = time::steady_clock::TimePoint::min();
   time::steady_clock::TimePoint m_expiry = time::steady_clock::TimePoint::min();
 };
diff --git a/tests/daemon/fw/asf-strategy.t.cpp b/tests/daemon/fw/asf-strategy.t.cpp
index 09013ee..14aa777 100644
--- a/tests/daemon/fw/asf-strategy.t.cpp
+++ b/tests/daemon/fw/asf-strategy.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -340,16 +340,14 @@
   topo.registerPrefix(nodeC, linkBC->getFace(nodeC), PRODUCER_PREFIX, 16);
   topo.registerPrefix(nodeB, linkBD->getFace(nodeB), PRODUCER_PREFIX, 80);
 
-  uint32_t nonce;
-
   // Send 6 interest since probes can be scheduled b/w 0-5 seconds
   for (int i = 1; i < 7; i++) {
     // Send ping number i
     Name name(PRODUCER_PREFIX);
     name.appendTimestamp();
-    shared_ptr<Interest> interest = makeInterest(name);
+    auto interest = makeInterest(name);
     ping->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
-    nonce = interest->getNonce();
+    auto nonce = interest->getNonce();
 
     // Don't know when the probe will be triggered since it is random between 0-5 seconds
     // or whether it will be triggered for this interest
@@ -360,13 +358,12 @@
     // Check if probe is sent to B else send another ping
     if (linkAB->getFace(nodeA).getCounters().nOutInterests == 1) {
       // Get pitEntry of node A
-      shared_ptr<pit::Entry> pitEntry = topo.getForwarder(nodeA).getPit().find(*interest);
-      //get outRecord associated with face towards B
-      pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(linkAB->getFace(nodeA));
+      auto pitEntry = topo.getForwarder(nodeA).getPit().find(*interest);
+      // Get outRecord associated with face towards B
+      auto outRecord = pitEntry->getOutRecord(linkAB->getFace(nodeA));
+      BOOST_REQUIRE(outRecord != pitEntry->out_end());
 
-      BOOST_CHECK(outRecord != pitEntry->out_end());
-
-      //Check that Nonce of interest is not equal to Nonce of Probe
+      // Check that Nonce of interest is not equal to Nonce of Probe
       BOOST_CHECK_NE(nonce, outRecord->getLastNonce());
 
       // B should not have received the probe interest yet
@@ -384,7 +381,6 @@
 
       // Get outRecord associated with face towards D.
       outRecord = pitEntry->getOutRecord(linkBD->getFace(nodeB));
-
       BOOST_CHECK(outRecord != pitEntry->out_end());
 
       // RTT between B and D
diff --git a/tests/daemon/table/dead-nonce-list.t.cpp b/tests/daemon/table/dead-nonce-list.t.cpp
index b98cd00..a5a537e 100644
--- a/tests/daemon/table/dead-nonce-list.t.cpp
+++ b/tests/daemon/table/dead-nonce-list.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -39,8 +39,8 @@
 {
   Name nameA("ndn:/A");
   Name nameB("ndn:/B");
-  const uint32_t nonce1 = 0x53b4eaa8;
-  const uint32_t nonce2 = 0x1f46372b;
+  const Interest::Nonce nonce1(0x53b4eaa8);
+  const Interest::Nonce nonce2(0x1f46372b);
 
   DeadNonceList dnl;
   BOOST_CHECK_EQUAL(dnl.size(), 0);
@@ -64,13 +64,8 @@
 protected:
   PeriodicalInsertionFixture()
     : dnl(LIFETIME)
-    , name("ndn:/N")
-    , lastNonce(0)
-    , addNonceBatch(0)
-    , addNonceInterval(LIFETIME / DeadNonceList::EXPECTED_MARK_COUNT)
-    , timeUnit(addNonceInterval / 2)
   {
-    this->addNonce();
+    addNonce();
   }
 
   void
@@ -86,7 +81,7 @@
       dnl.add(name, ++lastNonce);
     }
 
-    if (addNonceInterval > time::nanoseconds::zero()) {
+    if (addNonceInterval > 0_ns) {
       addNonceEvent = getScheduler().schedule(addNonceInterval, [this] { addNonce(); });
     }
   }
@@ -96,17 +91,17 @@
   void
   advanceClocksByLifetime(float t)
   {
-    this->advanceClocks(timeUnit, time::duration_cast<time::nanoseconds>(LIFETIME * t));
+    advanceClocks(timeUnit, time::duration_cast<time::nanoseconds>(LIFETIME * t));
   }
 
 protected:
   static const time::nanoseconds LIFETIME;
   DeadNonceList dnl;
-  Name name;
-  uint32_t lastNonce;
-  size_t addNonceBatch;
-  time::nanoseconds addNonceInterval;
-  time::nanoseconds timeUnit;
+  Name name = "/N";
+  uint32_t lastNonce = 0;
+  size_t addNonceBatch = 0;
+  const time::nanoseconds addNonceInterval = LIFETIME / DeadNonceList::EXPECTED_MARK_COUNT;
+  const time::nanoseconds timeUnit = addNonceInterval / 2;
   scheduler::ScopedEventId addNonceEvent;
 };
 
@@ -121,7 +116,7 @@
   this->advanceClocksByLifetime(10.0);
 
   Name nameC("ndn:/C");
-  const uint32_t nonceC = 0x25390656;
+  const Interest::Nonce nonceC(0x25390656);
   BOOST_CHECK_EQUAL(dnl.has(nameC, nonceC), false);
   dnl.add(nameC, nonceC);
   BOOST_CHECK_EQUAL(dnl.has(nameC, nonceC), true);
diff --git a/tests/test-common.cpp b/tests/test-common.cpp
index 9bc824a..8fe7c59 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-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -32,16 +32,14 @@
 
 shared_ptr<Interest>
 makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime,
-             optional<uint32_t> nonce)
+             optional<Interest::Nonce> nonce)
 {
   auto interest = make_shared<Interest>(name);
   interest->setCanBePrefix(canBePrefix);
   if (lifetime) {
     interest->setInterestLifetime(*lifetime);
   }
-  if (nonce) {
-    interest->setNonce(*nonce);
-  }
+  interest->setNonce(nonce);
   return interest;
 }
 
@@ -59,7 +57,6 @@
   fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
   data.setSignature(fakeSignature);
   data.wireEncode();
-
   return data;
 }
 
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index e123b5e..c5c12bc 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -52,7 +52,7 @@
 shared_ptr<Interest>
 makeInterest(const Name& name, bool canBePrefix = false,
              optional<time::milliseconds> lifetime = nullopt,
-             optional<uint32_t> nonce = nullopt);
+             optional<Interest::Nonce> nonce = nullopt);
 
 /** \brief create a Data with fake signature
  *  \note Data may be modified afterwards without losing the fake signature.
@@ -76,34 +76,22 @@
 }
 
 /** \brief create a Nack
- *  \param interest Interest
- *  \param reason Nack reason
  */
 lp::Nack
 makeNack(Interest interest, lp::NackReason reason);
 
-/** \brief replace a name component
- *  \param[inout] name name
- *  \param index name component index
- *  \param a arguments to name::Component constructor
+/** \brief replace a name component in a packet
+ *  \param[inout] pkt the packet
+ *  \param index the index of the name component to replace
+ *  \param args arguments to name::Component constructor
  */
-template<typename... A>
+template<typename Packet, typename ...Args>
 void
-setNameComponent(Name& name, ssize_t index, A&&... a)
+setNameComponent(Packet& pkt, ssize_t index, Args&& ...args)
 {
-  Name name2 = name.getPrefix(index);
-  name2.append(name::Component(std::forward<A>(a)...));
-  name2.append(name.getSubName(name2.size()));
-  name = std::move(name2);
-}
-
-template<typename Packet, typename... A>
-void
-setNameComponent(Packet& packet, ssize_t index, A&&... a)
-{
-  Name name = packet.getName();
-  setNameComponent(name, index, std::forward<A>(a)...);
-  packet.setName(name);
+  Name name = pkt.getName();
+  name.set(index, name::Component(std::forward<Args>(args)...));
+  pkt.setName(name);
 }
 
 /** \brief create a prefix announcement without signing