fw: localhop scope restriction in BestRouteStrategy2

localhop scope rules are implemented as wouldViolateScope function;
the old violatesScope function is now deprecated.
Strategy::sendInterest overload without specific Interest packet is also
deprecated. BestRouteStrategy2 has switched to use the new overload.

refs #3841, #1756

Change-Id: Ic117f01926eadddf1da3ccb580b52a3903a70c89
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index e897b49..6bb1d42 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -24,7 +24,7 @@
  */
 
 #include "best-route-strategy2.hpp"
-#include "pit-algorithm.hpp"
+#include "algorithm.hpp"
 #include "core/logger.hpp"
 
 namespace nfd {
@@ -47,31 +47,33 @@
 }
 
 /** \brief determines whether a NextHop is eligible
- *  \param pitEntry PIT entry
+ *  \param inFace incoming face of current Interest
+ *  \param interest incoming Interest
  *  \param nexthop next hop
- *  \param currentDownstream incoming FaceId of current Interest
+ *  \param pitEntry PIT entry
  *  \param wantUnused if true, NextHop must not have unexpired out-record
  *  \param now time::steady_clock::now(), ignored if !wantUnused
  */
 static inline bool
-predicate_NextHop_eligible(const shared_ptr<pit::Entry>& pitEntry,
-  const fib::NextHop& nexthop, FaceId currentDownstream,
-  bool wantUnused = false,
-  time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min())
+isNextHopEligible(const Face& inFace, const Interest& interest,
+                  const fib::NextHop& nexthop,
+                  const shared_ptr<pit::Entry>& pitEntry,
+                  bool wantUnused = false,
+                  time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min())
 {
-  Face& upstream = nexthop.getFace();
+  const Face& outFace = nexthop.getFace();
 
-  // upstream is current downstream
-  if (upstream.getId() == currentDownstream)
+  // do not forward back to the same face
+  if (&outFace == &inFace)
     return false;
 
   // forwarding would violate scope
-  if (violatesScope(*pitEntry, upstream))
+  if (wouldViolateScope(inFace, interest, outFace))
     return false;
 
   if (wantUnused) {
-    // NextHop must not have unexpired out-record
-    pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(upstream);
+    // nexthop must not have unexpired out-record
+    pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(outFace);
     if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
       return false;
     }
@@ -84,14 +86,14 @@
  *  \note It is assumed that every nexthop has an out-record.
  */
 static inline fib::NextHopList::const_iterator
-findEligibleNextHopWithEarliestOutRecord(const shared_ptr<pit::Entry>& pitEntry,
+findEligibleNextHopWithEarliestOutRecord(const Face& inFace, const Interest& interest,
                                          const fib::NextHopList& nexthops,
-                                         FaceId currentDownstream)
+                                         const shared_ptr<pit::Entry>& pitEntry)
 {
   fib::NextHopList::const_iterator found = nexthops.end();
   time::steady_clock::TimePoint earliestRenewed = time::steady_clock::TimePoint::max();
   for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
-    if (!predicate_NextHop_eligible(pitEntry, *it, currentDownstream))
+    if (!isNextHopEligible(inFace, interest, *it, pitEntry))
       continue;
     pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(it->getFace());
     BOOST_ASSERT(outRecord != pitEntry->out_end());
@@ -121,7 +123,7 @@
   if (suppression == RetxSuppression::NEW) {
     // forward to nexthop with lowest cost except downstream
     it = std::find_if(nexthops.begin(), nexthops.end(),
-      bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(),
+      bind(&isNextHopEligible, cref(inFace), interest, _1, pitEntry,
            false, time::steady_clock::TimePoint::min()));
 
     if (it == nexthops.end()) {
@@ -136,7 +138,7 @@
     }
 
     Face& outFace = it->getFace();
-    this->sendInterest(pitEntry, outFace);
+    this->sendInterest(pitEntry, outFace, interest);
     NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
                            << " newPitEntry-to=" << outFace.getId());
     return;
@@ -144,24 +146,24 @@
 
   // find an unused upstream with lowest cost except downstream
   it = std::find_if(nexthops.begin(), nexthops.end(),
-                    bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(),
+                    bind(&isNextHopEligible, cref(inFace), interest, _1, pitEntry,
                          true, time::steady_clock::now()));
   if (it != nexthops.end()) {
     Face& outFace = it->getFace();
-    this->sendInterest(pitEntry, outFace);
+    this->sendInterest(pitEntry, outFace, interest);
     NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
                            << " retransmit-unused-to=" << outFace.getId());
     return;
   }
 
   // find an eligible upstream that is used earliest
-  it = findEligibleNextHopWithEarliestOutRecord(pitEntry, nexthops, inFace.getId());
+  it = findEligibleNextHopWithEarliestOutRecord(inFace, interest, nexthops, pitEntry);
   if (it == nexthops.end()) {
     NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " retransmitNoNextHop");
   }
   else {
     Face& outFace = it->getFace();
-    this->sendInterest(pitEntry, outFace);
+    this->sendInterest(pitEntry, outFace, interest);
     NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
                            << " retransmit-retry-to=" << outFace.getId());
   }
@@ -226,7 +228,6 @@
     return;
   }
 
-
   NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
                 " nack=" << nack.getReason() <<
                 " nack-to=all out-nack=" << outNack.getReason());