Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 27 | namespace ns3 { |
| 28 | namespace ndn { |
| 29 | namespace 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 35 | struct aggregate_stats_policy_traits { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 36 | /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 37 | static std::string |
| 38 | GetName() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 39 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | return "AggregateStats"; |
| 41 | } |
| 42 | struct policy_hook_type { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | 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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 53 | // typedef typename boost::intrusive::list< Container, Hook > policy_container; |
| 54 | |
| 55 | // could be just typedef |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | class type { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 57 | public: |
| 58 | typedef Container parent_trie; |
| 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | type(Base& base) |
| 61 | : base_(base) |
| 62 | , m_updates(0) |
| 63 | , m_inserts(0) |
| 64 | , m_lookups(0) |
| 65 | , m_erases(0) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 66 | { |
| 67 | } |
| 68 | |
| 69 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | update(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 72 | m_updates++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 73 | // do nothing |
| 74 | } |
| 75 | |
| 76 | inline bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | insert(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 78 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | m_inserts++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 80 | return true; |
| 81 | } |
| 82 | |
| 83 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | lookup(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 85 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | m_lookups++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | erase(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 91 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | m_erases++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | inline void set_max_size(uint32_t) |
| 96 | { |
| 97 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 98 | |
| 99 | inline uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | get_max_size() const |
| 101 | { |
| 102 | return 0; |
| 103 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 104 | |
| 105 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | clear() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 107 | { |
| 108 | // is called only at the end of simulation |
| 109 | } |
| 110 | |
| 111 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 112 | ResetStats() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 113 | { |
| 114 | m_updates = 0; |
| 115 | m_inserts = 0; |
| 116 | m_lookups = 0; |
| 117 | m_erases = 0; |
| 118 | } |
| 119 | |
| 120 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 121 | GetUpdates() const |
| 122 | { |
| 123 | return m_updates; |
| 124 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 125 | |
| 126 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 127 | GetInserts() const |
| 128 | { |
| 129 | return m_inserts; |
| 130 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 131 | |
| 132 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 133 | GetLookups() const |
| 134 | { |
| 135 | return m_lookups; |
| 136 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 137 | |
| 138 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 139 | GetErases() const |
| 140 | { |
| 141 | return m_erases; |
| 142 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 143 | |
| 144 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | type() |
| 146 | : base_(*((Base*)0)){}; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 147 | |
| 148 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | Base& base_; |
| 150 | |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 151 | 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_ |