fib: add EndpointId field in NextHop record

refs: #4284

Change-Id: If0cfc21cfa81d6fa3c1590ecdce8fbbc1ea95e13
diff --git a/tests/daemon/table/cleanup.t.cpp b/tests/daemon/table/cleanup.t.cpp
index 20638ab..3365a50 100644
--- a/tests/daemon/table/cleanup.t.cpp
+++ b/tests/daemon/table/cleanup.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-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -50,7 +50,7 @@
     Name name = Name("/P").appendVersion(i);
 
     fib::Entry* fibEntry = fib.insert(name).first;
-    fibEntry->addNextHop(*face1, 0);
+    fibEntry->addOrUpdateNextHop(*face1, 0, 0);
 
     shared_ptr<Interest> interest = makeInterest(name);
     shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
@@ -89,24 +89,24 @@
   BOOST_CHECK_EQUAL(fib.size(), 0);
 
   fib::Entry* entryA = fib.insert("/A").first;
-  entryA->addNextHop(*face1, 0);
-  entryA->addNextHop(*face2, 0);
+  entryA->addOrUpdateNextHop(*face1, 0, 0);
+  entryA->addOrUpdateNextHop(*face2, 0, 0);
   // {'/A':[1,2]}
 
   fib::Entry* entryB = fib.insert("/B").first;
-  entryB->addNextHop(*face1, 0);
+  entryB->addOrUpdateNextHop(*face1, 0, 0);
   // {'/A':[1,2], '/B':[1]}
 
   fib::Entry* entryC = fib.insert("/C").first;
-  entryC->addNextHop(*face2, 1);
+  entryC->addOrUpdateNextHop(*face2, 0, 1);
   // {'/A':[1,2], '/B':[1], '/C':[2]}
 
   fib::Entry* entryB1 = fib.insert("/B/1").first;
-  entryB1->addNextHop(*face1, 0);
+  entryB1->addOrUpdateNextHop(*face1, 0, 0);
   // {'/A':[1,2], '/B':[1], '/B/1':[1], '/C':[2]}
 
   fib::Entry* entryB12 = fib.insert("/B/1/2").first;
-  entryB12->addNextHop(*face1, 0);
+  entryB12->addOrUpdateNextHop(*face1, 0, 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 204c5a3..0a6ccff 100644
--- a/tests/daemon/table/fib.t.cpp
+++ b/tests/daemon/table/fib.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-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -51,71 +51,138 @@
   // []
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
 
-  entry.addNextHop(*face1, 20);
-  // [(face1,20)]
+  // [(face, cost, endpointId)]
+  entry.addOrUpdateNextHop(*face1, 200, 20);
+  // [(face1,200,20)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
   BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
+  BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getEndpointId(), 200);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
 
-  entry.addNextHop(*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);
-
-  entry.addNextHop(*face2, 40);
-  // [(face1,30), (face2,40)]
+  entry.addOrUpdateNextHop(*face1, 300, 30);
+  // [(face1,200,20), (face1,300,30)]
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
+  BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
+  BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getEndpointId(), 200);
+  BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
+
+  entry.addOrUpdateNextHop(*face2, 400, 40);
+  // [(face1,200,20), (face1,300,30), (face2,400,40)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 3);
   {
     NextHopList::const_iterator it = entry.getNextHops().begin();
     BOOST_REQUIRE(it != entry.getNextHops().end());
     BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 200);
+    BOOST_CHECK_EQUAL(it->getCost(), 20);
+
+    ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 300);
     BOOST_CHECK_EQUAL(it->getCost(), 30);
 
     ++it;
     BOOST_REQUIRE(it != entry.getNextHops().end());
     BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 400);
     BOOST_CHECK_EQUAL(it->getCost(), 40);
 
     ++it;
     BOOST_CHECK(it == entry.getNextHops().end());
   }
 
-  entry.addNextHop(*face2, 10);
-  // [(face2,10), (face1,30)]
-  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
+  entry.addOrUpdateNextHop(*face2, 100, 10);
+  // [(face2,100,10), (face1,200,20), (face1,300,30), (face2,400,40)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 4);
   {
     NextHopList::const_iterator it = entry.getNextHops().begin();
     BOOST_REQUIRE(it != entry.getNextHops().end());
     BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 100);
     BOOST_CHECK_EQUAL(it->getCost(), 10);
 
     ++it;
     BOOST_REQUIRE(it != entry.getNextHops().end());
     BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 200);
+    BOOST_CHECK_EQUAL(it->getCost(), 20);
+
+    ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 300);
     BOOST_CHECK_EQUAL(it->getCost(), 30);
 
     ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 400);
+    BOOST_CHECK_EQUAL(it->getCost(), 40);
+
+    ++it;
     BOOST_CHECK(it == entry.getNextHops().end());
   }
 
-  entry.removeNextHop(*face1);
-  // [(face2,10)]
-  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+  entry.addOrUpdateNextHop(*face1, 200, 50);
+  // [(face2,100,10), (face1,300,30), (face2,400,40), (face1,200,50)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 4);
+  {
+    NextHopList::const_iterator it = entry.getNextHops().begin();
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 100);
+    BOOST_CHECK_EQUAL(it->getCost(), 10);
+
+    ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 300);
+    BOOST_CHECK_EQUAL(it->getCost(), 30);
+
+    ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 400);
+    BOOST_CHECK_EQUAL(it->getCost(), 40);
+
+    ++it;
+    BOOST_REQUIRE(it != entry.getNextHops().end());
+    BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+    BOOST_CHECK_EQUAL(it->getEndpointId(), 200);
+    BOOST_CHECK_EQUAL(it->getCost(), 50);
+
+    ++it;
+    BOOST_CHECK(it == entry.getNextHops().end());
+  }
+
+  entry.removeNextHop(*face1, 200);
+  // [(face2,100,10), (face1,300,30), (face2,400,40)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 3);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
+  BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getEndpointId(), 100);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
 
-  entry.removeNextHop(*face1);
-  // [(face2,10)]
-  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+  entry.removeNextHop(*face1, 200);
+  // [(face2,100,10), (face1,300,30), (face2,400,40)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 3);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
+  BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getEndpointId(), 100);
   BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
 
-  entry.removeNextHop(*face2);
+  entry.removeNextHop(*face2,100);
+  // [(face1,300,30), (face2,400,40)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
+
+  entry.removeNextHop(*face2,400);
+  // [(face1,300,30)]
+  BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+
+  entry.removeNextHop(*face1,300);
   // []
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
 
-  entry.removeNextHop(*face2);
+  entry.removeNextHop(*face1,300);
   // []
   BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
 }