blob: 9dfd62bc62b5c3c89d2b2ac4930c8624e11e2046 [file] [log] [blame]
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -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 _CCNX_PIT_IMPL_H_
22#define _CCNX_PIT_IMPL_H_
23
24#include "ccnx-pit.h"
25#include "../utils/trie-with-policy.h"
26#include "../utils/empty-policy.h"
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070027#include "../utils/persistent-policy.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070028#include "ns3/ccnx-name-components.h"
29
30namespace ns3 {
31
Alexander Afanasyev36b45772012-07-10 16:57:42 -070032template<class Pit>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070033class CcnxPitEntryImpl : public CcnxPitEntry
34{
35public:
Alexander Afanasyev36b45772012-07-10 16:57:42 -070036 CcnxPitEntryImpl (CcnxPit &pit,
37 Ptr<const CcnxInterestHeader> header,
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070038 Ptr<CcnxFibEntry> fibEntry)
Alexander Afanasyev36b45772012-07-10 16:57:42 -070039 : CcnxPitEntry (pit, header, fibEntry)
40 , item_ (0)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070041 {
Alexander Afanasyev36b45772012-07-10 16:57:42 -070042 static_cast<Pit&> (m_container).i_time.insert (*this);
43 }
44
45 virtual ~CcnxPitEntryImpl ()
46 {
47 static_cast<Pit&> (m_container).i_time.erase (*this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070048 }
49
Alexander Afanasyev36b45772012-07-10 16:57:42 -070050 // to make sure policies work
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070051 void
Alexander Afanasyev36b45772012-07-10 16:57:42 -070052 SetTrie (typename Pit::super::iterator item) { item_ = item; }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070053
Alexander Afanasyev36b45772012-07-10 16:57:42 -070054 typename Pit::super::iterator to_iterator () { return item_; }
55 typename Pit::super::const_iterator to_iterator () const { return item_; }
56
57public:
58 boost::intrusive::set_member_hook<> time_hook_;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070059
60private:
Alexander Afanasyev36b45772012-07-10 16:57:42 -070061 typename Pit::super::iterator item_;
62};
63
64template<class T>
65struct TimestampIndex
66{
67 bool
68 operator () (const T &a, const T &b) const
69 {
70 return a.GetExpireTime () < b.GetExpireTime ();
71 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070072};
73
74////////////////////////////////////////////////////////////////////////
75////////////////////////////////////////////////////////////////////////
76
77/**
78 * \ingroup ccnx
79 * \brief Class implementing Pending Interests Table
80 */
81class CcnxPitImpl : public CcnxPit
Alexander Afanasyev36b45772012-07-10 16:57:42 -070082 , protected ndnSIM::trie_with_policy<CcnxNameComponents,
83 ndnSIM::smart_pointer_payload_traits<CcnxPitEntryImpl< CcnxPitImpl > >,
84 ndnSIM::persistent_policy_traits
85 >
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070086{
87public:
Alexander Afanasyev36b45772012-07-10 16:57:42 -070088 typedef ndnSIM::trie_with_policy<CcnxNameComponents,
89 ndnSIM::smart_pointer_payload_traits<CcnxPitEntryImpl< CcnxPitImpl > >,
90 ndnSIM::persistent_policy_traits
91 > super;
92 typedef CcnxPitEntryImpl< CcnxPitImpl > entry;
93
94 // typedef CcnxPitEntryImpl::trie super;
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -070095
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070096 /**
97 * \brief Interface ID
98 *
99 * \return interface ID
100 */
101 static TypeId GetTypeId ();
102
103 /**
104 * \brief PIT constructor
105 */
106 CcnxPitImpl ();
107
108 /**
109 * \brief Destructor
110 */
111 virtual ~CcnxPitImpl ();
112
113 // inherited from CcnxPit
114 virtual Ptr<CcnxPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700115 Lookup (const CcnxContentObjectHeader &header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700116
117 virtual Ptr<CcnxPitEntry>
118 Lookup (const CcnxInterestHeader &header);
119
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700120 virtual Ptr<CcnxPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700121 Create (Ptr<const CcnxInterestHeader> header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700122
123 virtual void
124 MarkErased (Ptr<CcnxPitEntry> entry);
125
126 virtual void
127 Print (std::ostream &os) const;
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -0700128
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700129 virtual Ptr<CcnxPitEntry>
130 Begin ();
131
132 virtual Ptr<CcnxPitEntry>
133 End ();
134
135 virtual Ptr<CcnxPitEntry>
136 Next (Ptr<CcnxPitEntry>);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700137
138protected:
139 // inherited from CcnxPit
140 virtual void DoCleanExpired ();
141
142 // inherited from Object class
143 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
144 virtual void DoDispose (); ///< @brief Do cleanup
145
146private:
147 uint32_t
148 GetMaxSize () const;
149
150 void
151 SetMaxSize (uint32_t maxSize);
152
153private:
154 Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700155
156 // indexes
157 typedef
158 boost::intrusive::set<entry,
159 boost::intrusive::compare < TimestampIndex< entry > >,
160 boost::intrusive::member_hook< entry,
161 boost::intrusive::set_member_hook<>,
162 &entry::time_hook_>
163 > expireTimeIndexType;
164 expireTimeIndexType i_time;
165
166 friend class CcnxPitEntryImpl< CcnxPitImpl >;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700167};
168
169} // namespace ns3
170
171#endif /* CCNX_PIT_IMPL_H */