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"
72 BasicEnergyUpdateTest::BasicEnergyUpdateTest ()
73 :
TestCase (
"Basic energy model update remaining energy test case")
76 m_tolerance = 1.0e-13;
79 BasicEnergyUpdateTest::~BasicEnergyUpdateTest ()
87 m_energySource.
SetTypeId (
"ns3::BasicEnergySource");
88 m_deviceEnergyModel.
SetTypeId (
"ns3::WifiRadioEnergyModel");
91 NS_TEST_ASSERT_MSG_EQ (
StateSwitchTest (WifiPhy::IDLE),
false,
"Problem with state switch test (WifiPhy idle).");
92 NS_TEST_ASSERT_MSG_EQ (
StateSwitchTest (WifiPhy::CCA_BUSY),
false,
"Problem with state switch test (WifiPhy cca busy).");
93 NS_TEST_ASSERT_MSG_EQ (
StateSwitchTest (WifiPhy::TX),
false,
"Problem with state switch test (WifiPhy tx).");
94 NS_TEST_ASSERT_MSG_EQ (
StateSwitchTest (WifiPhy::RX),
false,
"Problem with state switch test (WifiPhy rx).");
95 NS_TEST_ASSERT_MSG_EQ (
StateSwitchTest (WifiPhy::SWITCHING),
false,
"Problem with state switch test (WifiPhy switching).");
115 source->AppendDeviceEnergyModel (model);
119 source->FindDeviceEnergyModels (
"ns3::WifiRadioEnergyModel");
121 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (
false, (models.
GetN () == 0),
"Model list is empty!");
124 DynamicCast<WifiRadioEnergyModel> (models.
Get (0));
126 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (0, devModel,
"NULL pointer to device model!");
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 ();
151 estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS;
157 double actualTime = m_timeS;
158 actualTime /= source->GetEnergyUpdateInterval ().GetSeconds ();
159 actualTime = floor (actualTime);
160 actualTime *= source->GetEnergyUpdateInterval ().GetSeconds ();
163 double current = 0.0;
167 current = devModel->GetIdleCurrentA ();
169 case WifiPhy::CCA_BUSY:
170 current = devModel->GetCcaBusyCurrentA ();
173 current = devModel->GetTxCurrentA ();
176 current = devModel->GetRxCurrentA ();
178 case WifiPhy::SWITCHING:
179 current = devModel->GetSwitchingCurrentA ();
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);
193 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (remainingEnergy, estRemainingEnergy, m_tolerance,
194 "Incorrect remaining energy!");
200 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (endState, state,
"Incorrect end state!");
201 Simulator::Destroy ();
240 double m_updateIntervalS;
244 BasicEnergyDepletionTest::BasicEnergyDepletionTest ()
245 :
TestCase (
"Basic energy model energy depletion test case")
251 m_updateIntervalS = 1.5;
254 BasicEnergyDepletionTest::~BasicEnergyDepletionTest ()
264 for (
double simTimeS = 0.0; simTimeS <= m_simTimeS; simTimeS += m_timeStepS)
266 for (
double updateIntervalS = 0.5; updateIntervalS <= m_updateIntervalS;
267 updateIntervalS += m_timeStepS)
269 NS_TEST_ASSERT_MSG_EQ (
DepletionTestCase (simTimeS, updateIntervalS),
false,
"Depletion test case problem.");
284 double updateIntervalS)
290 std::string phyMode (
"DsssRate1Mbps");
293 Config::SetDefault (
"ns3::WifiRemoteStationManager::FragmentationThreshold",
296 Config::SetDefault (
"ns3::WifiRemoteStationManager::RtsCtsThreshold",
299 Config::SetDefault (
"ns3::WifiRemoteStationManager::NonUnicastMode",
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");
358 NS_LOG_DEBUG (
"Expected callback count is " << m_numOfNodes);
359 NS_LOG_DEBUG (
"Actual callback count is " << m_callbackCount);
362 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (m_numOfNodes, m_callbackCount,
"Not all callbacks are invoked!");
380 BasicEnergyModelTestSuite::BasicEnergyModelTestSuite ()
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
Assign WifiRadioEnergyModel to wifi devices.
Holds a vector of ns3::EnergySource pointers.
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.
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())
#define NS_LOG_COMPONENT_DEFINE(name)
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
void SetTypeId(TypeId tid)
void Set(std::string name, const AttributeValue &v)
void DoRun(void)
Implementation to actually run this test case.
helps to create WifiNetDevice objects
void DoRun(void)
Implementation to actually run this test case.
Holds a vector of ns3::DeviceEnergyModel pointers.
#define NS_FATAL_ERROR(msg)
fatal error handling
NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
void SetChannel(Ptr< YansWifiChannel > channel)
hold objects of type ns3::Time
Ptr< Object > Create(void) const
Creates a BasicEnergySource object.
holds a vector of ns3::NetDevice pointers
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<DeviceEnergyModel> stored in this container.
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
keep track of a set of node pointers.
EnergySourceContainer Install(Ptr< Node > node) const
manage and create wifi channel objects for the yans model.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
A WiFi radio energy model.
instantiate subclasses of ns3::Object.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#define NS_LOG_DEBUG(msg)
void Set(std::string name, const AttributeValue &v)
uint32_t GetN(void) const
Get the number of Ptr<DeviceEnergyModel> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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 an floating point type.
bool DepletionTestCase(double simTimeS, double updateIntervalS)
void DepletionHandler(void)