A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
test-cosine-antenna.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
20 #include <ns3/cosine-antenna-model.h>
21 #include <ns3/double.h>
22 #include <ns3/log.h>
23 #include <ns3/simulator.h>
24 #include <ns3/test.h>
25 
26 #include <cmath>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 
31 using namespace ns3;
32 
33 NS_LOG_COMPONENT_DEFINE("TestCosineAntennaModel");
34 
41 {
42  EQUAL = 0,
43  LESSTHAN = 1
44 };
45 
52 {
53  public:
62  static std::string BuildNameString(Angles a, double b, double o, double g);
73  double b,
74  double o,
75  double g,
76  double expectedGainDb,
78 
79  private:
80  void DoRun() override;
82  double m_b;
83  double m_o;
84  double m_g;
85  double m_expectedGain;
87 };
88 
89 std::string
90 CosineAntennaModelTestCase::BuildNameString(Angles a, double b, double o, double g)
91 {
92  std::ostringstream oss;
93  oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth() << ", beamdwidth=" << b
94  << "deg"
95  << ", orientation=" << o << ", maxGain=" << g << " dB";
96  return oss.str();
97 }
98 
100  double b,
101  double o,
102  double g,
103  double expectedGainDb,
105  : TestCase(BuildNameString(a, b, o, g)),
106  m_a(a),
107  m_b(b),
108  m_o(o),
109  m_g(g),
110  m_expectedGain(expectedGainDb),
111  m_cond(cond)
112 {
113 }
114 
115 void
117 {
119 
120  Ptr<CosineAntennaModel> a = CreateObject<CosineAntennaModel>();
121  a->SetAttribute("HorizontalBeamwidth", DoubleValue(m_b));
122  a->SetAttribute("VerticalBeamwidth", DoubleValue(m_b));
123  a->SetAttribute("Orientation", DoubleValue(m_o));
124  a->SetAttribute("MaxGain", DoubleValue(m_g));
125  double actualGain = a->GetGainDb(m_a);
126  switch (m_cond)
127  {
128  case EQUAL:
129  NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
131  0.001,
132  "wrong value of the radiation pattern");
133  break;
134  case LESSTHAN:
135  NS_TEST_EXPECT_MSG_LT(actualGain, m_expectedGain, "gain higher than expected");
136  break;
137  default:
138  break;
139  }
140 }
141 
148 {
149  public:
151 };
152 
154  : TestSuite("cosine-antenna-model", UNIT)
155 {
156  // to calculate the azimut angle offset for a given gain in db:
157  // phideg = (2*acos(10^(targetgaindb/(20*n))))*180/pi
158  // e.g., with a 60 deg beamwidth, gain is -20dB at +- 74.945 degrees from boresight
159 
160  // phi, theta, beamwidth,
161  // orientation, maxGain,
162  // expectedGain, condition
164  60,
165  0,
166  0,
167  0,
168  EQUAL),
169  TestCase::QUICK);
171  60,
172  0,
173  0,
174  -3,
175  EQUAL),
176  TestCase::QUICK);
178  60,
179  0,
180  0,
181  -3,
182  EQUAL),
183  TestCase::QUICK);
185  60,
186  0,
187  0,
188  -20,
189  LESSTHAN),
190  TestCase::QUICK);
192  60,
193  0,
194  0,
195  -20,
196  LESSTHAN),
197  TestCase::QUICK);
199  60,
200  0,
201  0,
202  -20,
203  LESSTHAN),
204  TestCase::QUICK);
206  60,
207  0,
208  0,
209  -20,
210  LESSTHAN),
211  TestCase::QUICK);
213  60,
214  0,
215  0,
216  -20,
217  LESSTHAN),
218  TestCase::QUICK);
220  60,
221  0,
222  0,
223  -20,
224  LESSTHAN),
225  TestCase::QUICK);
227  60,
228  0,
229  0,
230  -20,
231  LESSTHAN),
232  TestCase::QUICK);
234  60,
235  0,
236  0,
237  -20,
238  LESSTHAN),
239  TestCase::QUICK);
240 
241  // test positive orientation
243  60,
244  60,
245  0,
246  0,
247  EQUAL),
248  TestCase::QUICK);
250  60,
251  60,
252  0,
253  -3,
254  EQUAL),
255  TestCase::QUICK);
257  60,
258  60,
259  0,
260  -3,
261  EQUAL),
262  TestCase::QUICK);
264  60,
265  60,
266  0,
267  -20,
268  LESSTHAN),
269  TestCase::QUICK);
271  60,
272  60,
273  0,
274  -20,
275  LESSTHAN),
276  TestCase::QUICK);
278  60,
279  60,
280  0,
281  -20,
282  LESSTHAN),
283  TestCase::QUICK);
285  60,
286  60,
287  0,
288  -20,
289  LESSTHAN),
290  TestCase::QUICK);
292  60,
293  60,
294  0,
295  -20,
296  LESSTHAN),
297  TestCase::QUICK);
299  60,
300  60,
301  0,
302  -20,
303  LESSTHAN),
304  TestCase::QUICK);
306  60,
307  60,
308  0,
309  -20,
310  LESSTHAN),
311  TestCase::QUICK);
313  60,
314  60,
315  0,
316  -20,
317  LESSTHAN),
318  TestCase::QUICK);
319 
320  // test negative orientation and different beamwidths
321  // with a 100 deg beamwidth, gain is -20dB at +- 117.47 degrees from boresight
323  100,
324  -150,
325  0,
326  0,
327  EQUAL),
328  TestCase::QUICK);
330  100,
331  -150,
332  0,
333  -3,
334  EQUAL),
335  TestCase::QUICK);
337  100,
338  -150,
339  0,
340  -3,
341  EQUAL),
342  TestCase::QUICK);
343  AddTestCase(
345  100,
346  -150,
347  0,
348  -20,
349  EQUAL),
350  TestCase::QUICK);
351  AddTestCase(
353  100,
354  -150,
355  0,
356  -20,
357  EQUAL),
358  TestCase::QUICK);
360  100,
361  -150,
362  0,
363  -20,
364  LESSTHAN),
365  TestCase::QUICK);
367  100,
368  -150,
369  0,
370  -20,
371  LESSTHAN),
372  TestCase::QUICK);
374  100,
375  -150,
376  0,
377  -20,
378  LESSTHAN),
379  TestCase::QUICK);
381  100,
382  -150,
383  0,
384  -20,
385  LESSTHAN),
386  TestCase::QUICK);
388  100,
389  -150,
390  0,
391  -20,
392  LESSTHAN),
393  TestCase::QUICK);
394  // with a 150 deg beamwidth, gain is -10dB at +- 124.93 degrees from boresight, and -20dB at +-
395  // 155.32 degrees from boresight
397  150,
398  -150,
399  0,
400  0,
401  EQUAL),
402  TestCase::QUICK);
404  150,
405  -150,
406  0,
407  -3,
408  EQUAL),
409  TestCase::QUICK);
411  150,
412  -150,
413  0,
414  -3,
415  EQUAL),
416  TestCase::QUICK);
417  AddTestCase(
419  150,
420  -150,
421  0,
422  -10,
423  EQUAL),
424  TestCase::QUICK);
425  AddTestCase(
427  150,
428  -150,
429  0,
430  -10,
431  EQUAL),
432  TestCase::QUICK);
433  AddTestCase(
435  150,
436  -150,
437  0,
438  -20,
439  EQUAL),
440  TestCase::QUICK);
441  AddTestCase(
443  150,
444  -150,
445  0,
446  -20,
447  EQUAL),
448  TestCase::QUICK);
450  150,
451  -150,
452  0,
453  -20,
454  LESSTHAN),
455  TestCase::QUICK);
457  150,
458  -150,
459  0,
460  -20,
461  LESSTHAN),
462  TestCase::QUICK);
463  // test flat beam, with beamwidth=360 deg
465  360,
466  0,
467  0,
468  0,
469  EQUAL),
470  TestCase::QUICK);
472  360,
473  0,
474  0,
475  0,
476  EQUAL),
477  TestCase::QUICK);
479  360,
480  0,
481  0,
482  0,
483  EQUAL),
484  TestCase::QUICK);
486  360,
487  0,
488  0,
489  0,
490  EQUAL),
491  TestCase::QUICK);
493  360,
494  0,
495  0,
496  0,
497  EQUAL),
498  TestCase::QUICK);
499 
500  // test maxGain
502  60,
503  0,
504  10,
505  10,
506  EQUAL),
507  TestCase::QUICK);
509  60,
510  0,
511  22,
512  19,
513  EQUAL),
514  TestCase::QUICK);
516  60,
517  0,
518  -4,
519  -7,
520  EQUAL),
521  TestCase::QUICK);
523  60,
524  0,
525  10,
526  -10,
527  LESSTHAN),
528  TestCase::QUICK);
530  60,
531  0,
532  -20,
533  -40,
534  LESSTHAN),
535  TestCase::QUICK);
537  60,
538  0,
539  40,
540  20,
541  LESSTHAN),
542  TestCase::QUICK);
544  100,
545  -150,
546  2,
547  2,
548  EQUAL),
549  TestCase::QUICK);
551  100,
552  -150,
553  4,
554  1,
555  EQUAL),
556  TestCase::QUICK);
558  100,
559  -150,
560  -1,
561  -4,
562  EQUAL),
563  TestCase::QUICK);
564 
565  // test elevation angle
567  60,
568  0,
569  0,
570  -3,
571  EQUAL),
572  TestCase::QUICK);
574  60,
575  0,
576  0,
577  -6,
578  EQUAL),
579  TestCase::QUICK);
581  60,
582  0,
583  0,
584  -6,
585  EQUAL),
586  TestCase::QUICK);
588  60,
589  0,
590  0,
591  -20,
592  LESSTHAN),
593  TestCase::QUICK);
595  60,
596  0,
597  0,
598  -20,
599  LESSTHAN),
600  TestCase::QUICK);
602  60,
603  60,
604  0,
605  -3,
606  EQUAL),
607  TestCase::QUICK);
609  60,
610  60,
611  0,
612  -6,
613  EQUAL),
614  TestCase::QUICK);
616  60,
617  60,
618  0,
619  -6,
620  EQUAL),
621  TestCase::QUICK);
622  AddTestCase(
624  60,
625  60,
626  0,
627  -20,
628  LESSTHAN),
629  TestCase::QUICK);
630  AddTestCase(
632  100,
633  -150,
634  0,
635  -3,
636  EQUAL),
637  TestCase::QUICK);
638  AddTestCase(
640  100,
641  -150,
642  0,
643  -6,
644  EQUAL),
645  TestCase::QUICK);
646  AddTestCase(
648  100,
649  -150,
650  0,
651  -6,
652  EQUAL),
653  TestCase::QUICK);
655  100,
656  -150,
657  0,
658  -20,
659  LESSTHAN),
660  TestCase::QUICK);
662  60,
663  0,
664  10,
665  7,
666  EQUAL),
667  TestCase::QUICK);
669  60,
670  0,
671  22,
672  16,
673  EQUAL),
674  TestCase::QUICK);
676  60,
677  0,
678  -4,
679  -10,
680  EQUAL),
681  TestCase::QUICK);
683  60,
684  0,
685  10,
686  -13,
687  LESSTHAN),
688  TestCase::QUICK);
690  60,
691  0,
692  -20,
693  -43,
694  LESSTHAN),
695  TestCase::QUICK);
697  60,
698  0,
699  40,
700  17,
701  LESSTHAN),
702  TestCase::QUICK);
704  100,
705  -150,
706  2,
707  -1,
708  EQUAL),
709  TestCase::QUICK);
711  100,
712  -150,
713  4,
714  -2,
715  EQUAL),
716  TestCase::QUICK);
718  100,
719  -150,
720  -1,
721  -7,
722  EQUAL),
723  TestCase::QUICK);
724 }
725 
CosineAntennaModel Test.
double m_expectedGain
Expected gain.
double m_b
Horizontal and Vertical Beamwidth.
CosineAntennaModelGainTestCondition m_cond
Test condition.
static std::string BuildNameString(Angles a, double b, double o, double g)
Build the test name.
void DoRun() override
Implementation to actually run this TestCase.
CosineAntennaModelTestCase(Angles a, double b, double o, double g, double expectedGainDb, CosineAntennaModelGainTestCondition cond)
Constructor.
CosineAntennaModel TestSuite.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
CosineAntennaModelGainTestCondition
Test condition (equal to or less than)
@ LESSTHAN
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
Definition: test.h:790
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition: test.h:510
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
static CosineAntennaModelTestSuite g_staticCosineAntennaModelTestSuiteInstance
Static variable for test initialization.