blob: 777ab390bba3b60948a635cde3bcaf018041c4e2 [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 Afanasyeve5a8b5a2013-03-15 15:15:26 -0700216PitImpl<Policy>::Find (const Name &prefix)
217{
218 typename super::iterator item = super::find_exact (prefix);
219
220 if (item == super::end ())
221 return 0;
222 else
223 return item->payload ();
224}
225
226
227template<class Policy>
228Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700229PitImpl<Policy>::Create (Ptr<const Interest> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700230{
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700231 NS_LOG_DEBUG (header->GetName ());
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700232 Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700233 if (fibEntry == 0)
234 return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800235
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700236 // NS_ASSERT_MSG (fibEntry != 0,
237 // "There should be at least default route set" <<
238 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700239
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700240 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700241 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700242 if (result.first != super::end ())
243 {
244 if (result.second)
245 {
246 newEntry->SetTrie (result.first);
247 return newEntry;
248 }
249 else
250 {
251 // should we do anything?
252 // update payload? add new payload?
253 return result.first->payload ();
254 }
255 }
256 else
257 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700258}
259
260
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700261template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700262void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700263PitImpl<Policy>::MarkErased (Ptr<Entry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700264{
Alexander Afanasyeveec66292013-02-06 16:23:21 -0800265 if (this->m_PitEntryPruningTimout.IsZero ())
266 {
267 super::erase (StaticCast< entry > (item)->to_iterator ());
268 }
269 else
270 {
271 item->OffsetLifetime (this->m_PitEntryPruningTimout - item->GetExpireTime () + Simulator::Now ());
272 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700273}
274
275
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700276template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700277void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700278PitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700279{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700280 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700281 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700282 for (; item != end; item++)
283 {
284 if (item->payload () == 0) continue;
285
286 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
287 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700288}
289
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700290template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700291uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700292PitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700293{
294 return super::getPolicy ().size ();
295}
296
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700297template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700298Ptr<Entry>
299PitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700300{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700301 typename super::parent_trie::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 break;
306 }
307
308 if (item == end)
309 return End ();
310 else
311 return item->payload ();
312}
313
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700314template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700315Ptr<Entry>
316PitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700317{
318 return 0;
319}
320
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700321template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700322Ptr<Entry>
323PitImpl<Policy>::Next (Ptr<Entry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700324{
325 if (from == 0) return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800326
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700327 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700328 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700329 end (0);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800330
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700331 for (item++; item != end; item++)
332 {
333 if (item->payload () == 0) continue;
334 break;
335 }
336
337 if (item == end)
338 return End ();
339 else
340 return item->payload ();
341}
342
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800343//////////////////////////////////////////////////////////////////////////////////////////
344//////////////////////////////////////////////////////////////////////////////////////////
345//////////////////////////////////////////////////////////////////////////////////////////
346
347template<>
348TypeId
349PitImpl<persistent_policy_traits>::GetTypeId ()
350{
351 static TypeId tid = TypeId ("ns3::ndn::pit::Persistent")
352 .SetGroupName ("Ndn")
353 .SetParent<Pit> ()
354 .AddConstructor< PitImpl< persistent_policy_traits > > ()
355 .AddAttribute ("MaxSize",
356 "Set maximum number of entries in PIT. If 0, limit is not enforced",
357 StringValue ("0"),
358 MakeUintegerAccessor (&PitImpl< persistent_policy_traits >::GetMaxSize,
359 &PitImpl< persistent_policy_traits >::SetMaxSize),
360 MakeUintegerChecker<uint32_t> ())
361 ;
362
363 return tid;
364}
365
366template<>
367TypeId
368PitImpl<random_policy_traits>::GetTypeId ()
369{
370 static TypeId tid = TypeId ("ns3::ndn::pit::Random")
371 .SetGroupName ("Ndn")
372 .SetParent<Pit> ()
373 .AddConstructor< PitImpl< random_policy_traits > > ()
374 .AddAttribute ("MaxSize",
375 "Set maximum number of entries in PIT. If 0, limit is not enforced",
376 StringValue ("0"),
377 MakeUintegerAccessor (&PitImpl< random_policy_traits >::GetMaxSize,
378 &PitImpl< random_policy_traits >::SetMaxSize),
379 MakeUintegerChecker<uint32_t> ())
380 ;
381
382 return tid;
383}
384
385template<>
386TypeId
387PitImpl<lru_policy_traits>::GetTypeId ()
388{
389 static TypeId tid = TypeId ("ns3::ndn::pit::Lru")
390 .SetGroupName ("Ndn")
391 .SetParent<Pit> ()
392 .AddConstructor< PitImpl< lru_policy_traits > > ()
393 .AddAttribute ("MaxSize",
394 "Set maximum number of entries in PIT. If 0, limit is not enforced",
395 StringValue ("0"),
396 MakeUintegerAccessor (&PitImpl< lru_policy_traits >::GetMaxSize,
397 &PitImpl< lru_policy_traits >::SetMaxSize),
398 MakeUintegerChecker<uint32_t> ())
399 ;
400
401 return tid;
402}
403
404template<>
405TypeId
406PitImpl<serialized_size_policy_traits>::GetTypeId ()
407{
408 static TypeId tid = TypeId ("ns3::ndn::pit::SerializedSize")
409 .SetGroupName ("Ndn")
410 .SetParent<Pit> ()
411 .AddConstructor< PitImpl< serialized_size_policy_traits > > ()
412 .AddAttribute ("MaxSize",
413 "Set maximum size of PIT in bytes. If 0, limit is not enforced",
414 UintegerValue (0),
415 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetMaxSize,
416 &PitImpl< serialized_size_policy_traits >::SetMaxSize),
417 MakeUintegerChecker<uint32_t> ())
418
419 .AddAttribute ("CurrentSize", "Get current size of PIT in bytes",
420 TypeId::ATTR_GET,
421 UintegerValue (0),
422 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetCurrentSize),
423 MakeUintegerChecker<uint32_t> ())
424
425 ;
426
427 return tid;
428}
429
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700430
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700431// explicit instantiation and registering
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700432template class PitImpl<persistent_policy_traits>;
433template class PitImpl<random_policy_traits>;
434template class PitImpl<lru_policy_traits>;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800435template class PitImpl<serialized_size_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700436
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700437NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits);
438NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits);
439NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800440NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, serialized_size_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700441
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800442#ifdef DOXYGEN
443// /**
444// * \brief PIT in which new entries will be rejected if PIT size reached its limit
445// */
446class Persistent : public PitImpl<persistent_policy_traits> { };
447
448/**
449 * \brief PIT in which PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT
450 */
451class Random : public PitImpl<random_policy_traits> { };
452
453/**
454 * \brief PIT in which the least recently used entry (the oldest entry with minimum number of incoming faces)
455 * will be removed when PIT size reached its limit
456 */
457class Lru : public PitImpl<lru_policy_traits> { };
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800458
459/**
460 * @brief A variant of persistent PIT implementation where size of PIT is based on size of interests in bytes (MaxSize parameter)
461 */
462class SerializedSize : public PitImpl<serialized_size_policy_traits> { };
463
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800464#endif
465
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700466} // namespace pit
467} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700468} // namespace ns3