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-2017, 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 
88  void
89  erase(const Name& exactName)
90  {
91  BOOST_ASSERT_MSG(false, "not implemented");
92  }
93 
96  void
97  setLimit(size_t nMaxPackets);
98 
101  size_t
102  getLimit() const;
103 
107  void
108  setPolicy(unique_ptr<Policy> policy);
109 
112  Policy*
113  getPolicy() const
114  {
115  return m_policy.get();
116  }
117 
120  size_t
121  size() const
122  {
123  return m_table.size();
124  }
125 
127  void
128  dump();
129 
130 public: // enumeration
132  {
133  typedef const Entry& result_type;
134 
135  const Entry&
136  operator()(const EntryImpl& entry) const
137  {
138  return entry;
139  }
140  };
141 
144  typedef boost::transform_iterator<EntryFromEntryImpl, iterator, const Entry&> const_iterator;
145 
146  const_iterator
147  begin() const
148  {
149  return boost::make_transform_iterator(m_table.begin(), EntryFromEntryImpl());
150  }
151 
152  const_iterator
153  end() const
154  {
155  return boost::make_transform_iterator(m_table.end(), EntryFromEntryImpl());
156  }
157 
158 private: // find
162  iterator
163  findLeftmost(const Interest& interest, iterator left, iterator right) const;
164 
168  iterator
169  findRightmost(const Interest& interest, iterator first, iterator last) const;
170 
174  iterator
175  findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const;
176 
177  void
178  setPolicyImpl(unique_ptr<Policy> policy);
179 
180 private:
181  Table m_table;
182  unique_ptr<Policy> m_policy;
183  ndn::util::signal::ScopedConnection m_beforeEvictConnection;
184 };
185 
186 } // namespace cs
187 
188 using cs::Cs;
189 
190 } // namespace nfd
191 
192 #endif // NFD_DAEMON_TABLE_CS_HPP
size_t getLimit() const
Definition: cs.cpp:59
const Entry & operator()(const EntryImpl &entry) const
Definition: cs.hpp:136
represents a base class for CS entry
Definition: cs-entry.hpp:36
std::function< void(const Interest &, const Data &data)> HitCallback
Definition: cs.hpp:73
std::set< EntryImpl > Table
Definition: cs-internal.hpp:38
Definition: cs.hpp:131
declares ContentStore internal types
const_iterator end() const
Definition: cs.hpp:153
const_iterator begin() const
Definition: cs.hpp:147
represents the ContentStore
Definition: cs.hpp:62
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void erase(const Name &exactName)
Definition: cs.hpp:89
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:75
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
Definition: cs.hpp:144
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
Definition: cs.cpp:53
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
Definition: cs.cpp:65
std::function< void(const Interest &)> MissCallback
Definition: cs.hpp:74
Policy * getPolicy() const
Definition: cs.hpp:113
an Entry in ContentStore implementation
represents a CS replacement policy
Definition: cs-policy.hpp:39
size_t size() const
Definition: cs.hpp:121
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const Entry & result_type
Definition: cs.hpp:133
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:115
Cs(size_t nMaxPackets=10)
Definition: cs.cpp:46