mgmt: implement cs/config command
refs #4050
Change-Id: I86b050ac062855bad66197a775a502007e687d8d
diff --git a/daemon/mgmt/cs-manager.cpp b/daemon/mgmt/cs-manager.cpp
index 62c0b8f..5c6c450 100644
--- a/daemon/mgmt/cs-manager.cpp
+++ b/daemon/mgmt/cs-manager.cpp
@@ -31,12 +31,41 @@
CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCnt,
Dispatcher& dispatcher, CommandAuthenticator& authenticator)
: NfdManagerBase(dispatcher, authenticator, "cs")
+ , m_cs(cs)
, m_fwCnt(fwCnt)
{
+ registerCommandHandler<ndn::nfd::CsConfigCommand>("config",
+ bind(&CsManager::changeConfig, this, _4, _5));
+
registerStatusDatasetHandler("info", bind(&CsManager::serveInfo, this, _1, _2, _3));
}
void
+CsManager::changeConfig(const ControlParameters& parameters,
+ const ndn::mgmt::CommandContinuation& done)
+{
+ using ndn::nfd::CsFlagBit;
+
+ if (parameters.hasCapacity()) {
+ m_cs.setLimit(parameters.getCapacity());
+ }
+
+ if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT)) {
+ m_cs.enableAdmit(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT));
+ }
+
+ if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE)) {
+ m_cs.enableServe(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE));
+ }
+
+ ControlParameters body;
+ body.setCapacity(m_cs.getLimit());
+ body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, m_cs.shouldAdmit(), false);
+ body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, m_cs.shouldServe(), false);
+ done(ControlResponse(200, "OK").setBody(body.wireEncode()));
+}
+
+void
CsManager::serveInfo(const Name& topPrefix, const Interest& interest,
ndn::mgmt::StatusDatasetContext& context) const
{
diff --git a/daemon/mgmt/cs-manager.hpp b/daemon/mgmt/cs-manager.hpp
index 800502d..6a862f1 100644
--- a/daemon/mgmt/cs-manager.hpp
+++ b/daemon/mgmt/cs-manager.hpp
@@ -42,6 +42,10 @@
Dispatcher& dispatcher, CommandAuthenticator& authenticator);
private:
+ void
+ changeConfig(const ControlParameters& parameters,
+ const ndn::mgmt::CommandContinuation& done);
+
/** \brief serve CS information dataset
*/
void
@@ -49,6 +53,7 @@
ndn::mgmt::StatusDatasetContext& context) const;
private:
+ Cs& m_cs;
const ForwarderCounters& m_fwCnt;
};