A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::WifiCoTraceHelper Class Reference

Track channel occupancy durations for WifiNetDevice. More...

#include "wifi-co-trace-helper.h"

+ Collaboration diagram for ns3::WifiCoTraceHelper:

Classes

struct  DeviceRecord
 Keeps track of channel occupancy statistics observed at a WifiNetDevice. More...
 

Public Member Functions

 WifiCoTraceHelper ()
 Default Constructor.
 
 WifiCoTraceHelper (Time startTime, Time stopTime)
 Construct a helper object measuring between two simulation time points [startTime, stopTime].
 
void Enable (NetDeviceContainer devices)
 Enables trace collection for all nodes corresponding to the devices in the specified NetDeviceContainer.
 
void Enable (NodeContainer nodes)
 Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
 
const std::vector< DeviceRecord > & GetDeviceRecords () const
 Returns measurement results on each installed device.
 
void PrintStatistics (std::ostream &os, Time::Unit unit=Time::Unit::AUTO) const
 Print measurement results on an output stream.
 
void Reset ()
 Resets the current statistics, clearing all links and their durations.
 
void Start (Time startTime)
 Starts the collection of statistics from a specified start time.
 
void Stop (Time stopTime)
 Stops the collection of statistics at a specified time.
 

Private Member Functions

void AlignDecimal (std::vector< std::string > &column) const
 A helper function used by PrintLinkStates method to format the output.
 
void AlignWidth (std::vector< std::string > &column) const
 A helper function used by PrintLinkStates method to format the output.
 
Time ComputeOverlappingDuration (Time start1, Time stop1, Time start2, Time stop2)
 Compute overlapping time-duration between two intervals.
 
std::map< WifiPhyState, doubleComputePercentage (const std::map< WifiPhyState, Time > &linkStates) const
 A helper function used by PrintStatistics method.
 
void NotifyWifiPhyState (std::size_t idx, std::size_t phyId, Time start, Time duration, WifiPhyState state)
 A callback used to update statistics.
 
std::ostream & PrintLinkStates (std::ostream &os, const std::map< WifiPhyState, Time > &linkStates, Time::Unit unit) const
 A helper function used by PrintStatistics method.
 

Private Attributes

std::vector< DeviceRecordm_deviceRecords
 Stores the collected statistics.
 
uint32_t m_numDevices {0}
 Count the number of devices traced by this helper.
 
Time m_startTime
 Instant at which statistics collection should start.
 
Time m_stopTime {Time::Max()}
 Instant at which statistics collection should stop.
 

Detailed Description

Track channel occupancy durations for WifiNetDevice.

The WifiCoTraceHelper class tracks the duration that a particular WifiNetDevice is in different states. The states are defined by the ns-3 WifiPhyStateHelper and include states such as IDLE, CCA_BUSY, TX, and RX. The helper tracks these durations between a user-configured start and end time. At the end of a simulation, this helper can print out statistics on channel occupancy, and permits the export of an internal data structure to allow for custom printing or statistics handling.

This helper supports both single-link devices and multi-link devices (MLD).

Definition at line 42 of file wifi-co-trace-helper.h.

Constructor & Destructor Documentation

◆ WifiCoTraceHelper() [1/2]

ns3::WifiCoTraceHelper::WifiCoTraceHelper ( )

Default Constructor.

StartTime is Seconds(0) and stopTime is Time::Max()

Definition at line 32 of file wifi-co-trace-helper.cc.

References NS_LOG_FUNCTION.

◆ WifiCoTraceHelper() [2/2]

ns3::WifiCoTraceHelper::WifiCoTraceHelper ( Time startTime,
Time stopTime )

Construct a helper object measuring between two simulation time points [startTime, stopTime].

Parameters
startTimeThe measurement start time
stopTimeThe measurement stop time

Definition at line 37 of file wifi-co-trace-helper.cc.

References ns3::Time::As(), m_startTime, m_stopTime, NS_ASSERT_MSG, NS_LOG_FUNCTION, ns3::Time::S, and stopTime.

+ Here is the call graph for this function:

Member Function Documentation

◆ AlignDecimal()

void ns3::WifiCoTraceHelper::AlignDecimal ( std::vector< std::string > & column) const
private

A helper function used by PrintLinkStates method to format the output.

It pads each string at left with space characters such that the decimal points are at the same position.

Parameters
columnA column of strings. Each string must contain a decimal point.

Definition at line 232 of file wifi-co-trace-helper.cc.

Referenced by PrintLinkStates().

+ Here is the caller graph for this function:

◆ AlignWidth()

void ns3::WifiCoTraceHelper::AlignWidth ( std::vector< std::string > & column) const
private

A helper function used by PrintLinkStates method to format the output.

It pads each string at right with space characters such that all strings have same width.

Parameters
columnA column of strings.

Definition at line 254 of file wifi-co-trace-helper.cc.

Referenced by PrintLinkStates().

+ Here is the caller graph for this function:

◆ ComputeOverlappingDuration()

Time ns3::WifiCoTraceHelper::ComputeOverlappingDuration ( Time start1,
Time stop1,
Time start2,
Time stop2 )
private

Compute overlapping time-duration between two intervals.

It is a helper function used by NotifyWifiPhyState function.

Parameters
start1Beginning of first interval
stop1End of first interval
start2Beginning of second interval
stop2End of second interval
Returns
Return the time duration common between the two intervals.

Definition at line 345 of file wifi-co-trace-helper.cc.

References Max, Min, NS_ASSERT_MSG, and ns3::Seconds().

Referenced by NotifyWifiPhyState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ComputePercentage()

std::map< WifiPhyState, double > ns3::WifiCoTraceHelper::ComputePercentage ( const std::map< WifiPhyState, Time > & linkStates) const
private

A helper function used by PrintStatistics method.

It converts absolute statistics to percentages.

Parameters
linkStatesStatistics of a link.
Returns
Statistics in percentages.

Definition at line 275 of file wifi-co-trace-helper.cc.

References ns3::Time::GetDouble(), ns3::Time::IsZero(), and NS_LOG_FUNCTION.

Referenced by PrintLinkStates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Enable() [1/2]

void ns3::WifiCoTraceHelper::Enable ( NetDeviceContainer devices)

Enables trace collection for all nodes corresponding to the devices in the specified NetDeviceContainer.

Parameters
devicesThe NetDeviceContainer to which traces are to be connected.

Definition at line 97 of file wifi-co-trace-helper.cc.

References ns3::DynamicCast(), m_deviceRecords, m_numDevices, ns3::MakeCallback(), NotifyWifiPhyState(), NS_LOG_FUNCTION, and NS_LOG_INFO.

+ Here is the call graph for this function:

◆ Enable() [2/2]

void ns3::WifiCoTraceHelper::Enable ( NodeContainer nodes)

Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.

Parameters
nodesThe NodeContainer containing WifiNetDevices to which traces are to be connected.

Definition at line 82 of file wifi-co-trace-helper.cc.

References ns3::NetDeviceContainer::Add(), Enable(), nodes, and NS_LOG_FUNCTION.

Referenced by LinkRenameTestCase::DoRun(), and Enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDeviceRecords()

const std::vector< WifiCoTraceHelper::DeviceRecord > & ns3::WifiCoTraceHelper::GetDeviceRecords ( ) const

Returns measurement results on each installed device.

Returns
Statistics of each device traced by this helper.

Definition at line 299 of file wifi-co-trace-helper.cc.

References m_deviceRecords.

Referenced by LinkRenameTestCase::DoRun(), and WifiCoTraceHelperBaseTestCase::GetChannelOccupancy().

+ Here is the caller graph for this function:

◆ NotifyWifiPhyState()

void ns3::WifiCoTraceHelper::NotifyWifiPhyState ( std::size_t idx,
std::size_t phyId,
Time start,
Time duration,
WifiPhyState state )
private

A callback used to update statistics.

Parameters
idxIndex of the device in m_deviceRecords vector.
phyIdId of Phy whose state is switched.
startInstant at which link switched its WifiPhyState to state.
durationDuration of time the link stays in this state.
stateThe state of the link from start to (start + duration).

Definition at line 305 of file wifi-co-trace-helper.cc.

References ns3::Time::As(), ComputeOverlappingDuration(), ns3::DynamicCast(), ns3::Node::GetDevice(), ns3::NodeList::GetNode(), ns3::Time::IsPositive(), m_deviceRecords, m_startTime, m_stopTime, NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Time::S, and ns3::Time::US.

Referenced by Enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintLinkStates()

std::ostream & ns3::WifiCoTraceHelper::PrintLinkStates ( std::ostream & os,
const std::map< WifiPhyState, Time > & linkStates,
Time::Unit unit ) const
private

A helper function used by PrintStatistics method.

It prints statistics of a link.

Parameters
osThe output stream to print to
linkStatesStatistics of a link.
unitThe unit of time in which the durations should be printed.
Returns
The output stream after IO operations.

Definition at line 175 of file wifi-co-trace-helper.cc.

References AlignDecimal(), AlignWidth(), ComputePercentage(), and NS_LOG_FUNCTION.

Referenced by PrintStatistics().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintStatistics()

void ns3::WifiCoTraceHelper::PrintStatistics ( std::ostream & os,
Time::Unit unit = Time::Unit::AUTO ) const

Print measurement results on an output stream.

Parameters
osThe output stream to print to
unitThe unit of time in which the durations should be printed. Defaults to AUTO.

Definition at line 125 of file wifi-co-trace-helper.cc.

References m_deviceRecords, m_numDevices, NS_ASSERT_MSG, NS_LOG_FUNCTION, and PrintLinkStates().

Referenced by LinkRenameTestCase::DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reset()

void ns3::WifiCoTraceHelper::Reset ( )

Resets the current statistics, clearing all links and their durations.

It does not disconnect traced callbacks. It does not clear DeviceRecords. Only the statistics collected prior to invoking this method is cleared.

Definition at line 71 of file wifi-co-trace-helper.cc.

References m_deviceRecords, and NS_LOG_FUNCTION.

◆ Start()

void ns3::WifiCoTraceHelper::Start ( Time startTime)

Starts the collection of statistics from a specified start time.

Parameters
startTimeThe time to start collecting statistics.

Definition at line 48 of file wifi-co-trace-helper.cc.

References m_startTime, m_stopTime, ns3::Simulator::Now(), NS_ASSERT_MSG, NS_LOG_FUNCTION, and ns3::Time::S.

+ Here is the call graph for this function:

◆ Stop()

void ns3::WifiCoTraceHelper::Stop ( Time stopTime)

Stops the collection of statistics at a specified time.

Parameters
stopTimeThe time to stop collecting statistics.

Definition at line 59 of file wifi-co-trace-helper.cc.

References m_startTime, m_stopTime, ns3::Simulator::Now(), NS_ASSERT_MSG, NS_LOG_FUNCTION, and ns3::Time::S.

Referenced by LinkRenameTestCase::DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_deviceRecords

std::vector<DeviceRecord> ns3::WifiCoTraceHelper::m_deviceRecords
private

Stores the collected statistics.

Definition at line 148 of file wifi-co-trace-helper.h.

Referenced by Enable(), GetDeviceRecords(), NotifyWifiPhyState(), PrintStatistics(), and Reset().

◆ m_numDevices

uint32_t ns3::WifiCoTraceHelper::m_numDevices {0}
private

Count the number of devices traced by this helper.

Definition at line 144 of file wifi-co-trace-helper.h.

Referenced by Enable(), and PrintStatistics().

◆ m_startTime

Time ns3::WifiCoTraceHelper::m_startTime
private

Instant at which statistics collection should start.

Definition at line 145 of file wifi-co-trace-helper.h.

Referenced by WifiCoTraceHelper(), NotifyWifiPhyState(), Start(), and Stop().

◆ m_stopTime

Time ns3::WifiCoTraceHelper::m_stopTime {Time::Max()}
private

Instant at which statistics collection should stop.

Definition at line 146 of file wifi-co-trace-helper.h.

Referenced by WifiCoTraceHelper(), NotifyWifiPhyState(), Start(), and Stop().


The documentation for this class was generated from the following files: