Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * 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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * 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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * 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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 19 | |
| 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 | |
| 26 | namespace ns3 { |
| 27 | namespace ndn { |
| 28 | namespace ndnSIM { |
| 29 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 30 | /// @cond include_hidden |
| 31 | |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 32 | /** |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 36 | struct aggregate_stats_policy_traits { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 37 | /// @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] | 38 | static std::string |
| 39 | GetName() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 40 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | return "AggregateStats"; |
| 42 | } |
| 43 | struct policy_hook_type { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | 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 Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 54 | // typedef typename boost::intrusive::list< Container, Hook > policy_container; |
| 55 | |
| 56 | // could be just typedef |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | class type { |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 58 | public: |
| 59 | typedef Container parent_trie; |
| 60 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | type(Base& base) |
| 62 | : base_(base) |
| 63 | , m_updates(0) |
| 64 | , m_inserts(0) |
| 65 | , m_lookups(0) |
| 66 | , m_erases(0) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
| 70 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | update(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 72 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | m_updates++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 74 | // do nothing |
| 75 | } |
| 76 | |
| 77 | inline bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | insert(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 79 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | m_inserts++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 81 | return true; |
| 82 | } |
| 83 | |
| 84 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | lookup(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | m_lookups++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | erase(typename parent_trie::iterator item) |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 92 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | m_erases++; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | inline void set_max_size(uint32_t) |
| 97 | { |
| 98 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 99 | |
| 100 | inline uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | get_max_size() const |
| 102 | { |
| 103 | return 0; |
| 104 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 105 | |
| 106 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | clear() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 108 | { |
| 109 | // is called only at the end of simulation |
| 110 | } |
| 111 | |
| 112 | inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | ResetStats() |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 114 | { |
| 115 | m_updates = 0; |
| 116 | m_inserts = 0; |
| 117 | m_lookups = 0; |
| 118 | m_erases = 0; |
| 119 | } |
| 120 | |
| 121 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 122 | GetUpdates() const |
| 123 | { |
| 124 | return m_updates; |
| 125 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 126 | |
| 127 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | GetInserts() const |
| 129 | { |
| 130 | return m_inserts; |
| 131 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 132 | |
| 133 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | GetLookups() const |
| 135 | { |
| 136 | return m_lookups; |
| 137 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 138 | |
| 139 | inline uint64_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 140 | GetErases() const |
| 141 | { |
| 142 | return m_erases; |
| 143 | } |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 144 | |
| 145 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 146 | type() |
| 147 | : base_(*((Base*)0)){}; |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 148 | |
| 149 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 150 | Base& base_; |
| 151 | |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 152 | 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 Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 164 | /// @endcond |
| 165 | |
Alexander Afanasyev | 26719e2 | 2013-03-26 12:43:28 -0700 | [diff] [blame] | 166 | #endif // AGGREGATE_STATS_POLICY_H_ |