Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #include "ndn-pit-impl.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 1a2df6a | 2012-08-17 13:21:51 -0700 | [diff] [blame] | 23 | #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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 27 | #include "../../utils/trie/multi-policy.h" |
| 28 | #include "../../utils/trie/aggregate-stats-policy.h" |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 30 | #include "ns3/log.h" |
Alexander Afanasyev | 1fb9fed | 2013-02-01 23:18:04 -0800 | [diff] [blame] | 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl"); |
| 33 | |
| 34 | #include "custom-policies/serialized-size-policy.h" |
| 35 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 36 | #include "ns3/string.h" |
| 37 | #include "ns3/uinteger.h" |
| 38 | #include "ns3/simulator.h" |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 39 | |
| 40 | #include <boost/lambda/bind.hpp> |
| 41 | #include <boost/lambda/lambda.hpp> |
| 42 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 43 | |
| 44 | using namespace boost::tuples; |
| 45 | using namespace boost; |
| 46 | namespace ll = boost::lambda; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 47 | |
| 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 Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 56 | |
| 57 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 58 | namespace ndn { |
| 59 | namespace pit { |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 61 | using namespace ndnSIM; |
| 62 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 63 | template<> |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 64 | uint32_t |
| 65 | PitImpl<serialized_size_policy_traits>::GetCurrentSize () const |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 66 | { |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 67 | return super::getPolicy ().get_current_space_used (); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 68 | } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 70 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 72 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 73 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 74 | // explicit instantiation and registering |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 75 | template class PitImpl<persistent_policy_traits>; |
| 76 | template class PitImpl<random_policy_traits>; |
| 77 | template class PitImpl<lru_policy_traits>; |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 78 | template class PitImpl<serialized_size_policy_traits>; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 80 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, persistent_policy_traits); |
| 81 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, random_policy_traits); |
| 82 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, lru_policy_traits); |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 83 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, serialized_size_policy_traits); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 85 | |
| 86 | typedef multi_policy_traits< boost::mpl::vector2< persistent_policy_traits, |
| 87 | aggregate_stats_policy_traits > > PersistentWithCountsTraits; |
| 88 | typedef multi_policy_traits< boost::mpl::vector2< random_policy_traits, |
| 89 | aggregate_stats_policy_traits > > RandomWithCountsTraits; |
| 90 | typedef multi_policy_traits< boost::mpl::vector2< lru_policy_traits, |
| 91 | aggregate_stats_policy_traits > > LruWithCountsTraits; |
| 92 | typedef multi_policy_traits< boost::mpl::vector2< serialized_size_policy_traits, |
| 93 | aggregate_stats_policy_traits > > SerializedSizeWithCountsTraits; |
| 94 | |
| 95 | template class PitImpl<PersistentWithCountsTraits>; |
| 96 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, PersistentWithCountsTraits); |
| 97 | |
| 98 | template class PitImpl<RandomWithCountsTraits>; |
| 99 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, RandomWithCountsTraits); |
| 100 | |
| 101 | template class PitImpl<LruWithCountsTraits>; |
| 102 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, LruWithCountsTraits); |
| 103 | |
| 104 | template class PitImpl<SerializedSizeWithCountsTraits>; |
| 105 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(PitImpl, SerializedSizeWithCountsTraits); |
| 106 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 107 | #ifdef DOXYGEN |
| 108 | // /** |
| 109 | // * \brief PIT in which new entries will be rejected if PIT size reached its limit |
| 110 | // */ |
| 111 | class 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 | */ |
| 116 | class 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 | */ |
| 122 | class Lru : public PitImpl<lru_policy_traits> { }; |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * @brief A variant of persistent PIT implementation where size of PIT is based on size of interests in bytes (MaxSize parameter) |
| 126 | */ |
| 127 | class SerializedSize : public PitImpl<serialized_size_policy_traits> { }; |
| 128 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 129 | #endif |
| 130 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 131 | } // namespace pit |
| 132 | } // namespace ndn |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 133 | } // namespace ns3 |