management: nfdc support and link error fix

Static INVALID_FACE_ID constant was causing link error (multiple
definitions). Now it is defined just as a constant and moved to
the general-purpose NFD-related ``encoding/tlv-nfd.hpp`` header.

Change-Id: I04295fa07f809aae9a24a531e31facf09c78729f
refs: #1198
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index 584f62a..c7f3620 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -40,6 +40,13 @@
 
 } // namespace nfd
 } // namespace tlv
+
+namespace nfd {
+
+const uint64_t INVALID_FACE_ID = std::numeric_limits<uint64_t>::max();
+
+} // namespace nfd
+
 } // namespace ndn
 
 #endif // NDN_TLV_NFD_HPP
diff --git a/src/management/nfd-controller.cpp b/src/management/nfd-controller.cpp
index 00a5378..c6fa7e7 100644
--- a/src/management/nfd-controller.cpp
+++ b/src/management/nfd-controller.cpp
@@ -9,6 +9,7 @@
 
 #include "nfd-controller.hpp"
 #include "nfd-fib-management-options.hpp"
+#include "nfd-face-management-options.hpp"
 #include "nfd-control-response.hpp"
 
 namespace ndn {
@@ -45,7 +46,7 @@
         onFail("Face ID is not set, should have been set after a successful prefix registration command");
       return;
     }
-  
+
   startFibCommand("remove-nexthop",
                   FibManagementOptions()
                   .setName(prefixToRegister)
@@ -65,7 +66,7 @@
     .append(options.wireEncode());
 
   Interest fibCommandInterest(fibCommandInterestName);
-  m_keyChain.sign(fibCommandInterest);
+  // m_keyChain.sign(fibCommandInterest);
 
   m_face.expressInterest(fibCommandInterest,
                          bind(&Controller::processFibCommandResponse, this, _2,
@@ -81,11 +82,6 @@
   onSuccess();
 }
 
-// void
-// processFaceActionResponse(Data& data,
-//                           const FaceOperationSucceedCallback& onSuccess,
-//                           const FailCallback&    onFail);
-
 void
 Controller::processFibCommandResponse(Data& data,
                                       const FibCommandSucceedCallback& onSuccess,
@@ -94,7 +90,6 @@
   try
     {
       ControlResponse response(data.getContent().blockFromValue());
-
       if (response.getCode() != 200)
         return onFail(response.getText());
 
@@ -108,5 +103,45 @@
     }
 }
 
+void
+Controller::startFaceCommand(const std::string& command,
+                             const FaceManagementOptions& options,
+                             const FaceCommandSucceedCallback& onSuccess,
+                             const FailCallback& onFail)
+{
+  Name faceCommandInterestName("/localhost/nfd/faces");
+  faceCommandInterestName
+    .append(command)
+    .append(options.wireEncode());
+
+  Interest faceCommandInterest(faceCommandInterestName);
+  // m_keyChain.sign(fibCommandInterest);
+
+  m_face.expressInterest(faceCommandInterest,
+                         bind(&Controller::processFaceCommandResponse, this, _2,
+                              onSuccess, onFail),
+                         bind(onFail, "Command Interest timed out"));
+}
+
+void
+Controller::processFaceCommandResponse(Data& data,
+                                       const FaceCommandSucceedCallback& onSuccess,
+                                       const FailCallback& onFail)
+{
+  try
+    {
+      ControlResponse response(data.getContent().blockFromValue());
+      if (response.getCode() != 200)
+        return onFail(response.getText());
+
+      FaceManagementOptions options(response.getBody());
+      return onSuccess(options);
+    }
+  catch(ndn::Tlv::Error& e)
+    {
+      if (static_cast<bool>(onFail))
+        return onFail(e.what());
+    }
+}
 } // namespace nfd
 } // namespace ndn
diff --git a/src/management/nfd-controller.hpp b/src/management/nfd-controller.hpp
index aa788a9..850c72d 100644
--- a/src/management/nfd-controller.hpp
+++ b/src/management/nfd-controller.hpp
@@ -16,11 +16,13 @@
 namespace nfd {
 
 class FibManagementOptions;
+class FaceManagementOptions;
 
 class Controller : public ndn::Controller
 {
 public:
   typedef function<void(const FibManagementOptions&)> FibCommandSucceedCallback;
+  typedef function<void(const FaceManagementOptions&)> FaceCommandSucceedCallback;
 
   /**
    * @brief Construct ndnd::Control object
@@ -37,27 +39,35 @@
                        const SuccessCallback& onSuccess,
                        const FailCallback&    onFail);
 
+protected:
   void
   startFibCommand(const std::string& command,
                   const FibManagementOptions& options,
                   const FibCommandSucceedCallback& onSuccess,
                   const FailCallback& onFailure);
+
+  void
+  startFaceCommand(const std::string& command,
+                   const FaceManagementOptions& options,
+                   const FaceCommandSucceedCallback& onSuccess,
+                   const FailCallback& onFailure);
+
 private:
   void
   recordSelfRegisteredFaceId(const FibManagementOptions& entry,
                              const SuccessCallback& onSuccess);
 
-  // void
-  // processFaceActionResponse(Data& data,
-  //                           const FaceOperationSucceedCallback& onSuccess,
-  //                           const FailCallback&    onFail);
-
   void
   processFibCommandResponse(Data& data,
                             const FibCommandSucceedCallback& onSuccess,
                             const FailCallback& onFail);
-  
-private:
+
+  void
+  processFaceCommandResponse(Data& data,
+                             const FaceCommandSucceedCallback& onSuccess,
+                             const FailCallback& onFail);
+
+protected:
   Face& m_face;
   KeyChain m_keyChain;
   uint64_t m_faceId; // internal face ID (needed for prefix de-registration)
diff --git a/src/management/nfd-face-management-options.hpp b/src/management/nfd-face-management-options.hpp
index 7158352..802cde0 100644
--- a/src/management/nfd-face-management-options.hpp
+++ b/src/management/nfd-face-management-options.hpp
@@ -66,15 +66,12 @@
   wireDecode (const Block &wire);
   
 private:
-  static const uint64_t INVALID_FACE_ID;
-
   uint64_t m_faceId;
   std::string m_uri;
 
   mutable Block wire_;
 };
 
-const uint64_t FaceManagementOptions::INVALID_FACE_ID = std::numeric_limits<uint64_t>::max();
 
 template<bool T>
 inline size_t
diff --git a/src/management/nfd-local-control-header.hpp b/src/management/nfd-local-control-header.hpp
index 5ddc14b..e3bbe0c 100644
--- a/src/management/nfd-local-control-header.hpp
+++ b/src/management/nfd-local-control-header.hpp
@@ -13,8 +13,6 @@
 namespace ndn {
 namespace nfd {
 
-const uint64_t INVALID_FACE_ID = std::numeric_limits<uint64_t>::max();
-
 class LocalControlHeader
 {
 public: