30 #include <ndn-cxx/mgmt/nfd/cs-info.hpp>
40 , m_fwCounters(fwCounters)
42 registerCommandHandler<ndn::nfd::CsConfigCommand>(
"config",
43 [
this] (
auto&&,
auto&&,
auto&&,
auto&&... args) { changeConfig(std::forward<decltype(args)>(args)...); });
44 registerCommandHandler<ndn::nfd::CsEraseCommand>(
"erase",
45 [
this] (
auto&&,
auto&&,
auto&&,
auto&&... args) { erase(std::forward<decltype(args)>(args)...); });
47 [
this] (
auto&&,
auto&&,
auto&&... args) { serveInfo(std::forward<decltype(args)>(args)...); });
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);
87 if (nErased == ERASE_LIMIT && count > ERASE_LIMIT) {
88 m_cs.find(Interest(parameters.getName()).setCanBePrefix(true),
89 [=] (const Interest&, const Data&) mutable {
90 body.setCapacity(ERASE_LIMIT);
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(ndn::mgmt::StatusDatasetContext& context)
const
106 ndn::nfd::CsInfo info;
107 info.setCapacity(m_cs.getLimit());
108 info.setEnableAdmit(m_cs.shouldAdmit());
109 info.setEnableServe(m_cs.shouldServe());
110 info.setNEntries(m_cs.size());
111 info.setNHits(m_fwCounters.nCsHits);
112 info.setNMisses(m_fwCounters.nCsMisses);
114 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).