30 #include <ndn-cxx/mgmt/nfd/cs-info.hpp>
38 , m_fwCounters(fwCounters)
40 registerCommandHandler<ndn::nfd::CsConfigCommand>(
"config",
41 std::bind(&CsManager::changeConfig,
this, _4, _5));
42 registerCommandHandler<ndn::nfd::CsEraseCommand>(
"erase",
43 std::bind(&CsManager::erase,
this, _4, _5));
49 CsManager::changeConfig(
const ControlParameters& parameters,
50 const ndn::mgmt::CommandContinuation& done)
52 using ndn::nfd::CsFlagBit;
54 if (parameters.hasCapacity()) {
55 m_cs.
setLimit(parameters.getCapacity());
58 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT)) {
59 m_cs.
enableAdmit(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT));
62 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE)) {
63 m_cs.
enableServe(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE));
66 ControlParameters body;
68 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, m_cs.
shouldAdmit(),
false);
69 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, m_cs.
shouldServe(),
false);
70 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
74 CsManager::erase(
const ControlParameters& parameters,
75 const ndn::mgmt::CommandContinuation& done)
77 size_t count = parameters.hasCount() ?
78 parameters.getCount() :
79 std::numeric_limits<size_t>::max();
81 [=] (
size_t nErased) {
82 ControlParameters body;
83 body.setName(parameters.getName());
84 body.setCount(nErased);
85 if (nErased == ERASE_LIMIT && count > ERASE_LIMIT) {
86 m_cs.find(Interest(parameters.getName()).setCanBePrefix(true),
87 [=] (const Interest&, const Data&) mutable {
88 body.setCapacity(ERASE_LIMIT);
89 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
91 [=] (const Interest&) {
92 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
96 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
102 CsManager::serveInfo(
const Name&,
const Interest&, 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_fwCounters.nCsHits);
110 info.setNMisses(m_fwCounters.nCsMisses);
112 context.append(info.wireEncode());
Provides ControlCommand authorization according to NFD's configuration file.
static constexpr size_t ERASE_LIMIT
CsManager(cs::Cs &cs, const ForwarderCounters &fwCounters, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
Counters provided by Forwarder.
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
Implements the Content Store.
bool shouldServe() const noexcept
Get CS_ENABLE_SERVE flag.
void enableAdmit(bool shouldAdmit) noexcept
Set CS_ENABLE_ADMIT flag.
bool shouldAdmit() const noexcept
Get CS_ENABLE_ADMIT flag.
void erase(const Name &prefix, size_t limit, AfterEraseCallback &&cb)
Asynchronously erases entries under prefix.
void setLimit(size_t nMaxPackets)
Change capacity (in number of packets).
void enableServe(bool shouldServe) noexcept
Set CS_ENABLE_SERVE flag.
size_t getLimit() const noexcept
Get capacity (in number of packets).