blob: 3a61c093d4865b72608f041ae15dececc29ba99e [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"
Alexander Afanasyev1fb9fed2013-02-01 23:18:04 -080033
34NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
35
36#include "custom-policies/serialized-size-policy.h"
37
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070038#include "ns3/string.h"
39#include "ns3/uinteger.h"
40#include "ns3/simulator.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070041
42#include <boost/lambda/bind.hpp>
43#include <boost/lambda/lambda.hpp>
44
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070045
46using namespace boost::tuples;
47using namespace boost;
48namespace ll = boost::lambda;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070049
50#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
51 static struct X ## type ## templ ## RegistrationClass \
52 { \
53 X ## type ## templ ## RegistrationClass () { \
54 ns3::TypeId tid = type<templ>::GetTypeId (); \
55 tid.GetParent (); \
56 } \
57 } x_ ## type ## templ ## RegistrationVariable
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070058
59namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060namespace ndn {
61namespace pit {
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070062
Alexander Afanasyeve77db792012-08-09 11:10:58 -070063using namespace ndnSIM;
64
Alexander Afanasyev7456b702013-02-01 22:41:48 -080065template<class Policy>
66uint32_t
67PitImpl<Policy>::GetCurrentSize () const
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070068{
Alexander Afanasyev7456b702013-02-01 22:41:48 -080069 return super::getPolicy ().size ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070070}
71
72template<>
Alexander Afanasyev7456b702013-02-01 22:41:48 -080073uint32_t
74PitImpl<serialized_size_policy_traits>::GetCurrentSize () const
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070075{
Alexander Afanasyev7456b702013-02-01 22:41:48 -080076 return super::getPolicy ().get_current_space_used ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070077}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070078
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070079template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080PitImpl<Policy>::PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070081{
82}
83
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070084template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070085PitImpl<Policy>::~PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070086{
87}
88
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070089template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070090uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091PitImpl<Policy>::GetMaxSize () const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070092{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070093 return super::getPolicy ().get_max_size ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070094}
95
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070096template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070097void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098PitImpl<Policy>::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070099{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700100 super::getPolicy ().set_max_size (maxSize);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700101}
102
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700103template<class Policy>
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800104void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700105PitImpl<Policy>::NotifyNewAggregate ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700106{
107 if (m_fib == 0)
108 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700109 m_fib = GetObject<Fib> ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700110 }
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700111 if (m_forwardingStrategy == 0)
112 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700113 m_forwardingStrategy = GetObject<ForwardingStrategy> ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700114 }
115
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700116 Pit::NotifyNewAggregate ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700117}
118
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700119template<class Policy>
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800120void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700121PitImpl<Policy>::DoDispose ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700122{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700123 super::clear ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700124
125 m_forwardingStrategy = 0;
126 m_fib = 0;
127
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128 Pit::DoDispose ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700129}
130
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700131template<class Policy>
132void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700133PitImpl<Policy>::RescheduleCleaning ()
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800134{
Alexander Afanasyevb18ae022012-09-03 21:46:36 -0700135 // m_cleanEvent.Cancel ();
136 Simulator::Remove (m_cleanEvent); // slower, but better for memory
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700137 if (i_time.empty ())
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700138 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700139 // NS_LOG_DEBUG ("No items in PIT");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700140 return;
141 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700142
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700143 Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700144 if (nextEvent <= 0) nextEvent = Seconds (0);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800145
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700146 NS_LOG_DEBUG ("Schedule next cleaning in " <<
147 nextEvent.ToDouble (Time::S) << "s (at " <<
148 i_time.begin ()->GetExpireTime () << "s abs time");
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800149
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700150 m_cleanEvent = Simulator::Schedule (nextEvent,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151 &PitImpl<Policy>::CleanExpired, this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700152}
153
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700154template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700155void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156PitImpl<Policy>::CleanExpired ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700157{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700158 NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700159 Time now = Simulator::Now ();
160
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700161 // uint32_t count = 0;
162 while (!i_time.empty ())
163 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700164 typename time_index::iterator entry = i_time.begin ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700165 if (entry->GetExpireTime () <= now) // is the record stale?
166 {
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700167 m_forwardingStrategy->WillEraseTimedOutPendingInterest (entry->to_iterator ()->payload ());
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700168 super::erase (entry->to_iterator ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700169 // count ++;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700170 }
171 else
172 break; // nothing else to do. All later records will not be stale
173 }
174
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700175 if (super::getPolicy ().size ())
176 {
177 NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ());
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700178 NS_LOG_DEBUG ("i_time size: " << i_time.size ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700179 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700180 RescheduleCleaning ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700181}
182
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700183template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700184Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700185PitImpl<Policy>::Lookup (const ContentObject &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700186{
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800187 /// @todo use predicate to search with exclude filters
Alexander Afanasyeveec66292013-02-06 16:23:21 -0800188 typename super::iterator item = super::longest_prefix_match_if (header.GetName (), EntryIsNotEmpty ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700189
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700190 if (item == super::end ())
191 return 0;
192 else
193 return item->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700194}
195
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700196template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700197Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700198PitImpl<Policy>::Lookup (const Interest &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700199{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700200 // NS_LOG_FUNCTION (header.GetName ());
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700201 NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700202 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700203
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700204 typename super::iterator foundItem, lastItem;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700205 bool reachLast;
206 boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700207
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700208 if (!reachLast || lastItem == super::end ())
209 return 0;
210 else
211 return lastItem->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700212}
213
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700214template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700215Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700216PitImpl<Policy>::Create (Ptr<const Interest> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700217{
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700218 NS_LOG_DEBUG (header->GetName ());
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700219 Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700220 if (fibEntry == 0)
221 return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800222
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700223 // NS_ASSERT_MSG (fibEntry != 0,
224 // "There should be at least default route set" <<
225 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700226
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700227 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700228 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700229 if (result.first != super::end ())
230 {
231 if (result.second)
232 {
233 newEntry->SetTrie (result.first);
234 return newEntry;
235 }
236 else
237 {
238 // should we do anything?
239 // update payload? add new payload?
240 return result.first->payload ();
241 }
242 }
243 else
244 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700245}
246
247
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700248template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700249void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700250PitImpl<Policy>::MarkErased (Ptr<Entry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700251{
Alexander Afanasyeveec66292013-02-06 16:23:21 -0800252 if (this->m_PitEntryPruningTimout.IsZero ())
253 {
254 super::erase (StaticCast< entry > (item)->to_iterator ());
255 }
256 else
257 {
258 item->OffsetLifetime (this->m_PitEntryPruningTimout - item->GetExpireTime () + Simulator::Now ());
259 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700260}
261
262
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700263template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700264void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700265PitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700266{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700267 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700268 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700269 for (; item != end; item++)
270 {
271 if (item->payload () == 0) continue;
272
273 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
274 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700275}
276
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700277template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700278uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700279PitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700280{
281 return super::getPolicy ().size ();
282}
283
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700284template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700285Ptr<Entry>
286PitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700287{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700288 typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700289 for (; item != end; item++)
290 {
291 if (item->payload () == 0) continue;
292 break;
293 }
294
295 if (item == end)
296 return End ();
297 else
298 return item->payload ();
299}
300
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700301template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700302Ptr<Entry>
303PitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700304{
305 return 0;
306}
307
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700308template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700309Ptr<Entry>
310PitImpl<Policy>::Next (Ptr<Entry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700311{
312 if (from == 0) return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800313
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700314 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700315 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700316 end (0);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800317
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700318 for (item++; item != end; item++)
319 {
320 if (item->payload () == 0) continue;
321 break;
322 }
323
324 if (item == end)
325 return End ();
326 else
327 return item->payload ();
328}
329
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800330//////////////////////////////////////////////////////////////////////////////////////////
331//////////////////////////////////////////////////////////////////////////////////////////
332//////////////////////////////////////////////////////////////////////////////////////////
333
334template<>
335TypeId
336PitImpl<persistent_policy_traits>::GetTypeId ()
337{
338 static TypeId tid = TypeId ("ns3::ndn::pit::Persistent")
339 .SetGroupName ("Ndn")
340 .SetParent<Pit> ()
341 .AddConstructor< PitImpl< persistent_policy_traits > > ()
342 .AddAttribute ("MaxSize",
343 "Set maximum number of entries in PIT. If 0, limit is not enforced",
344 StringValue ("0"),
345 MakeUintegerAccessor (&PitImpl< persistent_policy_traits >::GetMaxSize,
346 &PitImpl< persistent_policy_traits >::SetMaxSize),
347 MakeUintegerChecker<uint32_t> ())
348 ;
349
350 return tid;
351}
352
353template<>
354TypeId
355PitImpl<random_policy_traits>::GetTypeId ()
356{
357 static TypeId tid = TypeId ("ns3::ndn::pit::Random")
358 .SetGroupName ("Ndn")
359 .SetParent<Pit> ()
360 .AddConstructor< PitImpl< random_policy_traits > > ()
361 .AddAttribute ("MaxSize",
362 "Set maximum number of entries in PIT. If 0, limit is not enforced",
363 StringValue ("0"),
364 MakeUintegerAccessor (&PitImpl< random_policy_traits >::GetMaxSize,
365 &PitImpl< random_policy_traits >::SetMaxSize),
366 MakeUintegerChecker<uint32_t> ())
367 ;
368
369 return tid;
370}
371
372template<>
373TypeId
374PitImpl<lru_policy_traits>::GetTypeId ()
375{
376 static TypeId tid = TypeId ("ns3::ndn::pit::Lru")
377 .SetGroupName ("Ndn")
378 .SetParent<Pit> ()
379 .AddConstructor< PitImpl< lru_policy_traits > > ()
380 .AddAttribute ("MaxSize",
381 "Set maximum number of entries in PIT. If 0, limit is not enforced",
382 StringValue ("0"),
383 MakeUintegerAccessor (&PitImpl< lru_policy_traits >::GetMaxSize,
384 &PitImpl< lru_policy_traits >::SetMaxSize),
385 MakeUintegerChecker<uint32_t> ())
386 ;
387
388 return tid;
389}
390
391template<>
392TypeId
393PitImpl<serialized_size_policy_traits>::GetTypeId ()
394{
395 static TypeId tid = TypeId ("ns3::ndn::pit::SerializedSize")
396 .SetGroupName ("Ndn")
397 .SetParent<Pit> ()
398 .AddConstructor< PitImpl< serialized_size_policy_traits > > ()
399 .AddAttribute ("MaxSize",
400 "Set maximum size of PIT in bytes. If 0, limit is not enforced",
401 UintegerValue (0),
402 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetMaxSize,
403 &PitImpl< serialized_size_policy_traits >::SetMaxSize),
404 MakeUintegerChecker<uint32_t> ())
405
406 .AddAttribute ("CurrentSize", "Get current size of PIT in bytes",
407 TypeId::ATTR_GET,
408 UintegerValue (0),
409 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetCurrentSize),
410 MakeUintegerChecker<uint32_t> ())
411
412 ;
413
414 return tid;
415}
416
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700417
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700418// explicit instantiation and registering
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700419template class PitImpl<persistent_policy_traits>;
420template class PitImpl<random_policy_traits>;
421template class PitImpl<lru_policy_traits>;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800422template class PitImpl<serialized_size_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700423
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700424NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits);
425NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits);
426NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800427NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, serialized_size_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700428
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800429#ifdef DOXYGEN
430// /**
431// * \brief PIT in which new entries will be rejected if PIT size reached its limit
432// */
433class Persistent : public PitImpl<persistent_policy_traits> { };
434
435/**
436 * \brief PIT in which PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT
437 */
438class Random : public PitImpl<random_policy_traits> { };
439
440/**
441 * \brief PIT in which the least recently used entry (the oldest entry with minimum number of incoming faces)
442 * will be removed when PIT size reached its limit
443 */
444class Lru : public PitImpl<lru_policy_traits> { };
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800445
446/**
447 * @brief A variant of persistent PIT implementation where size of PIT is based on size of interests in bytes (MaxSize parameter)
448 */
449class SerializedSize : public PitImpl<serialized_size_policy_traits> { };
450
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800451#endif
452
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700453} // namespace pit
454} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700455} // namespace ns3