NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
cs-policy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "cs-policy.hpp"
27 #include "cs.hpp"
28 #include "core/logger.hpp"
29 
30 NFD_LOG_INIT("CsPolicy");
31 
32 namespace nfd {
33 namespace cs {
34 
35 Policy::Registry&
36 Policy::getRegistry()
37 {
38  static Registry registry;
39  return registry;
40 }
41 
42 unique_ptr<Policy>
43 Policy::create(const std::string& key)
44 {
45  Registry& registry = getRegistry();
46  auto i = registry.find(key);
47  return i == registry.end() ? nullptr : i->second();
48 }
49 
50 Policy::Policy(const std::string& policyName)
51  : m_policyName(policyName)
52 {
53 }
54 
55 void
56 Policy::setLimit(size_t nMaxEntries)
57 {
58  NFD_LOG_INFO("setLimit " << nMaxEntries);
59  m_limit = nMaxEntries;
60  this->evictEntries();
61 }
62 
63 void
65 {
66  BOOST_ASSERT(m_cs != nullptr);
67  this->doAfterInsert(i);
68 }
69 
70 void
72 {
73  BOOST_ASSERT(m_cs != nullptr);
74  this->doAfterRefresh(i);
75 }
76 
77 void
79 {
80  BOOST_ASSERT(m_cs != nullptr);
81  this->doBeforeErase(i);
82 }
83 
84 void
86 {
87  BOOST_ASSERT(m_cs != nullptr);
88  this->doBeforeUse(i);
89 }
90 
91 } // namespace cs
92 } // namespace nfd
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
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
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
#define NFD_LOG_INFO(expression)
Definition: logger.hpp:56
Table::const_iterator iterator
Definition: cs-internal.hpp:41
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
void afterInsert(iterator i)
invoked by CS after a new entry is inserted
Definition: cs-policy.cpp:64
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
#define NFD_LOG_INIT(name)
Definition: logger.hpp:34
void afterRefresh(iterator i)
invoked by CS after an existing entry is refreshed by same Data
Definition: cs-policy.cpp:71