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/string.h"
33 #include "ns3/yans-wifi-helper.h"
63 void CreateLoadProfiles (
void);
73 bool ConstantLoadTest (
double load,
Time expLifetime);
84 bool VariableLoadTest (std::vector<double> loads,
85 std::vector<Time> timeStamps,
118 std::vector<double> loads;
119 std::vector<Time> timeStamps;
122 loads.push_back (0.628);
124 loads.push_back (0.628);
126 timeStamps.push_back (
Seconds (0));
127 timeStamps.push_back (
Seconds (19.5 * 60));
128 timeStamps.push_back (
Seconds (26.0 * 60));
130 profile.
loads = loads;
135 m_loadProfiles.push_back (profile);
141 loads.push_back (0.4947);
143 loads.push_back (0.4947);
145 timeStamps.push_back (
Seconds (0));
146 timeStamps.push_back (
Seconds (31.0 * 60));
147 timeStamps.push_back (
Seconds (41.3 * 60));
149 profile.
loads = loads;
154 m_loadProfiles.push_back (profile);
160 loads.push_back (0.4256);
162 loads.push_back (0.4256);
164 timeStamps.push_back (
Seconds (0));
165 timeStamps.push_back (
Seconds (41.0 * 60));
166 timeStamps.push_back (
Seconds (54.6 * 60));
168 profile.
loads = loads;
173 m_loadProfiles.push_back (profile);
179 loads.push_back (0.2923);
181 loads.push_back (0.2923);
183 timeStamps.push_back (
Seconds (0));
184 timeStamps.push_back (
Seconds (74.6 * 60));
185 timeStamps.push_back (
Seconds (99.5 * 60));
187 profile.
loads = loads;
192 m_loadProfiles.push_back (profile);
198 loads.push_back (0.2227);
200 loads.push_back (0.2227);
202 timeStamps.push_back (
Seconds (0));
203 timeStamps.push_back (
Seconds (105.7 * 60));
204 timeStamps.push_back (
Seconds (140.9 * 60));
206 profile.
loads = loads;
211 m_loadProfiles.push_back (profile);
217 loads.push_back (0.628);
219 loads.push_back (0.628);
221 timeStamps.push_back (
Seconds (0));
222 timeStamps.push_back (
Seconds (19.5 * 60));
223 timeStamps.push_back (
Seconds (29.9 * 60));
225 profile.
loads = loads;
230 m_loadProfiles.push_back (profile);
236 loads.push_back (0.628);
238 loads.push_back (0.628);
240 timeStamps.push_back (
Seconds (0));
241 timeStamps.push_back (
Seconds (19.5 * 60));
242 timeStamps.push_back (
Seconds (22.1 * 60));
244 profile.
loads = loads;
249 m_loadProfiles.push_back (profile);
255 loads.push_back (0.628);
257 loads.push_back (0.628);
259 timeStamps.push_back (
Seconds (0));
260 timeStamps.push_back (
Seconds (23.4 * 60));
261 timeStamps.push_back (
Seconds (29.9 * 60));
263 profile.
loads = loads;
268 m_loadProfiles.push_back (profile);
274 loads.push_back (0.628);
276 loads.push_back (0.628);
278 timeStamps.push_back (
Seconds (0));
279 timeStamps.push_back (
Seconds (15.6 * 60));
280 timeStamps.push_back (
Seconds (22.1 * 60));
282 profile.
loads = loads;
287 m_loadProfiles.push_back (profile);
293 loads.push_back (0.300);
294 loads.push_back (0.628);
295 loads.push_back (0.4947);
296 loads.push_back (0.2523);
297 loads.push_back (0.2341);
298 loads.push_back (0.1379);
299 loads.push_back (0.1139);
300 loads.push_back (0.2656);
302 timeStamps.push_back (
Seconds (0));
303 timeStamps.push_back (
Seconds (0.5 * 60));
304 timeStamps.push_back (
Seconds (5.5 * 60));
305 timeStamps.push_back (
Seconds (10.5 * 60));
306 timeStamps.push_back (
Seconds (35.5 * 60));
307 timeStamps.push_back (
Seconds (60.5 * 60));
308 timeStamps.push_back (
Seconds (85.5 * 60));
309 timeStamps.push_back (
Seconds (110.5 * 60));
311 profile.
loads = loads;
316 m_loadProfiles.push_back (profile);
322 loads.push_back (0.300);
323 loads.push_back (0.1139);
324 loads.push_back (0.1379);
325 loads.push_back (0.2341);
326 loads.push_back (0.2523);
327 loads.push_back (0.4947);
328 loads.push_back (0.628);
329 loads.push_back (0.2656);
331 timeStamps.push_back (
Seconds (0));
332 timeStamps.push_back (
Seconds (0.5 * 60));
333 timeStamps.push_back (
Seconds (25.5 * 60));
334 timeStamps.push_back (
Seconds (50.5 * 60));
335 timeStamps.push_back (
Seconds (75.5 * 60));
336 timeStamps.push_back (
Seconds (100.5 * 60));
337 timeStamps.push_back (
Seconds (105.5 * 60));
338 timeStamps.push_back (
Seconds (110.5 * 60));
340 profile.
loads = loads;
345 m_loadProfiles.push_back (profile);
351 loads.push_back (0.300);
352 loads.push_back (0.1139);
353 loads.push_back (0.1379);
354 loads.push_back (0.2341);
355 loads.push_back (0.2523);
356 loads.push_back (0.4947);
357 loads.push_back (0.0);
358 loads.push_back (0.300);
359 loads.push_back (0.628);
360 loads.push_back (0.2656);
362 timeStamps.push_back (
Seconds (0));
363 timeStamps.push_back (
Seconds (0.5 * 60));
364 timeStamps.push_back (
Seconds (25.5 * 60));
365 timeStamps.push_back (
Seconds (50.5 * 60));
366 timeStamps.push_back (
Seconds (75.5 * 60));
367 timeStamps.push_back (
Seconds (100.5 * 60));
368 timeStamps.push_back (
Seconds (105.5 * 60));
369 timeStamps.push_back (
Seconds (130.5 * 60));
370 timeStamps.push_back (
Seconds (131.0 * 60));
371 timeStamps.push_back (
Seconds (136.0 * 60));
373 profile.
loads = loads;
378 m_loadProfiles.push_back (profile);
384 loads.push_back (0.300);
385 timeStamps.push_back (
Seconds (0));
387 for (
int i = 0; i < 5; i++)
389 loads.push_back (0.628);
390 loads.push_back (0.4947);
391 loads.push_back (0.2523);
392 loads.push_back (0.2341);
393 loads.push_back (0.1379);
394 loads.push_back (0.1139);
396 timeStamps.push_back (
Seconds ((0.5 + i * 22.5) * 60));
397 timeStamps.push_back (
Seconds ((1.5 + i * 22.5) * 60));
398 timeStamps.push_back (
Seconds ((2.5 + i * 22.5) * 60));
399 timeStamps.push_back (
Seconds ((7.5 + i * 22.5) * 60));
400 timeStamps.push_back (
Seconds ((12.5 + i * 22.5) * 60));
401 timeStamps.push_back (
Seconds ((17.5 + i * 22.5) * 60));
404 loads.push_back (0.2656);
405 timeStamps.push_back (
Seconds (110.5 * 60));
407 profile.
loads = loads;
412 m_loadProfiles.push_back (profile);
418 loads.push_back (0.300);
419 timeStamps.push_back (
Seconds (0));
421 for (
int i = 0; i < 5; i++)
423 loads.push_back (0.1139);
424 loads.push_back (0.1379);
425 loads.push_back (0.2341);
426 loads.push_back (0.2523);
427 loads.push_back (0.4947);
428 loads.push_back (0.628);
430 timeStamps.push_back (
Seconds ((0.5 + i * 22.5) * 60));
431 timeStamps.push_back (
Seconds ((5.5 + i * 22.5) * 60));
432 timeStamps.push_back (
Seconds ((10.5 + i * 22.5) * 60));
433 timeStamps.push_back (
Seconds ((15.5 + i * 22.5) * 60));
434 timeStamps.push_back (
Seconds ((20.5 + i * 22.5) * 60));
435 timeStamps.push_back (
Seconds ((21.5 + i * 22.5) * 60));
438 loads.push_back (0.2656);
439 timeStamps.push_back (
Seconds (112.5 * 60));
441 profile.
loads = loads;
446 m_loadProfiles.push_back (profile);
452 loads.push_back (0.2227);
453 loads.push_back (0.2045);
454 loads.push_back (0.1083);
455 loads.push_back (0.0843);
456 loads.push_back (0.2227);
458 timeStamps.push_back (
Seconds (0));
459 timeStamps.push_back (
Seconds (50.0 * 60));
460 timeStamps.push_back (
Seconds (100.0 * 60));
461 timeStamps.push_back (
Seconds (150.0 * 60));
462 timeStamps.push_back (
Seconds (200.0 * 60));
464 profile.
loads = loads;
469 m_loadProfiles.push_back (profile);
475 loads.push_back (0.0843);
476 loads.push_back (0.1083);
477 loads.push_back (0.2045);
478 loads.push_back (0.2227);
479 loads.push_back (0.2227);
481 timeStamps.push_back (
Seconds (0));
482 timeStamps.push_back (
Seconds (50.0 * 60));
483 timeStamps.push_back (
Seconds (100.0 * 60));
484 timeStamps.push_back (
Seconds (150.0 * 60));
485 timeStamps.push_back (
Seconds (200.0 * 60));
487 profile.
loads = loads;
492 m_loadProfiles.push_back (profile);
498 loads.push_back (0.0843);
499 loads.push_back (0.1083);
500 loads.push_back (0.2045);
501 loads.push_back (0.0);
502 loads.push_back (0.2227);
503 loads.push_back (0.2227);
505 timeStamps.push_back (
Seconds (0));
506 timeStamps.push_back (
Seconds (50.0 * 60));
507 timeStamps.push_back (
Seconds (100.0 * 60));
508 timeStamps.push_back (
Seconds (150.0 * 60));
509 timeStamps.push_back (
Seconds (200.0 * 60));
510 timeStamps.push_back (
Seconds (250.0 * 60));
512 profile.
loads = loads;
517 m_loadProfiles.push_back (profile);
523 for (
int i = 0; i < 10; i++)
525 loads.push_back (0.0843);
526 loads.push_back (0.1083);
527 loads.push_back (0.2045);
528 loads.push_back (0.2227);
530 timeStamps.push_back (
Seconds ((0.0 + i * 20.0) * 60));
531 timeStamps.push_back (
Seconds ((5.0 + i * 20.0) * 60));
532 timeStamps.push_back (
Seconds ((10.0 + i * 20.0) * 60));
533 timeStamps.push_back (
Seconds ((15.0 + i * 20.0) * 60));
536 loads.push_back (0.2227);
537 timeStamps.push_back (
Seconds (200.0));
539 profile.
loads = loads;
544 m_loadProfiles.push_back (profile);
550 for (
int i = 0; i < 10; i++)
552 loads.push_back (0.0755);
553 loads.push_back (0.0949);
554 loads.push_back (0.2045);
555 loads.push_back (0.2227);
557 timeStamps.push_back (
Seconds ((0.0 + i * 20.0) * 60));
558 timeStamps.push_back (
Seconds ((5.0 + i * 20.0) * 60));
559 timeStamps.push_back (
Seconds ((10.0 + i * 20.0) * 60));
560 timeStamps.push_back (
Seconds ((15.0 + i * 20.0) * 60));
563 loads.push_back (0.2227);
564 timeStamps.push_back (
Seconds (200.0));
566 profile.
loads = loads;
571 m_loadProfiles.push_back (profile);
577 for (
int i = 0; i < 50; i++)
579 loads.push_back (0.4947);
580 loads.push_back (0.628);
582 timeStamps.push_back (
Seconds ((0.0 + i * 2.0) * 60));
583 timeStamps.push_back (
Seconds ((1.0 + i * 2.0) * 60));
586 profile.
loads = loads;
591 m_loadProfiles.push_back (profile);
597 for (
int i = 0; i < 50; i++)
599 loads.push_back (0.4947);
600 loads.push_back (0.628);
601 loads.push_back (0.0576);
603 timeStamps.push_back (
Seconds ((0.0 + i * 3.0) * 60));
604 timeStamps.push_back (
Seconds ((1.0 + i * 3.0) * 60));
605 timeStamps.push_back (
Seconds ((2.0 + i * 3.0) * 60));
608 profile.
loads = loads;
613 m_loadProfiles.push_back (profile);
619 for (
int i = 0; i < 150; i++)
621 loads.push_back (0.005 + 0.005 * i);
622 timeStamps.push_back (
Seconds ((0.0 + i * 1.0) * 60));
625 profile.
loads = loads;
630 m_loadProfiles.push_back (profile);
637 main (
int argc,
char **argv)
647 std::cerr <<
"Problems with constant load test (640mA)." << std::endl;
652 std::cerr <<
"Problems with constant load test (320mA)." << std::endl;
657 std::cerr <<
"Problems with constant load test (128mA)." << std::endl;
662 std::cerr <<
"Problems with constant load test (64mA)." << std::endl;
667 std::cerr <<
"Problems with constant load test (32mA)." << std::endl;
686 std::cerr <<
"Problems with variable load test (Itsy)." << std::endl;
703 std::cerr <<
"Problems with variable load test (DUALFOIL)." << std::endl;
717 std::string phyMode (
"DsssRate1Mbps");
752 wifiMac.
SetType (
"ns3::AdhocWifiMac");
759 rvModelHelper.
Set (
"RvBatteryModelAlphaValue",
DoubleValue (m_alpha));
760 rvModelHelper.
Set (
"RvBatteryModelBetaValue",
DoubleValue (m_beta));
761 rvModelHelper.
Set (
"RvBatteryModelLowBatteryThreshold",
DoubleValue (0.0));
780 NS_LOG_DEBUG (
"Actual lifetime = " << actualLifetime.GetSeconds () <<
"s");
784 if (actualLifetime != expLifetime)
786 std::cerr <<
"ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
795 std::vector<Time> timeStamps,
798 NS_ASSERT (loads.size () == timeStamps.size ());
804 std::string phyMode (
"DsssRate1Mbps");
839 wifiMac.
SetType (
"ns3::AdhocWifiMac");
846 rvModelHelper.
Set (
"RvBatteryModelAlphaValue",
DoubleValue (m_alpha));
847 rvModelHelper.
Set (
"RvBatteryModelBetaValue",
DoubleValue (m_beta));
848 rvModelHelper.
Set (
"RvBatteryModelLowBatteryThreshold",
DoubleValue (0.0));
861 for (uint32_t i = 1; i < loads.size (); i++)
864 wifiDevicePtr, loads[i]);
876 NS_LOG_DEBUG (
"Actual lifetime = " << actualLifetime.GetSeconds () <<
"s");
882 if ((actualLifetime.GetSeconds ()) > (expLifetime.
GetSeconds ()) + (120) ||
883 (actualLifetime.GetSeconds ()) < (expLifetime.
GetSeconds ()) - (120))
885 std::cerr <<
"VariableLoadTest: Incorrect lifetime." << std::endl;
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
Simulation virtual time values and global simulation resolution.
Assign WifiRadioEnergyModel to wifi devices.
Smart pointer class similar to boost::intrusive_ptr.
Holds a vector of ns3::EnergySource pointers.
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.
std::vector< LoadProfile > m_loadProfiles
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
std::vector< double > loads
helps to create WifiNetDevice objects
Include Radiotap link layer information.
Holds a vector of ns3::DeviceEnergyModel pointers.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
void CreateLoadProfiles(void)
Creates load profiles according to D.
void SetChannel(Ptr< YansWifiChannel > channel)
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
std::vector< Time > timeStamps
Time GetLifetime(void) const
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
bool ConstantLoadTest(double load, Time expLifetime)
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Creates a RvBatteryModel object.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr stored in this container.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void Set(std::string name, const AttributeValue &v)
EnergySourceContainer Install(Ptr< Node > node) const
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
void Set(std::string name, const AttributeValue &v)
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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr stored in this container.
This example was originally devised as a test, then it was converted to an example.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
#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.
void SetDefault(std::string name, const AttributeValue &value)
virtual ~BatteryLifetimeTest()
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())
This class can be used to hold variables of floating point type such as 'double' or 'float'...
bool VariableLoadTest(std::vector< double > loads, std::vector< Time > timeStamps, Time expLifetime)
void test(void)
Example use of ns3::SystemThread.
void SetIdleCurrentA(double idleCurrentA)