22 #include "ns3/simulator.h"
24 #include "ns3/double.h"
28 #define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
30 #define PERIODIC_CHECK_INTERVAL (Seconds (1))
46 .AddConstructor<FlowMonitor> ()
47 .AddAttribute (
"MaxPerHopDelay", (
"The maximum per-hop delay that should be considered. "
48 "Packets still not received after this delay are to be considered lost."),
52 .AddAttribute (
"StartTime", (
"The time when the monitoring starts."),
56 .AddAttribute (
"DelayBinWidth", (
"The width used in the delay histogram."),
59 MakeDoubleChecker <double> ())
60 .AddAttribute (
"JitterBinWidth", (
"The width used in the jitter histogram."),
63 MakeDoubleChecker <double> ())
64 .AddAttribute (
"PacketSizeBinWidth", (
"The width used in the packetSize histogram."),
67 MakeDoubleChecker <double> ())
68 .AddAttribute (
"FlowInterruptionsBinWidth", (
"The width used in the flowInterruptions histogram."),
71 MakeDoubleChecker <double> ())
72 .AddAttribute (
"FlowInterruptionsMinTime", (
"The minimum inter-arrival time that is considered a flow interruption."),
107 std::map<FlowId, FlowStats>::iterator iter;
146 NS_LOG_DEBUG (
"ReportFirstTx: adding tracked packet (flowId=" << flowId <<
", packetId=" << packetId
149 probe->AddPacketStats (flowId, packetSize, Seconds (0));
169 std::pair<FlowId, FlowPacketId> key (flowId, packetId);
173 NS_LOG_WARN (
"Received packet forward report (flowId=" << flowId <<
", packetId=" << packetId
174 <<
") but not known to be transmitted.");
178 tracked->second.timesForwarded++;
182 probe->AddPacketStats (flowId, packetSize, delay);
193 TrackedPacketMap::iterator tracked =
m_trackedPackets.find (std::make_pair (flowId, packetId));
196 NS_LOG_WARN (
"Received packet last-tx report (flowId=" << flowId <<
", packetId=" << packetId
197 <<
") but not known to be transmitted.");
202 Time delay = (now - tracked->second.firstSeenTime);
203 probe->AddPacketStats (flowId, packetSize, delay);
211 if (jitter > Seconds (0))
243 NS_LOG_DEBUG (
"ReportLastTx: removing tracked packet (flowId="
244 << flowId <<
", packetId=" << packetId <<
").");
258 probe->AddPacketDropStats (flowId, packetSize, reasonCode);
271 TrackedPacketMap::iterator tracked =
m_trackedPackets.find (std::make_pair (flowId, packetId));
276 NS_LOG_DEBUG (
"ReportDrop: removing tracked packet (flowId="
277 << flowId <<
", packetId=" << packetId <<
").");
282 std::map<FlowId, FlowMonitor::FlowStats>
297 if (now - iter->second.lastSeenTime >= maxDelay)
300 std::map<FlowId, FlowStats>::iterator
303 flow->second.lostPackets++;
341 std::vector< Ptr<FlowProbe> >
404 INDENT (indent); os <<
"<FlowMonitor>\n";
406 INDENT (indent); os <<
"<FlowStats>\n";
408 for (std::map<FlowId, FlowStats>::const_iterator flowI =
m_flowStats.begin ();
413 #define ATTRIB(name) << " " # name "=\"" << flowI->second.name << "\""
414 os <<
"<Flow flowId=\"" << flowI->first <<
"\""
415 ATTRIB (timeFirstTxPacket)
416 ATTRIB (timeFirstRxPacket)
433 for (uint32_t reasonCode = 0; reasonCode < flowI->second.packetsDropped.size (); reasonCode++)
436 os <<
"<packetsDropped reasonCode=\"" << reasonCode <<
"\""
437 <<
" number=\"" << flowI->second.packetsDropped[reasonCode]
440 for (uint32_t reasonCode = 0; reasonCode < flowI->second.bytesDropped.size (); reasonCode++)
443 os <<
"<bytesDropped reasonCode=\"" << reasonCode <<
"\""
444 <<
" bytes=\"" << flowI->second.bytesDropped[reasonCode]
447 if (enableHistograms)
449 flowI->second.delayHistogram.SerializeToXmlStream (os, indent,
"delayHistogram");
450 flowI->second.jitterHistogram.SerializeToXmlStream (os, indent,
"jitterHistogram");
451 flowI->second.packetSizeHistogram.SerializeToXmlStream (os, indent,
"packetSizeHistogram");
452 flowI->second.flowInterruptionsHistogram.SerializeToXmlStream (os, indent,
"flowInterruptionsHistogram");
456 INDENT (indent); os <<
"</Flow>\n";
459 INDENT (indent); os <<
"</FlowStats>\n";
465 INDENT (indent); os <<
"<FlowProbes>\n";
472 INDENT (indent); os <<
"</FlowProbes>\n";
476 INDENT (indent); os <<
"</FlowMonitor>\n";
483 std::ostringstream os;
492 std::ofstream os (fileName.c_str (), std::ios::out|std::ios::binary);
493 os <<
"<?xml version=\"1.0\" ?>\n";
#define PERIODIC_CHECK_INTERVAL
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
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.
uint32_t rxPackets
Total number of received packets for the flow.
uint32_t txPackets
Total number of transmitted packets for the flow.
#define NS_ASSERT(condition)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Time m_maxPerHopDelay
Minimum per-hop delay.
static TypeId GetTypeId()
Get the type ID.
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...
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
std::map< FlowId, FlowStats > m_flowStats
FlowId –> FlowStats.
Time m_flowInterruptionsMinTime
Flow interruptions minimum time.
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 SetFlowClassifier(Ptr< FlowClassifier > classifier)
Set the FlowClassifier to be used by the flow monitor.
TrackedPacketMap m_trackedPackets
Tracked packets.
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter...
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.
double GetSeconds(void) const
Time firstSeenTime
absolute time when the packet was first seen by a probe
hold objects of type ns3::Time
Time jitterSum
Contains the sum of all end-to-end delay jitter (delay variation) values for all received packets of ...
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.
virtual void NotifyConstructionCompleted(void)
This method is invoked once all member attributes have been initialized.
void SetDefaultBinWidth(double binWidth)
Set the bin width.
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
double m_packetSizeBinWidth
packet size bin width (for histograms)
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
double m_jitterBinWidth
Jitter bin width (for histograms)
EventId m_stopEvent
Stop event.
Time lastSeenTime
absolute time when the packet was last seen by a probe
double m_delayBinWidth
Delay bin width (for histograms)
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
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node...
static Time Now(void)
Return the "current simulation time".
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
void StopRightNow()
End monitoring flows right now
Histogram delayHistogram
Histogram of the packet delays.
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.
#define NS_LOG_DEBUG(msg)
Ptr< FlowClassifier > m_classifier
the FlowClassifier
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
uint64_t txBytes
Total number of transmitted bytes for the flow.
Structure that represents the measured metrics of an individual packet flow.
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Structure to represent a single tracked packet data.
Histogram jitterHistogram
Histogram of the packet jitters.
a base class which provides memory management and object aggregation
EventId m_startEvent
Start event.
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.
Hold a floating point type.
void AddValue(double value)
Add a value to the histogram.
void PeriodicCheckForLostPackets()
Periodic function to check for lost packets and prune statistics.
uint32_t timesForwarded
number of times the packet was reportedly forwarded
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.
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e. ...
TypeId SetParent(TypeId tid)
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.
TypeId GetInstanceTypeId() const
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...