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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 23 | #include "ns3/ndn-interest-header.h" |
| 24 | #include "ns3/ndn-content-object-header.h" |
| 25 | #include "ns3/ndn-forwarding-strategy.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 27 | #include "../../utils/empty-policy.h" |
| 28 | #include "../../utils/persistent-policy.h" |
| 29 | #include "../../utils/random-policy.h" |
| 30 | #include "../../utils/lru-policy.h" |
| 31 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 32 | #include "ns3/log.h" |
| 33 | #include "ns3/string.h" |
| 34 | #include "ns3/uinteger.h" |
| 35 | #include "ns3/simulator.h" |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 36 | |
| 37 | #include <boost/lambda/bind.hpp> |
| 38 | #include <boost/lambda/lambda.hpp> |
| 39 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 40 | NS_LOG_COMPONENT_DEFINE ("NdnPitImpl"); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 41 | |
| 42 | using namespace boost::tuples; |
| 43 | using namespace boost; |
| 44 | namespace ll = boost::lambda; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 45 | using namespace ndnSIM; |
| 46 | |
| 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 Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 55 | |
| 56 | namespace ns3 { |
| 57 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 58 | template<> |
| 59 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 60 | NdnPitImpl<persistent_policy_traits>::GetTypeId () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 61 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 62 | static TypeId tid = TypeId ("ns3::NdnPit") |
| 63 | .SetGroupName ("Ndn") |
| 64 | .SetParent<NdnPit> () |
| 65 | .AddConstructor< NdnPitImpl< persistent_policy_traits > > () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 66 | .AddAttribute ("MaxSize", |
| 67 | "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 68 | StringValue ("0"), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 69 | MakeUintegerAccessor (&NdnPitImpl< persistent_policy_traits >::GetMaxSize, |
| 70 | &NdnPitImpl< persistent_policy_traits >::SetMaxSize), |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 71 | MakeUintegerChecker<uint32_t> ()) |
| 72 | ; |
| 73 | |
Alexander Afanasyev | 0a0dc39 | 2012-07-27 13:41:49 -0700 | [diff] [blame] | 74 | return tid; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | template<> |
| 78 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 79 | NdnPitImpl<random_policy_traits>::GetTypeId () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 80 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 81 | static TypeId tid = TypeId ("ns3::NdnPitRandom") |
| 82 | .SetGroupName ("Ndn") |
| 83 | .SetParent<NdnPit> () |
| 84 | .AddConstructor< NdnPitImpl< random_policy_traits > > () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 85 | .AddAttribute ("MaxSize", |
| 86 | "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 87 | StringValue ("0"), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 88 | MakeUintegerAccessor (&NdnPitImpl< random_policy_traits >::GetMaxSize, |
| 89 | &NdnPitImpl< random_policy_traits >::SetMaxSize), |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 90 | MakeUintegerChecker<uint32_t> ()) |
| 91 | ; |
| 92 | |
Alexander Afanasyev | 0a0dc39 | 2012-07-27 13:41:49 -0700 | [diff] [blame] | 93 | return tid; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | template<> |
| 97 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 98 | NdnPitImpl<lru_policy_traits>::GetTypeId () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 99 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 100 | static TypeId tid = TypeId ("ns3::NdnPitLru") |
| 101 | .SetGroupName ("Ndn") |
| 102 | .SetParent<NdnPit> () |
| 103 | .AddConstructor< NdnPitImpl< lru_policy_traits > > () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 104 | .AddAttribute ("MaxSize", |
| 105 | "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 106 | StringValue ("0"), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 107 | MakeUintegerAccessor (&NdnPitImpl< lru_policy_traits >::GetMaxSize, |
| 108 | &NdnPitImpl< lru_policy_traits >::SetMaxSize), |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 109 | MakeUintegerChecker<uint32_t> ()) |
| 110 | ; |
| 111 | |
Alexander Afanasyev | 0a0dc39 | 2012-07-27 13:41:49 -0700 | [diff] [blame] | 112 | return tid; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 113 | } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 114 | |
Alexander Afanasyev | 0a0dc39 | 2012-07-27 13:41:49 -0700 | [diff] [blame] | 115 | // template<class Policy> |
| 116 | // TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 117 | // NdnPitImpl<Policy>::GetTypeId () |
Alexander Afanasyev | 0a0dc39 | 2012-07-27 13:41:49 -0700 | [diff] [blame] | 118 | // { |
| 119 | // static TypeId tid = TypeId ("ns3::UnknownPitPolicy"); |
| 120 | |
| 121 | // return tid; |
| 122 | // } |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 124 | // NdnPitEntryImpl::NdnPitEntryImpl (NdnPit &pit, |
| 125 | // Ptr<const NdnInterestHeader> header, |
| 126 | // Ptr<NdnFibEntry> fibEntry) |
| 127 | // : NdnPitEntry (pit, header, fibEntry) |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 128 | // , item_ (0) |
| 129 | // { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 130 | // static_cast<NdnPitImpl&> (m_container).i_time.insert (*this); |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 131 | // } |
| 132 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 133 | // NdnPitEntryImpl::~NdnPitEntryImpl () |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 134 | // { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 135 | // static_cast<NdnPitImpl&> (m_container).i_time.erase (*this); |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 136 | // } |
| 137 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 138 | // TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 139 | // NdnPitImpl::GetTypeId () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 140 | // { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 141 | // static TypeId tid = TypeId ("ns3::NdnPit") |
| 142 | // .SetGroupName ("Ndn") |
| 143 | // .SetParent<NdnPit> () |
| 144 | // .AddConstructor<NdnPitImpl> () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 145 | // .AddAttribute ("MaxSize", |
| 146 | // "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 147 | // StringValue ("0"), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 148 | // MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize), |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 149 | // MakeUintegerChecker<uint32_t> ()) |
| 150 | // ; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 152 | // return tid; |
| 153 | // } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 154 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 155 | |
| 156 | // template<class AcceptanceAndReplacementPolicy> |
| 157 | // TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 158 | // NdnPitImpl::GetTypeId () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 159 | // { |
| 160 | // #error "Not specialized version is not supported" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 161 | // // static TypeId tid = TypeId ("ns3::NdnPit") |
| 162 | // // .SetGroupName ("Ndn") |
| 163 | // // .SetParent<NdnPit> () |
| 164 | // // .AddConstructor<NdnPitImpl> () |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 165 | // // .AddAttribute ("MaxSize", |
| 166 | // // "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 167 | // // StringValue ("0"), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 168 | // // MakeUintegerAccessor (&NdnPitImpl::GetMaxSize, &NdnPitImpl::SetMaxSize), |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 169 | // // MakeUintegerChecker<uint32_t> ()) |
| 170 | // // ; |
| 171 | |
| 172 | // return Typeid (); |
| 173 | // } |
| 174 | |
| 175 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 176 | NdnPitImpl<Policy>::NdnPitImpl () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 177 | { |
| 178 | } |
| 179 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 180 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 181 | NdnPitImpl<Policy>::~NdnPitImpl () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 182 | { |
| 183 | } |
| 184 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 185 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 186 | uint32_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 187 | NdnPitImpl<Policy>::GetMaxSize () const |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 188 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 189 | return super::getPolicy ().get_max_size (); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 192 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 193 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 194 | NdnPitImpl<Policy>::SetMaxSize (uint32_t maxSize) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 195 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 196 | super::getPolicy ().set_max_size (maxSize); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 199 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 200 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 201 | NdnPitImpl<Policy>::NotifyNewAggregate () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 202 | { |
| 203 | if (m_fib == 0) |
| 204 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 205 | m_fib = GetObject<NdnFib> (); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 206 | } |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 207 | if (m_forwardingStrategy == 0) |
| 208 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 209 | m_forwardingStrategy = GetObject<NdnForwardingStrategy> (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 212 | NdnPit::NotifyNewAggregate (); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 215 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 216 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 217 | NdnPitImpl<Policy>::DoDispose () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 218 | { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 219 | super::clear (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 220 | |
| 221 | m_forwardingStrategy = 0; |
| 222 | m_fib = 0; |
| 223 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 224 | NdnPit::DoDispose (); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 227 | template<class Policy> |
| 228 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 229 | NdnPitImpl<Policy>::RescheduleCleaning () |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 230 | { |
| 231 | m_cleanEvent.Cancel (); |
| 232 | if (i_time.empty ()) |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 233 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 234 | // NS_LOG_DEBUG ("No items in PIT"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 235 | return; |
| 236 | } |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 237 | |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 238 | Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now (); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 239 | if (nextEvent <= 0) nextEvent = Seconds (0); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 240 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 241 | // NS_LOG_DEBUG ("Schedule next cleaning in " << |
| 242 | // nextEvent.ToDouble (Time::S) << "s (at " << |
| 243 | // i_time.begin ()->GetExpireTime () << "s abs time"); |
| 244 | |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 245 | m_cleanEvent = Simulator::Schedule (nextEvent, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 246 | &NdnPitImpl<Policy>::CleanExpired, this); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 249 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 250 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 251 | NdnPitImpl<Policy>::CleanExpired () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 252 | { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 253 | NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ()); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 254 | Time now = Simulator::Now (); |
| 255 | |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 256 | // uint32_t count = 0; |
| 257 | while (!i_time.empty ()) |
| 258 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 259 | typename time_index::iterator entry = i_time.begin (); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 260 | if (entry->GetExpireTime () <= now) // is the record stale? |
| 261 | { |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 262 | m_forwardingStrategy->WillErasePendingInterest (entry->to_iterator ()->payload ()); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 263 | super::erase (entry->to_iterator ()); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 264 | // count ++; |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 265 | } |
| 266 | else |
| 267 | break; // nothing else to do. All later records will not be stale |
| 268 | } |
| 269 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 270 | if (super::getPolicy ().size ()) |
| 271 | { |
| 272 | NS_LOG_DEBUG ("Size: " << super::getPolicy ().size ()); |
Alexander Afanasyev | 6b51b08 | 2012-07-27 16:28:34 -0700 | [diff] [blame] | 273 | NS_LOG_DEBUG ("i_time size: " << i_time.size ()); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 274 | } |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 275 | RescheduleCleaning (); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 278 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 279 | Ptr<NdnPitEntry> |
| 280 | NdnPitImpl<Policy>::Lookup (const NdnContentObjectHeader &header) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 281 | { |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 282 | /// @todo use predicate to search with exclude filters |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 283 | typename super::iterator item = super::longest_prefix_match (header.GetName ()); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 284 | |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 285 | if (item == super::end ()) |
| 286 | return 0; |
| 287 | else |
| 288 | return item->payload (); // which could also be 0 |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 291 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 292 | Ptr<NdnPitEntry> |
| 293 | NdnPitImpl<Policy>::Lookup (const NdnInterestHeader &header) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 294 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 295 | // NS_LOG_FUNCTION (header.GetName ()); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 296 | NS_ASSERT_MSG (m_fib != 0, "FIB should be set"); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 297 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Forwarding strategy should be set"); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 298 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 299 | typename super::iterator foundItem, lastItem; |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 300 | bool reachLast; |
| 301 | boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (header.GetName ()); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 302 | |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 303 | if (!reachLast || lastItem == super::end ()) |
| 304 | return 0; |
| 305 | else |
| 306 | return lastItem->payload (); // which could also be 0 |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 309 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 310 | Ptr<NdnPitEntry> |
| 311 | NdnPitImpl<Policy>::Create (Ptr<const NdnInterestHeader> header) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 312 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 313 | Ptr<NdnFibEntry> fibEntry = m_fib->LongestPrefixMatch (*header); |
Alexander Afanasyev | 3c5b6a7 | 2012-07-20 15:35:48 -0700 | [diff] [blame] | 314 | if (fibEntry == 0) |
| 315 | return 0; |
| 316 | |
| 317 | // NS_ASSERT_MSG (fibEntry != 0, |
| 318 | // "There should be at least default route set" << |
| 319 | // " Prefix = "<< header->GetName() << ", NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 320 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 321 | Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*this), header, fibEntry); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 322 | std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 323 | if (result.first != super::end ()) |
| 324 | { |
| 325 | if (result.second) |
| 326 | { |
| 327 | newEntry->SetTrie (result.first); |
| 328 | return newEntry; |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | // should we do anything? |
| 333 | // update payload? add new payload? |
| 334 | return result.first->payload (); |
| 335 | } |
| 336 | } |
| 337 | else |
| 338 | return 0; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 342 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 343 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 344 | NdnPitImpl<Policy>::MarkErased (Ptr<NdnPitEntry> item) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 345 | { |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 346 | // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout); |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 347 | super::erase (StaticCast< entry > (item)->to_iterator ()); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 351 | template<class Policy> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 352 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 353 | NdnPitImpl<Policy>::Print (std::ostream& os) const |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 354 | { |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 355 | // !!! unordered_set imposes "random" order of item in the same level !!! |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 356 | typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 357 | for (; item != end; item++) |
| 358 | { |
| 359 | if (item->payload () == 0) continue; |
| 360 | |
| 361 | os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n"; |
| 362 | } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 365 | template<class Policy> |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 366 | uint32_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 367 | NdnPitImpl<Policy>::GetSize () const |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 368 | { |
| 369 | return super::getPolicy ().size (); |
| 370 | } |
| 371 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 372 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 373 | Ptr<NdnPitEntry> |
| 374 | NdnPitImpl<Policy>::Begin () |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 375 | { |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 376 | typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 377 | for (; item != end; item++) |
| 378 | { |
| 379 | if (item->payload () == 0) continue; |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | if (item == end) |
| 384 | return End (); |
| 385 | else |
| 386 | return item->payload (); |
| 387 | } |
| 388 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 389 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 390 | Ptr<NdnPitEntry> |
| 391 | NdnPitImpl<Policy>::End () |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 392 | { |
| 393 | return 0; |
| 394 | } |
| 395 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 396 | template<class Policy> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 397 | Ptr<NdnPitEntry> |
| 398 | NdnPitImpl<Policy>::Next (Ptr<NdnPitEntry> from) |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 399 | { |
| 400 | if (from == 0) return 0; |
| 401 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 402 | typename super::parent_trie::recursive_iterator |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 403 | item (*StaticCast< entry > (from)->to_iterator ()), |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 404 | end (0); |
| 405 | |
| 406 | for (item++; item != end; item++) |
| 407 | { |
| 408 | if (item->payload () == 0) continue; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | if (item == end) |
| 413 | return End (); |
| 414 | else |
| 415 | return item->payload (); |
| 416 | } |
| 417 | |
| 418 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 419 | // explicit instantiation and registering |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 420 | template class NdnPitImpl<persistent_policy_traits>; |
| 421 | template class NdnPitImpl<random_policy_traits>; |
| 422 | template class NdnPitImpl<lru_policy_traits>; |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 423 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 424 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, persistent_policy_traits); |
| 425 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, random_policy_traits); |
| 426 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(NdnPitImpl, lru_policy_traits); |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 427 | |
| 428 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 429 | } // namespace ns3 |