21 #ifndef FRESHNESS_POLICY_H_
22 #define FRESHNESS_POLICY_H_
24 #include <boost/intrusive/options.hpp>
25 #include <boost/intrusive/list.hpp>
27 #include <ns3/nstime.h>
28 #include <ns3/simulator.h>
29 #include <ns3/traced-callback.h>
41 static std::string
GetName () {
return "Freshness"; }
43 struct policy_hook_type :
public boost::intrusive::set_member_hook<> { Time timeWhenShouldExpire; };
45 template<
class Container>
48 typedef boost::intrusive::member_hook< Container,
50 &Container::policy_hook_ > type;
58 static Time& get_freshness (
typename Container::iterator item)
60 return static_cast<typename policy_container::value_traits::hook_type*
>
61 (policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
64 static const Time& get_freshness (
typename Container::const_iterator item)
66 return static_cast<const typename policy_container::value_traits::hook_type*
>
67 (policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire;
73 bool operator () (
const Key &a,
const Key &b)
const
75 return get_freshness (&a) < get_freshness (&b);
79 typedef boost::intrusive::multiset< Container,
80 boost::intrusive::compare< MemberHookLess< Container > >,
81 Hook > policy_container;
84 class type :
public policy_container
88 typedef Container parent_trie;
97 update (
typename parent_trie::iterator item)
103 insert (
typename parent_trie::iterator item)
106 Time freshness = item->payload ()->GetData ()->GetFreshness ();
107 if (!freshness.IsZero ())
109 get_freshness (item) = Simulator::Now () + freshness;
113 policy_container::insert (*item);
120 lookup (
typename parent_trie::iterator item)
126 erase (
typename parent_trie::iterator item)
128 if (!item->payload ()->GetData ()->GetFreshness ().IsZero ())
131 policy_container::erase (policy_container::s_iterator_to (*item));
138 policy_container::clear ();
142 set_max_size (
size_t max_size)
144 max_size_ = max_size;
148 get_max_size ()
const
154 type () : base_(*((Base*)0)) { };
167 #endif // LIFETIME_STATS_POLICY_H
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Traits for freshness policy.