nfdc: strategy-choice

Change-Id: I806ed8296b6cc3be4a142ac2b5e08629930614a2
refs: #1312
diff --git a/tools/nfdc.cpp b/tools/nfdc.cpp
index 2f2937f..285bd9d 100644
--- a/tools/nfdc.cpp
+++ b/tools/nfdc.cpp
@@ -20,14 +20,16 @@
   "           Add a nexthop to a FIB entry\n"
   "       remove-nexthop <name> <faceId> \n"
   "           Remove a nexthop from a FIB entry\n"
-  "       set-strategy <name> <stratgy>\n"
-  "           Set a forwarding strategy for a namespace\n"
   "       create <uri> \n"
   "           Create a face in one of the following formats:\n"
   "           UDP unicast:    udp[4|6]://<remote-IP-or-host>[:<remote-port>]\n"
   "           TCP:            tcp[4|6]://<remote-IP-or-host>[:<remote-port>] \n"
   "       destroy <faceId> \n"
   "           Destroy a face\n"
+  "       set-strategy <name> <strategy> \n"
+  "           Set the strategy for a namespace \n"
+  "       unset-strategy <name> \n"
+  "           Unset the strategy for a namespace \n"
   << std::endl;
 }
 
@@ -57,11 +59,6 @@
       return false;
     fibRemoveNextHop(commandOptions);
   }
-  else if (command == "set-strategy") {
-    if (nOptions != 2)
-      return false;
-    fibSetStrategy(commandOptions);
-  }
   else if (command == "create") {
     if (nOptions != 1)
       return false;
@@ -72,6 +69,16 @@
       return false;
     faceDestroy(commandOptions);
   }
+  else if (command == "set-strategy") {
+    if (nOptions != 2)
+      return false;
+    strategyChoiceSet(commandOptions);
+  }
+  else if (command == "unset-strategy") {
+    if (nOptions != 1)
+      return false;
+    strategyChoiceUnset(commandOptions);
+  }
   else
     usage(m_programName);
 
@@ -114,23 +121,6 @@
                   bind(&Controller::onFibSuccess, this, _1, "Nexthop Removal succeeded"),
                   bind(&Controller::onError, this, _1, "Nexthop Removal failed"));
 }
-  
-void
-Controller::fibSetStrategy(const char* commandOptions[])
-{
-  const std::string& name = commandOptions[0];
-  const std::string& strategy = commandOptions[1];
-  ndn::nfd::FibManagementOptions fibOptions;
-  
-  fibOptions.setName(name);
-  fibOptions.setStrategy(strategy);
-  
-  startFibCommand("set-strategy",
-                  fibOptions,
-                  bind(&Controller::onFibSuccess,this, _1, "Successfully set forwarding strategy"),
-                  bind(&Controller::onError,this, _1, "Failed to set forwarding strategy"));
-
-}
 
 namespace {
 bool
@@ -173,17 +163,59 @@
                    bind(&Controller::onFaceSuccess, this, _1, "Face destroy succeeded"),
                    bind(&Controller::onError, this, _1, "Face destroy failed"));
 }
-
+  
+void
+Controller::strategyChoiceSet(const char* commandOptions[])
+{
+  const std::string& name = commandOptions[0];
+  const std::string& strategy = commandOptions[1];
+  ndn::nfd::StrategyChoiceOptions strategyChoiceOptions;
+  
+  strategyChoiceOptions.setName(name);
+  strategyChoiceOptions.setStrategy(strategy);
+  
+  startStrategyChoiceCommand("set",
+                             strategyChoiceOptions,
+                             bind(&Controller::onSetStrategySuccess,
+                                  this,
+                                  _1,
+                                  "Successfully set strategy choice"),
+                             bind(&Controller::onError, this, _1, "Failed to set strategy choice"));
+  
+}
+  
+void
+Controller::strategyChoiceUnset(const char* commandOptions[])
+{
+  const std::string& name = commandOptions[0];
+  ndn::nfd::StrategyChoiceOptions strategyChoiceOptions;
+  
+  strategyChoiceOptions.setName(name);
+  startStrategyChoiceCommand("unset",
+                             strategyChoiceOptions,
+                             bind(&Controller::onSetStrategySuccess,
+                                  this,
+                                  _1,
+                                  "Successfully unset strategy choice"),
+                             bind(&Controller::onError, this, _1, "Failed to unset strategy choice"));
+}
+  
 void
 Controller::onFibSuccess(const ndn::nfd::FibManagementOptions& resp, const std::string& message)
 {
-  std::cout << resp << std::endl;
+  std::cout << message << ": " << resp << std::endl;
 }
   
 void
 Controller::onFaceSuccess(const ndn::nfd::FaceManagementOptions& resp, const std::string& message)
 {
-  std::cout << resp << std::endl;
+  std::cout << message << ": " << resp << std::endl;
+}
+void
+Controller::onSetStrategySuccess(const ndn::nfd::StrategyChoiceOptions& resp,
+                                 const std::string& message)
+{
+  std::cout << message << ": " << resp << std::endl;
 }
   
 void
@@ -191,7 +223,7 @@
 {
   throw Error(message + ": " + error);
 }
-}// namespace nfdc
+} // namespace nfdc
 
 int
 main(int argc, char** argv)
diff --git a/tools/nfdc.hpp b/tools/nfdc.hpp
index 8786a39..fa131fb 100644
--- a/tools/nfdc.hpp
+++ b/tools/nfdc.hpp
@@ -12,6 +12,7 @@
 #include <ndn-cpp-dev/management/nfd-controller.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-strategy-choice-options.hpp>
 #include <vector>
 
 namespace nfdc {
@@ -56,20 +57,7 @@
    * @param cmdOptions          delNext command without leading 'remove-nexthop' component
    */
   void
-  fibRemoveNextHop(const char* cmdOptions[]);
-  /**
-   * \brief Sets a forwarding strategy for a namespace
-   *
-   * This command sets a forwarding strategy for a namespace.
-   *
-   * cmd format:
-   *   name strategy
-   *
-   * @param cmdOptions          setStrategy command without leading 'setStrategy' component
-   */
-  void
-  fibSetStrategy(const char* cmdOptions[]);
-  
+  fibRemoveNextHop(const char* cmdOptions[]);  
   /**
    * \brief create new face
    *
@@ -92,22 +80,49 @@
    */
   void
   faceDestroy(const char* cmdOptions[]);
-
+  /**
+   * \brief Set the strategy for a namespace
+   *
+   *
+   * cmd format:
+   *   name strategy
+   *
+   * @param cmdOptions          Set command without leading 'Unset' component
+   */
+  void
+  strategyChoiceSet(const char* cmdOptions[]);
+  /**
+   * \brief Unset the strategy for a namespace
+   *
+   *
+   * cmd format:
+   *   name strategy
+   *
+   * @param cmdOptions          Unset command without leading 'Unset' component
+   */
+  void
+  strategyChoiceUnset(const char* cmdOptions[]);
+  
 private:
   void
-  onFibSuccess(const ndn::nfd::FibManagementOptions& fibOptions, const std::string& message);
+  onFibSuccess(const ndn::nfd::FibManagementOptions& fibOptions,
+               const std::string& message);
 
   void
-  onFaceSuccess(const ndn::nfd::FaceManagementOptions& faceOptions, const std::string& message);
+  onFaceSuccess(const ndn::nfd::FaceManagementOptions& faceOptions,
+                const std::string& message);
   
   void
+  onSetStrategySuccess(const ndn::nfd::StrategyChoiceOptions& resp,
+                       const std::string& message);
+  void
   onError(const std::string& error, const std::string& message);
   
 public:
   const char* m_programName;
 };
 
-}// namespace nfdc
+} // namespace nfdc
 
 #endif // NFD_TOOLS_NFDC_HPP