13#include "ns3/energy-source.h"
15#include "ns3/pointer.h"
16#include "ns3/simulator.h"
29 TypeId(
"ns3::WifiRadioEnergyModel")
31 .SetGroupName(
"Energy")
33 .AddAttribute(
"IdleCurrentA",
34 "The default radio Idle current in Ampere.",
39 .AddAttribute(
"CcaBusyCurrentA",
40 "The default radio CCA Busy State current in Ampere.",
45 .AddAttribute(
"TxCurrentA",
46 "The radio TX current in Ampere.",
51 .AddAttribute(
"RxCurrentA",
52 "The radio RX current in Ampere.",
57 .AddAttribute(
"SwitchingCurrentA",
58 "The default radio Channel Switch current in Ampere.",
63 .AddAttribute(
"SleepCurrentA",
64 "The radio Sleep current in Ampere.",
69 .AddAttribute(
"TxCurrentModel",
70 "A pointer to the attached TX current model.",
75 "TotalEnergyConsumption",
76 "Total energy consumption of the radio device.",
78 "ns3::TracedValueCallback::Double");
86 m_nPendingChangeState(0)
91 m_listener = std::make_shared<WifiRadioEnergyModelPhyListener>();
128 const auto supplyVoltage =
m_source->GetSupplyVoltage();
234 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Setting NULL energy depletion callback!");
245 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Setting NULL energy recharged callback!");
272 const auto remainingEnergy =
m_source->GetRemainingEnergy();
273 const auto supplyVoltage =
m_source->GetSupplyVoltage();
275 return Seconds(remainingEnergy / (current * supplyVoltage));
307 const auto supplyVoltage =
m_source->GetSupplyVoltage();
344 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is depleted!");
356 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is recharged!");
368 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is changed!");
380std::shared_ptr<WifiRadioEnergyModelPhyListener>
419 NS_FATAL_ERROR(
"WifiRadioEnergyModel: undefined radio state " << state);
433 std::string stateName;
440 stateName =
"CCA_BUSY";
449 stateName =
"SWITCHING";
458 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Switching to state: " << stateName
499 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
511 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
522 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
533 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Update tx current callback not set!");
538 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
550 const std::vector<Time>& )
555 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
570 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
585 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
597 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
608 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
620 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
631 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
void Nullify()
Discard the implementation, set it to null.
bool IsNull() const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
A WiFi radio energy model.
void HandleEnergyChanged() override
Handles energy changed.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
void SetSleepCurrentA(ampere_u sleepCurrentA)
Sets sleep current.
void SetRxCurrentA(ampere_u rxCurrentA)
Sets receive current.
WifiPhyState GetCurrentState() const
Ptr< energy::EnergySource > m_source
energy source
void ChangeState(int newState) override
Changes state of the WifiRadioEnergyMode.
ampere_u GetSleepCurrentA() const
Gets sleep current.
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
ampere_u GetCcaBusyCurrentA() const
Gets CCA busy current.
void SetIdleCurrentA(ampere_u idleCurrentA)
Sets idle current.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model in watts.
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
void SetTxCurrentFromModel(dBm_u txPower)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model.
EventId m_switchToOffEvent
switch to off event
void DoDispose() override
Destructor implementation.
void HandleEnergyRecharged() override
Handles energy recharged.
Time m_lastUpdateTime
time stamp of previous energy update
ampere_u GetSwitchingCurrentA() const
Gets switching current.
ampere_u m_switchingCurrent
switching current
ampere_u m_txCurrent
transmit current
ampere_u GetStateA(WifiPhyState state) const
ampere_u GetTxCurrentA() const
Gets transmit current.
std::shared_ptr< WifiRadioEnergyModelPhyListener > m_listener
WifiPhy listener.
void HandleEnergyDepletion() override
Handles energy depletion.
ampere_u m_idleCurrent
idle current
static TypeId GetTypeId()
Get the type ID.
ampere_u DoGetCurrentA() const override
void SetCcaBusyCurrentA(ampere_u ccaBusyCurrentA)
Sets CCA busy current.
~WifiRadioEnergyModel() override
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
std::shared_ptr< WifiRadioEnergyModelPhyListener > GetPhyListener()
ampere_u m_rxCurrent
receive current
WifiPhyState m_currentState
current state the radio is in
ampere_u GetIdleCurrentA() const
Gets idle current.
void SetWifiRadioState(const WifiPhyState state)
ampere_u m_ccaBusyCurrent
CCA busy current.
Time GetMaximumTimeInState(WifiPhyState state) const
void SetTxCurrentA(ampere_u txCurrentA)
Sets transmit current.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
void SetSwitchingCurrentA(ampere_u switchingCurrentA)
Sets switching current.
ampere_u GetRxCurrentA() const
Gets receive current.
ampere_u m_sleepCurrent
sleep current
Watt_u GetTotalEnergyConsumption() const override
void SetEnergySource(const Ptr< energy::EnergySource > source) override
Sets pointer to EnergySource installed on node.
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
uint8_t m_nPendingChangeState
pending state change
energy::DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
WifiRadioEnergyModelPhyListener()
void NotifySleep() override
Notify listeners that we went to sleep.
~WifiRadioEnergyModelPhyListener() override
void NotifyOff() override
Notify listeners that we went to switch off.
void NotifyRxStart(Time duration) override
void SetChangeStateCallback(energy::DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
void NotifyRxEndOk() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the TX current stored in WifiRadioEnergyModel based on the nominal TX power u...
void NotifyRxEndError() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void NotifyTxStart(Time duration, dBm_u txPower) override
void NotifySwitchingStart(Time duration) override
void SwitchToIdle()
A helper function that makes scheduling m_changeStateCallback possible.
void NotifyWakeup() override
Notify listeners that we woke up.
EventId m_switchToIdleEvent
switch to idle event
void NotifyOn() override
Notify listeners that we went to switch on.
void NotifyCcaBusyStart(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations) override
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
@ SWITCHING
The PHY layer is switching to other channel.
@ TX
The PHY layer is sending a packet.
@ OFF
The PHY layer is switched off.
@ IDLE
The PHY layer is IDLE.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ SLEEP
The PHY layer is sleeping.
@ RX
The PHY layer is receiving a packet.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeChecker > MakeDoubleChecker()
double ampere_u
ampere weak type
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
double Watt_u
Watt weak type.
@ IDLE
Channel is IDLE, no packet is being transmitted.