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