table: add Fib::afterNewNextHop signal

Refs: #4931
Change-Id: I68915b5f5688ad2f62147069fea86956a22672b6
diff --git a/tests/daemon/table/cleanup.t.cpp b/tests/daemon/table/cleanup.t.cpp
index 911de1c..d23bb9b 100644
--- a/tests/daemon/table/cleanup.t.cpp
+++ b/tests/daemon/table/cleanup.t.cpp
@@ -49,7 +49,7 @@
     Name name = Name("/P").appendVersion(i);
 
     fib::Entry* fibEntry = fib.insert(name).first;
-    fibEntry->addOrUpdateNextHop(*face1, 0);
+    fib.addOrUpdateNextHop(*fibEntry, *face1, 0);
 
     shared_ptr<Interest> interest = makeInterest(name);
     shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
@@ -88,24 +88,24 @@
   BOOST_CHECK_EQUAL(fib.size(), 0);
 
   fib::Entry* entryA = fib.insert("/A").first;
-  entryA->addOrUpdateNextHop(*face1, 0);
-  entryA->addOrUpdateNextHop(*face2, 0);
+  fib.addOrUpdateNextHop(*entryA, *face1, 0);
+  fib.addOrUpdateNextHop(*entryA, *face2, 0);
   // {'/A':[1,2]}
 
   fib::Entry* entryB = fib.insert("/B").first;
-  entryB->addOrUpdateNextHop(*face1, 0);
+  fib.addOrUpdateNextHop(*entryB, *face1, 0);
   // {'/A':[1,2], '/B':[1]}
 
   fib::Entry* entryC = fib.insert("/C").first;
-  entryC->addOrUpdateNextHop(*face2, 1);
+  fib.addOrUpdateNextHop(*entryC, *face2, 1);
   // {'/A':[1,2], '/B':[1], '/C':[2]}
 
   fib::Entry* entryB1 = fib.insert("/B/1").first;
-  entryB1->addOrUpdateNextHop(*face1, 0);
+  fib.addOrUpdateNextHop(*entryB1, *face1, 0);
   // {'/A':[1,2], '/B':[1], '/B/1':[1], '/C':[2]}
 
   fib::Entry* entryB12 = fib.insert("/B/1/2").first;
-  entryB12->addOrUpdateNextHop(*face1, 0);
+  fib.addOrUpdateNextHop(*entryB12, *face1, 0);
   // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/C':[2]}
 
   // ---- close face1 ----
diff --git a/tests/daemon/table/fib.t.cpp b/tests/daemon/table/fib.t.cpp
index 33cbdfe..101b3b9 100644
--- a/tests/daemon/table/fib.t.cpp
+++ b/tests/daemon/table/fib.t.cpp
@@ -42,29 +42,53 @@
 
 BOOST_AUTO_TEST_CASE(FibEntry)
 {
-  Name prefix("ndn:/pxWhfFza");
+  NameTree nameTree;
+  Fib fib(nameTree);
+
+  Name prefix("/pxWhfFza");
   shared_ptr<Face> face1 = make_shared<DummyFace>();
   shared_ptr<Face> face2 = make_shared<DummyFace>();
 
-  Entry entry(prefix);
+  Face* expectedFace = nullptr;
+  uint64_t expectedCost = 0;
+  size_t nNewNextHopSignals = 0;
+
+  fib.afterNewNextHop.connect(
+    [&] (const Name& prefix1, const NextHop& nextHop) {
+      ++nNewNextHopSignals;
+      BOOST_CHECK_EQUAL(prefix1, prefix);
+      BOOST_CHECK_EQUAL(&nextHop.getFace(), expectedFace);
+      BOOST_CHECK_EQUAL(nextHop.getCost(), expectedCost);
+    });
+
+  Entry& entry = *fib.insert(prefix).first;
+
   BOOST_CHECK_EQUAL(entry.getPrefix(), prefix);
 
   // []
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
 
-  entry.addOrUpdateNextHop(*face1, 20);
+  expectedFace = face1.get();
+  expectedCost = 20;
+
+  fib.addOrUpdateNextHop(entry, *face1, 20);
   // [(face1,20)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
   BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
+  BOOST_CHECK_EQUAL(nNewNextHopSignals, 1);
 
-  entry.addOrUpdateNextHop(*face1, 30);
+  fib.addOrUpdateNextHop(entry, *face1, 30);
   // [(face1,30)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
   BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 30);
+  BOOST_CHECK_EQUAL(nNewNextHopSignals, 1);
 
-  entry.addOrUpdateNextHop(*face2, 40);
+  expectedFace = face2.get();
+  expectedCost = 40;
+
+  fib.addOrUpdateNextHop(entry, *face2, 40);
   // [(face1,30), (face2,40)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
   {
@@ -80,9 +104,11 @@
 
     ++it;
     BOOST_CHECK(it == entry.getNextHops().end());
+
+    BOOST_CHECK_EQUAL(nNewNextHopSignals, 2);
   }
 
-  entry.addOrUpdateNextHop(*face2, 10);
+  fib.addOrUpdateNextHop(entry, *face2, 10);
   // [(face2,10), (face1,30)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
   {
@@ -98,27 +124,28 @@
 
     ++it;
     BOOST_CHECK(it == entry.getNextHops().end());
+
+    BOOST_CHECK_EQUAL(nNewNextHopSignals, 2);
   }
 
-  entry.removeNextHop(*face1);
+  Fib::RemoveNextHopResult status = fib.removeNextHop(entry, *face1);
   // [(face2,10)]
+  BOOST_CHECK(status == Fib::RemoveNextHopResult::NEXTHOP_REMOVED);
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
 
-  entry.removeNextHop(*face1);
+  status = fib.removeNextHop(entry, *face1);
   // [(face2,10)]
+  BOOST_CHECK(status == Fib::RemoveNextHopResult::NO_SUCH_NEXTHOP);
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
 
-  entry.removeNextHop(*face2);
+  status = fib.removeNextHop(entry, *face2);
   // []
-  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
-
-  entry.removeNextHop(*face2);
-  // []
-  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
+  BOOST_CHECK(status == Fib::RemoveNextHopResult::FIB_ENTRY_REMOVED);
+  BOOST_CHECK(fib.findExactMatch(prefix) == nullptr);
 }
 
 BOOST_AUTO_TEST_CASE(Insert_LongestPrefixMatch)