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!");
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
double GetRxCurrentA(void) const
Gets receive current in Amperes.
Simulation virtual time values and global simulation resolution.
static TypeId GetTypeId(void)
Get the type ID.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void HandleEnergyRecharged(void)
Handles energy recharged.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model in watts.
Base class for device energy models.
double GetTxCurrentA(void) const
Gets transmit current in Amperes.
double m_rxCurrentA
receive current in Amperes
void SetWifiRadioState(const WifiPhyState state)
The PHY layer is sleeping.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the TX current stored in WifiRadioEnergyModel based on the nominal TX power u...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Channel is IDLE, no packet is being transmitted.
double m_ccaBusyCurrentA
CCA busy current in Amperes.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
void NotifyOff(void) override
Defined in ns3::WifiPhyListener.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
WifiRadioEnergyModelPhyListener * m_listener
WifiPhy listener.
virtual ~WifiRadioEnergyModelPhyListener()
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current in Amperes.
WifiRadioEnergyModelPhyListener * GetPhyListener(void)
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void SwitchToIdle(void)
A helper function that makes scheduling m_changeStateCallback possible.
void NotifyOn(void) override
Defined in ns3::WifiPhyListener.
void SetRxCurrentA(double rxCurrentA)
Sets receive current in Amperes.
void NotifySwitchingStart(Time duration) override
double m_idleCurrentA
idle current in Amperes
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
Sets CCA busy current in Amperes.
Time GetMaximumTimeInState(int state) const
double GetTotalEnergyConsumption(void) const
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double m_sleepCurrentA
sleep current in Amperes
WifiPhyState GetCurrentState(void) const
Ptr< EnergySource > m_source
energy source
void NotifyMaybeCcaBusyStart(Time duration) override
void NotifyTxStart(Time duration, double txPowerDbm) override
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model...
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
WifiRadioEnergyModelPhyListener()
The PHY layer has sense the medium busy through the CCA mechanism.
Time m_lastUpdateTime
time stamp of previous energy update
double GetSwitchingCurrentA(void) const
Gets switching current in Amperes.
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
EventId m_switchToOffEvent
switch to off event
EventId m_switchToIdleEvent
switch to idle event
void NotifyRxStart(Time duration) override
Switches the WifiRadioEnergyModel to RX state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
void NotifyWakeup(void) override
Defined in ns3::WifiPhyListener.
WifiPhyState
The state of the PHY layer.
WifiPhyState m_currentState
current state the radio is in
double GetStateA(int state) const
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
static Time Now(void)
Return the current simulation virtual time.
void NotifyRxEndOk(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
double GetCcaBusyCurrentA(void) const
Gets CCA busy current in Amperes.
void SetTxCurrentA(double txCurrentA)
Sets transmit current in Amperes.
A WiFi radio energy model.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
The PHY layer is sending a packet.
void NotifySleep(void) override
Defined in ns3::WifiPhyListener.
void DoDispose(void)
Destructor implementation.
void HandleEnergyChanged(void)
Handles energy changed.
bool IsPositive(void) const
Exactly equivalent to t >= 0.
uint8_t m_nPendingChangeState
pending state change
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
Time Seconds(double value)
Construct a Time in the indicated unit.
The PHY layer is receiving a packet.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
double DoGetCurrentA(void) const
The PHY layer is switched off.
void Nullify(void)
Discard the implementation, set it to null.
virtual void ChangeState(int newState)=0
The PHY layer is switching to other channel.
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current in Amperes.
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
double m_switchingCurrentA
switching current in Amperes
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
bool IsNull(void) const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
double GetSleepCurrentA(void) const
Gets sleep current in Amperes.
virtual ~WifiRadioEnergyModel()
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void SetIdleCurrentA(double idleCurrentA)
Sets idle current in Amperes.
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...
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double GetIdleCurrentA(void) const
Gets idle current in Amperes.
void NotifyRxEndError(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
void HandleEnergyDepletion(void)
Handles energy depletion.
double m_txCurrentA
transmit current in Amperes