Class Histogram.
authorPedro Fortuna <pedro.fortuna@inescporto.pt>
Thu Apr 30 19:24:40 2009 +0100 (9 months ago)
changeset 3944e4b11ff588ec
parent 3941 009dc59d7502
child 3945 91e35f21dcd0
Class Histogram.
src/contrib/flow-monitor/flow-monitor.h
src/contrib/flow-monitor/histogram.cc
src/contrib/flow-monitor/histogram.h
src/contrib/flow-monitor/wscript
     1.1 --- a/src/contrib/flow-monitor/flow-monitor.h	Thu Apr 30 16:17:06 2009 +0100
     1.2 +++ b/src/contrib/flow-monitor/flow-monitor.h	Thu Apr 30 19:24:40 2009 +0100
     1.3 @@ -55,6 +55,7 @@
     1.4  
     1.5    // --- methods to be used by the FlowMonitorProbe's only ---
     1.6    void AddProbe (Ptr<FlowProbe> probe);
     1.7 +  void AddDelayVal (double delay);
     1.8    void ReportFirstTx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
     1.9    void ReportForwarding (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
    1.10    void ReportLastRx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
    1.11 @@ -67,6 +68,7 @@
    1.12    // remember to call CheckForLostPackets first!
    1.13    std::map<FlowId, FlowStats> GetFlowStats () const;
    1.14    std::vector< Ptr<FlowProbe> > GetAllProbes () const;
    1.15 +  
    1.16  
    1.17  
    1.18  protected:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/contrib/flow-monitor/histogram.cc	Thu Apr 30 19:24:40 2009 +0100
     2.3 @@ -0,0 +1,105 @@
     2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2.5 +//
     2.6 +// Copyright (c) 2009 INESC Porto
     2.7 +//
     2.8 +// This program is free software; you can redistribute it and/or modify
     2.9 +// it under the terms of the GNU General Public License version 2 as
    2.10 +// published by the Free Software Foundation;
    2.11 +//
    2.12 +// This program is distributed in the hope that it will be useful,
    2.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 +// GNU General Public License for more details.
    2.16 +//
    2.17 +// You should have received a copy of the GNU General Public License
    2.18 +// along with this program; if not, write to the Free Software
    2.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 +//
    2.21 +// Author: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
    2.22 +//
    2.23 +
    2.24 +#include "histogram.h"
    2.25 +#include "ns3/simulator.h"
    2.26 +#include "ns3/log.h"
    2.27 +
    2.28 +#define DEFAULT_BIN_WIDTH	1
    2.29 +#define RESERVED_BINS_INC	10
    2.30 +
    2.31 +namespace ns3 {
    2.32 +
    2.33 +NS_LOG_COMPONENT_DEFINE ("Histogram");
    2.34 +
    2.35 +NS_OBJECT_ENSURE_REGISTERED (Histogram);
    2.36 +  
    2.37 +void 
    2.38 +Histogram::SetBinWidth(double binWidth)
    2.39 +{
    2.40 +  this->bin_width=binWidth;
    2.41 +}
    2.42 +  
    2.43 +uint32_t 
    2.44 +Histogram::GetNBins() const
    2.45 +{
    2.46 +  return this->number_bins;
    2.47 +}
    2.48 +  
    2.49 +double 
    2.50 +Histogram::GetBinStart(uint32_t index)
    2.51 +{
    2.52 +  return (double)((index+1)*bin_width);
    2.53 +}
    2.54 +  
    2.55 +double 
    2.56 +Histogram::GetBinWidth(uint32_t index) const
    2.57 +{
    2.58 +  return this->bin_width;
    2.59 +}
    2.60 +
    2.61 +uint32_t 
    2.62 +Histogram::GetBinCount(uint32_t index) 
    2.63 +{
    2.64 +  return this->histogram.size();
    2.65 +}
    2.66 +  
    2.67 +void 
    2.68 +Histogram::AddHistogramValue(double value)
    2.69 +{
    2.70 +  //check if we need to expand the vector
    2.71 +  if (histogram.size() == histogram.capacity())
    2.72 +    histogram.resize(histogram.size()+RESERVED_BINS_INC);
    2.73 +
    2.74 +  uint32_t index = floor(value/bin_width);
    2.75 +  
    2.76 +  // see
    2.77 +//  if (index+1<histogram.capacity()
    2.78 +  
    2.79 +  //uint32_t counter = histogram.at(index)++;
    2.80 +  this->histogram[index]++;
    2.81 +}
    2.82 +  
    2.83 +TypeId 
    2.84 +Histogram::GetTypeId (void)
    2.85 +{
    2.86 +  static TypeId tid = TypeId ("ns3::Histogram")
    2.87 +    .SetParent<Object> ()
    2.88 +    .AddConstructor<Histogram> ()
    2.89 +    ;
    2.90 +  return tid;
    2.91 +}
    2.92 +
    2.93 +TypeId 
    2.94 +Histogram::GetInstanceTypeId (void) const
    2.95 +{
    2.96 +  return GetTypeId ();
    2.97 +}
    2.98 +
    2.99 +Histogram::Histogram ()
   2.100 +{
   2.101 +  //no need to init Vector
   2.102 +  histogram.reserve(RESERVED_BINS_INC);
   2.103 +  bin_width=DEFAULT_BIN_WIDTH;
   2.104 +  number_bins=0;
   2.105 +}
   2.106 +
   2.107 +} // namespace ns3
   2.108 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/contrib/flow-monitor/histogram.h	Thu Apr 30 19:24:40 2009 +0100
     3.3 @@ -0,0 +1,65 @@
     3.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     3.5 +//
     3.6 +// Copyright (c) 2009 INESC Porto
     3.7 +//
     3.8 +// This program is free software; you can redistribute it and/or modify
     3.9 +// it under the terms of the GNU General Public License version 2 as
    3.10 +// published by the Free Software Foundation;
    3.11 +//
    3.12 +// This program is distributed in the hope that it will be useful,
    3.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 +// GNU General Public License for more details.
    3.16 +//
    3.17 +// You should have received a copy of the GNU General Public License
    3.18 +// along with this program; if not, write to the Free Software
    3.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.20 +//
    3.21 +// Author: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
    3.22 +//
    3.23 +
    3.24 +#ifndef __HISTOGRAM_H__
    3.25 +#define __HISTOGRAM_H__
    3.26 +
    3.27 +#include <vector>
    3.28 +//#include <map>
    3.29 +
    3.30 +#include "ns3/ptr.h"
    3.31 +#include "ns3/object.h"
    3.32 +//#include "ns3/nstime.h"
    3.33 +
    3.34 +namespace ns3 {
    3.35 +
    3.36 +class Histogram : public Object
    3.37 +{
    3.38 +public:
    3.39 +
    3.40 +  // --- basic methods ---
    3.41 +  static TypeId GetTypeId ();
    3.42 +  TypeId GetInstanceTypeId () const;
    3.43 +  Histogram ();
    3.44 +
    3.45 +  // Methods for Configuring the Histogram
    3.46 +  void SetBinWidth(double binWidth);
    3.47 +
    3.48 +  // Methods for Getting the Histogram Results
    3.49 +  uint32_t GetNBins() const;
    3.50 +  double GetBinStart(uint32_t index);
    3.51 +  double GetBinWidth(uint32_t index) const;
    3.52 +  uint32_t GetBinCount(uint32_t index);
    3.53 +  
    3.54 +  // Method for adding values
    3.55 +  void AddHistogramValue(double value);
    3.56 +  
    3.57 +private:
    3.58 +  std::vector<uint32_t> histogram;
    3.59 +  double bin_width;
    3.60 +  uint32_t number_bins;
    3.61 +
    3.62 +};
    3.63 +
    3.64 +
    3.65 +} // namespace ns3
    3.66 +
    3.67 +#endif
    3.68 +
     4.1 --- a/src/contrib/flow-monitor/wscript	Thu Apr 30 16:17:06 2009 +0100
     4.2 +++ b/src/contrib/flow-monitor/wscript	Thu Apr 30 19:24:40 2009 +0100
     4.3 @@ -8,6 +8,7 @@
     4.4         'flow-probe.cc',
     4.5         'ipv4-flow-classifier.cc',
     4.6         'ipv4-flow-probe.cc',
     4.7 +       'histogram.cc',	
     4.8          ]
     4.9      headers = bld.create_obj('ns3header')
    4.10      headers.module = 'flow-monitor'
    4.11 @@ -17,5 +18,6 @@
    4.12         'flow-classifier.h',
    4.13         'ipv4-flow-classifier.h',
    4.14         'ipv4-flow-probe.h',
    4.15 +       'histogram.h',
    4.16          ]
    4.17