22 #include "ns3/simulator.h"
23 #include "ns3/pointer.h"
24 #include "ns3/energy-source.h"
39 .SetGroupName (
"Energy")
41 .AddAttribute (
"IdleCurrentA",
42 "The default radio Idle current in Ampere.",
46 MakeDoubleChecker<double> ())
47 .AddAttribute (
"CcaBusyCurrentA",
48 "The default radio CCA Busy State current in Ampere.",
52 MakeDoubleChecker<double> ())
53 .AddAttribute (
"TxCurrentA",
54 "The radio TX current in Ampere.",
58 MakeDoubleChecker<double> ())
59 .AddAttribute (
"RxCurrentA",
60 "The radio RX current in Ampere.",
64 MakeDoubleChecker<double> ())
65 .AddAttribute (
"SwitchingCurrentA",
66 "The default radio Channel Switch current in Ampere.",
70 MakeDoubleChecker<double> ())
71 .AddAttribute (
"SleepCurrentA",
72 "The radio Sleep current in Ampere.",
76 MakeDoubleChecker<double> ())
77 .AddAttribute (
"TxCurrentModel",
"A pointer to the attached TX current model.",
80 MakePointerChecker<WifiTxCurrentModel> ())
81 .AddTraceSource (
"TotalEnergyConsumption",
82 "Total energy consumption of the radio device.",
84 "ns3::TracedValueCallback::Double")
92 m_lastUpdateTime (
Seconds (0.0)),
93 m_nPendingChangeState (0)
131 double supplyVoltage =
m_source->GetSupplyVoltage ();
238 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy depletion callback!");
250 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy recharged callback!");
275 NS_FATAL_ERROR (
"Requested maximum remaining time for OFF state");
277 double remainingEnergy =
m_source->GetRemainingEnergy ();
278 double supplyVoltage =
m_source->GetSupplyVoltage ();
280 return Seconds (remainingEnergy / (current * supplyVoltage));
308 double supplyVoltage =
m_source->GetSupplyVoltage ();
313 NS_ASSERT (m_totalEnergyConsumption <= m_source->GetInitialEnergy ());
334 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Total energy consumption is " <<
345 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is depleted!");
357 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is recharged!");
369 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is changed!");
417 NS_FATAL_ERROR (
"WifiRadioEnergyModel: undefined radio state " << state);
431 std::string stateName;
438 stateName =
"CCA_BUSY";
447 stateName =
"SWITCHING";
456 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Switching to state: " << stateName <<
496 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
508 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
519 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
530 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Update tx current callback not set!");
535 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
549 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
563 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
577 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
589 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
600 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
612 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
623 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
bool IsNull(void) const
Check for null implementation.
void Nullify(void)
Discard the implementation, set it to null.
Base class for device energy models.
virtual void ChangeState(int newState)=0
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
bool IsPositive(void) const
Exactly equivalent to t >= 0.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
A WiFi radio energy model.
double GetStateA(int state) const
double GetSwitchingCurrentA(void) const
Gets switching current in Amperes.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
double m_idleCurrentA
idle current in Amperes
void HandleEnergyRecharged(void)
Handles energy recharged.
double GetCcaBusyCurrentA(void) const
Gets CCA busy current in Amperes.
double m_ccaBusyCurrentA
CCA busy current in Amperes.
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
WifiRadioEnergyModelPhyListener * GetPhyListener(void)
double GetSleepCurrentA(void) const
Gets sleep current in Amperes.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
Sets CCA busy current in Amperes.
Time GetMaximumTimeInState(int state) const
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double m_sleepCurrentA
sleep current in Amperes
WifiRadioEnergyModelPhyListener * m_listener
WifiPhy listener.
double GetTotalEnergyConsumption(void) const
Ptr< EnergySource > m_source
energy source
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 HandleEnergyDepletion(void)
Handles energy depletion.
EventId m_switchToOffEvent
switch to off event
void SetRxCurrentA(double rxCurrentA)
Sets receive current in Amperes.
void HandleEnergyChanged(void)
Handles energy changed.
double m_txCurrentA
transmit current in Amperes
static TypeId GetTypeId(void)
Get the type ID.
Time m_lastUpdateTime
time stamp of previous energy update
void SetTxCurrentA(double txCurrentA)
Sets transmit current in Amperes.
void DoDispose(void)
Destructor implementation.
WifiPhyState GetCurrentState(void) const
virtual ~WifiRadioEnergyModel()
double GetRxCurrentA(void) const
Gets receive current in Amperes.
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current in Amperes.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current in Amperes.
double m_rxCurrentA
receive current in Amperes
WifiPhyState m_currentState
current state the radio is in
double GetTxCurrentA(void) const
Gets transmit current in Amperes.
void SetWifiRadioState(const WifiPhyState state)
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double DoGetCurrentA(void) const
void SetIdleCurrentA(double idleCurrentA)
Sets idle current in Amperes.
double GetIdleCurrentA(void) const
Gets idle current in Amperes.
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
double m_switchingCurrentA
switching current in Amperes
uint8_t m_nPendingChangeState
pending state change
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change.
void NotifyRxEndOk(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
WifiRadioEnergyModelPhyListener()
void NotifyOn(void) override
Defined in ns3::WifiPhyListener.
void NotifyTxStart(Time duration, double txPowerDbm) override
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
void NotifyOff(void) override
Defined in ns3::WifiPhyListener.
void NotifyRxStart(Time duration) override
Switches the WifiRadioEnergyModel to RX state.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the TX current stored in WifiRadioEnergyModel based on the nominal TX power u...
void NotifyWakeup(void) override
Defined in ns3::WifiPhyListener.
void NotifySleep(void) override
Defined in ns3::WifiPhyListener.
void NotifyMaybeCcaBusyStart(Time duration) override
void SwitchToIdle(void)
A helper function that makes scheduling m_changeStateCallback possible.
virtual ~WifiRadioEnergyModelPhyListener()
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void NotifySwitchingStart(Time duration) override
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
EventId m_switchToIdleEvent
switch to idle event
void NotifyRxEndError(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
@ IDLE
Channel is IDLE, no packet is being transmitted.
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ SWITCHING
The PHY layer is switching to other channel.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ OFF
The PHY layer is switched off.
@ SLEEP
The PHY layer is sleeping.
@ IDLE
The PHY layer is IDLE.