20 #ifndef LIFETIME_STATS_POLICY_H_
21 #define LIFETIME_STATS_POLICY_H_
25 #include "ns3/ndnSIM/model/ndn-common.hpp"
27 #include <boost/intrusive/options.hpp>
28 #include <boost/intrusive/list.hpp>
30 #include <ns3/nstime.h>
31 #include <ns3/simulator.h>
32 #include <ns3/traced-callback.h>
41 struct lifetime_stats_policy_traits {
46 return "LifetimeStats";
49 struct policy_hook_type :
public boost::intrusive::list_member_hook<> {
53 template<
class Container>
54 struct container_hook {
55 typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
59 template<
class Base,
class Container,
class Hook>
61 typedef typename boost::intrusive::list<Container, Hook> policy_container;
64 get_time(
typename Container::iterator item)
66 return static_cast<typename policy_container::value_traits::hook_type*
>(
67 policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
71 get_time(
typename Container::const_iterator item)
73 return static_cast<const typename policy_container::value_traits::hook_type*
>(
74 policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
77 class type :
public policy_container {
79 typedef policy policy_base;
80 typedef Container parent_trie;
85 , m_willRemoveEntry(0)
90 update(
typename parent_trie::iterator item)
96 insert(
typename parent_trie::iterator item)
98 get_time(item) = Simulator::Now();
100 policy_container::push_back(*item);
105 lookup(
typename parent_trie::iterator item)
111 erase(
typename parent_trie::iterator item)
113 Time lifetime = Simulator::Now() - get_time(item);
115 if (m_willRemoveEntry != 0) {
116 (*m_willRemoveEntry)(item->payload(), lifetime);
119 policy_container::erase(policy_container::s_iterator_to(*item));
125 policy_container::clear();
129 set_max_size(
size_t max_size)
131 max_size_ = max_size;
142 TracedCallback<typename parent_trie::payload_traits::const_base_type, Time>* callback)
144 m_willRemoveEntry = callback;
149 : base_(*((Base*)0)){};
155 TracedCallback<typename parent_trie::payload_traits::const_base_type, Time>*
167 #endif // LIFETIME_STATS_POLICY_H