tools: add 'nfdc cs config' command

refs #4050

Change-Id: Ifc49b78a286b1947452d3d7917b5937b95d1bfe5
diff --git a/tools/nfdc/available-commands.cpp b/tools/nfdc/available-commands.cpp
index fca0745..5be4854 100644
--- a/tools/nfdc/available-commands.cpp
+++ b/tools/nfdc/available-commands.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "available-commands.hpp"
+#include "cs-module.hpp"
 #include "face-module.hpp"
 #include "rib-module.hpp"
 #include "status.hpp"
@@ -39,6 +40,7 @@
   registerStatusCommands(parser);
   FaceModule::registerCommands(parser);
   RibModule::registerCommands(parser);
+  CsModule::registerCommands(parser);
   StrategyChoiceModule::registerCommands(parser);
 }
 
diff --git a/tools/nfdc/cs-module.cpp b/tools/nfdc/cs-module.cpp
index 975fd99..9d28855 100644
--- a/tools/nfdc/cs-module.cpp
+++ b/tools/nfdc/cs-module.cpp
@@ -31,6 +31,53 @@
 namespace nfdc {
 
 void
+CsModule::registerCommands(CommandParser& parser)
+{
+  CommandDefinition defCsConfig("cs", "config");
+  defCsConfig
+    .setTitle("change CS configuration")
+    .addArg("capacity", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
+    .addArg("admit", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
+    .addArg("serve", ArgValueType::BOOLEAN, Required::NO, Positional::NO);
+  parser.addCommand(defCsConfig, &CsModule::config);
+}
+
+void
+CsModule::config(ExecuteContext& ctx)
+{
+  using boost::logic::indeterminate;
+
+  auto capacity = ctx.args.getOptional<uint64_t>("capacity");
+  auto enableAdmit = ctx.args.getTribool("admit");
+  auto enableServe = ctx.args.getTribool("serve");
+
+  ControlParameters p;
+  if (capacity) {
+    p.setCapacity(*capacity);
+  }
+  if (!indeterminate(enableAdmit)) {
+    p.setFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT, enableAdmit);
+  }
+  if (!indeterminate(enableServe)) {
+    p.setFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE, enableServe);
+  }
+
+  ctx.controller.start<ndn::nfd::CsConfigCommand>(p,
+    [&] (const ControlParameters& resp) {
+      text::ItemAttributes ia;
+      ctx.out << "cs-config-updated "
+              << ia("capacity") << resp.getCapacity()
+              << ia("admit") << text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT)}
+              << ia("serve") << text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE)}
+              << '\n';
+    },
+    ctx.makeCommandFailureHandler("updating CS config"),
+    ctx.makeCommandOptions());
+
+  ctx.face.processEvents();
+}
+
+void
 CsModule::fetchStatus(Controller& controller,
                       const function<void()>& onSuccess,
                       const Controller::DatasetFailCallback& onFailure,
diff --git a/tools/nfdc/cs-module.hpp b/tools/nfdc/cs-module.hpp
index 143b3e4..7634d3d 100644
--- a/tools/nfdc/cs-module.hpp
+++ b/tools/nfdc/cs-module.hpp
@@ -26,6 +26,7 @@
 #ifndef NFD_TOOLS_NFDC_CS_MODULE_HPP
 #define NFD_TOOLS_NFDC_CS_MODULE_HPP
 
+#include "command-parser.hpp"
 #include "module.hpp"
 
 namespace nfd {
@@ -40,6 +41,16 @@
 class CsModule : public Module, noncopyable
 {
 public:
+  /** \brief register 'cs config' command
+   */
+  static void
+  registerCommands(CommandParser& parser);
+
+  /** \brief the 'cs config' command
+   */
+  static void
+  config(ExecuteContext& ctx);
+
   void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,