21 #include "ns3/rv-battery-model.h"
22 #include "ns3/wifi-radio-energy-model.h"
23 #include "ns3/rv-battery-model-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/command-line.h"
33 #include "ns3/string.h"
34 #include "ns3/yans-wifi-helper.h"
66 void CreateLoadProfiles (
void);
76 bool ConstantLoadTest (
double load,
Time expLifetime);
87 bool VariableLoadTest (std::vector<double> loads,
88 std::vector<Time> timeStamps,
122 std::vector<double> loads;
123 std::vector<Time> timeStamps;
126 loads.push_back (0.628);
128 loads.push_back (0.628);
130 timeStamps.push_back (
Seconds (0));
131 timeStamps.push_back (
Seconds (19.5 * 60));
132 timeStamps.push_back (
Seconds (26.0 * 60));
134 profile.
loads = loads;
139 m_loadProfiles.push_back (profile);
145 loads.push_back (0.4947);
147 loads.push_back (0.4947);
149 timeStamps.push_back (
Seconds (0));
150 timeStamps.push_back (
Seconds (31.0 * 60));
151 timeStamps.push_back (
Seconds (41.3 * 60));
153 profile.
loads = loads;
158 m_loadProfiles.push_back (profile);
164 loads.push_back (0.4256);
166 loads.push_back (0.4256);
168 timeStamps.push_back (
Seconds (0));
169 timeStamps.push_back (
Seconds (41.0 * 60));
170 timeStamps.push_back (
Seconds (54.6 * 60));
172 profile.
loads = loads;
177 m_loadProfiles.push_back (profile);
183 loads.push_back (0.2923);
185 loads.push_back (0.2923);
187 timeStamps.push_back (
Seconds (0));
188 timeStamps.push_back (
Seconds (74.6 * 60));
189 timeStamps.push_back (
Seconds (99.5 * 60));
191 profile.
loads = loads;
196 m_loadProfiles.push_back (profile);
202 loads.push_back (0.2227);
204 loads.push_back (0.2227);
206 timeStamps.push_back (
Seconds (0));
207 timeStamps.push_back (
Seconds (105.7 * 60));
208 timeStamps.push_back (
Seconds (140.9 * 60));
210 profile.
loads = loads;
215 m_loadProfiles.push_back (profile);
221 loads.push_back (0.628);
223 loads.push_back (0.628);
225 timeStamps.push_back (
Seconds (0));
226 timeStamps.push_back (
Seconds (19.5 * 60));
227 timeStamps.push_back (
Seconds (29.9 * 60));
229 profile.
loads = loads;
234 m_loadProfiles.push_back (profile);
240 loads.push_back (0.628);
242 loads.push_back (0.628);
244 timeStamps.push_back (
Seconds (0));
245 timeStamps.push_back (
Seconds (19.5 * 60));
246 timeStamps.push_back (
Seconds (22.1 * 60));
248 profile.
loads = loads;
253 m_loadProfiles.push_back (profile);
259 loads.push_back (0.628);
261 loads.push_back (0.628);
263 timeStamps.push_back (
Seconds (0));
264 timeStamps.push_back (
Seconds (23.4 * 60));
265 timeStamps.push_back (
Seconds (29.9 * 60));
267 profile.
loads = loads;
272 m_loadProfiles.push_back (profile);
278 loads.push_back (0.628);
280 loads.push_back (0.628);
282 timeStamps.push_back (
Seconds (0));
283 timeStamps.push_back (
Seconds (15.6 * 60));
284 timeStamps.push_back (
Seconds (22.1 * 60));
286 profile.
loads = loads;
291 m_loadProfiles.push_back (profile);
297 loads.push_back (0.300);
298 loads.push_back (0.628);
299 loads.push_back (0.4947);
300 loads.push_back (0.2523);
301 loads.push_back (0.2341);
302 loads.push_back (0.1379);
303 loads.push_back (0.1139);
304 loads.push_back (0.2656);
306 timeStamps.push_back (
Seconds (0));
307 timeStamps.push_back (
Seconds (0.5 * 60));
308 timeStamps.push_back (
Seconds (5.5 * 60));
309 timeStamps.push_back (
Seconds (10.5 * 60));
310 timeStamps.push_back (
Seconds (35.5 * 60));
311 timeStamps.push_back (
Seconds (60.5 * 60));
312 timeStamps.push_back (
Seconds (85.5 * 60));
313 timeStamps.push_back (
Seconds (110.5 * 60));
315 profile.
loads = loads;
320 m_loadProfiles.push_back (profile);
326 loads.push_back (0.300);
327 loads.push_back (0.1139);
328 loads.push_back (0.1379);
329 loads.push_back (0.2341);
330 loads.push_back (0.2523);
331 loads.push_back (0.4947);
332 loads.push_back (0.628);
333 loads.push_back (0.2656);
335 timeStamps.push_back (
Seconds (0));
336 timeStamps.push_back (
Seconds (0.5 * 60));
337 timeStamps.push_back (
Seconds (25.5 * 60));
338 timeStamps.push_back (
Seconds (50.5 * 60));
339 timeStamps.push_back (
Seconds (75.5 * 60));
340 timeStamps.push_back (
Seconds (100.5 * 60));
341 timeStamps.push_back (
Seconds (105.5 * 60));
342 timeStamps.push_back (
Seconds (110.5 * 60));
344 profile.
loads = loads;
349 m_loadProfiles.push_back (profile);
355 loads.push_back (0.300);
356 loads.push_back (0.1139);
357 loads.push_back (0.1379);
358 loads.push_back (0.2341);
359 loads.push_back (0.2523);
360 loads.push_back (0.4947);
361 loads.push_back (0.0);
362 loads.push_back (0.300);
363 loads.push_back (0.628);
364 loads.push_back (0.2656);
366 timeStamps.push_back (
Seconds (0));
367 timeStamps.push_back (
Seconds (0.5 * 60));
368 timeStamps.push_back (
Seconds (25.5 * 60));
369 timeStamps.push_back (
Seconds (50.5 * 60));
370 timeStamps.push_back (
Seconds (75.5 * 60));
371 timeStamps.push_back (
Seconds (100.5 * 60));
372 timeStamps.push_back (
Seconds (105.5 * 60));
373 timeStamps.push_back (
Seconds (130.5 * 60));
374 timeStamps.push_back (
Seconds (131.0 * 60));
375 timeStamps.push_back (
Seconds (136.0 * 60));
377 profile.
loads = loads;
382 m_loadProfiles.push_back (profile);
388 loads.push_back (0.300);
389 timeStamps.push_back (
Seconds (0));
391 for (
int i = 0; i < 5; i++)
393 loads.push_back (0.628);
394 loads.push_back (0.4947);
395 loads.push_back (0.2523);
396 loads.push_back (0.2341);
397 loads.push_back (0.1379);
398 loads.push_back (0.1139);
400 timeStamps.push_back (
Seconds ((0.5 + i * 22.5) * 60));
401 timeStamps.push_back (
Seconds ((1.5 + i * 22.5) * 60));
402 timeStamps.push_back (
Seconds ((2.5 + i * 22.5) * 60));
403 timeStamps.push_back (
Seconds ((7.5 + i * 22.5) * 60));
404 timeStamps.push_back (
Seconds ((12.5 + i * 22.5) * 60));
405 timeStamps.push_back (
Seconds ((17.5 + i * 22.5) * 60));
408 loads.push_back (0.2656);
409 timeStamps.push_back (
Seconds (110.5 * 60));
411 profile.
loads = loads;
416 m_loadProfiles.push_back (profile);
422 loads.push_back (0.300);
423 timeStamps.push_back (
Seconds (0));
425 for (
int i = 0; i < 5; i++)
427 loads.push_back (0.1139);
428 loads.push_back (0.1379);
429 loads.push_back (0.2341);
430 loads.push_back (0.2523);
431 loads.push_back (0.4947);
432 loads.push_back (0.628);
434 timeStamps.push_back (
Seconds ((0.5 + i * 22.5) * 60));
435 timeStamps.push_back (
Seconds ((5.5 + i * 22.5) * 60));
436 timeStamps.push_back (
Seconds ((10.5 + i * 22.5) * 60));
437 timeStamps.push_back (
Seconds ((15.5 + i * 22.5) * 60));
438 timeStamps.push_back (
Seconds ((20.5 + i * 22.5) * 60));
439 timeStamps.push_back (
Seconds ((21.5 + i * 22.5) * 60));
442 loads.push_back (0.2656);
443 timeStamps.push_back (
Seconds (112.5 * 60));
445 profile.
loads = loads;
450 m_loadProfiles.push_back (profile);
456 loads.push_back (0.2227);
457 loads.push_back (0.2045);
458 loads.push_back (0.1083);
459 loads.push_back (0.0843);
460 loads.push_back (0.2227);
462 timeStamps.push_back (
Seconds (0));
463 timeStamps.push_back (
Seconds (50.0 * 60));
464 timeStamps.push_back (
Seconds (100.0 * 60));
465 timeStamps.push_back (
Seconds (150.0 * 60));
466 timeStamps.push_back (
Seconds (200.0 * 60));
468 profile.
loads = loads;
473 m_loadProfiles.push_back (profile);
479 loads.push_back (0.0843);
480 loads.push_back (0.1083);
481 loads.push_back (0.2045);
482 loads.push_back (0.2227);
483 loads.push_back (0.2227);
485 timeStamps.push_back (
Seconds (0));
486 timeStamps.push_back (
Seconds (50.0 * 60));
487 timeStamps.push_back (
Seconds (100.0 * 60));
488 timeStamps.push_back (
Seconds (150.0 * 60));
489 timeStamps.push_back (
Seconds (200.0 * 60));
491 profile.
loads = loads;
496 m_loadProfiles.push_back (profile);
502 loads.push_back (0.0843);
503 loads.push_back (0.1083);
504 loads.push_back (0.2045);
505 loads.push_back (0.0);
506 loads.push_back (0.2227);
507 loads.push_back (0.2227);
509 timeStamps.push_back (
Seconds (0));
510 timeStamps.push_back (
Seconds (50.0 * 60));
511 timeStamps.push_back (
Seconds (100.0 * 60));
512 timeStamps.push_back (
Seconds (150.0 * 60));
513 timeStamps.push_back (
Seconds (200.0 * 60));
514 timeStamps.push_back (
Seconds (250.0 * 60));
516 profile.
loads = loads;
521 m_loadProfiles.push_back (profile);
527 for (
int i = 0; i < 10; i++)
529 loads.push_back (0.0843);
530 loads.push_back (0.1083);
531 loads.push_back (0.2045);
532 loads.push_back (0.2227);
534 timeStamps.push_back (
Seconds ((0.0 + i * 20.0) * 60));
535 timeStamps.push_back (
Seconds ((5.0 + i * 20.0) * 60));
536 timeStamps.push_back (
Seconds ((10.0 + i * 20.0) * 60));
537 timeStamps.push_back (
Seconds ((15.0 + i * 20.0) * 60));
540 loads.push_back (0.2227);
541 timeStamps.push_back (
Seconds (200.0));
543 profile.
loads = loads;
548 m_loadProfiles.push_back (profile);
554 for (
int i = 0; i < 10; i++)
556 loads.push_back (0.0755);
557 loads.push_back (0.0949);
558 loads.push_back (0.2045);
559 loads.push_back (0.2227);
561 timeStamps.push_back (
Seconds ((0.0 + i * 20.0) * 60));
562 timeStamps.push_back (
Seconds ((5.0 + i * 20.0) * 60));
563 timeStamps.push_back (
Seconds ((10.0 + i * 20.0) * 60));
564 timeStamps.push_back (
Seconds ((15.0 + i * 20.0) * 60));
567 loads.push_back (0.2227);
568 timeStamps.push_back (
Seconds (200.0));
570 profile.
loads = loads;
575 m_loadProfiles.push_back (profile);
581 for (
int i = 0; i < 50; i++)
583 loads.push_back (0.4947);
584 loads.push_back (0.628);
586 timeStamps.push_back (
Seconds ((0.0 + i * 2.0) * 60));
587 timeStamps.push_back (
Seconds ((1.0 + i * 2.0) * 60));
590 profile.
loads = loads;
595 m_loadProfiles.push_back (profile);
601 for (
int i = 0; i < 50; i++)
603 loads.push_back (0.4947);
604 loads.push_back (0.628);
605 loads.push_back (0.0576);
607 timeStamps.push_back (
Seconds ((0.0 + i * 3.0) * 60));
608 timeStamps.push_back (
Seconds ((1.0 + i * 3.0) * 60));
609 timeStamps.push_back (
Seconds ((2.0 + i * 3.0) * 60));
612 profile.
loads = loads;
617 m_loadProfiles.push_back (profile);
623 for (
int i = 0; i < 150; i++)
625 loads.push_back (0.005 + 0.005 * i);
626 timeStamps.push_back (
Seconds ((0.0 + i * 1.0) * 60));
629 profile.
loads = loads;
634 m_loadProfiles.push_back (profile);
641 main (
int argc,
char **argv)
644 cmd.Parse (argc, argv);
651 if (test.ConstantLoadTest (0.640,
Seconds (2844.0)))
654 std::cerr <<
"Problems with constant load test (640mA)." << std::endl;
656 if (test.ConstantLoadTest (0.320,
Seconds (6146.0)))
659 std::cerr <<
"Problems with constant load test (320mA)." << std::endl;
661 if (test.ConstantLoadTest (0.128,
Seconds (16052.0)))
664 std::cerr <<
"Problems with constant load test (128mA)." << std::endl;
666 if (test.ConstantLoadTest (0.064,
Seconds (32561.0)))
669 std::cerr <<
"Problems with constant load test (64mA)." << std::endl;
671 if (test.ConstantLoadTest (0.032,
Seconds (65580.0)))
674 std::cerr <<
"Problems with constant load test (32mA)." << std::endl;
678 test.CreateLoadProfiles ();
682 test.m_alpha = 35220;
684 for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
688 if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
689 test.m_loadProfiles[i].timeStamps,
690 test.m_loadProfiles[i].itsyLifetime))
693 std::cerr <<
"Problems with variable load test (Itsy)." << std::endl;
699 test.m_alpha = 40027;
701 for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
705 if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
706 test.m_loadProfiles[i].timeStamps,
707 test.m_loadProfiles[i].dualFoilLifeTime))
710 std::cerr <<
"Problems with variable load test (DUALFOIL)." << std::endl;
724 std::string phyMode (
"DsssRate1Mbps");
755 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
759 wifiMac.
SetType (
"ns3::AdhocWifiMac");
766 rvModelHelper.
Set (
"RvBatteryModelAlphaValue",
DoubleValue (m_alpha));
767 rvModelHelper.
Set (
"RvBatteryModelBetaValue",
DoubleValue (m_beta));
768 rvModelHelper.
Set (
"RvBatteryModelLowBatteryThreshold",
DoubleValue (0.0));
784 actualLifetime = srcPtr->GetLifetime ();
791 if (actualLifetime != expLifetime)
793 std::cerr <<
"ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
802 std::vector<Time> timeStamps,
805 NS_ASSERT (loads.size () == timeStamps.size ());
811 std::string phyMode (
"DsssRate1Mbps");
842 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
846 wifiMac.
SetType (
"ns3::AdhocWifiMac");
853 rvModelHelper.
Set (
"RvBatteryModelAlphaValue",
DoubleValue (m_alpha));
854 rvModelHelper.
Set (
"RvBatteryModelBetaValue",
DoubleValue (m_beta));
855 rvModelHelper.
Set (
"RvBatteryModelLowBatteryThreshold",
DoubleValue (0.0));
868 for (uint32_t i = 1; i < loads.size (); i++)
871 wifiDevicePtr, loads[i]);
880 actualLifetime = srcPtr->GetLifetime ();
889 if (
Abs (actualLifetime - expLifetime) >
Seconds (120))
891 std::cerr <<
"VariableLoadTest: Incorrect lifetime." << std::endl;
This example was originally devised as a test, then it was converted to an example.
virtual ~BatteryLifetimeTest()
void CreateLoadProfiles(void)
Creates load profiles according to D.
bool ConstantLoadTest(double load, Time expLifetime)
double m_beta
Beta parameter of the battery model.
bool VariableLoadTest(std::vector< double > loads, std::vector< Time > timeStamps, Time expLifetime)
double m_alpha
Alpha parameter of the battery model.
std::vector< LoadProfile > m_loadProfiles
Load profiles.
Parse command-line arguments.
Holds a vector of ns3::DeviceEnergyModel pointers.
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Holds a vector of ns3::EnergySource pointers.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
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)
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Run(void)
Run the simulation.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const enum 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(double idleCurrentA)
Sets idle current in Amperes.
manage and create wifi channel 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< YansWifiChannel > Create(void) const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
#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.
Load profile of the battery.
std::vector< Time > timeStamps
Timestamps container.
std::vector< double > loads
Loads container.
Time dualFoilLifeTime
Expected lifetime for a Dualfoil battery.
Time itsyLifetime
Expected lifetime for an ITSY battery.