A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
flow-probe.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2009 INESC Porto
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 2 as
6// published by the Free Software Foundation;
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
18//
19
20#include "flow-probe.h"
21
22#include "flow-monitor.h"
23
24namespace ns3
25{
26
27/* static */
28TypeId
30{
31 static TypeId tid = TypeId("ns3::FlowProbe").SetParent<Object>().SetGroupName("FlowMonitor")
32 // No AddConstructor because this class has no default constructor.
33 ;
34
35 return tid;
36}
37
39{
40}
41
43 : m_flowMonitor(flowMonitor)
44{
45 m_flowMonitor->AddProbe(this);
46}
47
48void
50{
51 m_flowMonitor = nullptr;
53}
54
55void
57{
58 FlowStats& flow = m_stats[flowId];
59 flow.delayFromFirstProbeSum += delayFromFirstProbe;
60 flow.bytes += packetSize;
61 ++flow.packets;
62}
63
64void
66{
67 FlowStats& flow = m_stats[flowId];
68
69 if (flow.packetsDropped.size() < reasonCode + 1)
70 {
71 flow.packetsDropped.resize(reasonCode + 1, 0);
72 flow.bytesDropped.resize(reasonCode + 1, 0);
73 }
74 ++flow.packetsDropped[reasonCode];
75 flow.bytesDropped[reasonCode] += packetSize;
76}
77
80{
81 return m_stats;
82}
83
84void
85FlowProbe::SerializeToXmlStream(std::ostream& os, uint16_t indent, uint32_t index) const
86{
87 os << std::string(indent, ' ') << "<FlowProbe index=\"" << index << "\">\n";
88
89 indent += 2;
90
91 for (auto iter = m_stats.begin(); iter != m_stats.end(); iter++)
92 {
93 os << std::string(indent, ' ');
94 os << "<FlowStats "
95 << " flowId=\"" << iter->first << "\""
96 << " packets=\"" << iter->second.packets << "\""
97 << " bytes=\"" << iter->second.bytes << "\""
98 << " delayFromFirstProbeSum=\"" << iter->second.delayFromFirstProbeSum << "\""
99 << " >\n";
100 indent += 2;
101 for (uint32_t reasonCode = 0; reasonCode < iter->second.packetsDropped.size(); reasonCode++)
102 {
103 os << std::string(indent, ' ');
104 os << "<packetsDropped reasonCode=\"" << reasonCode << "\""
105 << " number=\"" << iter->second.packetsDropped[reasonCode] << "\" />\n";
106 }
107 for (uint32_t reasonCode = 0; reasonCode < iter->second.bytesDropped.size(); reasonCode++)
108 {
109 os << std::string(indent, ' ');
110 os << "<bytesDropped reasonCode=\"" << reasonCode << "\""
111 << " bytes=\"" << iter->second.bytesDropped[reasonCode] << "\" />\n";
112 }
113 indent -= 2;
114 os << std::string(indent, ' ') << "</FlowStats>\n";
115 }
116 indent -= 2;
117 os << std::string(indent, ' ') << "</FlowProbe>\n";
118}
119
120} // namespace ns3
Stats m_stats
The flow stats.
Definition: flow-probe.h:110
void AddPacketStats(FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
Add a packet data to the flow stats.
Definition: flow-probe.cc:56
FlowProbe(Ptr< FlowMonitor > flowMonitor)
Constructor.
Definition: flow-probe.cc:42
void DoDispose() override
Destructor implementation.
Definition: flow-probe.cc:49
void AddPacketDropStats(FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
Add a packet drop data to the flow stats.
Definition: flow-probe.cc:65
std::map< FlowId, FlowStats > Stats
Container to map FlowId -> FlowStats.
Definition: flow-probe.h:83
Stats GetStats() const
Get the partial flow statistics stored in this probe.
Definition: flow-probe.cc:79
static TypeId GetTypeId()
Register this type.
Definition: flow-probe.cc:29
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:85
Ptr< FlowMonitor > m_flowMonitor
the FlowMonitor instance
Definition: flow-probe.h:109
~FlowProbe() override
Definition: flow-probe.cc:38
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:444
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
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:61
uint64_t bytes
Number of bytes seen of this flow.
Definition: flow-probe.h:77
uint32_t packets
Number of packets seen of this flow.
Definition: flow-probe.h:79
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:75
std::vector< uint32_t > packetsDropped
packetsDropped[reasonCode] => number of dropped packets
Definition: flow-probe.h:70
std::vector< uint64_t > bytesDropped
bytesDropped[reasonCode] => number of dropped bytes
Definition: flow-probe.h:72
static const uint32_t packetSize
Packet size generated at the AP.