switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / RateAnalyzer.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief RateAnalyzer public header */
30
31 #ifndef HH_SENF_PPI_RateAnalyzer_
32 #define HH_SENF_PPI_RateAnalyzer_ 1
33
34 // Custom includes
35 #include <boost/function.hpp>
36 #include <boost/signal.hpp>
37 #include "MonitorModule.hh"
38 #include "IntervalTimer.hh"
39
40 //#include "RateAnalyzer.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 namespace senf {
44 namespace ppi {
45 namespace module {
46
47     /** \brief Generate periodic packet statistics
48
49         This module will periodically generate statistics concerning the traversing packets. The
50         statistics are emitted as Boost.Signals signals:
51
52         \li \c signals.packetsPerSecond: number of packets in the last interval scaled to 1 second
53         \li \c signals.bytesPerSecond; number of bytes in the last interval scaled to 1 second
54         \li \c signals.bytesPerPacket: minimal, average and maximal packet size in the last interval
55
56         These signals are normally connected as needed to senf::Statistics instances.
57
58         \code
59         senf::RateAnalyzer analyzer;
60         senf::Statistics packets;
61         senf::Statistics packetSize;
62
63         analyzer.signals.packetsPerSecond.connect(packets);
64         analyzer.signals.bytesPerPacket.connect(packetSize);
65
66         analyzer.startStatistics(senf::ClockService::milliseconds(100u));
67         \endcode
68
69         Statistics output is only generated after a call to startStatistics()
70
71         \ingroup routing_modules
72      */
73     class RateAnalyzer
74         : public MonitorModule<>
75     {
76         SENF_PPI_MODULE(RateAnalyzer);
77     public:
78         //-////////////////////////////////////////////////////////////////////////
79         ///\name Structors and default members
80         //\{
81
82         RateAnalyzer();
83
84         //\}
85         //-////////////////////////////////////////////////////////////////////////
86         // Statistics signals
87
88         struct Statistics {
89             boost::signal<void (float)> packetsPerSecond;
90             boost::signal<void (float)> bytesPerSecond;
91             boost::signal<void (unsigned,float,unsigned)> bytesPerPacket;
92         } signals;
93
94         void startStatistics(senf::ClockService::clock_type interval);
95                                         ///< Start generating statistics at given interval
96
97     private:
98         void v_handlePacket(Packet const & p);
99         void tick();
100
101         senf::ppi::IntervalTimer timer_;
102         unsigned packets_;
103         unsigned bytes_;
104         unsigned minSize_;
105         unsigned maxSize_;
106         double factor_;
107     };
108
109 }}}
110
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
112 //#include "RateAnalyzer.cci"
113 //#include "RateAnalyzer.ct"
114 //#include "RateAnalyzer.cti"
115 #endif
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // End: