NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
cs.hpp
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 #ifndef NFD_DAEMON_TABLE_CS_HPP
27 #define NFD_DAEMON_TABLE_CS_HPP
28 
29 #include "cs-policy.hpp"
30 #include "cs-internal.hpp"
31 #include "cs-entry-impl.hpp"
32 #include <ndn-cxx/util/signal.hpp>
33 #include <boost/iterator/transform_iterator.hpp>
34 
35 namespace nfd {
36 namespace cs {
37 
48 class Cs : noncopyable
49 {
50 public:
51  explicit
52  Cs(size_t nMaxPackets = 10);
53 
56  void
57  insert(const Data& data, bool isUnsolicited = false);
58 
59  using AfterEraseCallback = std::function<void(size_t nErased)>;
60 
67  void
68  erase(const Name& prefix, size_t limit, const AfterEraseCallback& cb);
69 
70  using HitCallback = std::function<void(const Interest&, const Data&)>;
71  using MissCallback = std::function<void(const Interest&)>;
72 
80  void
81  find(const Interest& interest,
82  const HitCallback& hitCallback,
83  const MissCallback& missCallback) const;
84 
87  size_t
88  size() const
89  {
90  return m_table.size();
91  }
92 
93 public: // configuration
96  size_t
97  getLimit() const
98  {
99  return m_policy->getLimit();
100  }
101 
104  void
105  setLimit(size_t nMaxPackets)
106  {
107  return m_policy->setLimit(nMaxPackets);
108  }
109 
112  Policy*
113  getPolicy() const
114  {
115  return m_policy.get();
116  }
117 
121  void
122  setPolicy(unique_ptr<Policy> policy);
123 
127  bool
128  shouldAdmit() const
129  {
130  return m_shouldAdmit;
131  }
132 
136  void
137  enableAdmit(bool shouldAdmit);
138 
142  bool
143  shouldServe() const
144  {
145  return m_shouldServe;
146  }
147 
151  void
152  enableServe(bool shouldServe);
153 
154 public: // enumeration
156  {
157  typedef const Entry& result_type;
158 
159  const Entry&
160  operator()(const EntryImpl& entry) const
161  {
162  return entry;
163  }
164  };
165 
168  typedef boost::transform_iterator<EntryFromEntryImpl, iterator, const Entry&> const_iterator;
169 
171  begin() const
172  {
173  return boost::make_transform_iterator(m_table.begin(), EntryFromEntryImpl());
174  }
175 
177  end() const
178  {
179  return boost::make_transform_iterator(m_table.end(), EntryFromEntryImpl());
180  }
181 
182 private: // find
186  iterator
187  findLeftmost(const Interest& interest, iterator left, iterator right) const;
188 
192  iterator
193  findRightmost(const Interest& interest, iterator first, iterator last) const;
194 
198  iterator
199  findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const;
200 
201  void
202  setPolicyImpl(unique_ptr<Policy> policy);
203 
205  void
206  dump();
207 
208 private:
209  Table m_table;
210  unique_ptr<Policy> m_policy;
211  signal::ScopedConnection m_beforeEvictConnection;
212 
213  bool m_shouldAdmit;
214  bool m_shouldServe;
215 };
216 
217 } // namespace cs
218 
219 using cs::Cs;
220 
221 } // namespace nfd
222 
223 #endif // NFD_DAEMON_TABLE_CS_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
std::function< void(size_t nErased)> AfterEraseCallback
Definition: cs.hpp:59
std::set< EntryImpl > Table
Definition: cs-internal.hpp:38
size_t getLimit() const
get capacity (in number of packets)
Definition: cs.hpp:97
const Entry & operator()(const EntryImpl &entry) const
Definition: cs.hpp:160
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
Definition: cs.hpp:128
Represents an Interest packet.
Definition: interest.hpp:42
bool shouldServe() const
get CS_ENABLE_SERVE flag
Definition: cs.hpp:143
const_iterator begin() const
Definition: cs.hpp:171
const Entry & result_type
Definition: cs.hpp:157
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
Definition: cs.cpp:232
declares ContentStore internal types
an Entry in ContentStore implementation
Table::const_iterator iterator
Definition: cs-internal.hpp:41
represents a CS replacement policy
Definition: cs-policy.hpp:39
size_t size() const
get number of stored packets
Definition: cs.hpp:88
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:56
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void erase(const Name &prefix, size_t limit, const AfterEraseCallback &cb)
asynchronously erases entries under prefix
Definition: cs.cpp:93
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
Definition: cs.hpp:168
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Definition: cs.cpp:209
Cs(size_t nMaxPackets=10)
Definition: cs.cpp:47
represents a base class for CS entry
Definition: cs-entry.hpp:36
disconnects a Connection automatically upon destruction
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
Definition: cs.hpp:105
Represents an absolute name.
Definition: name.hpp:42
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:116
implements the Content Store
Definition: cs.hpp:48
const_iterator end() const
Definition: cs.hpp:177
std::function< void(const Interest &, const Data &)> HitCallback
Definition: cs.hpp:70
Represents a Data packet.
Definition: data.hpp:35
std::function< void(const Interest &)> MissCallback
Definition: cs.hpp:71
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
Definition: cs.cpp:242
Policy * getPolicy() const
get replacement policy
Definition: cs.hpp:113