27 #include <ndn-cxx/mgmt/nfd/cs-info.hpp> 39 registerCommandHandler<ndn::nfd::CsConfigCommand>(
"config",
40 bind(&CsManager::changeConfig,
this, _4, _5));
41 registerCommandHandler<ndn::nfd::CsEraseCommand>(
"erase",
42 bind(&CsManager::erase,
this, _4, _5));
48 CsManager::changeConfig(
const ControlParameters& parameters,
49 const ndn::mgmt::CommandContinuation& done)
51 using ndn::nfd::CsFlagBit;
53 if (parameters.hasCapacity()) {
54 m_cs.setLimit(parameters.getCapacity());
57 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT)) {
58 m_cs.enableAdmit(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT));
61 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE)) {
62 m_cs.enableServe(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE));
65 ControlParameters body;
66 body.setCapacity(m_cs.getLimit());
67 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, m_cs.shouldAdmit(),
false);
68 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, m_cs.shouldServe(),
false);
69 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
73 CsManager::erase(
const ControlParameters& parameters,
74 const ndn::mgmt::CommandContinuation& done)
76 size_t count = parameters.hasCount() ?
77 parameters.getCount() :
78 std::numeric_limits<size_t>::max();
79 m_cs.erase(parameters.getName(), std::min(count,
ERASE_LIMIT),
80 [=] (
size_t nErased) {
81 ControlParameters body;
82 body.setName(parameters.getName());
83 body.setCount(nErased);
85 m_cs.find(Interest(parameters.getName()).setCanBePrefix(
true),
86 [=] (
const Interest&,
const Data&)
mutable {
88 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
90 [=] (
const Interest&) {
91 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
95 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
101 CsManager::serveInfo(
const Name& topPrefix,
const Interest& interest,
102 ndn::mgmt::StatusDatasetContext& context)
const 104 ndn::nfd::CsInfo info;
105 info.setCapacity(m_cs.getLimit());
106 info.setEnableAdmit(m_cs.shouldAdmit());
107 info.setEnableServe(m_cs.shouldServe());
108 info.setNEntries(m_cs.size());
109 info.setNHits(m_fwCnt.
nCsHits);
112 context.append(info.wireEncode());
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
static constexpr size_t ERASE_LIMIT
Provides ControlCommand authorization according to NFD configuration file.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
counters provided by Forwarder
CsManager(Cs &cs, const ForwarderCounters &fwCnt, Dispatcher &dispatcher, CommandAuthenticator &authenticator)