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; -*- */
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-policy.hpp"
27 #include "cs.hpp"
28 #include "core/logger.hpp"
29 
30 #include <boost/range/adaptor/map.hpp>
31 #include <boost/range/algorithm/copy.hpp>
32 
34 
35 namespace nfd {
36 namespace cs {
37 
38 Policy::Registry&
39 Policy::getRegistry()
40 {
41  static Registry registry;
42  return registry;
43 }
44 
45 unique_ptr<Policy>
46 Policy::create(const std::string& policyName)
47 {
48  Registry& registry = getRegistry();
49  auto i = registry.find(policyName);
50  return i == registry.end() ? nullptr : i->second();
51 }
52 
53 std::set<std::string>
55 {
56  std::set<std::string> policyNames;
57  boost::copy(getRegistry() | boost::adaptors::map_keys,
58  std::inserter(policyNames, policyNames.end()));
59  return policyNames;
60 }
61 
62 Policy::Policy(const std::string& policyName)
63  : m_policyName(policyName)
64 {
65 }
66 
67 void
68 Policy::setLimit(size_t nMaxEntries)
69 {
70  NFD_LOG_INFO("setLimit " << nMaxEntries);
71  m_limit = nMaxEntries;
72  this->evictEntries();
73 }
74 
75 void
77 {
78  BOOST_ASSERT(m_cs != nullptr);
79  this->doAfterInsert(i);
80 }
81 
82 void
84 {
85  BOOST_ASSERT(m_cs != nullptr);
86  this->doAfterRefresh(i);
87 }
88 
89 void
91 {
92  BOOST_ASSERT(m_cs != nullptr);
93  this->doBeforeErase(i);
94 }
95 
96 void
98 {
99  BOOST_ASSERT(m_cs != nullptr);
100  this->doBeforeUse(i);
101 }
102 
103 } // namespace cs
104 } // 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:68
static unique_ptr< Policy > create(const std::string &policyName)
Definition: cs-policy.cpp:46
virtual void doAfterRefresh(iterator i)=0
invoked after an existing entry is refreshed by same Data
CsPolicy
Definition: cs-policy.cpp:33
virtual void doBeforeUse(iterator i)=0
invoked before an entry is used to match a lookup
#define NFD_LOG_INFO
Definition: logger.hpp:39
Table::const_iterator iterator
Definition: cs-internal.hpp:41
static std::set< std::string > getPolicyNames()
Definition: cs-policy.cpp:54
void beforeErase(iterator i)
invoked by CS before an entry is erased due to management command
Definition: cs-policy.cpp:90
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:97
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:76
virtual void doAfterInsert(iterator i)=0
invoked after a new entry is created in CS
Policy(const std::string &policyName)
Definition: cs-policy.cpp:62
#define NFD_LOG_INIT(name)
Definition: logger.hpp:31
void afterRefresh(iterator i)
invoked by CS after an existing entry is refreshed by same Data
Definition: cs-policy.cpp:83