A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flow-monitor.h
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 
41 class FlowMonitor : public Object
42 {
43 public:
44 
46  struct FlowStats
47  {
52 
57 
62 
66 
69  Time delaySum; // delayCount == rxPackets
70 
78  Time jitterSum; // jitterCount == rxPackets - 1
79 
80  Time lastDelay;
81 
83  uint64_t txBytes;
85  uint64_t rxBytes;
87  uint32_t txPackets;
89  uint32_t rxPackets;
90 
96  uint32_t lostPackets;
97 
100  uint32_t timesForwarded;
101 
108 
121  std::vector<uint32_t> packetsDropped; // packetsDropped[reasonCode] => number of dropped packets
122 
125  std::vector<uint64_t> bytesDropped; // bytesDropped[reasonCode] => number of dropped bytes
126  Histogram flowInterruptionsHistogram; // histogram of durations of flow interruptions
127  };
128 
129  // --- basic methods ---
130  static TypeId GetTypeId ();
131  TypeId GetInstanceTypeId () const;
132  FlowMonitor ();
133 
135  void SetFlowClassifier (Ptr<FlowClassifier> classifier);
136 
138  void Start (const Time &time);
140  void Stop (const Time &time);
142  void StartRightNow ();
144  void StopRightNow ();
145 
146  // --- methods to be used by the FlowMonitorProbe's only ---
150  void AddProbe (Ptr<FlowProbe> probe);
151 
156  void ReportFirstTx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
159  void ReportForwarding (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
162  void ReportLastRx (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize);
165  void ReportDrop (Ptr<FlowProbe> probe, FlowId flowId, FlowPacketId packetId,
166  uint32_t packetSize, uint32_t reasonCode);
167 
169  void CheckForLostPackets ();
170 
174  void CheckForLostPackets (Time maxDelay);
175 
176  // --- methods to get the results ---
181  std::map<FlowId, FlowStats> GetFlowStats () const;
182 
184  std::vector< Ptr<FlowProbe> > GetAllProbes () const;
185 
191  void SerializeToXmlStream (std::ostream &os, int indent, bool enableHistograms, bool enableProbes);
197  std::string SerializeToXmlString (int indent, bool enableHistograms, bool enableProbes);
202  void SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes);
203 
204 
205 protected:
206 
207  virtual void NotifyConstructionCompleted ();
208  virtual void DoDispose (void);
209 
210 private:
211 
213  {
214  Time firstSeenTime; // absolute time when the packet was first seen by a probe
215  Time lastSeenTime; // absolute time when the packet was last seen by a probe
216  uint32_t timesForwarded; // number of times the packet was reportedly forwarded
217  };
218 
219  // FlowId --> FlowStats
220  std::map<FlowId, FlowStats> m_flowStats;
221 
222  // (FlowId,PacketId) --> TrackedPacket
223  typedef std::map< std::pair<FlowId, FlowPacketId>, TrackedPacket> TrackedPacketMap;
224  TrackedPacketMap m_trackedPackets;
225  Time m_maxPerHopDelay;
226  std::vector< Ptr<FlowProbe> > m_flowProbes;
227 
228  // note: this is needed only for serialization
229  Ptr<FlowClassifier> m_classifier;
230 
231  EventId m_startEvent;
232  EventId m_stopEvent;
233  bool m_enabled;
234  double m_delayBinWidth;
235  double m_jitterBinWidth;
236  double m_packetSizeBinWidth;
237  double m_flowInterruptionsBinWidth;
238  Time m_flowInterruptionsMinTime;
239 
240  FlowStats& GetStatsForFlow (FlowId flowId);
241  void PeriodicCheckForLostPackets ();
242 };
243 
244 
245 } // namespace ns3
246 
247 #endif /* FLOW_MONITOR_H */
248 
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void CheckForLostPackets()
Check right now for packets that appear to be lost.
void StartRightNow()
Begin monitoring flows right now
uint32_t rxPackets
Total number of received packets for the flow.
Definition: flow-monitor.h:89
uint32_t txPackets
Total number of transmitted packets for the flow.
Definition: flow-monitor.h:87
void ReportDrop(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize, uint32_t reasonCode)
std::vector< uint64_t > bytesDropped
Definition: flow-monitor.h:125
void ReportFirstTx(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize)
void SetFlowClassifier(Ptr< FlowClassifier > classifier)
Set the FlowClassifier to be used by the flow monitor.
std::map< FlowId, FlowStats > GetFlowStats() const
void SerializeToXmlStream(std::ostream &os, int indent, bool enableHistograms, bool enableProbes)
std::string SerializeToXmlString(int indent, bool enableHistograms, bool enableProbes)
virtual void NotifyConstructionCompleted()
void Stop(const Time &time)
Set the time, counting from the current time, from which to stop monitoring flows.
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:103
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
std::vector< Ptr< FlowProbe > > GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
virtual void DoDispose(void)
Definition: flow-monitor.cc:91
uint64_t txBytes
Total number of transmitted bytes for the flow.
Definition: flow-monitor.h:83
Structure that represents the measured metrics of an individual packet flow.
Definition: flow-monitor.h:46
Histogram jitterHistogram
Histogram of the packet jitters.
Definition: flow-monitor.h:105
a base class which provides memory management and object aggregation
Definition: object.h:63
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)
uint64_t rxBytes
Total number of received bytes for the flow.
Definition: flow-monitor.h:85
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:41
void AddProbe(Ptr< FlowProbe > probe)
a unique identifier for an interface.
Definition: type-id.h:44
void ReportLastRx(Ptr< FlowProbe > probe, FlowId flowId, FlowPacketId packetId, uint32_t packetSize)
Histogram packetSizeHistogram
Histogram of the packet sizes.
Definition: flow-monitor.h:107
TypeId GetInstanceTypeId() const
Definition: flow-monitor.cc:79
std::vector< uint32_t > packetsDropped
Definition: flow-monitor.h:121