NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-content-store.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011,2012 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  * Ilya Moiseenko <iliamo@cs.ucla.edu>
20  */
21 
22 #ifndef NDN_CONTENT_STORE_H
23 #define NDN_CONTENT_STORE_H
24 
25 #include "ns3/object.h"
26 #include "ns3/ptr.h"
27 #include "ns3/traced-callback.h"
28 
29 #include <boost/tuple/tuple.hpp>
30 
31 namespace ns3 {
32 
33 class Packet;
34 
35 namespace ndn {
36 
37 class Data;
38 class Interest;
39 class Name;
40 class ContentStore;
41 
51 namespace cs {
52 
57 class Entry : public SimpleRefCount<Entry>
58 {
59 public:
69  Entry (Ptr<ContentStore> cs, Ptr<const Data> data);
70 
75  const Name&
76  GetName () const;
77 
82  Ptr<const Data>
83  GetData () const;
84 
88  Ptr<ContentStore>
89  GetContentStore ();
90 
91 private:
92  Ptr<ContentStore> m_cs;
93  Ptr<const Data> m_data;
94 };
95 
96 } // namespace cs
97 
98 
105 class ContentStore : public Object
106 {
107 public:
113  static
114  TypeId GetTypeId ();
115 
119  virtual
120  ~ContentStore ();
121 
131  virtual Ptr<Data>
132  Lookup (Ptr<const Interest> interest) = 0;
133 
142  virtual bool
143  Add (Ptr<const Data> data) = 0;
144 
145  // /*
146  // * \brief Add a new content to the content store.
147  // *
148  // * \param header Interest header for which an entry should be removed
149  // * @returns true if an existing entry was removed, false otherwise
150  // */
151  // virtual bool
152  // Remove (Ptr<Interest> header) = 0;
153 
157  virtual void
158  Print (std::ostream &os) const = 0;
159 
160 
164  virtual uint32_t
165  GetSize () const = 0;
166 
170  virtual Ptr<cs::Entry>
171  Begin () = 0;
172 
176  virtual Ptr<cs::Entry>
177  End () = 0;
178 
182  virtual Ptr<cs::Entry>
183  Next (Ptr<cs::Entry>) = 0;
184 
188 
192  static inline Ptr<ContentStore>
193  GetContentStore (Ptr<Object> node);
194 
195 protected:
196  TracedCallback<Ptr<const Interest>,
197  Ptr<const Data> > m_cacheHitsTrace;
198 
199  TracedCallback<Ptr<const Interest> > m_cacheMissesTrace;
200 };
201 
202 inline std::ostream&
203 operator<< (std::ostream &os, const ContentStore &cs)
204 {
205  cs.Print (os);
206  return os;
207 }
208 
209 inline Ptr<ContentStore>
211 {
212  return node->GetObject<ContentStore> ();
213 }
214 
215 
216 } // namespace ndn
217 } // namespace ns3
218 
219 #endif // NDN_CONTENT_STORE_H
Base class for NDN content store.
const Name & GetName() const
Get prefix of the stored entry.
virtual Ptr< Data > Lookup(Ptr< const Interest > interest)=0
Find corresponding CS entry for the given interest.
Class for NDN Name.
Definition: name.h:29
TracedCallback< Ptr< const Interest >, Ptr< const Data > > m_cacheHitsTrace
trace of cache hits
virtual ~ContentStore()
Virtual destructor.
virtual Ptr< cs::Entry > Next(Ptr< cs::Entry >)=0
Advance the iterator.
TracedCallback< Ptr< const Interest > > m_cacheMissesTrace
trace of cache misses
virtual bool Add(Ptr< const Data > data)=0
Add a new content to the content store.
NDN content store entry.
static TypeId GetTypeId()
Interface ID.
static Ptr< ContentStore > GetContentStore(Ptr< Object > node)
Static call to cheat python bindings.
virtual Ptr< cs::Entry > Begin()=0
Return first element of content store (no order guaranteed)
virtual Ptr< cs::Entry > End()=0
Return item next after last (no order guaranteed)
virtual uint32_t GetSize() const =0
Get number of entries in content store.
Ptr< const Data > GetData() const
Get Data of the stored entry.
Ptr< ContentStore > GetContentStore()
Get pointer to access store, to which this entry is added.
virtual void Print(std::ostream &os) const =0
Print out content store entries.
Entry(Ptr< ContentStore > cs, Ptr< const Data > data)
Construct content store entry.