rib: move RibManager to mgmt

Refs: #4528
Change-Id: Idff4ce8fe28b48163794cd12f0d185f8ca4233e3
diff --git a/daemon/fw/self-learning-strategy.cpp b/daemon/fw/self-learning-strategy.cpp
index 42f0f22..92f9ae3 100644
--- a/daemon/fw/self-learning-strategy.cpp
+++ b/daemon/fw/self-learning-strategy.cpp
@@ -227,7 +227,7 @@
 {
   runOnRibIoService([pitEntryWeak = weak_ptr<pit::Entry>{pitEntry}, inFaceId = inFace.getId(), data, pa] {
     rib::Service::get().getRibManager().slAnnounce(pa, inFaceId, ROUTE_RENEW_LIFETIME,
-      [] (rib::RibManager::SlAnnounceResult res) {
+      [] (RibManager::SlAnnounceResult res) {
         NFD_LOG_DEBUG("Add route via PrefixAnnouncement with result=" << res);
       });
   });
@@ -239,7 +239,7 @@
   // renew route with PA or ignore PA (if route has no PA)
   runOnRibIoService([name, inFaceId, maxLifetime] {
     rib::Service::get().getRibManager().slRenew(name, inFaceId, maxLifetime,
-      [] (rib::RibManager::SlAnnounceResult res) {
+      [] (RibManager::SlAnnounceResult res) {
         NFD_LOG_DEBUG("Renew route with result=" << res);
       });
   });
diff --git a/daemon/rib/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
similarity index 98%
rename from daemon/rib/rib-manager.cpp
rename to daemon/mgmt/rib-manager.cpp
index 4477ebc..0a73db2 100644
--- a/daemon/rib/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -36,7 +36,9 @@
 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
 
 namespace nfd {
-namespace rib {
+
+using rib::RibUpdate;
+using rib::Route;
 
 NFD_LOG_INIT(RibManager);
 
@@ -46,7 +48,7 @@
 
 const Name RibManager::LOCALHOP_TOP_PREFIX = "/localhop/nfd";
 
-RibManager::RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
+RibManager::RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
                        ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
                        ndn::util::Scheduler& scheduler)
   : ManagerBase(dispatcher, MGMT_MODULE_NAME)
@@ -267,7 +269,7 @@
 {
   auto now = time::steady_clock::now();
   for (const auto& kv : m_rib) {
-    const RibEntry& entry = *kv.second;
+    const rib::RibEntry& entry = *kv.second;
     ndn::nfd::RibEntry item;
     item.setName(entry.getName());
     for (const Route& route : entry.getRoutes()) {
@@ -414,7 +416,7 @@
 void
 RibManager::slFindAnn(const Name& name, const SlFindAnnCallback& cb) const
 {
-  shared_ptr<RibEntry> entry;
+  shared_ptr<rib::RibEntry> entry;
   auto exactMatch = m_rib.find(name);
   if (exactMatch != m_rib.end()) {
     entry = exactMatch->second;
@@ -496,5 +498,4 @@
   }
 }
 
-} // namespace rib
 } // namespace nfd
diff --git a/daemon/rib/rib-manager.hpp b/daemon/mgmt/rib-manager.hpp
similarity index 91%
rename from daemon/rib/rib-manager.hpp
rename to daemon/mgmt/rib-manager.hpp
index 503dc2f..876ed75 100644
--- a/daemon/rib/rib-manager.hpp
+++ b/daemon/mgmt/rib-manager.hpp
@@ -23,28 +23,26 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef NFD_DAEMON_RIB_RIB_MANAGER_HPP
-#define NFD_DAEMON_RIB_RIB_MANAGER_HPP
-
-#include "fib-updater.hpp"
-#include "rib.hpp"
+#ifndef NFD_DAEMON_MGMT_RIB_MANAGER_HPP
+#define NFD_DAEMON_MGMT_RIB_MANAGER_HPP
 
 #include "core/config-file.hpp"
 #include "core/manager-base.hpp"
+#include "rib/rib.hpp"
 
-#include <ndn-cxx/security/validator-config.hpp>
 #include <ndn-cxx/mgmt/nfd/controller.hpp>
 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
 #include <ndn-cxx/util/scheduler.hpp>
 
 namespace nfd {
-namespace rib {
 
 /**
- * @brief Serve commands and datasets in NFD RIB management protocol.
+ * @brief Serve commands and datasets of NFD RIB management protocol.
+ * @sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt
  */
-class RibManager : public nfd::ManagerBase
+class RibManager : public ManagerBase
 {
 public:
   class Error : public std::runtime_error
@@ -53,8 +51,9 @@
     using std::runtime_error::runtime_error;
   };
 
-  RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain, ndn::nfd::Controller& nfdController,
-             Dispatcher& dispatcher, ndn::util::Scheduler& scheduler);
+  RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
+             ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
+             ndn::util::Scheduler& scheduler);
 
   /**
    * @brief Apply localhost_security configuration.
@@ -174,7 +173,7 @@
    *  \param done completion callback
    */
   void
-  beginAddRoute(const Name& name, Route route, optional<time::nanoseconds> expires,
+  beginAddRoute(const Name& name, rib::Route route, optional<time::nanoseconds> expires,
                 const std::function<void(RibUpdateResult)>& done);
 
   /** \brief Start removing a route from RIB and FIB.
@@ -183,11 +182,12 @@
    *  \param done completion callback
    */
   void
-  beginRemoveRoute(const Name& name, const Route& route,
+  beginRemoveRoute(const Name& name, const rib::Route& route,
                    const std::function<void(RibUpdateResult)>& done);
 
   void
-  beginRibUpdate(const RibUpdate& update, const std::function<void(RibUpdateResult)>& done);
+  beginRibUpdate(const rib::RibUpdate& update,
+                 const std::function<void(RibUpdateResult)>& done);
 
 private: // management Dispatcher related
   void
@@ -243,7 +243,7 @@
   static const Name LOCALHOP_TOP_PREFIX;
 
 private:
-  Rib& m_rib;
+  rib::Rib& m_rib;
   ndn::KeyChain& m_keyChain;
   ndn::nfd::Controller& m_nfdController;
   Dispatcher& m_dispatcher;
@@ -262,7 +262,6 @@
 std::ostream&
 operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
 
-} // namespace rib
 } // namespace nfd
 
-#endif // NFD_DAEMON_RIB_RIB_MANAGER_HPP
+#endif // NFD_DAEMON_MGMT_RIB_MANAGER_HPP
diff --git a/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp b/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
index 2d508f8..7810619 100644
--- a/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
+++ b/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,7 +25,7 @@
 
 #include "host-to-gateway-readvertise-policy.hpp"
 #include "core/scope-prefix.hpp"
-#include "rib/rib-manager.hpp"
+#include "mgmt/rib-manager.hpp"
 
 #include <ndn-cxx/security/pib/identity.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
diff --git a/daemon/rib/service.hpp b/daemon/rib/service.hpp
index 0d6a71a..fe9b110 100644
--- a/daemon/rib/service.hpp
+++ b/daemon/rib/service.hpp
@@ -26,9 +26,10 @@
 #ifndef NFD_DAEMON_RIB_SERVICE_HPP
 #define NFD_DAEMON_RIB_SERVICE_HPP
 
-#include "rib-manager.hpp"
-
 #include "core/config-file.hpp"
+#include "mgmt/rib-manager.hpp"
+#include "rib/fib-updater.hpp"
+#include "rib/rib.hpp"
 
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/mgmt/dispatcher.hpp>
diff --git a/tests/daemon/rib/sl-announce.t.cpp b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
similarity index 92%
rename from tests/daemon/rib/sl-announce.t.cpp
rename to tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
index 86b6025..06e3d5e 100644
--- a/tests/daemon/rib/sl-announce.t.cpp
+++ b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -23,17 +23,17 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "rib/rib-manager.hpp"
+#include "mgmt/rib-manager.hpp"
+#include "rib/fib-updater.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;
+using rib::Route;
 
 class RibManagerSlAnnounceFixture : public IdentityManagementTimeFixture
 {
@@ -49,7 +49,7 @@
     , m_trustedSigner(m_keyChain.createIdentity("/trusted", ndn::RsaKeyParams()))
     , m_untrustedSigner(m_keyChain.createIdentity("/untrusted", ndn::RsaKeyParams()))
   {
-    rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
+    rib.mockFibResponse = [] (const auto&) { return true; };
     rib.wantMockFibResponseOnce = false;
 
     // Face, Controller, Dispatcher are irrelevant to SlAnnounce functions but required by
@@ -62,16 +62,16 @@
 
   template<typename ...T>
   ndn::PrefixAnnouncement
-  makeTrustedAnn(const T&... args)
+  makeTrustedAnn(T&&... args)
   {
-    return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_trustedSigner);
+    return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_trustedSigner);
   }
 
   template<typename ...T>
   ndn::PrefixAnnouncement
-  makeUntrustedAnn(const T&... args)
+  makeUntrustedAnn(T&&... args)
   {
-    return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_untrustedSigner);
+    return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_untrustedSigner);
   }
 
   /** \brief Invoke manager->slAnnounce and wait for result.
@@ -158,7 +158,7 @@
   }
 
 public:
-  Rib rib;
+  rib::Rib rib;
   unique_ptr<RibManager> manager;
 
 private:
@@ -166,13 +166,15 @@
   ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
   ndn::mgmt::Dispatcher m_dispatcher;
-  FibUpdater m_fibUpdater;
+  rib::FibUpdater m_fibUpdater;
 
   ndn::security::SigningInfo m_trustedSigner;
   ndn::security::SigningInfo m_untrustedSigner;
 };
 
-BOOST_FIXTURE_TEST_SUITE(TestSlAnnounce, RibManagerSlAnnounceFixture)
+BOOST_AUTO_TEST_SUITE(Mgmt)
+BOOST_AUTO_TEST_SUITE(TestRibManager)
+BOOST_FIXTURE_TEST_SUITE(SlAnnounce, RibManagerSlAnnounceFixture)
 
 BOOST_AUTO_TEST_CASE(AnnounceUnconfigured)
 {
@@ -327,8 +329,9 @@
   BOOST_CHECK(!pa);
 }
 
-BOOST_AUTO_TEST_SUITE_END() // TestSlAnnounce
+BOOST_AUTO_TEST_SUITE_END() // SlAnnounce
+BOOST_AUTO_TEST_SUITE_END() // TestRibManager
+BOOST_AUTO_TEST_SUITE_END() // Mgmt
 
 } // namespace tests
-} // namespace rib
 } // namespace nfd
diff --git a/tests/daemon/rib/rib-manager.t.cpp b/tests/daemon/mgmt/rib-manager.t.cpp
similarity index 93%
rename from tests/daemon/rib/rib-manager.t.cpp
rename to tests/daemon/mgmt/rib-manager.t.cpp
index be59ca5..46da6a1 100644
--- a/tests/daemon/rib/rib-manager.t.cpp
+++ b/tests/daemon/mgmt/rib-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -23,22 +23,19 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "rib/rib-manager.hpp"
+#include "mgmt/rib-manager.hpp"
 #include "core/fib-max-depth.hpp"
+#include "rib/fib-updater.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;
@@ -65,7 +62,7 @@
     , 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) {
+    m_rib.mockFibResponse = [] (const rib::RibUpdateBatch& batch) {
       BOOST_CHECK(batch.begin() != batch.end());
       return true;
     };
@@ -93,7 +90,7 @@
   registerWithNfd()
   {
     m_manager.registerWithNfd();
-    advanceClocks(time::milliseconds(1));
+    advanceClocks(1_ms);
 
     auto replyFibAddCommand = [this] (const Interest& interest) {
       nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
@@ -114,7 +111,7 @@
     for (const auto& command : m_commands) {
       if (commandPrefix.isPrefixOf(command.getName())) {
         replyFibAddCommand(command);
-        advanceClocks(time::milliseconds(1));
+        advanceClocks(1_ms);
       }
     }
 
@@ -210,8 +207,8 @@
 
   ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
-  Rib m_rib;
-  FibUpdater m_fibUpdater;
+  rib::Rib m_rib;
+  rib::FibUpdater m_fibUpdater;
   RibManager m_manager;
 };
 
@@ -240,6 +237,7 @@
   return os << static_cast<int>(result);
 }
 
+BOOST_AUTO_TEST_SUITE(Mgmt)
 BOOST_AUTO_TEST_SUITE(TestRibManager)
 
 class AddTopPrefixFixture : public RibManagerFixture
@@ -389,20 +387,20 @@
 
 BOOST_AUTO_TEST_CASE(Expiration)
 {
-  auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, time::milliseconds(50));
+  auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms);
   auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527);
   receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
 
-  advanceClocks(time::milliseconds(55));
+  advanceClocks(55_ms);
   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));
+  paramsRegister.setExpirationPeriod(100_ms);
   receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
 
-  advanceClocks(time::milliseconds(55));
+  advanceClocks(55_ms);
   BOOST_REQUIRE_EQUAL(m_commands.size(), 1); // the registered route is still active
   BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
 }
@@ -431,8 +429,8 @@
 BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture)
 {
   uint64_t faceId = 0;
-  auto generateRoute = [&faceId] () -> Route {
-    Route route;
+  auto generateRoute = [&faceId] () -> rib::Route {
+    rib::Route route;
     route.faceId = ++faceId;
     route.cost = route.faceId * 10;
     route.expires = nullopt;
@@ -491,7 +489,7 @@
 {
   BOOST_CHECK_EQUAL(m_commands.size(), 0);
 
-  advanceClocks(time::seconds(301)); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s
+  advanceClocks(301_s); // 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");
@@ -512,7 +510,7 @@
   activeFaces.push_back(status);
 
   m_manager.removeInvalidFaces(activeFaces);
-  advanceClocks(time::milliseconds(100));
+  advanceClocks(100_ms);
   BOOST_REQUIRE_EQUAL(m_rib.size(), 1);
 
   auto it1 = m_rib.find("/test-remove-invalid-faces-1");
@@ -531,24 +529,23 @@
   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;
+  auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) {
+    return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId);
   };
 
   m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1));
-  advanceClocks(time::milliseconds(100));
+  advanceClocks(100_ms);
   BOOST_CHECK_EQUAL(m_rib.size(), 0);
 
   m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2));
-  advanceClocks(time::milliseconds(100));
+  advanceClocks(100_ms);
   BOOST_CHECK_EQUAL(m_rib.size(), 0);
 }
 
 BOOST_AUTO_TEST_SUITE_END() // FaceMonitor
+
 BOOST_AUTO_TEST_SUITE_END() // TestRibManager
+BOOST_AUTO_TEST_SUITE_END() // Mgmt
 
 } // namespace tests
-} // namespace rib
 } // namespace nfd