A Discrete-Event Network Simulator
API
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/command-line.h"
33 #include "ns3/string.h"
34 #include "ns3/yans-wifi-helper.h"
35 #include <cmath>
36 
37 using namespace ns3;
38 
39 NS_LOG_COMPONENT_DEFINE ("RvBatteryModelTestSuite");
40 
53 {
54 public:
56  virtual ~BatteryLifetimeTest ();
57 
64  void CreateLoadProfiles (void);
65 
74  bool ConstantLoadTest (double load, Time expLifetime);
75 
85  bool VariableLoadTest (std::vector<double> loads,
86  std::vector<Time> timeStamps,
87  Time expLifetime);
88 
89  typedef struct LoadProfile
90  {
91  std::vector<double> loads;
92  std::vector<Time> timeStamps;
95  } LoadProfile;
96 
97  std::vector<LoadProfile> m_loadProfiles;
98  double m_alpha;
99  double m_beta;
100 };
101 
103 {
104  // Itsy battery
105  m_alpha = 35220;
106  m_beta = 0.637;
107 }
108 
110 {
111 }
112 
113 void
115 {
116  // create set of load profiles
117  LoadProfile profile;
118 
119  std::vector<double> loads;
120  std::vector<Time> timeStamps;
121 
122  // C1
123  loads.push_back (0.628);
124  loads.push_back (0);
125  loads.push_back (0.628);
126 
127  timeStamps.push_back (Seconds (0));
128  timeStamps.push_back (Seconds (19.5 * 60));
129  timeStamps.push_back (Seconds (26.0 * 60));
130 
131  profile.loads = loads;
132  profile.timeStamps = timeStamps;
133  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
134  profile.dualFoilLifeTime = Seconds (36.2 * 60); // 36.2 minutes
135 
136  m_loadProfiles.push_back (profile);
137 
138  loads.clear ();
139  timeStamps.clear ();
140 
141  // C2
142  loads.push_back (0.4947);
143  loads.push_back (0);
144  loads.push_back (0.4947);
145 
146  timeStamps.push_back (Seconds (0));
147  timeStamps.push_back (Seconds (31.0 * 60));
148  timeStamps.push_back (Seconds (41.3 * 60));
149 
150  profile.loads = loads;
151  profile.timeStamps = timeStamps;
152  profile.itsyLifetime = Seconds (73.9 * 60); // 73.9 minutes
153  profile.dualFoilLifeTime = Seconds (55.8 * 60); // 55.8 minutes
154 
155  m_loadProfiles.push_back (profile);
156 
157  loads.clear ();
158  timeStamps.clear ();
159 
160  // C3
161  loads.push_back (0.4256);
162  loads.push_back (0);
163  loads.push_back (0.4256);
164 
165  timeStamps.push_back (Seconds (0));
166  timeStamps.push_back (Seconds (41.0 * 60));
167  timeStamps.push_back (Seconds (54.6 * 60));
168 
169  profile.loads = loads;
170  profile.timeStamps = timeStamps;
171  profile.itsyLifetime = Seconds (88.8 * 60); // 88.8 minutes
172  profile.dualFoilLifeTime = Seconds (71.8 * 60); // 71.8 minutes
173 
174  m_loadProfiles.push_back (profile);
175 
176  loads.clear ();
177  timeStamps.clear ();
178 
179  // C4
180  loads.push_back (0.2923);
181  loads.push_back (0);
182  loads.push_back (0.2923);
183 
184  timeStamps.push_back (Seconds (0));
185  timeStamps.push_back (Seconds (74.6 * 60));
186  timeStamps.push_back (Seconds (99.5 * 60));
187 
188  profile.loads = loads;
189  profile.timeStamps = timeStamps;
190  profile.itsyLifetime = Seconds (137.8 * 60); // 137.8 minutes
191  profile.dualFoilLifeTime = Seconds (124.9 * 60); // 124.9 minutes
192 
193  m_loadProfiles.push_back (profile);
194 
195  loads.clear ();
196  timeStamps.clear ();
197 
198  // C5
199  loads.push_back (0.2227);
200  loads.push_back (0);
201  loads.push_back (0.2227);
202 
203  timeStamps.push_back (Seconds (0));
204  timeStamps.push_back (Seconds (105.7 * 60));
205  timeStamps.push_back (Seconds (140.9 * 60));
206 
207  profile.loads = loads;
208  profile.timeStamps = timeStamps;
209  profile.itsyLifetime = Seconds (185.8 * 60); // 185.8 minutes
210  profile.dualFoilLifeTime = Seconds (176.7 * 60); // 176.7 minutes
211 
212  m_loadProfiles.push_back (profile);
213 
214  loads.clear ();
215  timeStamps.clear ();
216 
217  // C6
218  loads.push_back (0.628);
219  loads.push_back (0);
220  loads.push_back (0.628);
221 
222  timeStamps.push_back (Seconds (0));
223  timeStamps.push_back (Seconds (19.5 * 60));
224  timeStamps.push_back (Seconds (29.9 * 60));
225 
226  profile.loads = loads;
227  profile.timeStamps = timeStamps;
228  profile.itsyLifetime = Seconds (58.9 * 60); // 58.9 minutes
229  profile.dualFoilLifeTime = Seconds (41.0 * 60); // 41.0 minutes
230 
231  m_loadProfiles.push_back (profile);
232 
233  loads.clear ();
234  timeStamps.clear ();
235 
236  // C7
237  loads.push_back (0.628);
238  loads.push_back (0);
239  loads.push_back (0.628);
240 
241  timeStamps.push_back (Seconds (0));
242  timeStamps.push_back (Seconds (19.5 * 60));
243  timeStamps.push_back (Seconds (22.1 * 60));
244 
245  profile.loads = loads;
246  profile.timeStamps = timeStamps;
247  profile.itsyLifetime = Seconds (51.1 * 60); // 51.1 minutes
248  profile.dualFoilLifeTime = Seconds (30.8 * 60); // 30.8 minutes
249 
250  m_loadProfiles.push_back (profile);
251 
252  loads.clear ();
253  timeStamps.clear ();
254 
255  // C8
256  loads.push_back (0.628);
257  loads.push_back (0);
258  loads.push_back (0.628);
259 
260  timeStamps.push_back (Seconds (0));
261  timeStamps.push_back (Seconds (23.4 * 60));
262  timeStamps.push_back (Seconds (29.9 * 60));
263 
264  profile.loads = loads;
265  profile.timeStamps = timeStamps;
266  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
267  profile.dualFoilLifeTime = Seconds (37.4 * 60); // 37.4 minutes
268 
269  m_loadProfiles.push_back (profile);
270 
271  loads.clear ();
272  timeStamps.clear ();
273 
274  // C9
275  loads.push_back (0.628);
276  loads.push_back (0);
277  loads.push_back (0.628);
278 
279  timeStamps.push_back (Seconds (0));
280  timeStamps.push_back (Seconds (15.6 * 60));
281  timeStamps.push_back (Seconds (22.1 * 60));
282 
283  profile.loads = loads;
284  profile.timeStamps = timeStamps;
285  profile.itsyLifetime = Seconds (55.0 * 60); // 55.0 minutes
286  profile.dualFoilLifeTime = Seconds (35.2 * 60); // 35.2 minutes
287 
288  m_loadProfiles.push_back (profile);
289 
290  loads.clear ();
291  timeStamps.clear ();
292 
293  // C10
294  loads.push_back (0.300);
295  loads.push_back (0.628);
296  loads.push_back (0.4947);
297  loads.push_back (0.2523);
298  loads.push_back (0.2341);
299  loads.push_back (0.1379);
300  loads.push_back (0.1139);
301  loads.push_back (0.2656);
302 
303  timeStamps.push_back (Seconds (0));
304  timeStamps.push_back (Seconds (0.5 * 60));
305  timeStamps.push_back (Seconds (5.5 * 60));
306  timeStamps.push_back (Seconds (10.5 * 60));
307  timeStamps.push_back (Seconds (35.5 * 60));
308  timeStamps.push_back (Seconds (60.5 * 60));
309  timeStamps.push_back (Seconds (85.5 * 60));
310  timeStamps.push_back (Seconds (110.5 * 60));
311 
312  profile.loads = loads;
313  profile.timeStamps = timeStamps;
314  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
315  profile.dualFoilLifeTime = Seconds (132.6 * 60); // 132.6 minutes
316 
317  m_loadProfiles.push_back (profile);
318 
319  loads.clear ();
320  timeStamps.clear ();
321 
322  // C11
323  loads.push_back (0.300);
324  loads.push_back (0.1139);
325  loads.push_back (0.1379);
326  loads.push_back (0.2341);
327  loads.push_back (0.2523);
328  loads.push_back (0.4947);
329  loads.push_back (0.628);
330  loads.push_back (0.2656);
331 
332  timeStamps.push_back (Seconds (0));
333  timeStamps.push_back (Seconds (0.5 * 60));
334  timeStamps.push_back (Seconds (25.5 * 60));
335  timeStamps.push_back (Seconds (50.5 * 60));
336  timeStamps.push_back (Seconds (75.5 * 60));
337  timeStamps.push_back (Seconds (100.5 * 60));
338  timeStamps.push_back (Seconds (105.5 * 60));
339  timeStamps.push_back (Seconds (110.5 * 60));
340 
341  profile.loads = loads;
342  profile.timeStamps = timeStamps;
343  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
344  profile.dualFoilLifeTime = Seconds (107.4 * 60); // 107.4 minutes
345 
346  m_loadProfiles.push_back (profile);
347 
348  loads.clear ();
349  timeStamps.clear ();
350 
351  // C12
352  loads.push_back (0.300);
353  loads.push_back (0.1139);
354  loads.push_back (0.1379);
355  loads.push_back (0.2341);
356  loads.push_back (0.2523);
357  loads.push_back (0.4947);
358  loads.push_back (0.0);
359  loads.push_back (0.300);
360  loads.push_back (0.628);
361  loads.push_back (0.2656);
362 
363  timeStamps.push_back (Seconds (0));
364  timeStamps.push_back (Seconds (0.5 * 60));
365  timeStamps.push_back (Seconds (25.5 * 60));
366  timeStamps.push_back (Seconds (50.5 * 60));
367  timeStamps.push_back (Seconds (75.5 * 60));
368  timeStamps.push_back (Seconds (100.5 * 60));
369  timeStamps.push_back (Seconds (105.5 * 60));
370  timeStamps.push_back (Seconds (130.5 * 60));
371  timeStamps.push_back (Seconds (131.0 * 60));
372  timeStamps.push_back (Seconds (136.0 * 60));
373 
374  profile.loads = loads;
375  profile.timeStamps = timeStamps;
376  profile.itsyLifetime = Seconds (169.3 * 60); // 169.3 minutes
377  profile.dualFoilLifeTime = Seconds (155.4 * 60); // 155.4 minutes
378 
379  m_loadProfiles.push_back (profile);
380 
381  loads.clear ();
382  timeStamps.clear ();
383 
384  // C13
385  loads.push_back (0.300);
386  timeStamps.push_back (Seconds (0));
387 
388  for (int i = 0; i < 5; i++)
389  {
390  loads.push_back (0.628);
391  loads.push_back (0.4947);
392  loads.push_back (0.2523);
393  loads.push_back (0.2341);
394  loads.push_back (0.1379);
395  loads.push_back (0.1139);
396 
397  timeStamps.push_back (Seconds ((0.5 + i * 22.5) * 60));
398  timeStamps.push_back (Seconds ((1.5 + i * 22.5) * 60));
399  timeStamps.push_back (Seconds ((2.5 + i * 22.5) * 60));
400  timeStamps.push_back (Seconds ((7.5 + i * 22.5) * 60));
401  timeStamps.push_back (Seconds ((12.5 + i * 22.5) * 60));
402  timeStamps.push_back (Seconds ((17.5 + i * 22.5) * 60));
403  }
404 
405  loads.push_back (0.2656);
406  timeStamps.push_back (Seconds (110.5 * 60));
407 
408  profile.loads = loads;
409  profile.timeStamps = timeStamps;
410  profile.itsyLifetime = Seconds (144.3 * 60); // 144.3 minutes
411  profile.dualFoilLifeTime = Seconds (131.7 * 60); // 131.7 minutes
412 
413  m_loadProfiles.push_back (profile);
414 
415  loads.clear ();
416  timeStamps.clear ();
417 
418  // C14, time stamp calculation in paper is off, using our own estimated value
419  loads.push_back (0.300);
420  timeStamps.push_back (Seconds (0));
421 
422  for (int i = 0; i < 5; i++)
423  {
424  loads.push_back (0.1139);
425  loads.push_back (0.1379);
426  loads.push_back (0.2341);
427  loads.push_back (0.2523);
428  loads.push_back (0.4947);
429  loads.push_back (0.628);
430 
431  timeStamps.push_back (Seconds ((0.5 + i * 22.5) * 60));
432  timeStamps.push_back (Seconds ((5.5 + i * 22.5) * 60));
433  timeStamps.push_back (Seconds ((10.5 + i * 22.5) * 60));
434  timeStamps.push_back (Seconds ((15.5 + i * 22.5) * 60));
435  timeStamps.push_back (Seconds ((20.5 + i * 22.5) * 60));
436  timeStamps.push_back (Seconds ((21.5 + i * 22.5) * 60));
437  }
438 
439  loads.push_back (0.2656);
440  timeStamps.push_back (Seconds (112.5 * 60));
441 
442  profile.loads = loads;
443  profile.timeStamps = timeStamps;
444  profile.itsyLifetime = Seconds (141.5 * 60); // 141.5 minutes
445  profile.dualFoilLifeTime = Seconds (126.3 * 60); // 126.3 minutes
446 
447  m_loadProfiles.push_back (profile);
448 
449  loads.clear ();
450  timeStamps.clear ();
451 
452  // C15
453  loads.push_back (0.2227);
454  loads.push_back (0.2045);
455  loads.push_back (0.1083);
456  loads.push_back (0.0843);
457  loads.push_back (0.2227);
458 
459  timeStamps.push_back (Seconds (0));
460  timeStamps.push_back (Seconds (50.0 * 60));
461  timeStamps.push_back (Seconds (100.0 * 60));
462  timeStamps.push_back (Seconds (150.0 * 60));
463  timeStamps.push_back (Seconds (200.0 * 60));
464 
465  profile.loads = loads;
466  profile.timeStamps = timeStamps;
467  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
468  profile.dualFoilLifeTime = Seconds (209.2 * 60); // 209.2 minutes
469 
470  m_loadProfiles.push_back (profile);
471 
472  loads.clear ();
473  timeStamps.clear ();
474 
475  // C16
476  loads.push_back (0.0843);
477  loads.push_back (0.1083);
478  loads.push_back (0.2045);
479  loads.push_back (0.2227);
480  loads.push_back (0.2227);
481 
482  timeStamps.push_back (Seconds (0));
483  timeStamps.push_back (Seconds (50.0 * 60));
484  timeStamps.push_back (Seconds (100.0 * 60));
485  timeStamps.push_back (Seconds (150.0 * 60));
486  timeStamps.push_back (Seconds (200.0 * 60));
487 
488  profile.loads = loads;
489  profile.timeStamps = timeStamps;
490  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
491  profile.dualFoilLifeTime = Seconds (200.7 * 60); // 200.7 minutes
492 
493  m_loadProfiles.push_back (profile);
494 
495  loads.clear ();
496  timeStamps.clear ();
497 
498  // C17
499  loads.push_back (0.0843);
500  loads.push_back (0.1083);
501  loads.push_back (0.2045);
502  loads.push_back (0.0);
503  loads.push_back (0.2227);
504  loads.push_back (0.2227);
505 
506  timeStamps.push_back (Seconds (0));
507  timeStamps.push_back (Seconds (50.0 * 60));
508  timeStamps.push_back (Seconds (100.0 * 60));
509  timeStamps.push_back (Seconds (150.0 * 60));
510  timeStamps.push_back (Seconds (200.0 * 60));
511  timeStamps.push_back (Seconds (250.0 * 60));
512 
513  profile.loads = loads;
514  profile.timeStamps = timeStamps;
515  profile.itsyLifetime = Seconds (261.4 * 60); // 261.4 minutes
516  profile.dualFoilLifeTime = Seconds (251.2 * 60); // 251.2 minutes
517 
518  m_loadProfiles.push_back (profile);
519 
520  loads.clear ();
521  timeStamps.clear ();
522 
523  // C18
524  for (int i = 0; i < 10; i++)
525  {
526  loads.push_back (0.0843);
527  loads.push_back (0.1083);
528  loads.push_back (0.2045);
529  loads.push_back (0.2227);
530 
531  timeStamps.push_back (Seconds ((0.0 + i * 20.0) * 60));
532  timeStamps.push_back (Seconds ((5.0 + i * 20.0) * 60));
533  timeStamps.push_back (Seconds ((10.0 + i * 20.0) * 60));
534  timeStamps.push_back (Seconds ((15.0 + i * 20.0) * 60));
535  }
536 
537  loads.push_back (0.2227);
538  timeStamps.push_back (Seconds (200.0));
539 
540  profile.loads = loads;
541  profile.timeStamps = timeStamps;
542  profile.itsyLifetime = Seconds (211.4 * 60); // 211.4 minutes
543  profile.dualFoilLifeTime = Seconds (204.6 * 60); // 204.6 minutes
544 
545  m_loadProfiles.push_back (profile);
546 
547  loads.clear ();
548  timeStamps.clear ();
549 
550  // C19
551  for (int i = 0; i < 10; i++)
552  {
553  loads.push_back (0.0755);
554  loads.push_back (0.0949);
555  loads.push_back (0.2045);
556  loads.push_back (0.2227);
557 
558  timeStamps.push_back (Seconds ((0.0 + i * 20.0) * 60));
559  timeStamps.push_back (Seconds ((5.0 + i * 20.0) * 60));
560  timeStamps.push_back (Seconds ((10.0 + i * 20.0) * 60));
561  timeStamps.push_back (Seconds ((15.0 + i * 20.0) * 60));
562  }
563 
564  loads.push_back (0.2227);
565  timeStamps.push_back (Seconds (200.0));
566 
567  profile.loads = loads;
568  profile.timeStamps = timeStamps;
569  profile.itsyLifetime = Seconds (216.4 * 60); // 216.4 minutes
570  profile.dualFoilLifeTime = Seconds (208.7 * 60); // 208.7 minutes
571 
572  m_loadProfiles.push_back (profile);
573 
574  loads.clear ();
575  timeStamps.clear ();
576 
577  // C20
578  for (int i = 0; i < 50; i++)
579  {
580  loads.push_back (0.4947);
581  loads.push_back (0.628);
582 
583  timeStamps.push_back (Seconds ((0.0 + i * 2.0) * 60));
584  timeStamps.push_back (Seconds ((1.0 + i * 2.0) * 60));
585  }
586 
587  profile.loads = loads;
588  profile.timeStamps = timeStamps;
589  profile.itsyLifetime = Seconds (55.3 * 60); // 55.3 minutes
590  profile.dualFoilLifeTime = Seconds (33.2 * 60); // 33.2 minutes
591 
592  m_loadProfiles.push_back (profile);
593 
594  loads.clear ();
595  timeStamps.clear ();
596 
597  // C21
598  for (int i = 0; i < 50; i++)
599  {
600  loads.push_back (0.4947);
601  loads.push_back (0.628);
602  loads.push_back (0.0576);
603 
604  timeStamps.push_back (Seconds ((0.0 + i * 3.0) * 60));
605  timeStamps.push_back (Seconds ((1.0 + i * 3.0) * 60));
606  timeStamps.push_back (Seconds ((2.0 + i * 3.0) * 60));
607  }
608 
609  profile.loads = loads;
610  profile.timeStamps = timeStamps;
611  profile.itsyLifetime = Seconds (79.6 * 60); // 79.6 minutes
612  profile.dualFoilLifeTime = Seconds (55.9 * 60); // 55.9 minutes
613 
614  m_loadProfiles.push_back (profile);
615 
616  loads.clear ();
617  timeStamps.clear ();
618 
619  // C22
620  for (int i = 0; i < 150; i++)
621  {
622  loads.push_back (0.005 + 0.005 * i);
623  timeStamps.push_back (Seconds ((0.0 + i * 1.0) * 60));
624  }
625 
626  profile.loads = loads;
627  profile.timeStamps = timeStamps;
628  profile.itsyLifetime = Seconds (112.2 * 60); // 112.2 minutes
629  profile.dualFoilLifeTime = Seconds (94.5 * 60); // 94.5 minutes
630 
631  m_loadProfiles.push_back (profile);
632 
633  loads.clear ();
634  timeStamps.clear ();
635 }
636 
637 int
638 main (int argc, char **argv)
639 {
641  cmd.Parse (argc, argv);
642 
643  NS_LOG_DEBUG ("Constant load run.");
644 
645  BatteryLifetimeTest test;
646  int ret = 0;
647 
648  if (test.ConstantLoadTest (0.640, Seconds (2844.0)))
649  {
650  ret = 1;
651  std::cerr << "Problems with constant load test (640mA)." << std::endl;
652  }
653  if (test.ConstantLoadTest (0.320, Seconds (6146.0)))
654  {
655  ret = 1;
656  std::cerr << "Problems with constant load test (320mA)." << std::endl;
657  }
658  if (test.ConstantLoadTest (0.128, Seconds (16052.0)))
659  {
660  ret = 1;
661  std::cerr << "Problems with constant load test (128mA)." << std::endl;
662  }
663  if (test.ConstantLoadTest (0.064, Seconds (32561.0)))
664  {
665  ret = 1;
666  std::cerr << "Problems with constant load test (64mA)." << std::endl;
667  }
668  if (test.ConstantLoadTest (0.032, Seconds (65580.0)))
669  {
670  ret = 1;
671  std::cerr << "Problems with constant load test (32mA)." << std::endl;
672  }
673 
674  // create load profiles for variable load test
675  test.CreateLoadProfiles ();
676 
677  // variable load with Itsy battery
678  NS_LOG_DEBUG ("\n\nItsy");
679  test.m_alpha = 35220;
680  test.m_beta = 0.637;
681  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
682  {
683  NS_LOG_DEBUG ("========");
684  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
685  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
686  test.m_loadProfiles[i].timeStamps,
687  test.m_loadProfiles[i].itsyLifetime))
688  {
689  ret = 1;
690  std::cerr << "Problems with variable load test (Itsy)." << std::endl;
691  }
692  }
693 
694  // variable load with DUALFOIL battery
695  NS_LOG_DEBUG ("\n\nDUALFOIL");
696  test.m_alpha = 40027;
697  test.m_beta = 0.276;
698  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
699  {
700  NS_LOG_DEBUG ("========");
701  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
702  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
703  test.m_loadProfiles[i].timeStamps,
704  test.m_loadProfiles[i].dualFoilLifeTime))
705  {
706  ret = 1;
707  std::cerr << "Problems with variable load test (DUALFOIL)." << std::endl;
708  }
709  }
710 
711  return ret;
712 }
713 
714 bool
715 BatteryLifetimeTest::ConstantLoadTest (double load, Time expLifetime)
716 {
717  // create single node
718  NodeContainer c;
719  c.Create (1);
720 
721  std::string phyMode ("DsssRate1Mbps");
722 
723  // disable fragmentation for frames below 2200 bytes
724  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
725  StringValue ("2200"));
726  // turn off RTS/CTS for frames below 2200 bytes
727  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
728  StringValue ("2200"));
729  // Fix non-unicast data rate to be the same as that of unicast
730  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
731  StringValue (phyMode));
732 
733  // install YansWifiPhy
735  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
736 
738  /*
739  * This is one parameter that matters when using FixedRssLossModel, set it to
740  * zero; otherwise, gain will be added.
741  */
742  wifiPhy.Set ("RxGain", DoubleValue (0));
743  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
745 
746  YansWifiChannelHelper wifiChannel;
747  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
748  wifiPhy.SetChannel (wifiChannel.Create ());
749 
750  // Add a MAC and disable rate control
751  WifiMacHelper wifiMac;
752  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
753  "DataMode", StringValue (phyMode),
754  "ControlMode", StringValue (phyMode));
755  // Set it to ad-hoc mode
756  wifiMac.SetType ("ns3::AdhocWifiMac");
757  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
758 
759  // Create and install battery model and device models
760  // RV battery model
761  RvBatteryModelHelper rvModelHelper;
762  // Set alpha & beta values
763  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
764  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
765  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
766  // install source
767  EnergySourceContainer sources = rvModelHelper.Install (c);
768  // device energy model
769  WifiRadioEnergyModelHelper radioEnergyHelper;
770  // set VariableLoadTestIDLE current, which will be the constant load
771  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (load));
772  // install on node
773  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
774 
775  // run simulation
776  Simulator::Stop (Seconds (70000.0));
777  Simulator::Run ();
778 
779  Time actualLifetime;
780  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
781  actualLifetime = srcPtr->GetLifetime ();
782 
783  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
784  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
785 
787 
788  if (actualLifetime != expLifetime)
789  {
790  std::cerr << "ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
791  return true;
792  }
793 
794  return false; // error free
795 }
796 
797 bool
798 BatteryLifetimeTest::VariableLoadTest (std::vector<double> loads,
799  std::vector<Time> timeStamps,
800  Time expLifetime)
801 {
802  NS_ASSERT (loads.size () == timeStamps.size ());
803 
804  // create single node
805  NodeContainer c;
806  c.Create (1);
807 
808  std::string phyMode ("DsssRate1Mbps");
809 
810  // disable fragmentation for frames below 2200 bytes
811  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
812  StringValue ("2200"));
813  // turn off RTS/CTS for frames below 2200 bytes
814  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
815  StringValue ("2200"));
816  // Fix non-unicast data rate to be the same as that of unicast
817  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
818  StringValue (phyMode));
819 
820  // install YansWifiPhy
822  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
823 
825  /*
826  * This is one parameter that matters when using FixedRssLossModel, set it to
827  * zero; otherwise, gain will be added.
828  */
829  wifiPhy.Set ("RxGain", DoubleValue (0));
830  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
832 
833  YansWifiChannelHelper wifiChannel;
834  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
835  wifiPhy.SetChannel (wifiChannel.Create ());
836 
837  // Add a MAC and disable rate control
838  WifiMacHelper wifiMac;
839  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
840  "DataMode", StringValue (phyMode),
841  "ControlMode", StringValue (phyMode));
842  // Set it to ad-hoc mode
843  wifiMac.SetType ("ns3::AdhocWifiMac");
844  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
845 
846  // Create and install battery model and device models
847  // RV battery model
848  RvBatteryModelHelper rvModelHelper;
849  // Set alpha & beta values
850  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
851  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
852  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
853  // install source
854  EnergySourceContainer sources = rvModelHelper.Install (c);
855  // device energy model
856  WifiRadioEnergyModelHelper radioEnergyHelper;
857  // set VariableLoadTestIDLE current, which will be the constant load
858  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (loads[0]));
859  // install on node
860  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
861 
862 
863  Ptr<WifiRadioEnergyModel> wifiDevicePtr = DynamicCast<WifiRadioEnergyModel> (deviceModels.Get (0));
864  // schedule load change events
865  for (uint32_t i = 1; i < loads.size (); i++)
866  {
868  wifiDevicePtr, loads[i]);
869  }
870 
871  // run simulation
872  Simulator::Stop (Seconds (70000.0));
873  Simulator::Run ();
874 
875  Time actualLifetime;
876  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
877  actualLifetime = srcPtr->GetLifetime ();
878 
879  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
880  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
881  NS_LOG_DEBUG ("Difference = " << expLifetime.GetSeconds () - actualLifetime.GetSeconds () << "s");
882 
884 
885  // error tolerance = 120s
886  if ((actualLifetime.GetSeconds ()) > (expLifetime.GetSeconds ()) + (120) ||
887  (actualLifetime.GetSeconds ()) < (expLifetime.GetSeconds ()) - (120))
888  {
889  std::cerr << "VariableLoadTest: Incorrect lifetime." << std::endl;
890  return true;
891  }
892 
893  return false; // error free
894 }
895 
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:134
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.
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
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
cmd
Definition: second.py:35
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:230
Time GetLifetime(void) const
Holds a vector of ns3::DeviceEnergyModel pointers.
Ptr< DeviceEnergyModel > Get(uint32_t i) const
Get the i-th Ptr<DeviceEnergyModel> stored in this container.
Ptr< YansWifiChannel > Create(void) const
void CreateLoadProfiles(void)
Creates load profiles according to D.
void SetChannel(Ptr< YansWifiChannel > channel)
std::vector< Time > timeStamps
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
bool ConstantLoadTest(double load, Time expLifetime)
holds a vector of ns3::NetDevice pointers
Creates a RvBatteryModel object.
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
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)
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:453
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())
wifi
Definition: third.py:89
This example was originally devised as a test, then it was converted to an example.
EnergySourceContainer Install(Ptr< Node > node) const
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
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())
devices
Definition: first.py:32
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
bool VariableLoadTest(std::vector< double > loads, std::vector< Time > timeStamps, Time expLifetime)
Include Radiotap link layer information.
Definition: wifi-helper.h:111
void SetIdleCurrentA(double idleCurrentA)
Sets idle current.
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const