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"
30 #include "ns3/simulator.h"
31 #include "ns3/double.h"
32 #include "ns3/config.h"
33 #include "ns3/string.h"
34 #include "ns3/yans-wifi-helper.h"
35 #include "ns3/nqos-wifi-mac-helper.h"
73 :
TestCase (
"Basic energy model update remaining energy test case")
115 source->AppendDeviceEnergyModel (model);
119 source->FindDeviceEnergyModels (
"ns3::WifiRadioEnergyModel");
124 DynamicCast<WifiRadioEnergyModel> (models.
Get (0));
134 Simulator::Schedule (Seconds (
m_timeS),
135 &WifiRadioEnergyModel::ChangeState, devModel, state);
138 Simulator::Schedule (Seconds (
m_timeS * 2),
139 &BasicEnergySource::UpdateEnergySource, source);
141 double timeDelta = 0.000000001;
143 Simulator::Stop (Seconds (
m_timeS * 2 + timeDelta));
149 double estRemainingEnergy = source->GetInitialEnergy ();
150 double voltage = source->GetSupplyVoltage ();
158 actualTime /= source->GetEnergyUpdateInterval ().GetSeconds ();
159 actualTime = floor (actualTime);
160 actualTime *= source->GetEnergyUpdateInterval ().GetSeconds ();
169 case WifiPhy::CCA_BUSY:
178 case WifiPhy::SWITCHING:
185 estRemainingEnergy -= current * voltage *
m_timeS;
188 double remainingEnergy = source->GetRemainingEnergy ();
189 NS_LOG_DEBUG (
"Remaining energy is " << remainingEnergy);
190 NS_LOG_DEBUG (
"Estimated remaining energy is " << estRemainingEnergy);
191 NS_LOG_DEBUG (
"Difference is " << estRemainingEnergy - remainingEnergy);
194 "Incorrect remaining energy!");
201 Simulator::Destroy ();
245 :
TestCase (
"Basic energy model energy depletion test case")
284 double updateIntervalS)
290 std::string phyMode (
"DsssRate1Mbps");
325 wifiMac.
SetType (
"ns3::AdhocWifiMac");
335 basicSourceHelper.
Set (
"BasicEnergySourceInitialEnergyJ",
DoubleValue (0.0));
337 basicSourceHelper.
Set (
"PeriodicEnergyUpdateInterval",
352 Simulator::Stop (Seconds (simTimeS));
354 Simulator::Destroy ();
357 NS_LOG_DEBUG (
"Update interval = " << updateIntervalS <<
"s");
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
BasicEnergyModelTestSuite()
Assign WifiRadioEnergyModel to wifi devices.
Holds a vector of ns3::EnergySource pointers.
ObjectFactory m_deviceEnergyModel
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, 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())
hold variables of type string
Make it easy to create and manage PHY objects for the yans model.
State
The state of the PHY layer.
virtual void SetType(std::string type, 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())
Channel is IDLE, no packet is being transmitted.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void SetTypeId(TypeId tid)
#define NS_FATAL_ERROR(msg)
fatal error handling
Test case of update remaining energy for BasicEnergySource and WifiRadioEnergyModel.
void Set(std::string name, const AttributeValue &v)
void DoRun(void)
Implementation to actually run this TestCase.
Unit test suite for energy model.
helps to create WifiNetDevice objects
void DoRun(void)
Implementation to actually run this TestCase.
Holds a vector of ns3::DeviceEnergyModel pointers.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
BasicEnergyDepletionTest()
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
void SetChannel(Ptr< YansWifiChannel > channel)
double GetCcaBusyCurrentA(void) const
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
static BasicEnergyModelTestSuite g_energyModelTestSuite
hold objects of type ns3::Time
Ptr< Object > Create(void) const
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not...
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Creates a BasicEnergySource object.
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
WifiPhy::State GetCurrentState(void) const
bool StateSwitchTest(WifiPhy::State state)
void AggregateObject(Ptr< Object > other)
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr stored in this container.
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
void SetDefault(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
EnergySourceContainer Install(Ptr< Node > node) const
double GetTxCurrentA(void) const
Test case of energy depletion handling for BasicEnergySource and WifiRadioEnergyModel.
double GetRxCurrentA(void) const
manage and create wifi channel objects for the yans model.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
A WiFi radio energy model.
virtual ~BasicEnergyUpdateTest()
instantiate subclasses of ns3::Object.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual ~BasicEnergyDepletionTest()
void Set(std::string name, const AttributeValue &v)
double GetIdleCurrentA(void) const
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
ObjectFactory m_energySource
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())
Hold a floating point type.
bool DepletionTestCase(double simTimeS, double updateIntervalS)
void DepletionHandler(void)
Callback invoked when energy is drained from source.
double GetSwitchingCurrentA(void) const