A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
buildings-shadowing-test.cc
Go to the documentation of this file.
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 #include <ns3/mobility-model.h>
31 #include <ns3/mobility-building-info.h>
32 #include <ns3/constant-position-mobility-model.h>
33 
35 
36 NS_LOG_COMPONENT_DEFINE ("BuildingsShadowingTest");
37 
38 
39 namespace ns3 {
40 
41 
42 
54  : TestSuite ("buildings-shadowing-test", SYSTEM)
55 {
56 
57  LogComponentEnable ("BuildingsShadowingTest", LOG_LEVEL_ALL);
58 
59  // Test #1 Outdoor Model
60  AddTestCase (new BuildingsShadowingTestCase (1, 2, 148.86, 7.0, "Outdoor Shadowing"), TestCase::QUICK);
61 
62  // Test #2 Indoor model
63  AddTestCase (new BuildingsShadowingTestCase (5, 6, 88.5724, 8.0, "Indoor Shadowing"), TestCase::QUICK);
64 
65  // Test #3 Indoor -> Outdoor
66  AddTestCase (new BuildingsShadowingTestCase (9, 10, 85.0012, 8.6, "Indoor -> Outdoor Shadowing"), TestCase::QUICK);
67 
68 }
69 
71 
72 
77 BuildingsShadowingTestCase::BuildingsShadowingTestCase ( uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
78  : TestCase ("SHADOWING calculation: " + name),
79  m_mobilityModelIndex1 (m1),
80  m_mobilityModelIndex2 (m2),
81  m_lossRef (refValue),
82  m_sigmaRef (sigmaRef)
83 {
84 }
85 
87 {
88 }
89 
90 void
92 {
93  NS_LOG_FUNCTION (this);
94 
95  // the building basically occupies the negative x plane, so any node
96  // in this area will fall in the building
97  Ptr<Building> building1 = CreateObject<Building> ();
98  building1->SetBoundaries (Box (-3000, -1, -4000, 4000.0, 0.0, 12));
101  building1->SetNFloors (3);
102 
105 
106  std::vector<double> loss;
107  double sum = 0.0;
108  double sumSquared = 0.0;
109  int samples = 10000;
110  for (int i = 0; i < samples; i++)
111  {
112  Ptr<HybridBuildingsPropagationLossModel> propagationLossModel = CreateObject<HybridBuildingsPropagationLossModel> ();
113  loss.push_back (propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef);
114  sum += loss.at (loss.size () - 1);
115  sumSquared += (loss.at (loss.size () - 1) * loss.at (loss.size () - 1));
116  }
117  double mean = sum / samples;
118  double sigma = std::sqrt (sumSquared / samples - (mean * mean));
119  // test whether the distribution falls in the 99% confidence interval, as expected with a nornal distribution
120  double ci = (2.575829303549 * sigma) / std::sqrt (samples);
121 
122  NS_LOG_INFO ("Mean from simulation " << mean << ", sigma " << sigma << ", reference value " << m_sigmaRef << ", CI(99%) " << ci);
123 
124  NS_TEST_ASSERT_MSG_EQ_TOL (std::fabs (mean), 0.0, ci, "Wrong shadowing distribution !");
126 }
127 
128 
129 
132 {
133 
134  /*
135  * The purpose of this method is to defer the creation of the
136  * MobilityModel instances to when DoRun() is called. In a previous
137  * version, MobilityModel instances where created directly in the
138  * constructor of the test suite, which caused subtle bugs due to
139  * "static initialization order fiasco". An example of such a subtle
140  * bug is that logging via NS_LOG failed for some modules.
141  *
142  */
143 
144  double hm = 1;
145  double hb = 30;
146  double henbHeight = 10.0;
147 
149 
150  switch (index)
151  {
152  case 1:
153  mm = CreateObject<ConstantPositionMobilityModel> ();
154  mm->SetPosition (Vector (0.0, 0.0, hb));
155  break;
156 
157  case 2:
158  mm = CreateObject<ConstantPositionMobilityModel> ();
159  mm->SetPosition (Vector (2000, 0.0, hm));
160  break;
161 
162  case 3:
163  mm = CreateObject<ConstantPositionMobilityModel> ();
164  mm->SetPosition (Vector (100, 0.0, hm));
165  break;
166 
167  case 4:
168  mm = CreateObject<ConstantPositionMobilityModel> ();
169  mm->SetPosition (Vector (900, 0.0, hm));
170  break;
171 
172  case 5:
173  mm = CreateObject<ConstantPositionMobilityModel> ();
174  mm->SetPosition (Vector (-5, 0.0, hm));
175  break;
176 
177  case 6:
178  mm = CreateObject<ConstantPositionMobilityModel> ();
179  mm->SetPosition (Vector (-5, 30, henbHeight));
180  break;
181 
182  case 7:
183  mm = CreateObject<ConstantPositionMobilityModel> ();
184  mm->SetPosition (Vector (-2000, 0.0, hm));
185  break;
186 
187  case 8:
188  mm = CreateObject<ConstantPositionMobilityModel> ();
189  mm->SetPosition (Vector (-100, 0.0, hm));
190  break;
191 
192  case 9:
193  mm = CreateObject<ConstantPositionMobilityModel> ();
194  mm->SetPosition (Vector (0, 0.0, hm));
195  break;
196 
197  case 10:
198  mm = CreateObject<ConstantPositionMobilityModel> ();
199  mm->SetPosition (Vector (-100, 0.0, henbHeight));
200  break;
201 
202  case 11:
203  mm = CreateObject<ConstantPositionMobilityModel> ();
204  mm->SetPosition (Vector (-500, 0.0, henbHeight));
205  break;
206 
207  default:
208  mm = 0;
209  break;
210  }
211  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
212  mm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
214  return mm;
215 }
216 
217 
218 
219 
220 } // namespace ns3