30 #include <ndn-cxx/mgmt/nfd/cs-info.hpp> 40 , m_fwCounters(fwCounters)
42 registerCommandHandler<ndn::nfd::CsConfigCommand>(
"config",
43 bind(&CsManager::changeConfig,
this, _4, _5));
44 registerCommandHandler<ndn::nfd::CsEraseCommand>(
"erase",
45 bind(&CsManager::erase,
this, _4, _5));
51 CsManager::changeConfig(
const ControlParameters& parameters,
52 const ndn::mgmt::CommandContinuation& done)
54 using ndn::nfd::CsFlagBit;
56 if (parameters.hasCapacity()) {
57 m_cs.
setLimit(parameters.getCapacity());
60 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT)) {
61 m_cs.
enableAdmit(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT));
64 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE)) {
65 m_cs.
enableServe(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE));
68 ControlParameters body;
70 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, m_cs.
shouldAdmit(),
false);
71 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, m_cs.
shouldServe(),
false);
72 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
76 CsManager::erase(
const ControlParameters& parameters,
77 const ndn::mgmt::CommandContinuation& done)
79 size_t count = parameters.hasCount() ?
80 parameters.getCount() :
81 std::numeric_limits<size_t>::max();
83 [=] (
size_t nErased) {
84 ControlParameters body;
85 body.setName(parameters.getName());
86 body.setCount(nErased);
88 m_cs.
find(Interest(parameters.getName()).setCanBePrefix(
true),
89 [=] (
const Interest&,
const Data&)
mutable {
91 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
93 [=] (
const Interest&) {
94 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
98 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
104 CsManager::serveInfo(
const Name& topPrefix,
const Interest& interest,
105 ndn::mgmt::StatusDatasetContext& context)
const 107 ndn::nfd::CsInfo info;
111 info.setNEntries(m_cs.
size());
112 info.setNHits(m_fwCounters.
nCsHits);
115 context.append(info.wireEncode());
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
static constexpr size_t ERASE_LIMIT
implements the Content Store
CsManager(cs::Cs &cs, const ForwarderCounters &fwCounters, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
bool shouldServe() const
get CS_ENABLE_SERVE flag
Provides ControlCommand authorization according to NFD configuration file.
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void erase(const Name &prefix, size_t limit, AfterEraseCallback &&cb)
asynchronously erases entries under prefix
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
size_t size() const
get number of stored packets
size_t getLimit() const
get capacity (in number of packets)
Counters provided by Forwarder.
void find(const Interest &interest, HitCallback &&hit, MissCallback &&miss) const
finds the best matching Data packet