20#include "ns3/command-line.h"
21#include "ns3/config.h"
22#include "ns3/device-energy-model-container.h"
23#include "ns3/double.h"
24#include "ns3/energy-source-container.h"
27#include "ns3/rv-battery-model-helper.h"
28#include "ns3/rv-battery-model.h"
29#include "ns3/simulator.h"
30#include "ns3/string.h"
31#include "ns3/wifi-radio-energy-model-helper.h"
32#include "ns3/wifi-radio-energy-model.h"
33#include "ns3/yans-wifi-helper.h"
89 std::vector<Time> timeStamps,
90 Time expLifetime)
const;
123 std::vector<double> loads;
124 std::vector<Time> timeStamps;
127 loads.push_back(0.628);
129 loads.push_back(0.628);
131 timeStamps.push_back(
Seconds(0));
132 timeStamps.push_back(
Seconds(19.5 * 60));
133 timeStamps.push_back(
Seconds(26.0 * 60));
135 profile.
loads = loads;
146 loads.push_back(0.4947);
148 loads.push_back(0.4947);
150 timeStamps.push_back(
Seconds(0));
151 timeStamps.push_back(
Seconds(31.0 * 60));
152 timeStamps.push_back(
Seconds(41.3 * 60));
154 profile.
loads = loads;
165 loads.push_back(0.4256);
167 loads.push_back(0.4256);
169 timeStamps.push_back(
Seconds(0));
170 timeStamps.push_back(
Seconds(41.0 * 60));
171 timeStamps.push_back(
Seconds(54.6 * 60));
173 profile.
loads = loads;
184 loads.push_back(0.2923);
186 loads.push_back(0.2923);
188 timeStamps.push_back(
Seconds(0));
189 timeStamps.push_back(
Seconds(74.6 * 60));
190 timeStamps.push_back(
Seconds(99.5 * 60));
192 profile.
loads = loads;
203 loads.push_back(0.2227);
205 loads.push_back(0.2227);
207 timeStamps.push_back(
Seconds(0));
208 timeStamps.push_back(
Seconds(105.7 * 60));
209 timeStamps.push_back(
Seconds(140.9 * 60));
211 profile.
loads = loads;
222 loads.push_back(0.628);
224 loads.push_back(0.628);
226 timeStamps.push_back(
Seconds(0));
227 timeStamps.push_back(
Seconds(19.5 * 60));
228 timeStamps.push_back(
Seconds(29.9 * 60));
230 profile.
loads = loads;
241 loads.push_back(0.628);
243 loads.push_back(0.628);
245 timeStamps.push_back(
Seconds(0));
246 timeStamps.push_back(
Seconds(19.5 * 60));
247 timeStamps.push_back(
Seconds(22.1 * 60));
249 profile.
loads = loads;
260 loads.push_back(0.628);
262 loads.push_back(0.628);
264 timeStamps.push_back(
Seconds(0));
265 timeStamps.push_back(
Seconds(23.4 * 60));
266 timeStamps.push_back(
Seconds(29.9 * 60));
268 profile.
loads = loads;
279 loads.push_back(0.628);
281 loads.push_back(0.628);
283 timeStamps.push_back(
Seconds(0));
284 timeStamps.push_back(
Seconds(15.6 * 60));
285 timeStamps.push_back(
Seconds(22.1 * 60));
287 profile.
loads = loads;
298 loads.push_back(0.300);
299 loads.push_back(0.628);
300 loads.push_back(0.4947);
301 loads.push_back(0.2523);
302 loads.push_back(0.2341);
303 loads.push_back(0.1379);
304 loads.push_back(0.1139);
305 loads.push_back(0.2656);
307 timeStamps.push_back(
Seconds(0));
308 timeStamps.push_back(
Seconds(0.5 * 60));
309 timeStamps.push_back(
Seconds(5.5 * 60));
310 timeStamps.push_back(
Seconds(10.5 * 60));
311 timeStamps.push_back(
Seconds(35.5 * 60));
312 timeStamps.push_back(
Seconds(60.5 * 60));
313 timeStamps.push_back(
Seconds(85.5 * 60));
314 timeStamps.push_back(
Seconds(110.5 * 60));
316 profile.
loads = loads;
327 loads.push_back(0.300);
328 loads.push_back(0.1139);
329 loads.push_back(0.1379);
330 loads.push_back(0.2341);
331 loads.push_back(0.2523);
332 loads.push_back(0.4947);
333 loads.push_back(0.628);
334 loads.push_back(0.2656);
336 timeStamps.push_back(
Seconds(0));
337 timeStamps.push_back(
Seconds(0.5 * 60));
338 timeStamps.push_back(
Seconds(25.5 * 60));
339 timeStamps.push_back(
Seconds(50.5 * 60));
340 timeStamps.push_back(
Seconds(75.5 * 60));
341 timeStamps.push_back(
Seconds(100.5 * 60));
342 timeStamps.push_back(
Seconds(105.5 * 60));
343 timeStamps.push_back(
Seconds(110.5 * 60));
345 profile.
loads = loads;
356 loads.push_back(0.300);
357 loads.push_back(0.1139);
358 loads.push_back(0.1379);
359 loads.push_back(0.2341);
360 loads.push_back(0.2523);
361 loads.push_back(0.4947);
362 loads.push_back(0.0);
363 loads.push_back(0.300);
364 loads.push_back(0.628);
365 loads.push_back(0.2656);
367 timeStamps.push_back(
Seconds(0));
368 timeStamps.push_back(
Seconds(0.5 * 60));
369 timeStamps.push_back(
Seconds(25.5 * 60));
370 timeStamps.push_back(
Seconds(50.5 * 60));
371 timeStamps.push_back(
Seconds(75.5 * 60));
372 timeStamps.push_back(
Seconds(100.5 * 60));
373 timeStamps.push_back(
Seconds(105.5 * 60));
374 timeStamps.push_back(
Seconds(130.5 * 60));
375 timeStamps.push_back(
Seconds(131.0 * 60));
376 timeStamps.push_back(
Seconds(136.0 * 60));
378 profile.
loads = loads;
389 loads.push_back(0.300);
390 timeStamps.push_back(
Seconds(0));
392 for (
int i = 0; i < 5; i++)
394 loads.push_back(0.628);
395 loads.push_back(0.4947);
396 loads.push_back(0.2523);
397 loads.push_back(0.2341);
398 loads.push_back(0.1379);
399 loads.push_back(0.1139);
401 timeStamps.push_back(
Seconds((0.5 + i * 22.5) * 60));
402 timeStamps.push_back(
Seconds((1.5 + i * 22.5) * 60));
403 timeStamps.push_back(
Seconds((2.5 + i * 22.5) * 60));
404 timeStamps.push_back(
Seconds((7.5 + i * 22.5) * 60));
405 timeStamps.push_back(
Seconds((12.5 + i * 22.5) * 60));
406 timeStamps.push_back(
Seconds((17.5 + i * 22.5) * 60));
409 loads.push_back(0.2656);
410 timeStamps.push_back(
Seconds(110.5 * 60));
412 profile.
loads = loads;
423 loads.push_back(0.300);
424 timeStamps.push_back(
Seconds(0));
426 for (
int i = 0; i < 5; i++)
428 loads.push_back(0.1139);
429 loads.push_back(0.1379);
430 loads.push_back(0.2341);
431 loads.push_back(0.2523);
432 loads.push_back(0.4947);
433 loads.push_back(0.628);
435 timeStamps.push_back(
Seconds((0.5 + i * 22.5) * 60));
436 timeStamps.push_back(
Seconds((5.5 + i * 22.5) * 60));
437 timeStamps.push_back(
Seconds((10.5 + i * 22.5) * 60));
438 timeStamps.push_back(
Seconds((15.5 + i * 22.5) * 60));
439 timeStamps.push_back(
Seconds((20.5 + i * 22.5) * 60));
440 timeStamps.push_back(
Seconds((21.5 + i * 22.5) * 60));
443 loads.push_back(0.2656);
444 timeStamps.push_back(
Seconds(112.5 * 60));
446 profile.
loads = loads;
457 loads.push_back(0.2227);
458 loads.push_back(0.2045);
459 loads.push_back(0.1083);
460 loads.push_back(0.0843);
461 loads.push_back(0.2227);
463 timeStamps.push_back(
Seconds(0));
464 timeStamps.push_back(
Seconds(50.0 * 60));
465 timeStamps.push_back(
Seconds(100.0 * 60));
466 timeStamps.push_back(
Seconds(150.0 * 60));
467 timeStamps.push_back(
Seconds(200.0 * 60));
469 profile.
loads = loads;
480 loads.push_back(0.0843);
481 loads.push_back(0.1083);
482 loads.push_back(0.2045);
483 loads.push_back(0.2227);
484 loads.push_back(0.2227);
486 timeStamps.push_back(
Seconds(0));
487 timeStamps.push_back(
Seconds(50.0 * 60));
488 timeStamps.push_back(
Seconds(100.0 * 60));
489 timeStamps.push_back(
Seconds(150.0 * 60));
490 timeStamps.push_back(
Seconds(200.0 * 60));
492 profile.
loads = loads;
503 loads.push_back(0.0843);
504 loads.push_back(0.1083);
505 loads.push_back(0.2045);
506 loads.push_back(0.0);
507 loads.push_back(0.2227);
508 loads.push_back(0.2227);
510 timeStamps.push_back(
Seconds(0));
511 timeStamps.push_back(
Seconds(50.0 * 60));
512 timeStamps.push_back(
Seconds(100.0 * 60));
513 timeStamps.push_back(
Seconds(150.0 * 60));
514 timeStamps.push_back(
Seconds(200.0 * 60));
515 timeStamps.push_back(
Seconds(250.0 * 60));
517 profile.
loads = loads;
528 for (
int i = 0; i < 10; i++)
530 loads.push_back(0.0843);
531 loads.push_back(0.1083);
532 loads.push_back(0.2045);
533 loads.push_back(0.2227);
535 timeStamps.push_back(
Seconds((0.0 + i * 20.0) * 60));
536 timeStamps.push_back(
Seconds((5.0 + i * 20.0) * 60));
537 timeStamps.push_back(
Seconds((10.0 + i * 20.0) * 60));
538 timeStamps.push_back(
Seconds((15.0 + i * 20.0) * 60));
541 loads.push_back(0.2227);
542 timeStamps.push_back(
Seconds(200.0));
544 profile.
loads = loads;
555 for (
int i = 0; i < 10; i++)
557 loads.push_back(0.0755);
558 loads.push_back(0.0949);
559 loads.push_back(0.2045);
560 loads.push_back(0.2227);
562 timeStamps.push_back(
Seconds((0.0 + i * 20.0) * 60));
563 timeStamps.push_back(
Seconds((5.0 + i * 20.0) * 60));
564 timeStamps.push_back(
Seconds((10.0 + i * 20.0) * 60));
565 timeStamps.push_back(
Seconds((15.0 + i * 20.0) * 60));
568 loads.push_back(0.2227);
569 timeStamps.push_back(
Seconds(200.0));
571 profile.
loads = loads;
582 for (
int i = 0; i < 50; i++)
584 loads.push_back(0.4947);
585 loads.push_back(0.628);
587 timeStamps.push_back(
Seconds((0.0 + i * 2.0) * 60));
588 timeStamps.push_back(
Seconds((1.0 + i * 2.0) * 60));
591 profile.
loads = loads;
602 for (
int i = 0; i < 50; i++)
604 loads.push_back(0.4947);
605 loads.push_back(0.628);
606 loads.push_back(0.0576);
608 timeStamps.push_back(
Seconds((0.0 + i * 3.0) * 60));
609 timeStamps.push_back(
Seconds((1.0 + i * 3.0) * 60));
610 timeStamps.push_back(
Seconds((2.0 + i * 3.0) * 60));
613 profile.
loads = loads;
624 for (
int i = 0; i < 150; i++)
626 loads.push_back(0.005 + 0.005 * i);
627 timeStamps.push_back(
Seconds((0.0 + i * 1.0) * 60));
630 profile.
loads = loads;
642main(
int argc,
char** argv)
645 cmd.Parse(argc, argv);
655 std::cerr <<
"Problems with constant load test (640mA)." << std::endl;
660 std::cerr <<
"Problems with constant load test (320mA)." << std::endl;
662 if (
test.ConstantLoadTest(0.128,
Seconds(16052.0)))
665 std::cerr <<
"Problems with constant load test (128mA)." << std::endl;
667 if (
test.ConstantLoadTest(0.064,
Seconds(32561.0)))
670 std::cerr <<
"Problems with constant load test (64mA)." << std::endl;
672 if (
test.ConstantLoadTest(0.032,
Seconds(65580.0)))
675 std::cerr <<
"Problems with constant load test (32mA)." << std::endl;
679 test.CreateLoadProfiles();
683 test.m_alpha = 35220;
685 for (
uint32_t i = 0; i <
test.m_loadProfiles.size(); i++)
689 if (
test.VariableLoadTest(
test.m_loadProfiles[i].loads,
690 test.m_loadProfiles[i].timeStamps,
691 test.m_loadProfiles[i].itsyLifetime))
694 std::cerr <<
"Problems with variable load test (Itsy)." << std::endl;
700 test.m_alpha = 40027;
702 for (
uint32_t i = 0; i <
test.m_loadProfiles.size(); i++)
706 if (
test.VariableLoadTest(
test.m_loadProfiles[i].loads,
707 test.m_loadProfiles[i].timeStamps,
708 test.m_loadProfiles[i].dualFoilLifeTime))
711 std::cerr <<
"Problems with variable load test (DUALFOIL)." << std::endl;
725 std::string phyMode(
"DsssRate1Mbps");
754 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
760 wifiMac.
SetType(
"ns3::AdhocWifiMac");
769 rvModelHelper.
Set(
"RvBatteryModelLowBatteryThreshold",
DoubleValue(0.0));
785 actualLifetime = srcPtr->GetLifetime();
792 if (actualLifetime != expLifetime)
794 std::cerr <<
"ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
803 std::vector<Time> timeStamps,
804 Time expLifetime)
const
806 NS_ASSERT(loads.size() == timeStamps.size());
812 std::string phyMode(
"DsssRate1Mbps");
841 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
847 wifiMac.
SetType(
"ns3::AdhocWifiMac");
856 rvModelHelper.
Set(
"RvBatteryModelLowBatteryThreshold",
DoubleValue(0.0));
867 DynamicCast<WifiRadioEnergyModel>(deviceModels.
Get(0));
869 for (
uint32_t i = 1; i < loads.size(); i++)
883 actualLifetime = srcPtr->GetLifetime();
892 if (
Abs(actualLifetime - expLifetime) >
Seconds(120))
894 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(double idleCurrentA)
Sets idle current in Amperes.
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.
-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.