NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-content-store.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef NDN_CONTENT_STORE_H
21 #define NDN_CONTENT_STORE_H
22 
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
24 
25 #include "ns3/object.h"
26 #include "ns3/ptr.h"
27 #include "ns3/traced-callback.h"
28 
29 #include <tuple>
30 
31 namespace ns3 {
32 
33 class Packet;
34 
35 namespace ndn {
36 
37 class ContentStore;
38 
48 namespace cs {
49 
54 class Entry : public SimpleRefCount<Entry> {
55 public:
65  Entry(Ptr<ContentStore> cs, shared_ptr<const Data> data);
66 
71  const Name&
72  GetName() const;
73 
78  shared_ptr<const Data>
79  GetData() const;
80 
84  Ptr<ContentStore>
86 
87 private:
88  Ptr<ContentStore> m_cs;
89  shared_ptr<const Data> m_data;
90 };
91 
92 } // namespace cs
93 
100 class ContentStore : public Object {
101 public:
107  static TypeId
108  GetTypeId();
109 
113  virtual ~ContentStore();
114 
123  virtual shared_ptr<Data>
124  Lookup(shared_ptr<const Interest> interest) = 0;
125 
130  virtual bool
131  Add(shared_ptr<const Data> data) = 0;
132 
133  // /*
134  // * \brief Add a new content to the content store.
135  // *
136  // * \param header Interest header for which an entry should be removed
137  // * @returns true if an existing entry was removed, false otherwise
138  // */
139  // virtual bool
140  // Remove (shared_ptr<Interest> header) = 0;
141 
145  virtual void
146  Print(std::ostream& os) const = 0;
147 
151  virtual uint32_t
152  GetSize() const = 0;
153 
157  virtual Ptr<cs::Entry>
158  Begin() = 0;
159 
163  virtual Ptr<cs::Entry>
164  End() = 0;
165 
169  virtual Ptr<cs::Entry> Next(Ptr<cs::Entry>) = 0;
170 
174 
178  static inline Ptr<ContentStore>
179  GetContentStore(Ptr<Object> node);
180 
181 public:
182  typedef void (*CacheHitsCallback)(shared_ptr<const Interest>, shared_ptr<const Data>);
183  typedef void (*CacheMissesCallback)(shared_ptr<const Interest>);
184 
185 protected:
186  TracedCallback<shared_ptr<const Interest>,
187  shared_ptr<const Data>> m_cacheHitsTrace;
188 
189  TracedCallback<shared_ptr<const Interest>> m_cacheMissesTrace;
190 };
191 
192 inline std::ostream&
193 operator<<(std::ostream& os, const ContentStore& cs)
194 {
195  cs.Print(os);
196  return os;
197 }
198 
199 inline Ptr<ContentStore>
201 {
202  return node->GetObject<ContentStore>();
203 }
204 
205 } // namespace ndn
206 } // namespace ns3
207 
208 #include <boost/functional/hash.hpp>
209 namespace boost {
210 inline std::size_t
211 hash_value(const ::ndn::name::Component component)
212 {
213  return boost::hash_range(component.wireEncode().wire(),
214  component.wireEncode().wire() + component.wireEncode().size());
215 }
216 }
217 
218 #endif // NDN_CONTENT_STORE_H
Copyright (c) 2011-2015 Regents of the University of California.
std::size_t hash_value(const ::ndn::name::Component component)
Copyright (c) 2013-2015 Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const ContentStore &cs)
const Name & GetName() const
Get prefix of the stored entry.
Entry(Ptr< ContentStore > cs, shared_ptr< const Data > data)
Construct content store entry.
NDN content store entry.
TracedCallback< shared_ptr< const Interest > > m_cacheMissesTrace
trace of cache misses
static Ptr< ContentStore > GetContentStore(Ptr< Object > node)
Static call to cheat python bindings.
virtual void Print(std::ostream &os) const =0
Print out content store entries.
shared_ptr< const Data > GetData() const
Get Data of the stored entry.
Copyright (c) 2011-2015 Regents of the University of California.
TracedCallback< shared_ptr< const Interest >, shared_ptr< const Data > > m_cacheHitsTrace
trace of cache hits
ndn cs ContentStore
Copyright (c) 2011-2015 Regents of the University of California.
Ptr< ContentStore > GetContentStore()
Get pointer to access store, to which this entry is added.
Base class for NDN content store.