20#include "ns3/basic-energy-source-helper.h"
21#include "ns3/basic-energy-source.h"
22#include "ns3/config.h"
23#include "ns3/device-energy-model-container.h"
24#include "ns3/double.h"
25#include "ns3/energy-source-container.h"
28#include "ns3/simulator.h"
29#include "ns3/string.h"
30#include "ns3/wifi-radio-energy-model-helper.h"
31#include "ns3/wifi-radio-energy-model.h"
32#include "ns3/yans-wifi-helper.h"
96 std::cerr <<
"Problem with state switch test (WifiPhy idle)." << std::endl;
101 std::cerr <<
"Problem with state switch test (WifiPhy cca busy)." << std::endl;
106 std::cerr <<
"Problem with state switch test (WifiPhy tx)." << std::endl;
111 std::cerr <<
"Problem with state switch test (WifiPhy rx)." << std::endl;
116 std::cerr <<
"Problem with state switch test (WifiPhy switching)." << std::endl;
121 std::cerr <<
"Problem with state switch test (WifiPhy sleep)." << std::endl;
134 source->SetInitialEnergy(50);
136 node->AggregateObject(source);
137 source->SetNode(node);
142 model->SetEnergySource(source);
144 source->AppendDeviceEnergyModel(model);
149 if (models.
GetN() == 0)
151 std::cerr <<
"Model list is empty!." << std::endl;
159 std::cerr <<
"NULL pointer to device model!." << std::endl;
172 static_cast<int>(state));
177 double timeDelta = 0.000000001;
185 double estRemainingEnergy = source->GetInitialEnergy();
186 double voltage = source->GetSupplyVoltage();
187 estRemainingEnergy -= devModel->GetIdleCurrentA() * voltage *
m_timeS;
190 double current = 0.0;
193 case WifiPhyState::IDLE:
194 current = devModel->GetIdleCurrentA();
196 case WifiPhyState::CCA_BUSY:
197 current = devModel->GetCcaBusyCurrentA();
199 case WifiPhyState::TX:
200 current = devModel->GetTxCurrentA();
202 case WifiPhyState::RX:
203 current = devModel->GetRxCurrentA();
205 case WifiPhyState::SWITCHING:
206 current = devModel->GetSwitchingCurrentA();
208 case WifiPhyState::SLEEP:
209 current = devModel->GetSleepCurrentA();
211 case WifiPhyState::OFF:
218 estRemainingEnergy -= current * voltage *
m_timeS;
219 estRemainingEnergy = std::max(0.0, estRemainingEnergy);
222 double remainingEnergy = source->GetRemainingEnergy();
223 NS_LOG_DEBUG(
"Remaining energy is " << remainingEnergy);
224 NS_LOG_DEBUG(
"Estimated remaining energy is " << estRemainingEnergy);
225 NS_LOG_DEBUG(
"Difference is " << estRemainingEnergy - remainingEnergy);
228 if ((remainingEnergy > (estRemainingEnergy +
m_tolerance)) ||
229 (remainingEnergy < (estRemainingEnergy -
m_tolerance)))
231 std::cerr <<
"Incorrect remaining energy!" << std::endl;
239 if (endState != state)
241 std::cerr <<
"Incorrect end state!" << std::endl;
319 std::cerr <<
"Depletion test case problem." << std::endl;
341 std::string phyMode(
"DsssRate1Mbps");
370 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
376 wifiMac.
SetType(
"ns3::AdhocWifiMac");
386 basicSourceHelper.
Set(
"BasicEnergySourceInitialEnergyJ",
DoubleValue(0.0));
388 basicSourceHelper.
Set(
"PeriodicEnergyUpdateInterval",
TimeValue(
Seconds(updateIntervalS)));
407 NS_LOG_DEBUG(
"Update interval = " << updateIntervalS <<
"s");
414 std::cerr <<
"Not all callbacks are invoked!" << std::endl;
424main(
int argc,
char** argv)
427 if (testEnergyUpdate.
DoRun())
433 if (testEnergyDepletion.
DoRun())
Test case of energy depletion handling for BasicEnergySource and WifiRadioEnergyModel.
BasicEnergyDepletionTest()
double m_updateIntervalS
update interval of each device model
double m_simTimeS
maximum simulation time, in seconds
double m_timeStepS
simulation time step size, in seconds
int m_numOfNodes
number of nodes in simulation
virtual ~BasicEnergyDepletionTest()
bool DepletionTestCase(double simTimeS, double updateIntervalS)
bool DoRun()
Performs some tests involving energy depletion.
void DepletionHandler()
Callback invoked when energy is drained from source.
int m_callbackCount
counter for # of callbacks invoked
Test case of update remaining energy for BasicEnergySource and WifiRadioEnergyModel.
double m_timeS
Time in seconds.
ObjectFactory m_energySource
Energy source factory.
ObjectFactory m_deviceEnergyModel
Device energy model factory.
bool StateSwitchTest(WifiPhyState state)
virtual ~BasicEnergyUpdateTest()
bool DoRun()
Performs some tests involving state updates and the relative energy consumption.
double m_tolerance
Tolerance for power estimation.
Creates a BasicEnergySource object.
void Set(std::string name, const AttributeValue &v) override
energy::DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const
This class can be used to hold variables of floating point type such as 'double' or 'float'.
energy::EnergySourceContainer Install(Ptr< Node > node) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
AttributeValue implementation for Time.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void Set(std::string name, const AttributeValue &v)
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Assign WifiRadioEnergyModel to wifi devices.
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
A WiFi radio energy model.
void ChangeState(int newState) override
Changes state of the WifiRadioEnergyMode.
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
void UpdateEnergySource() override
Implements UpdateEnergySource.
Holds a vector of ns3::DeviceEnergyModel pointers.
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
uint32_t GetN() const
Get the number of Ptr<DeviceEnergyModel> stored in this container.
Holds a vector of ns3::EnergySource pointers.
void SetDefault(std::string name, const AttributeValue &value)
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...