21 #ifndef SERIALIZED_POLICY_H_
22 #define SERIALIZED_POLICY_H_
24 #include <boost/intrusive/options.hpp>
25 #include <boost/intrusive/set.hpp>
37 static std::string
GetName () {
return "SerializedSize"; }
39 struct policy_hook_type :
public boost::intrusive::set_member_hook<> { uint32_t size; };
41 template<
class Container>
44 typedef boost::intrusive::member_hook< Container,
46 &Container::policy_hook_ > type;
54 static uint32_t& get_size (
typename Container::iterator item)
56 return static_cast<typename policy_container::value_traits::hook_type*
>
57 (policy_container::value_traits::to_node_ptr(*item))->size;
60 static const uint32_t& get_size (
typename Container::const_iterator item)
62 return static_cast<const typename policy_container::value_traits::hook_type*
>
63 (policy_container::value_traits::to_node_ptr(*item))->size;
69 bool operator () (
const Key &a,
const Key &b)
const
71 return get_size (&a) < get_size (&b);
75 typedef typename boost::intrusive::multiset< Container,
76 boost::intrusive::compare< MemberHookLess< Container > >,
77 Hook > policy_container;
80 class type :
public policy_container
83 typedef Container parent_trie;
88 , current_space_used_ (0)
93 update (
typename parent_trie::iterator item)
96 current_space_used_ -= get_size (item);
97 policy_container::erase (*item);
99 if (item->payload ()->GetInterest ()->GetWire ())
101 policy::get_size (item) = item->payload ()->GetInterest ()->GetWire ()->GetSize ();
105 policy::get_size (item) = 0;
107 current_space_used_ += get_size (item);
109 policy_container::insert (*item);
113 insert (
typename parent_trie::iterator item)
115 uint32_t interestSize = 0;
116 if (item->payload ()->GetInterest ()->GetWire ())
118 interestSize = item->payload ()->GetInterest ()->GetWire ()->GetSize ();
122 NS_LOG_DEBUG (
"Number of entries: " << policy_container::size ()
123 <<
", space used: " << current_space_used_
124 <<
", name: " << item->payload ()->GetPrefix ()
125 <<
", interest size: " << interestSize);
127 if (max_size_ != 0 && current_space_used_ + interestSize > max_size_)
129 NS_LOG_DEBUG (
"Rejecting PIT entry");
136 policy::get_size (item) = interestSize;
137 current_space_used_ += interestSize;
139 policy_container::insert (*item);
144 lookup (
typename parent_trie::iterator item)
150 erase (
typename parent_trie::iterator item)
152 NS_LOG_DEBUG (
"Erasing entry with name: " << item->payload ()->GetPrefix ());
154 current_space_used_ -= policy::get_size (item);
155 policy_container::erase (policy_container::s_iterator_to (*item));
161 policy_container::clear ();
165 set_max_size (
size_t max_size)
167 max_size_ = max_size;
171 get_max_size ()
const
177 get_current_space_used ()
const
179 return current_space_used_;
183 type () : base_(*((Base*)0)) { };
188 uint32_t current_space_used_;
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Traits for Least Recently Used replacement policy.