face: drop direct FIB management

refs #2533

Change-Id: I33c1c8873498048970f7a485be9f6e021b286c8b
diff --git a/client.conf.sample b/client.conf.sample
index de8012e..abed4ff 100644
--- a/client.conf.sample
+++ b/client.conf.sample
@@ -9,12 +9,6 @@
 
 transport=unix:///var/run/nfd.sock
 
-; "protocol" determines the protocol for prefix registration
-; it has a value of:
-;   nfd-0.1
-;   nrd-0.1
-protocol=nrd-0.1
-
 ; "pib" determines which Public Info Base (PIB) should used by default in applications.
 ; If "pib" is not specified, the default PIB will be used.
 ; Note that default PIB could be different on different system.
diff --git a/src/detail/face-impl.hpp b/src/detail/face-impl.hpp
index c13906a..cb5b3bc 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -196,40 +196,17 @@
   {
     using namespace nfd;
 
-    typedef void (Controller::*Registrator)
-      (const ControlParameters&,
-       const Controller::CommandSucceedCallback&,
-       const Controller::CommandFailCallback&,
-       const CommandOptions&);
+    ControlParameters params;
+    params.setName(prefix);
+    params.setFlags(flags);
 
-    ControlParameters registerParameters, unregisterParameters;
-    registerParameters.setName(prefix);
-    unregisterParameters.setName(prefix);
+    auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options);
 
-    Registrator registrator, unregistrator;
-    if (!m_face.m_isDirectNfdFibManagementRequested) {
-      registrator = static_cast<Registrator>(&Controller::start<RibRegisterCommand>);
-      unregistrator = static_cast<Registrator>(&Controller::start<RibUnregisterCommand>);
-
-      registerParameters.setFlags(flags);
-    }
-    else {
-      registrator = static_cast<Registrator>(&Controller::start<FibAddNextHopCommand>);
-      unregistrator = static_cast<Registrator>(&Controller::start<FibRemoveNextHopCommand>);
-    }
-
-    RegisteredPrefix::Unregistrator boundUnregistrator =
-        bind(unregistrator, m_face.m_nfdController.get(), unregisterParameters, _1, _2,
-                  options);
-
-    shared_ptr<RegisteredPrefix> prefixToRegister =
-      make_shared<RegisteredPrefix>(prefix, filter, boundUnregistrator);
-
-    ((*m_face.m_nfdController).*registrator)(registerParameters,
-                                             bind(&Impl::afterPrefixRegistered, this,
-                                                  prefixToRegister, onSuccess),
-                                             bind(onFailure, prefixToRegister->getPrefix(), _2),
-                                             options);
+    m_face.m_nfdController->start<RibRegisterCommand>(params,
+                                                      bind(&Impl::afterPrefixRegistered, this,
+                                                           prefixToRegister, onSuccess),
+                                                      bind(onFailure, prefixToRegister->getPrefix(), _2),
+                                                      options);
 
     return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get());
   }
@@ -255,22 +232,29 @@
                         const UnregisterPrefixSuccessCallback& onSuccess,
                         const UnregisterPrefixFailureCallback& onFailure)
   {
-    RegisteredPrefixTable::iterator i = std::find_if(m_registeredPrefixTable.begin(),
-                                                     m_registeredPrefixTable.end(),
-                                                     MatchRegisteredPrefixId(registeredPrefixId));
-    if (i != m_registeredPrefixTable.end())
-      {
-        const shared_ptr<InterestFilterRecord>& filter = (*i)->getFilter();
-        if (static_cast<bool>(filter))
-          {
-            // it was a combined operation
-            m_interestFilterTable.remove(filter);
-          }
-        (*i)->unregister(bind(&Impl::finalizeUnregisterPrefix, this, i, onSuccess),
-                         bind(onFailure, _2));
+    using namespace nfd;
+    auto i = std::find_if(m_registeredPrefixTable.begin(),
+                          m_registeredPrefixTable.end(),
+                          MatchRegisteredPrefixId(registeredPrefixId));
+    if (i != m_registeredPrefixTable.end()) {
+      RegisteredPrefix& record = **i;
+
+      const shared_ptr<InterestFilterRecord>& filter = record.getFilter();
+
+      if (filter != nullptr) {
+        // it was a combined operation
+        m_interestFilterTable.remove(filter);
       }
+
+      ControlParameters params;
+      params.setName(record.getPrefix());
+      m_face.m_nfdController->start<RibUnregisterCommand>(params,
+                                                          bind(&Impl::finalizeUnregisterPrefix, this, i, onSuccess),
+                                                          bind(onFailure, _2),
+                                                          record.getCommandOptions());
+    }
     else {
-      if (static_cast<bool>(onFailure)) {
+      if (onFailure != nullptr) {
         onFailure("Unrecognized PrefixId");
       }
     }
diff --git a/src/detail/registered-prefix.hpp b/src/detail/registered-prefix.hpp
index cfa3983..6e9beb4 100644
--- a/src/detail/registered-prefix.hpp
+++ b/src/detail/registered-prefix.hpp
@@ -27,13 +27,11 @@
 #include "../interest.hpp"
 
 #include "interest-filter-record.hpp"
+#include "management/nfd-command-options.hpp"
+#include "management/nfd-control-parameters.hpp"
 
 namespace ndn {
 
-namespace nfd {
-class ControlParameters;
-}
-
 class RegisteredPrefix : noncopyable
 {
 public:
@@ -45,23 +43,12 @@
    */
   typedef function<void(uint32_t/*code*/,const std::string&/*reason*/)> FailureCallback;
 
-  /// @brief Function that should be called to unregister prefix
-  typedef function<void(const SuccessCallback& onSuccess,
-                        const FailureCallback& onFailure)> Unregistrator;
-
-  RegisteredPrefix(const Name& prefix,
-                   const Unregistrator& unregistrator)
-    : m_prefix(prefix)
-    , m_unregistrator(unregistrator)
-  {
-  }
-
   RegisteredPrefix(const Name& prefix,
                    const shared_ptr<InterestFilterRecord>& filter,
-                   const Unregistrator& unregistrator)
+                   const nfd::CommandOptions& options)
     : m_prefix(prefix)
     , m_filter(filter)
-    , m_unregistrator(unregistrator)
+    , m_options(options)
   {
   }
 
@@ -77,19 +64,16 @@
     return m_filter;
   }
 
-  void
-  unregister(const SuccessCallback& onSuccess,
-             const FailureCallback& onFailure)
+  const nfd::CommandOptions&
+  getCommandOptions() const
   {
-    if (static_cast<bool>(m_unregistrator)) {
-      m_unregistrator(onSuccess, onFailure);
-    }
+    return m_options;
   }
 
 private:
   Name m_prefix;
   shared_ptr<InterestFilterRecord> m_filter;
-  Unregistrator m_unregistrator;
+  nfd::CommandOptions m_options;
 };
 
 /**
diff --git a/src/face.cpp b/src/face.cpp
index b36f955..3722fda 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -36,7 +36,6 @@
   : m_internalIoService(new boost::asio::io_service())
   , m_ioService(*m_internalIoService)
   , m_internalKeyChain(new KeyChain())
-  , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
   construct(*m_internalKeyChain);
@@ -45,7 +44,6 @@
 Face::Face(boost::asio::io_service& ioService)
   : m_ioService(ioService)
   , m_internalKeyChain(new KeyChain())
-  , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
   construct(*m_internalKeyChain);
@@ -64,7 +62,6 @@
   : m_internalIoService(new boost::asio::io_service())
   , m_ioService(*m_internalIoService)
   , m_internalKeyChain(new KeyChain())
-  , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
   construct(transport, *m_internalKeyChain);
@@ -74,7 +71,6 @@
            boost::asio::io_service& ioService)
   : m_ioService(ioService)
   , m_internalKeyChain(new KeyChain())
-  , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
   construct(transport, *m_internalKeyChain);
@@ -85,7 +81,6 @@
            KeyChain& keyChain)
   : m_ioService(ioService)
   , m_internalKeyChain(nullptr)
-  , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
   construct(transport, keyChain);
@@ -145,34 +140,6 @@
   m_impl->m_pitTimeoutCheckTimer      = make_shared<monotonic_deadline_timer>(ref(m_ioService));
   m_impl->m_processEventsTimeoutTimer = make_shared<monotonic_deadline_timer>(ref(m_ioService));
   m_impl->ensureConnected(false);
-
-  std::string protocol = "nrd-0.1";
-
-  try
-    {
-      protocol = m_impl->m_config.getParsedConfiguration().get<std::string>("protocol");
-    }
-  catch (boost::property_tree::ptree_bad_path& error)
-    {
-      // protocol not specified
-    }
-  catch (boost::property_tree::ptree_bad_data& error)
-    {
-      throw ConfigFile::Error(error.what());
-    }
-
-  if (isSupportedNrdProtocol(protocol))
-    {
-      // do nothing
-    }
-  else if (isSupportedNfdProtocol(protocol))
-    {
-      m_isDirectNfdFibManagementRequested = true;
-    }
-  else
-    {
-      throw Face::Error("Cannot create controller for unsupported protocol \"" + protocol + "\"");
-    }
 }
 
 Face::~Face() = default;
diff --git a/src/face.hpp b/src/face.hpp
index d7399e8..47e841e 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -247,7 +247,7 @@
    * @param onInterest     A callback to be called when a matching interest is received
    * @param onSuccess      A callback to be called when prefixRegister command succeeds
    * @param onFailure      A callback to be called when prefixRegister command fails
-   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags          (optional) RIB flags
    * @param certificate    (optional) A certificate under which the prefix registration
    *                       command is signed.  When omitted, a default certificate of
    *                       the default identity is used to sign the registration command
@@ -280,7 +280,7 @@
    * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
    * @param onInterest     A callback to be called when a matching interest is received
    * @param onFailure      A callback to be called when prefixRegister command fails
-   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags          (optional) RIB flags
    * @param certificate    (optional) A certificate under which the prefix registration
    *                       command is signed.  When omitted, a default certificate of
    *                       the default identity is used to sign the registration command
@@ -315,7 +315,7 @@
    * @param onFailure      A callback to be called when prefixRegister command fails
    * @param identity       A signing identity. A prefix registration command is signed
    *                       under the default certificate of this identity
-   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags          (optional) RIB flags
    *
    * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
    */
@@ -342,7 +342,7 @@
    * @param onFailure      A callback to be called when prefixRegister command fails
    * @param identity       A signing identity. A prefix registration command is signed
    *                       under the default certificate of this identity
-   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags          (optional) RIB flags
    *
    * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
    */
@@ -373,7 +373,7 @@
   /**
    * @brief Register prefix with the connected NDN forwarder
    *
-   * This method only modifies forwarder's RIB (or FIB) and does not associate any
+   * This method only modifies forwarder's RIB and does not associate any
    * onInterest callbacks.  Use setInterestFilter method to dispatch incoming Interests to
    * the right callbacks.
    *
@@ -383,7 +383,7 @@
    * @param certificate (optional) A certificate under which the prefix registration
    *                    command is signed.  When omitted, a default certificate of
    *                    the default identity is used to sign the registration command
-   * @param flags       (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags       (optional) RIB flags
    *
    * @return The registered prefix ID which can be used with unregisterPrefix
    *
@@ -402,7 +402,7 @@
    * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
    *        interest is received.
    *
-   * This method only modifies forwarder's RIB (or FIB) and does not associate any
+   * This method only modifies forwarder's RIB and does not associate any
    * onInterest callbacks.  Use setInterestFilter method to dispatch incoming Interests to
    * the right callbacks.
    *
@@ -411,7 +411,7 @@
    * @param onFailure A callback to be called when prefixRegister command fails
    * @param identity  A signing identity. A prefix registration command is signed
    *                  under the default certificate of this identity
-   * @param flags     (optional) RIB flags (not used when direct FIB management is requested)
+   * @param flags     (optional) RIB flags
    *
    * @return The registered prefix ID which can be used with unregisterPrefix
    */
@@ -449,7 +449,7 @@
   unsetInterestFilter(const InterestFilterId* interestFilterId);
 
   /**
-   * @brief Deregister prefix from RIB (or FIB)
+   * @brief Unregister prefix from RIB
    *
    * unregisterPrefix will use the same credentials as original
    * setInterestFilter/registerPrefix command
@@ -466,12 +466,6 @@
                    const UnregisterPrefixSuccessCallback& onSuccess,
                    const UnregisterPrefixFailureCallback& onFailure);
 
-  /**
-   * @brief (FOR DEBUG PURPOSES ONLY) Request direct NFD FIB management
-   */
-  void
-  setDirectFibManagement(bool isDirectFibManagementRequested = false);
-
    /**
    * @brief Publish data packet
    *
@@ -549,12 +543,6 @@
   void
   construct(shared_ptr<Transport> transport, KeyChain& keyChain);
 
-  bool
-  isSupportedNfdProtocol(const std::string& protocol);
-
-  bool
-  isSupportedNrdProtocol(const std::string& protocol);
-
   class ProcessEventsTimeout
   {
   };
@@ -585,30 +573,11 @@
   unique_ptr<KeyChain> m_internalKeyChain;
 
   unique_ptr<nfd::Controller> m_nfdController;
-  bool m_isDirectNfdFibManagementRequested;
 
   class Impl;
   unique_ptr<Impl> m_impl;
 };
 
-inline bool
-Face::isSupportedNfdProtocol(const std::string& protocol)
-{
-  return protocol == "nfd-0.1";
-}
-
-inline bool
-Face::isSupportedNrdProtocol(const std::string& protocol)
-{
-  return protocol == "nrd-0.1";
-}
-
-inline void
-Face::setDirectFibManagement(bool isDirectFibManagementRequested/* = false*/)
-{
-  m_isDirectNfdFibManagementRequested = isDirectFibManagementRequested;
-}
-
 } // namespace ndn
 
 #endif // NDN_FACE_HPP