21 #ifndef NDN_CONTENT_STORE_WITH_FRESHNESS_H_ 
   22 #define NDN_CONTENT_STORE_WITH_FRESHNESS_H_ 
   24 #include "content-store-impl.h" 
   26 #include "../../utils/trie/multi-policy.h" 
   27 #include "custom-policies/freshness-policy.h" 
   37 template<
class Policy>
 
   39     public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::freshness_policy_traits > > >
 
   44   typedef typename super::policy_container::template index<1>::type freshness_policy_container;
 
   50   Print (std::ostream &os) 
const;
 
   53   Add (Ptr<const Data> data);
 
   60   RescheduleCleaning ();
 
   63   static LogComponent g_log; 
 
   66   Time m_scheduledCleaningTime;
 
   74 template<
class Policy>
 
   79 template<
class Policy>
 
   83   static TypeId tid = TypeId ((
"ns3::ndn::cs::Freshness::"+Policy::GetName ()).c_str ())
 
   95 template<
class Policy>
 
   99   bool ok = super::Add (data);
 
  100   if (!ok) 
return false;
 
  102   NS_LOG_DEBUG (data->GetName () << 
" added to cache");
 
  103   RescheduleCleaning ();
 
  107 template<
class Policy>
 
  111   const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
 
  113   if (freshness.size () > 0)
 
  115       Time nextStateTime = freshness_policy_container::policy_base::get_freshness (&(*freshness.begin ()));
 
  117       if (m_scheduledCleaningTime.IsZero () || 
 
  118           m_scheduledCleaningTime > nextStateTime) 
 
  120           if (m_cleanEvent.IsRunning ())
 
  122               Simulator::Remove (m_cleanEvent); 
 
  126           m_cleanEvent = Simulator::Schedule (nextStateTime - Now (), &ContentStoreWithFreshness< Policy >::CleanExpired, 
this);
 
  127           m_scheduledCleaningTime = nextStateTime;
 
  132       if (m_cleanEvent.IsRunning ())
 
  134           Simulator::Remove (m_cleanEvent); 
 
  140 template<
class Policy>
 
  142 ContentStoreWithFreshness< Policy >::CleanExpired ()
 
  144   freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
 
  147   Time now = Simulator::Now ();
 
  149   while (!freshness.empty ())
 
  151       typename freshness_policy_container::iterator entry = freshness.begin ();
 
  153       if (freshness_policy_container::policy_base::get_freshness (&(*entry)) <= now) 
 
  155           super::erase (&(*entry));
 
  162   m_scheduledCleaningTime = Time ();
 
  163   RescheduleCleaning ();
 
  166 template<
class Policy>
 
  173        item != this->getPolicy ().end ();
 
  176       Time ttl = freshness_policy_container::policy_base::get_freshness (&(*item)) - Simulator::Now ();
 
  177       os << item->payload ()->GetName () << 
"(left: " << ttl.ToDouble (Time::S) << 
"s)" << std::endl;
 
  187 #endif // NDN_CONTENT_STORE_WITH_FRESHNESS_H_ 
Special content store realization that honors Freshness parameter in Data packets. 
 
virtual bool Add(Ptr< const Data > data)
Add a new content to the content store. 
 
Base implementation of NDN content store. 
 
virtual void Print(std::ostream &os) const 
Print out content store entries.