A Discrete-Event Network Simulator
API
flow-monitor.h
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 #ifndef FLOW_MONITOR_H
21 #define FLOW_MONITOR_H
22 
23 #include "ns3/event-id.h"
24 #include "ns3/flow-classifier.h"
25 #include "ns3/flow-probe.h"
26 #include "ns3/histogram.h"
27 #include "ns3/nstime.h"
28 #include "ns3/object.h"
29 #include "ns3/ptr.h"
30 
31 #include <map>
32 #include <vector>
33 
34 namespace ns3
35 {
36 
50 class FlowMonitor : public Object
51 {
52  public:
54  struct FlowStats
55  {
60 
65 
70 
74 
77  Time delaySum; // delayCount == rxPackets
78 
86  Time jitterSum; // jitterCount == rxPackets - 1
87 
91 
93  uint64_t txBytes;
95  uint64_t rxBytes;
97  uint32_t txPackets;
99  uint32_t rxPackets;
100 
106  uint32_t lostPackets;
107 
110  uint32_t timesForwarded;
111 
118 
131  std::vector<uint32_t>
132  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 override;
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,
182  FlowId flowId,
183  FlowPacketId packetId,
184  uint32_t packetSize);
191  void ReportForwarding(Ptr<FlowProbe> probe,
192  FlowId flowId,
193  FlowPacketId packetId,
194  uint32_t packetSize);
201  void ReportLastRx(Ptr<FlowProbe> probe,
202  FlowId flowId,
203  FlowPacketId packetId,
204  uint32_t packetSize);
212  void ReportDrop(Ptr<FlowProbe> probe,
213  FlowId flowId,
214  FlowPacketId packetId,
215  uint32_t packetSize,
216  uint32_t reasonCode);
217 
219  void CheckForLostPackets();
220 
225  void CheckForLostPackets(Time maxDelay);
226 
227  // --- methods to get the results ---
228 
230  typedef std::map<FlowId, FlowStats> FlowStatsContainer;
232  typedef std::map<FlowId, FlowStats>::iterator FlowStatsContainerI;
234  typedef std::map<FlowId, FlowStats>::const_iterator FlowStatsContainerCI;
236  typedef std::vector<Ptr<FlowProbe>> FlowProbeContainer;
238  typedef std::vector<Ptr<FlowProbe>>::iterator FlowProbeContainerI;
240  typedef std::vector<Ptr<FlowProbe>>::const_iterator FlowProbeContainerCI;
241 
247  const FlowStatsContainer& GetFlowStats() const;
248 
251  const FlowProbeContainer& GetAllProbes() const;
252 
258  void SerializeToXmlStream(std::ostream& os,
259  uint16_t indent,
260  bool enableHistograms,
261  bool enableProbes);
262 
268  std::string SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes);
269 
274  void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes);
275 
276  protected:
277  void NotifyConstructionCompleted() override;
278  void DoDispose() override;
279 
280  private:
283  {
286  uint32_t timesForwarded;
287  };
288 
291 
293  typedef std::map<std::pair<FlowId, FlowPacketId>, TrackedPacket> TrackedPacketMap;
297 
298  // note: this is needed only for serialization
299  std::list<Ptr<FlowClassifier>> m_classifiers;
300 
303  bool m_enabled;
309 
314 
317 };
318 
319 } // namespace ns3
320 
321 #endif /* FLOW_MONITOR_H */
An identifier for simulation events.
Definition: event-id.h:55
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:51
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
FlowProbeContainer m_flowProbes
all the FlowProbes
Definition: flow-monitor.h:296
void StopRightNow()
End monitoring flows right now
const FlowProbeContainer & GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
std::vector< Ptr< FlowProbe > >::const_iterator FlowProbeContainerCI
Container Const Iterator: FlowProbe.
Definition: flow-monitor.h:240
std::vector< Ptr< FlowProbe > > FlowProbeContainer
Container: FlowProbe.
Definition: flow-monitor.h:236
FlowStatsContainer m_flowStats
FlowId --> FlowStats.
Definition: flow-monitor.h:290
bool m_enabled
FlowMon is enabled.
Definition: flow-monitor.h:303
void CheckForLostPackets()
Check right now for packets that appear to be lost.
void Start(const Time &time)
Set the time, counting from the current time, from which to start monitoring flows.
std::map< std::pair< FlowId, FlowPacketId >, TrackedPacket > TrackedPacketMap
(FlowId,PacketId) --> TrackedPacket
Definition: flow-monitor.h:293
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
Definition: flow-monitor.h:307
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
void AddFlowClassifier(Ptr< FlowClassifier > classifier)
Add a FlowClassifier to be used by the flow monitor.
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...
EventId m_startEvent
Start event.
Definition: flow-monitor.h:301
std::list< Ptr< FlowClassifier > > m_classifiers
the FlowClassifiers
Definition: flow-monitor.h:299
void AddProbe(Ptr< FlowProbe > probe)
Register a new FlowProbe that will begin monitoring and report events to this monitor.
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...
Time m_flowInterruptionsMinTime
Flow interruptions minimum time.
Definition: flow-monitor.h:308
std::vector< Ptr< FlowProbe > >::iterator FlowProbeContainerI
Container Iterator: FlowProbe.
Definition: flow-monitor.h:238
std::map< FlowId, FlowStats > FlowStatsContainer
Container: FlowId, FlowStats.
Definition: flow-monitor.h:230
double m_jitterBinWidth
Jitter bin width (for histograms)
Definition: flow-monitor.h:305
std::map< FlowId, FlowStats >::const_iterator FlowStatsContainerCI
Container Const Iterator: FlowId, FlowStats.
Definition: flow-monitor.h:234
std::string SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but returns the output as a std::string.
void Stop(const Time &time)
Set the time, counting from the current time, from which to stop monitoring flows.
void PeriodicCheckForLostPackets()
Periodic function to check for lost packets and prune statistics.
double m_packetSizeBinWidth
packet size bin width (for histograms)
Definition: flow-monitor.h:306
Time m_maxPerHopDelay
Minimum per-hop delay.
Definition: flow-monitor.h:295
void DoDispose() override
Destructor implementation.
std::map< FlowId, FlowStats >::iterator FlowStatsContainerI
Container Iterator: FlowId, FlowStats.
Definition: flow-monitor.h:232
void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
TrackedPacketMap m_trackedPackets
Tracked packets.
Definition: flow-monitor.h:294
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: flow-monitor.cc:88
double m_delayBinWidth
Delay bin width (for histograms)
Definition: flow-monitor.h:304
void StartRightNow()
Begin monitoring flows right now
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...
void SerializeToXmlStream(std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes)
Serializes the results to an std::ostream in XML format.
EventId m_stopEvent
Stop event.
Definition: flow-monitor.h:302
static TypeId GetTypeId()
Get the type ID.
Definition: flow-monitor.cc:39
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...
Class used to store data and make an histogram of the data frequency.
Definition: histogram.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
uint32_t FlowId
Abstract identifier of a packet flow.
uint32_t FlowPacketId
Abstract identifier of a packet within a flow.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure that represents the measured metrics of an individual packet flow.
Definition: flow-monitor.h:55
uint32_t rxPackets
Total number of received packets for the flow.
Definition: flow-monitor.h:99
Histogram packetSizeHistogram
Histogram of the packet sizes.
Definition: flow-monitor.h:117
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e.
Definition: flow-monitor.h:69
uint32_t lostPackets
Total number of packets that are assumed to be lost, i.e.
Definition: flow-monitor.h:106
Histogram jitterHistogram
Histogram of the packet jitters.
Definition: flow-monitor.h:115
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter.
Definition: flow-monitor.h:90
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
Definition: flow-monitor.h:73
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
Definition: flow-monitor.h:137
uint64_t rxBytes
Total number of received bytes for the flow.
Definition: flow-monitor.h:95
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
Definition: flow-monitor.h:77
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node,...
Definition: flow-monitor.h:64
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
Definition: flow-monitor.h:110
uint32_t txPackets
Total number of transmitted packets for the flow.
Definition: flow-monitor.h:97
uint64_t txBytes
Total number of transmitted bytes for the flow.
Definition: flow-monitor.h:93
Histogram delayHistogram
Histogram of the packet delays.
Definition: flow-monitor.h:113
Time jitterSum
Contains the sum of all end-to-end delay jitter (delay variation) values for all received packets of ...
Definition: flow-monitor.h:86
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
Definition: flow-monitor.h:136
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
Definition: flow-monitor.h:59
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
Structure to represent a single tracked packet data.
Definition: flow-monitor.h:283
Time lastSeenTime
absolute time when the packet was last seen by a probe
Definition: flow-monitor.h:285
Time firstSeenTime
absolute time when the packet was first seen by a probe
Definition: flow-monitor.h:284
uint32_t timesForwarded
number of times the packet was reportedly forwarded
Definition: flow-monitor.h:286
static const uint32_t packetSize
Packet size generated at the AP.