A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
buildings-shadowing-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7 * Nicola Baldo <nbaldo@cttc.es>
8 */
9
11
12#include <ns3/building.h>
13#include <ns3/buildings-helper.h>
14#include <ns3/constant-position-mobility-model.h>
15#include <ns3/double.h>
16#include <ns3/enum.h>
17#include <ns3/hybrid-buildings-propagation-loss-model.h>
18#include <ns3/log.h>
19#include <ns3/mobility-building-info.h>
20#include <ns3/mobility-model.h>
21#include <ns3/ptr.h>
22#include <ns3/simulator.h>
23#include <ns3/string.h>
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("BuildingsShadowingTest");
28
29/*
30 * Test 1.1 Shadowing compound test
31 *
32 * This TestSuite tests the shadowing model of BuildingPathlossModel
33 * by reproducing several communication scenarios
34 */
35
37 : TestSuite("buildings-shadowing-test", Type::SYSTEM)
38{
39 LogComponentEnable("BuildingsShadowingTest", LOG_LEVEL_ALL);
40
41 // Test #1 Outdoor Model
42 AddTestCase(new BuildingsShadowingTestCase(1, 2, 148.86, 7.0, "Outdoor Shadowing"),
43 TestCase::Duration::QUICK);
44
45 // Test #2 Indoor model
46 AddTestCase(new BuildingsShadowingTestCase(5, 6, 88.5724, 8.0, "Indoor Shadowing"),
47 TestCase::Duration::QUICK);
48
49 // Test #3 Indoor -> Outdoor
50 AddTestCase(new BuildingsShadowingTestCase(9, 10, 85.0012, 8.6, "Indoor -> Outdoor Shadowing"),
51 TestCase::Duration::QUICK);
52}
53
54/// Static variable for test initialization
56
57/*
58 * TestCase
59 */
60
62 uint16_t m2,
63 double refValue,
64 double sigmaRef,
65 std::string name)
66 : TestCase("SHADOWING calculation: " + name),
67 m_mobilityModelIndex1(m1),
68 m_mobilityModelIndex2(m2),
69 m_lossRef(refValue),
70 m_sigmaRef(sigmaRef)
71{
72}
73
77
78void
80{
81 NS_LOG_FUNCTION(this);
82
83 // the building basically occupies the negative x plane, so any node
84 // in this area will fall in the building
86 building1->SetBoundaries(Box(-3000, -1, -4000, 4000.0, 0.0, 12));
87 building1->SetBuildingType(Building::Residential);
88 building1->SetExtWallsType(Building::ConcreteWithWindows);
89 building1->SetNFloors(3);
90
91 Ptr<HybridBuildingsPropagationLossModel> propagationLossModel =
93
94 std::vector<double> loss;
95 double sum = 0.0;
96 double sumSquared = 0.0;
97 int samples = 1000;
98 for (int i = 0; i < samples; i++)
99 {
102 double shadowingLoss = propagationLossModel->DoCalcRxPower(0.0, mma, mmb) + m_lossRef;
103 double shadowingLoss2 = propagationLossModel->DoCalcRxPower(0.0, mma, mmb) + m_lossRef;
104 NS_TEST_ASSERT_MSG_EQ_TOL(shadowingLoss,
105 shadowingLoss2,
106 0.001,
107 "Shadowing is not constant for the same mobility model pair!");
108 loss.push_back(shadowingLoss);
109 sum += shadowingLoss;
110 sumSquared += (shadowingLoss * shadowingLoss);
111 }
112 double sampleMean = sum / samples;
113 double sampleVariance = (sumSquared - (sum * sum / samples)) / (samples - 1);
114 double sampleStd = std::sqrt(sampleVariance);
115
116 // test whether the sample mean falls in the 99% confidence interval
117 const double zn995 = 2.575829303549; // 99.5 quantile of the normal distribution
118 double ci = (zn995 * sampleStd) / std::sqrt(samples);
119 NS_LOG_INFO("SampleMean from simulation " << sampleMean << ", sampleStd " << sampleStd
120 << ", reference value " << m_sigmaRef << ", CI(99%) "
121 << ci);
122 NS_TEST_ASSERT_MSG_EQ_TOL(std::fabs(sampleMean), 0.0, ci, "Wrong shadowing distribution !");
123
124 // test whether the sample variance falls in the 99% confidence interval
125 // since the shadowing is gaussian, its sample variance follows the
126 // chi2 distribution with samples-1 degrees of freedom
127 double chi2 = (samples - 1) * sampleVariance / (m_sigmaRef * m_sigmaRef);
128 const double zchi2_005 = 887.621135217515; // 0.5% quantile of the chi2 distribution
129 const double zchi2_995 = 1117.89045267865; // 99.5% quantile of the chi2 distribution
130 NS_TEST_ASSERT_MSG_GT(chi2, zchi2_005, "sample variance lesser than expected");
131 NS_TEST_ASSERT_MSG_LT(chi2, zchi2_995, "sample variance greater than expected");
132
134}
135
138{
139 /*
140 * The purpose of this method is to defer the creation of the
141 * MobilityModel instances to when DoRun() is called. In a previous
142 * version, MobilityModel instances where created directly in the
143 * constructor of the test suite, which caused subtle bugs due to
144 * "static initialization order fiasco". An example of such a subtle
145 * bug is that logging via NS_LOG failed for some modules.
146 *
147 */
148
149 double hm = 1;
150 double hb = 30;
151 double henbHeight = 10.0;
152
154
155 switch (index)
156 {
157 case 1:
159 mm->SetPosition(Vector(0.0, 0.0, hb));
160 break;
161
162 case 2:
164 mm->SetPosition(Vector(2000, 0.0, hm));
165 break;
166
167 case 3:
169 mm->SetPosition(Vector(100, 0.0, hm));
170 break;
171
172 case 4:
174 mm->SetPosition(Vector(900, 0.0, hm));
175 break;
176
177 case 5:
179 mm->SetPosition(Vector(-5, 0.0, hm));
180 break;
181
182 case 6:
184 mm->SetPosition(Vector(-5, 30, henbHeight));
185 break;
186
187 case 7:
189 mm->SetPosition(Vector(-2000, 0.0, hm));
190 break;
191
192 case 8:
194 mm->SetPosition(Vector(-100, 0.0, hm));
195 break;
196
197 case 9:
199 mm->SetPosition(Vector(0, 0.0, hm));
200 break;
201
202 case 10:
204 mm->SetPosition(Vector(-100, 0.0, henbHeight));
205 break;
206
207 case 11:
209 mm->SetPosition(Vector(-500, 0.0, henbHeight));
210 break;
211
212 default:
213 mm = nullptr;
214 break;
215 }
217 mm->AggregateObject(buildingInfo); // operation usually done by BuildingsHelper::Install
218 buildingInfo->MakeConsistent(mm);
219 return mm;
220}
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)
void DoRun() override
Implementation to actually run this TestCase.
BuildingsShadowingTestCase(uint16_t m1, uint16_t m2, double refValue, double sigmaRef, std::string name)
Constructor.
double m_sigmaRef
pathloss standard deviation value reference value
a 3d box
Definition box.h:24
@ ConcreteWithWindows
Definition building.h:58
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:699
#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:864
#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:327
const double m1
First component modulus, 232 - 209.
Definition rng-stream.cc:49
const double m2
Second component modulus, 232 - 22853.
Definition rng-stream.cc:52
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105