A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  TypeId GetInstanceTypeId () const;
147  FlowMonitor ();
148 
151  void AddFlowClassifier (Ptr<FlowClassifier> classifier);
152 
155  void Start (const Time &time);
158  void Stop (const Time &time);
160  void StartRightNow ();
162  void StopRightNow ();
163 
164  // --- methods to be used by the FlowMonitorProbe's only ---
169  void AddProbe (Ptr<FlowProbe> probe);
170 
179  void ReportFirstTx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
186  void ReportForwarding (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
193  void ReportLastRx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
201  void ReportDrop (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId,
202  uint32_t packetSize, uint32_t reasonCode);
203 
205  void CheckForLostPackets ();
206 
211  void CheckForLostPackets (Time maxDelay);
212 
213  // --- methods to get the results ---
219  std::map<FlowId, FlowStats> GetFlowStats () const;
220 
223  std::vector< Ptr<FlowProbe> > GetAllProbes () const;
224 
230  void SerializeToXmlStream (std::ostream &os, int indent, bool enableHistograms, bool enableProbes);
236  std::string SerializeToXmlString (int indent, bool enableHistograms, bool enableProbes);
241  void SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes);
242 
243 
244 protected:
245 
246  virtual void NotifyConstructionCompleted ();
247  virtual void DoDispose (void);
248 
249 private:
250 
253  {
256  uint32_t timesForwarded;
257  };
258 
260  std::map<FlowId, FlowStats> m_flowStats;
261 
263  typedef std::map< std::pair<FlowId, FlowPacketId>, TrackedPacket> TrackedPacketMap;
266  std::vector< Ptr<FlowProbe> > m_flowProbes;
267 
268  // note: this is needed only for serialization
269  std::list<Ptr<FlowClassifier> > m_classifiers;
270 
273  bool m_enabled;
279 
283  FlowStats& GetStatsForFlow (FlowId flowId);
284 
287 };
288 
289 
290 } // namespace ns3
291 
292 #endif /* FLOW_MONITOR_H */
293 
uint32_t FlowPacketId
Abstract identifier of a packet within a flow.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
void CheckForLostPackets()
Check right now for packets that appear to be lost.
void StartRightNow()
Begin monitoring flows right now
uint32_t lostPackets
Total number of packets that are assumed to be lost, i.e.
Definition: flow-monitor.h:107
uint32_t rxPackets
Total number of received packets for the flow.
Definition: flow-monitor.h:100
uint32_t txPackets
Total number of transmitted packets for the flow.
Definition: flow-monitor.h:98
Time m_maxPerHopDelay
Minimum per-hop delay.
Definition: flow-monitor.h:265
static TypeId GetTypeId()
Get the type ID.
Definition: flow-monitor.cc:40
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...
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
Definition: flow-monitor.h:78
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
Definition: flow-monitor.h:136
std::map< FlowId, FlowStats > m_flowStats
FlowId –> FlowStats.
Definition: flow-monitor.h:260
Time m_flowInterruptionsMinTime
Flow interruptions minimum time.
Definition: flow-monitor.h:278
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...
TrackedPacketMap m_trackedPackets
Tracked packets.
Definition: flow-monitor.h:264
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter...
Definition: flow-monitor.h:91
std::map< FlowId, FlowStats > GetFlowStats() const
Retrieve all collected the flow statistics.
void SerializeToXmlStream(std::ostream &os, int indent, bool enableHistograms, bool enableProbes)
Serializes the results to an std::ostream in XML format.
Time firstSeenTime
absolute time when the packet was first seen by a probe
Definition: flow-monitor.h:254
std::list< Ptr< FlowClassifier > > m_classifiers
the FlowClassifiers
Definition: flow-monitor.h:269
std::map< std::pair< FlowId, FlowPacketId >, TrackedPacket > TrackedPacketMap
(FlowId,PacketId) –> TrackedPacket
Definition: flow-monitor.h:263
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
std::string SerializeToXmlString(int indent, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but returns the output as a std::string.
bool m_enabled
FlowMon is enabled.
Definition: flow-monitor.h:273
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
Definition: flow-monitor.h:60
double m_packetSizeBinWidth
packet size bin width (for histograms)
Definition: flow-monitor.h:276
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
double m_jitterBinWidth
Jitter bin width (for histograms)
Definition: flow-monitor.h:275
EventId m_stopEvent
Stop event.
Definition: flow-monitor.h:272
Time lastSeenTime
absolute time when the packet was last seen by a probe
Definition: flow-monitor.h:255
double m_delayBinWidth
Delay bin width (for histograms)
Definition: flow-monitor.h:274
virtual void NotifyConstructionCompleted()
This method is invoked once all member attributes have been initialized.
void Stop(const Time &time)
Set the time, counting from the current time, from which to stop monitoring flows.
std::vector< Ptr< FlowProbe > > m_flowProbes
all the FlowProbes
Definition: flow-monitor.h:266
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node...
Definition: flow-monitor.h:65
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
Definition: flow-monitor.h:111
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
Definition: flow-monitor.h:74
void AddFlowClassifier(Ptr< FlowClassifier > classifier)
Add a FlowClassifier to be used by the flow monitor.
void StopRightNow()
End monitoring flows right now
an identifier for simulation events.
Definition: event-id.h:46
Histogram delayHistogram
Histogram of the packet delays.
Definition: flow-monitor.h:114
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
std::vector< Ptr< FlowProbe > > GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: flow-monitor.cc:91
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
Definition: flow-monitor.h:137
uint64_t txBytes
Total number of transmitted bytes for the flow.
Definition: flow-monitor.h:94
Structure that represents the measured metrics of an individual packet flow.
Definition: flow-monitor.h:55
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
Definition: flow-monitor.h:277
Structure to represent a single tracked packet data.
Definition: flow-monitor.h:252
Histogram jitterHistogram
Histogram of the packet jitters.
Definition: flow-monitor.h:116
a base class which provides memory management and object aggregation
Definition: object.h:64
EventId m_startEvent
Start event.
Definition: flow-monitor.h:271
void Start(const Time &time)
Set the time, counting from the current time, from which to start monitoring flows.
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...
uint64_t rxBytes
Total number of received bytes for the flow.
Definition: flow-monitor.h:96
void PeriodicCheckForLostPackets()
Periodic function to check for lost packets and prune statistics.
uint32_t timesForwarded
number of times the packet was reportedly forwarded
Definition: flow-monitor.h:256
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:50
void AddProbe(Ptr< FlowProbe > probe)
Register a new FlowProbe that will begin monitoring and report events to this monitor.
a unique identifier for an interface.
Definition: type-id.h:49
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e. ...
Definition: flow-monitor.h:70
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...
Histogram packetSizeHistogram
Histogram of the packet sizes.
Definition: flow-monitor.h:118
TypeId GetInstanceTypeId() const
Definition: flow-monitor.cc:79
Class used to store data and make an histogram of the data frequency.
Definition: histogram.h:45
uint32_t FlowId
Abstract identifier of a packet flow.
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