rib: move entire subdir to daemon/rib

Refs: #4528
Change-Id: I7de03631ddef0f014f12f979373aa449f42486d1
diff --git a/tests/daemon/rib/create-route.hpp b/tests/daemon/rib/create-route.hpp
new file mode 100644
index 0000000..b248575
--- /dev/null
+++ b/tests/daemon/rib/create-route.hpp
@@ -0,0 +1,53 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_RIB_CREATE_ROUTE_HPP
+#define NFD_TESTS_DAEMON_RIB_CREATE_ROUTE_HPP
+
+#include "rib/route.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+inline Route
+createRoute(uint64_t faceId,
+            std::underlying_type_t<ndn::nfd::RouteOrigin> origin,
+            uint64_t cost = 0,
+            std::underlying_type_t<ndn::nfd::RouteFlags> flags = ndn::nfd::ROUTE_FLAGS_NONE)
+{
+  Route r;
+  r.faceId = faceId;
+  r.origin = static_cast<ndn::nfd::RouteOrigin>(origin);
+  r.cost = cost;
+  r.flags = flags;
+  return r;
+}
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_RIB_CREATE_ROUTE_HPP
diff --git a/tests/daemon/rib/fib-updates-common.hpp b/tests/daemon/rib/fib-updates-common.hpp
new file mode 100644
index 0000000..4668af5
--- /dev/null
+++ b/tests/daemon/rib/fib-updates-common.hpp
@@ -0,0 +1,159 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP
+#define NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP
+
+#include "rib/fib-updater.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+#include "tests/daemon/rib/create-route.hpp"
+
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+inline bool
+compareNameFaceIdCostAction(const FibUpdate& lhs, 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::IdentityManagementFixture
+{
+public:
+  FibUpdatesFixture()
+    : face(g_io, m_keyChain)
+    , controller(face, m_keyChain)
+    , fibUpdater(rib, controller)
+  {
+  }
+
+  void
+  insertRoute(const Name& name, uint64_t faceId,
+              std::underlying_type_t<ndn::nfd::RouteOrigin> origin,
+              uint64_t cost,
+              std::underlying_type_t<ndn::nfd::RouteFlags> flags)
+  {
+    Route route = createRoute(faceId, origin, cost, flags);
+
+    RibUpdate update;
+    update.setAction(RibUpdate::REGISTER)
+          .setName(name)
+          .setRoute(route);
+
+    simulateSuccessfulResponse();
+    rib.beginApplyUpdate(update, nullptr, nullptr);
+  }
+
+  void
+  eraseRoute(const Name& name, uint64_t faceId,
+             std::underlying_type_t<ndn::nfd::RouteOrigin> origin)
+  {
+    Route route = createRoute(faceId, origin, 0, 0);
+
+    RibUpdate update;
+    update.setAction(RibUpdate::UNREGISTER)
+          .setName(name)
+          .setRoute(route);
+
+    simulateSuccessfulResponse();
+    rib.beginApplyUpdate(update, nullptr, nullptr);
+  }
+
+  void
+  destroyFace(uint64_t faceId)
+  {
+    simulateSuccessfulResponse();
+    rib.beginRemoveFace(faceId);
+  }
+
+  const FibUpdater::FibUpdateList&
+  getFibUpdates()
+  {
+    fibUpdates.clear();
+    fibUpdates = fibUpdater.m_updatesForBatchFaceId;
+    fibUpdates.insert(fibUpdates.end(), fibUpdater.m_updatesForNonBatchFaceId.begin(),
+                                        fibUpdater.m_updatesForNonBatchFaceId.end());
+
+    return fibUpdates;
+  }
+
+  FibUpdater::FibUpdateList
+  getSortedFibUpdates()
+  {
+    FibUpdater::FibUpdateList updates = getFibUpdates();
+    updates.sort(&compareNameFaceIdCostAction);
+    return updates;
+  }
+
+  void
+  clearFibUpdates()
+  {
+    fibUpdater.m_updatesForBatchFaceId.clear();
+    fibUpdater.m_updatesForNonBatchFaceId.clear();
+  }
+
+private:
+  void
+  simulateSuccessfulResponse()
+  {
+    rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
+    rib.wantMockFibResponseOnce = true;
+  }
+
+public:
+  ndn::util::DummyClientFace face;
+  ndn::nfd::Controller controller;
+
+  Rib rib;
+  FibUpdater fibUpdater;
+  FibUpdater::FibUpdateList fibUpdates;
+};
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP
diff --git a/tests/daemon/rib/fib-updates-erase-face.t.cpp b/tests/daemon/rib/fib-updates-erase-face.t.cpp
new file mode 100644
index 0000000..d55f207
--- /dev/null
+++ b/tests/daemon/rib/fib-updates-erase-face.t.cpp
@@ -0,0 +1,431 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016,  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(TestFibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(EraseFace)
+
+BOOST_AUTO_TEST_CASE(WithInheritedFace_Root)
+{
+  insertRoute("/", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 2, 0, 75, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to remove face 1 from /
+  eraseRoute("/", 1, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/a", 5, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 5, 255, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 20, 0);
+  insertRoute("/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
+  eraseRoute("/a", 5, 255);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 to remove face 3 from /a/b and one to remove inherited route
+  eraseRoute("/a/b", 3, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/a", 5, 0, 10, 0);
+  insertRoute("/a", 5, 255, 5, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to update cost to 10 for /a
+  eraseRoute("/a", 5, 255);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to update cost for /a
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to remove route from /
+  eraseRoute("/", 1, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to remove route from /a
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+                                     ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 to remove face1 from /a and
+  // 1 to remove face1 from /a/b
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
+                                     ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 to add face1 to /a and
+  // 1 to add face1 to /a/b
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 2 to add face1 to /a and /a/b
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 2 to remove face 1 from /a and /a/b
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 to update cost on /a and
+  // 1 to add face1 to /a/b
+  eraseRoute("/a", 1 ,128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 updates: 1 to remove route from /a
+  eraseRoute("/a", 1, 128);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 3, 0, 10, 0);
+  insertRoute("/a/b", 4, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 100, 0);
+  insertRoute("/a", 2, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 2 to add face ID 1 to /a and /a/b
+  destroyFace(2);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::FibUpdateList::const_iterator update = updates.begin();
+  BOOST_CHECK_EQUAL(update->name,  "/a");
+  BOOST_CHECK_EQUAL(update->faceId, 1);
+  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::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_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
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/fib-updates-new-face.t.cpp b/tests/daemon/rib/fib-updates-new-face.t.cpp
new file mode 100644
index 0000000..49cd56f
--- /dev/null
+++ b/tests/daemon/rib/fib-updates-new-face.t.cpp
@@ -0,0 +1,272 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015,  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(TestFibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(NewFace)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  // should generate 1 update
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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
+  clearFibUpdates();
+
+  // should generate 2 updates
+  insertRoute("/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
+  clearFibUpdates();
+
+  // should generate 2 updates
+  insertRoute("/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)
+{
+  insertRoute("/", 1, 0, 50, 0);
+
+  // Clear any updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 0 updates
+  insertRoute("/", 1, 128, 75, 0);
+
+  BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
+{
+  insertRoute("/",  1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: to update cost for face 1 on / and /a
+  insertRoute("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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
+  clearFibUpdates();
+
+  // Should generate 0 updates
+  insertRoute("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit)
+{
+  insertRoute("/",    1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a",   2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 1 update: 1 to add face 5 to /a
+  insertRoute("/a", 5, 128, 50, 0);
+
+  const FibUpdater::FibUpdateList& updates = getFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/",    1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a",   2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: one for the inserted route and
+  // one to add route to /a/b
+  insertRoute("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/",    1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a",   2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 3 updates:
+  // - one for the inserted route for /a and
+  // - two to remove face1 from /a/b and /a/c
+  insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+  FibUpdater::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)
+{
+  insertRoute("/",    1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a",   2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates:
+  // - one for the inserted route for /a and
+  // - one to update /a/b with the new cost
+  insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE |
+                                     ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 3);
+
+  FibUpdater::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/daemon/rib/fib-updates-new-namespace.t.cpp b/tests/daemon/rib/fib-updates-new-namespace.t.cpp
new file mode 100644
index 0000000..90abd31
--- /dev/null
+++ b/tests/daemon/rib/fib-updates-new-namespace.t.cpp
@@ -0,0 +1,200 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015,  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(TestFibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(NewNamespace)
+
+BOOST_AUTO_TEST_CASE(NoFlags)
+{
+  // No flags, empty RIB, should generate 1 update for the inserted route
+  insertRoute("/a/b", 1, 0, 10, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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
+  eraseRoute("/a/b", 1, 0);
+  clearFibUpdates();
+
+  // Parent with child inherit flag
+  insertRoute("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 3 updates, 1 for the inserted route and 2 from inheritance
+  insertRoute("/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 route
+  insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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
+  eraseRoute("/a", 1, 0);
+  clearFibUpdates();
+
+  insertRoute("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 30, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 3 updates, 1 for the inserted route, 1 to add the route to the child,
+  // and 1 to remove the previously inherited route
+  insertRoute("/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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 2, 0, 10, 0);
+  insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 for the inserted route and 1 to add the route to "/a/b"
+  insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 2, 0, 10, 0);
+  insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates: 1 for the inserted route and
+  // 1 to remove the inherited route from "/a/b"
+  insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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/daemon/rib/fib-updates-update-face.t.cpp b/tests/daemon/rib/fib-updates-update-face.t.cpp
new file mode 100644
index 0000000..54cd2d4
--- /dev/null
+++ b/tests/daemon/rib/fib-updates-update-face.t.cpp
@@ -0,0 +1,266 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015,  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(TestFibUpdates, FibUpdatesFixture)
+
+BOOST_AUTO_TEST_SUITE(UpdateFace)
+
+BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  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
+  insertRoute("/", 1, 128, 75, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 0 updates
+  insertRoute("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 2 updates
+  insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Should generate 0 updates
+  insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(ChangeCost)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  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
+  insertRoute("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Turn on child inherit flag for the entry in /a
+  // Should generate 1 updates: 1 to add face to /a/b
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a/b", 2, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 25, 0);
+
+  // Clear updates generated from previous insertions
+  clearFibUpdates();
+
+  // Turn off child inherit flag for the entry in /a
+  // Should generate 1 update: 1 to add face1 to /a/b
+  insertRoute("/a", 1, 0, 100, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 1);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, 0);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 10, 0);
+
+  // Clear updates generated from previous insertions
+  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
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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)
+{
+  insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
+  insertRoute("/a/b", 3, 0, 10, 0);
+  insertRoute("/a/c", 1, 0, 10, 0);
+
+  // Clear updates generated from previous insertions
+  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
+  insertRoute("/a", 2, 0, 10, 0);
+
+  FibUpdater::FibUpdateList updates = getSortedFibUpdates();
+  BOOST_REQUIRE_EQUAL(updates.size(), 2);
+
+  FibUpdater::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/daemon/rib/readvertise/client-to-nlsr-readvertise-policy.t.cpp b/tests/daemon/rib/readvertise/client-to-nlsr-readvertise-policy.t.cpp
new file mode 100644
index 0000000..6925de1
--- /dev/null
+++ b/tests/daemon/rib/readvertise/client-to-nlsr-readvertise-policy.t.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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/readvertise/client-to-nlsr-readvertise-policy.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Readvertise)
+BOOST_FIXTURE_TEST_SUITE(TestClientToNlsrReadvertisePolicy, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(ReadvertiseClientRoute)
+{
+  auto entry = make_shared<RibEntry>();
+  entry->setName("/test/A");
+  Route route;
+  route.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
+  auto routeIt = entry->insertRoute(route).first;
+  RibRouteRef rrr{entry, routeIt};
+
+  ClientToNlsrReadvertisePolicy policy;
+  optional<ReadvertiseAction> action = policy.handleNewRoute(rrr);
+
+  BOOST_REQUIRE(action);
+  BOOST_CHECK_EQUAL(action->prefix, "/test/A");
+  BOOST_REQUIRE_EQUAL(action->signer, ndn::security::SigningInfo());
+}
+
+BOOST_AUTO_TEST_CASE(DontReadvertiseRoute)
+{
+  auto entry = make_shared<RibEntry>();
+  entry->setName("/test/A");
+  Route route;
+  route.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
+  auto routeIt = entry->insertRoute(route).first;
+  RibRouteRef rrr{entry, routeIt};
+
+  ClientToNlsrReadvertisePolicy policy;
+  optional<ReadvertiseAction> action = policy.handleNewRoute(rrr);
+
+  BOOST_CHECK(!action);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestClientToNlsrReadvertisePolicy
+BOOST_AUTO_TEST_SUITE_END() // Readvertise
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp b/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
new file mode 100644
index 0000000..1b357cb
--- /dev/null
+++ b/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
@@ -0,0 +1,114 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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/readvertise/host-to-gateway-readvertise-policy.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/security/signing-helpers.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+class HostToGatewayReadvertisePolicyFixture : public IdentityManagementFixture
+{
+public:
+  RibRouteRef
+  makeNewRoute(const Name& prefix) {
+    auto entry = make_shared<RibEntry>();
+    entry->setName(prefix);
+
+    Route route;
+    auto routeIt = entry->insertRoute(route).first;
+    return RibRouteRef{entry, routeIt};
+  }
+
+  shared_ptr<HostToGatewayReadvertisePolicy>
+  makePolicy(const ConfigSection& section = ConfigSection())
+  {
+    return make_shared<HostToGatewayReadvertisePolicy>(m_keyChain, section);
+  }
+};
+
+BOOST_AUTO_TEST_SUITE(Readvertise)
+BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy,
+                         HostToGatewayReadvertisePolicyFixture)
+
+BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
+{
+  BOOST_REQUIRE(addIdentity("/A"));
+  BOOST_REQUIRE(addIdentity("/A/B"));
+  BOOST_REQUIRE(addIdentity("/C/nrd"));
+
+  auto test = [this] (Name routeName, optional<ReadvertiseAction> expectedAction) {
+    auto policy = makePolicy();
+    auto action = policy->handleNewRoute(makeNewRoute(routeName));
+
+    if (expectedAction) {
+      BOOST_REQUIRE(action);
+      BOOST_CHECK_EQUAL(action->prefix, expectedAction->prefix);
+      BOOST_REQUIRE_EQUAL(action->signer, expectedAction->signer);
+    }
+    else {
+      BOOST_REQUIRE(!action);
+    }
+  };
+
+  test("/D/app", nullopt);
+  test("/A/B/app", ReadvertiseAction{"/A", ndn::security::signingByIdentity("/A")});
+  test("/C/nrd", ReadvertiseAction{"/C", ndn::security::signingByIdentity("/C/nrd")});
+}
+
+BOOST_AUTO_TEST_CASE(DontReadvertise)
+{
+  auto policy = makePolicy();
+  BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhost/test")));
+  BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhop/nfd")));
+}
+
+BOOST_AUTO_TEST_CASE(LoadRefreshInterval)
+{
+  auto policy = makePolicy();
+  BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // default setting is 25
+
+  ConfigSection section;
+  section.put("refresh_interval_wrong", 10);
+  policy = makePolicy(section);
+  BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // wrong formate
+
+  section.put("refresh_interval", 10);
+  policy = makePolicy(section);
+  BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(10));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestHostToGatewayReadvertisePolicy
+BOOST_AUTO_TEST_SUITE_END() // Readvertise
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
new file mode 100644
index 0000000..4967788
--- /dev/null
+++ b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
@@ -0,0 +1,257 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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/readvertise/nfd-rib-readvertise-destination.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+#include "tests/test-common.hpp"
+
+#include <ndn-cxx/security/signing-info.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+class NfdRibReadvertiseDestinationFixture : public IdentityManagementTimeFixture
+{
+public:
+  NfdRibReadvertiseDestinationFixture()
+    : nSuccessCallbacks(0)
+    , nFailureCallbacks(0)
+    , face(g_io, m_keyChain, {true, false})
+    , scheduler(g_io)
+    , controller(face, m_keyChain)
+    , dest(controller, rib, ndn::nfd::CommandOptions().setPrefix("/localhost/nlsr"))
+    , successCallback([this] { nSuccessCallbacks++; })
+    , failureCallback([this] (const std::string& str) { nFailureCallbacks++; })
+  {
+  }
+
+public:
+  uint32_t nSuccessCallbacks;
+  uint32_t nFailureCallbacks;
+
+protected:
+  ndn::util::DummyClientFace face;
+  ndn::util::Scheduler scheduler;
+  ndn::nfd::Controller controller;
+  Rib rib;
+  NfdRibReadvertiseDestination dest;
+  std::function<void()> successCallback;
+  std::function<void(const std::string&)> failureCallback;
+};
+
+BOOST_AUTO_TEST_SUITE(Readvertise)
+BOOST_FIXTURE_TEST_SUITE(TestNfdRibReadvertiseDestination, NfdRibReadvertiseDestinationFixture)
+
+class AdvertiseSuccessScenario
+{
+public:
+  ndn::nfd::ControlResponse
+  makeResponse(const ControlParameters& sentCp)
+  {
+    ControlParameters response;
+
+    response.setFaceId(1)
+      .setName(sentCp.getName())
+      .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
+      .setCost(0)
+      .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+    ndn::nfd::ControlResponse responsePayload;
+    responsePayload.setCode(200)
+      .setText("Successfully registered.")
+      .setBody(response.wireEncode());
+    return responsePayload;
+  }
+
+  void
+  checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture)
+  {
+    BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 1);
+    BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 0);
+  }
+};
+
+class AdvertiseFailureScenario
+{
+public:
+  ndn::nfd::ControlResponse
+  makeResponse(ControlParameters sentCp)
+  {
+    ndn::nfd::ControlResponse responsePayload(403, "Not Authenticated");
+    return responsePayload;
+  }
+
+  void
+  checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture)
+  {
+    BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 1);
+    BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 0);
+  }
+};
+
+using AdvertiseScenarios = boost::mpl::vector<AdvertiseSuccessScenario, AdvertiseFailureScenario>;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(Advertise, Scenario, AdvertiseScenarios)
+{
+  Scenario scenario;
+  Name prefix("/ndn/memphis/test");
+  ReadvertisedRoute rr(prefix);
+  const Name RIB_REGISTER_COMMAND_PREFIX("/localhost/nlsr/rib/register");
+
+  dest.advertise(rr, successCallback, failureCallback);
+  advanceClocks(time::milliseconds(100));
+
+  // Retrieve the sent Interest to build the response
+  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+  const Interest& sentInterest = face.sentInterests[0];
+  BOOST_CHECK(RIB_REGISTER_COMMAND_PREFIX.isPrefixOf(sentInterest.getName()));
+
+  // Parse the sent command Interest to check correctness.
+  ControlParameters sentCp;
+  BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_REGISTER_COMMAND_PREFIX.size()).blockFromValue()));
+  BOOST_CHECK_EQUAL(sentCp.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(sentCp.getName(), prefix);
+
+  ndn::nfd::ControlResponse responsePayload = scenario.makeResponse(sentCp);
+  auto responseData = makeData(sentInterest.getName());
+  responseData->setContent(responsePayload.wireEncode());
+  face.receive(*responseData);
+  this->advanceClocks(time::milliseconds(10));
+
+  scenario.checkCommandOutcome(this);
+}
+
+class WithdrawSuccessScenario
+{
+public:
+  ndn::nfd::ControlResponse
+  makeResponse(const ControlParameters& sentCp)
+  {
+    ControlParameters response;
+
+    response.setFaceId(1)
+      .setName(sentCp.getName())
+      .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT);
+
+    ndn::nfd::ControlResponse responsePayload;
+    responsePayload.setCode(200)
+      .setText("Successfully removed")
+      .setBody(response.wireEncode());
+
+    return responsePayload;
+  }
+
+  void
+  checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture)
+  {
+    BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 1);
+    BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 0);
+  }
+};
+
+class WithdrawFailureScenario
+{
+public:
+  ndn::nfd::ControlResponse
+  makeResponse(ControlParameters sentCp)
+  {
+    ndn::nfd::ControlResponse responsePayload(403, "Not authenticated");
+    return responsePayload;
+  }
+
+  void
+  checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture)
+  {
+    BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 1);
+    BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 0);
+  }
+};
+
+using WithdrawScenarios = boost::mpl::vector<WithdrawSuccessScenario, WithdrawFailureScenario>;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(Withdraw, Scenario, WithdrawScenarios)
+{
+  Scenario scenario;
+  Name prefix("/ndn/memphis/test");
+  ReadvertisedRoute rr(prefix);
+  const Name RIB_UNREGISTER_COMMAND_PREFIX("/localhost/nlsr/rib/unregister");
+
+  dest.withdraw(rr, successCallback, failureCallback);
+  this->advanceClocks(time::milliseconds(10));
+
+  // Retrieve the sent Interest to build the response
+  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+  const Interest& sentInterest = face.sentInterests[0];
+  BOOST_CHECK(RIB_UNREGISTER_COMMAND_PREFIX.isPrefixOf(sentInterest.getName()));
+
+  ControlParameters sentCp;
+  BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_UNREGISTER_COMMAND_PREFIX.size()).blockFromValue()));
+  BOOST_CHECK_EQUAL(sentCp.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(sentCp.getName(), prefix);
+
+  ndn::nfd::ControlResponse responsePayload = scenario.makeResponse(sentCp);
+  auto responseData = makeData(sentInterest.getName());
+  responseData->setContent(responsePayload.wireEncode());
+
+  face.receive(*responseData);
+  this->advanceClocks(time::milliseconds(1));
+
+  scenario.checkCommandOutcome(this);
+}
+
+BOOST_AUTO_TEST_CASE(DestinationAvailability)
+{
+  std::vector<bool> availabilityChangeHistory;
+  Name commandPrefix("/localhost/nlsr");
+  Route route;
+
+  dest.afterAvailabilityChange.connect(
+    std::bind(&std::vector<bool>::push_back, &availabilityChangeHistory, _1));
+  BOOST_CHECK_EQUAL(dest.isAvailable(), false);
+
+  rib.insert(commandPrefix, route);
+  this->advanceClocks(time::milliseconds(100));
+  BOOST_CHECK_EQUAL(dest.isAvailable(), true);
+  BOOST_REQUIRE_EQUAL(availabilityChangeHistory.size(), 1);
+  BOOST_CHECK_EQUAL(availabilityChangeHistory.back(), true);
+
+  rib.erase(commandPrefix, route);
+  this->advanceClocks(time::milliseconds(100));
+  BOOST_CHECK_EQUAL(dest.isAvailable(), false);
+  BOOST_REQUIRE_EQUAL(availabilityChangeHistory.size(), 2);
+  BOOST_CHECK_EQUAL(availabilityChangeHistory.back(), false);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestNfdRibReadvertiseDestination
+BOOST_AUTO_TEST_SUITE_END() // Readvertise
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/readvertise/readvertise.t.cpp b/tests/daemon/rib/readvertise/readvertise.t.cpp
new file mode 100644
index 0000000..1ff0f85
--- /dev/null
+++ b/tests/daemon/rib/readvertise/readvertise.t.cpp
@@ -0,0 +1,306 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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/readvertise/readvertise.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/range/algorithm/copy.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+class DummyReadvertisePolicy : public ReadvertisePolicy
+{
+public:
+  optional<ReadvertiseAction>
+  handleNewRoute(const RibRouteRef& route) const override
+  {
+    return this->decision;
+  }
+
+  time::milliseconds
+  getRefreshInterval() const override
+  {
+    return time::seconds(60);
+  }
+
+public:
+  optional<ReadvertiseAction> decision;
+};
+
+class DummyReadvertiseDestination : public ReadvertiseDestination
+{
+public:
+  DummyReadvertiseDestination()
+  {
+    this->setAvailability(true);
+  }
+
+  void
+  advertise(const ReadvertisedRoute& rr,
+            std::function<void()> successCb,
+            std::function<void(const std::string&)> failureCb) override
+  {
+    advertiseHistory.push_back({time::steady_clock::now(), rr.prefix});
+    if (shouldSucceed) {
+      successCb();
+    }
+    else {
+      failureCb("FAKE-FAILURE");
+    }
+  }
+
+  void
+  withdraw(const ReadvertisedRoute& rr,
+           std::function<void()> successCb,
+           std::function<void(const std::string&)> failureCb) override
+  {
+    withdrawHistory.push_back({time::steady_clock::now(), rr.prefix});
+    if (shouldSucceed) {
+      successCb();
+    }
+    else {
+      failureCb("FAKE-FAILURE");
+    }
+  }
+
+  void
+  setAvailability(bool isAvailable)
+  {
+    this->ReadvertiseDestination::setAvailability(isAvailable);
+  }
+
+public:
+  struct HistoryEntry
+  {
+    time::steady_clock::TimePoint timestamp;
+    Name prefix;
+  };
+
+  bool shouldSucceed = true;
+  std::vector<HistoryEntry> advertiseHistory;
+  std::vector<HistoryEntry> withdrawHistory;
+};
+
+class ReadvertiseFixture : public IdentityManagementTimeFixture
+{
+public:
+  ReadvertiseFixture()
+    : m_face(g_io, m_keyChain, {false, false})
+    , m_scheduler(g_io)
+  {
+    auto policyUnique = make_unique<DummyReadvertisePolicy>();
+    policy = policyUnique.get();
+    auto destinationUnique = make_unique<DummyReadvertiseDestination>();
+    destination = destinationUnique.get();
+    readvertise = make_unique<Readvertise>(m_rib, m_scheduler,
+                                           std::move(policyUnique), std::move(destinationUnique));
+  }
+
+  void
+  insertRoute(const Name& prefix, uint64_t faceId, ndn::nfd::RouteOrigin origin)
+  {
+    Route route;
+    route.faceId = faceId;
+    route.origin = origin;
+    m_rib.insert(prefix, route);
+    this->advanceClocks(time::milliseconds(6));
+  }
+
+  void
+  eraseRoute(const Name& prefix, uint64_t faceId, ndn::nfd::RouteOrigin origin)
+  {
+    Route route;
+    route.faceId = faceId;
+    route.origin = origin;
+    m_rib.erase(prefix, route);
+    this->advanceClocks(time::milliseconds(6));
+  }
+
+  void
+  setDestinationAvailability(bool isAvailable)
+  {
+    destination->setAvailability(isAvailable);
+    this->advanceClocks(time::milliseconds(6));
+  }
+
+protected:
+  DummyReadvertisePolicy* policy;
+  DummyReadvertiseDestination* destination;
+  unique_ptr<Readvertise> readvertise;
+
+private:
+  ndn::util::DummyClientFace m_face;
+  ndn::util::Scheduler m_scheduler;
+  Rib m_rib;
+};
+
+BOOST_AUTO_TEST_SUITE(Readvertise)
+BOOST_FIXTURE_TEST_SUITE(TestReadvertise, ReadvertiseFixture)
+
+BOOST_AUTO_TEST_CASE(AddRemoveRoute)
+{
+  policy->decision = ReadvertiseAction{"/A", ndn::security::SigningInfo()};
+
+  // advertising /A
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 1);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.at(0).prefix, "/A");
+
+  // /A is already advertised
+  this->insertRoute("/A/2", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 1);
+
+  // refresh every 60 seconds
+  destination->advertiseHistory.clear();
+  this->advanceClocks(time::seconds(61), 5);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 5);
+
+  // /A is still needed by /A/2 route
+  this->eraseRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0);
+
+  // withdrawing /A
+  this->eraseRoute("/A/2", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 1);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.at(0).prefix, "/A");
+}
+
+BOOST_AUTO_TEST_CASE(NoAdvertise)
+{
+  policy->decision = nullopt;
+
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->insertRoute("/A/2", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->eraseRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->eraseRoute("/A/2", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 0);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(DestinationAvailability)
+{
+  this->setDestinationAvailability(false);
+
+  policy->decision = ReadvertiseAction{"/A", ndn::security::SigningInfo()};
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  policy->decision = ReadvertiseAction{"/B", ndn::security::SigningInfo()};
+  this->insertRoute("/B/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 0);
+
+  this->setDestinationAvailability(true);
+  std::set<Name> advertisedPrefixes;
+  boost::copy(destination->advertiseHistory | boost::adaptors::transformed(
+                [] (const DummyReadvertiseDestination::HistoryEntry& he) { return he.prefix; }),
+              std::inserter(advertisedPrefixes, advertisedPrefixes.end()));
+  std::set<Name> expectedPrefixes{"/A", "/B"};
+  BOOST_CHECK_EQUAL_COLLECTIONS(advertisedPrefixes.begin(), advertisedPrefixes.end(),
+                                expectedPrefixes.begin(), expectedPrefixes.end());
+  destination->advertiseHistory.clear();
+
+  this->setDestinationAvailability(false);
+  this->eraseRoute("/B/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0);
+
+  this->setDestinationAvailability(true);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 1);
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.at(0).prefix, "/A");
+}
+
+BOOST_AUTO_TEST_CASE(AdvertiseRetryInterval)
+{
+  destination->shouldSucceed = false;
+
+  policy->decision = ReadvertiseAction{"/A", ndn::security::SigningInfo()};
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+
+  this->advanceClocks(time::seconds(10), time::seconds(3600));
+  BOOST_REQUIRE_GT(destination->advertiseHistory.size(), 2);
+
+  // destination->advertise keeps failing, so interval should increase
+  using FloatInterval = time::duration<float, time::steady_clock::Duration::period>;
+  FloatInterval initialInterval = destination->advertiseHistory[1].timestamp -
+                                  destination->advertiseHistory[0].timestamp;
+  FloatInterval lastInterval = initialInterval;
+  for (size_t i = 2; i < destination->advertiseHistory.size(); ++i) {
+    FloatInterval interval = destination->advertiseHistory[i].timestamp -
+                             destination->advertiseHistory[i - 1].timestamp;
+    BOOST_CHECK_CLOSE(interval.count(), (lastInterval * 2.0).count(), 10.0);
+    lastInterval = interval;
+  }
+
+  destination->shouldSucceed = true;
+  this->advanceClocks(time::seconds(3600));
+  destination->advertiseHistory.clear();
+
+  // destination->advertise has succeeded, retry interval should reset to initial
+  destination->shouldSucceed = false;
+  this->advanceClocks(time::seconds(10), time::seconds(300));
+  BOOST_REQUIRE_GE(destination->advertiseHistory.size(), 2);
+  FloatInterval restartInterval = destination->advertiseHistory[1].timestamp -
+                                  destination->advertiseHistory[0].timestamp;
+  BOOST_CHECK_CLOSE(restartInterval.count(), initialInterval.count(), 10.0);
+}
+
+BOOST_AUTO_TEST_CASE(ChangeDuringRetry)
+{
+  destination->shouldSucceed = false;
+  policy->decision = ReadvertiseAction{"/A", ndn::security::SigningInfo()};
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->advanceClocks(time::seconds(10), time::seconds(300));
+  BOOST_CHECK_GT(destination->advertiseHistory.size(), 0);
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0);
+
+  // destination->advertise has been failing, but we want to withdraw
+  destination->advertiseHistory.clear();
+  destination->withdrawHistory.clear();
+  this->eraseRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->advanceClocks(time::seconds(10), time::seconds(300));
+  BOOST_CHECK_EQUAL(destination->advertiseHistory.size(), 0); // don't try to advertise
+  BOOST_CHECK_GT(destination->withdrawHistory.size(), 0); // try to withdraw
+
+  // destination->withdraw has been failing, but we want to advertise
+  destination->advertiseHistory.clear();
+  destination->withdrawHistory.clear();
+  this->insertRoute("/A/1", 1, ndn::nfd::ROUTE_ORIGIN_CLIENT);
+  this->advanceClocks(time::seconds(10), time::seconds(300));
+  BOOST_CHECK_GT(destination->advertiseHistory.size(), 0); // try to advertise
+  BOOST_CHECK_EQUAL(destination->withdrawHistory.size(), 0); // don't try to withdraw
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestReadvertise
+BOOST_AUTO_TEST_SUITE_END() // Readvertise
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/rib-entry.t.cpp b/tests/daemon/rib/rib-entry.t.cpp
new file mode 100644
index 0000000..a5c9f3c
--- /dev/null
+++ b/tests/daemon/rib/rib-entry.t.cpp
@@ -0,0 +1,175 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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-entry.hpp"
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_FIXTURE_TEST_SUITE(TestRibEntry, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  rib::RibEntry entry;
+  rib::RibEntry::iterator entryIt;
+  bool didInsert = false;
+
+  rib::Route route1;
+  route1.faceId = 1;
+  route1.origin = ndn::nfd::ROUTE_ORIGIN_APP;
+
+  std::tie(entryIt, didInsert) = entry.insertRoute(route1);
+  BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+  BOOST_CHECK(entryIt == entry.findRoute(route1));
+  BOOST_CHECK(didInsert);
+
+  Route route2;
+  route2.faceId = 1;
+  route2.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
+
+  std::tie(entryIt, didInsert) = entry.insertRoute(route2);
+  BOOST_CHECK_EQUAL(entry.getRoutes().size(), 2);
+  BOOST_CHECK(entryIt == entry.findRoute(route2));
+  BOOST_CHECK(didInsert);
+
+  entry.eraseRoute(route1);
+  BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+  BOOST_CHECK(entry.findRoute(route1) == entry.end());
+
+  BOOST_CHECK(entry.findRoute(route1) == entry.getRoutes().end());
+  BOOST_CHECK(entry.findRoute(route2) != entry.getRoutes().end());
+
+  std::tie(entryIt, didInsert) = entry.insertRoute(route2);
+  BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+  BOOST_CHECK(!didInsert);
+
+  entry.eraseRoute(route1);
+  BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+  BOOST_CHECK(entry.findRoute(route2) != entry.getRoutes().end());
+}
+
+BOOST_FIXTURE_TEST_SUITE(GetAnnouncement, UnitTestTimeFixture)
+
+static Route
+makeSimpleRoute(uint64_t faceId)
+{
+  Route route;
+  route.faceId = faceId;
+  return route;
+}
+
+static Route
+makeSimpleRoute(uint64_t faceId, time::steady_clock::Duration expiration)
+{
+  Route route = makeSimpleRoute(faceId);
+  route.expires = time::steady_clock::now() + expiration;
+  return route;
+}
+
+BOOST_AUTO_TEST_CASE(Empty)
+{
+  RibEntry entry;
+  // entry has no Route
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 30_s);
+  BOOST_CHECK_GE(pa.getExpiration(), 15_s);
+  BOOST_CHECK_LE(pa.getExpiration(), 30_s);
+  // A RibEntry without Route does not have a defined expiration time,
+  // so this test only checks that there's no exception and the expiration period is clamped.
+}
+
+BOOST_AUTO_TEST_CASE(ReuseAnnouncement1)
+{
+  RibEntry entry;
+  entry.insertRoute(Route(makePrefixAnn("/A", 212_s), 5858));
+  entry.insertRoute(Route(makePrefixAnn("/A", 555_s), 2454));
+  entry.insertRoute(makeSimpleRoute(8282, 799_s));
+  entry.insertRoute(makeSimpleRoute(1141));
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 30_s);
+  BOOST_CHECK_EQUAL(pa.getExpiration(), 555_s); // not modified and not clamped
+}
+
+BOOST_AUTO_TEST_CASE(ReuseAnnouncement2)
+{
+  RibEntry entry;
+  entry.insertRoute(Route(makePrefixAnn("/A", 212_s), 7557)); // expires at +212s
+
+  advanceClocks(100_s);
+  entry.insertRoute(Route(makePrefixAnn("/A", 136_s), 1010)); // expires at +236s
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 30_s);
+  BOOST_CHECK_EQUAL(pa.getExpiration(), 136_s);
+  // Although face 7557's announcement has a longer expiration period,
+  // the route for face 1010 expires last and thus its announcement is chosen.
+}
+
+BOOST_AUTO_TEST_CASE(MakeAnnouncement)
+{
+  RibEntry entry;
+  entry.insertRoute(makeSimpleRoute(6398, 765_s));
+  entry.insertRoute(makeSimpleRoute(2954, 411_s));
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 999_s);
+  BOOST_CHECK_EQUAL(pa.getExpiration(), 764_s);
+}
+
+BOOST_AUTO_TEST_CASE(MakeAnnouncementInfinite)
+{
+  RibEntry entry;
+  entry.insertRoute(makeSimpleRoute(4877, 240_s));
+  entry.insertRoute(makeSimpleRoute(5053));
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 877_s);
+  BOOST_CHECK_EQUAL(pa.getExpiration(), 877_s); // clamped at maxExpiration
+}
+
+BOOST_AUTO_TEST_CASE(MakeAnnouncementShortExpiration)
+{
+  RibEntry entry;
+  entry.insertRoute(makeSimpleRoute(4877, 8_s));
+  entry.insertRoute(makeSimpleRoute(5053, 9_s));
+
+  advanceClocks(1_s);
+  auto pa = entry.getPrefixAnnouncement(15_s, 666_s);
+  BOOST_CHECK_EQUAL(pa.getExpiration(), 15_s); // clamped at minExpiration
+}
+
+BOOST_AUTO_TEST_SUITE_END() // GetAnnouncement
+
+BOOST_AUTO_TEST_SUITE_END() // TestRibEntry
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/rib-manager.t.cpp b/tests/daemon/rib/rib-manager.t.cpp
new file mode 100644
index 0000000..be59ca5
--- /dev/null
+++ b/tests/daemon/rib/rib-manager.t.cpp
@@ -0,0 +1,554 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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-manager.hpp"
+#include "core/fib-max-depth.hpp"
+
+#include "tests/manager-common-fixture.hpp"
+
+#include <ndn-cxx/lp/tags.hpp>
+#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
+#include <ndn-cxx/mgmt/nfd/face-status.hpp>
+#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+struct ConfigurationStatus
+{
+  bool isLocalhostConfigured;
+  bool isLocalhopConfigured;
+};
+
+static ConfigSection
+getValidatorConfigSection()
+{
+  ConfigSection section;
+  section.put("trust-anchor.type", "any");
+  return section;
+}
+
+class RibManagerFixture : public ManagerCommonFixture
+{
+public:
+  explicit
+  RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib)
+    : m_commands(m_face.sentInterests)
+    , m_status(status)
+    , m_scheduler(g_io)
+    , m_nfdController(m_face, m_keyChain)
+    , m_fibUpdater(m_rib, m_nfdController)
+    , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler)
+  {
+    m_rib.mockFibResponse = [] (const RibUpdateBatch& batch) {
+      BOOST_CHECK(batch.begin() != batch.end());
+      return true;
+    };
+    m_rib.wantMockFibResponseOnce = false;
+
+    if (m_status.isLocalhostConfigured) {
+      m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test");
+    }
+    if (m_status.isLocalhopConfigured) {
+      m_manager.enableLocalhop(getValidatorConfigSection(), "test");
+    }
+    else {
+      m_manager.disableLocalhop();
+    }
+
+    registerWithNfd();
+
+    if (shouldClearRib) {
+      clearRib();
+    }
+  }
+
+private:
+  void
+  registerWithNfd()
+  {
+    m_manager.registerWithNfd();
+    advanceClocks(time::milliseconds(1));
+
+    auto replyFibAddCommand = [this] (const Interest& interest) {
+      nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
+      BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib");
+      params.setFaceId(1).setCost(0);
+      nfd::ControlResponse resp;
+
+      resp.setCode(200).setBody(params.wireEncode());
+      shared_ptr<Data> data = make_shared<Data>(interest.getName());
+      data->setContent(resp.wireEncode());
+
+      m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256));
+
+      m_face.getIoService().post([this, data] { m_face.receive(*data); });
+    };
+
+    Name commandPrefix("/localhost/nfd/fib/add-nexthop");
+    for (const auto& command : m_commands) {
+      if (commandPrefix.isPrefixOf(command.getName())) {
+        replyFibAddCommand(command);
+        advanceClocks(time::milliseconds(1));
+      }
+    }
+
+    // clear commands and responses
+    m_responses.clear();
+    m_commands.clear();
+  }
+
+  void
+  clearRib()
+  {
+    while (!m_rib.empty()) {
+      m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin());
+    }
+  }
+
+public:
+  static ControlParameters
+  makeRegisterParameters(const Name& name, uint64_t faceId = 0,
+                         time::milliseconds expiry = time::milliseconds::max())
+  {
+    return ControlParameters()
+      .setName(name)
+      .setFaceId(faceId)
+      .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR)
+      .setCost(10)
+      .setFlags(0)
+      .setExpirationPeriod(expiry);
+  }
+
+  static ControlParameters
+  makeUnregisterParameters(const Name& name, uint64_t faceId = 0)
+  {
+    return ControlParameters()
+      .setName(name)
+      .setFaceId(faceId)
+      .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
+  }
+
+public:
+  enum class CheckCommandResult {
+    OK,
+    OUT_OF_BOUNDARY,
+    WRONG_FORMAT,
+    WRONG_VERB,
+    WRONG_PARAMS_FORMAT,
+    WRONG_PARAMS_NAME,
+    WRONG_PARAMS_FACE
+  };
+
+  CheckCommandResult
+  checkCommand(size_t idx, const char* verbStr, const ControlParameters& expectedParams) const
+  {
+    if (idx > m_commands.size()) {
+      return CheckCommandResult::OUT_OF_BOUNDARY;
+    }
+    const auto& name = m_commands[idx].getName();
+
+    if (!FIB_COMMAND_PREFIX.isPrefixOf(name) || FIB_COMMAND_PREFIX.size() >= name.size()) {
+      return CheckCommandResult::WRONG_FORMAT;
+    }
+    const auto& verb = name[FIB_COMMAND_PREFIX.size()];
+
+    Name::Component expectedVerb(verbStr);
+    if (verb != expectedVerb) {
+      return CheckCommandResult::WRONG_VERB;
+    }
+
+    ControlParameters parameters;
+    try {
+      Block rawParameters = name[FIB_COMMAND_PREFIX.size() + 1].blockFromValue();
+      parameters.wireDecode(rawParameters);
+    }
+    catch (...) {
+      return CheckCommandResult::WRONG_PARAMS_FORMAT;
+    }
+
+    if (parameters.getName() != expectedParams.getName()) {
+      return CheckCommandResult::WRONG_PARAMS_NAME;
+    }
+
+    if (parameters.getFaceId() != expectedParams.getFaceId()) {
+      return CheckCommandResult::WRONG_PARAMS_FACE;
+    }
+
+    return CheckCommandResult::OK;
+  }
+
+protected:
+  static const Name FIB_COMMAND_PREFIX;
+  std::vector<Interest>& m_commands;
+  ConfigurationStatus m_status;
+
+  ndn::util::Scheduler m_scheduler;
+  ndn::nfd::Controller m_nfdController;
+  Rib m_rib;
+  FibUpdater m_fibUpdater;
+  RibManager m_manager;
+};
+
+const Name RibManagerFixture::FIB_COMMAND_PREFIX("/localhost/nfd/fib");
+
+std::ostream&
+operator<<(std::ostream& os, RibManagerFixture::CheckCommandResult result)
+{
+  switch (result) {
+  case RibManagerFixture::CheckCommandResult::OK:
+    return os << "OK";
+  case RibManagerFixture::CheckCommandResult::OUT_OF_BOUNDARY:
+    return os << "OUT_OF_BOUNDARY";
+  case RibManagerFixture::CheckCommandResult::WRONG_FORMAT:
+    return os << "WRONG_FORMAT";
+  case RibManagerFixture::CheckCommandResult::WRONG_VERB:
+    return os << "WRONG_VERB";
+  case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_FORMAT:
+    return os << "WRONG_PARAMS_FORMAT";
+  case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_NAME:
+    return os << "WRONG_PARAMS_NAME";
+  case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_FACE:
+    return os << "WRONG_PARAMS_FACE";
+  };
+
+  return os << static_cast<int>(result);
+}
+
+BOOST_AUTO_TEST_SUITE(TestRibManager)
+
+class AddTopPrefixFixture : public RibManagerFixture
+{
+public:
+  AddTopPrefixFixture()
+    : RibManagerFixture({true, true}, false)
+  {
+  }
+};
+
+BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture)
+{
+  BOOST_CHECK_EQUAL(m_rib.size(), 2);
+
+  std::vector<Name> ribEntryNames;
+  for (auto&& entry : m_rib) {
+    ribEntryNames.push_back(entry.first);
+  }
+  BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd");
+  BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd");
+}
+
+class UnauthorizedRibManagerFixture : public RibManagerFixture
+{
+public:
+  UnauthorizedRibManagerFixture()
+    : RibManagerFixture({false, false}, true)
+  {
+  }
+};
+
+class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture
+{
+public:
+  LocalhostAuthorizedRibManagerFixture()
+    : RibManagerFixture({true, false}, true)
+  {
+  }
+};
+
+class LocalhopAuthorizedRibManagerFixture : public RibManagerFixture
+{
+public:
+  LocalhopAuthorizedRibManagerFixture()
+    : RibManagerFixture({false, true}, true)
+  {
+  }
+};
+
+class AuthorizedRibManagerFixture : public RibManagerFixture
+{
+public:
+  AuthorizedRibManagerFixture()
+    : RibManagerFixture({true, true}, true)
+  {
+  }
+};
+
+using AllFixtures = boost::mpl::vector<
+  UnauthorizedRibManagerFixture,
+  LocalhostAuthorizedRibManagerFixture,
+  LocalhopAuthorizedRibManagerFixture,
+  AuthorizedRibManagerFixture
+>;
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T)
+{
+  auto parameters  = this->makeRegisterParameters("/test-authorization", 9527);
+  auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters);
+  auto commandHop  = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters);
+  auto successResp = this->makeResponse(200, "Success", parameters);
+  auto failureResp = ControlResponse(403, "authorization rejected");
+
+  BOOST_CHECK_EQUAL(this->m_responses.size(), 0);
+  this->receiveInterest(commandHost);
+  this->receiveInterest(commandHop);
+
+  auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1;
+  auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp;
+  auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp;
+
+  BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses);
+  BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse),
+                    ManagerCommonFixture::CheckResponseResult::OK);
+  if (nExpectedResponses == 2) {
+    BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse),
+                      ManagerCommonFixture::CheckResponseResult::OK);
+  }
+}
+
+BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  auto paramsRegister    = makeRegisterParameters("/test-register-unregister", 9527);
+  auto paramsUnregister  = makeUnregisterParameters("/test-register-unregister", 9527);
+
+  auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister);
+  commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234));
+  auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister);
+  commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234));
+
+  receiveInterest(commandRegister);
+  receiveInterest(commandUnregister);
+
+  BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
+  BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)),
+                    CheckResponseResult::OK);
+  BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)),
+                    CheckResponseResult::OK);
+
+  BOOST_REQUIRE_EQUAL(m_commands.size(), 2);
+  BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
+  BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK);
+}
+
+BOOST_AUTO_TEST_CASE(SelfOperation)
+{
+  auto paramsRegister = makeRegisterParameters("/test-self-register-unregister");
+  auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister");
+  BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0);
+  BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0);
+
+  const uint64_t inFaceId = 9527;
+  auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister);
+  commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId));
+  auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister);
+  commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId));
+
+  receiveInterest(commandRegister);
+  receiveInterest(commandUnregister);
+
+  paramsRegister.setFaceId(inFaceId);
+  paramsUnregister.setFaceId(inFaceId);
+
+  BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
+  BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)),
+                    CheckResponseResult::OK);
+  BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)),
+                    CheckResponseResult::OK);
+
+  BOOST_REQUIRE_EQUAL(m_commands.size(), 2);
+  BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
+  BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK);
+}
+
+BOOST_AUTO_TEST_CASE(Expiration)
+{
+  auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, time::milliseconds(50));
+  auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527);
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
+
+  advanceClocks(time::milliseconds(55));
+  BOOST_REQUIRE_EQUAL(m_commands.size(), 2); // the registered route has expired
+  BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
+  BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK);
+
+  m_commands.clear();
+  paramsRegister.setExpirationPeriod(time::milliseconds(100));
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
+
+  advanceClocks(time::milliseconds(55));
+  BOOST_REQUIRE_EQUAL(m_commands.size(), 1); // the registered route is still active
+  BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
+}
+
+BOOST_AUTO_TEST_CASE(NameTooLong)
+{
+  Name prefix;
+  while (prefix.size() <= FIB_MAX_DEPTH) {
+    prefix.append("A");
+  }
+  auto params = makeRegisterParameters(prefix, 2899);
+  auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params);
+  receiveInterest(command);
+
+  BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
+  BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), ControlResponse(414,
+                      "Route prefix cannot exceed " + ndn::to_string(FIB_MAX_DEPTH) +
+                      " components")),
+                    CheckResponseResult::OK);
+
+  BOOST_CHECK_EQUAL(m_commands.size(), 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister
+
+BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture)
+{
+  uint64_t faceId = 0;
+  auto generateRoute = [&faceId] () -> Route {
+    Route route;
+    route.faceId = ++faceId;
+    route.cost = route.faceId * 10;
+    route.expires = nullopt;
+    return route;
+  };
+
+  const size_t nEntries = 108;
+  std::set<Name> actualPrefixes;
+  for (size_t i = 0; i < nEntries; ++i) {
+    Name prefix = Name("/test-dataset").appendNumber(i);
+    actualPrefixes.insert(prefix);
+    m_rib.insert(prefix, generateRoute());
+    if (i & 0x1) {
+      m_rib.insert(prefix, generateRoute());
+      m_rib.insert(prefix, generateRoute());
+    }
+  }
+
+  receiveInterest(Interest("/localhost/nfd/rib/list"));
+
+  Block content = concatenateResponses();
+  content.parse();
+  BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
+
+  std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords;
+  for (size_t idx = 0; idx < nEntries; ++idx) {
+    ndn::nfd::RibEntry decodedEntry(content.elements()[idx]);
+    receivedRecords.push_back(decodedEntry);
+    actualPrefixes.erase(decodedEntry.getName());
+
+    auto matchedEntryIt = m_rib.find(decodedEntry.getName());
+    BOOST_REQUIRE(matchedEntryIt != m_rib.end());
+
+    auto matchedEntry = matchedEntryIt->second;
+    BOOST_REQUIRE(matchedEntry != nullptr);
+
+    expectedRecords.emplace_back();
+    expectedRecords.back().setName(matchedEntry->getName());
+    for (const auto& route : matchedEntry->getRoutes()) {
+      expectedRecords.back().addRoute(ndn::nfd::Route()
+                                      .setFaceId(route.faceId)
+                                      .setOrigin(route.origin)
+                                      .setCost(route.cost)
+                                      .setFlags(route.flags));
+    }
+  }
+
+  BOOST_CHECK_EQUAL(actualPrefixes.size(), 0);
+  BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(),
+                                expectedRecords.begin(), expectedRecords.end());
+}
+
+BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture)
+
+BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent)
+{
+  BOOST_CHECK_EQUAL(m_commands.size(), 0);
+
+  advanceClocks(time::seconds(301)); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s
+  BOOST_REQUIRE_EQUAL(m_commands.size(), 2);
+  BOOST_CHECK_EQUAL(m_commands[0].getName(), "/localhost/nfd/faces/events");
+  BOOST_CHECK_EQUAL(m_commands[1].getName(), "/localhost/nfd/faces/list");
+}
+
+BOOST_AUTO_TEST_CASE(RemoveInvalidFaces)
+{
+  auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1");
+  auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2");
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1)));
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2)));
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2)));
+  BOOST_REQUIRE_EQUAL(m_rib.size(), 3);
+
+  ndn::nfd::FaceStatus status;
+  status.setFaceId(1);
+  std::vector<ndn::nfd::FaceStatus> activeFaces;
+  activeFaces.push_back(status);
+
+  m_manager.removeInvalidFaces(activeFaces);
+  advanceClocks(time::milliseconds(100));
+  BOOST_REQUIRE_EQUAL(m_rib.size(), 1);
+
+  auto it1 = m_rib.find("/test-remove-invalid-faces-1");
+  auto it2 = m_rib.find("/test-remove-invalid-faces-2");
+  BOOST_CHECK(it2 == m_rib.end());
+  BOOST_REQUIRE(it1 != m_rib.end());
+  BOOST_CHECK(it1->second->hasFaceId(1));
+  BOOST_CHECK(!it1->second->hasFaceId(2));
+}
+
+BOOST_AUTO_TEST_CASE(OnNotification)
+{
+  auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1);
+  auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1);
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1));
+  receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2));
+  BOOST_REQUIRE_EQUAL(m_rib.size(), 2);
+
+  auto makeNotification = [] (ndn::nfd::FaceEventKind eventKind, uint64_t faceId) -> ndn::nfd::FaceEventNotification {
+    ndn::nfd::FaceEventNotification notification;
+    notification.setKind(eventKind).setFaceId(faceId);
+    return notification;
+  };
+
+  m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1));
+  advanceClocks(time::milliseconds(100));
+  BOOST_CHECK_EQUAL(m_rib.size(), 0);
+
+  m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2));
+  advanceClocks(time::milliseconds(100));
+  BOOST_CHECK_EQUAL(m_rib.size(), 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // FaceMonitor
+BOOST_AUTO_TEST_SUITE_END() // TestRibManager
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/rib-update.t.cpp b/tests/daemon/rib/rib-update.t.cpp
new file mode 100644
index 0000000..22577f0
--- /dev/null
+++ b/tests/daemon/rib/rib-update.t.cpp
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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-update.hpp"
+#include "rib/rib-update-batch.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/daemon/rib/create-route.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestRibUpdate, nfd::tests::BaseFixture)
+
+BOOST_AUTO_TEST_CASE(BatchBasic)
+{
+  const uint64_t faceId = 1;
+
+  RibUpdateBatch batch(faceId);
+
+  Route routeRegister = createRoute(faceId, 128, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+  RibUpdate registerUpdate;
+  registerUpdate.setAction(RibUpdate::REGISTER)
+                .setName("/a")
+                .setRoute(routeRegister);
+
+  batch.add(registerUpdate);
+
+  BOOST_CHECK_EQUAL(batch.getFaceId(), faceId);
+
+  Route routeUnregister = createRoute(faceId, 0, 0, ndn::nfd::ROUTE_FLAG_CAPTURE);
+
+  RibUpdate unregisterUpdate;
+  unregisterUpdate.setAction(RibUpdate::UNREGISTER)
+                  .setName("/a/b")
+                  .setRoute(routeUnregister);
+
+  batch.add(unregisterUpdate);
+
+  BOOST_REQUIRE_EQUAL(batch.size(), 2);
+  RibUpdateBatch::const_iterator it = batch.begin();
+
+  BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::REGISTER);
+  BOOST_CHECK_EQUAL(it->getName(), "/a");
+  BOOST_CHECK_EQUAL(it->getRoute(), routeRegister);
+
+  ++it;
+  BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::UNREGISTER);
+  BOOST_CHECK_EQUAL(it->getName(), "/a/b");
+  BOOST_CHECK_EQUAL(it->getRoute(), routeUnregister);
+
+  ++it;
+  BOOST_CHECK(it == batch.end());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestRibUpdate
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/rib.t.cpp b/tests/daemon/rib/rib.t.cpp
new file mode 100644
index 0000000..26a47b3
--- /dev/null
+++ b/tests/daemon/rib/rib.t.cpp
@@ -0,0 +1,335 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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 "tests/daemon/rib/create-route.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestRib, nfd::tests::BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Parent)
+{
+  rib::Rib rib;
+
+  Name name1("/");
+  rib.insert(name1, createRoute(1, 20));
+
+  Name name2("/hello");
+  rib.insert(name2, createRoute(2, 20));
+
+  Name name3("/hello/world");
+  rib.insert(name3, createRoute(3, 20));
+
+  shared_ptr<rib::RibEntry> ribEntry = rib.findParent(name3);
+  BOOST_REQUIRE(ribEntry != nullptr);
+  BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 2);
+
+  ribEntry = rib.findParent(name2);
+  BOOST_REQUIRE(ribEntry != nullptr);
+  BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 1);
+
+  Name name4("/hello/test/foo/bar");
+  rib.insert(name4, createRoute(3, 20));
+
+  ribEntry = rib.findParent(name4);
+  BOOST_REQUIRE(ribEntry != nullptr);
+  BOOST_CHECK(ribEntry->getRoutes().front().faceId == 2);
+}
+
+BOOST_AUTO_TEST_CASE(Children)
+{
+  rib::Rib rib;
+
+  Name name1("/");
+  rib.insert(name1, createRoute(1, 20));
+
+  Name name2("/hello/world");
+  rib.insert(name2, createRoute(2, 20));
+
+  Name name3("/hello/test/foo/bar");
+  rib.insert(name3, createRoute(3, 20));
+
+  BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 2);
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0);
+  BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0);
+
+  Name name4("/hello");
+  rib.insert(name4, createRoute(4, 20));
+
+  BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 1);
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0);
+  BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0);
+  BOOST_CHECK_EQUAL((rib.find(name4)->second)->getChildren().size(), 2);
+
+  BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().front()->getName(), "/hello");
+  BOOST_CHECK_EQUAL((rib.find(name4)->second)->getParent()->getName(), "/");
+
+  BOOST_REQUIRE(static_cast<bool>((rib.find(name2)->second)->getParent()));
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getParent()->getName(), name4);
+  BOOST_REQUIRE(static_cast<bool>((rib.find(name3)->second)->getParent()));
+  BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4);
+}
+
+BOOST_AUTO_TEST_CASE(EraseFace)
+{
+  rib::Rib rib;
+
+  Route route1 = createRoute(1, 20);
+  Name name1("/");
+  rib.insert(name1, route1);
+
+  Route route2 = createRoute(2, 20);
+  Name name2("/hello/world");
+  rib.insert(name2, route2);
+
+  Route route3 = createRoute(1, 20);
+  Name name3("/hello/world");
+  rib.insert(name3, route3);
+
+  Route route4 = createRoute(1, 20);
+  Name name4("/not/inserted");
+
+  rib.erase(name4, route4);
+  rib.erase(name1, route1);
+
+  BOOST_CHECK(rib.find(name1) == rib.end());
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 2);
+
+  rib.erase(name2, route2);
+
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1);
+  BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().front().faceId, 1);
+
+  rib.erase(name3, route3);
+
+  BOOST_CHECK(rib.find(name2) == rib.end());
+
+  rib.erase(name4, route4);
+}
+
+BOOST_AUTO_TEST_CASE(EraseRibEntry)
+{
+  rib::Rib rib;
+
+  Name name1("/");
+  rib.insert(name1, createRoute(1, 20));
+
+  Route route2 = createRoute(2, 20);
+  Name name2("/hello");
+  rib.insert(name2, route2);
+
+  Name name3("/hello/world");
+  rib.insert(name3, createRoute(1, 20));
+
+  shared_ptr<rib::RibEntry> ribEntry1 = rib.find(name1)->second;
+  shared_ptr<rib::RibEntry> ribEntry2 = rib.find(name2)->second;
+  shared_ptr<rib::RibEntry> ribEntry3 = rib.find(name3)->second;
+
+  BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry2);
+  BOOST_CHECK(ribEntry3->getParent() == ribEntry2);
+
+  rib.erase(name2, route2);
+  BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry3);
+  BOOST_CHECK(ribEntry3->getParent() == ribEntry1);
+}
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  rib::Rib rib;
+
+  Route route1;
+  Name name1("/hello/world");
+  route1.faceId = 1;
+  route1.cost = 10;
+  route1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE;
+  route1.expires = time::steady_clock::now() + time::milliseconds(1500);
+
+  rib.insert(name1, route1);
+  BOOST_CHECK_EQUAL(rib.size(), 1);
+
+  rib.insert(name1, route1);
+  BOOST_CHECK_EQUAL(rib.size(), 1);
+
+  Route route2;
+  Name name2("/hello/world");
+  route2.faceId = 1;
+  route2.cost = 100;
+  route2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
+  route2.expires = time::steady_clock::now() + time::seconds(0);
+
+  rib.insert(name2, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 1);
+
+  route2.faceId = 2;
+  rib.insert(name2, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 2);
+
+  BOOST_CHECK(rib.find(name1)->second->hasFaceId(route1.faceId));
+  BOOST_CHECK(rib.find(name1)->second->hasFaceId(route2.faceId));
+
+  Name name3("/foo/bar");
+  rib.insert(name3, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 3);
+
+  route2.origin = ndn::nfd::ROUTE_ORIGIN_AUTOCONF;
+  rib.insert(name3, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 4);
+
+  rib.erase(name3, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 3);
+
+  Name name4("/hello/world");
+  rib.erase(name4, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 3);
+
+  route2.origin = ndn::nfd::ROUTE_ORIGIN_APP;
+  rib.erase(name4, route2);
+  BOOST_CHECK_EQUAL(rib.size(), 2);
+
+  BOOST_CHECK(rib.find(name2, route2) == nullptr);
+  BOOST_CHECK(rib.find(name1, route1) != nullptr);
+
+  Name name5("/hello/world/666");
+  Name name6("/hello/world/cs/ua/edu");
+  BOOST_CHECK(rib.findLongestPrefix(name1, route1) != nullptr);
+  BOOST_CHECK(rib.findLongestPrefix(name5, route1) != nullptr);
+  BOOST_CHECK(rib.findLongestPrefix(name6, route1) != nullptr);
+
+  rib.erase(name1, route1);
+  BOOST_CHECK_EQUAL(rib.size(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(RibSignals)
+{
+  rib::Rib rib;
+
+  Route route;
+  Name name("/hello/world");
+
+  Route route1 = createRoute(1, 20, 10);
+  Route route2 = createRoute(2, 30, 20);
+
+  RibRouteRef routeInfo;
+
+  int nAfterInsertEntryInvocations = 0;
+  int nAfterAddRouteInvocations = 0;
+  int nBeforeRemoveRouteInvocations = 0;
+  int nAfterEraseEntryInvocations = 0;
+  rib.afterInsertEntry.connect([&] (const Name& inName) {
+      BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 0);
+      BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 0);
+      BOOST_CHECK(rib.find(name) != rib.end());
+      nAfterInsertEntryInvocations++;
+    });
+
+  rib.afterAddRoute.connect([&] (const RibRouteRef& rrr) {
+      BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1);
+      BOOST_CHECK(rib.find(name) != rib.end());
+      BOOST_CHECK(rib.find(name, route) != nullptr);
+      nAfterAddRouteInvocations++;
+    });
+
+  rib.beforeRemoveRoute.connect([&] (const RibRouteRef& rrr) {
+      BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0);
+      BOOST_CHECK(rib.find(name) != rib.end());
+      BOOST_CHECK(rib.find(name, route) != nullptr);
+      nBeforeRemoveRouteInvocations++;
+    });
+
+  rib.afterEraseEntry.connect([&] (const Name& inName) {
+      BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2);
+      BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0);
+      BOOST_CHECK(rib.find(name) == rib.end());
+      nAfterEraseEntryInvocations++;
+    });
+
+  route = route1;
+  rib.insert(name, route);
+  BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1);
+  BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 1);
+
+  route = route2;
+  rib.insert(name, route);
+  BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1);
+  BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 2);
+
+  route = route1;
+  rib.erase(name, route);
+  BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 1);
+  BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0);
+
+  route = route2;
+  rib.erase(name, route);
+  BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2);
+  BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 1);
+}
+
+BOOST_AUTO_TEST_CASE(Output)
+{
+  rib::Rib rib;
+
+  Route root = createRoute(1, 20);
+  Name name1("/");
+  root.expires = nullopt;
+  rib.insert(name1, root);
+
+  Route route1 = createRoute(2, 20);
+  Name name2("/hello");
+  route1.expires = nullopt;
+  rib.insert(name2, route1);
+
+  Route route2 = createRoute(3, 20);
+  Name name3("/hello/world");
+  route2.expires = nullopt;
+  rib.insert(name3, route2);
+
+  const std::string ribStr = std::string(R"TEXT(
+RibEntry {
+  Name: /
+  Route(faceid: 1, origin: 20, cost: 0, flags: 0x0, never expires)
+}
+RibEntry {
+  Name: /hello
+  Route(faceid: 2, origin: 20, cost: 0, flags: 0x0, never expires)
+}
+RibEntry {
+  Name: /hello/world
+  Route(faceid: 3, origin: 20, cost: 0, flags: 0x0, never expires)
+}
+)TEXT").substr(1);
+
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(rib), ribStr);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestRib
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/route.t.cpp b/tests/daemon/rib/route.t.cpp
new file mode 100644
index 0000000..b1390b8
--- /dev/null
+++ b/tests/daemon/rib/route.t.cpp
@@ -0,0 +1,165 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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/route.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture)
+
+BOOST_FIXTURE_TEST_SUITE(CreateFromAnnouncement, UnitTestTimeFixture)
+
+BOOST_AUTO_TEST_CASE(NoValidity)
+{
+  auto pa = makePrefixAnn("/A", 212_s);
+  Route route(pa, 1815);
+  BOOST_CHECK_EQUAL(route.faceId, 1815);
+  BOOST_CHECK_EQUAL(route.origin, ndn::nfd::ROUTE_ORIGIN_PREFIXANN);
+  BOOST_CHECK_EQUAL(route.cost, 2048);
+  BOOST_CHECK_EQUAL(route.flags, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
+  BOOST_REQUIRE(route.expires);
+  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_CASE(BeforeNotBefore)
+{
+  auto pa = makePrefixAnn("/A", 212_s, {10_s, 80_s});
+  Route route(pa, 1053);
+  BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
+  BOOST_REQUIRE(route.expires);
+  BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
+}
+
+BOOST_AUTO_TEST_CASE(AfterNotAfter)
+{
+  auto pa = makePrefixAnn("/A", 212_s, {-80_s, -10_s});
+  Route route(pa, 2972);
+  BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
+  BOOST_REQUIRE(route.expires);
+  BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
+}
+
+BOOST_AUTO_TEST_CASE(ExpirationLtValidity)
+{
+  auto pa = makePrefixAnn("/A", 212_s, {-100_s, 300_s});
+  Route route(pa, 7804);
+  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
+  BOOST_REQUIRE(route.expires);
+  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_CASE(ValidityLtExpiration)
+{
+  auto pa = makePrefixAnn("/A", 212_s, {-100_s, 200_s});
+  Route route(pa, 7804);
+  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 200_s);
+  BOOST_REQUIRE(route.expires);
+  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // CreateFromAnnouncement
+
+BOOST_AUTO_TEST_CASE(Equality)
+{
+  Route a;
+  Route b;
+  BOOST_CHECK_EQUAL(a, b);
+
+  a.faceId = b.faceId = 15404;
+  a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
+  a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
+  a.cost = b.cost = 28826;
+  a.expires = b.expires = time::steady_clock::now() + 26782232_ms;
+  BOOST_CHECK_EQUAL(a, b);
+
+  b.faceId = 18559;
+  BOOST_CHECK_NE(a, b);
+  a.faceId = 18559;
+
+  b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
+  BOOST_CHECK_NE(a, b);
+  a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
+
+  b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
+  BOOST_CHECK_NE(a, b);
+  a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
+
+  b.cost = 103;
+  BOOST_CHECK_NE(a, b);
+  a.cost = 103;
+
+  b.expires = nullopt;
+  BOOST_CHECK_NE(a, b);
+  a.expires = nullopt;
+
+  BOOST_CHECK_EQUAL(a, b);
+}
+
+BOOST_FIXTURE_TEST_CASE(EqualityAnn, UnitTestTimeFixture)
+{
+  auto ann1 = makePrefixAnn("/ann", 1_h);
+  auto ann2 = makePrefixAnn("/ann", 2_h);
+  BOOST_CHECK_EQUAL(Route(ann1, 7001), Route(ann1, 7001));
+  BOOST_CHECK_NE(Route(ann1, 7001), Route(ann1, 7002));
+  BOOST_CHECK_NE(Route(ann1, 7001), Route(ann2, 7001));
+}
+
+BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture)
+{
+  Route r;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+                    "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)");
+
+  r.faceId = 4980;
+  r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
+  r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
+  r.cost = 2312;
+  r.expires = time::steady_clock::now() + 791214234_ms;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+                    "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: "
+                    "791214234 milliseconds)");
+
+  r.expires = nullopt;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+                    "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");
+
+  r = Route(makePrefixAnn("/ann", 1_h), 3247);
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+                    "Route(faceid: 3247, origin: prefixann, cost: 2048, flags: 0x1, expires in: "
+                    "3600000 milliseconds, announcement: (/ann expires=3600000 milliseconds))");
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestRoute
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/service.t.cpp b/tests/daemon/rib/service.t.cpp
new file mode 100644
index 0000000..14ee649
--- /dev/null
+++ b/tests/daemon/rib/service.t.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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/service.hpp"
+#include "tests/rib-io-fixture.hpp"
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestService, nfd::tests::RibIoFixture)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  ConfigSection section;
+  section.put("face_system.unix.path", "/var/run/nfd.sock");
+
+  ndn::KeyChain ribKeyChain;
+
+  BOOST_CHECK_THROW(Service::get(), std::logic_error);
+  BOOST_CHECK_THROW(Service(section, ribKeyChain), std::logic_error);
+
+  runOnRibIoService([&] {
+    {
+      BOOST_CHECK_THROW(Service::get(), std::logic_error);
+      Service ribService(section, ribKeyChain);
+      BOOST_CHECK_EQUAL(&ribService, &Service::get());
+    }
+    BOOST_CHECK_THROW(Service::get(), std::logic_error);
+    Service ribService(section, ribKeyChain);
+    BOOST_CHECK_THROW(Service(section, ribKeyChain), std::logic_error);
+  });
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestRibService
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/daemon/rib/sl-announce.t.cpp b/tests/daemon/rib/sl-announce.t.cpp
new file mode 100644
index 0000000..86b6025
--- /dev/null
+++ b/tests/daemon/rib/sl-announce.t.cpp
@@ -0,0 +1,334 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018,  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-manager.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+class RibManagerSlAnnounceFixture : public IdentityManagementTimeFixture
+{
+public:
+  using SlAnnounceResult = RibManager::SlAnnounceResult;
+
+  RibManagerSlAnnounceFixture()
+    : m_face(g_io, m_keyChain)
+    , m_scheduler(g_io)
+    , m_nfdController(m_face, m_keyChain)
+    , m_dispatcher(m_face, m_keyChain)
+    , m_fibUpdater(rib, m_nfdController)
+    , m_trustedSigner(m_keyChain.createIdentity("/trusted", ndn::RsaKeyParams()))
+    , m_untrustedSigner(m_keyChain.createIdentity("/untrusted", ndn::RsaKeyParams()))
+  {
+    rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
+    rib.wantMockFibResponseOnce = false;
+
+    // Face, Controller, Dispatcher are irrelevant to SlAnnounce functions but required by
+    // RibManager construction, so they are private. RibManager is a pointer to avoid code style
+    // rule 1.4 violation.
+    manager = make_unique<RibManager>(rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler);
+
+    loadTrustSchema();
+  }
+
+  template<typename ...T>
+  ndn::PrefixAnnouncement
+  makeTrustedAnn(const T&... args)
+  {
+    return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_trustedSigner);
+  }
+
+  template<typename ...T>
+  ndn::PrefixAnnouncement
+  makeUntrustedAnn(const T&... args)
+  {
+    return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_untrustedSigner);
+  }
+
+  /** \brief Invoke manager->slAnnounce and wait for result.
+   */
+  SlAnnounceResult
+  slAnnounceSync(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime)
+  {
+    optional<SlAnnounceResult> result;
+    manager->slAnnounce(pa, faceId, maxLifetime,
+      [&] (RibManager::SlAnnounceResult res) {
+        BOOST_CHECK(!result);
+        result = res;
+      });
+
+    g_io.poll();
+    BOOST_CHECK(result);
+    return result.value_or(SlAnnounceResult::ERROR);
+  }
+
+  /** \brief Invoke manager->slRenew and wait for result.
+   */
+  SlAnnounceResult
+  slRenewSync(const Name& name, uint64_t faceId, time::milliseconds maxLifetime)
+  {
+    optional<SlAnnounceResult> result;
+    manager->slRenew(name, faceId, maxLifetime,
+      [&] (RibManager::SlAnnounceResult res) {
+        BOOST_CHECK(!result);
+        result = res;
+      });
+
+    g_io.poll();
+    BOOST_CHECK(result);
+    return result.value_or(SlAnnounceResult::ERROR);
+  }
+
+  /** \brief Invoke manager->slFindAnn and wait for result.
+   */
+  optional<ndn::PrefixAnnouncement>
+  slFindAnnSync(const Name& name)
+  {
+    optional<optional<ndn::PrefixAnnouncement>> result;
+    manager->slFindAnn(name,
+      [&] (optional<ndn::PrefixAnnouncement> found) {
+        BOOST_CHECK(!result);
+        result = found;
+      });
+
+    g_io.poll();
+    BOOST_CHECK(result);
+    return result.value_or(nullopt);
+  }
+
+  /** \brief Lookup a route with PREFIXANN origin.
+   */
+  Route*
+  findAnnRoute(const Name& name, uint64_t faceId)
+  {
+    Route routeQuery;
+    routeQuery.faceId = faceId;
+    routeQuery.origin = ndn::nfd::ROUTE_ORIGIN_PREFIXANN;
+    return rib.find(name, routeQuery);
+  }
+
+private:
+  /** \brief Prepare a trust schema and load as localhop_security.
+   *
+   *  Test case may revert this operation with ribManager->disableLocalhop().
+   */
+  void
+  loadTrustSchema()
+  {
+    ConfigSection section;
+    section.put("rule.id", "PA");
+    section.put("rule.for", "data");
+    section.put("rule.checker.type", "customized");
+    section.put("rule.checker.sig-type", "rsa-sha256");
+    section.put("rule.checker.key-locator.type", "name");
+    section.put("rule.checker.key-locator.name", "/trusted");
+    section.put("rule.checker.key-locator.relation", "is-prefix-of");
+    section.put("trust-anchor.type", "base64");
+    section.put("trust-anchor.base64-string", getIdentityCertificateBase64("/trusted"));
+    manager->enableLocalhop(section, "trust-schema.section");
+  }
+
+public:
+  Rib rib;
+  unique_ptr<RibManager> manager;
+
+private:
+  ndn::util::DummyClientFace m_face;
+  ndn::util::Scheduler m_scheduler;
+  ndn::nfd::Controller m_nfdController;
+  ndn::mgmt::Dispatcher m_dispatcher;
+  FibUpdater m_fibUpdater;
+
+  ndn::security::SigningInfo m_trustedSigner;
+  ndn::security::SigningInfo m_untrustedSigner;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestSlAnnounce, RibManagerSlAnnounceFixture)
+
+BOOST_AUTO_TEST_CASE(AnnounceUnconfigured)
+{
+  manager->disableLocalhop();
+  auto pa = makeTrustedAnn("/fMXN7UeB", 1_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3275, 1_h), SlAnnounceResult::VALIDATION_FAILURE);
+
+  BOOST_CHECK(findAnnRoute("/fMXN7UeB", 3275) == nullptr);
+}
+
+BOOST_AUTO_TEST_CASE(AnnounceValidationError)
+{
+  auto pa = makeUntrustedAnn("/1nzAe0Y4", 1_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2959, 1_h), SlAnnounceResult::VALIDATION_FAILURE);
+
+  BOOST_CHECK(findAnnRoute("/1nzAe0Y4", 2959) == nullptr);
+}
+
+BOOST_AUTO_TEST_CASE(AnnounceInsert_AnnLifetime)
+{
+  auto pa = makeTrustedAnn("/EHJYmJz9", 1_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1641, 2_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/EHJYmJz9", 1641);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 1_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h);
+}
+
+BOOST_AUTO_TEST_CASE(AnnounceInsert_ArgLifetime)
+{
+  auto pa = makeTrustedAnn("/BU9Fec9E", 2_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1282, 1_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/BU9Fec9E", 1282);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 2_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h);
+}
+
+BOOST_AUTO_TEST_CASE(AnnounceReplace)
+{
+  auto pa = makeTrustedAnn("/HsBFGvL3", 1_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2813, 1_h), SlAnnounceResult::OK);
+
+  pa = makeTrustedAnn("/HsBFGvL3", 2_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2813, 2_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/HsBFGvL3", 2813);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 2_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 2_h);
+}
+
+BOOST_AUTO_TEST_CASE(AnnounceExpired)
+{
+  auto pa = makeTrustedAnn("/awrVv6V7", 1_h, std::make_pair(-3_h, -1_h));
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 9087, 1_h), SlAnnounceResult::EXPIRED);
+
+  BOOST_CHECK(findAnnRoute("/awrVv6V7", 9087) == nullptr);
+}
+
+BOOST_AUTO_TEST_CASE(RenewNotFound)
+{
+  BOOST_CHECK_EQUAL(slRenewSync("IAYigN73", 1070, 1_h), SlAnnounceResult::NOT_FOUND);
+
+  BOOST_CHECK(findAnnRoute("/IAYigN73", 1070) == nullptr);
+}
+
+BOOST_AUTO_TEST_CASE(RenewProlong_ArgLifetime)
+{
+  auto pa = makeTrustedAnn("/P2IYFqtr", 4_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 4506, 2_h), SlAnnounceResult::OK);
+  advanceClocks(1_h); // Route has 1_h remaining lifetime
+
+  BOOST_CHECK_EQUAL(slRenewSync("/P2IYFqtr/2321", 4506, 2_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/P2IYFqtr", 4506);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 2_h); // set by slRenew
+}
+
+BOOST_AUTO_TEST_CASE(RenewProlong_AnnLifetime)
+{
+  auto pa = makeTrustedAnn("/be01Yiba", 4_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1589, 2_h), SlAnnounceResult::OK);
+  advanceClocks(1_h); // Route has 1_h remaining lifetime
+
+  BOOST_CHECK_EQUAL(slRenewSync("/be01Yiba/4324", 1589, 5_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/be01Yiba", 1589);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 3_h); // capped by annExpires
+}
+
+BOOST_AUTO_TEST_CASE(RenewShorten)
+{
+  auto pa = makeTrustedAnn("/5XCHYCAd", 4_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3851, 4_h), SlAnnounceResult::OK);
+  advanceClocks(1_h); // Route has 3_h remaining lifetime
+
+  BOOST_CHECK_EQUAL(slRenewSync("/5XCHYCAd/98934", 3851, 1_h), SlAnnounceResult::OK);
+
+  Route* route = findAnnRoute("/5XCHYCAd", 3851);
+  BOOST_REQUIRE(route != nullptr);
+  BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h);
+  BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h); // set by slRenew
+}
+
+BOOST_AUTO_TEST_CASE(RenewShorten_Zero)
+{
+  auto pa = makeTrustedAnn("/cdQ7KPNw", 4_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 8031, 4_h), SlAnnounceResult::OK);
+  advanceClocks(1_h); // Route has 3_h remaining lifetime
+
+  BOOST_CHECK_EQUAL(slRenewSync("/cdQ7KPNw/8023", 8031, 0_s), SlAnnounceResult::EXPIRED);
+
+  BOOST_CHECK(findAnnRoute("/cdQ7KPNw", 8031) == nullptr);
+}
+
+BOOST_AUTO_TEST_CASE(FindExisting)
+{
+  auto pa = makeTrustedAnn("/JHugsjjr", 1_h);
+  BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2363, 1_h), SlAnnounceResult::OK);
+
+  auto found = slFindAnnSync("/JHugsjjr");
+  BOOST_REQUIRE(found);
+  BOOST_CHECK_EQUAL(found->getAnnouncedName(), "/JHugsjjr");
+  BOOST_CHECK(found->getData());
+
+  auto found2 = slFindAnnSync("/JHugsjjr/StvXhKR5");
+  BOOST_CHECK(found == found2);
+}
+
+BOOST_AUTO_TEST_CASE(FindNew)
+{
+  Route route;
+  route.faceId = 1367;
+  route.origin = ndn::nfd::ROUTE_ORIGIN_APP;
+  rib.insert("/dLY1pRhR", route);
+
+  auto pa = slFindAnnSync("/dLY1pRhR/3qNK9Ngn");
+  BOOST_REQUIRE(pa);
+  BOOST_CHECK_EQUAL(pa->getAnnouncedName(), "/dLY1pRhR");
+}
+
+BOOST_AUTO_TEST_CASE(FindNone)
+{
+  auto pa = slFindAnnSync("/2YNeYuV2");
+  BOOST_CHECK(!pa);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestSlAnnounce
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd