fw: duplicate Nonce from same face is not loop

refs #3888

Change-Id: I973f58281dca32b5f807d7be82a49d04314cbfb1
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 1e01e02..7a36042 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -159,8 +159,12 @@
   shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;
 
   // detect duplicate Nonce in PIT entry
-  bool hasDuplicateNonceInPit = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), inFace) !=
-                                fw::DUPLICATE_NONCE_NONE;
+  int dnw = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), inFace);
+  bool hasDuplicateNonceInPit = dnw != fw::DUPLICATE_NONCE_NONE;
+  if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
+    // for p2p face: duplicate Nonce from same incoming face is not loop
+    hasDuplicateNonceInPit = hasDuplicateNonceInPit && !(dnw & fw::DUPLICATE_NONCE_IN_SAME);
+  }
   if (hasDuplicateNonceInPit) {
     // goto Interest loop pipeline
     this->onInterestLoop(inFace, interest);
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index 37cb5f9..c669454 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.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-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -173,14 +173,14 @@
   {
   }
 
-  virtual void
+  void
   onDataUnsolicited(Face& inFace, const Data& data) override
   {
     ++onDataUnsolicited_count;
   }
 
 protected:
-  virtual void
+  void
   dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger) override
   {
     ++dispatchToStrategy_count;
@@ -503,13 +503,11 @@
   face1->receiveInterest(*interest1a);
   BOOST_CHECK(face1->sentNacks.empty());
 
-  // receive Interest with duplicate Nonce on face1
+  // receive Interest with duplicate Nonce on face1: legit retransmission
   face1->sentNacks.clear();
   shared_ptr<Interest> interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
   face1->receiveInterest(*interest1b);
-  BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
-  BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest(), *interest1b);
-  BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::DUPLICATE);
+  BOOST_CHECK(face1->sentNacks.empty());
 
   // receive Interest with duplicate Nonce on face2
   face2->sentNacks.clear();