b19fd76d37e3848b4edf47502b3a3146811ced12
[senf.git] / senf / PPI / RateAnalyzer.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief RateAnalyzer public header */
25
26 #ifndef HH_SENF_PPI_RateAnalyzer_
27 #define HH_SENF_PPI_RateAnalyzer_ 1
28
29 // Custom includes
30 #include <boost/function.hpp>
31 #include <boost/signal.hpp>
32 #include "MonitorModule.hh"
33 #include "IntervalTimer.hh"
34
35 //#include "RateAnalyzer.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace ppi {
40 namespace module {
41
42     /** \brief Generate periodic packet statistics
43
44         This module will periodically generate statistics concerning the traversing packets. The
45         statistics are emitted as Boost.Signals signals:
46
47         \li \c signals.packetsPerSecond: number of packets in the last interval scaled to 1 second
48         \li \c signals.bytesPerSecond; number of bytes in the last interval scaled to 1 second
49         \li \c signals.bytesPerPacket: minimal, average and maximal packet size in the last interval
50
51         These signals are normally connected as needed to senf::Statistics instances.
52
53         \code
54         senf::RateAnalyzer analyzer;
55         senf::Statistics packets;
56         senf::Statistics packetSize;
57
58         analyzer.signals.packetsPerSecond.connect(packets);
59         analyzer.signals.bytesPerPacket.connect(packetSize);
60
61         analyzer.startStatistics(senf::ClockService::milliseconds(100u));
62         \endcode
63
64         Statistics output is only generated after a call to startStatistics()
65
66         \ingroup routing_modules
67      */
68     class RateAnalyzer
69         : public MonitorModule<>
70     {
71         SENF_PPI_MODULE(RateAnalyzer);
72     public:
73         ///////////////////////////////////////////////////////////////////////////
74         ///\name Structors and default members
75         ///\{
76
77         RateAnalyzer();
78
79         ///\}
80         ///////////////////////////////////////////////////////////////////////////
81         // Statistics signals
82
83         struct Statistics {
84             boost::signal<void (float)> packetsPerSecond;
85             boost::signal<void (float)> bytesPerSecond;
86             boost::signal<void (unsigned,float,unsigned)> bytesPerPacket;
87         } signals;
88
89         void startStatistics(senf::ClockService::clock_type interval);
90                                         ///< Start generating statistics at given interval
91
92     private:
93         void v_handlePacket(Packet const & p);
94         void tick();
95
96         senf::ppi::IntervalTimer timer_;
97         unsigned packets_;
98         unsigned bytes_;
99         unsigned minSize_;
100         unsigned maxSize_;
101         double factor_;
102     };
103
104 }}}
105
106 ///////////////////////////////hh.e////////////////////////////////////////
107 //#include "RateAnalyzer.cci"
108 //#include "RateAnalyzer.ct"
109 //#include "RateAnalyzer.cti"
110 #endif
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: