NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 
73  void
74  insert(const Data& data, bool isUnsolicited = false);
75 
76  typedef std::function<void(const Interest&, const Data& data)> HitCallback;
77  typedef std::function<void(const Interest&)> MissCallback;
78 
86  void
87  find(const Interest& interest,
88  const HitCallback& hitCallback,
89  const MissCallback& missCallback) const;
90 
91  void
92  erase(const Name& exactName)
93  {
94  BOOST_ASSERT_MSG(false, "not implemented");
95  }
96 
99  void
100  setLimit(size_t nMaxPackets);
101 
104  size_t
105  getLimit() const;
106 
110  void
111  setPolicy(unique_ptr<Policy> policy);
112 
115  Policy*
116  getPolicy() const
117  {
118  return m_policy.get();
119  }
120 
123  size_t
124  size() const
125  {
126  return m_table.size();
127  }
128 
130  void
131  dump();
132 
133 public: // enumeration
135  {
136  typedef const Entry& result_type;
137 
138  const Entry&
139  operator()(const EntryImpl& entry) const
140  {
141  return entry;
142  }
143  };
144 
147  typedef boost::transform_iterator<EntryFromEntryImpl, iterator, const Entry&> const_iterator;
148 
149  const_iterator
150  begin() const
151  {
152  return boost::make_transform_iterator(m_table.begin(), EntryFromEntryImpl());
153  }
154 
155  const_iterator
156  end() const
157  {
158  return boost::make_transform_iterator(m_table.end(), EntryFromEntryImpl());
159  }
160 
161 private: // find
165  iterator
166  findLeftmost(const Interest& interest, iterator left, iterator right) const;
167 
171  iterator
172  findRightmost(const Interest& interest, iterator first, iterator last) const;
173 
177  iterator
178  findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const;
179 
180  void
181  setPolicyImpl(unique_ptr<Policy> policy);
182 
183 private:
184  Table m_table;
185  unique_ptr<Policy> m_policy;
186  ndn::util::signal::ScopedConnection m_beforeEvictConnection;
187 };
188 
189 } // namespace cs
190 
191 using cs::Cs;
192 
193 } // namespace nfd
194 
195 #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
Cs(size_t nMaxPackets=10, unique_ptr< Policy > policy=makeDefaultPolicy())
Definition: cs.cpp:54
size_t getLimit() const
Definition: cs.cpp:67
const Entry & operator()(const EntryImpl &entry) const
Definition: cs.hpp:139
represents an Interest packet
Definition: interest.hpp:42
const_iterator begin() const
Definition: cs.hpp:150
const Entry & result_type
Definition: cs.hpp:136
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
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
Definition: cs.hpp:124
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Definition: cs.cpp:83
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
unique_ptr< Policy > makeDefaultPolicy()
Definition: cs.cpp:48
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
Definition: cs.hpp:147
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
Definition: cs.cpp:73
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:61
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
Definition: cs.cpp:123
std::function< void(const Interest &, const Data &data)> HitCallback
Definition: cs.hpp:76
void erase(const Name &exactName)
Definition: cs.hpp:92
std::function< void(const Interest &)> MissCallback
Definition: cs.hpp:77
represents the ContentStore
Definition: cs.hpp:65
const_iterator end() const
Definition: cs.hpp:156
represents a Data packet
Definition: data.hpp:37
Policy * getPolicy() const
Definition: cs.hpp:116