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-2021, 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 
31 namespace nfd {
32 namespace cs {
33 
44 class Cs : noncopyable
45 {
46 public:
47  explicit
48  Cs(size_t nMaxPackets = 10);
49 
52  void
53  insert(const Data& data, bool isUnsolicited = false);
54 
62  template<typename AfterEraseCallback>
63  void
64  erase(const Name& prefix, size_t limit, AfterEraseCallback&& cb)
65  {
66  size_t nErased = eraseImpl(prefix, limit);
67  cb(nErased);
68  }
69 
79  template<typename HitCallback, typename MissCallback>
80  void
81  find(const Interest& interest, HitCallback&& hit, MissCallback&& miss) const
82  {
83  auto match = findImpl(interest);
84  if (match == m_table.end()) {
85  miss(interest);
86  return;
87  }
88  hit(interest, match->getData());
89  }
90 
93  size_t
94  size() const
95  {
96  return m_table.size();
97  }
98 
99 public: // configuration
102  size_t
103  getLimit() const
104  {
105  return m_policy->getLimit();
106  }
107 
110  void
111  setLimit(size_t nMaxPackets)
112  {
113  return m_policy->setLimit(nMaxPackets);
114  }
115 
118  Policy*
119  getPolicy() const
120  {
121  return m_policy.get();
122  }
123 
127  void
128  setPolicy(unique_ptr<Policy> policy);
129 
133  bool
134  shouldAdmit() const
135  {
136  return m_shouldAdmit;
137  }
138 
142  void
143  enableAdmit(bool shouldAdmit);
144 
148  bool
149  shouldServe() const
150  {
151  return m_shouldServe;
152  }
153 
157  void
158  enableServe(bool shouldServe);
159 
160 public: // enumeration
161  using const_iterator = Table::const_iterator;
162 
164  begin() const
165  {
166  return m_table.begin();
167  }
168 
170  end() const
171  {
172  return m_table.end();
173  }
174 
175 private:
176  std::pair<const_iterator, const_iterator>
177  findPrefixRange(const Name& prefix) const;
178 
179  size_t
180  eraseImpl(const Name& prefix, size_t limit);
181 
183  findImpl(const Interest& interest) const;
184 
185  void
186  setPolicyImpl(unique_ptr<Policy> policy);
187 
189  void
190  dump();
191 
192 private:
193  Table m_table;
194  unique_ptr<Policy> m_policy;
195  signal::ScopedConnection m_beforeEvictConnection;
196 
197  bool m_shouldAdmit = true;
198  bool m_shouldServe = true;
199 };
200 
201 } // namespace cs
202 
203 using cs::Cs;
204 
205 } // namespace nfd
206 
207 #endif // NFD_DAEMON_TABLE_CS_HPP
std::set< Entry, std::less<> > Table
an ordered container of ContentStore entries
Definition: cs-entry.hpp:116
size_t getLimit() const
get capacity (in number of packets)
Definition: cs.hpp:103
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
Definition: cs.hpp:134
Represents an Interest packet.
Definition: interest.hpp:48
bool shouldServe() const
get CS_ENABLE_SERVE flag
Definition: cs.hpp:149
const_iterator begin() const
Definition: cs.hpp:164
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
Definition: cs.cpp:165
represents a CS replacement policy
Definition: cs-policy.hpp:38
size_t size() const
get number of stored packets
Definition: cs.hpp:94
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:51
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
Table::const_iterator const_iterator
Definition: cs.hpp:161
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Definition: cs.cpp:144
Cs(size_t nMaxPackets=10)
Definition: cs.cpp:44
Disconnects a Connection automatically upon destruction.
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
Definition: cs.hpp:111
Represents an absolute name.
Definition: name.hpp:41
implements the Content Store
Definition: cs.hpp:44
const_iterator end() const
Definition: cs.hpp:170
Represents a Data packet.
Definition: data.hpp:37
void find(const Interest &interest, HitCallback &&hit, MissCallback &&miss) const
finds the best matching Data packet
Definition: cs.hpp:81
void erase(const Name &prefix, size_t limit, AfterEraseCallback &&cb)
asynchronously erases entries under prefix
Definition: cs.hpp:64
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
Definition: cs.cpp:175
Policy * getPolicy() const
get replacement policy
Definition: cs.hpp:119