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