blob: 4d2673b638114853d595889cceed66ef77f8301b [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
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080030/// @cond include_hidden
31
Alexander Afanasyev26719e22013-03-26 12:43:28 -070032/**
33 * @brief Traits for policy that just keeps track of number of elements
34 * It's doing a rather expensive job, but just in case it needs to be extended later
35 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036struct aggregate_stats_policy_traits {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070037 /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 static std::string
39 GetName()
Alexander Afanasyev26719e22013-03-26 12:43:28 -070040 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 return "AggregateStats";
42 }
43 struct policy_hook_type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070044 };
45
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 template<class Container>
47 struct container_hook {
48 struct type {
49 };
50 };
51
52 template<class Base, class Container, class Hook>
53 struct policy {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070054 // typedef typename boost::intrusive::list< Container, Hook > policy_container;
55
56 // could be just typedef
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 class type {
Alexander Afanasyev26719e22013-03-26 12:43:28 -070058 public:
59 typedef Container parent_trie;
60
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 type(Base& base)
62 : base_(base)
63 , m_updates(0)
64 , m_inserts(0)
65 , m_lookups(0)
66 , m_erases(0)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070067 {
68 }
69
70 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 update(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070072 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 m_updates++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070074 // do nothing
75 }
76
77 inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 insert(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070079 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 m_inserts++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070081 return true;
82 }
83
84 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 lookup(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070086 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 m_lookups++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070088 }
89
90 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 erase(typename parent_trie::iterator item)
Alexander Afanasyev26719e22013-03-26 12:43:28 -070092 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 m_erases++;
Alexander Afanasyev26719e22013-03-26 12:43:28 -070094 }
95
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 inline void set_max_size(uint32_t)
97 {
98 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -070099
100 inline uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 get_max_size() const
102 {
103 return 0;
104 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700105
106 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 clear()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700108 {
109 // is called only at the end of simulation
110 }
111
112 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 ResetStats()
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700114 {
115 m_updates = 0;
116 m_inserts = 0;
117 m_lookups = 0;
118 m_erases = 0;
119 }
120
121 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 GetUpdates() const
123 {
124 return m_updates;
125 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700126
127 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 GetInserts() const
129 {
130 return m_inserts;
131 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700132
133 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 GetLookups() const
135 {
136 return m_lookups;
137 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700138
139 inline uint64_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140 GetErases() const
141 {
142 return m_erases;
143 }
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700144
145 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 type()
147 : base_(*((Base*)0)){};
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700148
149 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800150 Base& base_;
151
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700152 uint64_t m_updates;
153 uint64_t m_inserts;
154 uint64_t m_lookups;
155 uint64_t m_erases;
156 };
157 };
158};
159
160} // ndnSIM
161} // ndn
162} // ns3
163
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800164/// @endcond
165
Alexander Afanasyev26719e22013-03-26 12:43:28 -0700166#endif // AGGREGATE_STATS_POLICY_H_