A Discrete-Event Network Simulator
API
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 using namespace ns3;
37 
38 NS_LOG_COMPONENT_DEFINE ("BuildingsShadowingTest");
39 
40 
41 /*
42 * Test 1.1 Shadowing compound test
43 *
44 * This TestSuite tests the shadowing model of BuildingPathlossModel
45 * by reproducing several communication scenarios
46 */
47 
48 
50  : TestSuite ("buildings-shadowing-test", SYSTEM)
51 {
52 
53  LogComponentEnable ("BuildingsShadowingTest", LOG_LEVEL_ALL);
54 
55  // Test #1 Outdoor Model
56  AddTestCase (new BuildingsShadowingTestCase (1, 2, 148.86, 7.0, "Outdoor Shadowing"), TestCase::QUICK);
57 
58  // Test #2 Indoor model
59  AddTestCase (new BuildingsShadowingTestCase (5, 6, 88.5724, 8.0, "Indoor Shadowing"), TestCase::QUICK);
60 
61  // Test #3 Indoor -> Outdoor
62  AddTestCase (new BuildingsShadowingTestCase (9, 10, 85.0012, 8.6, "Indoor -> Outdoor Shadowing"), TestCase::QUICK);
63 
64 }
65 
68 
69 
70 /*
71 * TestCase
72 */
73 
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 
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<HybridBuildingsPropagationLossModel> propagationLossModel = CreateObject<HybridBuildingsPropagationLossModel> ();
101 
102  std::vector<double> loss;
103  double sum = 0.0;
104  double sumSquared = 0.0;
105  int samples = 1000;
106  for (int i = 0; i < samples; i++)
107  {
110  double shadowingLoss = propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef;
111  double shadowingLoss2 = propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef;
112  NS_TEST_ASSERT_MSG_EQ_TOL (shadowingLoss, shadowingLoss2, 0.001,
113  "Shadowing is not constant for the same mobility model pair!");
114  loss.push_back (shadowingLoss);
115  sum += shadowingLoss;
116  sumSquared += (shadowingLoss * shadowingLoss);
117  }
118  double sampleMean = sum / samples;
119  double sampleVariance = (sumSquared - (sum * sum / samples)) / (samples - 1);
120  double sampleStd = std::sqrt (sampleVariance);
121 
122  // test whether the sample mean falls in the 99% confidence interval
123  const double zn995 = 2.575829303549; // 99.5 quantile of the normal distribution
124  double ci = (zn995 * sampleStd) / std::sqrt (samples);
125  NS_LOG_INFO ("SampleMean from simulation " << sampleMean << ", sampleStd " << sampleStd << ", reference value " << m_sigmaRef << ", CI(99%) " << ci);
126  NS_TEST_ASSERT_MSG_EQ_TOL (std::fabs (sampleMean), 0.0, ci, "Wrong shadowing distribution !");
127 
128  // test whether the sample variance falls in the 99% confidence interval
129  // since the shadowing is gaussian, its sample variance follows the
130  // chi2 distribution with samples-1 degrees of freedom
131  double chi2 = (samples - 1) * sampleVariance / (m_sigmaRef*m_sigmaRef);
132  const double zchi2_005 = 887.621135217515; // 0.5% quantile of the chi2 distribution
133  const double zchi2_995 = 1117.89045267865; // 99.5% quantile of the chi2 distribution
134  NS_TEST_ASSERT_MSG_GT (chi2, zchi2_005, "sample variance lesser than expected");
135  NS_TEST_ASSERT_MSG_LT (chi2, zchi2_995, "sample variance greater than expected");
136 
137  Simulator::Destroy ();
138 }
139 
140 
141 
144 {
145 
146  /*
147  * The purpose of this method is to defer the creation of the
148  * MobilityModel instances to when DoRun() is called. In a previous
149  * version, MobilityModel instances where created directly in the
150  * constructor of the test suite, which caused subtle bugs due to
151  * "static initialization order fiasco". An example of such a subtle
152  * bug is that logging via NS_LOG failed for some modules.
153  *
154  */
155 
156  double hm = 1;
157  double hb = 30;
158  double henbHeight = 10.0;
159 
161 
162  switch (index)
163  {
164  case 1:
165  mm = CreateObject<ConstantPositionMobilityModel> ();
166  mm->SetPosition (Vector (0.0, 0.0, hb));
167  break;
168 
169  case 2:
170  mm = CreateObject<ConstantPositionMobilityModel> ();
171  mm->SetPosition (Vector (2000, 0.0, hm));
172  break;
173 
174  case 3:
175  mm = CreateObject<ConstantPositionMobilityModel> ();
176  mm->SetPosition (Vector (100, 0.0, hm));
177  break;
178 
179  case 4:
180  mm = CreateObject<ConstantPositionMobilityModel> ();
181  mm->SetPosition (Vector (900, 0.0, hm));
182  break;
183 
184  case 5:
185  mm = CreateObject<ConstantPositionMobilityModel> ();
186  mm->SetPosition (Vector (-5, 0.0, hm));
187  break;
188 
189  case 6:
190  mm = CreateObject<ConstantPositionMobilityModel> ();
191  mm->SetPosition (Vector (-5, 30, henbHeight));
192  break;
193 
194  case 7:
195  mm = CreateObject<ConstantPositionMobilityModel> ();
196  mm->SetPosition (Vector (-2000, 0.0, hm));
197  break;
198 
199  case 8:
200  mm = CreateObject<ConstantPositionMobilityModel> ();
201  mm->SetPosition (Vector (-100, 0.0, hm));
202  break;
203 
204  case 9:
205  mm = CreateObject<ConstantPositionMobilityModel> ();
206  mm->SetPosition (Vector (0, 0.0, hm));
207  break;
208 
209  case 10:
210  mm = CreateObject<ConstantPositionMobilityModel> ();
211  mm->SetPosition (Vector (-100, 0.0, henbHeight));
212  break;
213 
214  case 11:
215  mm = CreateObject<ConstantPositionMobilityModel> ();
216  mm->SetPosition (Vector (-500, 0.0, henbHeight));
217  break;
218 
219  default:
220  mm = 0;
221  break;
222  }
223  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
224  mm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
225  buildingInfo->MakeConsistent (mm);
226  return mm;
227 }
static BuildingsShadowingTestSuite buildingsShadowingTestSuite
Static variable for test initialization.
uint16_t m_mobilityModelIndex2
Second MobilityModel Index.
Ptr< MobilityModel > CreateMobilityModel(uint16_t index)
Create a mobility model based on its index.
uint16_t m_mobilityModelIndex1
First MobilityModel Index.
double m_lossRef
pathloss value (without shadowing)
BuildingsShadowingTestCase(uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
Constructor.
double m_sigmaRef
pathloss standard deviation value reference value
virtual void DoRun(void)
Implementation to actually run this TestCase.
a 3d box
Definition: box.h:35
void SetPosition(const Vector &position)
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#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:675
#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:825
#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:323
const double m1
First component modulus, 232 - 209.
Definition: rng-stream.cc:58
const double m2
Second component modulus, 232 - 22853.
Definition: rng-stream.cc:61
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361