A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
buildings-shadowing-test.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Marco Miozzo <marco.miozzo@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include <ns3/simulator.h>
23 #include <ns3/log.h>
24 #include <ns3/hybrid-buildings-propagation-loss-model.h>
25 #include <ns3/string.h>
26 #include <ns3/double.h>
27 #include <ns3/building.h>
28 #include <ns3/enum.h>
29 #include <ns3/buildings-helper.h>
30 
31 #include "buildings-shadowing-test.h"
32 
33 NS_LOG_COMPONENT_DEFINE ("BuildingsShadowingTest");
34 
35 
36 namespace ns3 {
37 
38 
39 
51  : TestSuite ("buildings-shadowing-test", SYSTEM)
52 {
53 
54  LogComponentEnable ("BuildingsShadowingTest", LOG_LEVEL_ALL);
55 
56  // Test #1 Outdoor Model
57  AddTestCase (new BuildingsShadowingTestCase (1, 2, 148.86, 7.0, "Outdoor Shadowing"), TestCase::QUICK);
58 
59  // Test #2 Indoor model
60  AddTestCase (new BuildingsShadowingTestCase (5, 6, 88.5724, 8.0, "Indoor Shadowing"), TestCase::QUICK);
61 
62  // Test #3 Indoor -> Outdoor
63  AddTestCase (new BuildingsShadowingTestCase (9, 10, 85.0012, 8.6, "Indoor -> Outdoor Shadowing"), TestCase::QUICK);
64 
65 }
66 
67 static BuildingsShadowingTestSuite buildingsShadowingTestSuite;
68 
69 
74 BuildingsShadowingTestCase::BuildingsShadowingTestCase ( uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
75  : TestCase ("SHADOWING calculation: " + name),
76  m_mobilityModelIndex1 (m1),
77  m_mobilityModelIndex2 (m2),
78  m_lossRef (refValue),
79  m_sigmaRef (sigmaRef)
80 {
81 }
82 
83 BuildingsShadowingTestCase::~BuildingsShadowingTestCase ()
84 {
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION (this);
91 
92  // the building basically occupies the negative x plane, so any node
93  // in this area will fall in the building
94  Ptr<Building> building1 = CreateObject<Building> ();
95  building1->SetBoundaries (Box (-3000, -1, -4000, 4000.0, 0.0, 12));
96  building1->SetBuildingType (Building::Residential);
97  building1->SetExtWallsType (Building::ConcreteWithWindows);
98  building1->SetNFloors (3);
99 
100  Ptr<MobilityModel> mma = CreateMobilityModel (m_mobilityModelIndex1);
101  Ptr<MobilityModel> mmb = CreateMobilityModel (m_mobilityModelIndex2);
102 
103  std::vector<double> loss;
104  double sum = 0.0;
105  double sumSquared = 0.0;
106  int samples = 10000;
107  for (int i = 0; i < samples; i++)
108  {
109  Ptr<HybridBuildingsPropagationLossModel> propagationLossModel = CreateObject<HybridBuildingsPropagationLossModel> ();
110  loss.push_back (propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef);
111  sum += loss.at (loss.size () - 1);
112  sumSquared += (loss.at (loss.size () - 1) * loss.at (loss.size () - 1));
113  }
114  double mean = sum / samples;
115  double sigma = std::sqrt (sumSquared / samples - (mean * mean));
116  // test whether the distribution falls in the 99% confidence interval, as expected with a nornal distribution
117  double ci = (2.575829303549 * sigma) / std::sqrt (samples);
118 
119  NS_LOG_INFO ("Mean from simulation " << mean << ", sigma " << sigma << ", reference value " << m_sigmaRef << ", CI(99%) " << ci);
120 
121  NS_TEST_ASSERT_MSG_EQ_TOL (std::fabs (mean), 0.0, ci, "Wrong shadowing distribution !");
123 }
124 
125 
126 
128 BuildingsShadowingTestCase::CreateMobilityModel (uint16_t index)
129 {
130 
131  /*
132  * The purpose of this method is to defer the creation of the
133  * MobilityModel instances to when DoRun() is called. In a previous
134  * version, MobilityModel instances where created directly in the
135  * constructor of the test suite, which caused subtle bugs due to
136  * "static initialization order fiasco". An example of such a subtle
137  * bug is that logging via NS_LOG failed for some modules.
138  *
139  */
140 
141  double hm = 1;
142  double hb = 30;
143  double henbHeight = 10.0;
144 
146 
147  switch (index)
148  {
149  case 1:
150  mm = CreateObject<BuildingsMobilityModel> ();
151  mm->SetPosition (Vector (0.0, 0.0, hb));
152  break;
153 
154  case 2:
155  mm = CreateObject<BuildingsMobilityModel> ();
156  mm->SetPosition (Vector (2000, 0.0, hm));
157  break;
158 
159  case 3:
160  mm = CreateObject<BuildingsMobilityModel> ();
161  mm->SetPosition (Vector (100, 0.0, hm));
162  break;
163 
164  case 4:
165  mm = CreateObject<BuildingsMobilityModel> ();
166  mm->SetPosition (Vector (900, 0.0, hm));
167  break;
168 
169  case 5:
170  mm = CreateObject<BuildingsMobilityModel> ();
171  mm->SetPosition (Vector (-5, 0.0, hm));
172  break;
173 
174  case 6:
175  mm = CreateObject<BuildingsMobilityModel> ();
176  mm->SetPosition (Vector (-5, 30, henbHeight));
177  break;
178 
179  case 7:
180  mm = CreateObject<BuildingsMobilityModel> ();
181  mm->SetPosition (Vector (-2000, 0.0, hm));
182  break;
183 
184  case 8:
185  mm = CreateObject<BuildingsMobilityModel> ();
186  mm->SetPosition (Vector (-100, 0.0, hm));
187  break;
188 
189  case 9:
190  mm = CreateObject<BuildingsMobilityModel> ();
191  mm->SetPosition (Vector (0, 0.0, hm));
192  break;
193 
194  case 10:
195  mm = CreateObject<BuildingsMobilityModel> ();
196  mm->SetPosition (Vector (-100, 0.0, henbHeight));
197  break;
198 
199  case 11:
200  mm = CreateObject<BuildingsMobilityModel> ();
201  mm->SetPosition (Vector (-500, 0.0, henbHeight));
202  break;
203 
204  default:
205  mm = 0;
206  break;
207  }
208  BuildingsHelper::MakeConsistent (mm);
209  return mm;
210 }
211 
212 
213 
214 
215 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
A suite of tests to run.
Definition: test.h:962
virtual void DoRun(void)
Implementation to actually run this test case.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:834
a 3d vector
Definition: vector.h:31
a 3d box
Definition: box.h:33
BuildingsShadowingTestCase(uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
static void Destroy(void)
Definition: simulator.cc:121
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311