20 #ifndef NDN_CONTENT_STORE_WITH_FRESHNESS_H_
21 #define NDN_CONTENT_STORE_WITH_FRESHNESS_H_
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
27 #include "../../utils/trie/multi-policy.hpp"
38 template<
class Policy>
41 multi_policy_traits<boost::mpl::
43 ndnSIM::freshness_policy_traits>>> {
47 ndnSIM::freshness_policy_traits>>>
56 Print(std::ostream& os)
const;
59 Add(shared_ptr<const Data> data);
69 static LogComponent g_log;
72 Time m_scheduledCleaningTime;
79 template<
class Policy>
81 + Policy::GetName()).c_str());
83 template<
class Policy>
87 static TypeId tid = TypeId((
"ns3::ndn::cs::Freshness::" + Policy::GetName()).c_str())
98 template<
class Policy>
102 bool ok = super::Add(data);
106 NS_LOG_DEBUG(data->getName() <<
" added to cache");
107 RescheduleCleaning();
111 template<
class Policy>
115 const freshness_policy_container& freshness =
116 this->getPolicy().template get<freshness_policy_container>();
118 if (freshness.size() > 0) {
120 freshness_policy_container::policy_base::get_freshness(&(*freshness.begin()));
122 if (m_scheduledCleaningTime.IsZero() ||
123 m_scheduledCleaningTime > nextStateTime)
125 if (m_cleanEvent.IsRunning()) {
126 Simulator::Remove(m_cleanEvent);
130 m_cleanEvent = Simulator::Schedule(nextStateTime - Now(),
131 &ContentStoreWithFreshness<Policy>::CleanExpired,
this);
132 m_scheduledCleaningTime = nextStateTime;
136 if (m_cleanEvent.IsRunning()) {
137 Simulator::Remove(m_cleanEvent);
142 template<
class Policy>
144 ContentStoreWithFreshness<Policy>::CleanExpired()
146 freshness_policy_container& freshness =
147 this->getPolicy().template get<freshness_policy_container>();
151 Time now = Simulator::Now();
153 while (!freshness.empty()) {
154 typename freshness_policy_container::iterator entry = freshness.begin();
156 if (freshness_policy_container::policy_base::get_freshness(&(*entry))
159 super::erase(&(*entry));
167 m_scheduledCleaningTime = Time();
168 RescheduleCleaning();
171 template<
class Policy>
178 for (
typename super::policy_container::const_iterator item = this->getPolicy().begin();
179 item != this->getPolicy().end(); item++) {
180 Time ttl = freshness_policy_container::policy_base::get_freshness(&(*item)) - Simulator::Now();
181 os << item->payload()->GetName() <<
"(left: " << ttl.ToDouble(Time::S) <<
"s)" << std::endl;
189 #endif // NDN_CONTENT_STORE_WITH_FRESHNESS_H_
static TypeId GetTypeId()
ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::freshness_policy_traits > > > super
virtual void Print(std::ostream &os) const
Print out content store entries.
Opaque type (shared_ptr) representing ID of a scheduled event.
Special content store realization that honors Freshness parameter in Data packets.
super::policy_container::template index< 1 >::type freshness_policy_container
Base implementation of NDN content store.
virtual bool Add(shared_ptr< const Data > data)
Add a new content to the content store.