NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
probability-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef PROBABILITY_POLICY_H_
21 #define PROBABILITY_POLICY_H_
22 
24 
25 #include "ns3/ndnSIM/model/ndn-common.hpp"
26 
27 #include <boost/intrusive/options.hpp>
28 #include <boost/intrusive/list.hpp>
29 
30 #include <ns3/random-variable-stream.h>
31 
32 namespace ns3 {
33 namespace ndn {
34 namespace ndnSIM {
35 
39 struct probability_policy_traits {
40  static std::string
41  GetName()
42  {
43  return "ProbabilityImpl";
44  }
45 
46  struct policy_hook_type : public boost::intrusive::list_member_hook<> {
47  };
48 
49  template<class Container>
50  struct container_hook {
51  typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
52  type;
53  };
54 
55  template<class Base, class Container, class Hook>
56  struct policy {
57  typedef typename boost::intrusive::list<Container, Hook> policy_container;
58 
59  class type : public policy_container {
60  public:
61  typedef policy policy_base; // to get access to get_freshness methods from outside
62  typedef Container parent_trie;
63 
64  type(Base& base)
65  : base_(base)
66  , max_size_(100)
67  , probability_(1.0)
68  , ns3_rand_(CreateObject<UniformRandomVariable>())
69  {
70  }
71 
72  inline void
73  update(typename parent_trie::iterator item)
74  {
75  }
76 
77  inline bool
78  insert(typename parent_trie::iterator item)
79  {
80  if (ns3_rand_->GetValue() < probability_) {
81  policy_container::push_back(*item);
82 
83  // allow caching
84  return true;
85  }
86  else {
87  // don't allow caching
88  return false;
89  }
90  }
91 
92  inline void
93  lookup(typename parent_trie::iterator item)
94  {
95  // do nothing. it's random policy
96  }
97 
98  inline void
99  erase(typename parent_trie::iterator item)
100  {
101  policy_container::erase(policy_container::s_iterator_to(*item));
102  }
103 
104  inline void
105  clear()
106  {
107  policy_container::clear();
108  }
109 
110  inline void
111  set_max_size(size_t max_size)
112  {
113  max_size_ = max_size;
114  }
115 
116  inline size_t
117  get_max_size() const
118  {
119  return max_size_;
120  }
121 
122  inline void
123  set_probability(double probability)
124  {
125  probability_ = probability;
126  }
127 
128  inline double
129  get_probability() const
130  {
131  return probability_;
132  }
133 
134  private:
135  type()
136  : base_(*((Base*)0)){};
137 
138  private:
139  Base& base_;
140  size_t max_size_;
141  double probability_;
142  Ptr<UniformRandomVariable> ns3_rand_;
143  };
144  };
145 };
146 
147 } // ndnSIM
148 } // ndn
149 } // ns3
150 
152 
153 #endif // PROBABILITY_POLICY_H
Copyright (c) 2011-2015 Regents of the University of California.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.