A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
buildings-penetration-loss-pathloss-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ns3/abort.h"
8#include "ns3/boolean.h"
9#include "ns3/building.h"
10#include "ns3/buildings-channel-condition-model.h"
11#include "ns3/channel-condition-model.h"
12#include "ns3/config.h"
13#include "ns3/constant-position-mobility-model.h"
14#include "ns3/constant-velocity-mobility-model.h"
15#include "ns3/double.h"
16#include "ns3/log.h"
17#include "ns3/mobility-building-info.h"
18#include "ns3/mobility-helper.h"
19#include "ns3/simulator.h"
20#include "ns3/test.h"
21#include "ns3/three-gpp-propagation-loss-model.h"
22
23using namespace ns3;
24
25NS_LOG_COMPONENT_DEFINE("BuildingsPenetrationLossesTest");
26
27/**
28 * \ingroup propagation-tests
29 *
30 * Test case for the 3GPP channel O2I building penetration losses.
31 * It considers pre-determined scenarios and based on the outdoor/indoor
32 * condition (O2O/O2I) checks whether the calculated received power
33 * is aligned with the calculation in 3GPP TR 38.901.
34 *
35 * For O2O condition the calculation is done according to Table 7.4.1-1
36 * and we check if the calculated received power is equal to the expected
37 * value.
38 * For the O2I condition, the calculation is done considering the building
39 * penetration losses based on the material of the building walls.
40 * In this case, we check if the calculated received power is less than the
41 * received value (thus ensure that losses have been included).
42 */
43
45{
46 public:
47 /**
48 * Constructor
49 */
51
52 /**
53 * Destructor
54 */
56
57 private:
58 /**
59 * Builds the simulation scenario and perform the tests
60 */
61 void DoRun() override;
62
63 /**
64 * Struct containing the parameters for each test
65 */
67 {
68 Vector m_positionA; //!< the position of the first node
69 Vector m_positionB; //!< the position of the second node
70 double m_frequency; //!< carrier frequency in Hz
71 TypeId m_condModel; //!< the type ID of the channel condition model to be used
72 TypeId m_propModel; //!< the type ID of the propagation loss model to be used
73 double m_pt; //!< transmitted power in dBm
74 double m_pr; //!< received power in dBm
75 };
76
77 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
78 Ptr<ThreeGppPropagationLossModel> m_propModel; //!< the propagation loss model
79 double m_tolerance; //!< tolerance
80};
81
83 : TestCase("Test case for BuildingsPenetrationLosses"),
84 m_testVectors(),
85 m_tolerance(2e-3)
86{
87}
88
92
93void
95{
96 // create the test vector
97 TestVector testVector;
98
99 // tests for the RMa scenario
100 testVector.m_positionA = Vector(0, 0, 35.0); // O2I case
101 testVector.m_positionB = Vector(10, 0, 1.5);
102 testVector.m_frequency = 5.0e9;
104 testVector.m_pt = 0.0;
105 testVector.m_pr = -77.3784;
106 m_testVectors.Add(testVector);
107
108 testVector.m_positionA = Vector(0, 0, 35.0); // O2I case
109 testVector.m_positionB = Vector(100, 0, 1.5);
110 testVector.m_frequency = 5.0e9;
112 testVector.m_pt = 0.0;
113 testVector.m_pr = -87.2965;
114 m_testVectors.Add(testVector);
115
116 testVector.m_positionA = Vector(0, 0, 35.0); // O2O case
117 testVector.m_positionB = Vector(1000, 0, 1.5);
118 testVector.m_frequency = 5.0e9;
120 testVector.m_pt = 0.0;
121 testVector.m_pr = -108.5577;
122 m_testVectors.Add(testVector);
123
124 // tests for the UMa scenario
125 testVector.m_positionA = Vector(0, 0, 25.0); // O2I case
126 testVector.m_positionB = Vector(10, 0, 1.5);
127 testVector.m_frequency = 5.0e9;
129 testVector.m_pt = 0.0;
130 testVector.m_pr = -72.9380;
131 m_testVectors.Add(testVector);
132
133 testVector.m_positionA = Vector(0, 0, 25.0); // O2I case
134 testVector.m_positionB = Vector(100, 0, 1.5);
135 testVector.m_frequency = 5.0e9;
137 testVector.m_pt = 0.0;
138 testVector.m_pr = -86.2362;
139 m_testVectors.Add(testVector);
140
141 testVector.m_positionA = Vector(0, 0, 25.0); // O2O case
142 testVector.m_positionB = Vector(1000, 0, 1.5);
143 testVector.m_frequency = 5.0e9;
145 testVector.m_pt = 0.0;
146 testVector.m_pr = -109.7252;
147 m_testVectors.Add(testVector);
148
149 // tests for the UMi scenario
150 testVector.m_positionA = Vector(0, 0, 10.0); // O2I case
151 testVector.m_positionB = Vector(10, 0, 1.5);
152 testVector.m_frequency = 5.0e9;
154 testVector.m_pt = 0.0;
155 testVector.m_pr = -69.8591;
156 m_testVectors.Add(testVector);
157
158 testVector.m_positionA = Vector(0, 0, 10.0); // O2I case
159 testVector.m_positionB = Vector(100, 0, 1.5);
160 testVector.m_frequency = 5.0e9;
162 testVector.m_pt = 0.0;
163 testVector.m_pr = -88.4122;
164 m_testVectors.Add(testVector);
165
166 testVector.m_positionA = Vector(0, 0, 10.0); // O2O case
167 testVector.m_positionB = Vector(1000, 0, 1.5);
168 testVector.m_frequency = 5.0e9;
170 testVector.m_pt = 0.0;
171 testVector.m_pr = -119.3114;
172 m_testVectors.Add(testVector);
173
174 // create the factory for the propagation loss model
175 ObjectFactory propModelFactory;
176
177 Ptr<Building> building = Create<Building>();
178 building->SetExtWallsType(Building::ExtWallsType_t::ConcreteWithWindows);
179 building->SetNRoomsX(1);
180 building->SetNRoomsY(1);
181 building->SetNFloors(2);
182 building->SetBoundaries(Box(0.0, 100.0, 0.0, 10.0, 0.0, 5.0));
183
184 // create the two nodes
186 nodes.Create(2);
187
188 // create the mobility models
191
192 // aggregate the nodes and the mobility models
195
198 a->AggregateObject(buildingInfoA); // operation usually done by BuildingsHelper::Install
199 buildingInfoA->MakeConsistent(a);
200
201 b->AggregateObject(buildingInfoB); // operation usually done by BuildingsHelper::Install
202 buildingInfoB->MakeConsistent(b);
203
205
206 for (std::size_t i = 0; i < m_testVectors.GetN(); i++)
207 {
208 TestVector testVector = m_testVectors.Get(i);
209 a->SetPosition(testVector.m_positionA);
210 b->SetPosition(testVector.m_positionB);
211
212 Ptr<ChannelCondition> cond = condModel->GetChannelCondition(a, b);
213
214 propModelFactory.SetTypeId(testVector.m_propModel);
215 m_propModel = propModelFactory.Create<ThreeGppPropagationLossModel>();
216 m_propModel->SetAttribute("Frequency", DoubleValue(testVector.m_frequency));
217 m_propModel->SetAttribute("ShadowingEnabled", BooleanValue(false));
218 m_propModel->SetChannelConditionModel(condModel);
219
220 bool isAIndoor = buildingInfoA->IsIndoor();
221 bool isBIndoor = buildingInfoB->IsIndoor();
222
223 if (!isAIndoor && !isBIndoor) // a and b are outdoor
224 {
225 cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
226 cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2O);
227
228 // check rcv power to be equal to the calculated value without losses
229 NS_TEST_EXPECT_MSG_EQ_TOL(m_propModel->CalcRxPower(testVector.m_pt, a, b),
230 testVector.m_pr,
232 "rcv power is not equal expected value");
233 }
234 else
235 {
236 cond->SetLosCondition(ChannelCondition::LosConditionValue::LOS);
237 cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2I);
238 cond->SetO2iLowHighCondition(ChannelCondition::O2iLowHighConditionValue::LOW);
239
240 // check rcv power to be lower than the calculated without losses
241 NS_TEST_EXPECT_MSG_LT(m_propModel->CalcRxPower(testVector.m_pt, a, b),
242 testVector.m_pr,
243 "rcv power is not less than calculated value");
244 }
245 m_propModel = nullptr;
246 }
248}
249
250/**
251 * \ingroup propagation-tests
252 *
253 * Test suite for the buildings penetration losses
254 */
260
262 : TestSuite("buildings-penetration-losses", Type::UNIT)
263{
264 AddTestCase(new BuildingsPenetrationLossesTestCase, TestCase::Duration::QUICK);
265}
266
267/// Static variable for test initialization
static BuildingsPenetrationLossesTestSuite g_buildingsPenetrationLossesTestSuite
Static variable for test initialization.
Test case for the 3GPP channel O2I building penetration losses.
TestVectors< TestVector > m_testVectors
array containing all the test vectors
Ptr< ThreeGppPropagationLossModel > m_propModel
the propagation loss model
void DoRun() override
Builds the simulation scenario and perform the tests.
Test suite for the buildings penetration losses.
a 3d box
Definition box.h:24
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition object.cc:298
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
A simple way to store test vectors (for stimulus or from responses)
Definition test.h:1348
Base class for the 3GPP propagation models.
a unique identifier for an interface.
Definition type-id.h:48
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
Definition test.h:780
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition test.h:500
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TypeId m_propModel
the type ID of the propagation loss model to be used
TypeId m_condModel
the type ID of the channel condition model to be used