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.
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 //
     3 // Copyright (c) 2009 INESC Porto
     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: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
    19 //
    20 
    21 #ifndef __FLOW_PROBE_H__
    22 #define __FLOW_PROBE_H__
    23 
    24 #include <map>
    25 #include <vector>
    26 
    27 #include "ns3/simple-ref-count.h"
    28 #include "ns3/flow-classifier.h"
    29 #include "ns3/nstime.h"
    30 
    31 namespace ns3 {
    32 
    33 class FlowMonitor;
    34   
    35 /// The FlowProbe class is responsible for listening for packet events
    36 /// in a specific point of the simulated space, report those events to
    37 /// the global FlowMonitor, and collect its own flow statistics
    38 /// regarding only the packets that pass through that probe.
    39 class FlowProbe : public SimpleRefCount<FlowProbe>
    40 {
    41 protected:
    42   
    43   FlowProbe (Ptr<FlowMonitor> flowMonitor);
    44   
    45 public:
    46   virtual ~FlowProbe ();
    47 
    48   struct FlowStats
    49   {
    50     FlowStats () : delayFromFirstProbeSum (Seconds (0)), bytes (0), packets (0) {}
    51 
    52     /// packetsDropped[reasonCode] => number of dropped packets
    53     std::vector<uint32_t> packetsDropped;
    54     /// bytesDropped[reasonCode] => number of dropped bytes
    55     std::vector<uint64_t> bytesDropped;
    56     /// divide by 'Scalar (packets)' to get the average delay from the
    57     /// first (entry) probe up to this one (partial delay)
    58     Time delayFromFirstProbeSum;
    59     /// Number of bytes seen of this flow
    60     uint64_t bytes;
    61     /// Number of packets seen of this flow
    62     uint32_t packets;
    63   };
    64   
    65   typedef std::map<FlowId, FlowStats> Stats;
    66   
    67   void AddPacketStats (FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe);
    68   void AddPacketDropStats (FlowId flowId, uint32_t packetSize, uint32_t reasonCode);
    69 
    70   /// Get the partial flow statistics stored in this probe.  With this
    71   /// information you can, for example, find out what is the delay
    72   /// from the first probe to this one.
    73   Stats GetStats () const;
    74 
    75   void SerializeToXmlStream (std::ostream &os, int indent, uint32_t index) const;
    76 
    77 protected:
    78   Ptr<FlowMonitor> m_flowMonitor;
    79   Stats m_stats;
    80 
    81 };
    82 
    83 
    84 } // namespace ns3
    85 
    86 #endif
    87