A Discrete-Event Network Simulator
API
flow-monitor.h
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 #ifndef FLOW_MONITOR_H
22 #define FLOW_MONITOR_H
23 
24 #include <vector>
25 #include <map>
26 
27 #include "ns3/ptr.h"
28 #include "ns3/object.h"
29 #include "ns3/flow-probe.h"
30 #include "ns3/flow-classifier.h"
31 #include "ns3/histogram.h"
32 #include "ns3/nstime.h"
33 #include "ns3/event-id.h"
34 
35 namespace ns3 {
36 
50 class FlowMonitor : public Object
51 {
52 public:
53 
55  struct FlowStats
56  {
61 
66 
71 
75 
78  Time delaySum; // delayCount == rxPackets
79 
87  Time jitterSum; // jitterCount == rxPackets - 1
88 
92 
94  uint64_t txBytes;
96  uint64_t rxBytes;
98  uint32_t txPackets;
100  uint32_t rxPackets;
101 
107  uint32_t lostPackets;
108 
111  uint32_t timesForwarded;
112 
119 
132  std::vector<uint32_t> packetsDropped; // packetsDropped[reasonCode] => number of dropped packets
133 
136  std::vector<uint64_t> bytesDropped; // bytesDropped[reasonCode] => number of dropped bytes
138  };
139 
140  // --- basic methods ---
145  static TypeId GetTypeId ();
146  virtual TypeId GetInstanceTypeId () const;
147  FlowMonitor ();
148 
151  void AddFlowClassifier (Ptr<FlowClassifier> classifier);
152 
156  void Start (const Time &time);
160  void Stop (const Time &time);
162  void StartRightNow ();
164  void StopRightNow ();
165 
166  // --- methods to be used by the FlowMonitorProbe's only ---
171  void AddProbe (Ptr<FlowProbe> probe);
172 
181  void ReportFirstTx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
188  void ReportForwarding (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
195  void ReportLastRx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
203  void ReportDrop (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId,
204  uint32_t packetSize, uint32_t reasonCode);
205 
207  void CheckForLostPackets ();
208 
213  void CheckForLostPackets (Time maxDelay);
214 
215  // --- methods to get the results ---
216 
218  typedef std::map<FlowId, FlowStats> FlowStatsContainer;
220  typedef std::map<FlowId, FlowStats>::iterator FlowStatsContainerI;
222  typedef std::map<FlowId, FlowStats>::const_iterator FlowStatsContainerCI;
224  typedef std::vector< Ptr<FlowProbe> > FlowProbeContainer;
226  typedef std::vector< Ptr<FlowProbe> >::iterator FlowProbeContainerI;
228  typedef std::vector< Ptr<FlowProbe> >::const_iterator FlowProbeContainerCI;
229 
235  const FlowStatsContainer& GetFlowStats () const;
236 
239  const FlowProbeContainer& GetAllProbes () const;
240 
246  void SerializeToXmlStream (std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes);
247 
253  std::string SerializeToXmlString (uint16_t indent, bool enableHistograms, bool enableProbes);
254 
259  void SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes);
260 
261 
262 protected:
263 
264  virtual void NotifyConstructionCompleted ();
265  virtual void DoDispose (void);
266 
267 private:
268 
271  {
274  uint32_t timesForwarded;
275  };
276 
279 
281  typedef std::map< std::pair<FlowId, FlowPacketId>, TrackedPacket> TrackedPacketMap;
285 
286  // note: this is needed only for serialization
287  std::list<Ptr<FlowClassifier> > m_classifiers;
288 
291  bool m_enabled;
297 
301  FlowStats& GetStatsForFlow (FlowId flowId);
302 
305 };
306 
307 
308 } // namespace ns3
309 
310 #endif /* FLOW_MONITOR_H */
311 
ns3::FlowMonitor::AddProbe
void AddProbe(Ptr< FlowProbe > probe)
Register a new FlowProbe that will begin monitoring and report events to this monitor.
Definition: flow-monitor.cc:349
ns3::FlowMonitor::TrackedPacket
Structure to represent a single tracked packet data.
Definition: flow-monitor.h:271
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::FlowMonitor::FlowProbeContainerI
std::vector< Ptr< FlowProbe > >::iterator FlowProbeContainerI
Container Iterator: FlowProbe.
Definition: flow-monitor.h:226
ns3::FlowMonitor::FlowStats::delaySum
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
Definition: flow-monitor.h:78
ns3::FlowMonitor::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition: flow-monitor.cc:37
ns3::FlowMonitor::StartRightNow
void StartRightNow()
Begin monitoring flows right now
Definition: flow-monitor.cc:387
ns3::FlowMonitor::FlowStats::bytesDropped
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
Definition: flow-monitor.h:136
ns3::FlowMonitor::m_maxPerHopDelay
Time m_maxPerHopDelay
Minimum per-hop delay.
Definition: flow-monitor.h:283
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::FlowMonitor::ReportFirstTx
void ReportFirstTx(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize)
FlowProbe implementations are supposed to call this method to report that a new packet was transmitte...
Definition: flow-monitor.cc:140
ns3::FlowMonitor::TrackedPacketMap
std::map< std::pair< FlowId, FlowPacketId >, TrackedPacket > TrackedPacketMap
(FlowId,PacketId) --> TrackedPacket
Definition: flow-monitor.h:281
ns3::FlowMonitor::m_flowProbes
FlowProbeContainer m_flowProbes
all the FlowProbes
Definition: flow-monitor.h:284
ns3::FlowMonitor::FlowStats::timeLastRxPacket
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
Definition: flow-monitor.h:74
ns3::FlowMonitor::NotifyConstructionCompleted
virtual void NotifyConstructionCompleted()
Notifier called once the ObjectBase is fully constructed.
Definition: flow-monitor.cc:342
ns3::FlowMonitor::FlowStats::rxBytes
uint64_t rxBytes
Total number of received bytes for the flow.
Definition: flow-monitor.h:96
ns3::FlowMonitor::FlowStats::lostPackets
uint32_t lostPackets
Total number of packets that are assumed to be lost, i.e.
Definition: flow-monitor.h:107
ns3::FlowMonitor::ReportDrop
void ReportDrop(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize, uint32_t reasonCode)
FlowProbe implementations are supposed to call this method to report that a known packet is being dro...
Definition: flow-monitor.cc:261
ns3::FlowMonitor::m_trackedPackets
TrackedPacketMap m_trackedPackets
Tracked packets.
Definition: flow-monitor.h:282
ns3::FlowMonitor::m_delayBinWidth
double m_delayBinWidth
Delay bin width (for histograms)
Definition: flow-monitor.h:292
ns3::FlowMonitor::ReportLastRx
void ReportLastRx(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize)
FlowProbe implementations are supposed to call this method to report that a known packet is being rec...
Definition: flow-monitor.cc:196
ns3::FlowMonitor::m_enabled
bool m_enabled
FlowMon is enabled.
Definition: flow-monitor.h:291
ns3::FlowMonitor::TrackedPacket::timesForwarded
uint32_t timesForwarded
number of times the packet was reportedly forwarded
Definition: flow-monitor.h:274
ns3::Histogram
Class used to store data and make an histogram of the data frequency.
Definition: histogram.h:46
ns3::FlowMonitor::m_startEvent
EventId m_startEvent
Start event.
Definition: flow-monitor.h:289
ns3::FlowMonitor::FlowStats::txBytes
uint64_t txBytes
Total number of transmitted bytes for the flow.
Definition: flow-monitor.h:94
ns3::FlowMonitor::SerializeToXmlString
std::string SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but returns the output as a std::string.
Definition: flow-monitor.cc:506
ns3::FlowMonitor::FlowStats::lastDelay
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter.
Definition: flow-monitor.h:91
ns3::FlowPacketId
uint32_t FlowPacketId
Abstract identifier of a packet within a flow.
Definition: flow-classifier.h:39
ns3::FlowMonitor::FlowStats::jitterHistogram
Histogram jitterHistogram
Histogram of the packet jitters.
Definition: flow-monitor.h:116
ns3::FlowId
uint32_t FlowId
Abstract identifier of a packet flow.
Definition: flow-classifier.h:33
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::FlowMonitor::FlowStats::rxPackets
uint32_t rxPackets
Total number of received packets for the flow.
Definition: flow-monitor.h:100
ns3::FlowMonitor::FlowStatsContainer
std::map< FlowId, FlowStats > FlowStatsContainer
Container: FlowId, FlowStats.
Definition: flow-monitor.h:218
check-style.indent
def indent(source, debug, level)
Definition: check-style.py:435
ns3::FlowMonitor::FlowProbeContainerCI
std::vector< Ptr< FlowProbe > >::const_iterator FlowProbeContainerCI
Container Const Iterator: FlowProbe.
Definition: flow-monitor.h:228
ns3::FlowMonitor::FlowStats::flowInterruptionsHistogram
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
Definition: flow-monitor.h:137
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::FlowMonitor::GetAllProbes
const FlowProbeContainer & GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
Definition: flow-monitor.cc:356
ns3::FlowMonitor::FlowProbeContainer
std::vector< Ptr< FlowProbe > > FlowProbeContainer
Container: FlowProbe.
Definition: flow-monitor.h:224
ns3::FlowMonitor::FlowStatsContainerCI
std::map< FlowId, FlowStats >::const_iterator FlowStatsContainerCI
Container Const Iterator: FlowId, FlowStats.
Definition: flow-monitor.h:222
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::FlowMonitor::FlowStats::packetSizeHistogram
Histogram packetSizeHistogram
Histogram of the packet sizes.
Definition: flow-monitor.h:118
ns3::FlowMonitor::m_jitterBinWidth
double m_jitterBinWidth
Jitter bin width (for histograms)
Definition: flow-monitor.h:293
ns3::FlowMonitor
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:51
ns3::FlowMonitor::Stop
void Stop(const Time &time)
Set the time, counting from the current time, from which to stop monitoring flows.
Definition: flow-monitor.cc:377
ns3::FlowMonitor::m_stopEvent
EventId m_stopEvent
Stop event.
Definition: flow-monitor.h:290
ns3::FlowMonitor::TrackedPacket::firstSeenTime
Time firstSeenTime
absolute time when the packet was first seen by a probe
Definition: flow-monitor.h:272
ns3::FlowMonitor::StopRightNow
void StopRightNow()
End monitoring flows right now
Definition: flow-monitor.cc:400
ns3::FlowMonitor::m_packetSizeBinWidth
double m_packetSizeBinWidth
packet size bin width (for histograms)
Definition: flow-monitor.h:294
ns3::FlowMonitor::FlowStats::packetsDropped
std::vector< uint32_t > packetsDropped
This attribute also tracks the number of lost packets and bytes, but discriminates the losses by a re...
Definition: flow-monitor.h:132
ns3::FlowMonitor::FlowStats::delayHistogram
Histogram delayHistogram
Histogram of the packet delays.
Definition: flow-monitor.h:114
ns3::FlowMonitor::FlowStats::timeFirstTxPacket
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
Definition: flow-monitor.h:60
packetSize
static const uint32_t packetSize
Definition: wifi-power-adaptation-distance.cc:113
ns3::FlowMonitor::GetStatsForFlow
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
Definition: flow-monitor.cc:109
ns3::FlowMonitor::FlowMonitor
FlowMonitor()
Definition: flow-monitor.cc:82
ns3::FlowMonitor::FlowStatsContainerI
std::map< FlowId, FlowStats >::iterator FlowStatsContainerI
Container Iterator: FlowId, FlowStats.
Definition: flow-monitor.h:220
ns3::FlowMonitor::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: flow-monitor.cc:89
ns3::FlowMonitor::PeriodicCheckForLostPackets
void PeriodicCheckForLostPackets()
Periodic function to check for lost packets and prune statistics.
Definition: flow-monitor.cc:335
ns3::FlowMonitor::TrackedPacket::lastSeenTime
Time lastSeenTime
absolute time when the packet was last seen by a probe
Definition: flow-monitor.h:273
ns3::FlowMonitor::FlowStats::jitterSum
Time jitterSum
Contains the sum of all end-to-end delay jitter (delay variation) values for all received packets of ...
Definition: flow-monitor.h:87
ns3::FlowMonitor::FlowStats::timeLastTxPacket
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e.
Definition: flow-monitor.h:70
ns3::FlowMonitor::FlowStats::txPackets
uint32_t txPackets
Total number of transmitted packets for the flow.
Definition: flow-monitor.h:98
ns3::FlowMonitor::AddFlowClassifier
void AddFlowClassifier(Ptr< FlowClassifier > classifier)
Add a FlowClassifier to be used by the flow monitor.
Definition: flow-monitor.cc:413
ns3::FlowMonitor::Start
void Start(const Time &time)
Set the time, counting from the current time, from which to start monitoring flows.
Definition: flow-monitor.cc:363
ns3::FlowMonitor::GetInstanceTypeId
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: flow-monitor.cc:77
ns3::FlowMonitor::m_flowInterruptionsMinTime
Time m_flowInterruptionsMinTime
Flow interruptions minimum time.
Definition: flow-monitor.h:296
ns3::FlowMonitor::SerializeToXmlStream
void SerializeToXmlStream(std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes)
Serializes the results to an std::ostream in XML format.
Definition: flow-monitor.cc:419
ns3::FlowMonitor::m_flowInterruptionsBinWidth
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
Definition: flow-monitor.h:295
ns3::FlowMonitor::m_flowStats
FlowStatsContainer m_flowStats
FlowId --> FlowStats.
Definition: flow-monitor.h:278
ns3::FlowMonitor::GetFlowStats
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
Definition: flow-monitor.cc:296
ns3::FlowMonitor::FlowStats::timesForwarded
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
Definition: flow-monitor.h:111
ns3::FlowMonitor::FlowStats
Structure that represents the measured metrics of an individual packet flow.
Definition: flow-monitor.h:56
ns3::FlowMonitor::CheckForLostPackets
void CheckForLostPackets()
Check right now for packets that appear to be lost.
Definition: flow-monitor.cc:329
ns3::FlowMonitor::FlowStats::timeFirstRxPacket
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node,...
Definition: flow-monitor.h:65
ns3::FlowMonitor::SerializeToXmlFile
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
Definition: flow-monitor.cc:516
ns3::FlowMonitor::ReportForwarding
void ReportForwarding(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize)
FlowProbe implementations are supposed to call this method to report that a known packet is being for...
Definition: flow-monitor.cc:170
ns3::FlowMonitor::m_classifiers
std::list< Ptr< FlowClassifier > > m_classifiers
the FlowClassifiers
Definition: flow-monitor.h:287