NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
cs-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_CS_POLICY_HPP
27 #define NFD_DAEMON_TABLE_CS_POLICY_HPP
28 
29 #include "cs-internal.hpp"
30 #include "cs-entry-impl.hpp"
31 
32 namespace nfd {
33 namespace cs {
34 
35 class Cs;
36 
39 class Policy : noncopyable
40 {
41 public: // registry
42  template<typename P>
43  static void
44  registerPolicy(const std::string& policyName = P::POLICY_NAME)
45  {
46  Registry& registry = getRegistry();
47  BOOST_ASSERT(registry.count(policyName) == 0);
48  registry[policyName] = [] { return make_unique<P>(); };
49  }
50 
54  static unique_ptr<Policy>
55  create(const std::string& policyName);
56 
59  static std::set<std::string>
61 
62 public:
63  explicit
64  Policy(const std::string& policyName);
65 
66  virtual
67  ~Policy() = default;
68 
69  const std::string&
70  getName() const;
71 
72 public:
75  Cs*
76  getCs() const;
77 
80  void
81  setCs(Cs *cs);
82 
85  size_t
86  getLimit() const;
87 
94  void
95  setLimit(size_t nMaxEntries);
96 
103 
110  void
112 
117  void
119 
123  void
125 
130  void
131  beforeUse(iterator i);
132 
133 protected:
142  virtual void
143  doAfterInsert(iterator i) = 0;
144 
150  virtual void
151  doAfterRefresh(iterator i) = 0;
152 
159  virtual void
160  doBeforeErase(iterator i) = 0;
161 
167  virtual void
168  doBeforeUse(iterator i) = 0;
169 
173  virtual void
174  evictEntries() = 0;
175 
176 protected:
178 
179 private: // registry
180  typedef std::function<unique_ptr<Policy>()> CreateFunc;
181  typedef std::map<std::string, CreateFunc> Registry; // indexed by policy name
182 
183  static Registry&
184  getRegistry();
185 
186 private:
187  std::string m_policyName;
188  size_t m_limit;
189  Cs* m_cs;
190 };
191 
192 inline const std::string&
194 {
195  return m_policyName;
196 }
197 
198 inline Cs*
200 {
201  return m_cs;
202 }
203 
204 inline void
206 {
207  m_cs = cs;
208 }
209 
210 inline size_t
212 {
213  return m_limit;
214 }
215 
216 } // namespace cs
217 } // namespace nfd
218 
222 #define NFD_REGISTER_CS_POLICY(P) \
223 static class NfdAuto ## P ## CsPolicyRegistrationClass \
224 { \
225 public: \
226  NfdAuto ## P ## CsPolicyRegistrationClass() \
227  { \
228  ::nfd::cs::Policy::registerPolicy<P>(); \
229  } \
230 } g_nfdAuto ## P ## CsPolicyRegistrationVariable
231 
232 #endif // NFD_DAEMON_TABLE_CS_POLICY_HPP
void setCs(Cs *cs)
sets cs
Definition: cs-policy.hpp:205
virtual void evictEntries()=0
evicts zero or more entries
void setLimit(size_t nMaxEntries)
sets hard limit (in number of entries)
Definition: cs-policy.cpp:67
Cs * getCs() const
gets cs
Definition: cs-policy.hpp:199
signal::Signal< Policy, iterator > beforeEvict
emits when an entry is being evicted
Definition: cs-policy.hpp:102
static unique_ptr< Policy > create(const std::string &policyName)
Definition: cs-policy.cpp:45
virtual void doAfterRefresh(iterator i)=0
invoked after an existing entry is refreshed by same Data
virtual void doBeforeUse(iterator i)=0
invoked before an entry is used to match a lookup
declares ContentStore internal types
provides a lightweight signal / event system
Definition: signal.hpp:50
Table::const_iterator iterator
Definition: cs-internal.hpp:41
represents a CS replacement policy
Definition: cs-policy.hpp:39
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a &#39;emit_signalName&#39; method
Definition: emit.hpp:59
static std::set< std::string > getPolicyNames()
Definition: cs-policy.cpp:53
void beforeErase(iterator i)
invoked by CS before an entry is erased due to management command
Definition: cs-policy.cpp:89
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
static void registerPolicy(const std::string &policyName=P::POLICY_NAME)
Definition: cs-policy.hpp:44
void beforeUse(iterator i)
invoked by CS before an entry is used to match a lookup
Definition: cs-policy.cpp:96
virtual void doBeforeErase(iterator i)=0
invoked before an entry is erased due to management command
represents the ContentStore
Definition: cs.hpp:62
void afterInsert(iterator i)
invoked by CS after a new entry is inserted
Definition: cs-policy.cpp:75
virtual ~Policy()=default
virtual void doAfterInsert(iterator i)=0
invoked after a new entry is created in CS
Policy(const std::string &policyName)
Definition: cs-policy.cpp:61
size_t getLimit() const
gets hard limit (in number of entries)
Definition: cs-policy.hpp:211
void afterRefresh(iterator i)
invoked by CS after an existing entry is refreshed by same Data
Definition: cs-policy.cpp:82
const std::string & getName() const
Definition: cs-policy.hpp:193