fw+table: add isSatisfied and dataFreshnessPeriod to PIT entry

Change-Id: I00731028131139164adca342d0a0fd7d3af0709a
refs: #4290
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index cea2974..8c0bb55 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -205,8 +205,11 @@
   data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
   // XXX should we lookup PIT for other Interests that also match csMatch?
 
+  pitEntry->isSatisfied = true;
+  pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
+
   // set PIT straggler timer
-  this->setStragglerTimer(pitEntry, true, data.getFreshnessPeriod());
+  this->setStragglerTimer(pitEntry);
 
   // goto outgoing Data pipeline
   this->onOutgoingData(data, *const_pointer_cast<Face>(inFace.shared_from_this()));
@@ -240,18 +243,17 @@
   this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
 
   // set PIT straggler timer
-  this->setStragglerTimer(pitEntry, false);
+  this->setStragglerTimer(pitEntry);
 }
 
 void
-Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                              ndn::optional<time::milliseconds> dataFreshnessPeriod)
+Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
 {
   NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName() <<
-                (isSatisfied ? " satisfied" : " unsatisfied"));
+                (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
 
   // Dead Nonce List insert if necessary
-  this->insertDeadNonceList(*pitEntry, isSatisfied, dataFreshnessPeriod, 0);
+  this->insertDeadNonceList(*pitEntry, 0);
 
   // PIT delete
   this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
@@ -307,15 +309,18 @@
     this->dispatchToStrategy(*pitEntry,
       [&] (fw::Strategy& strategy) { strategy.beforeSatisfyInterest(pitEntry, inFace, data); });
 
+    pitEntry->isSatisfied = true;
+    pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
+
     // Dead Nonce List insert if necessary (for out-record of inFace)
-    this->insertDeadNonceList(*pitEntry, true, data.getFreshnessPeriod(), &inFace);
+    this->insertDeadNonceList(*pitEntry, &inFace);
 
     // mark PIT satisfied
     pitEntry->clearInRecords();
     pitEntry->deleteOutRecord(inFace);
 
     // set PIT straggler timer
-    this->setStragglerTimer(pitEntry, true, data.getFreshnessPeriod());
+    this->setStragglerTimer(pitEntry);
   }
 
   // foreach pending downstream
@@ -498,18 +503,17 @@
 
   scheduler::cancel(pitEntry->m_unsatisfyTimer);
   pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow,
-    bind(&Forwarder::onInterestFinalize, this, pitEntry, false, ndn::nullopt));
+    bind(&Forwarder::onInterestFinalize, this, pitEntry));
 }
 
 void
-Forwarder::setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                             ndn::optional<time::milliseconds> dataFreshnessPeriod)
+Forwarder::setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry)
 {
   time::nanoseconds stragglerTime = time::milliseconds(100);
 
   scheduler::cancel(pitEntry->m_stragglerTimer);
   pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime,
-    bind(&Forwarder::onInterestFinalize, this, pitEntry, isSatisfied, dataFreshnessPeriod));
+    bind(&Forwarder::onInterestFinalize, this, pitEntry));
 }
 
 void
@@ -527,16 +531,14 @@
 }
 
 void
-Forwarder::insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                               ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream)
+Forwarder::insertDeadNonceList(pit::Entry& pitEntry, Face* upstream)
 {
   // need Dead Nonce List insert?
   bool needDnl = true;
-  if (isSatisfied) {
-    BOOST_ASSERT(dataFreshnessPeriod);
-    BOOST_ASSERT(*dataFreshnessPeriod >= time::milliseconds::zero());
+  if (pitEntry.isSatisfied) {
+    BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms);
     needDnl = static_cast<bool>(pitEntry.getInterest().getMustBeFresh()) &&
-              *dataFreshnessPeriod < m_deadNonceList.getLifetime();
+              pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime();
   }
 
   if (!needDnl) {
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index a61aae8..c50c573 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -215,12 +215,9 @@
   onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
 
   /** \brief Interest finalize pipeline
-   *  \param isSatisfied whether the Interest has been satisfied
-   *  \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
    */
   VIRTUAL_WITH_TESTS void
-  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                     ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
+  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
 
   /** \brief incoming Data pipeline
    */
@@ -255,8 +252,7 @@
   setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
 
   VIRTUAL_WITH_TESTS void
-  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                    ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
+  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry);
 
   VIRTUAL_WITH_TESTS void
   cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
@@ -266,8 +262,7 @@
    *                  if not null, insert Nonce only on the out-records of this face
    */
   VIRTUAL_WITH_TESTS void
-  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                      ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
+  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
 
   /** \brief call trigger (method) on the effective strategy of pitEntry
    */
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index 157b9f9..ee4b726 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.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,
@@ -30,7 +30,9 @@
 namespace pit {
 
 Entry::Entry(const Interest& interest)
-  : m_interest(interest.shared_from_this())
+  : isSatisfied(false)
+  , dataFreshnessPeriod(0_ms)
+  , m_interest(interest.shared_from_this())
   , m_nameTreeEntry(nullptr)
 {
 }
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 31a2f04..9cfb0a4 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -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,
@@ -236,6 +236,15 @@
    */
   scheduler::EventId m_stragglerTimer;
 
+  /** \brief indicate if PIT entry is satisfied
+   */
+  bool isSatisfied;
+
+  /** \brief Data freshness period
+   *  \note This field is meaningful only if isSatisfied is true
+   */
+  time::milliseconds dataFreshnessPeriod;
+
 private:
   shared_ptr<const Interest> m_interest;
   InRecordCollection m_inRecords;