|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include "ns3/simulator.h"
24 #include "ns3/double.h"
28 #define PERIODIC_CHECK_INTERVAL (Seconds (1))
41 .SetGroupName (
"FlowMonitor")
43 .AddAttribute (
"MaxPerHopDelay", (
"The maximum per-hop delay that should be considered. "
44 "Packets still not received after this delay are to be considered lost."),
48 .AddAttribute (
"StartTime", (
"The time when the monitoring starts."),
52 .AddAttribute (
"DelayBinWidth", (
"The width used in the delay histogram."),
55 MakeDoubleChecker <double> ())
56 .AddAttribute (
"JitterBinWidth", (
"The width used in the jitter histogram."),
59 MakeDoubleChecker <double> ())
60 .AddAttribute (
"PacketSizeBinWidth", (
"The width used in the packetSize histogram."),
63 MakeDoubleChecker <double> ())
64 .AddAttribute (
"FlowInterruptionsBinWidth", (
"The width used in the flowInterruptions histogram."),
67 MakeDoubleChecker <double> ())
68 .AddAttribute (
"FlowInterruptionsMinTime", (
"The minimum inter-arrival time that is considered a flow interruption."),
153 NS_LOG_DEBUG (
"ReportFirstTx: adding tracked packet (flowId=" << flowId <<
", packetId=" << packetId
178 std::pair<FlowId, FlowPacketId> key (flowId, packetId);
182 NS_LOG_WARN (
"Received packet forward report (flowId=" << flowId <<
", packetId=" << packetId
183 <<
") but not known to be transmitted.");
187 tracked->second.timesForwarded++;
204 TrackedPacketMap::iterator tracked =
m_trackedPackets.find (std::make_pair (flowId, packetId));
207 NS_LOG_WARN (
"Received packet last-tx report (flowId=" << flowId <<
", packetId=" << packetId
208 <<
") but not known to be transmitted.");
213 Time delay = (now - tracked->second.firstSeenTime);
254 NS_LOG_DEBUG (
"ReportLastTx: removing tracked packet (flowId="
255 << flowId <<
", packetId=" << packetId <<
").");
284 TrackedPacketMap::iterator tracked =
m_trackedPackets.find (std::make_pair (flowId, packetId));
289 NS_LOG_DEBUG (
"ReportDrop: removing tracked packet (flowId="
290 << flowId <<
", packetId=" << packetId <<
").");
311 if (now - iter->second.lastSeenTime >= maxDelay)
316 flow->second.lostPackets++;
368 NS_LOG_DEBUG (
"FlowMonitor already enabled; returning");
392 NS_LOG_DEBUG (
"FlowMonitor already enabled; returning");
424 os << std::string (
indent,
' ' ) <<
"<FlowMonitor>\n";
426 os << std::string (
indent,
' ' ) <<
"<FlowStats>\n";
431 os << std::string (
indent,
' ' );
432 #define ATTRIB(name) << " " # name "=\"" << flowI->second.name << "\""
433 #define ATTRIB_TIME(name) << " " #name "=\"" << flowI->second.name.As (Time::NS) << "\""
434 os <<
"<Flow flowId=\"" << flowI->first <<
"\""
453 for (uint32_t reasonCode = 0; reasonCode < flowI->second.packetsDropped.size (); reasonCode++)
455 os << std::string (
indent,
' ' );
456 os <<
"<packetsDropped reasonCode=\"" << reasonCode <<
"\""
457 <<
" number=\"" << flowI->second.packetsDropped[reasonCode]
460 for (uint32_t reasonCode = 0; reasonCode < flowI->second.bytesDropped.size (); reasonCode++)
462 os << std::string (
indent,
' ' );
463 os <<
"<bytesDropped reasonCode=\"" << reasonCode <<
"\""
464 <<
" bytes=\"" << flowI->second.bytesDropped[reasonCode]
467 if (enableHistograms)
469 flowI->second.delayHistogram.SerializeToXmlStream (os,
indent,
"delayHistogram");
470 flowI->second.jitterHistogram.SerializeToXmlStream (os,
indent,
"jitterHistogram");
471 flowI->second.packetSizeHistogram.SerializeToXmlStream (os,
indent,
"packetSizeHistogram");
472 flowI->second.flowInterruptionsHistogram.SerializeToXmlStream (os,
indent,
"flowInterruptionsHistogram");
476 os << std::string (
indent,
' ' ) <<
"</Flow>\n";
479 os << std::string (
indent,
' ' ) <<
"</FlowStats>\n";
485 (*iter)->SerializeToXmlStream (os,
indent);
490 os << std::string (
indent,
' ' ) <<
"<FlowProbes>\n";
497 os << std::string (
indent,
' ' ) <<
"</FlowProbes>\n";
501 os << std::string (
indent,
' ' ) <<
"</FlowMonitor>\n";
509 std::ostringstream os;
518 NS_LOG_FUNCTION (
this << fileName << enableHistograms << enableProbes);
519 std::ofstream os (fileName.c_str (), std::ios::out|std::ios::binary);
520 os <<
"<?xml version=\"1.0\" ?>\n";
void AddProbe(Ptr< FlowProbe > probe)
Register a new FlowProbe that will begin monitoring and report events to this monitor.
Structure to represent a single tracked packet data.
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time delaySum
Contains the sum of all end-to-end delays for all received packets of the flow.
static TypeId GetTypeId()
Get the type ID.
void StartRightNow()
Begin monitoring flows right now
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
std::vector< uint64_t > bytesDropped
This attribute also tracks the number of lost bytes.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
void AddPacketDropStats(FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
Add a packet drop data to the flow stats.
Time m_maxPerHopDelay
Minimum per-hop delay.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
#define ATTRIB_TIME(name)
FlowProbeContainer m_flowProbes
all the FlowProbes
Time timeLastRxPacket
Contains the absolute time when the last packet in the flow was received, i.e.
virtual void NotifyConstructionCompleted()
Notifier called once the ObjectBase is fully constructed.
void AddPacketStats(FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
Add a packet data to the flow stats.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
uint64_t rxBytes
Total number of received bytes for the flow.
uint32_t lostPackets
Total number of packets that are assumed to be lost, i.e.
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...
TrackedPacketMap m_trackedPackets
Tracked packets.
double m_delayBinWidth
Delay bin width (for histograms)
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...
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
bool m_enabled
FlowMon is enabled.
uint32_t timesForwarded
number of times the packet was reportedly forwarded
EventId m_startEvent
Start event.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
uint64_t txBytes
Total number of transmitted bytes for the flow.
std::string SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but returns the output as a std::string.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Time lastDelay
Contains the last measured delay of a packet It is stored to measure the packet's Jitter.
Histogram jitterHistogram
Histogram of the packet jitters.
uint32_t FlowId
Abstract identifier of a packet flow.
Smart pointer class similar to boost::intrusive_ptr.
uint32_t rxPackets
Total number of received packets for the flow.
std::map< FlowId, FlowStats > FlowStatsContainer
Container: FlowId, FlowStats.
def indent(source, debug, level)
Histogram flowInterruptionsHistogram
histogram of durations of flow interruptions
A base class which provides memory management and object aggregation.
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...
const FlowProbeContainer & GetAllProbes() const
Get a list of all FlowProbe's associated with this FlowMonitor.
std::vector< Ptr< FlowProbe > > FlowProbeContainer
Container: FlowProbe.
std::map< FlowId, FlowStats >::const_iterator FlowStatsContainerCI
Container Const Iterator: FlowId, FlowStats.
Simulation virtual time values and global simulation resolution.
Histogram packetSizeHistogram
Histogram of the packet sizes.
double m_jitterBinWidth
Jitter bin width (for histograms)
An object that monitors and reports back packet flows observed during a simulation.
void Stop(const Time &time)
Set the time, counting from the current time, from which to stop monitoring flows.
Time firstSeenTime
absolute time when the packet was first seen by a probe
EventId m_stopEvent
Stop event.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void StopRightNow()
End monitoring flows right now
double m_packetSizeBinWidth
packet size bin width (for histograms)
std::vector< uint32_t > packetsDropped
This attribute also tracks the number of lost packets and bytes, but discriminates the losses by a re...
Histogram delayHistogram
Histogram of the packet delays.
Time timeFirstTxPacket
Contains the absolute time when the first packet in the flow was transmitted, i.e.
static const uint32_t packetSize
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
FlowStats & GetStatsForFlow(FlowId flowId)
Get the stats for a given flow.
void AddValue(double value)
Add a value to the histogram.
AttributeValue implementation for Time.
std::map< FlowId, FlowStats >::iterator FlowStatsContainerI
Container Iterator: FlowId, FlowStats.
virtual void DoDispose(void)
Destructor implementation.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void PeriodicCheckForLostPackets()
Periodic function to check for lost packets and prune statistics.
Time lastSeenTime
absolute time when the packet was last seen by a probe
Time jitterSum
Contains the sum of all end-to-end delay jitter (delay variation) values for all received packets of ...
Time timeLastTxPacket
Contains the absolute time when the last packet in the flow was transmitted, i.e.
uint32_t txPackets
Total number of transmitted packets for the flow.
void AddFlowClassifier(Ptr< FlowClassifier > classifier)
Add a FlowClassifier to be used by the flow monitor.
void Start(const Time &time)
Set the time, counting from the current time, from which to start monitoring flows.
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Time m_flowInterruptionsMinTime
Flow interruptions minimum time.
void SetDefaultBinWidth(double binWidth)
Set the bin width.
void SerializeToXmlStream(std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes)
Serializes the results to an std::ostream in XML format.
double m_flowInterruptionsBinWidth
Flow interruptions bin width (for histograms)
FlowStatsContainer m_flowStats
FlowId --> FlowStats.
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
uint32_t timesForwarded
Contains the number of times a packet has been reportedly forwarded, summed for all received packets ...
Structure that represents the measured metrics of an individual packet flow.
void CheckForLostPackets()
Check right now for packets that appear to be lost.
virtual void DoDispose(void)
Destructor implementation.
Time timeFirstRxPacket
Contains the absolute time when the first packet in the flow was received by an end node,...
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
#define PERIODIC_CHECK_INTERVAL
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
virtual void NotifyConstructionCompleted(void)
Notifier called once the ObjectBase is fully constructed.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
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...
std::list< Ptr< FlowClassifier > > m_classifiers
the FlowClassifiers