blob: b2cb0bd5de894021489b871595aff8341e34b1dc [file] [log] [blame]
Alexander Afanasyev26719e22013-03-26 12:43:28 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011-2013 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 AGGREGATE_STATS_POLICY_H_
22#define AGGREGATE_STATS_POLICY_H_
23
24#include <boost/intrusive/options.hpp>
25#include <boost/intrusive/list.hpp>
26
27namespace ns3 {
28namespace ndn {
29namespace ndnSIM {
30
31/**
32 * @brief Traits for policy that just keeps track of number of elements
33 * It's doing a rather expensive job, but just in case it needs to be extended later
34 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035struct aggregate_stats_policy_traits {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070036 /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037 static std::string
38 GetName()
Alexander Afanasyev26719e22013-03-26 12:43:28 -070039 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 return "AggregateStats";
41 }
42 struct policy_hook_type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070043 };
44
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 template<class Container>
46 struct container_hook {
47 struct type {
48 };
49 };
50
51 template<class Base, class Container, class Hook>
52 struct policy {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070053 // typedef typename boost::intrusive::list< Container, Hook > policy_container;
54
55 // could be just typedef
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 class type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070057 public:
58 typedef Container parent_trie;
59
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 type(Base& base)
61 : base_(base)
62 , m_updates(0)
63 , m_inserts(0)
64 , m_lookups(0)
65 , m_erases(0)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070066 {
67 }
68
69 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 update(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070071 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 m_updates++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070073 // do nothing
74 }
75
76 inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 insert(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070078 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 m_inserts++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070080 return true;
81 }
82
83 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 lookup(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070085 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 m_lookups++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070087 }
88
89 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 erase(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070091 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 m_erases++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070093 }
94
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 inline void set_max_size(uint32_t)
96 {
97 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -070098
99 inline uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 get_max_size() const
101 {
102 return 0;
103 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700104
105 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 clear()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700107 {
108 // is called only at the end of simulation
109 }
110
111 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 ResetStats()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700113 {
114 m_updates = 0;
115 m_inserts = 0;
116 m_lookups = 0;
117 m_erases = 0;
118 }
119
120 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800121 GetUpdates() const
122 {
123 return m_updates;
124 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700125
126 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800127 GetInserts() const
128 {
129 return m_inserts;
130 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700131
132 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800133 GetLookups() const
134 {
135 return m_lookups;
136 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700137
138 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139 GetErases() const
140 {
141 return m_erases;
142 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700143
144 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 type()
146 : base_(*((Base*)0)){};
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700147
148 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 Base& base_;
150
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700151 uint64_t m_updates;
152 uint64_t m_inserts;
153 uint64_t m_lookups;
154 uint64_t m_erases;
155 };
156 };
157};
158
159} // ndnSIM
160} // ndn
161} // ns3
162
163#endif // AGGREGATE_STATS_POLICY_H_