A Discrete-Event Network Simulator
API
flow-probe.cc
Go to the documentation of this file.
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 #include "ns3/flow-probe.h"
22 #include "ns3/flow-monitor.h"
23 
24 namespace ns3 {
25 
26 /* static */
28 {
29  static TypeId tid = TypeId ("ns3::FlowProbe")
30  .SetParent<Object> ()
31  .SetGroupName ("FlowMonitor")
32  // No AddConstructor because this class has no default constructor.
33  ;
34 
35  return tid;
36 }
37 
39 {
40 }
41 
42 
44  : m_flowMonitor (flowMonitor)
45 {
46  m_flowMonitor->AddProbe (this);
47 }
48 
49 void
51 {
52  m_flowMonitor = 0;
54 }
55 
56 void
57 FlowProbe::AddPacketStats (FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
58 {
59  FlowStats &flow = m_stats[flowId];
60  flow.delayFromFirstProbeSum += delayFromFirstProbe;
61  flow.bytes += packetSize;
62  ++flow.packets;
63 }
64 
65 void
66 FlowProbe::AddPacketDropStats (FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
67 {
68  FlowStats &flow = m_stats[flowId];
69 
70  if (flow.packetsDropped.size () < reasonCode + 1)
71  {
72  flow.packetsDropped.resize (reasonCode + 1, 0);
73  flow.bytesDropped.resize (reasonCode + 1, 0);
74  }
75  ++flow.packetsDropped[reasonCode];
76  flow.bytesDropped[reasonCode] += packetSize;
77 }
78 
81 {
82  return m_stats;
83 }
84 
85 void
86 FlowProbe::SerializeToXmlStream (std::ostream &os, uint16_t indent, uint32_t index) const
87 {
88  os << std::string ( indent, ' ' ) << "<FlowProbe index=\"" << index << "\">\n";
89 
90  indent += 2;
91 
92  for (Stats::const_iterator iter = m_stats.begin (); iter != m_stats.end (); iter++)
93  {
94  os << std::string ( indent, ' ' );
95  os << "<FlowStats "
96  << " flowId=\"" << iter->first << "\""
97  << " packets=\"" << iter->second.packets << "\""
98  << " bytes=\"" << iter->second.bytes << "\""
99  << " delayFromFirstProbeSum=\"" << iter->second.delayFromFirstProbeSum << "\""
100  << " >\n";
101  indent += 2;
102  for (uint32_t reasonCode = 0; reasonCode < iter->second.packetsDropped.size (); reasonCode++)
103  {
104  os << std::string ( indent, ' ' );
105  os << "<packetsDropped reasonCode=\"" << reasonCode << "\""
106  << " number=\"" << iter->second.packetsDropped[reasonCode]
107  << "\" />\n";
108  }
109  for (uint32_t reasonCode = 0; reasonCode < iter->second.bytesDropped.size (); reasonCode++)
110  {
111  os << std::string ( indent, ' ' );
112  os << "<bytesDropped reasonCode=\"" << reasonCode << "\""
113  << " bytes=\"" << iter->second.bytesDropped[reasonCode]
114  << "\" />\n";
115  }
116  indent -= 2;
117  os << std::string ( indent, ' ' ) << "</FlowStats>\n";
118  }
119  indent -= 2;
120  os << std::string ( indent, ' ' ) << "</FlowProbe>\n";
121 }
122 
123 
124 
125 } // namespace ns3
126 
127 
virtual ~FlowProbe()
Definition: flow-probe.cc:38
Stats m_stats
The flow stats.
Definition: flow-probe.h:104
void AddPacketStats(FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
Add a packet data to the flow stats.
Definition: flow-probe.cc:57
FlowProbe(Ptr< FlowMonitor > flowMonitor)
Constructor.
Definition: flow-probe.cc:43
static TypeId GetTypeId(void)
Register this type.
Definition: flow-probe.cc:27
void AddPacketDropStats(FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
Add a packet drop data to the flow stats.
Definition: flow-probe.cc:66
std::map< FlowId, FlowStats > Stats
Container to map FlowId -> FlowStats.
Definition: flow-probe.h:77
Stats GetStats() const
Get the partial flow statistics stored in this probe.
Definition: flow-probe.cc:80
virtual void DoDispose(void)
Destructor implementation.
Definition: flow-probe.cc:50
void SerializeToXmlStream(std::ostream &os, uint16_t indent, uint32_t index) const
Serializes the results to an std::ostream in XML format.
Definition: flow-probe.cc:86
Ptr< FlowMonitor > m_flowMonitor
the FlowMonitor instance
Definition: flow-probe.h:103
A base class which provides memory management and object aggregation.
Definition: object.h:88
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
uint32_t FlowId
Abstract identifier of a packet flow.
def indent(source, debug, level)
Definition: check-style.py:432
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure to hold the statistics of a flow.
Definition: flow-probe.h:60
uint64_t bytes
Number of bytes seen of this flow.
Definition: flow-probe.h:71
uint32_t packets
Number of packets seen of this flow.
Definition: flow-probe.h:73
Time delayFromFirstProbeSum
divide by 'packets' to get the average delay from the first (entry) probe up to this one (partial del...
Definition: flow-probe.h:69
std::vector< uint32_t > packetsDropped
packetsDropped[reasonCode] => number of dropped packets
Definition: flow-probe.h:64
std::vector< uint64_t > bytesDropped
bytesDropped[reasonCode] => number of dropped bytes
Definition: flow-probe.h:66
static const uint32_t packetSize