NFD: Extend forwarding pipelines with beforeSatisfyInterest and beforeExpirePendingInterest signals

Change-Id: I7d8266c3c53b0b6ef791b90c9c93de216b459ad2
Refs: #2361, #2362
diff --git a/NFD/daemon/fw/forwarder.cpp b/NFD/daemon/fw/forwarder.cpp
index 4066e3f..85d7b6c 100644
--- a/NFD/daemon/fw/forwarder.cpp
+++ b/NFD/daemon/fw/forwarder.cpp
@@ -26,7 +26,9 @@
 #include "forwarder.hpp"
 #include "core/logger.hpp"
 #include "core/random.hpp"
+#include "face/null-face.hpp"
 #include "available-strategies.hpp"
+
 #include <boost/random/uniform_int_distribution.hpp>
 
 namespace nfd {
@@ -43,8 +45,10 @@
   , m_pit(m_nameTree)
   , m_measurements(m_nameTree)
   , m_strategyChoice(m_nameTree, fw::makeDefaultStrategy(*this))
+  , m_csFace(make_shared<NullFace>(FaceUri("contentstore://")))
 {
   fw::installStrategies(*this);
+  getFaceTable().addReserved(m_csFace, FACEID_CONTENT_STORE);
 }
 
 Forwarder::~Forwarder()
@@ -104,6 +108,10 @@
       const_cast<Data*>(csMatch)->setIncomingFaceId(FACEID_CONTENT_STORE);
       // XXX should we lookup PIT for other Interests that also match csMatch?
 
+      // invoke PIT satisfy callback
+      beforeSatisfyInterest(*pitEntry, *m_csFace, *csMatch);
+      this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyInterest, _1,
+                                              pitEntry, cref(*m_csFace), cref(*csMatch)));
       // set PIT straggler timer
       this->setStragglerTimer(pitEntry, true, csMatch->getFreshnessPeriod());
 
@@ -226,6 +234,7 @@
   NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName());
 
   // invoke PIT unsatisfied callback
+  beforeExpirePendingInterest(*pitEntry);
   this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeExpirePendingInterest, _1,
                                           pitEntry));
 
@@ -298,6 +307,7 @@
     }
 
     // invoke PIT satisfy callback
+    beforeSatisfyInterest(*pitEntry, inFace, data);
     this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyInterest, _1,
                                             pitEntry, cref(inFace), cref(data)));
 
diff --git a/NFD/daemon/fw/forwarder.hpp b/NFD/daemon/fw/forwarder.hpp
index 627148e..574688f 100644
--- a/NFD/daemon/fw/forwarder.hpp
+++ b/NFD/daemon/fw/forwarder.hpp
@@ -45,6 +45,8 @@
 class Strategy;
 } // namespace fw
 
+class NullFace;
+
 /** \brief main class of NFD
  *
  *  Forwarder owns all faces and tables, and implements forwarding pipelines.
@@ -110,6 +112,17 @@
   void
   setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
 
+public:
+  /** \brief trigger before PIT entry is satisfied
+   *  \sa Strategy::beforeSatisfyInterest
+   */
+  signal::Signal<Forwarder, pit::Entry, Face, Data> beforeSatisfyInterest;
+
+  /** \brief trigger before PIT entry expires
+   *  \sa Strategy::beforeExpirePendingInterest
+   */
+  signal::Signal<Forwarder, pit::Entry> beforeExpirePendingInterest;
+
 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
   /** \brief incoming Interest pipeline
    */
@@ -204,6 +217,7 @@
   Measurements   m_measurements;
   StrategyChoice m_strategyChoice;
   DeadNonceList  m_deadNonceList;
+  shared_ptr<NullFace> m_csFace;
 
   ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;