NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
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 
60 unique_ptr<Policy>
62 
65 class Cs : noncopyable
66 {
67 public:
68  explicit
69  Cs(size_t nMaxPackets = 10, unique_ptr<Policy> policy = makeDefaultPolicy());
70 
74  bool
75  insert(const Data& data, bool isUnsolicited = false);
76 
77  typedef std::function<void(const Interest&, const Data& data)> HitCallback;
78  typedef std::function<void(const Interest&)> MissCallback;
79 
87  void
88  find(const Interest& interest,
89  const HitCallback& hitCallback,
90  const MissCallback& missCallback) const;
91 
92  void
93  erase(const Name& exactName)
94  {
95  BOOST_ASSERT_MSG(false, "not implemented");
96  }
97 
100  void
101  setLimit(size_t nMaxPackets);
102 
105  size_t
106  getLimit() const;
107 
111  void
112  setPolicy(unique_ptr<Policy> policy);
113 
116  Policy*
117  getPolicy() const
118  {
119  return m_policy.get();
120  }
121 
124  size_t
125  size() const
126  {
127  return m_table.size();
128  }
129 
131  void
132  dump();
133 
134 public: // enumeration
136  {
137  typedef const Entry& result_type;
138 
139  const Entry&
140  operator()(const EntryImpl& entry) const
141  {
142  return entry;
143  }
144  };
145 
148  typedef boost::transform_iterator<EntryFromEntryImpl, iterator, const Entry&> const_iterator;
149 
150  const_iterator
151  begin() const
152  {
153  return boost::make_transform_iterator(m_table.begin(), EntryFromEntryImpl());
154  }
155 
156  const_iterator
157  end() const
158  {
159  return boost::make_transform_iterator(m_table.end(), EntryFromEntryImpl());
160  }
161 
162 private: // find
166  iterator
167  findLeftmost(const Interest& interest, iterator left, iterator right) const;
168 
172  iterator
173  findRightmost(const Interest& interest, iterator first, iterator last) const;
174 
178  iterator
179  findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const;
180 
181  void
182  setPolicyImpl(unique_ptr<Policy>& policy);
183 
184 private:
185  Table m_table;
186  unique_ptr<Policy> m_policy;
187  ndn::util::signal::ScopedConnection m_beforeEvictConnection;
188 };
189 
190 } // namespace cs
191 
192 using cs::Cs;
193 
194 } // namespace nfd
195 
196 #endif // NFD_DAEMON_TABLE_CS_HPP
size_t getLimit() const
Definition: cs.cpp:66
const_iterator end() const
Definition: cs.hpp:157
std::set< EntryImpl > Table
Definition: cs-internal.hpp:38
Cs(size_t nMaxPackets=10, unique_ptr< Policy > policy=makeDefaultPolicy())
Definition: cs.cpp:53
Policy * getPolicy() const
Definition: cs.hpp:117
bool insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:82
represents an Interest packet
Definition: interest.hpp:45
const_iterator begin() const
Definition: cs.hpp:151
const Entry & result_type
Definition: cs.hpp:137
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
const Entry & operator()(const EntryImpl &entry) const
Definition: cs.hpp:140
an Entry in ContentStore implementation
Table::const_iterator iterator
Definition: cs-internal.hpp:41
represents a CS replacement policy
Definition: cs-policy.hpp:39
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
unique_ptr< Policy > makeDefaultPolicy()
Definition: cs.cpp:48
size_t size() const
Definition: cs.hpp:125
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
Definition: cs.hpp:148
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:120
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
Definition: cs.cpp:72
represents a base class for CS entry
Definition: cs-entry.hpp:36
disconnects a Connection automatically upon destruction
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
Definition: cs.cpp:60
Name abstraction to represent an absolute name.
Definition: name.hpp:46
std::function< void(const Interest &, const Data &data)> HitCallback
Definition: cs.hpp:77
void erase(const Name &exactName)
Definition: cs.hpp:93
std::function< void(const Interest &)> MissCallback
Definition: cs.hpp:78
represents the ContentStore
Definition: cs.hpp:65
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
represents a Data packet
Definition: data.hpp:39