|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
21 #include "ns3/basic-energy-source.h"
22 #include "ns3/wifi-radio-energy-model.h"
23 #include "ns3/basic-energy-source-helper.h"
24 #include "ns3/wifi-radio-energy-model-helper.h"
25 #include "ns3/energy-source-container.h"
26 #include "ns3/device-energy-model-container.h"
29 #include "ns3/simulator.h"
30 #include "ns3/double.h"
31 #include "ns3/config.h"
32 #include "ns3/string.h"
33 #include "ns3/yans-wifi-helper.h"
88 m_energySource.SetTypeId (
"ns3::BasicEnergySource");
89 m_deviceEnergyModel.SetTypeId (
"ns3::WifiRadioEnergyModel");
95 std::cerr <<
"Problem with state switch test (WifiPhy idle)." << std::endl;
100 std::cerr <<
"Problem with state switch test (WifiPhy cca busy)." << std::endl;
105 std::cerr <<
"Problem with state switch test (WifiPhy tx)." << std::endl;
110 std::cerr <<
"Problem with state switch test (WifiPhy rx)." << std::endl;
115 std::cerr <<
"Problem with state switch test (WifiPhy switching)." << std::endl;
120 std::cerr <<
"Problem with state switch test (WifiPhy sleep)." << std::endl;
150 if ((models.
GetN () == 0))
152 std::cerr <<
"Model list is empty!." << std::endl;
157 DynamicCast<WifiRadioEnergyModel> (models.
Get (0));
161 std::cerr <<
"NULL pointer to device model!." << std::endl;
178 double timeDelta = 0.000000001;
188 estRemainingEnergy -= devModel->
GetIdleCurrentA () * voltage * m_timeS;
191 double current = 0.0;
219 estRemainingEnergy -= current * voltage * m_timeS;
220 estRemainingEnergy =
std::max (0.0, estRemainingEnergy);
224 NS_LOG_DEBUG (
"Remaining energy is " << remainingEnergy);
225 NS_LOG_DEBUG (
"Estimated remaining energy is " << estRemainingEnergy);
226 NS_LOG_DEBUG (
"Difference is " << estRemainingEnergy - remainingEnergy);
229 if ((remainingEnergy > (estRemainingEnergy + m_tolerance))
230 || (remainingEnergy < (estRemainingEnergy - m_tolerance)))
232 std::cerr <<
"Incorrect remaining energy!" << std::endl;
240 if (endState != state)
242 std::cerr <<
"Incorrect end state!" << std::endl;
272 void DepletionHandler (
void);
281 bool DepletionTestCase (
double simTimeS,
double updateIntervalS);
298 m_updateIntervalS = 1.5;
313 for (
double simTimeS = 0.0; simTimeS <= m_simTimeS; simTimeS += m_timeStepS)
315 for (
double updateIntervalS = 0.5; updateIntervalS <= m_updateIntervalS;
316 updateIntervalS += m_timeStepS)
318 if (DepletionTestCase (simTimeS, updateIntervalS))
321 std::cerr <<
"Depletion test case problem." << std::endl;
338 double updateIntervalS)
344 std::string phyMode (
"DsssRate1Mbps");
375 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
379 wifiMac.
SetType (
"ns3::AdhocWifiMac");
389 basicSourceHelper.
Set (
"BasicEnergySourceInitialEnergyJ",
DoubleValue (0.0));
391 basicSourceHelper.
Set (
"PeriodicEnergyUpdateInterval",
411 NS_LOG_DEBUG (
"Update interval = " << updateIntervalS <<
"s");
412 NS_LOG_DEBUG (
"Expected callback count is " << m_numOfNodes);
413 NS_LOG_DEBUG (
"Actual callback count is " << m_callbackCount);
416 if (m_numOfNodes != m_callbackCount)
418 std::cerr <<
"Not all callbacks are invoked!" << std::endl;
428 main (
int argc,
char **argv)
431 if (testEnergyUpdate.
DoRun ())
437 if (testEnergyDepletion.
DoRun ())
holds a vector of ns3::NetDevice pointers
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Make it easy to create and manage PHY objects for the YANS model.
void SetPropagationDelay(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
Test case of energy depletion handling for BasicEnergySource and WifiRadioEnergyModel.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ RX
The PHY layer is receiving a packet.
helps to create WifiNetDevice objects
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
double GetCcaBusyCurrentA(void) const
Gets CCA busy current in Amperes.
@ IDLE
The PHY layer is IDLE.
bool DoRun(void)
Performs some tests involving energy depletion.
ObjectFactory m_energySource
virtual void UpdateEnergySource(void)
Implements UpdateEnergySource.
@ OFF
The PHY layer is switched off.
double GetTxCurrentA(void) const
Gets transmit current in Amperes.
virtual ~BasicEnergyDepletionTest()
double GetSleepCurrentA(void) const
Gets sleep current in Amperes.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
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.
void SetInitialEnergy(double initialEnergyJ)
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
void SetChannel(Ptr< YansWifiChannel > channel)
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
double GetRxCurrentA(void) const
Gets receive current in Amperes.
void Set(std::string name, const AttributeValue &v)
Holds a vector of ns3::EnergySource pointers.
EnergySourceContainer Install(Ptr< Node > node) const
bool DepletionTestCase(double simTimeS, double updateIntervalS)
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
ObjectFactory m_deviceEnergyModel
virtual ~BasicEnergyUpdateTest()
virtual double GetSupplyVoltage(void) const
Ptr< YansWifiChannel > Create(void) const
bool DoRun(void)
Performs some tests involving state updates and the relative energy consumption.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
Creates a BasicEnergySource object.
void DepletionHandler(void)
Callback invoked when energy is drained from source.
Assign WifiRadioEnergyModel to wifi devices.
Instantiate subclasses of ns3::Object.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
void SetNode(Ptr< Node > node)
Sets pointer to node containing this EnergySource.
Holds a vector of ns3::DeviceEnergyModel pointers.
virtual double GetInitialEnergy(void) const
@ SLEEP
The PHY layer is sleeping.
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...
static void Run(void)
Run the simulation.
Hold variables of type string.
WifiPhyState
The state of the PHY layer.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
#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.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
BasicEnergyDepletionTest()
AttributeValue implementation for Time.
A WiFi radio energy model.
keep track of a set of node pointers.
void SetType(std::string type, Args &&... args)
manage and create wifi channel objects for the YANS model.
virtual double GetRemainingEnergy(void)
create MAC layers for a ns3::WifiNetDevice.
void SetDefault(std::string name, const AttributeValue &value)
@ TX
The PHY layer is sending a packet.
DeviceEnergyModelContainer FindDeviceEnergyModels(TypeId tid)
void Set(std::string name, const AttributeValue &v)
uint32_t GetN(void) const
Get the number of Ptr<DeviceEnergyModel> stored in this container.
bool StateSwitchTest(WifiPhyState state)
Test case of update remaining energy for BasicEnergySource and WifiRadioEnergyModel.
double GetSwitchingCurrentA(void) const
Gets switching current in Amperes.
void AppendDeviceEnergyModel(Ptr< DeviceEnergyModel > deviceEnergyModelPtr)