mgmt: declare cs/config command

refs #4050

Change-Id: I779d425d0ca89750cf923c84009c19b37eecc9cf
diff --git a/src/mgmt/nfd/control-command.cpp b/src/mgmt/nfd/control-command.cpp
index 5ecf975..f85c870 100644
--- a/src/mgmt/nfd/control-command.cpp
+++ b/src/mgmt/nfd/control-command.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -88,6 +88,12 @@
       BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but present"));
     }
   }
+
+  if (m_optional[CONTROL_PARAMETER_FLAGS] && m_optional[CONTROL_PARAMETER_MASK]) {
+    if (parameters.hasFlags() != parameters.hasMask()) {
+      BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
+    }
+  }
 }
 
 FaceCreateCommand::FaceCreateCommand()
@@ -116,16 +122,6 @@
 }
 
 void
-FaceCreateCommand::validateRequest(const ControlParameters& parameters) const
-{
-  this->ControlCommand::validateRequest(parameters);
-
-  if (parameters.hasFlags() != parameters.hasMask()) {
-    BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
-  }
-}
-
-void
 FaceCreateCommand::validateResponse(const ControlParameters& parameters) const
 {
   this->ControlCommand::validateResponse(parameters);
@@ -158,16 +154,6 @@
 }
 
 void
-FaceUpdateCommand::validateRequest(const ControlParameters& parameters) const
-{
-  this->ControlCommand::validateRequest(parameters);
-
-  if (parameters.hasFlags() != parameters.hasMask()) {
-    BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
-  }
-}
-
-void
 FaceUpdateCommand::validateResponse(const ControlParameters& parameters) const
 {
   this->ControlCommand::validateResponse(parameters);
@@ -264,6 +250,18 @@
   }
 }
 
+CsConfigCommand::CsConfigCommand()
+  : ControlCommand("cs", "config")
+{
+  m_requestValidator
+    .optional(CONTROL_PARAMETER_CAPACITY)
+    .optional(CONTROL_PARAMETER_FLAGS)
+    .optional(CONTROL_PARAMETER_MASK);
+  m_responseValidator
+    .required(CONTROL_PARAMETER_CAPACITY)
+    .required(CONTROL_PARAMETER_FLAGS);
+}
+
 StrategyChoiceSetCommand::StrategyChoiceSetCommand()
   : ControlCommand("strategy-choice", "set")
 {
diff --git a/src/mgmt/nfd/control-command.hpp b/src/mgmt/nfd/control-command.hpp
index 97b0fa8..74f0bb1 100644
--- a/src/mgmt/nfd/control-command.hpp
+++ b/src/mgmt/nfd/control-command.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -148,9 +148,6 @@
   applyDefaultsToRequest(ControlParameters& parameters) const override;
 
   void
-  validateRequest(const ControlParameters& parameters) const override;
-
-  void
   validateResponse(const ControlParameters& parameters) const override;
 };
 
@@ -168,9 +165,6 @@
   void
   applyDefaultsToRequest(ControlParameters& parameters) const override;
 
-  void
-  validateRequest(const ControlParameters& parameters) const override;
-
   /**
    * \note This can only validate ControlParameters in a success response.
    *       Failure responses should be validated with validateRequest.
@@ -236,6 +230,18 @@
 
 /**
  * \ingroup management
+ * \brief represents a cs/config command
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/CsMgmt#Update-config
+ */
+class CsConfigCommand : public ControlCommand
+{
+public:
+  CsConfigCommand();
+};
+
+
+/**
+ * \ingroup management
  * \brief represents a strategy-choice/set command
  * \sa https://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
  */
diff --git a/src/mgmt/nfd/control-parameters.cpp b/src/mgmt/nfd/control-parameters.cpp
index 61fb823..a98e807 100644
--- a/src/mgmt/nfd/control-parameters.cpp
+++ b/src/mgmt/nfd/control-parameters.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -68,6 +68,9 @@
   if (this->hasFlags()) {
     totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
   }
+  if (this->hasCapacity()) {
+    totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Capacity, m_capacity);
+  }
   if (this->hasCost()) {
     totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Cost, m_cost);
   }
@@ -156,6 +159,12 @@
     m_cost = readNonNegativeInteger(*val);
   }
 
+  val = m_wire.find(tlv::nfd::Capacity);
+  m_hasFields[CONTROL_PARAMETER_CAPACITY] = val != m_wire.elements_end();
+  if (this->hasCapacity()) {
+    m_capacity = readNonNegativeInteger(*val);
+  }
+
   val = m_wire.find(tlv::nfd::Flags);
   m_hasFields[CONTROL_PARAMETER_FLAGS] = val != m_wire.elements_end();
   if (this->hasFlags()) {
@@ -295,6 +304,10 @@
     os << "Cost: " << parameters.getCost() << ", ";
   }
 
+  if (parameters.hasCapacity()) {
+    os << "Capacity: " << parameters.getCapacity() << ", ";
+  }
+
   if (parameters.hasFlags()) {
     os << "Flags: " << AsHex{parameters.getFlags()} << ", ";
   }
diff --git a/src/mgmt/nfd/control-parameters.hpp b/src/mgmt/nfd/control-parameters.hpp
index 791813f..79b84e0 100644
--- a/src/mgmt/nfd/control-parameters.hpp
+++ b/src/mgmt/nfd/control-parameters.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -40,6 +40,7 @@
   CONTROL_PARAMETER_LOCAL_URI,
   CONTROL_PARAMETER_ORIGIN,
   CONTROL_PARAMETER_COST,
+  CONTROL_PARAMETER_CAPACITY,
   CONTROL_PARAMETER_FLAGS,
   CONTROL_PARAMETER_MASK,
   CONTROL_PARAMETER_STRATEGY,
@@ -55,6 +56,7 @@
   "LocalUri",
   "Origin",
   "Cost",
+  "Capacity",
   "Flags",
   "Mask",
   "Strategy",
@@ -278,6 +280,36 @@
   }
 
   bool
+  hasCapacity() const
+  {
+    return m_hasFields[CONTROL_PARAMETER_CAPACITY];
+  }
+
+  uint64_t
+  getCapacity() const
+  {
+    BOOST_ASSERT(this->hasCapacity());
+    return m_capacity;
+  }
+
+  ControlParameters&
+  setCapacity(uint64_t capacity)
+  {
+    m_wire.reset();
+    m_capacity = capacity;
+    m_hasFields[CONTROL_PARAMETER_CAPACITY] = true;
+    return *this;
+  }
+
+  ControlParameters&
+  unsetCapacity()
+  {
+    m_wire.reset();
+    m_hasFields[CONTROL_PARAMETER_CAPACITY] = false;
+    return *this;
+  }
+
+  bool
   hasFlags() const
   {
     return m_hasFields[CONTROL_PARAMETER_FLAGS];
@@ -474,6 +506,7 @@
   std::string         m_localUri;
   RouteOrigin         m_origin;
   uint64_t            m_cost;
+  uint64_t            m_capacity;
   uint64_t            m_flags;
   uint64_t            m_mask;
   Name                m_strategy;