21 #ifndef _NDN_PIT_IMPL_H_ 
   22 #define _NDN_PIT_IMPL_H_ 
   27 #include "ns3/simulator.h" 
   29 #include "../../utils/trie/trie-with-policy.h" 
   30 #include "ndn-pit-entry-impl.h" 
   32 #include "ns3/ndn-interest.h" 
   33 #include "ns3/ndn-data.h" 
   34 #include "ns3/ndn-forwarding-strategy.h" 
   35 #include "ns3/ndn-name.h" 
   41 class ForwardingStrategy;
 
   49 template<
class Policy>
 
   52                                                    ndnSIM::smart_pointer_payload_traits< EntryImpl< PitImpl< Policy > > >,
 
   93   Create (Ptr<const Interest> header);
 
   96   MarkErased (Ptr<Entry> 
entry);
 
   99   Print (std::ostream &os) 
const;
 
  113   const typename super::policy_container &
 
  114   GetPolicy ()
 const { 
return super::getPolicy (); }
 
  116   typename super::policy_container &
 
  117   GetPolicy () { 
return super::getPolicy (); }
 
  120   void RescheduleCleaning ();
 
  121   void CleanExpired ();
 
  132   SetMaxSize (uint32_t maxSize);
 
  135   GetCurrentSize () 
const;
 
  138   EventId m_cleanEvent;
 
  140   Ptr<ForwardingStrategy> m_forwardingStrategy;
 
  142   static LogComponent g_log; 
 
  146   boost::intrusive::multiset<entry,
 
  147                         boost::intrusive::compare < TimestampIndex< entry > >,
 
  148                         boost::intrusive::member_hook< entry,
 
  149                                                        boost::intrusive::set_member_hook<>,
 
  161 template<
class Policy>
 
  165 template<
class Policy>
 
  169   static TypeId tid = TypeId ((
"ns3::ndn::pit::"+Policy::GetName ()).c_str ())
 
  170     .SetGroupName (
"Ndn")
 
  173     .AddAttribute (
"MaxSize",
 
  174                    "Set maximum size of PIT in bytes. If 0, limit is not enforced",
 
  178                    MakeUintegerChecker<uint32_t> ())
 
  180     .AddAttribute (
"CurrentSize", 
"Get current size of PIT in bytes",
 
  184                    MakeUintegerChecker<uint32_t> ())
 
  190 template<
class Policy>
 
  194   return super::getPolicy ().size ();
 
  197 template<
class Policy>
 
  202 template<
class Policy>
 
  207 template<
class Policy>
 
  211   return super::getPolicy ().get_max_size ();
 
  214 template<
class Policy>
 
  216 PitImpl<Policy>::SetMaxSize (uint32_t maxSize)
 
  218   super::getPolicy ().set_max_size (maxSize);
 
  221 template<
class Policy>
 
  227       m_fib = GetObject<Fib> ();
 
  229   if (m_forwardingStrategy == 0)
 
  231       m_forwardingStrategy = GetObject<ForwardingStrategy> ();
 
  234   Pit::NotifyNewAggregate ();
 
  237 template<
class Policy>
 
  243   m_forwardingStrategy = 0;
 
  249 template<
class Policy>
 
  254   Simulator::Remove (m_cleanEvent); 
 
  261   Time nextEvent = i_time.begin ()->GetExpireTime () - Simulator::Now ();
 
  262   if (nextEvent <= 0) nextEvent = Seconds (0);
 
  264   NS_LOG_DEBUG (
"Schedule next cleaning in " <<
 
  265                 nextEvent.ToDouble (Time::S) << 
"s (at " <<
 
  266                 i_time.begin ()->GetExpireTime () << 
"s abs time");
 
  268   m_cleanEvent = Simulator::Schedule (nextEvent,
 
  269                                       &PitImpl<Policy>::CleanExpired, 
this);
 
  272 template<
class Policy>
 
  274 PitImpl<Policy>::CleanExpired ()
 
  276   NS_LOG_LOGIC (
"Cleaning PIT. Total: " << i_time.size ());
 
  277   Time now = Simulator::Now ();
 
  280   while (!i_time.empty ())
 
  282       typename time_index::iterator entry = i_time.begin ();
 
  283       if (entry->GetExpireTime () <= now) 
 
  285           m_forwardingStrategy->WillEraseTimedOutPendingInterest (entry->to_iterator ()->payload ());
 
  286           super::erase (entry->to_iterator ());
 
  293   if (super::getPolicy ().size ())
 
  295       NS_LOG_DEBUG (
"Size: " << super::getPolicy ().size ());
 
  296       NS_LOG_DEBUG (
"i_time size: " << i_time.size ());
 
  298   RescheduleCleaning ();
 
  301 template<
class Policy>
 
  308   if (item == super::end ())
 
  311     return item->payload (); 
 
  314 template<
class Policy>
 
  319   NS_ASSERT_MSG (m_fib != 0, 
"FIB should be set");
 
  320   NS_ASSERT_MSG (m_forwardingStrategy != 0, 
"Forwarding strategy  should be set");
 
  324   boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().
find (header.
GetName ());
 
  326   if (!reachLast || lastItem == super::end ())
 
  329     return lastItem->payload (); 
 
  332 template<
class Policy>
 
  338   if (item == super::end ())
 
  341     return item->payload ();
 
  345 template<
class Policy>
 
  349   NS_LOG_DEBUG (header->GetName ());
 
  350   Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (*header);
 
  358   Ptr< entry > newEntry = ns3::Create< entry > (boost::ref (*
this), header, fibEntry);
 
  359   std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
 
  360   if (result.first != super::end ())
 
  364           newEntry->SetTrie (result.first);
 
  371           return result.first->payload ();
 
  379 template<
class Policy>
 
  383   if (this->m_PitEntryPruningTimout.IsZero ())
 
  385       super::erase (StaticCast< entry > (item)->to_iterator ());
 
  389       item->OffsetLifetime (this->m_PitEntryPruningTimout - item->GetExpireTime () + Simulator::Now ());
 
  394 template<
class Policy>
 
  399   typename super::parent_trie::const_recursive_iterator item (super::getTrie ()), end (0);
 
  400   for (; item != end; item++)
 
  402       if (item->payload () == 0) 
continue;
 
  404       os << item->payload ()->GetPrefix () << 
"\t" << *item->payload () << 
"\n";
 
  408 template<
class Policy>
 
  412   return super::getPolicy ().size ();
 
  415 template<
class Policy>
 
  419   typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
 
  420   for (; item != end; item++)
 
  422       if (item->payload () == 0) 
continue;
 
  429     return item->payload ();
 
  432 template<
class Policy>
 
  439 template<
class Policy>
 
  443   if (from == 0) 
return 0;
 
  445   typename super::parent_trie::recursive_iterator
 
  446     item (*StaticCast< entry > (from)->to_iterator ()),
 
  449   for (item++; item != end; item++)
 
  451       if (item->payload () == 0) 
continue;
 
  458     return item->payload ();
 
boost::tuple< iterator, bool, iterator > find(const FullKey &key)
Perform the longest prefix match. 
 
virtual void NotifyNewAggregate()
Even when object is aggregated to another Object. 
 
virtual Ptr< Entry > Find(const Name &prefix)
Get PIT entry for the prefix (exact match) 
 
Class implementing Pending Interests Table. 
 
virtual Ptr< Entry > Lookup(const Data &header)
Find corresponding PIT entry for the given content name. 
 
const Name & GetName() const 
Get interest name. 
 
Class implementing Pending Interests Table. 
 
const Name & GetName() const 
Get name of the content object. 
 
virtual void DoDispose()
Do cleanup. 
 
virtual uint32_t GetSize() const 
Get number of entries in PIT. 
 
PIT entry implementation with additional pointers to the underlying container. 
 
virtual void Print(std::ostream &os) const 
Print out PIT contents for debugging purposes. 
 
static TypeId GetTypeId()
Interface ID. 
 
NDN Interest (wire formats are defined in wire) 
 
virtual Ptr< Entry > End()
Return item next after last (no order guaranteed) 
 
virtual Ptr< Entry > Create(Ptr< const Interest > header)
Creates a PIT entry for the given interest. 
 
virtual Ptr< Entry > Begin()
Return first element of FIB (no order guaranteed) 
 
virtual ~PitImpl()
Destructor. 
 
PitImpl()
PIT constructor.