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
fifo-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 FIFO_POLICY_H_
22 #define FIFO_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 
35 {
37  static std::string GetName () { return "Fifo"; }
38 
39  struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
40 
41  template<class Container>
43  {
44  // could be class/struct implementation
45  typedef boost::intrusive::member_hook< Container,
47  &Container::policy_hook_ > type;
48  };
49 
50  template<class Base,
51  class Container,
52  class Hook>
53  struct policy
54  {
55  typedef typename boost::intrusive::list< Container, Hook > policy_container;
56 
57  // could be just typedef
58  class type : public policy_container
59  {
60  public:
61  typedef Container parent_trie;
62 
63  type (Base &base)
64  : base_ (base)
65  , max_size_ (100)
66  {
67  }
68 
69  inline void
70  update (typename parent_trie::iterator item)
71  {
72  // do nothing
73  }
74 
75  inline bool
76  insert (typename parent_trie::iterator item)
77  {
78  if (max_size_ != 0 && policy_container::size () >= max_size_)
79  {
80  base_.erase (&(*policy_container::begin ()));
81  }
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
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Definition: fifo-policy.h:37
Traits for First In First Out replacement policy.
Definition: fifo-policy.h:34