rib: Generate FIB updates using route flags
refs: #1325
Change-Id: I5c567da1c06819caeba5cc5b024914666ba70ab6
diff --git a/tests/rib/fib-updates-common.hpp b/tests/rib/fib-updates-common.hpp
new file mode 100644
index 0000000..c8c0af4
--- /dev/null
+++ b/tests/rib/fib-updates-common.hpp
@@ -0,0 +1,112 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+inline FaceEntry
+createFaceEntry(uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
+{
+ FaceEntry temp;
+ temp.faceId = faceId;
+ temp.origin = origin;
+ temp.cost = cost;
+ temp.flags = flags;
+
+ return temp;
+}
+
+inline bool
+compareNameFaceIdCostAction(const shared_ptr<const FibUpdate>& lhs,
+ const shared_ptr<const FibUpdate>& rhs)
+{
+ if (lhs->name < rhs->name)
+ {
+ return true;
+ }
+ else if (lhs->name == rhs->name)
+ {
+ if (lhs->faceId < rhs->faceId)
+ {
+ return true;
+ }
+ else if (lhs->faceId == rhs->faceId)
+ {
+ if (lhs->cost < rhs->cost)
+ {
+ return true;
+ }
+ else if (lhs->cost == rhs->cost)
+ {
+ return lhs->action < rhs->action;
+ }
+ }
+ }
+
+ return false;
+}
+
+class FibUpdatesFixture : public nfd::tests::BaseFixture
+{
+public:
+ void
+ insertFaceEntry(const Name& name, uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
+ {
+ rib::FaceEntry faceEntry;
+ faceEntry.faceId = faceId;
+ faceEntry.origin = origin;
+ faceEntry.cost = cost;
+ faceEntry.flags = flags;
+
+ rib.insert(name, faceEntry);
+ }
+
+ void
+ eraseFaceEntry(const Name& name, uint64_t faceId, uint64_t origin)
+ {
+ rib::FaceEntry faceEntry;
+ faceEntry.faceId = faceId;
+ faceEntry.origin = origin;
+
+ rib.erase(name, faceEntry);
+ }
+
+
+ Rib::FibUpdateList
+ getSortedFibUpdates()
+ {
+ Rib::FibUpdateList updates = rib.getFibUpdates();
+ updates.sort(&compareNameFaceIdCostAction);
+ return updates;
+ }
+
+public:
+ rib::Rib rib;
+};
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/fib-updates-erase-face.cpp b/tests/rib/fib-updates-erase-face.cpp
new file mode 100644
index 0000000..e56c0d3
--- /dev/null
+++ b/tests/rib/fib-updates-erase-face.cpp
@@ -0,0 +1,396 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/rib.hpp"
+
+#include "tests/test-common.hpp"
+#include "fib-updates-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(EraseFace)
+
+BOOST_AUTO_TEST_CASE(WithInheritedFace_Root)
+{
+ insertFaceEntry("/", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 2, 0, 75, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to remove face 1 from /
+ eraseFaceEntry("/", 1, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(WithInheritedFace)
+{
+ insertFaceEntry("/a", 5, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 5, 255, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 20, 0);
+ insertFaceEntry("/a/b", 3, 0, 5, 0);
+
+ // /a should have face 5 with cost 10; /a/b should have face 3 with cost 5 and
+ // face 5 with cost 10
+ eraseFaceEntry("/a", 5, 255);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to remove face 3 from /a/b and one to remove inherited face.
+ eraseFaceEntry("/a/b", 3, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 3);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(MultipleFaces)
+{
+ insertFaceEntry("/a", 5, 0, 10, 0);
+ insertFaceEntry("/a", 5, 255, 5, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to update cost to 10 for /a
+ eraseFaceEntry("/a", 5, 255);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 5);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_NoCaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to update cost for /a
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(MakeRibEmpty)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to remove face from /
+ eraseFaceEntry("/", 1, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_CaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to remove face from /a
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(BothFlags_NoCaptureChange_CaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+ ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to remove face1 from /a and
+ // 1 to remove face1 to /a/b
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(BothFlags_CaptureChange_NoCaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+ ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to add face1 to /a and
+ // 1 to add face1 to /a/b
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_NoCaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 2 to add face1 to /a and /a/b
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_CaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 2 to remove face 1 from /a and /a/b
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(Capture_CaptureChange_NoCaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to update cost on /a and
+ // 1 to add face1 to /a/b
+ eraseFaceEntry("/a", 1 ,128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(Capture_NoCaptureChange_CaptureOnRoute)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 updates: 1 to remove face from /a
+ eraseFaceEntry("/a", 1, 128);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(EraseFaceById)
+{
+ insertFaceEntry("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 100, 0);
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 4 updates: 4 to remove face ID 1 from /, /a, /a/b, and /a/c
+ rib.erase(1);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 4);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/c");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // EraseFace
+
+BOOST_AUTO_TEST_SUITE_END() // FibUpdates
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/fib-updates-new-face.cpp b/tests/rib/fib-updates-new-face.cpp
new file mode 100644
index 0000000..b8e7d69
--- /dev/null
+++ b/tests/rib/fib-updates-new-face.cpp
@@ -0,0 +1,272 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/rib.hpp"
+
+#include "tests/test-common.hpp"
+#include "fib-updates-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(NewFace)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ // should generate 1 update
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = rib.getFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ // Clear any updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // should generate 2 updates
+ insertFaceEntry("/a", 2, 0, 50, 0);
+
+ updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // should generate 2 updates
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+
+ updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 3);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(UpdateOnLowerCostNoChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, 0);
+
+ // Clear any updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 0 updates
+ insertFaceEntry("/", 1, 128, 75, 0);
+
+ BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: to update cost for face 1 on / and /a
+ insertFaceEntry("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 25);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 25);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 0 updates
+ insertFaceEntry("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 1 update: 1 to add face 5 to /a
+ insertFaceEntry("/a", 5, 128, 50, 0);
+
+ const Rib::FibUpdateList& updates = rib.getFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 5);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(NoCaptureChangeWithChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: one for the inserted face and
+ // one to add face to /a/b
+ insertFaceEntry("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 4);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 4);
+ BOOST_CHECK_EQUAL((*update)->cost, 5);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithoutChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 3 updates:
+ // - one for the inserted face for /a and
+ // - two to remove face1 from /a/b and /a/c
+ insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/c");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates:
+ // - one for the inserted face for /a and
+ // - one to update /a/b with the new cost
+ insertFaceEntry("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE |
+ ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // NewFace
+
+BOOST_AUTO_TEST_SUITE_END() // FibUpdates
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/fib-updates-new-namespace.cpp b/tests/rib/fib-updates-new-namespace.cpp
new file mode 100644
index 0000000..e409c51
--- /dev/null
+++ b/tests/rib/fib-updates-new-namespace.cpp
@@ -0,0 +1,202 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/rib.hpp"
+
+#include "tests/test-common.hpp"
+#include "fib-updates-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(NewNamespace)
+
+BOOST_AUTO_TEST_CASE(NoFlags)
+{
+ // No flags, empty RIB, should generate 1 update for the inserted face
+ insertFaceEntry("/a/b", 1, 0, 10, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ // Reset RIB
+ eraseFaceEntry("/a/b", 1, 0);
+ rib.clearFibUpdates();
+
+ // Parent with child inherit flag
+ insertFaceEntry("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 3 updates, 1 for the inserted face and 2 from inheritance
+ insertFaceEntry("/a/b", 1, 0, 10, 0);
+
+ updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+ update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->cost, 70);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 3);
+ BOOST_CHECK_EQUAL((*update)->cost, 30);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(BothFlags)
+{
+ // Empty RIB, should generate 1 update for the inserted face
+ insertFaceEntry("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+ ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ // Reset RIB
+ eraseFaceEntry("/a", 1, 0);
+ rib.clearFibUpdates();
+
+ insertFaceEntry("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 30, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 3 updates, 1 for the inserted face, 1 to add the face to the child,
+ // and 1 to remove the previously inherited entry
+ insertFaceEntry("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+ ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+ updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+ update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(ChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 2, 0, 10, 0);
+ insertFaceEntry("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 for the inserted face and 1 to add the face to "/a/b"
+ insertFaceEntry("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(Capture)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 2, 0, 10, 0);
+ insertFaceEntry("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 for the inserted face and
+ // 1 to remove inherited face from "/a/b"
+ insertFaceEntry("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // NewNamespace
+
+BOOST_AUTO_TEST_SUITE_END() // FibUpdates
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/fib-updates-update-face.cpp b/tests/rib/fib-updates-update-face.cpp
new file mode 100644
index 0000000..13f5e21
--- /dev/null
+++ b/tests/rib/fib-updates-update-face.cpp
@@ -0,0 +1,266 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/rib.hpp"
+
+#include "tests/test-common.hpp"
+#include "fib-updates-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(UpdateFace)
+
+BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to update the cost of / face 1 to 50 and
+ // 1 to update the cost of /a face 1 to 50
+ insertFaceEntry("/", 1, 128, 75, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 0 updates
+ insertFaceEntry("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates
+ insertFaceEntry("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 25);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 25);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(NoChangeInCost)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 0 updates
+ insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(ChangeCost)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Should generate 2 updates: 1 to add face2 with new cost to /a and
+ // 1 to add face2 with new cost to /a/b
+ insertFaceEntry("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->cost, 300);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->cost, 300);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(TurnOnChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Turn on child inherit flag for the entry in /a
+ // Should generate 1 updates: 1 to add face to /a/b
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 2);
+ BOOST_CHECK_EQUAL((*update)->cost, 10);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(TurnOffChildInherit)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a/b", 2, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 25, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Turn off child inherit flag for the entry in /a
+ // Should generate 1 update: 1 to add face1 to /a/b
+ insertFaceEntry("/a", 1, 0, 100, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(TurnOnCapture)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, 0);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 10, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Turn on capture flag for the entry in /a
+ // Should generate 2 updates: 1 to remove face1 from /a and
+ // 1 to remove face1 from /a/b
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_CASE(TurnOffCapture)
+{
+ insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+ insertFaceEntry("/a/b", 3, 0, 10, 0);
+ insertFaceEntry("/a/c", 1, 0, 10, 0);
+
+ // Clear updates generated from previous insertions
+ rib.clearFibUpdates();
+
+ // Turn off capture flag for the entry in /a
+ // Should generate 2 updates: 1 to add face1 to /a and
+ // 1 to add face1 to /a/b
+ insertFaceEntry("/a", 2, 0, 10, 0);
+
+ Rib::FibUpdateList updates = getSortedFibUpdates();
+ BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+ Rib::FibUpdateList::const_iterator update = updates.begin();
+ BOOST_CHECK_EQUAL((*update)->name, "/a");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+
+ ++update;
+ BOOST_CHECK_EQUAL((*update)->name, "/a/b");
+ BOOST_CHECK_EQUAL((*update)->faceId, 1);
+ BOOST_CHECK_EQUAL((*update)->cost, 50);
+ BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // UpdateFace
+
+BOOST_AUTO_TEST_SUITE_END() // FibUpdates
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/rib.cpp b/tests/rib/rib.cpp
index c3b0eab..2ee3070 100644
--- a/tests/rib/rib.cpp
+++ b/tests/rib/rib.cpp
@@ -63,7 +63,7 @@
BOOST_CHECK_EQUAL(entry.eraseFace(face1), false);
}
-BOOST_AUTO_TEST_CASE(Rib_Parent)
+BOOST_AUTO_TEST_CASE(Parent)
{
rib::Rib rib;
@@ -104,7 +104,7 @@
BOOST_CHECK(ribEntry->getFaces().front().faceId == 2);
}
-BOOST_AUTO_TEST_CASE(Rib_Children)
+BOOST_AUTO_TEST_CASE(Children)
{
rib::Rib rib;
@@ -150,7 +150,7 @@
BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4);
}
-BOOST_AUTO_TEST_CASE(Rib_EraseFace)
+BOOST_AUTO_TEST_CASE(EraseFace)
{
rib::Rib rib;
@@ -195,7 +195,7 @@
rib.erase(name4, entry4);
}
-BOOST_AUTO_TEST_CASE(Rib_EraseRibEntry)
+BOOST_AUTO_TEST_CASE(EraseRibEntry)
{
rib::Rib rib;
@@ -229,7 +229,7 @@
BOOST_CHECK(ribEntry3->getParent() == ribEntry1);
}
-BOOST_AUTO_TEST_CASE(Rib_EraseByFaceId)
+BOOST_AUTO_TEST_CASE(EraseByFaceId)
{
rib::Rib rib;