blob: 14b6b2ad6831ca11a0a6fbeb1cbe1bf32458e69f [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 Afanasyev7456b702013-02-01 22:41:48 -080031#include "custom-policies/serialized-size-policy.h"
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070032
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070033#include "ns3/log.h"
34#include "ns3/string.h"
35#include "ns3/uinteger.h"
36#include "ns3/simulator.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070037
38#include <boost/lambda/bind.hpp>
39#include <boost/lambda/lambda.hpp>
40
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070042
43using namespace boost::tuples;
44using namespace boost;
45namespace ll = boost::lambda;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070046
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 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057namespace ndn {
58namespace pit {
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070059
Alexander Afanasyeve77db792012-08-09 11:10:58 -070060using namespace ndnSIM;
61
Alexander Afanasyev7456b702013-02-01 22:41:48 -080062template<class Policy>
63uint32_t
64PitImpl<Policy>::GetCurrentSize () const
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070065{
Alexander Afanasyev7456b702013-02-01 22:41:48 -080066 return super::getPolicy ().size ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070067}
68
69template<>
Alexander Afanasyev7456b702013-02-01 22:41:48 -080070uint32_t
71PitImpl<serialized_size_policy_traits>::GetCurrentSize () const
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070072{
Alexander Afanasyev7456b702013-02-01 22:41:48 -080073 return super::getPolicy ().get_current_space_used ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070074}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070075
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070076template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077PitImpl<Policy>::PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070078{
79}
80
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070081template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082PitImpl<Policy>::~PitImpl ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070083{
84}
85
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070086template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070087uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088PitImpl<Policy>::GetMaxSize () const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070089{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070090 return super::getPolicy ().get_max_size ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070091}
92
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070093template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070094void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095PitImpl<Policy>::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070096{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070097 super::getPolicy ().set_max_size (maxSize);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070098}
99
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700100template<class Policy>
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800101void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700102PitImpl<Policy>::NotifyNewAggregate ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700103{
104 if (m_fib == 0)
105 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106 m_fib = GetObject<Fib> ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700107 }
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700108 if (m_forwardingStrategy == 0)
109 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110 m_forwardingStrategy = GetObject<ForwardingStrategy> ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700111 }
112
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700113 Pit::NotifyNewAggregate ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700114}
115
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700116template<class Policy>
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800117void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700118PitImpl<Policy>::DoDispose ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700119{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700120 super::clear ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700121
122 m_forwardingStrategy = 0;
123 m_fib = 0;
124
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700125 Pit::DoDispose ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700126}
127
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700128template<class Policy>
129void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130PitImpl<Policy>::RescheduleCleaning ()
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800131{
Alexander Afanasyevb18ae022012-09-03 21:46:36 -0700132 // m_cleanEvent.Cancel ();
133 Simulator::Remove (m_cleanEvent); // slower, but better for memory
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700134 if (i_time.empty ())
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700135 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700136 // NS_LOG_DEBUG ("No items in PIT");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700137 return;
138 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700139
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700140 Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700141 if (nextEvent <= 0) nextEvent = Seconds (0);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800142
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700143 NS_LOG_DEBUG ("Schedule next cleaning in " <<
144 nextEvent.ToDouble (Time::S) << "s (at " <<
145 i_time.begin ()->GetExpireTime () << "s abs time");
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800146
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700147 m_cleanEvent = Simulator::Schedule (nextEvent,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700148 &PitImpl<Policy>::CleanExpired, this);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700149}
150
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700151template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700152void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700153PitImpl<Policy>::CleanExpired ()
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700154{
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700155 NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700156 Time now = Simulator::Now ();
157
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700158 // uint32_t count = 0;
159 while (!i_time.empty ())
160 {
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700161 typename time_index::iterator entry = i_time.begin ();
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700162 if (entry->GetExpireTime () <= now) // is the record stale?
163 {
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700164 m_forwardingStrategy->WillEraseTimedOutPendingInterest (entry->to_iterator ()->payload ());
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700165 super::erase (entry->to_iterator ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700166 // count ++;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700167 }
168 else
169 break; // nothing else to do. All later records will not be stale
170 }
171
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700172 if (super::getPolicy ().size ())
173 {
174 NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ());
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700175 NS_LOG_DEBUG ("i_time size: " << i_time.size ());
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700176 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700177 RescheduleCleaning ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700178}
179
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700180template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700181Ptr<Entry>
182PitImpl<Policy>::Lookup (const ContentObjectHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700183{
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800184 /// @todo use predicate to search with exclude filters
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700185 typename super::iterator item = super::longest_prefix_match (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700186
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700187 if (item == super::end ())
188 return 0;
189 else
190 return item->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700191}
192
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700193template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700194Ptr<Entry>
195PitImpl<Policy>::Lookup (const InterestHeader &header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700196{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700197 // NS_LOG_FUNCTION (header.GetName ());
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700198 NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700199 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set");
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700200
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700201 typename super::iterator foundItem, lastItem;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700202 bool reachLast;
203 boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700204
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700205 if (!reachLast || lastItem == super::end ())
206 return 0;
207 else
208 return lastItem->payload (); // which could also be 0
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700209}
210
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700211template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700212Ptr<Entry>
213PitImpl<Policy>::Create (Ptr<const InterestHeader> header)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700214{
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700215 NS_LOG_DEBUG (header->GetName ());
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700216 Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (*header);
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700217 if (fibEntry == 0)
218 return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800219
Alexander Afanasyev3c5b6a72012-07-20 15:35:48 -0700220 // NS_ASSERT_MSG (fibEntry != 0,
221 // "There should be at least default route set" <<
222 // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700223
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700224 Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700225 std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700226 if (result.first != super::end ())
227 {
228 if (result.second)
229 {
230 newEntry->SetTrie (result.first);
231 return newEntry;
232 }
233 else
234 {
235 // should we do anything?
236 // update payload? add new payload?
237 return result.first->payload ();
238 }
239 }
240 else
241 return 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700242}
243
244
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700245template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700246void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700247PitImpl<Policy>::MarkErased (Ptr<Entry> item)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700248{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700249 // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700250 super::erase (StaticCast< entry > (item)->to_iterator ());
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700251}
252
253
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700254template<class Policy>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700255void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700256PitImpl<Policy>::Print (std::ostream& os) const
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700257{
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700258 // !!! unordered_set imposes "random" order of item in the same level !!!
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700259 typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700260 for (; item != end; item++)
261 {
262 if (item->payload () == 0) continue;
263
264 os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
265 }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700266}
267
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700268template<class Policy>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700269uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700270PitImpl<Policy>::GetSize () const
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700271{
272 return super::getPolicy ().size ();
273}
274
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700275template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700276Ptr<Entry>
277PitImpl<Policy>::Begin ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700278{
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700279 typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700280 for (; item != end; item++)
281 {
282 if (item->payload () == 0) continue;
283 break;
284 }
285
286 if (item == end)
287 return End ();
288 else
289 return item->payload ();
290}
291
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700292template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700293Ptr<Entry>
294PitImpl<Policy>::End ()
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700295{
296 return 0;
297}
298
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700299template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700300Ptr<Entry>
301PitImpl<Policy>::Next (Ptr<Entry> from)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700302{
303 if (from == 0) return 0;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800304
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700305 typename super::parent_trie::recursive_iterator
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700306 item (*StaticCast< entry > (from)->to_iterator ()),
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700307 end (0);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800308
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700309 for (item++; item != end; item++)
310 {
311 if (item->payload () == 0) continue;
312 break;
313 }
314
315 if (item == end)
316 return End ();
317 else
318 return item->payload ();
319}
320
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800321//////////////////////////////////////////////////////////////////////////////////////////
322//////////////////////////////////////////////////////////////////////////////////////////
323//////////////////////////////////////////////////////////////////////////////////////////
324
325template<>
326TypeId
327PitImpl<persistent_policy_traits>::GetTypeId ()
328{
329 static TypeId tid = TypeId ("ns3::ndn::pit::Persistent")
330 .SetGroupName ("Ndn")
331 .SetParent<Pit> ()
332 .AddConstructor< PitImpl< persistent_policy_traits > > ()
333 .AddAttribute ("MaxSize",
334 "Set maximum number of entries in PIT. If 0, limit is not enforced",
335 StringValue ("0"),
336 MakeUintegerAccessor (&PitImpl< persistent_policy_traits >::GetMaxSize,
337 &PitImpl< persistent_policy_traits >::SetMaxSize),
338 MakeUintegerChecker<uint32_t> ())
339 ;
340
341 return tid;
342}
343
344template<>
345TypeId
346PitImpl<random_policy_traits>::GetTypeId ()
347{
348 static TypeId tid = TypeId ("ns3::ndn::pit::Random")
349 .SetGroupName ("Ndn")
350 .SetParent<Pit> ()
351 .AddConstructor< PitImpl< random_policy_traits > > ()
352 .AddAttribute ("MaxSize",
353 "Set maximum number of entries in PIT. If 0, limit is not enforced",
354 StringValue ("0"),
355 MakeUintegerAccessor (&PitImpl< random_policy_traits >::GetMaxSize,
356 &PitImpl< random_policy_traits >::SetMaxSize),
357 MakeUintegerChecker<uint32_t> ())
358 ;
359
360 return tid;
361}
362
363template<>
364TypeId
365PitImpl<lru_policy_traits>::GetTypeId ()
366{
367 static TypeId tid = TypeId ("ns3::ndn::pit::Lru")
368 .SetGroupName ("Ndn")
369 .SetParent<Pit> ()
370 .AddConstructor< PitImpl< lru_policy_traits > > ()
371 .AddAttribute ("MaxSize",
372 "Set maximum number of entries in PIT. If 0, limit is not enforced",
373 StringValue ("0"),
374 MakeUintegerAccessor (&PitImpl< lru_policy_traits >::GetMaxSize,
375 &PitImpl< lru_policy_traits >::SetMaxSize),
376 MakeUintegerChecker<uint32_t> ())
377 ;
378
379 return tid;
380}
381
382template<>
383TypeId
384PitImpl<serialized_size_policy_traits>::GetTypeId ()
385{
386 static TypeId tid = TypeId ("ns3::ndn::pit::SerializedSize")
387 .SetGroupName ("Ndn")
388 .SetParent<Pit> ()
389 .AddConstructor< PitImpl< serialized_size_policy_traits > > ()
390 .AddAttribute ("MaxSize",
391 "Set maximum size of PIT in bytes. If 0, limit is not enforced",
392 UintegerValue (0),
393 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetMaxSize,
394 &PitImpl< serialized_size_policy_traits >::SetMaxSize),
395 MakeUintegerChecker<uint32_t> ())
396
397 .AddAttribute ("CurrentSize", "Get current size of PIT in bytes",
398 TypeId::ATTR_GET,
399 UintegerValue (0),
400 MakeUintegerAccessor (&PitImpl< serialized_size_policy_traits >::GetCurrentSize),
401 MakeUintegerChecker<uint32_t> ())
402
403 ;
404
405 return tid;
406}
407
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700408
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700409// explicit instantiation and registering
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700410template class PitImpl<persistent_policy_traits>;
411template class PitImpl<random_policy_traits>;
412template class PitImpl<lru_policy_traits>;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800413template class PitImpl<serialized_size_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700414
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700415NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits);
416NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits);
417NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800418NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, serialized_size_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -0700419
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800420#ifdef DOXYGEN
421// /**
422// * \brief PIT in which new entries will be rejected if PIT size reached its limit
423// */
424class Persistent : public PitImpl<persistent_policy_traits> { };
425
426/**
427 * \brief PIT in which PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT
428 */
429class Random : public PitImpl<random_policy_traits> { };
430
431/**
432 * \brief PIT in which the least recently used entry (the oldest entry with minimum number of incoming faces)
433 * will be removed when PIT size reached its limit
434 */
435class Lru : public PitImpl<lru_policy_traits> { };
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800436
437/**
438 * @brief A variant of persistent PIT implementation where size of PIT is based on size of interests in bytes (MaxSize parameter)
439 */
440class SerializedSize : public PitImpl<serialized_size_policy_traits> { };
441
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800442#endif
443
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700444} // namespace pit
445} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700446} // namespace ns3