A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rv-battery-model-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: He Wu <mdzz@u.washington.edu>
19  */
20 
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"
27 #include "ns3/log.h"
28 #include "ns3/node.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"
34 #include <cmath>
35 
36 using namespace ns3;
37 
38 NS_LOG_COMPONENT_DEFINE ("RvBatteryModelTestSuite");
39 
52 {
53 public:
55  virtual ~BatteryLifetimeTest ();
56 
63  void CreateLoadProfiles (void);
64 
73  bool ConstantLoadTest (double load, Time expLifetime);
74 
84  bool VariableLoadTest (std::vector<double> loads,
85  std::vector<Time> timeStamps,
86  Time expLifetime);
87 
88  typedef struct LoadProfile
89  {
90  std::vector<double> loads;
91  std::vector<Time> timeStamps;
94  } LoadProfile;
95 
96  std::vector<LoadProfile> m_loadProfiles;
97  double m_alpha;
98  double m_beta;
99 };
100 
102 {
103  // Itsy battery
104  m_alpha = 35220;
105  m_beta = 0.637;
106 }
107 
109 {
110 }
111 
112 void
114 {
115  // create set of load profiles
116  LoadProfile profile;
117 
118  std::vector<double> loads;
119  std::vector<Time> timeStamps;
120 
121  // C1
122  loads.push_back (0.628);
123  loads.push_back (0);
124  loads.push_back (0.628);
125 
126  timeStamps.push_back (Seconds (0));
127  timeStamps.push_back (Seconds (19.5 * 60));
128  timeStamps.push_back (Seconds (26.0 * 60));
129 
130  profile.loads = loads;
131  profile.timeStamps = timeStamps;
132  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
133  profile.dualFoilLifeTime = Seconds (36.2 * 60); // 36.2 minutes
134 
135  m_loadProfiles.push_back (profile);
136 
137  loads.clear ();
138  timeStamps.clear ();
139 
140  // C2
141  loads.push_back (0.4947);
142  loads.push_back (0);
143  loads.push_back (0.4947);
144 
145  timeStamps.push_back (Seconds (0));
146  timeStamps.push_back (Seconds (31.0 * 60));
147  timeStamps.push_back (Seconds (41.3 * 60));
148 
149  profile.loads = loads;
150  profile.timeStamps = timeStamps;
151  profile.itsyLifetime = Seconds (73.9 * 60); // 73.9 minutes
152  profile.dualFoilLifeTime = Seconds (55.8 * 60); // 55.8 minutes
153 
154  m_loadProfiles.push_back (profile);
155 
156  loads.clear ();
157  timeStamps.clear ();
158 
159  // C3
160  loads.push_back (0.4256);
161  loads.push_back (0);
162  loads.push_back (0.4256);
163 
164  timeStamps.push_back (Seconds (0));
165  timeStamps.push_back (Seconds (41.0 * 60));
166  timeStamps.push_back (Seconds (54.6 * 60));
167 
168  profile.loads = loads;
169  profile.timeStamps = timeStamps;
170  profile.itsyLifetime = Seconds (88.8 * 60); // 88.8 minutes
171  profile.dualFoilLifeTime = Seconds (71.8 * 60); // 71.8 minutes
172 
173  m_loadProfiles.push_back (profile);
174 
175  loads.clear ();
176  timeStamps.clear ();
177 
178  // C4
179  loads.push_back (0.2923);
180  loads.push_back (0);
181  loads.push_back (0.2923);
182 
183  timeStamps.push_back (Seconds (0));
184  timeStamps.push_back (Seconds (74.6 * 60));
185  timeStamps.push_back (Seconds (99.5 * 60));
186 
187  profile.loads = loads;
188  profile.timeStamps = timeStamps;
189  profile.itsyLifetime = Seconds (137.8 * 60); // 137.8 minutes
190  profile.dualFoilLifeTime = Seconds (124.9 * 60); // 124.9 minutes
191 
192  m_loadProfiles.push_back (profile);
193 
194  loads.clear ();
195  timeStamps.clear ();
196 
197  // C5
198  loads.push_back (0.2227);
199  loads.push_back (0);
200  loads.push_back (0.2227);
201 
202  timeStamps.push_back (Seconds (0));
203  timeStamps.push_back (Seconds (105.7 * 60));
204  timeStamps.push_back (Seconds (140.9 * 60));
205 
206  profile.loads = loads;
207  profile.timeStamps = timeStamps;
208  profile.itsyLifetime = Seconds (185.8 * 60); // 185.8 minutes
209  profile.dualFoilLifeTime = Seconds (176.7 * 60); // 176.7 minutes
210 
211  m_loadProfiles.push_back (profile);
212 
213  loads.clear ();
214  timeStamps.clear ();
215 
216  // C6
217  loads.push_back (0.628);
218  loads.push_back (0);
219  loads.push_back (0.628);
220 
221  timeStamps.push_back (Seconds (0));
222  timeStamps.push_back (Seconds (19.5 * 60));
223  timeStamps.push_back (Seconds (29.9 * 60));
224 
225  profile.loads = loads;
226  profile.timeStamps = timeStamps;
227  profile.itsyLifetime = Seconds (58.9 * 60); // 58.9 minutes
228  profile.dualFoilLifeTime = Seconds (41.0 * 60); // 41.0 minutes
229 
230  m_loadProfiles.push_back (profile);
231 
232  loads.clear ();
233  timeStamps.clear ();
234 
235  // C7
236  loads.push_back (0.628);
237  loads.push_back (0);
238  loads.push_back (0.628);
239 
240  timeStamps.push_back (Seconds (0));
241  timeStamps.push_back (Seconds (19.5 * 60));
242  timeStamps.push_back (Seconds (22.1 * 60));
243 
244  profile.loads = loads;
245  profile.timeStamps = timeStamps;
246  profile.itsyLifetime = Seconds (51.1 * 60); // 51.1 minutes
247  profile.dualFoilLifeTime = Seconds (30.8 * 60); // 30.8 minutes
248 
249  m_loadProfiles.push_back (profile);
250 
251  loads.clear ();
252  timeStamps.clear ();
253 
254  // C8
255  loads.push_back (0.628);
256  loads.push_back (0);
257  loads.push_back (0.628);
258 
259  timeStamps.push_back (Seconds (0));
260  timeStamps.push_back (Seconds (23.4 * 60));
261  timeStamps.push_back (Seconds (29.9 * 60));
262 
263  profile.loads = loads;
264  profile.timeStamps = timeStamps;
265  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
266  profile.dualFoilLifeTime = Seconds (37.4 * 60); // 37.4 minutes
267 
268  m_loadProfiles.push_back (profile);
269 
270  loads.clear ();
271  timeStamps.clear ();
272 
273  // C9
274  loads.push_back (0.628);
275  loads.push_back (0);
276  loads.push_back (0.628);
277 
278  timeStamps.push_back (Seconds (0));
279  timeStamps.push_back (Seconds (15.6 * 60));
280  timeStamps.push_back (Seconds (22.1 * 60));
281 
282  profile.loads = loads;
283  profile.timeStamps = timeStamps;
284  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
285  profile.dualFoilLifeTime = Seconds (35.2 * 60); // 35.2 minutes
286 
287  m_loadProfiles.push_back (profile);
288 
289  loads.clear ();
290  timeStamps.clear ();
291 
292  // C10
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);
301 
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));
310 
311  profile.loads = loads;
312  profile.timeStamps = timeStamps;
313  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
314  profile.dualFoilLifeTime = Seconds (132.6 * 60); // 132.6 minutes
315 
316  m_loadProfiles.push_back (profile);
317 
318  loads.clear ();
319  timeStamps.clear ();
320 
321  // C11
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);
330 
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));
339 
340  profile.loads = loads;
341  profile.timeStamps = timeStamps;
342  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
343  profile.dualFoilLifeTime = Seconds (107.4 * 60); // 107.4 minutes
344 
345  m_loadProfiles.push_back (profile);
346 
347  loads.clear ();
348  timeStamps.clear ();
349 
350  // C12
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);
361 
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));
372 
373  profile.loads = loads;
374  profile.timeStamps = timeStamps;
375  profile.itsyLifetime = Seconds (169.3 * 60); // 169.3 minutes
376  profile.dualFoilLifeTime = Seconds (155.4 * 60); // 155.4 minutes
377 
378  m_loadProfiles.push_back (profile);
379 
380  loads.clear ();
381  timeStamps.clear ();
382 
383  // C13
384  loads.push_back (0.300);
385  timeStamps.push_back (Seconds (0));
386 
387  for (int i = 0; i < 5; i++)
388  {
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);
395 
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));
402  }
403 
404  loads.push_back (0.2656);
405  timeStamps.push_back (Seconds (110.5 * 60));
406 
407  profile.loads = loads;
408  profile.timeStamps = timeStamps;
409  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
410  profile.dualFoilLifeTime = Seconds (131.7 * 60); // 131.7 minutes
411 
412  m_loadProfiles.push_back (profile);
413 
414  loads.clear ();
415  timeStamps.clear ();
416 
417  // C14, time stamp calculation in paper is off, using our own estimated value
418  loads.push_back (0.300);
419  timeStamps.push_back (Seconds (0));
420 
421  for (int i = 0; i < 5; i++)
422  {
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);
429 
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));
436  }
437 
438  loads.push_back (0.2656);
439  timeStamps.push_back (Seconds (112.5 * 60));
440 
441  profile.loads = loads;
442  profile.timeStamps = timeStamps;
443  profile.itsyLifetime = Seconds (141.5 * 60); // 141.5 minutes
444  profile.dualFoilLifeTime = Seconds (126.3 * 60); // 126.3 minutes
445 
446  m_loadProfiles.push_back (profile);
447 
448  loads.clear ();
449  timeStamps.clear ();
450 
451  // C15
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);
457 
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));
463 
464  profile.loads = loads;
465  profile.timeStamps = timeStamps;
466  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
467  profile.dualFoilLifeTime = Seconds (209.2 * 60); // 209.2 minutes
468 
469  m_loadProfiles.push_back (profile);
470 
471  loads.clear ();
472  timeStamps.clear ();
473 
474  // C16
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);
480 
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));
486 
487  profile.loads = loads;
488  profile.timeStamps = timeStamps;
489  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
490  profile.dualFoilLifeTime = Seconds (200.7 * 60); // 200.7 minutes
491 
492  m_loadProfiles.push_back (profile);
493 
494  loads.clear ();
495  timeStamps.clear ();
496 
497  // C17
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);
504 
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));
511 
512  profile.loads = loads;
513  profile.timeStamps = timeStamps;
514  profile.itsyLifetime = Seconds (261.4 * 60); // 261.4 minutes
515  profile.dualFoilLifeTime = Seconds (251.2 * 60); // 251.2 minutes
516 
517  m_loadProfiles.push_back (profile);
518 
519  loads.clear ();
520  timeStamps.clear ();
521 
522  // C18
523  for (int i = 0; i < 10; i++)
524  {
525  loads.push_back (0.0843);
526  loads.push_back (0.1083);
527  loads.push_back (0.2045);
528  loads.push_back (0.2227);
529 
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));
534  }
535 
536  loads.push_back (0.2227);
537  timeStamps.push_back (Seconds (200.0));
538 
539  profile.loads = loads;
540  profile.timeStamps = timeStamps;
541  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
542  profile.dualFoilLifeTime = Seconds (204.6 * 60); // 204.6 minutes
543 
544  m_loadProfiles.push_back (profile);
545 
546  loads.clear ();
547  timeStamps.clear ();
548 
549  // C19
550  for (int i = 0; i < 10; i++)
551  {
552  loads.push_back (0.0755);
553  loads.push_back (0.0949);
554  loads.push_back (0.2045);
555  loads.push_back (0.2227);
556 
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));
561  }
562 
563  loads.push_back (0.2227);
564  timeStamps.push_back (Seconds (200.0));
565 
566  profile.loads = loads;
567  profile.timeStamps = timeStamps;
568  profile.itsyLifetime = Seconds (216.4 * 60); // 216.4 minutes
569  profile.dualFoilLifeTime = Seconds (208.7 * 60); // 208.7 minutes
570 
571  m_loadProfiles.push_back (profile);
572 
573  loads.clear ();
574  timeStamps.clear ();
575 
576  // C20
577  for (int i = 0; i < 50; i++)
578  {
579  loads.push_back (0.4947);
580  loads.push_back (0.628);
581 
582  timeStamps.push_back (Seconds ((0.0 + i * 2.0) * 60));
583  timeStamps.push_back (Seconds ((1.0 + i * 2.0) * 60));
584  }
585 
586  profile.loads = loads;
587  profile.timeStamps = timeStamps;
588  profile.itsyLifetime = Seconds (55.3 * 60); // 55.3 minutes
589  profile.dualFoilLifeTime = Seconds (33.2 * 60); // 33.2 minutes
590 
591  m_loadProfiles.push_back (profile);
592 
593  loads.clear ();
594  timeStamps.clear ();
595 
596  // C21
597  for (int i = 0; i < 50; i++)
598  {
599  loads.push_back (0.4947);
600  loads.push_back (0.628);
601  loads.push_back (0.0576);
602 
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));
606  }
607 
608  profile.loads = loads;
609  profile.timeStamps = timeStamps;
610  profile.itsyLifetime = Seconds (79.6 * 60); // 79.6 minutes
611  profile.dualFoilLifeTime = Seconds (55.9 * 60); // 55.9 minutes
612 
613  m_loadProfiles.push_back (profile);
614 
615  loads.clear ();
616  timeStamps.clear ();
617 
618  // C22
619  for (int i = 0; i < 150; i++)
620  {
621  loads.push_back (0.005 + 0.005 * i);
622  timeStamps.push_back (Seconds ((0.0 + i * 1.0) * 60));
623  }
624 
625  profile.loads = loads;
626  profile.timeStamps = timeStamps;
627  profile.itsyLifetime = Seconds (112.2 * 60); // 112.2 minutes
628  profile.dualFoilLifeTime = Seconds (94.5 * 60); // 94.5 minutes
629 
630  m_loadProfiles.push_back (profile);
631 
632  loads.clear ();
633  timeStamps.clear ();
634 }
635 
636 int
637 main (int argc, char **argv)
638 {
639  NS_LOG_DEBUG ("Constant load run.");
640 
642  int ret = 0;
643 
644  if (test.ConstantLoadTest (0.640, Seconds (2844.0)))
645  {
646  ret = 1;
647  std::cerr << "Problems with constant load test (640mA)." << std::endl;
648  }
649  if (test.ConstantLoadTest (0.320, Seconds (6146.0)))
650  {
651  ret = 1;
652  std::cerr << "Problems with constant load test (320mA)." << std::endl;
653  }
654  if (test.ConstantLoadTest (0.128, Seconds (16052.0)))
655  {
656  ret = 1;
657  std::cerr << "Problems with constant load test (128mA)." << std::endl;
658  }
659  if (test.ConstantLoadTest (0.064, Seconds (32561.0)))
660  {
661  ret = 1;
662  std::cerr << "Problems with constant load test (64mA)." << std::endl;
663  }
664  if (test.ConstantLoadTest (0.032, Seconds (65580.0)))
665  {
666  ret = 1;
667  std::cerr << "Problems with constant load test (32mA)." << std::endl;
668  }
669 
670  // create load profiles for variable load test
671  test.CreateLoadProfiles ();
672 
673  // variable load with Itsy battery
674  NS_LOG_DEBUG ("\n\nItsy");
675  test.m_alpha = 35220;
676  test.m_beta = 0.637;
677  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
678  {
679  NS_LOG_DEBUG ("========");
680  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
681  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
682  test.m_loadProfiles[i].timeStamps,
683  test.m_loadProfiles[i].itsyLifetime))
684  {
685  ret = 1;
686  std::cerr << "Problems with variable load test (Itsy)." << std::endl;
687  }
688  }
689 
690  // variable load with DUALFOIL battery
691  NS_LOG_DEBUG ("\n\nDUALFOIL");
692  test.m_alpha = 40027;
693  test.m_beta = 0.276;
694  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
695  {
696  NS_LOG_DEBUG ("========");
697  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
698  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
699  test.m_loadProfiles[i].timeStamps,
700  test.m_loadProfiles[i].dualFoilLifeTime))
701  {
702  ret = 1;
703  std::cerr << "Problems with variable load test (DUALFOIL)." << std::endl;
704  }
705  }
706 
707  return ret;
708 }
709 
710 bool
711 BatteryLifetimeTest::ConstantLoadTest (double load, Time expLifetime)
712 {
713  // create single node
714  NodeContainer c;
715  c.Create (1);
716 
717  std::string phyMode ("DsssRate1Mbps");
718 
719  // disable fragmentation for frames below 2200 bytes
720  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
721  StringValue ("2200"));
722  // turn off RTS/CTS for frames below 2200 bytes
723  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
724  StringValue ("2200"));
725  // Fix non-unicast data rate to be the same as that of unicast
726  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
727  StringValue (phyMode));
728 
729  // install YansWifiPhy
732 
734  /*
735  * This is one parameter that matters when using FixedRssLossModel, set it to
736  * zero; otherwise, gain will be added.
737  */
738  wifiPhy.Set ("RxGain", DoubleValue (0));
739  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
741 
742  YansWifiChannelHelper wifiChannel;
743  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
744  wifiPhy.SetChannel (wifiChannel.Create ());
745 
746  // Add a MAC and disable rate control
747  WifiMacHelper wifiMac;
748  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
749  "DataMode", StringValue (phyMode),
750  "ControlMode", StringValue (phyMode));
751  // Set it to ad-hoc mode
752  wifiMac.SetType ("ns3::AdhocWifiMac");
753  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
754 
755  // Create and install battery model and device models
756  // RV battery model
757  RvBatteryModelHelper rvModelHelper;
758  // Set alpha & beta values
759  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
760  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
761  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
762  // install source
763  EnergySourceContainer sources = rvModelHelper.Install (c);
764  // device energy model
765  WifiRadioEnergyModelHelper radioEnergyHelper;
766  // set VariableLoadTestIDLE current, which will be the constant load
767  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (load));
768  // install on node
769  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
770 
771  // run simulation
772  Simulator::Stop (Seconds (70000.0));
773  Simulator::Run ();
774 
775  Time actualLifetime;
776  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
777  actualLifetime = srcPtr->GetLifetime ();
778 
779  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
780  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
781 
783 
784  if (actualLifetime != expLifetime)
785  {
786  std::cerr << "ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
787  return true;
788  }
789 
790  return false; // error free
791 }
792 
793 bool
794 BatteryLifetimeTest::VariableLoadTest (std::vector<double> loads,
795  std::vector<Time> timeStamps,
796  Time expLifetime)
797 {
798  NS_ASSERT (loads.size () == timeStamps.size ());
799 
800  // create single node
801  NodeContainer c;
802  c.Create (1);
803 
804  std::string phyMode ("DsssRate1Mbps");
805 
806  // disable fragmentation for frames below 2200 bytes
807  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
808  StringValue ("2200"));
809  // turn off RTS/CTS for frames below 2200 bytes
810  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
811  StringValue ("2200"));
812  // Fix non-unicast data rate to be the same as that of unicast
813  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
814  StringValue (phyMode));
815 
816  // install YansWifiPhy
819 
821  /*
822  * This is one parameter that matters when using FixedRssLossModel, set it to
823  * zero; otherwise, gain will be added.
824  */
825  wifiPhy.Set ("RxGain", DoubleValue (0));
826  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
828 
829  YansWifiChannelHelper wifiChannel;
830  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
831  wifiPhy.SetChannel (wifiChannel.Create ());
832 
833  // Add a MAC and disable rate control
834  WifiMacHelper wifiMac;
835  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
836  "DataMode", StringValue (phyMode),
837  "ControlMode", StringValue (phyMode));
838  // Set it to ad-hoc mode
839  wifiMac.SetType ("ns3::AdhocWifiMac");
840  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
841 
842  // Create and install battery model and device models
843  // RV battery model
844  RvBatteryModelHelper rvModelHelper;
845  // Set alpha & beta values
846  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
847  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
848  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
849  // install source
850  EnergySourceContainer sources = rvModelHelper.Install (c);
851  // device energy model
852  WifiRadioEnergyModelHelper radioEnergyHelper;
853  // set VariableLoadTestIDLE current, which will be the constant load
854  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (loads[0]));
855  // install on node
856  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
857 
858 
859  Ptr<WifiRadioEnergyModel> wifiDevicePtr = DynamicCast<WifiRadioEnergyModel> (deviceModels.Get (0));
860  // schedule load change events
861  for (uint32_t i = 1; i < loads.size (); i++)
862  {
864  wifiDevicePtr, loads[i]);
865  }
866 
867  // run simulation
868  Simulator::Stop (Seconds (70000.0));
869  Simulator::Run ();
870 
871  Time actualLifetime;
872  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
873  actualLifetime = srcPtr->GetLifetime ();
874 
875  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
876  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
877  NS_LOG_DEBUG ("Difference = " << expLifetime.GetSeconds () - actualLifetime.GetSeconds () << "s");
878 
880 
881  // error tolerance = 120s
882  if ((actualLifetime.GetSeconds ()) > (expLifetime.GetSeconds ()) + (120) ||
883  (actualLifetime.GetSeconds ()) < (expLifetime.GetSeconds ()) - (120))
884  {
885  std::cerr << "VariableLoadTest: Incorrect lifetime." << std::endl;
886  return true;
887  }
888 
889  return false; // error free
890 }
891 
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Assign WifiRadioEnergyModel to wifi devices.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Holds a vector of ns3::EnergySource pointers.
tuple devices
Definition: first.py:32
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())
Definition: wifi-helper.cc:71
Hold variables of type string.
Definition: string.h:41
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...
Definition: assert.h:67
static void Run(void)
Run the simulation.
Definition: simulator.cc:200
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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
Definition: wifi-helper.h:76
Include Radiotap link layer information.
Holds a vector of ns3::DeviceEnergyModel pointers.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:100
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.
Definition: nstime.h:341
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.
Definition: simulator.h:1221
bool ConstantLoadTest(double load, Time expLifetime)
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:94
Creates a RvBatteryModel object.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:164
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
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<EnergySource> 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.
Definition: simulator.cc:208
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
tuple wifi
Definition: third.py:89
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'...
Definition: double.h:41
bool VariableLoadTest(std::vector< double > loads, std::vector< Time > timeStamps, Time expLifetime)
void test(void)
Example use of ns3::SystemThread.
void SetIdleCurrentA(double idleCurrentA)