rib: Don't add inherited routes to RIB entries pending removal

refs: #3404

Change-Id: I33a4ee7aa4e286a562c720656cb9e4ee7753ae05
diff --git a/rib/fib-updater.cpp b/rib/fib-updater.cpp
index 8478fe6..7cd4bed 100644
--- a/rib/fib-updater.cpp
+++ b/rib/fib-updater.cpp
@@ -568,10 +568,10 @@
     Rib::RouteSet routesToRemove;
     routesToRemove.insert(route);
 
-    // If capture is turned off for the route, need to add ancestors
-    // to self and children
+    // If capture is turned off for the route and another route is installed in the RibEntry,
+    // add ancestors to self
     Rib::RouteSet routesToAdd;
-    if (captureWasTurnedOff) {
+    if (captureWasTurnedOff && entry.getNRoutes() != 0) {
       // Look for an ancestors that were blocked previously
       routesToAdd = m_rib.getAncestorRoutes(entry);
 
@@ -595,10 +595,10 @@
     modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
   }
   else if (route.isCapture()) {
-    // If capture is turned off for the route, need to add ancestors
-    // to self and children
+    // If capture is turned off for the route and another route is installed in the RibEntry,
+    // add ancestors to self
     Rib::RouteSet routesToAdd;
-    if (captureWasTurnedOff) {
+    if (captureWasTurnedOff && entry.getNRoutes() != 0) {
       // Look for an ancestors that were blocked previously
       routesToAdd = m_rib.getAncestorRoutes(entry);
 
diff --git a/tests/rib/fib-updates-erase-face.t.cpp b/tests/rib/fib-updates-erase-face.t.cpp
index e5204ad..74002d8 100644
--- a/tests/rib/fib-updates-erase-face.t.cpp
+++ b/tests/rib/fib-updates-erase-face.t.cpp
@@ -404,6 +404,24 @@
   BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
 }
 
+BOOST_AUTO_TEST_CASE(RemoveNamespaceWithCapture) // Bug #3404
+{
+  insertRoute("/", 262, ndn::nfd::ROUTE_ORIGIN_STATIC, 0, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  uint64_t appFaceId = 264;
+  ndn::Name ndnConPrefix("/ndn/edu/site/ndnrtc/user/username/streams/main_camera/low");
+  insertRoute(ndnConPrefix, appFaceId, ndn::nfd::ROUTE_ORIGIN_CLIENT, 0,
+              ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  destroyFace(appFaceId);
+
+  // FibUpdater should not generate any inherited routes for the erased RibEntry
+  BOOST_CHECK_EQUAL(fibUpdater.m_inheritedRoutes.size(), 0);
+}
+
 BOOST_AUTO_TEST_SUITE_END() // EraseFace
 
 BOOST_AUTO_TEST_SUITE_END() // FibUpdates