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 | |
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 |
| 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 | |
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 |
| 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 | |
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 |
| 117 | // CcnxPitImpl<Policy>::GetTypeId () |
| 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 | |
| 124 | // CcnxPitEntryImpl::CcnxPitEntryImpl (CcnxPit &pit, |
| 125 | // Ptr<const CcnxInterestHeader> header, |
| 126 | // Ptr<CcnxFibEntry> fibEntry) |
| 127 | // : CcnxPitEntry (pit, header, fibEntry) |
| 128 | // , item_ (0) |
| 129 | // { |
| 130 | // static_cast<CcnxPitImpl&> (m_container).i_time.insert (*this); |
| 131 | // } |
| 132 | |
| 133 | // CcnxPitEntryImpl::~CcnxPitEntryImpl () |
| 134 | // { |
| 135 | // static_cast<CcnxPitImpl&> (m_container).i_time.erase (*this); |
| 136 | // } |
| 137 | |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 138 | // TypeId |
| 139 | // CcnxPitImpl::GetTypeId () |
| 140 | // { |
| 141 | // static TypeId tid = TypeId ("ns3::CcnxPit") |
| 142 | // .SetGroupName ("Ccnx") |
| 143 | // .SetParent<CcnxPit> () |
| 144 | // .AddConstructor<CcnxPitImpl> () |
| 145 | // .AddAttribute ("MaxSize", |
| 146 | // "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 147 | // StringValue ("0"), |
| 148 | // MakeUintegerAccessor (&CcnxPitImpl::GetMaxSize, &CcnxPitImpl::SetMaxSize), |
| 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 |
| 158 | // CcnxPitImpl::GetTypeId () |
| 159 | // { |
| 160 | // #error "Not specialized version is not supported" |
| 161 | // // static TypeId tid = TypeId ("ns3::CcnxPit") |
| 162 | // // .SetGroupName ("Ccnx") |
| 163 | // // .SetParent<CcnxPit> () |
| 164 | // // .AddConstructor<CcnxPitImpl> () |
| 165 | // // .AddAttribute ("MaxSize", |
| 166 | // // "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 167 | // // StringValue ("0"), |
| 168 | // // MakeUintegerAccessor (&CcnxPitImpl::GetMaxSize, &CcnxPitImpl::SetMaxSize), |
| 169 | // // MakeUintegerChecker<uint32_t> ()) |
| 170 | // // ; |
| 171 | |
| 172 | // return Typeid (); |
| 173 | // } |
| 174 | |
| 175 | template<class Policy> |
| 176 | CcnxPitImpl<Policy>::CcnxPitImpl () |
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> |
| 181 | CcnxPitImpl<Policy>::~CcnxPitImpl () |
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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 187 | CcnxPitImpl<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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 194 | CcnxPitImpl<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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 201 | CcnxPitImpl<Policy>::NotifyNewAggregate () |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 202 | { |
| 203 | if (m_fib == 0) |
| 204 | { |
| 205 | m_fib = GetObject<CcnxFib> (); |
| 206 | } |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 207 | if (m_forwardingStrategy == 0) |
| 208 | { |
| 209 | m_forwardingStrategy = GetObject<CcnxForwardingStrategy> (); |
| 210 | } |
| 211 | |
| 212 | CcnxPit::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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 217 | CcnxPitImpl<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 | |
| 224 | CcnxPit::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 |
| 229 | CcnxPitImpl<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 | 6b51b08 | 2012-07-27 16:28:34 -0700 | [diff] [blame^] | 246 | &CcnxPitImpl<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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 251 | CcnxPitImpl<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 | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 279 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 280 | CcnxPitImpl<Policy>::Lookup (const CcnxContentObjectHeader &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 | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 292 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 293 | CcnxPitImpl<Policy>::Lookup (const CcnxInterestHeader &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 | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 310 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 311 | CcnxPitImpl<Policy>::Create (Ptr<const CcnxInterestHeader> header) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 312 | { |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 313 | Ptr<CcnxFibEntry> 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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 344 | CcnxPitImpl<Policy>::MarkErased (Ptr<CcnxPitEntry> 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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 353 | CcnxPitImpl<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 | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 367 | CcnxPitImpl<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 | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 373 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 374 | CcnxPitImpl<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 | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 390 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 391 | CcnxPitImpl<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 | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 397 | Ptr<CcnxPitEntry> |
Alexander Afanasyev | bd6f3f4 | 2012-07-26 17:50:17 -0700 | [diff] [blame] | 398 | CcnxPitImpl<Policy>::Next (Ptr<CcnxPitEntry> 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 |
| 420 | template class CcnxPitImpl<persistent_policy_traits>; |
| 421 | template class CcnxPitImpl<random_policy_traits>; |
| 422 | template class CcnxPitImpl<lru_policy_traits>; |
| 423 | |
| 424 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(CcnxPitImpl, persistent_policy_traits); |
| 425 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(CcnxPitImpl, random_policy_traits); |
| 426 | NS_OBJECT_ENSURE_REGISTERED_TEMPL(CcnxPitImpl, lru_policy_traits); |
| 427 | |
| 428 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 429 | } // namespace ns3 |