nrd<->nfd: Update code to match new changes in NFD management protocol

Change-Id: I2d6f915cbd58beecc7af17a81a3ef8e995cb37c8
Refs: #1415
diff --git a/src/common.hpp b/src/common.hpp
index b09fc63..063b82f 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -14,8 +14,6 @@
 #include <ndn-cpp-dev/security/key-chain.hpp>
 #include <ndn-cpp-dev/util/scheduler.hpp>
 
-#include <ndn-cpp-dev/management/nfd-fib-management-options.hpp>
-#include <ndn-cpp-dev/management/nfd-face-management-options.hpp>
 #include <ndn-cpp-dev/management/nfd-controller.hpp>
 #include <ndn-cpp-dev/management/nfd-control-response.hpp>
 #include <ndn-cpp-dev/management/nrd-prefix-reg-options.hpp>
diff --git a/src/nrd.cpp b/src/nrd.cpp
index bad2265..403a32f 100644
--- a/src/nrd.cpp
+++ b/src/nrd.cpp
@@ -42,8 +42,8 @@
 }
 
 Nrd::Nrd()
-  : m_nfdController(new nfd::Controller(m_face)),
-    m_verbDispatch(COMMAND_VERBS,
+  : m_nfdController(new nfd::Controller(m_face))
+  , m_verbDispatch(COMMAND_VERBS,
                    COMMAND_VERBS + (sizeof(COMMAND_VERBS) / sizeof(VerbAndProcessor)))
 {
   //check whether the components of localhop and localhost prefixes are same
@@ -167,16 +167,27 @@
 }
 
 void
-Nrd::onCommandError(const std::string& error,
+Nrd::onCommandError(uint32_t code, const std::string& error,
                     const Interest& request,
                     const PrefixRegOptions& options)
 {
+  std::cout << "NFD Error: " << error << " (code: " << code << ")" << std::endl;
+
   nfd::ControlResponse response;
 
-  response.setCode(400);
-  response.setText(error);
+  if (code == 404)
+    {
+      response.setCode(code);
+      response.setText(error);
+    }
+  else
+    {
+      response.setCode(533);
+      std::ostringstream os;
+      os << "Failure to update NFD " << "(NFD Error: " << code << " " << error << ")";
+      response.setText(os.str());
+    }
 
-  std::cout << "Error: " << error << std::endl;
   sendResponse(request.getName(), response);
   m_managedRib.erase(options);
 }
@@ -220,20 +231,27 @@
   // Rib tree, then nrd will generate fib updates based on flags and then
   // will add next hops one by one..
   m_managedRib.insert(options);
-  m_nfdController->fibAddNextHop(options.getName(), options.getFaceId(),
-                                 options.getCost(),
-                                 bind(&Nrd::onRegSuccess, this, request, options),
-                                 bind(&Nrd::onCommandError, this, _1, request, options));
+  m_nfdController->start<nfd::FibAddNextHopCommand>(
+     nfd::ControlParameters()
+       .setName(options.getName())
+       .setFaceId(options.getFaceId())
+       .setCost(options.getCost()),
+     bind(&Nrd::onRegSuccess, this, request, options),
+     bind(&Nrd::onCommandError, this, _1, _2, request, options)
+  );
 }
 
 
 void
 Nrd::deleteEntry(const Interest& request, const PrefixRegOptions& options)
 {
-  m_nfdController->fibRemoveNextHop(options.getName(),
-                                    options.getFaceId(),
-                                    bind(&Nrd::onUnRegSuccess, this, request, options),
-                                    bind(&Nrd::onCommandError, this, _1, request, options));
+  m_nfdController->start<nfd::FibRemoveNextHopCommand>(
+     nfd::ControlParameters()
+       .setName(options.getName())
+       .setFaceId(options.getFaceId()),
+     bind(&Nrd::onUnRegSuccess, this, request, options),
+     bind(&Nrd::onCommandError, this, _1, _2, request, options)
+  );
 }
 
 
@@ -253,9 +271,10 @@
 
 
 void
-Nrd::onControlHeaderError()
+Nrd::onControlHeaderError(uint32_t code, const std::string& reason)
 {
-  std::cout << "Error: couldn't enable local control header" << std::endl;
+  std::cout << "Error: couldn't enable local control header "
+            << "(code: " << code << ", info: " << reason << ")" << std::endl;
   m_face.shutdown();
 }
 
@@ -263,13 +282,12 @@
 void
 Nrd::enableLocalControlHeader()
 {
-  Name enable("/localhost/nfd/control-header/in-faceid/enable");
-  Interest enableCommand(enable);
-
-  m_keyChain.sign(enableCommand);
-  m_face.expressInterest(enableCommand,
-                         ndn::bind(&Nrd::onControlHeaderSuccess, this),
-                         ndn::bind(&Nrd::onControlHeaderError, this));
+  m_nfdController->start<nfd::FaceEnableLocalControlCommand>(
+    nfd::ControlParameters()
+      .setLocalControlFeature(nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
+    bind(&Nrd::onControlHeaderSuccess, this),
+    bind(&Nrd::onControlHeaderError, this, _1, _2)
+  );
 }
 
 } // namespace nrd
diff --git a/src/nrd.hpp b/src/nrd.hpp
index 7e7ce08..7e1473e 100644
--- a/src/nrd.hpp
+++ b/src/nrd.hpp
@@ -36,10 +36,10 @@
                uint32_t code,
                const std::string& text);
   void
-  onCommandError(const std::string& error, 
-                 const ndn::Interest& interest, 
+  onCommandError(uint32_t code, const std::string& error,
+                 const ndn::Interest& interest,
                  const PrefixRegOptions& options);
- 
+
   void
   onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
 
@@ -50,11 +50,11 @@
   onControlHeaderSuccess();
 
   void
-  onControlHeaderError();
+  onControlHeaderError(uint32_t code, const std::string& reason);
 
   void
   setInterestFilterFailed(const Name& name, const std::string& msg);
-  
+
   void
   insertEntry(const Interest& request, const PrefixRegOptions& options);
 
@@ -99,4 +99,3 @@
 } // namespace ndn
 
 #endif // NRD_HPP
-