NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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
45  {
46  const std::string& key = P::POLICY_NAME;
47  Registry& registry = getRegistry();
48  BOOST_ASSERT(registry.count(key) == 0);
49  registry[key] = [] { return make_unique<P>(); };
50  }
51 
54  static unique_ptr<Policy>
55  create(const std::string& key);
56 
57 public:
58  explicit
59  Policy(const std::string& policyName);
60 
61  virtual
62  ~Policy() = default;
63 
64  const std::string&
65  getName() const;
66 
67 public:
70  Cs*
71  getCs() const;
72 
75  void
76  setCs(Cs *cs);
77 
80  size_t
81  getLimit() const;
82 
89  void
90  setLimit(size_t nMaxEntries);
91 
98 
105  void
107 
112  void
114 
118  void
120 
125  void
126  beforeUse(iterator i);
127 
128 protected:
137  virtual void
138  doAfterInsert(iterator i) = 0;
139 
145  virtual void
146  doAfterRefresh(iterator i) = 0;
147 
154  virtual void
155  doBeforeErase(iterator i) = 0;
156 
162  virtual void
163  doBeforeUse(iterator i) = 0;
164 
168  virtual void
169  evictEntries() = 0;
170 
171 protected:
172  DECLARE_SIGNAL_EMIT(beforeEvict)
173 
174 private: // registry
175  typedef std::function<unique_ptr<Policy>()> CreateFunc;
176  typedef std::map<std::string, CreateFunc> Registry; // indexed by key
177 
178  static Registry&
179  getRegistry();
180 
181 private:
182  std::string m_policyName;
183  size_t m_limit;
184  Cs* m_cs;
185 };
186 
187 inline const std::string&
189 {
190  return m_policyName;
191 }
192 
193 inline Cs*
195 {
196  return m_cs;
197 }
198 
199 inline void
201 {
202  m_cs = cs;
203 }
204 
205 inline size_t
207 {
208  return m_limit;
209 }
210 
211 } // namespace cs
212 } // namespace nfd
213 
217 #define NFD_REGISTER_CS_POLICY(P) \
218 static class NfdAuto ## P ## CsPolicyRegistrationClass \
219 { \
220 public: \
221  NfdAuto ## P ## CsPolicyRegistrationClass() \
222  { \
223  ::nfd::cs::Policy::registerPolicy<P>(); \
224  } \
225 } g_nfdAuto ## P ## CsPolicyRegistrationVariable
226 
227 #endif // NFD_DAEMON_TABLE_CS_POLICY_HPP
void setCs(Cs *cs)
sets cs
Definition: cs-policy.hpp:200
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:56
Cs * getCs() const
gets cs
Definition: cs-policy.hpp:194
signal::Signal< Policy, iterator > beforeEvict
emits when an entry is being evicted
Definition: cs-policy.hpp:97
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
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
provides a lightweight signal / event system
Table::const_iterator iterator
Definition: cs-internal.hpp:41
represents a CS replacement policy
Definition: cs-policy.hpp:39
void beforeErase(iterator i)
invoked by CS before an entry is erased due to management command
Definition: cs-policy.cpp:78
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void beforeUse(iterator i)
invoked by CS before an entry is used to match a lookup
Definition: cs-policy.cpp:85
virtual void doBeforeErase(iterator i)=0
invoked before an entry is erased due to management command
static unique_ptr< Policy > create(const std::string &key)
Definition: cs-policy.cpp:43
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a &#39;emit_signalName&#39; method
Definition: signal-emit.hpp:59
represents the ContentStore
Definition: cs.hpp:65
void afterInsert(iterator i)
invoked by CS after a new entry is inserted
Definition: cs-policy.cpp:64
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:50
size_t getLimit() const
gets hard limit (in number of entries)
Definition: cs-policy.hpp:206
void afterRefresh(iterator i)
invoked by CS after an existing entry is refreshed by same Data
Definition: cs-policy.cpp:71
static void registerPolicy()
Definition: cs-policy.hpp:44
const std::string & getName() const
Definition: cs-policy.hpp:188