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));
99  building1->SetBuildingType (Building::Residential);
100  building1->SetExtWallsType (Building::ConcreteWithWindows);
101  building1->SetNFloors (3);
102 
103  Ptr<HybridBuildingsPropagationLossModel> propagationLossModel = CreateObject<HybridBuildingsPropagationLossModel> ();
104 
105  std::vector<double> loss;
106  double sum = 0.0;
107  double sumSquared = 0.0;
108  int samples = 1000;
109  for (int i = 0; i < samples; i++)
110  {
113  double shadowingLoss = propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef;
114  double shadowingLoss2 = propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef;
115  NS_TEST_ASSERT_MSG_EQ_TOL (shadowingLoss, shadowingLoss2, 0.001,
116  "Shadowing is not constant for the same mobility model pair!");
117  loss.push_back (shadowingLoss);
118  sum += shadowingLoss;
119  sumSquared += (shadowingLoss * shadowingLoss);
120  }
121  double sampleMean = sum / samples;
122  double sampleVariance = (sumSquared - (sum * sum / samples)) / (samples - 1);
123  double sampleStd = std::sqrt (sampleVariance);
124 
125  // test whether the sample mean falls in the 99% confidence interval
126  const double zn995 = 2.575829303549; // 99.5 quantile of the normal distribution
127  double ci = (zn995 * sampleStd) / std::sqrt (samples);
128  NS_LOG_INFO ("SampleMean from simulation " << sampleMean << ", sampleStd " << sampleStd << ", reference value " << m_sigmaRef << ", CI(99%) " << ci);
129  NS_TEST_ASSERT_MSG_EQ_TOL (std::fabs (sampleMean), 0.0, ci, "Wrong shadowing distribution !");
130 
131  // test whether the sample variance falls in the 99% confidence interval
132  // since the shadowing is gaussian, its sample variance follows the
133  // chi2 distribution with samples-1 degrees of freedom
134  double chi2 = (samples - 1) * sampleVariance / (m_sigmaRef*m_sigmaRef);
135  const double zchi2_005 = 887.621135217515; // 0.5% quantile of the chi2 distribution
136  const double zchi2_995 = 1117.89045267865; // 99.5% quantile of the chi2 distribution
137  NS_TEST_ASSERT_MSG_GT (chi2, zchi2_005, "sample variance lesser than expected");
138  NS_TEST_ASSERT_MSG_LT (chi2, zchi2_995, "sample variance greater than expected");
139 
141 }
142 
143 
144 
147 {
148 
149  /*
150  * The purpose of this method is to defer the creation of the
151  * MobilityModel instances to when DoRun() is called. In a previous
152  * version, MobilityModel instances where created directly in the
153  * constructor of the test suite, which caused subtle bugs due to
154  * "static initialization order fiasco". An example of such a subtle
155  * bug is that logging via NS_LOG failed for some modules.
156  *
157  */
158 
159  double hm = 1;
160  double hb = 30;
161  double henbHeight = 10.0;
162 
164 
165  switch (index)
166  {
167  case 1:
168  mm = CreateObject<ConstantPositionMobilityModel> ();
169  mm->SetPosition (Vector (0.0, 0.0, hb));
170  break;
171 
172  case 2:
173  mm = CreateObject<ConstantPositionMobilityModel> ();
174  mm->SetPosition (Vector (2000, 0.0, hm));
175  break;
176 
177  case 3:
178  mm = CreateObject<ConstantPositionMobilityModel> ();
179  mm->SetPosition (Vector (100, 0.0, hm));
180  break;
181 
182  case 4:
183  mm = CreateObject<ConstantPositionMobilityModel> ();
184  mm->SetPosition (Vector (900, 0.0, hm));
185  break;
186 
187  case 5:
188  mm = CreateObject<ConstantPositionMobilityModel> ();
189  mm->SetPosition (Vector (-5, 0.0, hm));
190  break;
191 
192  case 6:
193  mm = CreateObject<ConstantPositionMobilityModel> ();
194  mm->SetPosition (Vector (-5, 30, henbHeight));
195  break;
196 
197  case 7:
198  mm = CreateObject<ConstantPositionMobilityModel> ();
199  mm->SetPosition (Vector (-2000, 0.0, hm));
200  break;
201 
202  case 8:
203  mm = CreateObject<ConstantPositionMobilityModel> ();
204  mm->SetPosition (Vector (-100, 0.0, hm));
205  break;
206 
207  case 9:
208  mm = CreateObject<ConstantPositionMobilityModel> ();
209  mm->SetPosition (Vector (0, 0.0, hm));
210  break;
211 
212  case 10:
213  mm = CreateObject<ConstantPositionMobilityModel> ();
214  mm->SetPosition (Vector (-100, 0.0, henbHeight));
215  break;
216 
217  case 11:
218  mm = CreateObject<ConstantPositionMobilityModel> ();
219  mm->SetPosition (Vector (-500, 0.0, henbHeight));
220  break;
221 
222  default:
223  mm = 0;
224  break;
225  }
226  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
227  mm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
229  return mm;
230 }
231 
232 
233 
234 
235 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:326
NS_LOG_COMPONENT_DEFINE("BuildingsShadowingTest")
A suite of tests to run.
Definition: test.h:1025
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_LOG_INFO(msg)
Definition: log.h:298
encapsulates test code
Definition: test.h:849
a 3d vector
Definition: vector.h:31
a 3d box
Definition: box.h:33
static void MakeConsistent(Ptr< MobilityModel > bmm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:773
BuildingsShadowingTestCase(uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
TestCase.
BuildingsShadowingTestSuite()
Test 1.1 Shadowing compound test.
void AggregateObject(Ptr< Object > other)
Definition: object.cc:243
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
Ptr< MobilityModel > CreateMobilityModel(uint16_t index)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
static BuildingsShadowingTestSuite buildingsShadowingTestSuite
void SetPosition(const Vector &position)
Fast test.
Definition: test.h:857
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:688
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311