30 #include <ndn-cxx/mgmt/nfd/cs-info.hpp>
40 , m_fwCounters(fwCounters)
42 registerCommandHandler<ndn::nfd::CsConfigCommand>([
this] (
auto&&,
auto&&,
auto&&... args) {
43 changeConfig(std::forward<decltype(args)>(args)...);
45 registerCommandHandler<ndn::nfd::CsEraseCommand>([
this] (
auto&&,
auto&&,
auto&&... args) {
46 erase(std::forward<decltype(args)>(args)...);
49 serveInfo(std::forward<decltype(args)>(args)...);
54 CsManager::changeConfig(
const ControlParameters& parameters,
55 const CommandContinuation& done)
57 using ndn::nfd::CsFlagBit;
59 if (parameters.hasCapacity()) {
60 m_cs.
setLimit(parameters.getCapacity());
63 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT)) {
64 m_cs.
enableAdmit(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT));
67 if (parameters.hasFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE)) {
68 m_cs.
enableServe(parameters.getFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE));
71 ControlParameters body;
73 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, m_cs.
shouldAdmit(),
false);
74 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, m_cs.
shouldServe(),
false);
75 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
79 CsManager::erase(
const ControlParameters& parameters,
80 const CommandContinuation& done)
82 size_t count = parameters.hasCount() ?
83 parameters.getCount() :
84 std::numeric_limits<size_t>::max();
86 [=] (
size_t nErased) {
87 ControlParameters body;
88 body.setName(parameters.getName());
89 body.setCount(nErased);
90 if (nErased == ERASE_LIMIT && count > ERASE_LIMIT) {
91 m_cs.find(Interest(parameters.getName()).setCanBePrefix(true),
92 [=] (const Interest&, const Data&) mutable {
93 body.setCapacity(ERASE_LIMIT);
94 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
96 [=] (const Interest&) {
97 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
101 done(ControlResponse(200,
"OK").setBody(body.wireEncode()));
107 CsManager::serveInfo(ndn::mgmt::StatusDatasetContext& context)
const
109 ndn::nfd::CsInfo info;
110 info.setCapacity(m_cs.getLimit());
111 info.setEnableAdmit(m_cs.shouldAdmit());
112 info.setEnableServe(m_cs.shouldServe());
113 info.setNEntries(m_cs.size());
114 info.setNHits(m_fwCounters.nCsHits);
115 info.setNMisses(m_fwCounters.nCsMisses);
117 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).