blob: 4b047eef135411627ceb7a434cac1d08377e6493 [file] [log] [blame]
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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 */
20
21#ifndef NDN_CONTENT_STORE_IMPL_H_
22#define NDN_CONTENT_STORE_IMPL_H_
23
24#include "ndn-content-store.h"
25#include "ns3/packet.h"
26#include "ns3/ndn-interest-header.h"
27#include "ns3/ndn-content-object-header.h"
28#include <boost/foreach.hpp>
29
30#include "../../utils/trie-with-policy.h"
31
32namespace ns3 {
33namespace ndn {
34namespace cs {
35
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070036template<class CS>
37class EntryImpl : public Entry
38{
39public:
40 EntryImpl (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet)
41 : Entry (header, packet)
42 , item_ (0)
43 {
44 }
45
46 void
47 SetTrie (typename CS::super::iterator item)
48 {
49 item_ = item;
50 }
51
52 typename CS::super::iterator to_iterator () { return item_; }
53 typename CS::super::const_iterator to_iterator () const { return item_; }
54
55private:
56 typename CS::super::iterator item_;
57};
58
59
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060
61template<class Policy>
62class ContentStoreImpl : public ContentStore,
63 protected ndnSIM::trie_with_policy< NameComponents,
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070064 ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065 Policy >
66{
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070067public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070068 typedef ndnSIM::trie_with_policy< NameComponents,
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070069 ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 Policy > super;
71
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070072 typedef EntryImpl< ContentStoreImpl< Policy > > entry;
73
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070074 static TypeId
75 GetTypeId ();
76
77 ContentStoreImpl () { };
78 virtual ~ContentStoreImpl () { };
79
80 // from ContentStore
81
82 virtual inline boost::tuple<Ptr<Packet>, Ptr<const ContentObjectHeader>, Ptr<const Packet> >
83 Lookup (Ptr<const InterestHeader> interest);
84
85 virtual inline bool
86 Add (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet);
87
88 // virtual bool
89 // Remove (Ptr<InterestHeader> header);
90
91 virtual inline void
92 Print (std::ostream &os) const;
93
Alexander Afanasyev29c19b92012-09-03 23:46:41 -070094 virtual uint32_t
95 GetSize () const;
96
97 virtual Ptr<Entry>
98 Begin ();
99
100 virtual Ptr<Entry>
101 End ();
102
103 virtual Ptr<Entry>
104 Next (Ptr<Entry>);
105
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106private:
107 void
108 SetMaxSize (uint32_t maxSize);
109
110 uint32_t
111 GetMaxSize () const;
112};
113
114} // namespace cs
115} // namespace ndn
116} // namespace ns3
117
118#endif // NDN_CONTENT_STORE_IMPL_H_