NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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 #include <boost/range/adaptor/map.hpp>
30 #include <boost/range/algorithm/copy.hpp>
31 
32 NFD_LOG_INIT("CsPolicy");
33 
34 namespace nfd {
35 namespace cs {
36 
37 Policy::Registry&
38 Policy::getRegistry()
39 {
40  static Registry registry;
41  return registry;
42 }
43 
44 unique_ptr<Policy>
45 Policy::create(const std::string& policyName)
46 {
47  Registry& registry = getRegistry();
48  auto i = registry.find(policyName);
49  return i == registry.end() ? nullptr : i->second();
50 }
51 
52 std::set<std::string>
54 {
55  std::set<std::string> policyNames;
56  boost::copy(getRegistry() | boost::adaptors::map_keys,
57  std::inserter(policyNames, policyNames.end()));
58  return policyNames;
59 }
60 
61 Policy::Policy(const std::string& policyName)
62  : m_policyName(policyName)
63 {
64 }
65 
66 void
67 Policy::setLimit(size_t nMaxEntries)
68 {
69  NFD_LOG_INFO("setLimit " << nMaxEntries);
70  m_limit = nMaxEntries;
71  this->evictEntries();
72 }
73 
74 void
76 {
77  BOOST_ASSERT(m_cs != nullptr);
78  this->doAfterInsert(i);
79 }
80 
81 void
83 {
84  BOOST_ASSERT(m_cs != nullptr);
85  this->doAfterRefresh(i);
86 }
87 
88 void
90 {
91  BOOST_ASSERT(m_cs != nullptr);
92  this->doBeforeErase(i);
93 }
94 
95 void
97 {
98  BOOST_ASSERT(m_cs != nullptr);
99  this->doBeforeUse(i);
100 }
101 
102 } // namespace cs
103 } // 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:67
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
#define NFD_LOG_INFO(expression)
Definition: logger.hpp:56
Table::const_iterator iterator
Definition: cs-internal.hpp:41
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
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
void afterInsert(iterator i)
invoked by CS after a new entry is inserted
Definition: cs-policy.cpp:75
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
#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:82