src/contrib/flow-monitor/flow-probe.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Nov 12 13:01:01 2009 +0100 (2009-11-12)
changeset 5505 c0ac392289c3
parent 5210 2acc35ea1e80
child 5877 24dd3b1a0bb6
permissions -rw-r--r--
replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
gjc@5205
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
gjc@5205
     2
//
gjc@5205
     3
// Copyright (c) 2009 INESC Porto
gjc@5205
     4
//
gjc@5205
     5
// This program is free software; you can redistribute it and/or modify
gjc@5205
     6
// it under the terms of the GNU General Public License version 2 as
gjc@5205
     7
// published by the Free Software Foundation;
gjc@5205
     8
//
gjc@5205
     9
// This program is distributed in the hope that it will be useful,
gjc@5205
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
gjc@5205
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
gjc@5205
    12
// GNU General Public License for more details.
gjc@5205
    13
//
gjc@5205
    14
// You should have received a copy of the GNU General Public License
gjc@5205
    15
// along with this program; if not, write to the Free Software
gjc@5205
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
gjc@5205
    17
//
gjc@5205
    18
// Author: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
gjc@5205
    19
//
gjc@5205
    20
gjc@5205
    21
#ifndef __FLOW_PROBE_H__
gjc@5205
    22
#define __FLOW_PROBE_H__
gjc@5205
    23
gjc@5205
    24
#include <map>
gjc@5205
    25
#include <vector>
gjc@5205
    26
mathieu@5505
    27
#include "ns3/simple-ref-count.h"
gjc@5205
    28
#include "ns3/flow-classifier.h"
gjc@5205
    29
#include "ns3/nstime.h"
gjc@5205
    30
gjc@5205
    31
namespace ns3 {
gjc@5205
    32
gjc@5205
    33
class FlowMonitor;
gjc@5205
    34
  
gjc@5210
    35
/// The FlowProbe class is responsible for listening for packet events
gjc@5210
    36
/// in a specific point of the simulated space, report those events to
gjc@5210
    37
/// the global FlowMonitor, and collect its own flow statistics
gjc@5210
    38
/// regarding only the packets that pass through that probe.
mathieu@5505
    39
class FlowProbe : public SimpleRefCount<FlowProbe>
gjc@5205
    40
{
gjc@5205
    41
protected:
gjc@5205
    42
  
gjc@5205
    43
  FlowProbe (Ptr<FlowMonitor> flowMonitor);
gjc@5205
    44
  
gjc@5205
    45
public:
mathieu@5505
    46
  virtual ~FlowProbe ();
gjc@5205
    47
gjc@5205
    48
  struct FlowStats
gjc@5205
    49
  {
gjc@5205
    50
    FlowStats () : delayFromFirstProbeSum (Seconds (0)), bytes (0), packets (0) {}
gjc@5205
    51
gjc@5210
    52
    /// packetsDropped[reasonCode] => number of dropped packets
gjc@5210
    53
    std::vector<uint32_t> packetsDropped;
gjc@5210
    54
    /// bytesDropped[reasonCode] => number of dropped bytes
gjc@5210
    55
    std::vector<uint64_t> bytesDropped;
gjc@5210
    56
    /// divide by 'Scalar (packets)' to get the average delay from the
gjc@5210
    57
    /// first (entry) probe up to this one (partial delay)
gjc@5210
    58
    Time delayFromFirstProbeSum;
gjc@5210
    59
    /// Number of bytes seen of this flow
gjc@5205
    60
    uint64_t bytes;
gjc@5210
    61
    /// Number of packets seen of this flow
gjc@5205
    62
    uint32_t packets;
gjc@5205
    63
  };
gjc@5205
    64
  
gjc@5205
    65
  typedef std::map<FlowId, FlowStats> Stats;
gjc@5205
    66
  
gjc@5205
    67
  void AddPacketStats (FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe);
gjc@5205
    68
  void AddPacketDropStats (FlowId flowId, uint32_t packetSize, uint32_t reasonCode);
gjc@5210
    69
gjc@5210
    70
  /// Get the partial flow statistics stored in this probe.  With this
gjc@5210
    71
  /// information you can, for example, find out what is the delay
gjc@5210
    72
  /// from the first probe to this one.
gjc@5205
    73
  Stats GetStats () const;
gjc@5205
    74
gjc@5205
    75
  void SerializeToXmlStream (std::ostream &os, int indent, uint32_t index) const;
gjc@5205
    76
gjc@5205
    77
protected:
gjc@5205
    78
  Ptr<FlowMonitor> m_flowMonitor;
gjc@5205
    79
  Stats m_stats;
gjc@5205
    80
gjc@5205
    81
};
gjc@5205
    82
gjc@5205
    83
gjc@5205
    84
} // namespace ns3
gjc@5205
    85
gjc@5205
    86
#endif
gjc@5205
    87