blob: ee61df4d972ad2e84226d7407a7873cca005af54 [file] [log] [blame]
Alexander Afanasyev0845c092012-07-13 17:45:33 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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#include "load-stats.h"
22
23using namespace ns3;
24
25const double EXP_1 = exp (-5.0/60.0); /* 1/exp(5sec/1min) */
26const double EXP_5 = exp (-5.0/300.0); /* 1/exp(5sec/5min) */
27const double EXP_15 = exp (-5.0/900.0); /* 1/exp(5sec/15min) */
28
29const double EPSILON = 0.000001;
30
31namespace ndnSIM
32{
33
34LoadStats::LoadStats ()
35 : counter_ (0)
36 , avg1_ (0)
37 , avg5_ (0)
38 , avg15_ (0)
39{
40}
41
42void
43LoadStats::Step ()
44{
45 // do magic
46 avg1_ = EXP_1 * avg1_ + (1 - EXP_1) * counter_;
47 avg5_ = EXP_1 * avg5_ + (1 - EXP_5) * counter_;
48 avg15_ = EXP_1 * avg15_ + (1 - EXP_15) * counter_;
49
50 counter_ = 0;
51}
52
53LoadStats &
54LoadStats::operator ++ (int)
55{
56 counter_ ++;
57 return *this;
58}
59
60// void
61// LoadStats::Increment (uint32_t amount)
62// {
63// counter_ += amount;
64// }
65
66// uint32_t
67// LoadStats::GetCounter () const
68// {
69// return counter_;
70// }
71
72LoadStats &
73LoadStats::operator += (const LoadStats &stats)
74{
75 counter_ += stats.counter_;
76 return *this;
77}
78
79LoadStats::stats_tuple
80LoadStats::GetStats () const
81{
82 return stats_tuple (avg1_, avg5_, avg15_);
83}
84
85bool
86LoadStats::IsEmpty () const
87{
88 return (avg1_ < EPSILON &&
89 avg5_ < EPSILON &&
90 avg15_ < EPSILON);
91}
92
93std::ostream &
94operator << (std::ostream &os, const LoadStats &stats)
95{
96 LoadStats::stats_tuple data = stats.GetStats ();
97 os << data.get<0> () << ", " << data.get<1> () << ", " << data.get<2> ();// << std::endl;
98 return os;
99}
100
101} // ndnSIM