fw: strip Link object when Interest reaches producer region

refs #3893

Change-Id: I7cb0a58f75eb4275bbf0fe0c7dcdb583c8519644
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 76e4127..1e01e02 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.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,
@@ -146,6 +146,15 @@
     return;
   }
 
+  // strip Link object if Interest has reached producer region
+  if (interest.hasLink() && m_networkRegionTable.isInProducerRegion(interest.getLink())) {
+    NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
+                  " interest=" << interest.getName() << " reaching-producer-region");
+    Interest& interestRef = const_cast<Interest&>(interest);
+    interestRef.unsetLink();
+    interestRef.unsetSelectedDelegation();
+  }
+
   // PIT insert
   shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;
 
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 4aeb015..0419a22 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -196,7 +196,6 @@
 Strategy::lookupFib(const pit::Entry& pitEntry) const
 {
   const Fib& fib = m_forwarder.getFib();
-  const NetworkRegionTable& nrt = m_forwarder.getNetworkRegionTable();
 
   const Interest& interest = pitEntry.getInterest();
   // has Link object?
@@ -209,13 +208,8 @@
 
   const Link& link = interest.getLink();
 
-  // in producer region?
-  if (nrt.isInProducerRegion(link)) {
-    // FIB lookup with Interest name
-    const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry);
-    NFD_LOG_TRACE("lookupFib inProducerRegion found=" << fibEntry.getPrefix());
-    return fibEntry;
-  }
+  // Link should have been stripped by incoming Interest pipeline when reaching producer region
+  BOOST_ASSERT(!m_forwarder.getNetworkRegionTable().isInProducerRegion(link));
 
   // has SelectedDelegation?
   if (interest.hasSelectedDelegation()) {
diff --git a/tests/daemon/fw/link-forwarding.t.cpp b/tests/daemon/fw/link-forwarding.t.cpp
index 864d598..8bf1dfb 100644
--- a/tests/daemon/fw/link-forwarding.t.cpp
+++ b/tests/daemon/fw/link-forwarding.t.cpp
@@ -70,13 +70,11 @@
       topo.setStrategy<BestRouteStrategy2>(node);
     }
 
-    topo.getForwarder(nodeA).getNetworkRegionTable().insert("/arizona/cs/avenir");
     topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
     topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
-    topo.getForwarder(nodeP).getNetworkRegionTable().insert("/telia/terabits/serverP");
     topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
     topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
-    topo.getForwarder(nodeQ).getNetworkRegionTable().insert("/ucla/cs/serverQ");
+    // NetworkRegionTable configuration is unnecessary on end hosts
 
     linkAH = topo.addLink("AH", time::milliseconds(10), {nodeA, nodeH});
     linkHT = topo.addLink("HT", time::milliseconds(10), {nodeH, nodeT});
@@ -139,12 +137,11 @@
   BOOST_CHECK_EQUAL(interestHT.hasSelectedDelegation(), true);
   BOOST_CHECK_EQUAL(interestHT.getSelectedDelegation(), "/telia/terabits");
 
-  // T forwards to P, no change to Link and SelectedDelegation
+  // T forwards to P, Link and SelectedDelegation are stripped when Interest reaches producer region
   BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
   const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
-  BOOST_CHECK_EQUAL(interestTP.hasLink(), true);
-  BOOST_CHECK_EQUAL(interestTP.hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interestTP.getSelectedDelegation(), "/telia/terabits");
+  BOOST_CHECK_EQUAL(interestTP.hasLink(), false);
+  BOOST_CHECK_EQUAL(interestTP.hasSelectedDelegation(), false);
 
   // Data is served by P and reaches A
   BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
@@ -180,12 +177,11 @@
   BOOST_CHECK_EQUAL(interestCS.hasSelectedDelegation(), true);
   BOOST_CHECK_EQUAL(interestCS.getSelectedDelegation(), "/ucla/cs");
 
-  // S forwards to Q, no change to Link and SelectedDelegation
+  // S forwards to Q, Link and SelectedDelegation are stripped when Interest reaches producer region
   BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
   const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
-  BOOST_CHECK_EQUAL(interestSQ.hasLink(), true);
-  BOOST_CHECK_EQUAL(interestSQ.hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interestSQ.getSelectedDelegation(), "/ucla/cs");
+  BOOST_CHECK_EQUAL(interestSQ.hasLink(), false);
+  BOOST_CHECK_EQUAL(interestSQ.hasSelectedDelegation(), false);
 
   // Data is served by Q and reaches A
   BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);