rib: Stop removed namespace from inheriting ancestor route

refs: #2757

Change-Id: I9f9e18109f0d8ee45571d23a6eea7f254302a56f
diff --git a/rib/fib-updater.cpp b/rib/fib-updater.cpp
index 839e5ea..8d581be 100644
--- a/rib/fib-updater.cpp
+++ b/rib/fib-updater.cpp
@@ -612,7 +612,8 @@
   // Need to check if the removed route was blocking an inherited route
   Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
 
-  if (!entry.hasCapture()) {
+  // If the current entry has capture set or is pending removal, don't add inherited route
+  if (!entry.hasCapture() && entry.getNRoutes() != 0) {
     // If there is an ancestor route which is the same as the erased route, add that route
     // to the current entry
     Rib::RouteSet::iterator it = ancestorRoutes.find(route);
diff --git a/tests/rib/fib-updates-erase-face.t.cpp b/tests/rib/fib-updates-erase-face.t.cpp
index 2493668..e5204ad 100644
--- a/tests/rib/fib-updates-erase-face.t.cpp
+++ b/tests/rib/fib-updates-erase-face.t.cpp
@@ -377,6 +377,33 @@
   BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
 }
 
+BOOST_AUTO_TEST_CASE(RemoveNamespaceWithAncestorFace) // Bug #2757
+{
+  uint64_t faceId = 263;
+
+  // Register route back to laptop
+  insertRoute("/", faceId, ndn::nfd::ROUTE_ORIGIN_STATIC, 0, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Register remote prefix
+  insertRoute("/Z/A", faceId, ndn::nfd::ROUTE_ORIGIN_CLIENT, 15, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Unregister remote prefix
+  // Should create an update to remove the remote prefix but should not create
+  // an update to add the ancestor route to the remote prefix's namespace
+  eraseRoute("/Z/A", faceId, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::FibUpdateList::const_iterator update = updates.begin();
+  BOOST_CHECK_EQUAL(update->name,  "/Z/A");
+  BOOST_CHECK_EQUAL(update->faceId, faceId);
+  BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
 BOOST_AUTO_TEST_SUITE_END() // EraseFace
 
 BOOST_AUTO_TEST_SUITE_END() // FibUpdates