blob: dcf6adac25780d74a21b694ae0c67eef7776948c [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 -070045using namespace ndnSIM;
46
47#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
48 static struct X ## type ## templ ## RegistrationClass \
49 { \
50 X ## type ## templ ## RegistrationClass () { \
51 ns3::TypeId tid = type<templ>::GetTypeId (); \
52 tid.GetParent (); \
53 } \
54 } x_ ## type ## templ ## RegistrationVariable
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070055
56namespace ns3 {
57
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070058template<>
59TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070060NdnPitImpl<persistent_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070061{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062 static TypeId tid = TypeId ("ns3::NdnPit")
63 .SetGroupName ("Ndn")
64 .SetParent<NdnPit> ()
65 .AddConstructor< NdnPitImpl< persistent_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070066 .AddAttribute ("MaxSize",
67 "Set maximum number of entries in PIT. If 0, limit is not enforced",
68 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070069 MakeUintegerAccessor (&NdnPitImpl< persistent_policy_traits >::GetMaxSize,
70 &NdnPitImpl< persistent_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070071 MakeUintegerChecker<uint32_t> ())
72 ;
73
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070074 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070075}
76
77template<>
78TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079NdnPitImpl<random_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070080{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081 static TypeId tid = TypeId ("ns3::NdnPitRandom")
82 .SetGroupName ("Ndn")
83 .SetParent<NdnPit> ()
84 .AddConstructor< NdnPitImpl< random_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070085 .AddAttribute ("MaxSize",
86 "Set maximum number of entries in PIT. If 0, limit is not enforced",
87 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070088 MakeUintegerAccessor (&NdnPitImpl< random_policy_traits >::GetMaxSize,
89 &NdnPitImpl< random_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070090 MakeUintegerChecker<uint32_t> ())
91 ;
92
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -070093 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070094}
95
96template<>
97TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070098NdnPitImpl<lru_policy_traits>::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070099{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700100 static TypeId tid = TypeId ("ns3::NdnPitLru")
101 .SetGroupName ("Ndn")
102 .SetParent<NdnPit> ()
103 .AddConstructor< NdnPitImpl< lru_policy_traits > > ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700104 .AddAttribute ("MaxSize",
105 "Set maximum number of entries in PIT. If 0, limit is not enforced",
106 StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700107 MakeUintegerAccessor (&NdnPitImpl< lru_policy_traits >::GetMaxSize,
108 &NdnPitImpl< lru_policy_traits >::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700109 MakeUintegerChecker<uint32_t> ())
110 ;
111
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700112 return tid;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700113}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700114
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700115// template<class Policy>
116// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700117// NdnPitImpl<Policy>::GetTypeId ()
Alexander Afanasyev0a0dc392012-07-27 13:41:49 -0700118// {
119// static TypeId tid = TypeId ("ns3::UnknownPitPolicy");
120
121// return tid;
122// }
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700123
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700124// NdnPitEntryImpl::NdnPitEntryImpl (NdnPit &pit,
125// Ptr<const NdnInterestHeader> header,
126// Ptr<NdnFibEntry> fibEntry)
127// : NdnPitEntry (pit, header, fibEntry)
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700128// , item_ (0)
129// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700130// static_cast<NdnPitImpl&> (m_container).i_time.insert (*this);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700131// }
132
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700133// NdnPitEntryImpl::~NdnPitEntryImpl ()
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700134// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700135// static_cast<NdnPitImpl&> (m_container).i_time.erase (*this);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700136// }
137
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700138// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700139// NdnPitImpl::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700140// {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700141// static TypeId tid = TypeId ("ns3::NdnPit")
142// .SetGroupName ("Ndn")
143// .SetParent<NdnPit> ()
144// .AddConstructor<NdnPitImpl> ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700145// .AddAttribute ("MaxSize",
146// "Set maximum number of entries in PIT. If 0, limit is not enforced",
147// StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700148// MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700149// MakeUintegerChecker<uint32_t> ())
150// ;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700151
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700152// return tid;
153// }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700154
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700155
156// template<class AcceptanceAndReplacementPolicy>
157// TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700158// NdnPitImpl::GetTypeId ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700159// {
160// #error "Not specialized version is not supported"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700161// // static TypeId tid = TypeId ("ns3::NdnPit")
162// // .SetGroupName ("Ndn")
163// // .SetParent<NdnPit> ()
164// // .AddConstructor<NdnPitImpl> ()
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700165// // .AddAttribute ("MaxSize",
166// // "Set maximum number of entries in PIT. If 0, limit is not enforced",
167// // StringValue ("0"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168// // MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize),
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700169// // MakeUintegerChecker<uint32_t> ())
170// // ;
171
172// return Typeid ();
173// }
174
175template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700176NdnPitImpl<Policy>::NdnPitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700177{
178}
179
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700180template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700181NdnPitImpl<Policy>::~NdnPitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700182{
183}
184
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700185template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700186uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700187NdnPitImpl<Policy>::GetMaxSize () const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700188{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700189 return super::getPolicy ().get_max_size ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700190}
191
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700192template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700193void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700194NdnPitImpl<Policy>::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700195{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700196 super::getPolicy ().set_max_size (maxSize);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700197}
198
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700199template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700200void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700201NdnPitImpl<Policy>::NotifyNewAggregate ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700202{
203 if (m_fib == 0)
204 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700205 m_fib = GetObject<NdnFib> ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700206 }
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700207 if (m_forwardingStrategy == 0)
208 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700209 m_forwardingStrategy = GetObject<NdnForwardingStrategy> ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700210 }
211
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700212 NdnPit::NotifyNewAggregate ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700213}
214
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700215template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700216void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700217NdnPitImpl<Policy>::DoDispose ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700218{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700219 super::clear ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700220
221 m_forwardingStrategy = 0;
222 m_fib = 0;
223
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700224 NdnPit::DoDispose ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700225}
226
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700227template<class Policy>
228void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700229NdnPitImpl<Policy>::RescheduleCleaning ()
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700230{
231 m_cleanEvent.Cancel ();
232 if (i_time.empty ())
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700233 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700234 // NS_LOG_DEBUG ("No items in PIT");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700235 return;
236 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700237
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700238 Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700239 if (nextEvent <= 0) nextEvent = Seconds (0);
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700240
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700241 // NS_LOG_DEBUG ("Schedule next cleaning in " <<
242 // nextEvent.ToDouble (Time::S) << "s (at " <<
243 // i_time.begin ()->GetExpireTime () << "s abs time");
244
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700245 m_cleanEvent = Simulator::Schedule (nextEvent,
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700246 &NdnPitImpl<Policy>::CleanExpired, this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700247}
248
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700249template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700250void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700251NdnPitImpl<Policy>::CleanExpired ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700252{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700253 NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700254 Time now = Simulator::Now ();
255
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700256 // uint32_t count = 0;
257 while (!i_time.empty ())
258 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700259 typename time_index::iterator entry = i_time.begin ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700260 if (entry->GetExpireTime () <= now) // is the record stale?
261 {
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700262 m_forwardingStrategy->WillErasePendingInterest (entry->to_iterator ()->payload ());
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700263 super::erase (entry->to_iterator ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700264 // count ++;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700265 }
266 else
267 break; // nothing else to do. All later records will not be stale
268 }
269
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700270 if (super::getPolicy ().size ())
271 {
272 NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ());
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700273 NS_LOG_DEBUG ("i_time size: " << i_time.size ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700274 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700275 RescheduleCleaning ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700276}
277
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700278template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700279Ptr<NdnPitEntry>
280NdnPitImpl<Policy>::Lookup (const NdnContentObjectHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700281{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700282 /// @todo use predicate to search with exclude filters
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700283 typename super::iterator item = super::longest_prefix_match (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700284
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700285 if (item == super::end ())
286 return 0;
287 else
288 return item->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700289}
290
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700291template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700292Ptr<NdnPitEntry>
293NdnPitImpl<Policy>::Lookup (const NdnInterestHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700294{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700295 // NS_LOG_FUNCTION (header.GetName ());
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700296 NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700297 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700298
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700299 typename super::iterator foundItem, lastItem;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700300 bool reachLast;
301 boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700302
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700303 if (!reachLast || lastItem == super::end ())
304 return 0;
305 else
306 return lastItem->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700307}
308
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700309template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700310Ptr<NdnPitEntry>
311NdnPitImpl<Policy>::Create (Ptr<const NdnInterestHeader> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700312{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700313 Ptr<NdnFibEntry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700314 if (fibEntry == 0)
315 return 0;
316
317 // NS_ASSERT_MSG (fibEntry != 0,
318 // "There should be at least default route set" <<
319 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700320
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700321 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700322 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700323 if (result.first != super::end ())
324 {
325 if (result.second)
326 {
327 newEntry->SetTrie (result.first);
328 return newEntry;
329 }
330 else
331 {
332 // should we do anything?
333 // update payload? add new payload?
334 return result.first->payload ();
335 }
336 }
337 else
338 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700339}
340
341
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700342template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700343void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700344NdnPitImpl<Policy>::MarkErased (Ptr<NdnPitEntry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700345{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700346 // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700347 super::erase (StaticCast< entry > (item)->to_iterator ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700348}
349
350
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700351template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700352void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700353NdnPitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700354{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700355 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700356 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700357 for (; item != end; item++)
358 {
359 if (item->payload () == 0) continue;
360
361 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
362 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700363}
364
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700365template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700366uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700367NdnPitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700368{
369 return super::getPolicy ().size ();
370}
371
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700372template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700373Ptr<NdnPitEntry>
374NdnPitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700375{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700376 typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700377 for (; item != end; item++)
378 {
379 if (item->payload () == 0) continue;
380 break;
381 }
382
383 if (item == end)
384 return End ();
385 else
386 return item->payload ();
387}
388
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700389template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700390Ptr<NdnPitEntry>
391NdnPitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700392{
393 return 0;
394}
395
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700396template<class Policy>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700397Ptr<NdnPitEntry>
398NdnPitImpl<Policy>::Next (Ptr<NdnPitEntry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700399{
400 if (from == 0) return 0;
401
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700402 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700403 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700404 end (0);
405
406 for (item++; item != end; item++)
407 {
408 if (item->payload () == 0) continue;
409 break;
410 }
411
412 if (item == end)
413 return End ();
414 else
415 return item->payload ();
416}
417
418
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700419// explicit instantiation and registering
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700420template class NdnPitImpl<persistent_policy_traits>;
421template class NdnPitImpl<random_policy_traits>;
422template class NdnPitImpl<lru_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700423
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700424NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, persistent_policy_traits);
425NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, random_policy_traits);
426NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, lru_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700427
428
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700429} // namespace ns3