mgmt: merge ManagerBase with NfdManagerBase

Refs: #4528
Change-Id: I2ecb4af68927157a9eafc269399855cff192bb54
diff --git a/daemon/mgmt/cs-manager.cpp b/daemon/mgmt/cs-manager.cpp
index 60099d2..50c3001 100644
--- a/daemon/mgmt/cs-manager.cpp
+++ b/daemon/mgmt/cs-manager.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,
@@ -24,17 +24,20 @@
  */
 
 #include "cs-manager.hpp"
+#include "fw/forwarder-counters.hpp"
+#include "table/cs.hpp"
+
 #include <ndn-cxx/mgmt/nfd/cs-info.hpp>
 
 namespace nfd {
 
 constexpr size_t CsManager::ERASE_LIMIT;
 
-CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCnt,
+CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCounters,
                      Dispatcher& dispatcher, CommandAuthenticator& authenticator)
-  : NfdManagerBase(dispatcher, authenticator, "cs")
+  : ManagerBase("cs", dispatcher, authenticator)
   , m_cs(cs)
-  , m_fwCnt(fwCnt)
+  , m_fwCounters(fwCounters)
 {
   registerCommandHandler<ndn::nfd::CsConfigCommand>("config",
     bind(&CsManager::changeConfig, this, _4, _5));
@@ -106,8 +109,8 @@
   info.setEnableAdmit(m_cs.shouldAdmit());
   info.setEnableServe(m_cs.shouldServe());
   info.setNEntries(m_cs.size());
-  info.setNHits(m_fwCnt.nCsHits);
-  info.setNMisses(m_fwCnt.nCsMisses);
+  info.setNHits(m_fwCounters.nCsHits);
+  info.setNMisses(m_fwCounters.nCsMisses);
 
   context.append(info.wireEncode());
   context.end();
diff --git a/daemon/mgmt/cs-manager.hpp b/daemon/mgmt/cs-manager.hpp
index e1d2bbd..83db017 100644
--- a/daemon/mgmt/cs-manager.hpp
+++ b/daemon/mgmt/cs-manager.hpp
@@ -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,
@@ -26,19 +26,24 @@
 #ifndef NFD_DAEMON_MGMT_CS_MANAGER_HPP
 #define NFD_DAEMON_MGMT_CS_MANAGER_HPP
 
-#include "nfd-manager-base.hpp"
-#include "table/cs.hpp"
-#include "fw/forwarder-counters.hpp"
+#include "manager-base.hpp"
 
 namespace nfd {
 
-/** \brief Implement the CS Management of NFD Management Protocol.
- *  \sa https://redmine.named-data.net/projects/nfd/wiki/CsMgmt
+namespace cs {
+class Cs;
+} // namespace cs
+
+class ForwarderCounters;
+
+/**
+ * \brief Implements the CS Management of NFD Management Protocol.
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/CsMgmt
  */
-class CsManager : public NfdManagerBase
+class CsManager : public ManagerBase
 {
 public:
-  CsManager(Cs& cs, const ForwarderCounters& fwCnt,
+  CsManager(cs::Cs& cs, const ForwarderCounters& fwCounters,
             Dispatcher& dispatcher, CommandAuthenticator& authenticator);
 
 private:
@@ -64,8 +69,8 @@
   static constexpr size_t ERASE_LIMIT = 256;
 
 private:
-  Cs& m_cs;
-  const ForwarderCounters& m_fwCnt;
+  cs::Cs& m_cs;
+  const ForwarderCounters& m_fwCounters;
 };
 
 } // namespace nfd
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 2299927..b7b22f2 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.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,
@@ -41,9 +41,8 @@
 NFD_LOG_INIT(FaceManager);
 
 FaceManager::FaceManager(FaceSystem& faceSystem,
-                         Dispatcher& dispatcher,
-                         CommandAuthenticator& authenticator)
-  : NfdManagerBase(dispatcher, authenticator, "faces")
+                         Dispatcher& dispatcher, CommandAuthenticator& authenticator)
+  : ManagerBase("faces", dispatcher, authenticator)
   , m_faceSystem(faceSystem)
   , m_faceTable(faceSystem.getFaceTable())
 {
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index 778e824..620ab99 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -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,
@@ -26,21 +26,20 @@
 #ifndef NFD_DAEMON_MGMT_FACE_MANAGER_HPP
 #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP
 
-#include "nfd-manager-base.hpp"
+#include "manager-base.hpp"
 #include "face/face-system.hpp"
 
 namespace nfd {
 
 /**
- * @brief implement the Face Management of NFD Management Protocol.
+ * @brief Implements the Face Management of NFD Management Protocol.
  * @sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
  */
-class FaceManager : public NfdManagerBase
+class FaceManager : public ManagerBase
 {
 public:
   FaceManager(FaceSystem& faceSystem,
-              Dispatcher& dispatcher,
-              CommandAuthenticator& authenticator);
+              Dispatcher& dispatcher, CommandAuthenticator& authenticator);
 
 private: // ControlCommand
   void
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index b73698d..8fef3a3 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -27,6 +27,7 @@
 
 #include "core/logger.hpp"
 #include "fw/face-table.hpp"
+#include "table/fib.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
 #include <ndn-cxx/mgmt/nfd/fib-entry.hpp>
@@ -37,11 +38,9 @@
 
 NFD_LOG_INIT(FibManager);
 
-FibManager::FibManager(Fib& fib,
-                       const FaceTable& faceTable,
-                       Dispatcher& dispatcher,
-                       CommandAuthenticator& authenticator)
-  : NfdManagerBase(dispatcher, authenticator, "fib")
+FibManager::FibManager(Fib& fib, const FaceTable& faceTable,
+                       Dispatcher& dispatcher, CommandAuthenticator& authenticator)
+  : ManagerBase("fib", dispatcher, authenticator)
   , m_fib(fib)
   , m_faceTable(faceTable)
 {
diff --git a/daemon/mgmt/fib-manager.hpp b/daemon/mgmt/fib-manager.hpp
index c5455e9..073fe43 100644
--- a/daemon/mgmt/fib-manager.hpp
+++ b/daemon/mgmt/fib-manager.hpp
@@ -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,
@@ -26,25 +26,25 @@
 #ifndef NFD_DAEMON_MGMT_FIB_MANAGER_HPP
 #define NFD_DAEMON_MGMT_FIB_MANAGER_HPP
 
-#include "nfd-manager-base.hpp"
-#include "fw/forwarder.hpp"
-#include "table/fib.hpp"
+#include "manager-base.hpp"
 
 namespace nfd {
 
+namespace fib {
+class Fib;
+} // namespace fib
+
 class FaceTable;
 
 /**
- * @brief implement the FIB Management of NFD Management Protocol.
+ * @brief Implements the FIB Management of NFD Management Protocol.
  * @sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt
  */
-class FibManager : public NfdManagerBase
+class FibManager : public ManagerBase
 {
 public:
-  FibManager(Fib& fib,
-             const FaceTable& faceTable,
-             Dispatcher& dispatcher,
-             CommandAuthenticator& authenticator);
+  FibManager(fib::Fib& fib, const FaceTable& faceTable,
+             Dispatcher& dispatcher, CommandAuthenticator& authenticator);
 
 private:
   void
@@ -66,7 +66,7 @@
   setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
 
 private:
-  Fib& m_fib;
+  fib::Fib& m_fib;
   const FaceTable& m_faceTable;
 };
 
diff --git a/daemon/mgmt/forwarder-status-manager.hpp b/daemon/mgmt/forwarder-status-manager.hpp
index 343d7d4..39c52f3 100644
--- a/daemon/mgmt/forwarder-status-manager.hpp
+++ b/daemon/mgmt/forwarder-status-manager.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,8 @@
 #ifndef NFD_DAEMON_MGMT_FORWARDER_STATUS_MANAGER_HPP
 #define NFD_DAEMON_MGMT_FORWARDER_STATUS_MANAGER_HPP
 
-#include "core/manager-base.hpp"
+#include "manager-base.hpp"
+
 #include <ndn-cxx/mgmt/nfd/forwarder-status.hpp>
 
 namespace nfd {
@@ -34,8 +35,8 @@
 class Forwarder;
 
 /**
- * @brief implement the Forwarder Status of NFD Management Protocol.
- * @sa http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
+ * @brief Implements the Forwarder Status of NFD Management Protocol.
+ * @sa https://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
  */
 class ForwarderStatusManager : noncopyable
 {
@@ -53,7 +54,7 @@
                     ndn::mgmt::StatusDatasetContext& context);
 
 private:
-  Forwarder&  m_forwarder;
+  Forwarder& m_forwarder;
   Dispatcher& m_dispatcher;
   time::system_clock::TimePoint m_startTimestamp;
 };
diff --git a/daemon/mgmt/manager-base.cpp b/daemon/mgmt/manager-base.cpp
new file mode 100644
index 0000000..496b439
--- /dev/null
+++ b/daemon/mgmt/manager-base.cpp
@@ -0,0 +1,117 @@
+/* -*- 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 "manager-base.hpp"
+
+namespace nfd {
+
+ManagerBase::ManagerBase(const std::string& module, Dispatcher& dispatcher)
+  : m_module(module)
+  , m_dispatcher(dispatcher)
+{
+}
+
+ManagerBase::ManagerBase(const std::string& module, Dispatcher& dispatcher,
+                         CommandAuthenticator& authenticator)
+  : m_module(module)
+  , m_dispatcher(dispatcher)
+  , m_authenticator(&authenticator)
+{
+}
+
+ManagerBase::~ManagerBase() = default;
+
+void
+ManagerBase::registerStatusDatasetHandler(const std::string& verb,
+                                          const ndn::mgmt::StatusDatasetHandler& handler)
+{
+  m_dispatcher.addStatusDataset(makeRelPrefix(verb),
+                                ndn::mgmt::makeAcceptAllAuthorization(),
+                                handler);
+}
+
+ndn::mgmt::PostNotification
+ManagerBase::registerNotificationStream(const std::string& verb)
+{
+  return m_dispatcher.addNotificationStream(makeRelPrefix(verb));
+}
+
+void
+ManagerBase::extractRequester(const Interest& interest,
+                              ndn::mgmt::AcceptContinuation accept)
+{
+  const Name& interestName = interest.getName();
+
+  try {
+    ndn::SignatureInfo sigInfo(interestName.at(ndn::signed_interest::POS_SIG_INFO).blockFromValue());
+    if (!sigInfo.hasKeyLocator() ||
+        sigInfo.getKeyLocator().getType() != ndn::KeyLocator::KeyLocator_Name) {
+      return accept("");
+    }
+
+    accept(sigInfo.getKeyLocator().getName().toUri());
+  }
+  catch (const tlv::Error&) {
+    accept("");
+  }
+}
+
+ndn::mgmt::Authorization
+ManagerBase::makeAuthorization(const std::string& verb)
+{
+  BOOST_ASSERT(m_authenticator != nullptr);
+  return m_authenticator->makeAuthorization(m_module, verb);
+}
+
+bool
+ManagerBase::validateParameters(const ControlCommand& command,
+                                const ndn::mgmt::ControlParameters& parameters)
+{
+  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&parameters) != nullptr);
+
+  try {
+    command.validateRequest(static_cast<const ControlParameters&>(parameters));
+  }
+  catch (const ControlCommand::ArgumentError&) {
+    return false;
+  }
+  return true;
+}
+
+void
+ManagerBase::handleCommand(shared_ptr<ControlCommand> command,
+                           const ControlCommandHandler& handler,
+                           const Name& prefix, const Interest& interest,
+                           const ndn::mgmt::ControlParameters& params,
+                           ndn::mgmt::CommandContinuation done)
+{
+  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
+
+  ControlParameters parameters = static_cast<const ControlParameters&>(params);
+  command->applyDefaultsToRequest(parameters);
+  handler(*command, prefix, interest, parameters, done);
+}
+
+} // namespace nfd
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
new file mode 100644
index 0000000..2c963b1
--- /dev/null
+++ b/daemon/mgmt/manager-base.hpp
@@ -0,0 +1,166 @@
+/* -*- 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_DAEMON_MGMT_MANAGER_BASE_HPP
+#define NFD_DAEMON_MGMT_MANAGER_BASE_HPP
+
+#include "command-authenticator.hpp"
+
+#include <ndn-cxx/mgmt/dispatcher.hpp>
+#include <ndn-cxx/mgmt/nfd/control-command.hpp>
+#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
+#include <ndn-cxx/mgmt/nfd/control-response.hpp>
+
+namespace nfd {
+
+using ndn::mgmt::Dispatcher;
+using ndn::nfd::ControlCommand;
+using ndn::nfd::ControlParameters;
+using ndn::nfd::ControlResponse;
+
+/**
+ * @brief A collection of common functions shared by all NFD managers,
+ *        such as communicating with the dispatcher and command validator.
+ */
+class ManagerBase : noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    using std::runtime_error::runtime_error;
+  };
+
+  virtual
+  ~ManagerBase();
+
+  const std::string&
+  getModule() const
+  {
+    return m_module;
+  }
+
+protected:
+  /**
+   * @warning if you use this constructor, you MUST override makeAuthorization()
+   */
+  ManagerBase(const std::string& module, Dispatcher& dispatcher);
+
+  ManagerBase(const std::string& module, Dispatcher& dispatcher,
+              CommandAuthenticator& authenticator);
+
+PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
+  // difference from mgmt::ControlCommand: accepts nfd::ControlParameters
+  using ControlCommandHandler = std::function<void(const ControlCommand& command,
+                                                   const Name& prefix, const Interest& interest,
+                                                   const ControlParameters& parameters,
+                                                   const ndn::mgmt::CommandContinuation done)>;
+
+  template<typename Command>
+  void
+  registerCommandHandler(const std::string& verb,
+                         const ControlCommandHandler& handler);
+
+  void
+  registerStatusDatasetHandler(const std::string& verb,
+                               const ndn::mgmt::StatusDatasetHandler& handler);
+
+  ndn::mgmt::PostNotification
+  registerNotificationStream(const std::string& verb);
+
+PUBLIC_WITH_TESTS_ELSE_PROTECTED: // helpers
+  /**
+   * @brief Extracts the requester from a ControlCommand request.
+   *
+   * This is called after the signature has been validated.
+   *
+   * @param interest a request for ControlCommand
+   * @param accept callback of successful validation, takes the requester string as a argument
+   */
+  void
+  extractRequester(const Interest& interest, ndn::mgmt::AcceptContinuation accept);
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+  /**
+   * @brief Returns an authorization function for a specific management module and verb.
+   */
+  virtual ndn::mgmt::Authorization
+  makeAuthorization(const std::string& verb);
+
+  /**
+   * @brief Validates the @p parameters for a given @p command.
+   *
+   * @param parameters the original ControlParameters
+   * @return whether the original ControlParameters can be validated
+   */
+  static bool
+  validateParameters(const ControlCommand& command,
+                     const ndn::mgmt::ControlParameters& parameters);
+
+  /**
+   * @brief Handles a control command.
+   */
+  static void
+  handleCommand(shared_ptr<ControlCommand> command,
+                const ControlCommandHandler& handler,
+                const Name& prefix, const Interest& interest,
+                const ndn::mgmt::ControlParameters& params,
+                ndn::mgmt::CommandContinuation done);
+
+  /**
+   * @brief Generates the relative prefix for a handler by appending the verb name to the module name.
+   *
+   * @param verb the verb name
+   * @return the generated relative prefix
+   */
+  PartialName
+  makeRelPrefix(const std::string& verb)
+  {
+    return PartialName(m_module).append(verb);
+  }
+
+private:
+  std::string m_module;
+  Dispatcher& m_dispatcher;
+  CommandAuthenticator* m_authenticator = nullptr;
+};
+
+template<typename Command>
+inline void
+ManagerBase::registerCommandHandler(const std::string& verb,
+                                    const ControlCommandHandler& handler)
+{
+  auto command = make_shared<Command>();
+
+  m_dispatcher.addControlCommand<ControlParameters>(
+    makeRelPrefix(verb),
+    makeAuthorization(verb),
+    bind(&ManagerBase::validateParameters, std::cref(*command), _1),
+    bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
+}
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP
diff --git a/daemon/mgmt/nfd-manager-base.cpp b/daemon/mgmt/nfd-manager-base.cpp
deleted file mode 100644
index b417934..0000000
--- a/daemon/mgmt/nfd-manager-base.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- 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 "nfd-manager-base.hpp"
-
-namespace nfd {
-
-NfdManagerBase::NfdManagerBase(Dispatcher& dispatcher,
-                               CommandAuthenticator& authenticator,
-                               const std::string& module)
-  : ManagerBase(dispatcher, module)
-  , m_authenticator(authenticator)
-{
-}
-
-ndn::mgmt::Authorization
-NfdManagerBase::makeAuthorization(const std::string& verb)
-{
-  return m_authenticator.makeAuthorization(this->getModule(), verb);
-}
-
-} // namespace nfd
diff --git a/daemon/mgmt/nfd-manager-base.hpp b/daemon/mgmt/nfd-manager-base.hpp
deleted file mode 100644
index 27c3392..0000000
--- a/daemon/mgmt/nfd-manager-base.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- 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/>.
- */
-
-#ifndef NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
-#define NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
-
-#include "core/manager-base.hpp"
-#include "command-authenticator.hpp"
-
-namespace nfd {
-
-using ndn::mgmt::Dispatcher;
-using ndn::nfd::ControlParameters;
-
-/**
- * @brief a collection of common functions shared by all NFD managers,
- *        such as communicating with the dispatcher and command validator.
- */
-class NfdManagerBase : public ManagerBase
-{
-public:
-  NfdManagerBase(Dispatcher& dispatcher,
-                 CommandAuthenticator& authenticator,
-                 const std::string& module);
-
-PUBLIC_WITH_TESTS_ELSE_PRIVATE: // command validation
-  virtual ndn::mgmt::Authorization
-  makeAuthorization(const std::string& verb) override;
-
-private:
-  CommandAuthenticator& m_authenticator;
-};
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
index 0a73db2..1532627 100644
--- a/daemon/mgmt/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -27,11 +27,9 @@
 
 #include "core/fib-max-depth.hpp"
 #include "core/logger.hpp"
+#include "rib/rib.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
-#include <ndn-cxx/mgmt/nfd/control-command.hpp>
-#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
-#include <ndn-cxx/mgmt/nfd/control-response.hpp>
 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
 
@@ -51,7 +49,7 @@
 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)
+  : ManagerBase(MGMT_MODULE_NAME, dispatcher)
   , m_rib(rib)
   , m_keyChain(keyChain)
   , m_nfdController(nfdController)
diff --git a/daemon/mgmt/rib-manager.hpp b/daemon/mgmt/rib-manager.hpp
index 876ed75..745cfa2 100644
--- a/daemon/mgmt/rib-manager.hpp
+++ b/daemon/mgmt/rib-manager.hpp
@@ -26,9 +26,9 @@
 #ifndef NFD_DAEMON_MGMT_RIB_MANAGER_HPP
 #define NFD_DAEMON_MGMT_RIB_MANAGER_HPP
 
+#include "manager-base.hpp"
 #include "core/config-file.hpp"
-#include "core/manager-base.hpp"
-#include "rib/rib.hpp"
+#include "rib/route.hpp"
 
 #include <ndn-cxx/mgmt/nfd/controller.hpp>
 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
@@ -38,19 +38,18 @@
 
 namespace nfd {
 
+namespace rib {
+class Rib;
+class RibUpdate;
+} // namespace rib
+
 /**
- * @brief Serve commands and datasets of NFD RIB management protocol.
+ * @brief Implements the RIB Management of NFD Management Protocol.
  * @sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt
  */
 class RibManager : public ManagerBase
 {
 public:
-  class Error : public std::runtime_error
-  {
-  public:
-    using std::runtime_error::runtime_error;
-  };
-
   RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
              ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
              ndn::util::Scheduler& scheduler);
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 8f7cef0..bebe1a0 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.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,
@@ -37,7 +37,7 @@
 StrategyChoiceManager::StrategyChoiceManager(StrategyChoice& strategyChoice,
                                              Dispatcher& dispatcher,
                                              CommandAuthenticator& authenticator)
-  : NfdManagerBase(dispatcher, authenticator, "strategy-choice")
+  : ManagerBase("strategy-choice", dispatcher, authenticator)
   , m_table(strategyChoice)
 {
   registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>("set",
diff --git a/daemon/mgmt/strategy-choice-manager.hpp b/daemon/mgmt/strategy-choice-manager.hpp
index 00d4dd9..370364b 100644
--- a/daemon/mgmt/strategy-choice-manager.hpp
+++ b/daemon/mgmt/strategy-choice-manager.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
 #ifndef NFD_DAEMON_MGMT_STRATEGY_CHOICE_MANAGER_HPP
 #define NFD_DAEMON_MGMT_STRATEGY_CHOICE_MANAGER_HPP
 
-#include "nfd-manager-base.hpp"
+#include "manager-base.hpp"
 
 namespace nfd {
 
@@ -35,15 +35,14 @@
 } // namespace strategy_choice
 
 /**
- * @brief implement the Strategy Choice Management of NFD Management Protocol.
- * @sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice
+ * @brief Implements the Strategy Choice Management of NFD Management Protocol.
+ * @sa https://redmine.named-data.net/projects/nfd/wiki/StrategyChoice
  */
-class StrategyChoiceManager : public NfdManagerBase
+class StrategyChoiceManager : public ManagerBase
 {
 public:
   StrategyChoiceManager(strategy_choice::StrategyChoice& table,
-                        Dispatcher& dispatcher,
-                        CommandAuthenticator& authenticator);
+                        Dispatcher& dispatcher, CommandAuthenticator& authenticator);
 
 private:
   void