blob: 3628cc68b595eebcd9245765152be8096ccb4a8c [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev26719e22013-03-26 12:43:28 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev26719e22013-03-26 12:43:28 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev26719e22013-03-26 12:43:28 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev26719e22013-03-26 12:43:28 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev26719e22013-03-26 12:43:28 -070019
20#ifndef AGGREGATE_STATS_POLICY_H_
21#define AGGREGATE_STATS_POLICY_H_
22
23#include <boost/intrusive/options.hpp>
24#include <boost/intrusive/list.hpp>
25
26namespace ns3 {
27namespace ndn {
28namespace ndnSIM {
29
30/**
31 * @brief Traits for policy that just keeps track of number of elements
32 * It's doing a rather expensive job, but just in case it needs to be extended later
33 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034struct aggregate_stats_policy_traits {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070035 /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036 static std::string
37 GetName()
Alexander Afanasyev26719e22013-03-26 12:43:28 -070038 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 return "AggregateStats";
40 }
41 struct policy_hook_type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070042 };
43
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 template<class Container>
45 struct container_hook {
46 struct type {
47 };
48 };
49
50 template<class Base, class Container, class Hook>
51 struct policy {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070052 // typedef typename boost::intrusive::list< Container, Hook > policy_container;
53
54 // could be just typedef
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 class type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070056 public:
57 typedef Container parent_trie;
58
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 type(Base& base)
60 : base_(base)
61 , m_updates(0)
62 , m_inserts(0)
63 , m_lookups(0)
64 , m_erases(0)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070065 {
66 }
67
68 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 update(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070070 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 m_updates++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070072 // do nothing
73 }
74
75 inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 insert(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070077 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 m_inserts++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070079 return true;
80 }
81
82 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 lookup(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070084 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 m_lookups++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070086 }
87
88 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 erase(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070090 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 m_erases++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070092 }
93
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 inline void set_max_size(uint32_t)
95 {
96 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -070097
98 inline uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 get_max_size() const
100 {
101 return 0;
102 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700103
104 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 clear()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700106 {
107 // is called only at the end of simulation
108 }
109
110 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 ResetStats()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700112 {
113 m_updates = 0;
114 m_inserts = 0;
115 m_lookups = 0;
116 m_erases = 0;
117 }
118
119 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 GetUpdates() const
121 {
122 return m_updates;
123 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700124
125 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 GetInserts() const
127 {
128 return m_inserts;
129 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700130
131 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 GetLookups() const
133 {
134 return m_lookups;
135 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700136
137 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 GetErases() const
139 {
140 return m_erases;
141 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700142
143 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 type()
145 : base_(*((Base*)0)){};
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700146
147 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800148 Base& base_;
149
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700150 uint64_t m_updates;
151 uint64_t m_inserts;
152 uint64_t m_lookups;
153 uint64_t m_erases;
154 };
155 };
156};
157
158} // ndnSIM
159} // ndn
160} // ns3
161
162#endif // AGGREGATE_STATS_POLICY_H_