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 * 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
19#include "ns3/abort.h"
20#include "ns3/boolean.h"
21#include "ns3/buildings-channel-condition-model.h"
22#include "ns3/buildings-module.h"
23#include "ns3/channel-condition-model.h"
24#include "ns3/config.h"
25#include "ns3/constant-position-mobility-model.h"
26#include "ns3/core-module.h"
27#include "ns3/double.h"
28#include "ns3/log.h"
29#include "ns3/simulator.h"
30#include "ns3/test.h"
31#include "ns3/three-gpp-v2v-channel-condition-model.h"
32#include "ns3/three-gpp-v2v-propagation-loss-model.h"
33#include "ns3/uinteger.h"
34
35using namespace ns3;
36
37NS_LOG_COMPONENT_DEFINE("ThreeGppV2vChannelConditionModelsTest");
38
39/**
40 * \ingroup building-test
41 *
42 * Test case for the classes ThreeGppV2vUrbanChannelConditionModel,
43 * and ThreeGppV2vHighwayChannelConditionModel to test their code to
44 * deterministically determine NLOS state. The test checks if the
45 * channel condition is correctly determined when a building is deployed in the
46 * scenario. Methodology from buildings-channel-condition-model-test.cc is used.
47 */
49{
50 public:
51 /**
52 * Constructor
53 */
55
56 /**
57 * Destructor
58 */
60
61 private:
62 /**
63 * Builds the simulation scenario and perform the tests
64 */
65 void DoRun() override;
66
67 /**
68 * Struct containing the parameters for each test
69 */
71 {
72 Vector m_positionA; //!< the position of the first node
73 Vector m_positionB; //!< the position of the second node
74 ChannelCondition::LosConditionValue m_losCond; //!< the correct channel condition
75 TypeId m_typeId; //!< the type ID of the channel condition model to be used
76 };
77
78 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
79};
80
82 : TestCase("Test case for the ThreeGppV2vUrban and ThreeGppV2vHighway ChannelConditionModel "
83 "with building"),
84 m_testVectors()
85{
86}
87
89{
90}
91
92void
94{
97
98 TestVector testVector;
99 // Add vectors for ThreeGppV2vUrbanChannelConditionModel
100 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
101 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
102 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
104 m_testVectors.Add(testVector);
105
106 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
107 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
108 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
110 m_testVectors.Add(testVector);
111
112 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
113 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
114 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
116 m_testVectors.Add(testVector);
117
118 // Now add same vectors for ThreeGppV2vHighwayChannelConditionModel
119 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
120 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
121 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
123 m_testVectors.Add(testVector);
124
125 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
126 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
127 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
129 m_testVectors.Add(testVector);
130
131 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
132 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
133 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
135 m_testVectors.Add(testVector);
136
137 // create the factory for the channel condition models
138 ObjectFactory condModelFactory;
139
140 // Deploy nodes and building and get the channel condition
142 nodes.Create(2);
143
144 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
146
147 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
149
150 Ptr<Building> building = Create<Building>();
151 building->SetNRoomsX(1);
152 building->SetNRoomsY(1);
153 building->SetNFloors(1);
154 building->SetBoundaries(Box(0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
155
157
158 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
159 {
160 testVector = m_testVectors.Get(i);
161 condModelFactory.SetTypeId(testVector.m_typeId);
163 DynamicCast<ChannelConditionModel>(condModelFactory.Create());
164 condModel->AssignStreams(1);
165
166 a->SetPosition(testVector.m_positionA);
167 b->SetPosition(testVector.m_positionB);
168 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
169 buildingInfoA->MakeConsistent(a);
170 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
171 buildingInfoB->MakeConsistent(b);
173 cond = condModel->GetChannelCondition(a, b);
174
175 NS_LOG_DEBUG("Got " << cond->GetLosCondition() << " expected condition "
176 << testVector.m_losCond);
177 NS_TEST_ASSERT_MSG_EQ(cond->GetLosCondition(),
178 testVector.m_losCond,
179 "Got unexpected channel condition");
180 }
181
183}
184
185/**
186 * Test case for the 3GPP V2V Urban channel condition models (probabilistic
187 * model for LOS/NLOSv states). It determines the channel condition multiple times,
188 * estimates the LOS probability and compares it with the value given by the
189 * formulas in 3GPP TR 37.885, Table 6.2-1. Methodology from channel-condition-model-
190 * test-suite.cc is used.
191 */
193{
194 public:
195 /**
196 * Constructor
197 */
199
200 /**
201 * Destructor
202 */
204
205 private:
206 /**
207 * Builds the simulation scenario and perform the tests
208 */
209 void DoRun() override;
210
211 /**
212 * Evaluates the channel condition between two nodes by calling the method
213 * GetChannelCondition on m_condModel. If the channel condition is LOS it
214 * increments m_numLos
215 * \param a the mobility model of the first node
216 * \param b the mobility model of the second node
217 */
219
220 /**
221 * Struct containing the parameters for each test
222 */
224 {
225 Vector m_positionA; //!< the position of the first node
226 Vector m_positionB; //!< the position of the second node
227 double m_pLos; //!< LOS probability
228 TypeId m_typeId; //!< the type ID of the channel condition model to be used
229 };
230
231 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
233 uint64_t m_numLos{0}; //!< the number of LOS occurrences
234 double m_tolerance; //!< tolerance
235};
236
238 : TestCase("Test case for the class ThreeGppV2vUrbanChannelConditionModel"),
239 m_testVectors(),
240 m_tolerance(2e-3)
241{
242}
243
245{
246}
247
248void
251{
253 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
254 {
255 m_numLos++;
256 }
257}
258
259void
261{
264
265 // create the test vector
266 TestVector testVector;
267
268 // tests for the V2v Urban scenario
269 testVector.m_positionA = Vector(0, 0, 1.6);
270 testVector.m_positionB = Vector(10, 0, 1.6);
271 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 10.0));
273 m_testVectors.Add(testVector);
274
275 testVector.m_positionA = Vector(0, 0, 1.6);
276 testVector.m_positionB = Vector(100, 0, 1.6);
277 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 100.0));
279 m_testVectors.Add(testVector);
280
281 testVector.m_positionA = Vector(0, 0, 1.6);
282 testVector.m_positionB = Vector(1000, 0, 1.6);
283 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 1000.0));
285 m_testVectors.Add(testVector);
286
287 // create the factory for the channel condition models
288 ObjectFactory condModelFactory;
289
290 // create the two nodes
292 nodes.Create(2);
293
294 // create the mobility models
295 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
296 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
297
298 // aggregate the nodes and the mobility models
301
303
304 // Get the channel condition multiple times and compute the LOS probability
305 uint32_t numberOfReps = 500000;
306 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
307 {
308 testVector = m_testVectors.Get(i);
309
310 // set the distance between the two nodes
311 a->SetPosition(testVector.m_positionA);
312 b->SetPosition(testVector.m_positionB);
313 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
314 buildingInfoA->MakeConsistent(a);
315 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
316 buildingInfoB->MakeConsistent(b);
317
318 // create the channel condition model
319 condModelFactory.SetTypeId(testVector.m_typeId);
321 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
323
324 m_numLos = 0;
325 for (uint32_t j = 0; j < numberOfReps; j++)
326 {
328 MilliSeconds(10 * j),
330 this,
331 a,
332 b);
333 }
334
337
338 double resultPlos = double(m_numLos) / double(numberOfReps);
339 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
340 << testVector.m_positionB << " numLos " << m_numLos
341 << " numberOfReps " << numberOfReps << " resultPlos "
342 << resultPlos << " ref " << testVector.m_pLos);
343 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
344 testVector.m_pLos,
346 "Got unexpected LOS probability");
347 }
348}
349
350/**
351 * Test case for the 3GPP V2V Highway channel condition models (probabilistic
352 * model for LOS/NLOSv states). It determines the channel condition multiple times,
353 * estimates the LOS probability and compares it with the value given by the
354 * formulas in 3GPP TR 37.885, Table 6.2-1. Methodology from channel-condition-model-
355 * test-suite.cc is used.
356 */
358{
359 public:
360 /**
361 * Constructor
362 */
364
365 /**
366 * Destructor
367 */
369
370 private:
371 /**
372 * Builds the simulation scenario and perform the tests
373 */
374 void DoRun() override;
375
376 /**
377 * Evaluates the channel condition between two nodes by calling the method
378 * GetChannelCondition on m_condModel. If the channel condition is LOS it
379 * increments m_numLos
380 * \param a the mobility model of the first node
381 * \param b the mobility model of the second node
382 */
384
385 /**
386 * Struct containing the parameters for each test
387 */
389 {
390 Vector m_positionA; //!< the position of the first node
391 Vector m_positionB; //!< the position of the second node
392 double m_pLos; //!< LOS probability
393 TypeId m_typeId; //!< the type ID of the channel condition model to be used
394 };
395
396 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
398 uint64_t m_numLos{0}; //!< the number of LOS occurrences
399 double m_tolerance; //!< tolerance
400};
401
403 : TestCase("Test case for the class ThreeGppV2vHighwayChannelConditionModel"),
404 m_testVectors(),
405 m_tolerance(2e-3)
406{
407}
408
410{
411}
412
413void
416{
418 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
419 {
420 m_numLos++;
421 }
422}
423
424void
426{
429
430 // create the test vector
431 TestVector testVector;
432
433 // tests for the V2v Highway scenario
434 testVector.m_positionA = Vector(0, 0, 1.6);
435 testVector.m_positionB = Vector(10, 0, 1.6);
436 testVector.m_pLos = std::min(1.0, 0.0000021013 * 10.0 * 10.0 - 0.002 * 10.0 + 1.0193);
438 m_testVectors.Add(testVector);
439
440 testVector.m_positionA = Vector(0, 0, 1.6);
441 testVector.m_positionB = Vector(100, 0, 1.6);
442 testVector.m_pLos = std::min(1.0, 0.0000021013 * 100.0 * 100.0 - 0.002 * 100.0 + 1.0193);
444 m_testVectors.Add(testVector);
445
446 testVector.m_positionA = Vector(0, 0, 1.6);
447 testVector.m_positionB = Vector(1000, 0, 1.6);
448 testVector.m_pLos = std::max(0.0, 0.54 - 0.001 * (1000.0 - 475));
450 m_testVectors.Add(testVector);
451
452 // create the factory for the channel condition models
453 ObjectFactory condModelFactory;
454
455 // create the two nodes
457 nodes.Create(2);
458
459 // create the mobility models
460 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
461 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
462
463 // aggregate the nodes and the mobility models
466
468
469 // Get the channel condition multiple times and compute the LOS probability
470 uint32_t numberOfReps = 500000;
471 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
472 {
473 testVector = m_testVectors.Get(i);
474
475 // set the distance between the two nodes
476 a->SetPosition(testVector.m_positionA);
477 b->SetPosition(testVector.m_positionB);
478
479 // create the channel condition model
480 condModelFactory.SetTypeId(testVector.m_typeId);
482 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
484
485 m_numLos = 0;
486 for (uint32_t j = 0; j < numberOfReps; j++)
487 {
489 MilliSeconds(10 * j),
491 this,
492 a,
493 b);
494 }
495
498
499 double resultPlos = static_cast<double>(m_numLos) / static_cast<double>(numberOfReps);
500 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
501 << testVector.m_positionB << " numLos " << m_numLos
502 << " numberOfReps " << numberOfReps << " resultPlos "
503 << resultPlos << " ref " << testVector.m_pLos);
504 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
505 testVector.m_pLos,
507 "Got unexpected LOS probability");
508 }
509}
510
511/**
512 * \ingroup building-test
513 *
514 * Test suite for the 3GPP V2V channel condition model
515 *
516 * Note that, in 3GPP V2V scenarios, the channel condition model is
517 * determined based on a two step procedure: 1st) NLOS state is determined
518 * based on a deterministic model (using buildings), and 2nd) the LOS or NLOSv
519 * state is determined based on a probabilistic model (using 3GPP formulas), in
520 * case that the vehicles are not in NLOS condition.
521 *
522 * The test ThreeGppV2vBuildingsChCondModelTestCase checks the
523 * 1st step of the procedure, the deterministic one, using buildings for
524 * both \link ns3::ThreeGppV2vUrbanChannelConditionModel \endlink and
525 * \link ns3::ThreeGppV2vHighwayChannelConditionModel \endlink .
526 *
527 * The tests ThreeGppV2vUrbanLosNlosvChCondModelTestCase and
528 * ThreeGppV2vHighwayLosNlosvChCondModelTestCase check the
529 * 2nd step of the procedure, the probabilistic one, without buildings, for
530 * the V2V Urban and V2V Highway scenarios, respectively.
531 *
532 */
534{
535 public:
537};
538
540 : TestSuite("three-gpp-v2v-channel-condition-model", Type::SYSTEM)
541{
543 TestCase::Duration::QUICK); // test for the deterministic procedure (NLOS vs
544 // LOS/NLOSv), based on buildings
546 TestCase::Duration::QUICK); // test for the probabilistic procedure (LOS vs
547 // NLOSv), in V2V urban scenario
549 TestCase::Duration::QUICK); // test for the probabilistic procedure (LOS vs
550 // NLOSv), in V2V highway scenario
551}
552
553/// 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:35
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.
Definition: object-base.cc:211
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:309
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1342
int64_t AssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
Ptr< ChannelCondition > GetChannelCondition(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Retrieve the condition of the channel between a and b.
Computes the channel condition for the V2V Highway scenario.
Computes the channel condition for the V2V Urban scenario.
AttributeValue implementation for Time.
Definition: nstime.h:1406
a unique identifier for an interface.
Definition: type-id.h:59
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:145
#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:511
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
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
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