9#include "ns3/command-line.h"
10#include "ns3/config.h"
11#include "ns3/device-energy-model-container.h"
12#include "ns3/double.h"
13#include "ns3/energy-source-container.h"
16#include "ns3/rv-battery-model-helper.h"
17#include "ns3/rv-battery-model.h"
18#include "ns3/simulator.h"
19#include "ns3/string.h"
20#include "ns3/wifi-radio-energy-model-helper.h"
21#include "ns3/wifi-radio-energy-model.h"
22#include "ns3/yans-wifi-helper.h"
78 std::vector<Time> timeStamps,
79 Time expLifetime)
const;
112 std::vector<double> loads;
113 std::vector<Time> timeStamps;
116 loads.push_back(0.628);
118 loads.push_back(0.628);
120 timeStamps.push_back(
Seconds(0));
121 timeStamps.push_back(
Seconds(19.5 * 60));
122 timeStamps.push_back(
Seconds(26.0 * 60));
124 profile.
loads = loads;
135 loads.push_back(0.4947);
137 loads.push_back(0.4947);
139 timeStamps.push_back(
Seconds(0));
140 timeStamps.push_back(
Seconds(31.0 * 60));
141 timeStamps.push_back(
Seconds(41.3 * 60));
143 profile.
loads = loads;
154 loads.push_back(0.4256);
156 loads.push_back(0.4256);
158 timeStamps.push_back(
Seconds(0));
159 timeStamps.push_back(
Seconds(41.0 * 60));
160 timeStamps.push_back(
Seconds(54.6 * 60));
162 profile.
loads = loads;
173 loads.push_back(0.2923);
175 loads.push_back(0.2923);
177 timeStamps.push_back(
Seconds(0));
178 timeStamps.push_back(
Seconds(74.6 * 60));
179 timeStamps.push_back(
Seconds(99.5 * 60));
181 profile.
loads = loads;
192 loads.push_back(0.2227);
194 loads.push_back(0.2227);
196 timeStamps.push_back(
Seconds(0));
197 timeStamps.push_back(
Seconds(105.7 * 60));
198 timeStamps.push_back(
Seconds(140.9 * 60));
200 profile.
loads = loads;
211 loads.push_back(0.628);
213 loads.push_back(0.628);
215 timeStamps.push_back(
Seconds(0));
216 timeStamps.push_back(
Seconds(19.5 * 60));
217 timeStamps.push_back(
Seconds(29.9 * 60));
219 profile.
loads = loads;
230 loads.push_back(0.628);
232 loads.push_back(0.628);
234 timeStamps.push_back(
Seconds(0));
235 timeStamps.push_back(
Seconds(19.5 * 60));
236 timeStamps.push_back(
Seconds(22.1 * 60));
238 profile.
loads = loads;
249 loads.push_back(0.628);
251 loads.push_back(0.628);
253 timeStamps.push_back(
Seconds(0));
254 timeStamps.push_back(
Seconds(23.4 * 60));
255 timeStamps.push_back(
Seconds(29.9 * 60));
257 profile.
loads = loads;
268 loads.push_back(0.628);
270 loads.push_back(0.628);
272 timeStamps.push_back(
Seconds(0));
273 timeStamps.push_back(
Seconds(15.6 * 60));
274 timeStamps.push_back(
Seconds(22.1 * 60));
276 profile.
loads = loads;
287 loads.push_back(0.300);
288 loads.push_back(0.628);
289 loads.push_back(0.4947);
290 loads.push_back(0.2523);
291 loads.push_back(0.2341);
292 loads.push_back(0.1379);
293 loads.push_back(0.1139);
294 loads.push_back(0.2656);
296 timeStamps.push_back(
Seconds(0));
297 timeStamps.push_back(
Seconds(0.5 * 60));
298 timeStamps.push_back(
Seconds(5.5 * 60));
299 timeStamps.push_back(
Seconds(10.5 * 60));
300 timeStamps.push_back(
Seconds(35.5 * 60));
301 timeStamps.push_back(
Seconds(60.5 * 60));
302 timeStamps.push_back(
Seconds(85.5 * 60));
303 timeStamps.push_back(
Seconds(110.5 * 60));
305 profile.
loads = loads;
316 loads.push_back(0.300);
317 loads.push_back(0.1139);
318 loads.push_back(0.1379);
319 loads.push_back(0.2341);
320 loads.push_back(0.2523);
321 loads.push_back(0.4947);
322 loads.push_back(0.628);
323 loads.push_back(0.2656);
325 timeStamps.push_back(
Seconds(0));
326 timeStamps.push_back(
Seconds(0.5 * 60));
327 timeStamps.push_back(
Seconds(25.5 * 60));
328 timeStamps.push_back(
Seconds(50.5 * 60));
329 timeStamps.push_back(
Seconds(75.5 * 60));
330 timeStamps.push_back(
Seconds(100.5 * 60));
331 timeStamps.push_back(
Seconds(105.5 * 60));
332 timeStamps.push_back(
Seconds(110.5 * 60));
334 profile.
loads = loads;
345 loads.push_back(0.300);
346 loads.push_back(0.1139);
347 loads.push_back(0.1379);
348 loads.push_back(0.2341);
349 loads.push_back(0.2523);
350 loads.push_back(0.4947);
351 loads.push_back(0.0);
352 loads.push_back(0.300);
353 loads.push_back(0.628);
354 loads.push_back(0.2656);
356 timeStamps.push_back(
Seconds(0));
357 timeStamps.push_back(
Seconds(0.5 * 60));
358 timeStamps.push_back(
Seconds(25.5 * 60));
359 timeStamps.push_back(
Seconds(50.5 * 60));
360 timeStamps.push_back(
Seconds(75.5 * 60));
361 timeStamps.push_back(
Seconds(100.5 * 60));
362 timeStamps.push_back(
Seconds(105.5 * 60));
363 timeStamps.push_back(
Seconds(130.5 * 60));
364 timeStamps.push_back(
Seconds(131.0 * 60));
365 timeStamps.push_back(
Seconds(136.0 * 60));
367 profile.
loads = loads;
378 loads.push_back(0.300);
379 timeStamps.push_back(
Seconds(0));
381 for (
int i = 0; i < 5; i++)
383 loads.push_back(0.628);
384 loads.push_back(0.4947);
385 loads.push_back(0.2523);
386 loads.push_back(0.2341);
387 loads.push_back(0.1379);
388 loads.push_back(0.1139);
390 timeStamps.push_back(
Seconds((0.5 + i * 22.5) * 60));
391 timeStamps.push_back(
Seconds((1.5 + i * 22.5) * 60));
392 timeStamps.push_back(
Seconds((2.5 + i * 22.5) * 60));
393 timeStamps.push_back(
Seconds((7.5 + i * 22.5) * 60));
394 timeStamps.push_back(
Seconds((12.5 + i * 22.5) * 60));
395 timeStamps.push_back(
Seconds((17.5 + i * 22.5) * 60));
398 loads.push_back(0.2656);
399 timeStamps.push_back(
Seconds(110.5 * 60));
401 profile.
loads = loads;
412 loads.push_back(0.300);
413 timeStamps.push_back(
Seconds(0));
415 for (
int i = 0; i < 5; i++)
417 loads.push_back(0.1139);
418 loads.push_back(0.1379);
419 loads.push_back(0.2341);
420 loads.push_back(0.2523);
421 loads.push_back(0.4947);
422 loads.push_back(0.628);
424 timeStamps.push_back(
Seconds((0.5 + i * 22.5) * 60));
425 timeStamps.push_back(
Seconds((5.5 + i * 22.5) * 60));
426 timeStamps.push_back(
Seconds((10.5 + i * 22.5) * 60));
427 timeStamps.push_back(
Seconds((15.5 + i * 22.5) * 60));
428 timeStamps.push_back(
Seconds((20.5 + i * 22.5) * 60));
429 timeStamps.push_back(
Seconds((21.5 + i * 22.5) * 60));
432 loads.push_back(0.2656);
433 timeStamps.push_back(
Seconds(112.5 * 60));
435 profile.
loads = loads;
446 loads.push_back(0.2227);
447 loads.push_back(0.2045);
448 loads.push_back(0.1083);
449 loads.push_back(0.0843);
450 loads.push_back(0.2227);
452 timeStamps.push_back(
Seconds(0));
453 timeStamps.push_back(
Seconds(50.0 * 60));
454 timeStamps.push_back(
Seconds(100.0 * 60));
455 timeStamps.push_back(
Seconds(150.0 * 60));
456 timeStamps.push_back(
Seconds(200.0 * 60));
458 profile.
loads = loads;
469 loads.push_back(0.0843);
470 loads.push_back(0.1083);
471 loads.push_back(0.2045);
472 loads.push_back(0.2227);
473 loads.push_back(0.2227);
475 timeStamps.push_back(
Seconds(0));
476 timeStamps.push_back(
Seconds(50.0 * 60));
477 timeStamps.push_back(
Seconds(100.0 * 60));
478 timeStamps.push_back(
Seconds(150.0 * 60));
479 timeStamps.push_back(
Seconds(200.0 * 60));
481 profile.
loads = loads;
492 loads.push_back(0.0843);
493 loads.push_back(0.1083);
494 loads.push_back(0.2045);
495 loads.push_back(0.0);
496 loads.push_back(0.2227);
497 loads.push_back(0.2227);
499 timeStamps.push_back(
Seconds(0));
500 timeStamps.push_back(
Seconds(50.0 * 60));
501 timeStamps.push_back(
Seconds(100.0 * 60));
502 timeStamps.push_back(
Seconds(150.0 * 60));
503 timeStamps.push_back(
Seconds(200.0 * 60));
504 timeStamps.push_back(
Seconds(250.0 * 60));
506 profile.
loads = loads;
517 for (
int i = 0; i < 10; i++)
519 loads.push_back(0.0843);
520 loads.push_back(0.1083);
521 loads.push_back(0.2045);
522 loads.push_back(0.2227);
524 timeStamps.push_back(
Seconds((0.0 + i * 20.0) * 60));
525 timeStamps.push_back(
Seconds((5.0 + i * 20.0) * 60));
526 timeStamps.push_back(
Seconds((10.0 + i * 20.0) * 60));
527 timeStamps.push_back(
Seconds((15.0 + i * 20.0) * 60));
530 loads.push_back(0.2227);
531 timeStamps.push_back(
Seconds(200.0));
533 profile.
loads = loads;
544 for (
int i = 0; i < 10; i++)
546 loads.push_back(0.0755);
547 loads.push_back(0.0949);
548 loads.push_back(0.2045);
549 loads.push_back(0.2227);
551 timeStamps.push_back(
Seconds((0.0 + i * 20.0) * 60));
552 timeStamps.push_back(
Seconds((5.0 + i * 20.0) * 60));
553 timeStamps.push_back(
Seconds((10.0 + i * 20.0) * 60));
554 timeStamps.push_back(
Seconds((15.0 + i * 20.0) * 60));
557 loads.push_back(0.2227);
558 timeStamps.push_back(
Seconds(200.0));
560 profile.
loads = loads;
571 for (
int i = 0; i < 50; i++)
573 loads.push_back(0.4947);
574 loads.push_back(0.628);
576 timeStamps.push_back(
Seconds((0.0 + i * 2.0) * 60));
577 timeStamps.push_back(
Seconds((1.0 + i * 2.0) * 60));
580 profile.
loads = loads;
591 for (
int i = 0; i < 50; i++)
593 loads.push_back(0.4947);
594 loads.push_back(0.628);
595 loads.push_back(0.0576);
597 timeStamps.push_back(
Seconds((0.0 + i * 3.0) * 60));
598 timeStamps.push_back(
Seconds((1.0 + i * 3.0) * 60));
599 timeStamps.push_back(
Seconds((2.0 + i * 3.0) * 60));
602 profile.
loads = loads;
613 for (
int i = 0; i < 150; i++)
615 loads.push_back(0.005 + 0.005 * i);
616 timeStamps.push_back(
Seconds((0.0 + i * 1.0) * 60));
619 profile.
loads = loads;
631main(
int argc,
char** argv)
634 cmd.Parse(argc, argv);
644 std::cerr <<
"Problems with constant load test (640mA)." << std::endl;
649 std::cerr <<
"Problems with constant load test (320mA)." << std::endl;
651 if (
test.ConstantLoadTest(0.128,
Seconds(16052.0)))
654 std::cerr <<
"Problems with constant load test (128mA)." << std::endl;
656 if (
test.ConstantLoadTest(0.064,
Seconds(32561.0)))
659 std::cerr <<
"Problems with constant load test (64mA)." << std::endl;
661 if (
test.ConstantLoadTest(0.032,
Seconds(65580.0)))
664 std::cerr <<
"Problems with constant load test (32mA)." << std::endl;
668 test.CreateLoadProfiles();
672 test.m_alpha = 35220;
674 for (
uint32_t i = 0; i <
test.m_loadProfiles.size(); i++)
678 if (
test.VariableLoadTest(
test.m_loadProfiles[i].loads,
679 test.m_loadProfiles[i].timeStamps,
680 test.m_loadProfiles[i].itsyLifetime))
683 std::cerr <<
"Problems with variable load test (Itsy)." << std::endl;
689 test.m_alpha = 40027;
691 for (
uint32_t i = 0; i <
test.m_loadProfiles.size(); i++)
695 if (
test.VariableLoadTest(
test.m_loadProfiles[i].loads,
696 test.m_loadProfiles[i].timeStamps,
697 test.m_loadProfiles[i].dualFoilLifeTime))
700 std::cerr <<
"Problems with variable load test (DUALFOIL)." << std::endl;
714 std::string phyMode(
"DsssRate1Mbps");
743 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
749 wifiMac.
SetType(
"ns3::AdhocWifiMac");
758 rvModelHelper.
Set(
"RvBatteryModelLowBatteryThreshold",
DoubleValue(0.0));
774 actualLifetime = srcPtr->GetLifetime();
781 if (actualLifetime != expLifetime)
783 std::cerr <<
"ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
792 std::vector<Time> timeStamps,
793 Time expLifetime)
const
795 NS_ASSERT(loads.size() == timeStamps.size());
801 std::string phyMode(
"DsssRate1Mbps");
830 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
836 wifiMac.
SetType(
"ns3::AdhocWifiMac");
845 rvModelHelper.
Set(
"RvBatteryModelLowBatteryThreshold",
DoubleValue(0.0));
858 for (
uint32_t i = 1; i < loads.size(); i++)
872 actualLifetime = srcPtr->GetLifetime();
881 if (
Abs(actualLifetime - expLifetime) >
Seconds(120))
883 std::cerr <<
"VariableLoadTest: Incorrect lifetime." << std::endl;
This example was originally devised as a test, then it was converted to an example.
bool ConstantLoadTest(double load, Time expLifetime) const
virtual ~BatteryLifetimeTest()
void CreateLoadProfiles()
Creates load profiles according to D.
double m_beta
Beta parameter of the battery model.
bool VariableLoadTest(std::vector< double > loads, std::vector< Time > timeStamps, Time expLifetime) const
double m_alpha
Alpha parameter of the battery model.
std::vector< LoadProfile > m_loadProfiles
Load profiles.
Parse command-line arguments.
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.
Smart pointer class similar to boost::intrusive_ptr.
Creates a RvBatteryModel object.
void Set(std::string name, const AttributeValue &v) override
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.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
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 Set(std::string name, const AttributeValue &v) override
void SetIdleCurrentA(ampere_u idleCurrentA)
Sets idle current.
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)
Holds a vector of ns3::DeviceEnergyModel pointers.
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
Holds a vector of ns3::EnergySource pointers.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void SetDefault(std::string name, const AttributeValue &value)
int64x64_t Abs(const int64x64_t &value)
Absolute value.
#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.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
-ns3 Test suite for the ns3 wrapper script
Load profile of the battery.
Time dualFoilLifeTime
Expected lifetime for a Dualfoil battery.
std::vector< Time > timeStamps
Timestamps container.
std::vector< double > loads
Loads container.
Time itsyLifetime
Expected lifetime for an ITSY battery.