A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-v2v-channel-condition-model-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 * Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 */
7
8#include "ns3/abort.h"
9#include "ns3/boolean.h"
10#include "ns3/buildings-channel-condition-model.h"
11#include "ns3/buildings-module.h"
12#include "ns3/channel-condition-model.h"
13#include "ns3/config.h"
14#include "ns3/constant-position-mobility-model.h"
15#include "ns3/core-module.h"
16#include "ns3/double.h"
17#include "ns3/log.h"
18#include "ns3/simulator.h"
19#include "ns3/test.h"
20#include "ns3/three-gpp-v2v-channel-condition-model.h"
21#include "ns3/three-gpp-v2v-propagation-loss-model.h"
22#include "ns3/uinteger.h"
23
24using namespace ns3;
25
26NS_LOG_COMPONENT_DEFINE("ThreeGppV2vChannelConditionModelsTest");
27
28/**
29 * \ingroup building-test
30 *
31 * Test case for the classes ThreeGppV2vUrbanChannelConditionModel,
32 * and ThreeGppV2vHighwayChannelConditionModel to test their code to
33 * deterministically determine NLOS state. The test checks if the
34 * channel condition is correctly determined when a building is deployed in the
35 * scenario. Methodology from buildings-channel-condition-model-test.cc is used.
36 */
38{
39 public:
40 /**
41 * Constructor
42 */
44
45 /**
46 * Destructor
47 */
49
50 private:
51 /**
52 * Builds the simulation scenario and perform the tests
53 */
54 void DoRun() override;
55
56 /**
57 * Struct containing the parameters for each test
58 */
60 {
61 Vector m_positionA; //!< the position of the first node
62 Vector m_positionB; //!< the position of the second node
63 ChannelCondition::LosConditionValue m_losCond; //!< the correct channel condition
64 TypeId m_typeId; //!< the type ID of the channel condition model to be used
65 };
66
67 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
68};
69
71 : TestCase("Test case for the ThreeGppV2vUrban and ThreeGppV2vHighway ChannelConditionModel "
72 "with building"),
73 m_testVectors()
74{
75}
76
80
81void
83{
86
87 TestVector testVector;
88 // Add vectors for ThreeGppV2vUrbanChannelConditionModel
89 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
90 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
91 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
93 m_testVectors.Add(testVector);
94
95 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
96 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
97 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
99 m_testVectors.Add(testVector);
100
101 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
102 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
103 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
105 m_testVectors.Add(testVector);
106
107 // Now add same vectors for ThreeGppV2vHighwayChannelConditionModel
108 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
109 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
110 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
112 m_testVectors.Add(testVector);
113
114 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
115 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
116 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
118 m_testVectors.Add(testVector);
119
120 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
121 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
122 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
124 m_testVectors.Add(testVector);
125
126 // create the factory for the channel condition models
127 ObjectFactory condModelFactory;
128
129 // Deploy nodes and building and get the channel condition
131 nodes.Create(2);
132
135
138
139 Ptr<Building> building = Create<Building>();
140 building->SetNRoomsX(1);
141 building->SetNRoomsY(1);
142 building->SetNFloors(1);
143 building->SetBoundaries(Box(0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
144
146
147 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
148 {
149 testVector = m_testVectors.Get(i);
150 condModelFactory.SetTypeId(testVector.m_typeId);
152 DynamicCast<ChannelConditionModel>(condModelFactory.Create());
153 condModel->AssignStreams(1);
154
155 a->SetPosition(testVector.m_positionA);
156 b->SetPosition(testVector.m_positionB);
157 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
158 buildingInfoA->MakeConsistent(a);
159 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
160 buildingInfoB->MakeConsistent(b);
162 cond = condModel->GetChannelCondition(a, b);
163
164 NS_LOG_DEBUG("Got " << cond->GetLosCondition() << " expected condition "
165 << testVector.m_losCond);
166 NS_TEST_ASSERT_MSG_EQ(cond->GetLosCondition(),
167 testVector.m_losCond,
168 "Got unexpected channel condition");
169 }
170
172}
173
174/**
175 * Test case for the 3GPP V2V Urban channel condition models (probabilistic
176 * model for LOS/NLOSv states). It determines the channel condition multiple times,
177 * estimates the LOS probability and compares it with the value given by the
178 * formulas in 3GPP TR 37.885, Table 6.2-1. Methodology from channel-condition-model-
179 * test-suite.cc is used.
180 */
182{
183 public:
184 /**
185 * Constructor
186 */
188
189 /**
190 * Destructor
191 */
193
194 private:
195 /**
196 * Builds the simulation scenario and perform the tests
197 */
198 void DoRun() override;
199
200 /**
201 * Evaluates the channel condition between two nodes by calling the method
202 * GetChannelCondition on m_condModel. If the channel condition is LOS it
203 * increments m_numLos
204 * \param a the mobility model of the first node
205 * \param b the mobility model of the second node
206 */
208
209 /**
210 * Struct containing the parameters for each test
211 */
213 {
214 Vector m_positionA; //!< the position of the first node
215 Vector m_positionB; //!< the position of the second node
216 double m_pLos; //!< LOS probability
217 TypeId m_typeId; //!< the type ID of the channel condition model to be used
218 };
219
220 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
222 uint64_t m_numLos{0}; //!< the number of LOS occurrences
223 double m_tolerance; //!< tolerance
224};
225
227 : TestCase("Test case for the class ThreeGppV2vUrbanChannelConditionModel"),
228 m_testVectors(),
229 m_tolerance(2e-3)
230{
231}
232
236
237void
240{
241 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
242 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
243 {
244 m_numLos++;
245 }
246}
247
248void
250{
253
254 // create the test vector
255 TestVector testVector;
256
257 // tests for the V2v Urban scenario
258 testVector.m_positionA = Vector(0, 0, 1.6);
259 testVector.m_positionB = Vector(10, 0, 1.6);
260 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 10.0));
262 m_testVectors.Add(testVector);
263
264 testVector.m_positionA = Vector(0, 0, 1.6);
265 testVector.m_positionB = Vector(100, 0, 1.6);
266 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 100.0));
268 m_testVectors.Add(testVector);
269
270 testVector.m_positionA = Vector(0, 0, 1.6);
271 testVector.m_positionB = Vector(1000, 0, 1.6);
272 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 1000.0));
274 m_testVectors.Add(testVector);
275
276 // create the factory for the channel condition models
277 ObjectFactory condModelFactory;
278
279 // create the two nodes
281 nodes.Create(2);
282
283 // create the mobility models
286
287 // aggregate the nodes and the mobility models
290
292
293 // Get the channel condition multiple times and compute the LOS probability
294 uint32_t numberOfReps = 500000;
295 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
296 {
297 testVector = m_testVectors.Get(i);
298
299 // set the distance between the two nodes
300 a->SetPosition(testVector.m_positionA);
301 b->SetPosition(testVector.m_positionB);
302 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
303 buildingInfoA->MakeConsistent(a);
304 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
305 buildingInfoB->MakeConsistent(b);
306
307 // create the channel condition model
308 condModelFactory.SetTypeId(testVector.m_typeId);
310 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
311 m_condModel->AssignStreams(1);
312
313 m_numLos = 0;
314 for (uint32_t j = 0; j < numberOfReps; j++)
315 {
317 MilliSeconds(10 * j),
319 this,
320 a,
321 b);
322 }
323
326
327 double resultPlos = double(m_numLos) / double(numberOfReps);
328 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
329 << testVector.m_positionB << " numLos " << m_numLos
330 << " numberOfReps " << numberOfReps << " resultPlos "
331 << resultPlos << " ref " << testVector.m_pLos);
332 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
333 testVector.m_pLos,
335 "Got unexpected LOS probability");
336 }
337}
338
339/**
340 * Test case for the 3GPP V2V Highway channel condition models (probabilistic
341 * model for LOS/NLOSv states). It determines the channel condition multiple times,
342 * estimates the LOS probability and compares it with the value given by the
343 * formulas in 3GPP TR 37.885, Table 6.2-1. Methodology from channel-condition-model-
344 * test-suite.cc is used.
345 */
347{
348 public:
349 /**
350 * Constructor
351 */
353
354 /**
355 * Destructor
356 */
358
359 private:
360 /**
361 * Builds the simulation scenario and perform the tests
362 */
363 void DoRun() override;
364
365 /**
366 * Evaluates the channel condition between two nodes by calling the method
367 * GetChannelCondition on m_condModel. If the channel condition is LOS it
368 * increments m_numLos
369 * \param a the mobility model of the first node
370 * \param b the mobility model of the second node
371 */
373
374 /**
375 * Struct containing the parameters for each test
376 */
378 {
379 Vector m_positionA; //!< the position of the first node
380 Vector m_positionB; //!< the position of the second node
381 double m_pLos; //!< LOS probability
382 TypeId m_typeId; //!< the type ID of the channel condition model to be used
383 };
384
385 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
387 uint64_t m_numLos{0}; //!< the number of LOS occurrences
388 double m_tolerance; //!< tolerance
389};
390
392 : TestCase("Test case for the class ThreeGppV2vHighwayChannelConditionModel"),
393 m_testVectors(),
394 m_tolerance(2e-3)
395{
396}
397
401
402void
405{
406 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
407 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
408 {
409 m_numLos++;
410 }
411}
412
413void
415{
418
419 // create the test vector
420 TestVector testVector;
421
422 // tests for the V2v Highway scenario
423 testVector.m_positionA = Vector(0, 0, 1.6);
424 testVector.m_positionB = Vector(10, 0, 1.6);
425 testVector.m_pLos = std::min(1.0, 0.0000021013 * 10.0 * 10.0 - 0.002 * 10.0 + 1.0193);
427 m_testVectors.Add(testVector);
428
429 testVector.m_positionA = Vector(0, 0, 1.6);
430 testVector.m_positionB = Vector(100, 0, 1.6);
431 testVector.m_pLos = std::min(1.0, 0.0000021013 * 100.0 * 100.0 - 0.002 * 100.0 + 1.0193);
433 m_testVectors.Add(testVector);
434
435 testVector.m_positionA = Vector(0, 0, 1.6);
436 testVector.m_positionB = Vector(1000, 0, 1.6);
437 testVector.m_pLos = std::max(0.0, 0.54 - 0.001 * (1000.0 - 475));
439 m_testVectors.Add(testVector);
440
441 // create the factory for the channel condition models
442 ObjectFactory condModelFactory;
443
444 // create the two nodes
446 nodes.Create(2);
447
448 // create the mobility models
451
452 // aggregate the nodes and the mobility models
455
457
458 // Get the channel condition multiple times and compute the LOS probability
459 uint32_t numberOfReps = 500000;
460 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
461 {
462 testVector = m_testVectors.Get(i);
463
464 // set the distance between the two nodes
465 a->SetPosition(testVector.m_positionA);
466 b->SetPosition(testVector.m_positionB);
467
468 // create the channel condition model
469 condModelFactory.SetTypeId(testVector.m_typeId);
471 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
472 m_condModel->AssignStreams(1);
473
474 m_numLos = 0;
475 for (uint32_t j = 0; j < numberOfReps; j++)
476 {
478 MilliSeconds(10 * j),
480 this,
481 a,
482 b);
483 }
484
487
488 double resultPlos = static_cast<double>(m_numLos) / static_cast<double>(numberOfReps);
489 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
490 << testVector.m_positionB << " numLos " << m_numLos
491 << " numberOfReps " << numberOfReps << " resultPlos "
492 << resultPlos << " ref " << testVector.m_pLos);
493 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
494 testVector.m_pLos,
496 "Got unexpected LOS probability");
497 }
498}
499
500/**
501 * \ingroup building-test
502 *
503 * Test suite for the 3GPP V2V channel condition model
504 *
505 * Note that, in 3GPP V2V scenarios, the channel condition model is
506 * determined based on a two step procedure: 1st) NLOS state is determined
507 * based on a deterministic model (using buildings), and 2nd) the LOS or NLOSv
508 * state is determined based on a probabilistic model (using 3GPP formulas), in
509 * case that the vehicles are not in NLOS condition.
510 *
511 * The test ThreeGppV2vBuildingsChCondModelTestCase checks the
512 * 1st step of the procedure, the deterministic one, using buildings for
513 * both \link ns3::ThreeGppV2vUrbanChannelConditionModel \endlink and
514 * \link ns3::ThreeGppV2vHighwayChannelConditionModel \endlink .
515 *
516 * The tests ThreeGppV2vUrbanLosNlosvChCondModelTestCase and
517 * ThreeGppV2vHighwayLosNlosvChCondModelTestCase check the
518 * 2nd step of the procedure, the probabilistic one, without buildings, for
519 * the V2V Urban and V2V Highway scenarios, respectively.
520 *
521 */
527
529 : TestSuite("three-gpp-v2v-channel-condition-model", Type::SYSTEM)
530{
532 TestCase::Duration::QUICK); // test for the deterministic procedure (NLOS vs
533 // LOS/NLOSv), based on buildings
535 TestCase::Duration::QUICK); // test for the probabilistic procedure (LOS vs
536 // NLOSv), in V2V urban scenario
538 TestCase::Duration::QUICK); // test for the probabilistic procedure (LOS vs
539 // NLOSv), in V2V highway scenario
540}
541
542/// Static variable for test initialization
Test case for the classes ThreeGppV2vUrbanChannelConditionModel, and ThreeGppV2vHighwayChannelConditi...
void DoRun() override
Builds the simulation scenario and perform the tests.
TestVectors< TestVector > m_testVectors
array containing all the test vectors
Test suite for the 3GPP V2V channel condition model.
Test case for the 3GPP V2V Highway channel condition models (probabilistic model for LOS/NLOSv states...
void EvaluateChannelCondition(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Evaluates the channel condition between two nodes by calling the method GetChannelCondition on m_cond...
void DoRun() override
Builds the simulation scenario and perform the tests.
TestVectors< TestVector > m_testVectors
array containing all the test vectors
Ptr< ThreeGppV2vHighwayChannelConditionModel > m_condModel
the channel condition model
Test case for the 3GPP V2V Urban channel condition models (probabilistic model for LOS/NLOSv states).
Ptr< ThreeGppV2vUrbanChannelConditionModel > m_condModel
the channel condition model
void DoRun() override
Builds the simulation scenario and perform the tests.
TestVectors< TestVector > m_testVectors
array containing all the test vectors
void EvaluateChannelCondition(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Evaluates the channel condition between two nodes by calling the method GetChannelCondition on m_cond...
a 3d box
Definition box.h:24
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
LosConditionValue
Possible values for Line-of-Sight condition.
mobility buildings information (to be used by mobility models)
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 SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
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
Computes the channel condition for the V2V Highway scenario.
Computes the channel condition for the V2V Urban scenario.
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
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_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
#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.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
TypeId m_typeId
the type ID of the channel condition model to be used
ChannelCondition::LosConditionValue m_losCond
the correct channel condition
TypeId m_typeId
the type ID of the channel condition model to be used
TypeId m_typeId
the type ID of the channel condition model to be used
static ThreeGppV2vChCondModelsTestSuite ThreeGppV2vChCondModelsTestSuite
Static variable for test initialization.