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, int indent, uint32_t index) const
87 {
88  #define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
89 
90  INDENT (indent); os << "<FlowProbe index=\"" << index << "\">\n";
91 
92  indent += 2;
93 
94  for (Stats::const_iterator iter = m_stats.begin (); iter != m_stats.end (); iter++)
95  {
96  INDENT (indent);
97  os << "<FlowStats "
98  << " flowId=\"" << iter->first << "\""
99  << " packets=\"" << iter->second.packets << "\""
100  << " bytes=\"" << iter->second.bytes << "\""
101  << " delayFromFirstProbeSum=\"" << iter->second.delayFromFirstProbeSum << "\""
102  << " >\n";
103  indent += 2;
104  for (uint32_t reasonCode = 0; reasonCode < iter->second.packetsDropped.size (); reasonCode++)
105  {
106  INDENT (indent);
107  os << "<packetsDropped reasonCode=\"" << reasonCode << "\""
108  << " number=\"" << iter->second.packetsDropped[reasonCode]
109  << "\" />\n";
110  }
111  for (uint32_t reasonCode = 0; reasonCode < iter->second.bytesDropped.size (); reasonCode++)
112  {
113  INDENT (indent);
114  os << "<bytesDropped reasonCode=\"" << reasonCode << "\""
115  << " bytes=\"" << iter->second.bytesDropped[reasonCode]
116  << "\" />\n";
117  }
118  indent -= 2;
119  INDENT (indent); os << "</FlowStats>\n";
120  }
121  indent -= 2;
122  INDENT (indent); os << "</FlowProbe>\n";
123 }
124 
125 
126 
127 } // namespace ns3
128 
129 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static TypeId GetTypeId(void)
Register this type.
Definition: flow-probe.cc:27
std::vector< uint64_t > bytesDropped
bytesDropped[reasonCode] => number of dropped bytes
Definition: flow-probe.h:69
virtual ~FlowProbe()
Definition: flow-probe.cc:38
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
void AddPacketStats(FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
Add a packet data to the flow stats.
Definition: flow-probe.cc:57
Ptr< FlowMonitor > m_flowMonitor
the FlowMonitor instance
Definition: flow-probe.h:106
uint32_t packets
Number of packets seen of this flow.
Definition: flow-probe.h:76
uint64_t bytes
Number of bytes seen of this flow.
Definition: flow-probe.h:74
def indent(source, debug, level)
Definition: check-style.py:286
std::vector< uint32_t > packetsDropped
packetsDropped[reasonCode] => number of dropped packets
Definition: flow-probe.h:67
Structure to hold the statistics of a flow.
Definition: flow-probe.h:62
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddPacketDropStats(FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
Add a packet drop data to the flow stats.
Definition: flow-probe.cc:66
#define INDENT(level)
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:72
void SerializeToXmlStream(std::ostream &os, int indent, uint32_t index) const
Serializes the results to an std::ostream in XML format.
Definition: flow-probe.cc:86
std::map< FlowId, FlowStats > Stats
Container to map FlowId -> FlowStats.
Definition: flow-probe.h:80
Stats GetStats() const
Get the partial flow statistics stored in this probe.
Definition: flow-probe.cc:80
static const uint32_t packetSize
A base class which provides memory management and object aggregation.
Definition: object.h:87
FlowProbe(FlowProbe const &)
Defined and not implemented to avoid misuse.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
virtual void DoDispose(void)
Destructor implementation.
Definition: flow-probe.cc:50
Stats m_stats
The flow stats.
Definition: flow-probe.h:107
uint32_t FlowId
Abstract identifier of a packet flow.