NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cs.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
30 #ifndef NFD_DAEMON_TABLE_CS_HPP
31 #define NFD_DAEMON_TABLE_CS_HPP
32 
33 #include "common.hpp"
34 #include "cs-skip-list-entry.hpp"
35 
36 #include <boost/multi_index/member.hpp>
37 #include <boost/multi_index_container.hpp>
38 #include <boost/multi_index/ordered_index.hpp>
39 #include <boost/multi_index/sequenced_index.hpp>
40 #include <boost/multi_index/identity.hpp>
41 
42 #include <queue>
43 
44 namespace nfd {
45 
46 typedef std::list<cs::skip_list::Entry*> SkipListLayer;
47 typedef std::list<SkipListLayer*> SkipList;
48 
50 {
51 public:
52  bool
53  operator()(const cs::skip_list::Entry* entry1, const cs::skip_list::Entry* entry2) const
54  {
55  return entry1->getStaleTime() < entry2->getStaleTime();
56  }
57 };
58 
60 {
61 public:
62  bool
63  operator()(const cs::skip_list::Entry* entry1, const cs::skip_list::Entry* entry2) const
64  {
65  return entry1->isUnsolicited();
66  }
67 
68  bool
69  operator()(bool isUnsolicited, const cs::skip_list::Entry* entry) const
70  {
71  if (isUnsolicited)
72  return true;
73  else
74  return !entry->isUnsolicited();
75  }
76 };
77 
78 // tags
79 class unsolicited;
80 class byStaleness;
81 class byArrival;
82 
83 typedef boost::multi_index_container<
85  boost::multi_index::indexed_by<
86 
87  // by arrival (FIFO)
88  boost::multi_index::sequenced<
89  boost::multi_index::tag<byArrival>
90  >,
91 
92  // index by staleness time
93  boost::multi_index::ordered_non_unique<
94  boost::multi_index::tag<byStaleness>,
95  boost::multi_index::identity<cs::skip_list::Entry*>,
97  >,
98 
99  // unsolicited Data is in the front
100  boost::multi_index::ordered_non_unique<
101  boost::multi_index::tag<unsolicited>,
102  boost::multi_index::identity<cs::skip_list::Entry*>,
104  >
105 
106  >
107 > CleanupIndex;
108 
111 class Cs : noncopyable
112 {
113 public:
114  explicit
115  Cs(size_t nMaxPackets = 10);
116 
117  ~Cs();
118 
127  bool
128  insert(const Data& data, bool isUnsolicited = false);
129 
133  const Data*
134  find(const Interest& interest) const;
135 
138  void
139  erase(const Name& exactName);
140 
143  void
144  setLimit(size_t nMaxPackets);
145 
149  size_t
150  getLimit() const;
151 
155  size_t
156  size() const;
157 
158 public: // enumeration
159  class const_iterator;
160 
166  begin() const;
167 
172  end() const;
173 
174  class const_iterator : public std::iterator<std::forward_iterator_tag, const cs::Entry>
175  {
176  public:
177  const_iterator() = default;
178 
179  const_iterator(SkipListLayer::const_iterator it);
180 
181  ~const_iterator();
182 
183  reference
184  operator*() const;
185 
186  pointer
187  operator->() const;
188 
190  operator++();
191 
193  operator++(int);
194 
195  bool
196  operator==(const const_iterator& other) const;
197 
198  bool
199  operator!=(const const_iterator& other) const;
200 
201  private:
202  SkipListLayer::const_iterator m_skipListIterator;
203  };
204 
205 protected:
209  bool
210  evictItem();
211 
212 private:
216  bool
217  isFull() const;
218 
224  size_t
225  pickRandomLayer() const;
226 
231  std::pair<cs::skip_list::Entry*, bool>
232  insertToSkipList(const Data& data, bool isUnsolicited = false);
233 
237  bool
238  eraseFromSkipList(cs::skip_list::Entry* entry);
239 
242  void
243  printSkipList() const;
244 
257  const Data*
258  selectChild(const Interest& interest, SkipListLayer::iterator startingPoint) const;
259 
264  bool
265  doesComplyWithSelectors(const Interest& interest,
266  cs::skip_list::Entry* entry,
267  bool doesInterestContainDigest) const;
268 
273  bool
274  recognizeInterestWithDigest(const Interest& interest, cs::skip_list::Entry* entry) const;
275 
276 private:
277  SkipList m_skipList;
278  CleanupIndex m_cleanupIndex;
279  size_t m_nMaxPackets; // user defined maximum size of the Content Store in packets
280  size_t m_nPackets; // current number of packets in Content Store
281  std::queue<cs::skip_list::Entry*> m_freeCsEntries; // memory pool
282 };
283 
284 inline Cs::const_iterator
285 Cs::begin() const
286 {
287  return const_iterator(m_skipList.front()->begin());
288 }
289 
290 inline Cs::const_iterator
291 Cs::end() const
292 {
293  return const_iterator(m_skipList.front()->end());
294 }
295 
296 inline
297 Cs::const_iterator::const_iterator(SkipListLayer::const_iterator it)
298  : m_skipListIterator(it)
299 {
300 }
301 
302 inline
304 {
305 }
306 
307 inline Cs::const_iterator&
309 {
310  ++m_skipListIterator;
311  return *this;
312 }
313 
314 inline Cs::const_iterator
316 {
317  Cs::const_iterator temp(*this);
318  ++(*this);
319  return temp;
320 }
321 
322 inline Cs::const_iterator::reference
324 {
325  return *(this->operator->());
326 }
327 
328 inline Cs::const_iterator::pointer
330 {
331  return *m_skipListIterator;
332 }
333 
334 inline bool
336 {
337  return m_skipListIterator == other.m_skipListIterator;
338 }
339 
340 inline bool
342 {
343  return !(*this == other);
344 }
345 
346 } // namespace nfd
347 
348 #endif // NFD_DAEMON_TABLE_CS_HPP
void erase(const Name &exactName)
deletes CS entry by the exact name
Definition: cs.cpp:747
reference operator*() const
Definition: cs.hpp:323
bool evictItem()
removes one Data packet from Content Store based on replacement policy
Definition: cs.cpp:362
const_iterator begin() const
returns an iterator pointing to the first CS entry
Definition: cs.hpp:285
pointer operator->() const
Definition: cs.hpp:329
std::list< cs::skip_list::Entry * > SkipListLayer
Definition: cs.hpp:46
const_iterator end() const
returns an iterator referring to the past-the-end CS entry
Definition: cs.hpp:291
const Data * find(const Interest &interest) const
finds the best match Data for an Interest
Definition: cs.cpp:407
std::list< SkipListLayer * > SkipList
Definition: cs.hpp:47
~Cs()
Definition: cs.cpp:73
size_t getLimit() const
returns maximum allowed size of Content Store (in packets)
Definition: cs.cpp:118
bool insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet This method does not consider the payload of the Data packet.
Definition: cs.cpp:265
size_t size() const
returns current size of Content Store measured in packets
Definition: cs.cpp:89
bool operator!=(const const_iterator &other) const
Definition: cs.hpp:341
const_iterator & operator++()
Definition: cs.hpp:308
bool isUnsolicited() const
Data packet is unsolicited if this particular NDN node did not receive an Interest packet for it...
Definition: cs-entry.hpp:129
bool operator()(bool isUnsolicited, const cs::skip_list::Entry *entry) const
Definition: cs.hpp:69
const time::steady_clock::TimePoint & getStaleTime() const
returns the absolute time when Data becomes expired
Definition: cs-entry.hpp:135
represents Content Store
Definition: cs.hpp:111
bool operator()(const cs::skip_list::Entry *entry1, const cs::skip_list::Entry *entry2) const
Definition: cs.hpp:53
boost::multi_index_container< cs::skip_list::Entry *, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< byArrival > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< byStaleness >, boost::multi_index::identity< cs::skip_list::Entry * >, StalenessComparator >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< unsolicited >, boost::multi_index::identity< cs::skip_list::Entry * >, UnsolicitedComparator > >> CleanupIndex
Definition: cs.hpp:81
bool operator()(const cs::skip_list::Entry *entry1, const cs::skip_list::Entry *entry2) const
Definition: cs.hpp:63
represents an entry in a CS with skip list implementation
void setLimit(size_t nMaxPackets)
sets maximum allowed size of Content Store (in packets)
Definition: cs.cpp:95
Cs(size_t nMaxPackets=10)
Definition: cs.cpp:62
bool operator==(const const_iterator &other) const
Definition: cs.hpp:335