blob: a0d0c3e395105a7622231904848ee00260880d6e [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 Afanasyev1a2df6a2012-08-17 13:21:51 -070023#include "../../utils/trie/empty-policy.h"
24#include "../../utils/trie/persistent-policy.h"
25#include "../../utils/trie/random-policy.h"
26#include "../../utils/trie/lru-policy.h"
Alexander Afanasyev26719e22013-03-26 12:43:28 -070027#include "../../utils/trie/multi-policy.h"
28#include "../../utils/trie/aggregate-stats-policy.h"
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070029
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070030#include "ns3/log.h"
Alexander Afanasyev1fb9fed2013-02-01 23:18:04 -080031
32NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
33
34#include "custom-policies/serialized-size-policy.h"
35
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070036#include "ns3/string.h"
37#include "ns3/uinteger.h"
38#include "ns3/simulator.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070039
40#include <boost/lambda/bind.hpp>
41#include <boost/lambda/lambda.hpp>
42
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070043
44using namespace boost::tuples;
45using namespace boost;
46namespace ll = boost::lambda;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070047
48#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
49 static struct X ## type ## templ ## RegistrationClass \
50 { \
51 X ## type ## templ ## RegistrationClass () { \
52 ns3::TypeId tid = type<templ>::GetTypeId (); \
53 tid.GetParent (); \
54 } \
55 } x_ ## type ## templ ## RegistrationVariable
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070056
57namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058namespace ndn {
59namespace pit {
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070060
Alexander Afanasyeve77db792012-08-09 11:10:58 -070061using namespace ndnSIM;
62
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070063template<>
Alexander Afanasyev7456b702013-02-01 22:41:48 -080064uint32_t
65PitImpl<serialized_size_policy_traits>::GetCurrentSize () const
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070066{
Alexander Afanasyev7456b702013-02-01 22:41:48 -080067 return super::getPolicy ().get_current_space_used ();
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070068}
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070069
Alexander Afanasyev7456b702013-02-01 22:41:48 -080070//////////////////////////////////////////////////////////////////////////////////////////
71//////////////////////////////////////////////////////////////////////////////////////////
72//////////////////////////////////////////////////////////////////////////////////////////
73
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070074// explicit instantiation and registering
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070075template class PitImpl<persistent_policy_traits>;
76template class PitImpl<random_policy_traits>;
77template class PitImpl<lru_policy_traits>;
Alexander Afanasyev7456b702013-02-01 22:41:48 -080078template class PitImpl<serialized_size_policy_traits>;
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070079
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits);
81NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits);
82NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits);
Alexander Afanasyev7456b702013-02-01 22:41:48 -080083NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, serialized_size_policy_traits);
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070084
Alexander Afanasyev26719e22013-03-26 12:43:28 -070085
86typedef multi_policy_traits< boost::mpl::vector2< persistent_policy_traits,
87 aggregate_stats_policy_traits > > PersistentWithCountsTraits;
88typedef multi_policy_traits< boost::mpl::vector2< random_policy_traits,
89 aggregate_stats_policy_traits > > RandomWithCountsTraits;
90typedef multi_policy_traits< boost::mpl::vector2< lru_policy_traits,
91 aggregate_stats_policy_traits > > LruWithCountsTraits;
92typedef multi_policy_traits< boost::mpl::vector2< serialized_size_policy_traits,
93 aggregate_stats_policy_traits > > SerializedSizeWithCountsTraits;
94
95template class PitImpl<PersistentWithCountsTraits>;
96NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, PersistentWithCountsTraits);
97
98template class PitImpl<RandomWithCountsTraits>;
99NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, RandomWithCountsTraits);
100
101template class PitImpl<LruWithCountsTraits>;
102NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, LruWithCountsTraits);
103
104template class PitImpl<SerializedSizeWithCountsTraits>;
105NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, SerializedSizeWithCountsTraits);
106
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800107#ifdef DOXYGEN
108// /**
109// * \brief PIT in which new entries will be rejected if PIT size reached its limit
110// */
111class Persistent : public PitImpl<persistent_policy_traits> { };
112
113/**
114 * \brief PIT in which PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT
115 */
116class Random : public PitImpl<random_policy_traits> { };
117
118/**
119 * \brief PIT in which the least recently used entry (the oldest entry with minimum number of incoming faces)
120 * will be removed when PIT size reached its limit
121 */
122class Lru : public PitImpl<lru_policy_traits> { };
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800123
124/**
125 * @brief A variant of persistent PIT implementation where size of PIT is based on size of interests in bytes (MaxSize parameter)
126 */
127class SerializedSize : public PitImpl<serialized_size_policy_traits> { };
128
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800129#endif
130
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131} // namespace pit
132} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700133} // namespace ns3