22 #include "ns3/double.h"
24 #include "ns3/simulator.h"
29 #define PERIODIC_CHECK_INTERVAL (Seconds(1))
44 .SetGroupName(
"FlowMonitor")
48 (
"The maximum per-hop delay that should be considered. "
49 "Packets still not received after this delay are to be considered lost."),
53 .AddAttribute(
"StartTime",
54 (
"The time when the monitoring starts."),
58 .AddAttribute(
"DelayBinWidth",
59 (
"The width used in the delay histogram."),
62 MakeDoubleChecker<double>())
63 .AddAttribute(
"JitterBinWidth",
64 (
"The width used in the jitter histogram."),
67 MakeDoubleChecker<double>())
68 .AddAttribute(
"PacketSizeBinWidth",
69 (
"The width used in the packetSize histogram."),
72 MakeDoubleChecker<double>())
73 .AddAttribute(
"FlowInterruptionsBinWidth",
74 (
"The width used in the flowInterruptions histogram."),
77 MakeDoubleChecker<double>())
79 "FlowInterruptionsMinTime",
80 (
"The minimum inter-arrival time that is considered a flow interruption."),
163 NS_LOG_DEBUG(
"ReportFirstTx: adding tracked packet (flowId=" << flowId <<
", packetId="
164 << packetId <<
").");
190 std::pair<FlowId, FlowPacketId> key(flowId, packetId);
194 NS_LOG_WARN(
"Received packet forward report (flowId="
195 << flowId <<
", packetId=" << packetId <<
") but not known to be transmitted.");
199 tracked->second.timesForwarded++;
221 NS_LOG_WARN(
"Received packet last-tx report (flowId="
222 << flowId <<
", packetId=" << packetId <<
") but not known to be transmitted.");
227 Time delay = (now - tracked->second.firstSeenTime);
268 NS_LOG_DEBUG(
"ReportLastTx: removing tracked packet (flowId=" << flowId <<
", packetId="
269 << packetId <<
").");
300 << reasonCode <<
"]; // becomes: " << stats.
packetsDropped[reasonCode]);
307 NS_LOG_DEBUG(
"ReportDrop: removing tracked packet (flowId=" << flowId <<
", packetId="
308 << packetId <<
").");
327 if (now - iter->second.lastSeenTime >= maxDelay)
332 flow->second.lostPackets++;
433 bool enableHistograms,
439 os << std::string(indent,
' ') <<
"<FlowMonitor>\n";
441 os << std::string(indent,
' ') <<
"<FlowStats>\n";
445 os << std::string(indent,
' ');
446 #define ATTRIB(name) << " " #name "=\"" << flowI->second.name << "\""
447 #define ATTRIB_TIME(name) << " " #name "=\"" << flowI->second.name.As(Time::NS) << "\""
448 os <<
"<Flow flowId=\"" << flowI->first
459 for (uint32_t reasonCode = 0; reasonCode < flowI->second.packetsDropped.size();
462 os << std::string(indent,
' ');
463 os <<
"<packetsDropped reasonCode=\"" << reasonCode <<
"\""
464 <<
" number=\"" << flowI->second.packetsDropped[reasonCode] <<
"\" />\n";
466 for (uint32_t reasonCode = 0; reasonCode < flowI->second.bytesDropped.size(); reasonCode++)
468 os << std::string(indent,
' ');
469 os <<
"<bytesDropped reasonCode=\"" << reasonCode <<
"\""
470 <<
" bytes=\"" << flowI->second.bytesDropped[reasonCode] <<
"\" />\n";
472 if (enableHistograms)
474 flowI->second.delayHistogram.SerializeToXmlStream(os, indent,
"delayHistogram");
475 flowI->second.jitterHistogram.SerializeToXmlStream(os, indent,
"jitterHistogram");
476 flowI->second.packetSizeHistogram.SerializeToXmlStream(os,
478 "packetSizeHistogram");
479 flowI->second.flowInterruptionsHistogram.SerializeToXmlStream(
482 "flowInterruptionsHistogram");
486 os << std::string(indent,
' ') <<
"</Flow>\n";
489 os << std::string(indent,
' ') <<
"</FlowStats>\n";
493 (*iter)->SerializeToXmlStream(os, indent);
498 os << std::string(indent,
' ') <<
"<FlowProbes>\n";
505 os << std::string(indent,
' ') <<
"</FlowProbes>\n";
509 os << std::string(indent,
' ') <<
"</FlowMonitor>\n";
516 std::ostringstream os;
525 std::ofstream os(fileName, std::ios::out | std::ios::binary);
526 os <<
"<?xml version=\"1.0\" ?>\n";
538 auto& flowStat = iter.second;
539 flowStat.delaySum =
Seconds(0);
540 flowStat.jitterSum =
Seconds(0);
541 flowStat.lastDelay =
Seconds(0);
542 flowStat.txBytes = 0;
543 flowStat.rxBytes = 0;
544 flowStat.txPackets = 0;
545 flowStat.rxPackets = 0;
546 flowStat.lostPackets = 0;
547 flowStat.timesForwarded = 0;
548 flowStat.bytesDropped.clear();
549 flowStat.packetsDropped.clear();
551 flowStat.delayHistogram.Clear();
552 flowStat.jitterHistogram.Clear();
553 flowStat.packetSizeHistogram.Clear();
554 flowStat.flowInterruptionsHistogram.Clear();
This class can be used to hold variables of floating point type such as 'double' or 'float'.
An object that monitors and reports back packet flows observed during a simulation.
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
FlowProbeContainer m_flowProbes
all the FlowProbes
void StopRightNow()
End monitoring flows right now
void ResetAllStats()
Reset all the statistics.
const FlowProbeContainer & GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
std::vector< Ptr< FlowProbe > > FlowProbeContainer
Container: FlowProbe.
FlowStatsContainer m_flowStats
FlowId --> FlowStats.
bool m_enabled
FlowMon is enabled.
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.
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
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.
std::list< Ptr< FlowClassifier > > m_classifiers
the FlowClassifiers
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.
std::map< FlowId, FlowStats > FlowStatsContainer
Container: FlowId, FlowStats.
double m_jitterBinWidth
Jitter bin width (for histograms)
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)
Time m_maxPerHopDelay
Minimum per-hop delay.
void DoDispose() override
Destructor implementation.
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.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
double m_delayBinWidth
Delay bin width (for histograms)
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.
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...
void AddPacketStats(FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
Add a packet data to the flow stats.
void AddPacketDropStats(FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
Add a packet drop data to the flow stats.
void SetDefaultBinWidth(double binWidth)
Set the bin width.
void AddValue(double value)
Add a value to the histogram.
virtual void NotifyConstructionCompleted()
Notifier called once the ObjectBase is fully constructed.
A base class which provides memory management and object aggregation.
virtual void DoDispose()
Destructor implementation.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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 Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define PERIODIC_CHECK_INTERVAL
#define ATTRIB_TIME(name)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
uint32_t FlowId
Abstract identifier of a packet flow.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Structure that represents the measured metrics of an individual packet flow.
uint32_t rxPackets
Total number of received packets for the flow.
Histogram packetSizeHistogram
Histogram of the packet sizes.
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e.
uint32_t lostPackets
Total number of packets that are assumed to be lost, i.e.
Histogram jitterHistogram
Histogram of the packet jitters.
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter.
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
uint64_t rxBytes
Total number of received bytes for the flow.
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node,...
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
uint32_t txPackets
Total number of transmitted packets for the flow.
uint64_t txBytes
Total number of transmitted bytes for the flow.
Histogram delayHistogram
Histogram of the packet delays.
Time jitterSum
Contains the sum of all end-to-end delay jitter (delay variation) values for all received packets of ...
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
std::vector< uint32_t > packetsDropped
This attribute also tracks the number of lost packets and bytes, but discriminates the losses by a re...
Structure to represent a single tracked packet data.
Time lastSeenTime
absolute time when the packet was last seen by a probe
Time firstSeenTime
absolute time when the packet was first seen by a probe
uint32_t timesForwarded
number of times the packet was reportedly forwarded
static const uint32_t packetSize
Packet size generated at the AP.