wifi: Make WifiPhyState a scoped enum within ns3 namespace

This commit is contained in:
Stefano Avallone
2024-02-13 18:04:51 +01:00
parent bd3650cda0
commit 42d47d615f
7 changed files with 65 additions and 37 deletions

View File

@@ -30,6 +30,7 @@ Applications have a new Attribute to set the IPv4 ToS field.
* (core) Deprecated enum `TestDuration` in `TestCase` class. It has been replaced by enum class `Duration`.
* (core) In `TestSuite` class, deprecated `ALL`, `UNIT`, `SYSTEM`, `EXAMPLE` and `PERFORMANCE`. They have been replaced by `Type::ALL`, `Type::UNIT`, `Type::SYSTEM`, `Type::EXAMPLE` and `Type::PERFORMANCE`, respectively.
* (wifi) Deprecated `WIFI_TID_TO_LINK_MAPPING_{NOT_SUPPORTED,SAME_LINK_SET,ANY_LINK_SET}`. They have been replaced by `WifiTidToLinkMappingNegSupport::{NOT_SUPPORTED,SAME_LINK_SET,ANY_LINK_SET}`, respectively.
* (wifi) Deprecated `{IDLE, CCA_BUSY, TX, RX, SWITCHING, SLEEP, OFF}`. They have been replaced by `WifiPhyState::{IDLE, CCA_BUSY, TX, RX, SWITCHING, SLEEP, OFF}`, respectively.
### Changes to build system

View File

@@ -165,7 +165,10 @@ BasicEnergyUpdateTest::StateSwitchTest(WifiPhyState state)
*/
// schedule change of state
Simulator::Schedule(Seconds(m_timeS), &WifiRadioEnergyModel::ChangeState, devModel, state);
Simulator::Schedule(Seconds(m_timeS),
&WifiRadioEnergyModel::ChangeState,
devModel,
static_cast<int>(state));
// Calculate remaining energy at simulation stop time
Simulator::Schedule(Seconds(m_timeS * 2), &BasicEnergySource::UpdateEnergySource, source);

View File

@@ -413,7 +413,7 @@ EmlsrManager::NotifyUlTxopStart(uint8_t linkId, std::optional<Time> timeToCtsEnd
{
auto stateHelper = m_staMac->GetWifiPhy(linkId)->GetState();
NS_ASSERT(stateHelper);
NS_ASSERT_MSG(stateHelper->GetState() == TX,
NS_ASSERT_MSG(stateHelper->GetState() == WifiPhyState::TX,
"Expecting the aux PHY to be transmitting (an RTS frame)");
NS_ASSERT_MSG(timeToCtsEnd.has_value(),
"Aux PHY is sending RTS, expected to get the time to CTS end");

View File

@@ -21,18 +21,22 @@
#ifndef WIFI_PHY_STATE_H
#define WIFI_PHY_STATE_H
#include "ns3/deprecated.h"
#include "ns3/fatal-error.h"
namespace ns3
{
/**
* The state of the PHY layer.
*/
/// State enumeration
enum WifiPhyState
enum class WifiPhyState
{
/**
* The PHY layer is IDLE.
*/
IDLE,
IDLE = 0,
/**
* The PHY layer has sense the medium busy through the CCA mechanism
*/
@@ -71,19 +75,19 @@ operator<<(std::ostream& os, WifiPhyState state)
{
switch (state)
{
case IDLE:
case WifiPhyState::IDLE:
return (os << "IDLE");
case CCA_BUSY:
case WifiPhyState::CCA_BUSY:
return (os << "CCA_BUSY");
case TX:
case WifiPhyState::TX:
return (os << "TX");
case RX:
case WifiPhyState::RX:
return (os << "RX");
case SWITCHING:
case WifiPhyState::SWITCHING:
return (os << "SWITCHING");
case SLEEP:
case WifiPhyState::SLEEP:
return (os << "SLEEP");
case OFF:
case WifiPhyState::OFF:
return (os << "OFF");
default:
NS_FATAL_ERROR("Invalid state");
@@ -91,4 +95,23 @@ operator<<(std::ostream& os, WifiPhyState state)
}
}
} // namespace ns3
NS_DEPRECATED_3_42("Use WifiPhyState::IDLE instead")
static constexpr auto IDLE = ns3::WifiPhyState::IDLE; //!< \deprecated See WifiPhyState::IDLE
NS_DEPRECATED_3_42("Use WifiPhyState::CCA_BUSY instead")
static constexpr auto CCA_BUSY =
ns3::WifiPhyState::CCA_BUSY; //!< \deprecated See WifiPhyState::CCA_BUSY
NS_DEPRECATED_3_42("Use WifiPhyState::TX instead")
static constexpr auto TX = ns3::WifiPhyState::TX; //!< \deprecated See WifiPhyState::TX
NS_DEPRECATED_3_42("Use WifiPhyState::RX instead")
static constexpr auto RX = ns3::WifiPhyState::RX; //!< \deprecated See WifiPhyState::RX
NS_DEPRECATED_3_42("Use WifiPhyState::SWITCHING instead")
static constexpr auto SWITCHING =
ns3::WifiPhyState::SWITCHING; //!< \deprecated See WifiPhyState::SWITCHING
NS_DEPRECATED_3_42("Use WifiPhyState::SLEEP instead")
static constexpr auto SLEEP = ns3::WifiPhyState::SLEEP; //!< \deprecated See WifiPhyState::SLEEP
NS_DEPRECATED_3_42("Use WifiPhyState::OFF instead")
static constexpr auto OFF = ns3::WifiPhyState::OFF; //!< \deprecated See WifiPhyState::OFF
#endif /* WIFI_PHY_STATE_H */

View File

@@ -124,7 +124,7 @@ WifiRadioEnergyModel::SetEnergySource(const Ptr<EnergySource> source)
m_switchToOffEvent = Simulator::Schedule(durationToOff,
&WifiRadioEnergyModel::ChangeState,
this,
WifiPhyState::OFF);
static_cast<int>(WifiPhyState::OFF));
}
double
@@ -274,7 +274,7 @@ WifiRadioEnergyModel::SetTxCurrentFromModel(double txPowerDbm)
}
Time
WifiRadioEnergyModel::GetMaximumTimeInState(int state) const
WifiRadioEnergyModel::GetMaximumTimeInState(WifiPhyState state) const
{
if (state == WifiPhyState::OFF)
{
@@ -289,25 +289,26 @@ WifiRadioEnergyModel::GetMaximumTimeInState(int state) const
void
WifiRadioEnergyModel::ChangeState(int newState)
{
NS_LOG_FUNCTION(this << newState);
WifiPhyState newPhyState{newState};
NS_LOG_FUNCTION(this << newPhyState);
m_nPendingChangeState++;
if (m_nPendingChangeState > 1 && newState == WifiPhyState::OFF)
if (m_nPendingChangeState > 1 && newPhyState == WifiPhyState::OFF)
{
SetWifiRadioState((WifiPhyState)newState);
SetWifiRadioState(newPhyState);
m_nPendingChangeState--;
return;
}
if (newState != WifiPhyState::OFF)
if (newPhyState != WifiPhyState::OFF)
{
m_switchToOffEvent.Cancel();
Time durationToOff = GetMaximumTimeInState(newState);
Time durationToOff = GetMaximumTimeInState(newPhyState);
m_switchToOffEvent = Simulator::Schedule(durationToOff,
&WifiRadioEnergyModel::ChangeState,
this,
WifiPhyState::OFF);
static_cast<int>(WifiPhyState::OFF));
}
Time duration = Simulator::Now() - m_lastUpdateTime;
@@ -337,7 +338,7 @@ WifiRadioEnergyModel::ChangeState(int newState)
if (m_nPendingChangeState <= 1 && m_currentState != WifiPhyState::OFF)
{
// update current state & last update time stamp
SetWifiRadioState((WifiPhyState)newState);
SetWifiRadioState(newPhyState);
// some debug message
NS_LOG_DEBUG("WifiRadioEnergyModel:Total energy consumption is " << m_totalEnergyConsumption
@@ -383,7 +384,7 @@ WifiRadioEnergyModel::HandleEnergyChanged()
m_switchToOffEvent = Simulator::Schedule(durationToOff,
&WifiRadioEnergyModel::ChangeState,
this,
WifiPhyState::OFF);
static_cast<int>(WifiPhyState::OFF));
}
}
@@ -407,7 +408,7 @@ WifiRadioEnergyModel::DoDispose()
}
double
WifiRadioEnergyModel::GetStateA(int state) const
WifiRadioEnergyModel::GetStateA(WifiPhyState state) const
{
switch (state)
{
@@ -508,7 +509,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxStart(Time duration)
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::RX);
m_changeStateCallback(static_cast<int>(WifiPhyState::RX));
m_switchToIdleEvent.Cancel();
}
@@ -520,7 +521,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxEndOk()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::IDLE);
m_changeStateCallback(static_cast<int>(WifiPhyState::IDLE));
}
void
@@ -531,7 +532,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxEndError()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::IDLE);
m_changeStateCallback(static_cast<int>(WifiPhyState::IDLE));
}
void
@@ -547,7 +548,7 @@ WifiRadioEnergyModelPhyListener::NotifyTxStart(Time duration, double txPowerDbm)
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::TX);
m_changeStateCallback(static_cast<int>(WifiPhyState::TX));
// schedule changing state back to IDLE after TX duration
m_switchToIdleEvent.Cancel();
m_switchToIdleEvent =
@@ -564,7 +565,7 @@ WifiRadioEnergyModelPhyListener::NotifyCcaBusyStart(Time duration,
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::CCA_BUSY);
m_changeStateCallback(static_cast<int>(WifiPhyState::CCA_BUSY));
// schedule changing state back to IDLE after CCA_BUSY duration
m_switchToIdleEvent.Cancel();
m_switchToIdleEvent =
@@ -579,7 +580,7 @@ WifiRadioEnergyModelPhyListener::NotifySwitchingStart(Time duration)
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::SWITCHING);
m_changeStateCallback(static_cast<int>(WifiPhyState::SWITCHING));
// schedule changing state back to IDLE after CCA_BUSY duration
m_switchToIdleEvent.Cancel();
m_switchToIdleEvent =
@@ -594,7 +595,7 @@ WifiRadioEnergyModelPhyListener::NotifySleep()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::SLEEP);
m_changeStateCallback(static_cast<int>(WifiPhyState::SLEEP));
m_switchToIdleEvent.Cancel();
}
@@ -606,7 +607,7 @@ WifiRadioEnergyModelPhyListener::NotifyWakeup()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::IDLE);
m_changeStateCallback(static_cast<int>(WifiPhyState::IDLE));
}
void
@@ -617,7 +618,7 @@ WifiRadioEnergyModelPhyListener::NotifyOff()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::OFF);
m_changeStateCallback(static_cast<int>(WifiPhyState::OFF));
m_switchToIdleEvent.Cancel();
}
@@ -629,7 +630,7 @@ WifiRadioEnergyModelPhyListener::NotifyOn()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::IDLE);
m_changeStateCallback(static_cast<int>(WifiPhyState::IDLE));
}
void
@@ -640,7 +641,7 @@ WifiRadioEnergyModelPhyListener::SwitchToIdle()
{
NS_FATAL_ERROR("WifiRadioEnergyModelPhyListener:Change state callback not set!");
}
m_changeStateCallback(WifiPhyState::IDLE);
m_changeStateCallback(static_cast<int>(WifiPhyState::IDLE));
}
} // namespace ns3

View File

@@ -305,7 +305,7 @@ class WifiRadioEnergyModel : public DeviceEnergyModel
*
* \returns the time the radio can stay in that state based on the remaining energy.
*/
Time GetMaximumTimeInState(int state) const;
Time GetMaximumTimeInState(WifiPhyState state) const;
/**
* \brief Handles energy depletion.
@@ -340,7 +340,7 @@ class WifiRadioEnergyModel : public DeviceEnergyModel
* \param state the wifi state
* \returns draw of device in Amperes, at given state.
*/
double GetStateA(int state) const;
double GetStateA(WifiPhyState state) const;
/**
* \returns Current draw of device in Amperes, at current state.

View File

@@ -765,8 +765,8 @@ class WifiPhyCcaIndicationTest : public TestCase
*/
struct StateCheckPoint
{
Time timePoint{Seconds(0)}; //!< time at which the check will performed
WifiPhyState expectedPhyState{IDLE}; //!< expected PHY state
Time timePoint{Seconds(0)}; //!< time at which the check will performed
WifiPhyState expectedPhyState{WifiPhyState::IDLE}; //!< expected PHY state
};
/**