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 
48 #ifndef NFD_DAEMON_TABLE_CS_HPP
49 #define NFD_DAEMON_TABLE_CS_HPP
50 
51 #include "cs-policy.hpp"
52 #include "cs-internal.hpp"
53 #include "cs-entry-impl.hpp"
54 #include <ndn-cxx/util/signal.hpp>
55 #include <boost/iterator/transform_iterator.hpp>
56 
57 namespace nfd {
58 namespace cs {
59 
62 class Cs : noncopyable
63 {
64 public:
65  explicit
66  Cs(size_t nMaxPackets = 10);
67 
70  void
71  insert(const Data& data, bool isUnsolicited = false);
72 
73  typedef std::function<void(const Interest&, const Data& data)> HitCallback;
74  typedef std::function<void(const Interest&)> MissCallback;
75 
83  void
84  find(const Interest& interest,
85  const HitCallback& hitCallback,
86  const MissCallback& missCallback) const;
87 
90  size_t
91  size() const
92  {
93  return m_table.size();
94  }
95 
96 public: // configuration
99  size_t
100  getLimit() const
101  {
102  return m_policy->getLimit();
103  }
104 
107  void
108  setLimit(size_t nMaxPackets)
109  {
110  return m_policy->setLimit(nMaxPackets);
111  }
112 
115  Policy*
116  getPolicy() const
117  {
118  return m_policy.get();
119  }
120 
124  void
125  setPolicy(unique_ptr<Policy> policy);
126 
130  bool
131  shouldAdmit() const
132  {
133  return m_shouldAdmit;
134  }
135 
139  void
140  enableAdmit(bool shouldAdmit);
141 
145  bool
146  shouldServe() const
147  {
148  return m_shouldServe;
149  }
150 
154  void
155  enableServe(bool shouldServe);
156 
157 public: // enumeration
159  {
160  typedef const Entry& result_type;
161 
162  const Entry&
163  operator()(const EntryImpl& entry) const
164  {
165  return entry;
166  }
167  };
168 
171  typedef boost::transform_iterator<EntryFromEntryImpl, iterator, const Entry&> const_iterator;
172 
174  begin() const
175  {
176  return boost::make_transform_iterator(m_table.begin(), EntryFromEntryImpl());
177  }
178 
180  end() const
181  {
182  return boost::make_transform_iterator(m_table.end(), EntryFromEntryImpl());
183  }
184 
185 private: // find
189  iterator
190  findLeftmost(const Interest& interest, iterator left, iterator right) const;
191 
195  iterator
196  findRightmost(const Interest& interest, iterator first, iterator last) const;
197 
201  iterator
202  findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const;
203 
204  void
205  setPolicyImpl(unique_ptr<Policy> policy);
206 
208  void
209  dump();
210 
211 private:
212  Table m_table;
213  unique_ptr<Policy> m_policy;
214  signal::ScopedConnection m_beforeEvictConnection;
215 
216  bool m_shouldAdmit;
217  bool m_shouldServe;
218 };
219 
220 } // namespace cs
221 
222 using cs::Cs;
223 
224 } // namespace nfd
225 
226 #endif // NFD_DAEMON_TABLE_CS_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
std::set< EntryImpl > Table
Definition: cs-internal.hpp:38
size_t getLimit() const
get capacity (in number of packets)
Definition: cs.hpp:100
const Entry & operator()(const EntryImpl &entry) const
Definition: cs.hpp:163
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
Definition: cs.hpp:131
represents an Interest packet
Definition: interest.hpp:42
bool shouldServe() const
get CS_ENABLE_SERVE flag
Definition: cs.hpp:146
const_iterator begin() const
Definition: cs.hpp:174
const Entry & result_type
Definition: cs.hpp:160
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
Definition: cs.cpp:208
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:91
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:55
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
Definition: cs.hpp:171
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Definition: cs.cpp:185
Cs(size_t nMaxPackets=10)
Definition: cs.cpp:46
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:108
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:92
std::function< void(const Interest &, const Data &data)> HitCallback
Definition: cs.hpp:73
std::function< void(const Interest &)> MissCallback
Definition: cs.hpp:74
represents the ContentStore
Definition: cs.hpp:62
const_iterator end() const
Definition: cs.hpp:180
Represents a Data packet.
Definition: data.hpp:35
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
Definition: cs.cpp:218
Policy * getPolicy() const
get replacement policy
Definition: cs.hpp:116