Track channel occupancy durations for WifiNetDevice. More...
#include "wifi-co-trace-helper.h"
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, double > | ComputePercentage (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< DeviceRecord > | m_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. | |
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.
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.
Construct a helper object measuring between two simulation time points [startTime, stopTime].
startTime | The measurement start time |
stopTime | The 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.
|
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.
column | A column of strings. Each string must contain a decimal point. |
Definition at line 232 of file wifi-co-trace-helper.cc.
Referenced by PrintLinkStates().
|
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.
column | A column of strings. |
Definition at line 254 of file wifi-co-trace-helper.cc.
Referenced by PrintLinkStates().
|
private |
Compute overlapping time-duration between two intervals.
It is a helper function used by NotifyWifiPhyState function.
start1 | Beginning of first interval |
stop1 | End of first interval |
start2 | Beginning of second interval |
stop2 | End of second interval |
Definition at line 345 of file wifi-co-trace-helper.cc.
References Max, Min, NS_ASSERT_MSG, and ns3::Seconds().
Referenced by NotifyWifiPhyState().
|
private |
A helper function used by PrintStatistics method.
It converts absolute statistics to percentages.
linkStates | Statistics of a link. |
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().
void ns3::WifiCoTraceHelper::Enable | ( | NetDeviceContainer | devices | ) |
Enables trace collection for all nodes corresponding to the devices in the specified NetDeviceContainer.
devices | The 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.
void ns3::WifiCoTraceHelper::Enable | ( | NodeContainer | nodes | ) |
Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
nodes | The 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().
const std::vector< WifiCoTraceHelper::DeviceRecord > & ns3::WifiCoTraceHelper::GetDeviceRecords | ( | ) | const |
Returns measurement results on each installed device.
Definition at line 299 of file wifi-co-trace-helper.cc.
References m_deviceRecords.
Referenced by LinkRenameTestCase::DoRun(), and WifiCoTraceHelperBaseTestCase::GetChannelOccupancy().
|
private |
A callback used to update statistics.
idx | Index of the device in m_deviceRecords vector. |
phyId | Id of Phy whose state is switched. |
start | Instant at which link switched its WifiPhyState to state. |
duration | Duration of time the link stays in this state. |
state | The 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().
|
private |
A helper function used by PrintStatistics method.
It prints statistics of a link.
os | The output stream to print to |
linkStates | Statistics of a link. |
unit | The unit of time in which the durations should be printed. |
Definition at line 175 of file wifi-co-trace-helper.cc.
References AlignDecimal(), AlignWidth(), ComputePercentage(), and NS_LOG_FUNCTION.
Referenced by PrintStatistics().
void ns3::WifiCoTraceHelper::PrintStatistics | ( | std::ostream & | os, |
Time::Unit | unit = Time::Unit::AUTO ) const |
Print measurement results on an output stream.
os | The output stream to print to |
unit | The 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().
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.
void ns3::WifiCoTraceHelper::Start | ( | Time | startTime | ) |
Starts the collection of statistics from a specified start time.
startTime | The 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.
void ns3::WifiCoTraceHelper::Stop | ( | Time | stopTime | ) |
Stops the collection of statistics at a specified time.
stopTime | The 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().
|
private |
Stores the collected statistics.
Definition at line 148 of file wifi-co-trace-helper.h.
Referenced by Enable(), GetDeviceRecords(), NotifyWifiPhyState(), PrintStatistics(), and Reset().
|
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().
|
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().
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().