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/string.h"
33 #include "ns3/yans-wifi-helper.h"
34 #include "ns3/nqos-wifi-mac-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 {
640  NS_LOG_DEBUG ("Constant load run.");
641 
643  int ret = 0;
644 
645  if (test.ConstantLoadTest (0.640, Seconds (2844.0)))
646  {
647  ret = 1;
648  std::cerr << "Problems with constant load test (640mA)." << std::endl;
649  }
650  if (test.ConstantLoadTest (0.320, Seconds (6146.0)))
651  {
652  ret = 1;
653  std::cerr << "Problems with constant load test (320mA)." << std::endl;
654  }
655  if (test.ConstantLoadTest (0.128, Seconds (16052.0)))
656  {
657  ret = 1;
658  std::cerr << "Problems with constant load test (128mA)." << std::endl;
659  }
660  if (test.ConstantLoadTest (0.064, Seconds (32561.0)))
661  {
662  ret = 1;
663  std::cerr << "Problems with constant load test (64mA)." << std::endl;
664  }
665  if (test.ConstantLoadTest (0.032, Seconds (65580.0)))
666  {
667  ret = 1;
668  std::cerr << "Problems with constant load test (32mA)." << std::endl;
669  }
670 
671  // create load profiles for variable load test
672  test.CreateLoadProfiles ();
673 
674  // variable load with Itsy battery
675  NS_LOG_DEBUG ("\n\nItsy");
676  test.m_alpha = 35220;
677  test.m_beta = 0.637;
678  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
679  {
680  NS_LOG_DEBUG ("========");
681  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
682  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
683  test.m_loadProfiles[i].timeStamps,
684  test.m_loadProfiles[i].itsyLifetime))
685  {
686  ret = 1;
687  std::cerr << "Problems with variable load test (Itsy)." << std::endl;
688  }
689  }
690 
691  // variable load with DUALFOIL battery
692  NS_LOG_DEBUG ("\n\nDUALFOIL");
693  test.m_alpha = 40027;
694  test.m_beta = 0.276;
695  for (uint32_t i = 0; i < test.m_loadProfiles.size (); i++)
696  {
697  NS_LOG_DEBUG ("========");
698  NS_LOG_DEBUG ("Variable load profile C" << i + 1);
699  if (test.VariableLoadTest (test.m_loadProfiles[i].loads,
700  test.m_loadProfiles[i].timeStamps,
701  test.m_loadProfiles[i].dualFoilLifeTime))
702  {
703  ret = 1;
704  std::cerr << "Problems with variable load test (DUALFOIL)." << std::endl;
705  }
706  }
707 
708  return ret;
709 }
710 
711 bool
712 BatteryLifetimeTest::ConstantLoadTest (double load, Time expLifetime)
713 {
714  // create single node
715  NodeContainer c;
716  c.Create (1);
717 
718  std::string phyMode ("DsssRate1Mbps");
719 
720  // disable fragmentation for frames below 2200 bytes
721  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
722  StringValue ("2200"));
723  // turn off RTS/CTS for frames below 2200 bytes
724  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
725  StringValue ("2200"));
726  // Fix non-unicast data rate to be the same as that of unicast
727  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
728  StringValue (phyMode));
729 
730  // install YansWifiPhy
733 
735  /*
736  * This is one parameter that matters when using FixedRssLossModel, set it to
737  * zero; otherwise, gain will be added.
738  */
739  wifiPhy.Set ("RxGain", DoubleValue (0));
740  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
742 
743  YansWifiChannelHelper wifiChannel;
744  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
745  wifiPhy.SetChannel (wifiChannel.Create ());
746 
747  // Add a non-QoS upper MAC, and disable rate control
749  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
750  "DataMode", StringValue (phyMode),
751  "ControlMode", StringValue (phyMode));
752  // Set it to ad-hoc mode
753  wifiMac.SetType ("ns3::AdhocWifiMac");
754  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
755 
756  // Create and install battery model and device models
757  // RV battery model
758  RvBatteryModelHelper rvModelHelper;
759  // Set alpha & beta values
760  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
761  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
762  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
763  // install source
764  EnergySourceContainer sources = rvModelHelper.Install (c);
765  // device energy model
766  WifiRadioEnergyModelHelper radioEnergyHelper;
767  // set VariableLoadTestIDLE current, which will be the constant load
768  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (load));
769  // install on node
770  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
771 
772  // run simulation
773  Simulator::Stop (Seconds (70000.0));
774  Simulator::Run ();
775 
776  Time actualLifetime;
777  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
778  actualLifetime = srcPtr->GetLifetime ();
779 
780  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
781  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
782 
784 
785  if (actualLifetime != expLifetime)
786  {
787  std::cerr << "ConstantLoadTest: Incorrect lifetime for load " << load << std::endl;
788  return true;
789  }
790 
791  return false; // error free
792 }
793 
794 bool
795 BatteryLifetimeTest::VariableLoadTest (std::vector<double> loads,
796  std::vector<Time> timeStamps,
797  Time expLifetime)
798 {
799  NS_ASSERT (loads.size () == timeStamps.size ());
800 
801  // create single node
802  NodeContainer c;
803  c.Create (1);
804 
805  std::string phyMode ("DsssRate1Mbps");
806 
807  // disable fragmentation for frames below 2200 bytes
808  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
809  StringValue ("2200"));
810  // turn off RTS/CTS for frames below 2200 bytes
811  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
812  StringValue ("2200"));
813  // Fix non-unicast data rate to be the same as that of unicast
814  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
815  StringValue (phyMode));
816 
817  // install YansWifiPhy
820 
822  /*
823  * This is one parameter that matters when using FixedRssLossModel, set it to
824  * zero; otherwise, gain will be added.
825  */
826  wifiPhy.Set ("RxGain", DoubleValue (0));
827  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
829 
830  YansWifiChannelHelper wifiChannel;
831  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
832  wifiPhy.SetChannel (wifiChannel.Create ());
833 
834  // Add a non-QoS upper MAC, and disable rate control
836  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
837  "DataMode", StringValue (phyMode),
838  "ControlMode", StringValue (phyMode));
839  // Set it to ad-hoc mode
840  wifiMac.SetType ("ns3::AdhocWifiMac");
841  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
842 
843  // Create and install battery model and device models
844  // RV battery model
845  RvBatteryModelHelper rvModelHelper;
846  // Set alpha & beta values
847  rvModelHelper.Set ("RvBatteryModelAlphaValue", DoubleValue (m_alpha));
848  rvModelHelper.Set ("RvBatteryModelBetaValue", DoubleValue (m_beta));
849  rvModelHelper.Set ("RvBatteryModelLowBatteryThreshold", DoubleValue (0.0));
850  // install source
851  EnergySourceContainer sources = rvModelHelper.Install (c);
852  // device energy model
853  WifiRadioEnergyModelHelper radioEnergyHelper;
854  // set VariableLoadTestIDLE current, which will be the constant load
855  radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (loads[0]));
856  // install on node
857  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
858 
859 
860  Ptr<WifiRadioEnergyModel> wifiDevicePtr = DynamicCast<WifiRadioEnergyModel> (deviceModels.Get (0));
861  // schedule load change events
862  for (uint32_t i = 1; i < loads.size (); i++)
863  {
865  wifiDevicePtr, loads[i]);
866  }
867 
868  // run simulation
869  Simulator::Stop (Seconds (70000.0));
870  Simulator::Run ();
871 
872  Time actualLifetime;
873  Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
874  actualLifetime = srcPtr->GetLifetime ();
875 
876  NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
877  NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
878  NS_LOG_DEBUG ("Difference = " << expLifetime.GetSeconds () - actualLifetime.GetSeconds () << "s");
879 
881 
882  // error tolerance = 120s
883  if ((actualLifetime.GetSeconds ()) > (expLifetime.GetSeconds ()) + (120) ||
884  (actualLifetime.GetSeconds ()) < (expLifetime.GetSeconds ()) - (120))
885  {
886  std::cerr << "VariableLoadTest: Incorrect lifetime." << std::endl;
887  return true;
888  }
889 
890  return false; // error free
891 }
892 
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:74
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
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())
#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:96
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:103
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:1216
bool ConstantLoadTest(double load, Time expLifetime)
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:97
Creates a RvBatteryModel object.
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state.
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
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 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.
void Set(std::string name, const AttributeValue &v)
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.
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)