NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
cs-manager.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include "cs-manager.hpp"
28 
29 namespace nfd {
30 
31 constexpr size_t CsManager::ERASE_LIMIT;
32 
34  Dispatcher& dispatcher, CommandAuthenticator& authenticator)
35  : NfdManagerBase(dispatcher, authenticator, "cs")
36  , m_cs(cs)
37  , m_fwCnt(fwCnt)
38 {
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));
43 
44  registerStatusDatasetHandler("info", bind(&CsManager::serveInfo, this, _1, _2, _3));
45 }
46 
47 void
48 CsManager::changeConfig(const ControlParameters& parameters,
50 {
51  using ndn::nfd::CsFlagBit;
52 
53  if (parameters.hasCapacity()) {
54  m_cs.setLimit(parameters.getCapacity());
55  }
56 
59  }
60 
63  }
64 
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()));
70 }
71 
72 void
73 CsManager::erase(const ControlParameters& parameters,
75 {
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);
84  if (nErased == ERASE_LIMIT && count > ERASE_LIMIT) {
85  m_cs.find(Interest(parameters.getName()).setCanBePrefix(true),
86  [=] (const Interest&, const Data&) mutable {
87  body.setCapacity(ERASE_LIMIT);
88  done(ControlResponse(200, "OK").setBody(body.wireEncode()));
89  },
90  [=] (const Interest&) {
91  done(ControlResponse(200, "OK").setBody(body.wireEncode()));
92  });
93  }
94  else {
95  done(ControlResponse(200, "OK").setBody(body.wireEncode()));
96  }
97  });
98 }
99 
100 void
101 CsManager::serveInfo(const Name& topPrefix, const Interest& interest,
102  ndn::mgmt::StatusDatasetContext& context) const
103 {
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);
110  info.setNMisses(m_fwCnt.nCsMisses);
111 
112  context.append(info.wireEncode());
113  context.end();
114 }
115 
116 } // namespace nfd
CsInfo & setNHits(uint64_t nHits)
Definition: cs-info.cpp:165
static constexpr size_t ERASE_LIMIT
Definition: cs-manager.hpp:64
counters provided by Forwarder
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:130
size_t getLimit() const
get capacity (in number of packets)
Definition: cs.hpp:97
CsManager(Cs &cs, const ForwarderCounters &fwCnt, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
Definition: cs-manager.cpp:33
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
Definition: cs.hpp:128
CsInfo & setNEntries(uint64_t nEntries)
Definition: cs-info.cpp:157
bool shouldServe() const
get CS_ENABLE_SERVE flag
Definition: cs.hpp:143
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
Definition: cs.cpp:231
CsInfo & setEnableAdmit(bool enableAdmit)
Definition: cs-info.cpp:141
size_t size() const
get number of stored packets
Definition: cs.hpp:88
mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void erase(const Name &prefix, size_t limit, const AfterEraseCallback &cb)
asynchronously erases entries under prefix
Definition: cs.cpp:92
CsInfo & setEnableServe(bool enableServe)
Definition: cs-info.cpp:149
void end()
end the response successfully after appending zero or more blocks
enables the CS to satisfy Interests using cached Data
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
Definition: cs.hpp:105
enables the CS to admit new Data
represents the CS Information dataset
Definition: cs-info.hpp:37
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:115
bool hasFlagBit(size_t bit) const
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
implements the Content Store
Definition: cs.hpp:48
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Definition: cs-info.cpp:48
CsInfo & setCapacity(uint64_t capacity)
Definition: cs-info.cpp:133
Provides ControlCommand authorization according to NFD configuration file.
void append(const Block &block)
append a Block to the response
bool getFlagBit(size_t bit) const
provides a context for generating response to a StatusDataset request
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
CsFlagBit
CS enablement flags.
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
CsInfo & setNMisses(uint64_t nMisses)
Definition: cs-info.cpp:173
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
Definition: cs.cpp:241