A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
channel-condition-model-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
3 * University of Padova
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 */
7
8#include "ns3/abort.h"
9#include "ns3/channel-condition-model.h"
10#include "ns3/config.h"
11#include "ns3/constant-position-mobility-model.h"
12#include "ns3/double.h"
13#include "ns3/log.h"
14#include "ns3/node-container.h"
15#include "ns3/simulator.h"
16#include "ns3/test.h"
17
18using namespace ns3;
19
20NS_LOG_COMPONENT_DEFINE("ChannelConditionModelsTest");
21
22/**
23 * \ingroup propagation-tests
24 *
25 * Test case for the 3GPP channel condition models. It determines the
26 * channel condition multiple times, estimates the LOS probability and
27 * compares it with the value given by the formulas in 3GPP TR 38.901,
28 * Table Table 7.4.2-1.
29 */
31{
32 public:
33 /**
34 * Constructor
35 */
37
38 /**
39 * Destructor
40 */
42
43 private:
44 /**
45 * Builds the simulation scenario and perform the tests
46 */
47 void DoRun() override;
48
49 /**
50 * Evaluates the channel condition between two nodes by calling the method
51 * GetChannelCondition on m_condModel. If the channel condition is LOS it
52 * increments m_numLos
53 * \param a the mobility model of the first node
54 * \param b the mobility model of the second node
55 */
57
58 /**
59 * Struct containing the parameters for each test
60 */
62 {
63 Vector m_positionA; //!< the position of the first node
64 Vector m_positionB; //!< the position of the second node
65 double m_pLos; //!< LOS probability
66 TypeId m_typeId; //!< the type ID of the channel condition model to be used
67 };
68
69 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
70 Ptr<ThreeGppChannelConditionModel> m_condModel; //!< the channel condition model
71 uint64_t m_numLos; //!< the number of LOS occurrences
72 double m_tolerance; //!< tolerance
73};
74
76 : TestCase("Test case for the child classes of ThreeGppChannelConditionModel"),
77 m_testVectors(),
78 m_tolerance(2.5e-3)
79{
80}
81
85
86void
89{
90 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
91 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
92 {
93 m_numLos++;
94 }
95}
96
97void
99{
100 // create the test vector
101 TestVector testVector;
102
103 // tests for the RMa scenario
104 testVector.m_positionA = Vector(0, 0, 35.0);
105 testVector.m_positionB = Vector(10, 0, 1.5);
106 testVector.m_pLos = 1;
108 m_testVectors.Add(testVector);
109
110 testVector.m_positionA = Vector(0, 0, 35.0);
111 testVector.m_positionB = Vector(100, 0, 1.5);
112 testVector.m_pLos = exp(-(100.0 - 10.0) / 1000.0);
114 m_testVectors.Add(testVector);
115
116 testVector.m_positionA = Vector(0, 0, 35.0);
117 testVector.m_positionB = Vector(1000, 0, 1.5);
118 testVector.m_pLos = exp(-(1000.0 - 10.0) / 1000.0);
120 m_testVectors.Add(testVector);
121
122 // tests for the UMa scenario
123 testVector.m_positionA = Vector(0, 0, 25.0);
124 testVector.m_positionB = Vector(18, 0, 1.5);
125 testVector.m_pLos = 1;
127 m_testVectors.Add(testVector);
128
129 testVector.m_positionA = Vector(0, 0, 25.0);
130 testVector.m_positionB = Vector(50, 0, 1.5);
131 testVector.m_pLos = (18.0 / 50.0 + exp(-50.0 / 63.0) * (1.0 - 18.0 / 50.0)) * (1.0 + 0);
133 m_testVectors.Add(testVector);
134
135 testVector.m_positionA = Vector(0, 0, 25.0);
136 testVector.m_positionB = Vector(50, 0, 15);
137 testVector.m_pLos =
138 (18.0 / 50.0 + exp(-50.0 / 63.0) * (1.0 - 18.0 / 50.0)) *
139 (1.0 + pow(2.0 / 10.0, 1.5) * 5.0 / 4.0 * pow(50.0 / 100.0, 3) * exp(-50.0 / 150.0));
141 m_testVectors.Add(testVector);
142
143 testVector.m_positionA = Vector(0, 0, 25.0);
144 testVector.m_positionB = Vector(100, 0, 1.5);
145 testVector.m_pLos = (18.0 / 100.0 + exp(-100.0 / 63.0) * (1.0 - 18.0 / 100.0)) * (1.0 + 0);
147 m_testVectors.Add(testVector);
148
149 testVector.m_positionA = Vector(0, 0, 25.0);
150 testVector.m_positionB = Vector(100, 0, 15);
151 testVector.m_pLos = (18.0 / 100.0 + exp(-100.0 / 63.0) * (1.0 - 18.0 / 100.0)) *
152 (1.0 + pow(2.0 / 10.0, 1.5) * 5.0 / 4.0 * 1.0 * exp(-100.0 / 150.0));
154 m_testVectors.Add(testVector);
155
156 // tests for the UMi-Street Canyon scenario
157 testVector.m_positionA = Vector(0, 0, 10.0);
158 testVector.m_positionB = Vector(18, 0, 1.5);
159 testVector.m_pLos = 1;
161 m_testVectors.Add(testVector);
162
163 testVector.m_positionA = Vector(0, 0, 10.0);
164 testVector.m_positionB = Vector(50, 0, 1.5);
165 testVector.m_pLos = (18.0 / 50.0 + exp(-50.0 / 36.0) * (1.0 - 18.0 / 50.0));
167 m_testVectors.Add(testVector);
168
169 m_testVectors.Add(testVector);
170 testVector.m_positionA = Vector(0, 0, 10.0);
171 testVector.m_positionB = Vector(100, 0, 15);
172 testVector.m_pLos = (18.0 / 100.0 + exp(-100.0 / 36.0) * (1.0 - 18.0 / 100.0));
174 m_testVectors.Add(testVector);
175
176 // tests for the Indoor Mixed Office scenario
177 testVector.m_positionA = Vector(0, 0, 2.0);
178 testVector.m_positionB = Vector(1.2, 0, 1.5);
179 testVector.m_pLos = 1;
181 m_testVectors.Add(testVector);
182
183 testVector.m_positionA = Vector(0, 0, 2.0);
184 testVector.m_positionB = Vector(5, 0, 1.5);
185 testVector.m_pLos = exp(-(5.0 - 1.2) / 4.7);
187 m_testVectors.Add(testVector);
188
189 testVector.m_positionA = Vector(0, 0, 2.0);
190 testVector.m_positionB = Vector(10, 0, 1.5);
191 testVector.m_pLos = exp(-(10.0 - 6.5) / 32.6) * 0.32;
193 m_testVectors.Add(testVector);
194
195 // tests for the Indoor Open Office scenario
196 testVector.m_positionA = Vector(0, 0, 3.0);
197 testVector.m_positionB = Vector(5, 0, 1.5);
198 testVector.m_pLos = 1;
200 m_testVectors.Add(testVector);
201
202 testVector.m_positionA = Vector(0, 0, 3.0);
203 testVector.m_positionB = Vector(30, 0, 1.5);
204 testVector.m_pLos = exp(-(30.0 - 5.0) / 70.8);
206 m_testVectors.Add(testVector);
207
208 testVector.m_positionA = Vector(0, 0, 3.0);
209 testVector.m_positionB = Vector(100, 0, 1.5);
210 testVector.m_pLos = exp(-(100.0 - 49.0) / 211.7) * 0.54;
212 m_testVectors.Add(testVector);
213
214 // create the factory for the channel condition models
215 ObjectFactory condModelFactory;
216
217 // create the two nodes
219 nodes.Create(2);
220
221 // create the mobility models
224
225 // aggregate the nodes and the mobility models
228
229 // Get the channel condition multiple times and compute the LOS probability
230 uint32_t numberOfReps = 500000;
231 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
232 {
233 testVector = m_testVectors.Get(i);
234
235 // set the distance between the two nodes
236 a->SetPosition(testVector.m_positionA);
237 b->SetPosition(testVector.m_positionB);
238
239 // create the channel condition model
240 condModelFactory.SetTypeId(testVector.m_typeId);
242 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
243
244 m_numLos = 0;
245 for (uint32_t j = 0; j < numberOfReps; j++)
246 {
249 this,
250 a,
251 b);
252 }
253
256
257 double resultPlos = double(m_numLos) / double(numberOfReps);
258 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
259 << testVector.m_positionB << " numLos " << m_numLos
260 << " numberOfReps " << numberOfReps << " resultPlos "
261 << resultPlos << " ref " << testVector.m_pLos);
262 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
263 testVector.m_pLos,
265 "Got unexpected LOS probability");
266 }
267}
268
269/**
270 * \ingroup propagation-tests
271 *
272 * Test suite for the channel condition models
273 */
279
281 : TestSuite("propagation-channel-condition-model", Type::UNIT)
282{
283 AddTestCase(new ThreeGppChannelConditionModelTestCase, TestCase::Duration::QUICK);
284}
285
286/// Static variable for test initialization
static ChannelConditionModelsTestSuite g_channelConditionModelsTestSuite
Static variable for test initialization.
Test suite for the channel condition models.
Test case for the 3GPP channel condition models.
void DoRun() override
Builds the simulation scenario and perform the tests.
void EvaluateChannelCondition(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Evaluates the channel condition between two nodes by calling the method GetChannelCondition on m_cond...
Ptr< ThreeGppChannelConditionModel > m_condModel
the channel condition model
TestVectors< TestVector > m_testVectors
array containing all the test vectors
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
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 channel condition models.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
AttributeValue implementation for Time.
Definition nstime.h:1395
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
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TypeId m_typeId
the type ID of the channel condition model to be used