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