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  NS_UNUSED (m_sigmaRef); // suppress private field unused warning
85 }
86 
88 {
89 }
90 
91 void
93 {
94  NS_LOG_FUNCTION (this);
95 
96  // the building basically occupies the negative x plane, so any node
97  // in this area will fall in the building
98  Ptr<Building> building1 = CreateObject<Building> ();
99  building1->SetBoundaries (Box (-3000, -1, -4000, 4000.0, 0.0, 12));
100  building1->SetBuildingType (Building::Residential);
101  building1->SetExtWallsType (Building::ConcreteWithWindows);
102  building1->SetNFloors (3);
103 
106 
107  std::vector<double> loss;
108  double sum = 0.0;
109  double sumSquared = 0.0;
110  int samples = 10000;
111  for (int i = 0; i < samples; i++)
112  {
113  Ptr<HybridBuildingsPropagationLossModel> propagationLossModel = CreateObject<HybridBuildingsPropagationLossModel> ();
114  loss.push_back (propagationLossModel->DoCalcRxPower (0.0, mma, mmb) + m_lossRef);
115  sum += loss.at (loss.size () - 1);
116  sumSquared += (loss.at (loss.size () - 1) * loss.at (loss.size () - 1));
117  }
118  double mean = sum / samples;
119  double sigma = std::sqrt (sumSquared / samples - (mean * mean));
120  // test whether the distribution falls in the 99% confidence interval, as expected with a nornal distribution
121  double ci = (2.575829303549 * sigma) / std::sqrt (samples);
122 
123  NS_LOG_INFO ("Mean from simulation " << mean << ", sigma " << sigma << ", reference value " << m_sigmaRef << ", CI(99%) " << ci);
124 
125  NS_TEST_ASSERT_MSG_EQ_TOL (std::fabs (mean), 0.0, ci, "Wrong shadowing distribution !");
127 }
128 
129 
130 
133 {
134 
135  /*
136  * The purpose of this method is to defer the creation of the
137  * MobilityModel instances to when DoRun() is called. In a previous
138  * version, MobilityModel instances where created directly in the
139  * constructor of the test suite, which caused subtle bugs due to
140  * "static initialization order fiasco". An example of such a subtle
141  * bug is that logging via NS_LOG failed for some modules.
142  *
143  */
144 
145  double hm = 1;
146  double hb = 30;
147  double henbHeight = 10.0;
148 
150 
151  switch (index)
152  {
153  case 1:
154  mm = CreateObject<ConstantPositionMobilityModel> ();
155  mm->SetPosition (Vector (0.0, 0.0, hb));
156  break;
157 
158  case 2:
159  mm = CreateObject<ConstantPositionMobilityModel> ();
160  mm->SetPosition (Vector (2000, 0.0, hm));
161  break;
162 
163  case 3:
164  mm = CreateObject<ConstantPositionMobilityModel> ();
165  mm->SetPosition (Vector (100, 0.0, hm));
166  break;
167 
168  case 4:
169  mm = CreateObject<ConstantPositionMobilityModel> ();
170  mm->SetPosition (Vector (900, 0.0, hm));
171  break;
172 
173  case 5:
174  mm = CreateObject<ConstantPositionMobilityModel> ();
175  mm->SetPosition (Vector (-5, 0.0, hm));
176  break;
177 
178  case 6:
179  mm = CreateObject<ConstantPositionMobilityModel> ();
180  mm->SetPosition (Vector (-5, 30, henbHeight));
181  break;
182 
183  case 7:
184  mm = CreateObject<ConstantPositionMobilityModel> ();
185  mm->SetPosition (Vector (-2000, 0.0, hm));
186  break;
187 
188  case 8:
189  mm = CreateObject<ConstantPositionMobilityModel> ();
190  mm->SetPosition (Vector (-100, 0.0, hm));
191  break;
192 
193  case 9:
194  mm = CreateObject<ConstantPositionMobilityModel> ();
195  mm->SetPosition (Vector (0, 0.0, hm));
196  break;
197 
198  case 10:
199  mm = CreateObject<ConstantPositionMobilityModel> ();
200  mm->SetPosition (Vector (-100, 0.0, henbHeight));
201  break;
202 
203  case 11:
204  mm = CreateObject<ConstantPositionMobilityModel> ();
205  mm->SetPosition (Vector (-500, 0.0, henbHeight));
206  break;
207 
208  default:
209  mm = 0;
210  break;
211  }
212  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> ();
213  mm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
215  return mm;
216 }
217 
218 
219 
220 
221 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#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:264
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)
BuildingsShadowingTestCase(uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
static void Destroy(void)
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:172
static BuildingsShadowingTestSuite buildingsShadowingTestSuite
void SetPosition(const Vector &position)
Fast test.
Definition: test.h:857
#define NS_UNUSED(x)
Definition: unused.h:5
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311