blob: 41a814b329aea5143634d2fb7be87dbfadfb34e7 [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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#include "ndn-pit-impl.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070022
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080023#include "ns3/ndn-interest.h"
24#include "ns3/ndn-content-object.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "ns3/ndn-forwarding-strategy.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070026
Alexander Afanasyev1a2df6a2012-08-17 13:21:51 -070027#include "../../utils/trie/empty-policy.h"
28#include "../../utils/trie/persistent-policy.h"
29#include "../../utils/trie/random-policy.h"
30#include "../../utils/trie/lru-policy.h"
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070031
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070032#include "ns3/log.h"
33#include "ns3/string.h"
34#include "ns3/uinteger.h"
35#include "ns3/simulator.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070036
37#include <boost/lambda/bind.hpp>
38#include <boost/lambda/lambda.hpp>
39
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070041
42using namespace boost::tuples;
43using namespace boost;
44namespace ll = boost::lambda;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070045
46#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
47 static struct X ## type ## templ ## RegistrationClass \
48 { \
49 X ## type ## templ ## RegistrationClass () { \
50 ns3::TypeId tid = type<templ>::GetTypeId (); \
51 tid.GetParent (); \
52 } \
53 } x_ ## type ## templ ## RegistrationVariable
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070054
55namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056namespace ndn {
57namespace pit {
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070058
Alexander Afanasyeve77db792012-08-09 11:10:58 -070059using namespace ndnSIM;
60
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070061template<>
62TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063PitImpl<persistent_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070064{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065 static TypeId tid = TypeId ("ns3::ndn::pit::Persistent")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070066 .SetGroupName ("Ndn")
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067 .SetParent<Pit> ()
68 .AddConstructor< PitImpl< persistent_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070069 .AddAttribute ("MaxSize",
70 "Set maximum number of entries in PIT. If 0, limit is not enforced",
71 StringValue ("0"),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070072 MakeUintegerAccessor (&PitImpl< persistent_policy_traits >::GetMaxSize,
73 &PitImpl< persistent_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070074 MakeUintegerChecker<uint32_t> ())
75 ;
76
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070077 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070078}
79
80template<>
81TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082PitImpl<random_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070083{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084 static TypeId tid = TypeId ("ns3::ndn::pit::Random")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070085 .SetGroupName ("Ndn")
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086 .SetParent<Pit> ()
87 .AddConstructor< PitImpl< random_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070088 .AddAttribute ("MaxSize",
89 "Set maximum number of entries in PIT. If 0, limit is not enforced",
90 StringValue ("0"),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091 MakeUintegerAccessor (&PitImpl< random_policy_traits >::GetMaxSize,
92 &PitImpl< random_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070093 MakeUintegerChecker<uint32_t> ())
94 ;
95
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070096 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070097}
98
99template<>
100TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101PitImpl<lru_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700102{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700103 static TypeId tid = TypeId ("ns3::ndn::pit::Lru")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700104 .SetGroupName ("Ndn")
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700105 .SetParent<Pit> ()
106 .AddConstructor< PitImpl< lru_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700107 .AddAttribute ("MaxSize",
108 "Set maximum number of entries in PIT. If 0, limit is not enforced",
109 StringValue ("0"),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110 MakeUintegerAccessor (&PitImpl< lru_policy_traits >::GetMaxSize,
111 &PitImpl< lru_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700112 MakeUintegerChecker<uint32_t> ())
113 ;
114
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700115 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700116}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700117
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700118template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119PitImpl<Policy>::PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700120{
121}
122
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700123template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124PitImpl<Policy>::~PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700125{
126}
127
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700128template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700129uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130PitImpl<Policy>::GetMaxSize () const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700131{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700132 return super::getPolicy ().get_max_size ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700133}
134
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700135template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700136void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700137PitImpl<Policy>::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700138{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700139 super::getPolicy ().set_max_size (maxSize);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700140}
141
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700142template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700143void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144PitImpl<Policy>::NotifyNewAggregate ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700145{
146 if (m_fib == 0)
147 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700148 m_fib = GetObject<Fib> ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700149 }
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700150 if (m_forwardingStrategy == 0)
151 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700152 m_forwardingStrategy = GetObject<ForwardingStrategy> ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700153 }
154
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700155 Pit::NotifyNewAggregate ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700156}
157
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700158template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700159void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160PitImpl<Policy>::DoDispose ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700161{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700162 super::clear ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700163
164 m_forwardingStrategy = 0;
165 m_fib = 0;
166
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 Pit::DoDispose ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700168}
169
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700170template<class Policy>
171void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700172PitImpl<Policy>::RescheduleCleaning ()
Alexander Afanasyevb18ae022012-09-03 21:46:36 -0700173{
174 // m_cleanEvent.Cancel ();
175 Simulator::Remove (m_cleanEvent); // slower, but better for memory
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700176 if (i_time.empty ())
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700177 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700178 // NS_LOG_DEBUG ("No items in PIT");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700179 return;
180 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700181
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700182 Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700183 if (nextEvent <= 0) nextEvent = Seconds (0);
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700184
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700185 NS_LOG_DEBUG ("Schedule next cleaning in " <<
186 nextEvent.ToDouble (Time::S) << "s (at " <<
187 i_time.begin ()->GetExpireTime () << "s abs time");
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700188
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700189 m_cleanEvent = Simulator::Schedule (nextEvent,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700190 &PitImpl<Policy>::CleanExpired, this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700191}
192
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700193template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700194void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700195PitImpl<Policy>::CleanExpired ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700196{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700197 NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700198 Time now = Simulator::Now ();
199
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700200 // uint32_t count = 0;
201 while (!i_time.empty ())
202 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700203 typename time_index::iterator entry = i_time.begin ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700204 if (entry->GetExpireTime () <= now) // is the record stale?
205 {
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700206 m_forwardingStrategy->WillEraseTimedOutPendingInterest (entry->to_iterator ()->payload ());
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700207 super::erase (entry->to_iterator ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700208 // count ++;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700209 }
210 else
211 break; // nothing else to do. All later records will not be stale
212 }
213
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700214 if (super::getPolicy ().size ())
215 {
216 NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ());
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700217 NS_LOG_DEBUG ("i_time size: " << i_time.size ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700218 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700219 RescheduleCleaning ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700220}
221
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700222template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700223Ptr<Entry>
224PitImpl<Policy>::Lookup (const ContentObjectHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700225{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700226 /// @todo use predicate to search with exclude filters
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700227 typename super::iterator item = super::longest_prefix_match (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700228
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700229 if (item == super::end ())
230 return 0;
231 else
232 return item->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700233}
234
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700235template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700236Ptr<Entry>
237PitImpl<Policy>::Lookup (const InterestHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700238{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700239 // NS_LOG_FUNCTION (header.GetName ());
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700240 NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700241 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700242
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700243 typename super::iterator foundItem, lastItem;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700244 bool reachLast;
245 boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700246
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700247 if (!reachLast || lastItem == super::end ())
248 return 0;
249 else
250 return lastItem->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700251}
252
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700253template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700254Ptr<Entry>
255PitImpl<Policy>::Create (Ptr<const InterestHeader> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700256{
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700257 NS_LOG_DEBUG (header->GetName ());
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700258 Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700259 if (fibEntry == 0)
260 return 0;
261
262 // NS_ASSERT_MSG (fibEntry != 0,
263 // "There should be at least default route set" <<
264 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700265
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700266 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700267 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700268 if (result.first != super::end ())
269 {
270 if (result.second)
271 {
272 newEntry->SetTrie (result.first);
273 return newEntry;
274 }
275 else
276 {
277 // should we do anything?
278 // update payload? add new payload?
279 return result.first->payload ();
280 }
281 }
282 else
283 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700284}
285
286
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700287template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700288void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700289PitImpl<Policy>::MarkErased (Ptr<Entry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700290{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700291 // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700292 super::erase (StaticCast< entry > (item)->to_iterator ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700293}
294
295
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700296template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700297void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700298PitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700299{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700300 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700301 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700302 for (; item != end; item++)
303 {
304 if (item->payload () == 0) continue;
305
306 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
307 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700308}
309
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700310template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700311uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700312PitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700313{
314 return super::getPolicy ().size ();
315}
316
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700317template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700318Ptr<Entry>
319PitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700320{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700321 typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700322 for (; item != end; item++)
323 {
324 if (item->payload () == 0) continue;
325 break;
326 }
327
328 if (item == end)
329 return End ();
330 else
331 return item->payload ();
332}
333
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700334template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700335Ptr<Entry>
336PitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700337{
338 return 0;
339}
340
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700341template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700342Ptr<Entry>
343PitImpl<Policy>::Next (Ptr<Entry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700344{
345 if (from == 0) return 0;
346
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700347 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700348 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700349 end (0);
350
351 for (item++; item != end; item++)
352 {
353 if (item->payload () == 0) continue;
354 break;
355 }
356
357 if (item == end)
358 return End ();
359 else
360 return item->payload ();
361}
362
363
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700364// explicit instantiation and registering
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700365template class PitImpl<persistent_policy_traits>;
366template class PitImpl<random_policy_traits>;
367template class PitImpl<lru_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700368
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700369NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits);
370NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits);
371NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700372
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800373#ifdef DOXYGEN
374// /**
375// * \brief PIT in which new entries will be rejected if PIT size reached its limit
376// */
377class Persistent : public PitImpl<persistent_policy_traits> { };
378
379/**
380 * \brief PIT in which PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT
381 */
382class Random : public PitImpl<random_policy_traits> { };
383
384/**
385 * \brief PIT in which the least recently used entry (the oldest entry with minimum number of incoming faces)
386 * will be removed when PIT size reached its limit
387 */
388class Lru : public PitImpl<lru_policy_traits> { };
389#endif
390
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700391} // namespace pit
392} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700393} // namespace ns3