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 energyToDecrease = 0.0;
132 double supplyVoltage =
m_source->GetSupplyVoltage ();
154 energyToDecrease = 0;
264 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy depletion callback!");
276 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy recharged callback!");
300 double remainingEnergy =
m_source->GetRemainingEnergy ();
301 double supplyVoltage =
m_source->GetSupplyVoltage ();
311 remainingTime =
NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (
m_txCurrentA * supplyVoltage))));
314 remainingTime =
NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (
m_rxCurrentA * supplyVoltage))));
323 NS_FATAL_ERROR (
"WifiRadioEnergyModel: undefined radio state " << state);
325 return remainingTime;
353 double energyToDecrease = 0.0;
354 double supplyVoltage =
m_source->GetSupplyVoltage ();
376 energyToDecrease = 0.0;
384 NS_ASSERT (m_totalEnergyConsumption <= m_source->GetInitialEnergy ());
405 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Total energy consumption is " <<
416 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is depleted!");
428 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is recharged!");
440 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is changed!");
497 std::string stateName;
504 stateName =
"CCA_BUSY";
513 stateName =
"SWITCHING";
522 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Switching to state: " << stateName <<
562 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
574 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
585 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
596 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Update tx current callback not set!");
601 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
615 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
629 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
643 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
655 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
666 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
678 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
689 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
double GetRxCurrentA(void) const
Gets receive current.
void NotifyOn(void)
Defined in ns3::WifiPhyListener.
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.
Base class for device energy models.
double GetTxCurrentA(void) const
Gets transmit current.
double m_rxCurrentA
receive current
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
#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.
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 SetRxCurrentA(double rxCurrentA)
Sets receive current.
void NotifyRxEndOk(void)
Switches the WifiRadioEnergyModel back to IDLE state.
double m_idleCurrentA
idle current
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.
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
WifiPhyState GetCurrentState(void) const
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Ptr< EnergySource > m_source
energy source
void NotifySwitchingStart(Time duration)
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
void NotifyMaybeCcaBusyStart(Time 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)
void NotifyOff(void)
Defined in ns3::WifiPhyListener.
WifiRadioEnergyModelPhyListener()
void NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
The PHY layer has sense the medium busy through the CCA mechanism.
Time m_lastUpdateTime
time stamp of previous energy update
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
double GetSwitchingCurrentA(void) const
Gets switching current.
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 NotifyTxStart(Time duration, double txPowerDbm)
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
WifiPhyState
The state of the PHY layer.
void NotifyWakeup(void)
Defined in ns3::WifiPhyListener.
WifiPhyState m_currentState
current state the radio is in
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
static Time Now(void)
Return the current simulation virtual time.
double GetCcaBusyCurrentA(void) const
Gets CCA busy current.
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
void NotifySleep(void)
Defined in ns3::WifiPhyListener.
A WiFi radio energy model.
void NotifyRxStart(Time duration)
Switches the WifiRadioEnergyModel to RX state.
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 DoDispose(void)
Destructor implementation.
void HandleEnergyChanged(void)
Handles energy changed.
bool IsPositive(void) const
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.
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
double m_switchingCurrentA
switching current
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.
virtual ~WifiRadioEnergyModel()
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void SetIdleCurrentA(double idleCurrentA)
Sets idle current.
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double GetIdleCurrentA(void) const
Gets idle current.
void HandleEnergyDepletion(void)
Handles energy depletion.
double m_txCurrentA
transmit current