blob: b5f3eaaa9ed933029116d5eab40049ec9f952aa9 [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 Afanasyev4aac5572012-08-09 10:49:55 -070023#include "ns3/ndn-interest-header.h"
24#include "ns3/ndn-content-object-header.h"
25#include "ns3/ndn-forwarding-strategy.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070026
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070027#include "../../utils/empty-policy.h"
28#include "../../utils/persistent-policy.h"
29#include "../../utils/random-policy.h"
30#include "../../utils/lru-policy.h"
31
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 Afanasyev4aac5572012-08-09 10:49:55 -070040NS_LOG_COMPONENT_DEFINE ("NdnPitImpl");
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 {
56
Alexander Afanasyeve77db792012-08-09 11:10:58 -070057using namespace ndnSIM;
58
59
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070060template<>
61TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062NdnPitImpl<persistent_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070063{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070064 static TypeId tid = TypeId ("ns3::NdnPit")
65 .SetGroupName ("Ndn")
66 .SetParent<NdnPit> ()
67 .AddConstructor< NdnPitImpl< persistent_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070068 .AddAttribute ("MaxSize",
69 "Set maximum number of entries in PIT. If 0, limit is not enforced",
70 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071 MakeUintegerAccessor (&NdnPitImpl< persistent_policy_traits >::GetMaxSize,
72 &NdnPitImpl< persistent_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070073 MakeUintegerChecker<uint32_t> ())
74 ;
75
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070076 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070077}
78
79template<>
80TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081NdnPitImpl<random_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070082{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083 static TypeId tid = TypeId ("ns3::NdnPitRandom")
84 .SetGroupName ("Ndn")
85 .SetParent<NdnPit> ()
86 .AddConstructor< NdnPitImpl< random_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070087 .AddAttribute ("MaxSize",
88 "Set maximum number of entries in PIT. If 0, limit is not enforced",
89 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070090 MakeUintegerAccessor (&NdnPitImpl< random_policy_traits >::GetMaxSize,
91 &NdnPitImpl< random_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070092 MakeUintegerChecker<uint32_t> ())
93 ;
94
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070095 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070096}
97
98template<>
99TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700100NdnPitImpl<lru_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700101{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700102 static TypeId tid = TypeId ("ns3::NdnPitLru")
103 .SetGroupName ("Ndn")
104 .SetParent<NdnPit> ()
105 .AddConstructor< NdnPitImpl< lru_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700106 .AddAttribute ("MaxSize",
107 "Set maximum number of entries in PIT. If 0, limit is not enforced",
108 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700109 MakeUintegerAccessor (&NdnPitImpl< lru_policy_traits >::GetMaxSize,
110 &NdnPitImpl< lru_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700111 MakeUintegerChecker<uint32_t> ())
112 ;
113
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700114 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700115}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700116
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700117// template<class Policy>
118// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700119// NdnPitImpl<Policy>::GetTypeId ()
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700120// {
121// static TypeId tid = TypeId ("ns3::UnknownPitPolicy");
122
123// return tid;
124// }
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700125
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700126// NdnPitEntryImpl::NdnPitEntryImpl (NdnPit &pit,
127// Ptr<const NdnInterestHeader> header,
128// Ptr<NdnFibEntry> fibEntry)
129// : NdnPitEntry (pit, header, fibEntry)
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700130// , item_ (0)
131// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700132// static_cast<NdnPitImpl&> (m_container).i_time.insert (*this);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700133// }
134
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700135// NdnPitEntryImpl::~NdnPitEntryImpl ()
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700136// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700137// static_cast<NdnPitImpl&> (m_container).i_time.erase (*this);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700138// }
139
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700140// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700141// NdnPitImpl::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700142// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700143// static TypeId tid = TypeId ("ns3::NdnPit")
144// .SetGroupName ("Ndn")
145// .SetParent<NdnPit> ()
146// .AddConstructor<NdnPitImpl> ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700147// .AddAttribute ("MaxSize",
148// "Set maximum number of entries in PIT. If 0, limit is not enforced",
149// StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700150// MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700151// MakeUintegerChecker<uint32_t> ())
152// ;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700153
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700154// return tid;
155// }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700156
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700157
158// template<class AcceptanceAndReplacementPolicy>
159// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700160// NdnPitImpl::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700161// {
162// #error "Not specialized version is not supported"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700163// // static TypeId tid = TypeId ("ns3::NdnPit")
164// // .SetGroupName ("Ndn")
165// // .SetParent<NdnPit> ()
166// // .AddConstructor<NdnPitImpl> ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700167// // .AddAttribute ("MaxSize",
168// // "Set maximum number of entries in PIT. If 0, limit is not enforced",
169// // StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700170// // MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700171// // MakeUintegerChecker<uint32_t> ())
172// // ;
173
174// return Typeid ();
175// }
176
177template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700178NdnPitImpl<Policy>::NdnPitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700179{
180}
181
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700182template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700183NdnPitImpl<Policy>::~NdnPitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700184{
185}
186
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700187template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700188uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700189NdnPitImpl<Policy>::GetMaxSize () const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700190{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700191 return super::getPolicy ().get_max_size ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700192}
193
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700194template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700195void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700196NdnPitImpl<Policy>::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700197{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700198 super::getPolicy ().set_max_size (maxSize);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700199}
200
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700201template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700202void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700203NdnPitImpl<Policy>::NotifyNewAggregate ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700204{
205 if (m_fib == 0)
206 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700207 m_fib = GetObject<NdnFib> ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700208 }
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700209 if (m_forwardingStrategy == 0)
210 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700211 m_forwardingStrategy = GetObject<NdnForwardingStrategy> ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700212 }
213
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700214 NdnPit::NotifyNewAggregate ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700215}
216
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700217template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700218void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700219NdnPitImpl<Policy>::DoDispose ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700220{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700221 super::clear ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700222
223 m_forwardingStrategy = 0;
224 m_fib = 0;
225
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700226 NdnPit::DoDispose ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700227}
228
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700229template<class Policy>
230void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700231NdnPitImpl<Policy>::RescheduleCleaning ()
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700232{
233 m_cleanEvent.Cancel ();
234 if (i_time.empty ())
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700235 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700236 // NS_LOG_DEBUG ("No items in PIT");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700237 return;
238 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700239
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700240 Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700241 if (nextEvent <= 0) nextEvent = Seconds (0);
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700242
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700243 // NS_LOG_DEBUG ("Schedule next cleaning in " <<
244 // nextEvent.ToDouble (Time::S) << "s (at " <<
245 // i_time.begin ()->GetExpireTime () << "s abs time");
246
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700247 m_cleanEvent = Simulator::Schedule (nextEvent,
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700248 &NdnPitImpl<Policy>::CleanExpired, this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700249}
250
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700251template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700252void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700253NdnPitImpl<Policy>::CleanExpired ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700254{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700255 NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700256 Time now = Simulator::Now ();
257
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700258 // uint32_t count = 0;
259 while (!i_time.empty ())
260 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700261 typename time_index::iterator entry = i_time.begin ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700262 if (entry->GetExpireTime () <= now) // is the record stale?
263 {
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700264 m_forwardingStrategy->WillErasePendingInterest (entry->to_iterator ()->payload ());
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700265 super::erase (entry->to_iterator ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700266 // count ++;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700267 }
268 else
269 break; // nothing else to do. All later records will not be stale
270 }
271
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700272 if (super::getPolicy ().size ())
273 {
274 NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ());
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700275 NS_LOG_DEBUG ("i_time size: " << i_time.size ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700276 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700277 RescheduleCleaning ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700278}
279
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700280template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700281Ptr<NdnPitEntry>
282NdnPitImpl<Policy>::Lookup (const NdnContentObjectHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700283{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700284 /// @todo use predicate to search with exclude filters
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700285 typename super::iterator item = super::longest_prefix_match (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700286
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700287 if (item == super::end ())
288 return 0;
289 else
290 return item->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700291}
292
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700293template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700294Ptr<NdnPitEntry>
295NdnPitImpl<Policy>::Lookup (const NdnInterestHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700296{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700297 // NS_LOG_FUNCTION (header.GetName ());
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700298 NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700299 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700300
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700301 typename super::iterator foundItem, lastItem;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700302 bool reachLast;
303 boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700304
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700305 if (!reachLast || lastItem == super::end ())
306 return 0;
307 else
308 return lastItem->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700309}
310
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700311template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700312Ptr<NdnPitEntry>
313NdnPitImpl<Policy>::Create (Ptr<const NdnInterestHeader> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700314{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700315 Ptr<NdnFibEntry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700316 if (fibEntry == 0)
317 return 0;
318
319 // NS_ASSERT_MSG (fibEntry != 0,
320 // "There should be at least default route set" <<
321 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700322
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700323 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700324 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700325 if (result.first != super::end ())
326 {
327 if (result.second)
328 {
329 newEntry->SetTrie (result.first);
330 return newEntry;
331 }
332 else
333 {
334 // should we do anything?
335 // update payload? add new payload?
336 return result.first->payload ();
337 }
338 }
339 else
340 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700341}
342
343
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700344template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700345void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700346NdnPitImpl<Policy>::MarkErased (Ptr<NdnPitEntry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700347{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700348 // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700349 super::erase (StaticCast< entry > (item)->to_iterator ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700350}
351
352
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700353template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700354void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700355NdnPitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700356{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700357 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700358 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700359 for (; item != end; item++)
360 {
361 if (item->payload () == 0) continue;
362
363 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
364 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700365}
366
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700367template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700368uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700369NdnPitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700370{
371 return super::getPolicy ().size ();
372}
373
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700374template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700375Ptr<NdnPitEntry>
376NdnPitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700377{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700378 typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700379 for (; item != end; item++)
380 {
381 if (item->payload () == 0) continue;
382 break;
383 }
384
385 if (item == end)
386 return End ();
387 else
388 return item->payload ();
389}
390
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700391template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700392Ptr<NdnPitEntry>
393NdnPitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700394{
395 return 0;
396}
397
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700398template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700399Ptr<NdnPitEntry>
400NdnPitImpl<Policy>::Next (Ptr<NdnPitEntry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700401{
402 if (from == 0) return 0;
403
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700404 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700405 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700406 end (0);
407
408 for (item++; item != end; item++)
409 {
410 if (item->payload () == 0) continue;
411 break;
412 }
413
414 if (item == end)
415 return End ();
416 else
417 return item->payload ();
418}
419
420
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700421// explicit instantiation and registering
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700422template class NdnPitImpl<persistent_policy_traits>;
423template class NdnPitImpl<random_policy_traits>;
424template class NdnPitImpl<lru_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700425
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700426NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, persistent_policy_traits);
427NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, random_policy_traits);
428NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, lru_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700429
430
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700431} // namespace ns3