NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
persistent-policy.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #ifndef PERSISTENT_POLICY_H_
22 #define PERSISTENT_POLICY_H_
23 
24 #include <boost/intrusive/options.hpp>
25 #include <boost/intrusive/list.hpp>
26 
27 namespace ns3 {
28 namespace ndn {
29 namespace ndnSIM {
30 
38 {
40  static std::string GetName () { return "Persistent"; }
41 
42  struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
43 
44  template<class Container>
46  {
47  typedef boost::intrusive::member_hook< Container,
49  &Container::policy_hook_ > type;
50  };
51 
52  template<class Base,
53  class Container,
54  class Hook>
55  struct policy
56  {
57  typedef typename boost::intrusive::list< Container, Hook > policy_container;
58 
59  // could be just typedef
60  class type : public policy_container
61  {
62  public:
63  typedef Container parent_trie;
64 
65  type (Base &base)
66  : base_ (base)
67  , max_size_ (100) // when 0, policy is not enforced
68  {
69  }
70 
71  inline void
72  update (typename parent_trie::iterator item)
73  {
74  // do nothing
75  }
76 
77  inline bool
78  insert (typename parent_trie::iterator item)
79  {
80  if (max_size_ != 0 && policy_container::size () >= max_size_)
81  return false;
82 
83  policy_container::push_back (*item);
84  return true;
85  }
86 
87  inline void
88  lookup (typename parent_trie::iterator item)
89  {
90  // do nothing
91  }
92 
93  inline void
94  erase (typename parent_trie::iterator item)
95  {
96  policy_container::erase (policy_container::s_iterator_to (*item));
97  }
98 
99  inline void
100  clear ()
101  {
102  policy_container::clear ();
103  }
104 
105  inline void
106  set_max_size (size_t max_size)
107  {
108  max_size_ = max_size;
109  }
110 
111  inline size_t
112  get_max_size () const
113  {
114  return max_size_;
115  }
116 
117  private:
118  // type () : base_(*((Base*)0)) { };
119 
120  private:
121  Base &base_;
122  size_t max_size_;
123  };
124  };
125 };
126 
127 } // ndnSIM
128 } // ndn
129 } // ns3
130 
131 #endif // PERSISTENT_POLICY_H_
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Traits for persistent replacement policy.