A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
probabilistic-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 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ns3/abort.h"
8#include "ns3/boolean.h"
9#include "ns3/channel-condition-model.h"
10#include "ns3/config.h"
11#include "ns3/constant-position-mobility-model.h"
12#include "ns3/core-module.h"
13#include "ns3/double.h"
14#include "ns3/log.h"
15#include "ns3/node-container.h"
16#include "ns3/probabilistic-v2v-channel-condition-model.h"
17#include "ns3/simulator.h"
18#include "ns3/test.h"
19#include "ns3/three-gpp-v2v-propagation-loss-model.h"
20#include "ns3/uinteger.h"
21
22using namespace ns3;
23
24NS_LOG_COMPONENT_DEFINE("ProbabilisticV2vChannelConditionModelsTest");
25
26/**
27 * \ingroup propagation-tests
28 *
29 * Test case for the V2V Urban channel condition models using a fully
30 * probabilistic model to determine LOS, NLOS and NLOSv states. The test
31 * determines the channel condition multiple times,
32 * estimates the LOS and NLOSv probabilities and compares them with the values
33 * given by M. Boban, X.Gong, and W. Xu, “Modeling the evolution of line-of-sight
34 * blockage for V2V channels,” in IEEE 84th Vehicular Technology
35 * Conference (VTC-Fall), 2016. Methodology from channel-condition-model-
36 * test-suite.cc is used, extended to a system with three states.
37 */
39{
40 public:
41 /**
42 * Constructor
43 */
45
46 /**
47 * Destructor
48 */
50
51 private:
52 /**
53 * Builds the simulation scenario and perform the tests
54 */
55 void DoRun() override;
56
57 /**
58 * Evaluates the channel condition between two nodes by calling the method
59 * GetChannelCondition on m_condModel. If the channel condition is LOS it
60 * increments m_numLos, if NLOSv it increments m_numNlosv
61 * \param a the mobility model of the first node
62 * \param b the mobility model of the second node
63 */
65
66 /**
67 * Struct containing the parameters for each test
68 */
70 {
71 Vector m_positionA; //!< the position of the first node
72 Vector m_positionB; //!< the position of the second node
73 double m_pLos{0.0}; //!< LOS probability
74 double m_pNlosv{0.0}; //!< NLOSv probability
75 std::string m_density; //!< the vehicles density
76 TypeId m_typeId; //!< the type ID of the channel condition model to be used
77 };
78
79 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
81 uint64_t m_numLos{0}; //!< the number of LOS occurrences
82 uint64_t m_numNlosv{0}; //!< the number of NLOSv occurrences
83 double m_tolerance; //!< tolerance
84};
85
87 : TestCase("Test case for the class ProbabilisticV2vUrbanChannelConditionModel"),
88 m_testVectors(),
89 m_tolerance(5e-3)
90{
91}
92
96
97void
100{
101 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
102 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
103 {
104 m_numLos++;
105 }
106 else if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::NLOSv)
107 {
108 m_numNlosv++;
109 }
110}
111
112void
114{
117
118 // create the test vector
119 TestVector testVector;
120
121 // tests for the V2v Urban scenario
122 testVector.m_positionA = Vector(0, 0, 1.6);
123 testVector.m_positionB = Vector(10, 0, 1.6);
124 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8548 * exp(-0.0064 * 10.0)));
126 testVector.m_pNlosv = std::min(
127 1.0,
128 std::max(0.0,
129 1 / (0.0396 * 10.0) * exp(-(log(10.0) - 5.2718) * (log(10.0) - 5.2718) / 3.4827)));
130 testVector.m_density = "Low";
131 m_testVectors.Add(testVector);
132
133 testVector.m_positionA = Vector(0, 0, 1.6);
134 testVector.m_positionB = Vector(100, 0, 1.6);
135 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8548 * exp(-0.0064 * 100.0)));
137 testVector.m_pNlosv =
138 std::min(1.0,
139 std::max(0.0,
140 1 / (0.0396 * 100.0) *
141 exp(-(log(100.0) - 5.2718) * (log(100.0) - 5.2718) / 3.4827)));
142 testVector.m_density = "Low";
143 m_testVectors.Add(testVector);
144
145 testVector.m_positionA = Vector(0, 0, 1.6);
146 testVector.m_positionB = Vector(10, 0, 1.6);
147 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8372 * exp(-0.0114 * 10.0)));
149 testVector.m_pNlosv = std::min(
150 1.0,
151 std::max(0.0,
152 1 / (0.0312 * 10.0) * exp(-(log(10.0) - 5.0063) * (log(10.0) - 5.0063) / 2.4544)));
153 testVector.m_density = "Medium";
154 m_testVectors.Add(testVector);
155
156 testVector.m_positionA = Vector(0, 0, 1.6);
157 testVector.m_positionB = Vector(100, 0, 1.6);
158 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8372 * exp(-0.0114 * 100.0)));
160 testVector.m_pNlosv =
161 std::min(1.0,
162 std::max(0.0,
163 1 / (0.0312 * 100.0) *
164 exp(-(log(100.0) - 5.0063) * (log(100.0) - 5.0063) / 2.4544)));
165 testVector.m_density = "Medium";
166 m_testVectors.Add(testVector);
167
168 testVector.m_positionA = Vector(0, 0, 1.6);
169 testVector.m_positionB = Vector(10, 0, 1.6);
170 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8962 * exp(-0.017 * 10.0)));
172 testVector.m_pNlosv = std::min(
173 1.0,
174 std::max(0.0,
175 1 / (0.0242 * 10.0) * exp(-(log(10.0) - 5.0115) * (log(10.0) - 5.0115) / 2.2092)));
176 testVector.m_density = "High";
177 m_testVectors.Add(testVector);
178
179 testVector.m_positionA = Vector(0, 0, 1.6);
180 testVector.m_positionB = Vector(100, 0, 1.6);
181 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8962 * exp(-0.017 * 100.0)));
183 testVector.m_pNlosv =
184 std::min(1.0,
185 std::max(0.0,
186 1 / (0.0242 * 100.0) *
187 exp(-(log(100.0) - 5.0115) * (log(100.0) - 5.0115) / 2.2092)));
188 testVector.m_density = "High";
189 m_testVectors.Add(testVector);
190
191 // create the factory for the channel condition models
192 ObjectFactory condModelFactory;
193
194 // create the two nodes
196 nodes.Create(2);
197
198 // create the mobility models
201
202 // aggregate the nodes and the mobility models
205
206 // Get the channel condition multiple times and compute the LOS probability
207 uint32_t numberOfReps = 500000;
208 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
209 {
210 testVector = m_testVectors.Get(i);
211
212 // set the distance between the two nodes
213 a->SetPosition(testVector.m_positionA);
214 b->SetPosition(testVector.m_positionB);
215
216 // create the channel condition model
217 condModelFactory.SetTypeId(testVector.m_typeId);
219 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
220 m_condModel->AssignStreams(1);
221 m_condModel->SetAttribute("Density", StringValue(testVector.m_density));
222
223 m_numLos = 0;
224 m_numNlosv = 0;
225 for (uint32_t j = 0; j < numberOfReps; j++)
226 {
229 this,
230 a,
231 b);
232 }
233
236
237 double resultPlos = double(m_numLos) / double(numberOfReps);
238 double resultPnlosv = double(m_numNlosv) / double(numberOfReps);
239 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
240 << testVector.m_positionB << " numLos " << m_numLos
241 << " numberOfReps " << numberOfReps << " resultPlos "
242 << resultPlos << " ref " << testVector.m_pLos);
243 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
244 testVector.m_pLos,
246 "Got unexpected LOS probability");
247 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
248 << testVector.m_positionB << " numNlosv " << m_numNlosv
249 << " numberOfReps " << numberOfReps << " resultPnlosv "
250 << resultPnlosv << " ref " << testVector.m_pNlosv);
251 NS_TEST_EXPECT_MSG_EQ_TOL(resultPnlosv,
252 testVector.m_pNlosv,
254 "Got unexpected NLOSv probability");
255 }
256}
257
258/**
259 * \ingroup propagation-tests
260 *
261 * Test case for the V2V Highway channel condition models using a fully
262 * probabilistic model to determine LOS, NLOS and NLOSv states. The test
263 * determines the channel condition multiple times,
264 * estimates the LOS and NLOS probabilities and compares them with the values
265 * given by M. Boban, X.Gong, and W. Xu, “Modeling the evolution of line-of-sight
266 * blockage for V2V channels,” in IEEE 84th Vehicular Technology
267 * Conference (VTC-Fall), 2016. Methodology from channel-condition-model-
268 * test-suite.cc is used, extended to a system with three states.
269 */
271{
272 public:
273 /**
274 * Constructor
275 */
277
278 /**
279 * Destructor
280 */
282
283 private:
284 /**
285 * Builds the simulation scenario and perform the tests
286 */
287 void DoRun() override;
288
289 /**
290 * Evaluates the channel condition between two nodes by calling the method
291 * GetChannelCondition on m_condModel. If the channel condition is LOS it
292 * increments m_numLos, if NLOS it increments m_numNlos
293 * \param a the mobility model of the first node
294 * \param b the mobility model of the second node
295 */
297
298 /**
299 * Struct containing the parameters for each test
300 */
302 {
303 Vector m_positionA; //!< the position of the first node
304 Vector m_positionB; //!< the position of the second node
305 double m_pLos{0.0}; //!< LOS probability
306 double m_pNlos{0.0}; //!< NLOS probability
307 std::string m_density; //!< the vehicles density
308 TypeId m_typeId; //!< the type ID of the channel condition model to be used
309 };
310
311 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
313 uint64_t m_numLos{0}; //!< the number of LOS occurrences
314 uint64_t m_numNlos{0}; //!< the number of NLOS occurrences
315 double m_tolerance; //!< tolerance
316};
317
319 : TestCase("Test case for the class ProbabilisticV2vHighwayChannelConditionModel"),
320 m_testVectors(),
321 m_tolerance(5e-3)
322{
323}
324
328
329void
332{
333 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
334 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
335 {
336 m_numLos++;
337 }
338 else if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::NLOS)
339 {
340 m_numNlos++;
341 }
342}
343
344void
346{
349
350 // create the test vector
351 TestVector testVector;
352
353 // tests for the V2v Highway scenario
354 testVector.m_positionA = Vector(0, 0, 1.6);
355 testVector.m_positionB = Vector(10, 0, 1.6);
356 double aLos = 1.5e-6;
357 double bLos = -0.0015;
358 double cLos = 1.0;
359 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
361 double aNlos = -2.9e-7;
362 double bNlos = 0.00059;
363 double cNlos = 0.0017;
364 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
365 testVector.m_density = "Low";
366 m_testVectors.Add(testVector);
367
368 testVector.m_positionA = Vector(0, 0, 1.6);
369 testVector.m_positionB = Vector(100, 0, 1.6);
370 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
372 testVector.m_pNlos =
373 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
374 testVector.m_density = "Low";
375 m_testVectors.Add(testVector);
376
377 testVector.m_positionA = Vector(0, 0, 1.6);
378 testVector.m_positionB = Vector(10, 0, 1.6);
379 aLos = 2.7e-6;
380 bLos = -0.0025;
381 cLos = 1.0;
382 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
384 aNlos = -3.7e-7;
385 bNlos = 0.00061;
386 cNlos = 0.015;
387 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
388 testVector.m_density = "Medium";
389 m_testVectors.Add(testVector);
390
391 testVector.m_positionA = Vector(0, 0, 1.6);
392 testVector.m_positionB = Vector(100, 0, 1.6);
393 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
395 testVector.m_pNlos =
396 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
397 testVector.m_density = "Medium";
398 m_testVectors.Add(testVector);
399
400 testVector.m_positionA = Vector(0, 0, 1.6);
401 testVector.m_positionB = Vector(10, 0, 1.6);
402 aLos = 3.2e-6;
403 bLos = -0.003;
404 cLos = 1.0;
405 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
407 aNlos = -4.1e-7;
408 bNlos = 0.00067;
409 cNlos = 0.0;
410 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
411 testVector.m_density = "High";
412 m_testVectors.Add(testVector);
413
414 testVector.m_positionA = Vector(0, 0, 1.6);
415 testVector.m_positionB = Vector(100, 0, 1.6);
416 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
418 testVector.m_pNlos =
419 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
420 testVector.m_density = "High";
421 m_testVectors.Add(testVector);
422
423 // create the factory for the channel condition models
424 ObjectFactory condModelFactory;
425
426 // create the two nodes
428 nodes.Create(2);
429
430 // create the mobility models
433
434 // aggregate the nodes and the mobility models
437
438 // Get the channel condition multiple times and compute the LOS probability
439 uint32_t numberOfReps = 500000;
440 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
441 {
442 testVector = m_testVectors.Get(i);
443
444 // set the distance between the two nodes
445 a->SetPosition(testVector.m_positionA);
446 b->SetPosition(testVector.m_positionB);
447
448 // create the channel condition model
449 condModelFactory.SetTypeId(testVector.m_typeId);
451 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
452 m_condModel->AssignStreams(1);
453 m_condModel->SetAttribute("Density", StringValue(testVector.m_density));
454
455 m_numLos = 0;
456 m_numNlos = 0;
457 for (uint32_t j = 0; j < numberOfReps; j++)
458 {
461 this,
462 a,
463 b);
464 }
465
468
469 double resultPlos = double(m_numLos) / double(numberOfReps);
470 double resultPnlos = double(m_numNlos) / double(numberOfReps);
471 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
472 << testVector.m_positionB << " numLos " << m_numLos
473 << " numberOfReps " << numberOfReps << " resultPlos "
474 << resultPlos << " ref " << testVector.m_pLos);
475 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
476 testVector.m_pLos,
478 "Got unexpected LOS probability");
479 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
480 << testVector.m_positionB << " numNlos " << m_numNlos
481 << " numberOfReps " << numberOfReps << " resultPnlos "
482 << resultPnlos << " ref " << testVector.m_pNlos);
483 NS_TEST_EXPECT_MSG_EQ_TOL(resultPnlos,
484 testVector.m_pNlos,
486 "Got unexpected NLOS probability");
487 }
488}
489
490/**
491 * \ingroup propagation-tests
492 *
493 * Test suite for the probabilistic V2V channel condition model
494 *
495 * The tests V2vUrbanProbChCondModelTestCase and
496 * V2vHighwayProbChCondModelTestCase test a fully probabilistic
497 * model for V2V channel condition, for Urban and Highway V2V scenarios,
498 * respectively. Basically, the model determines NLOS/LOS/NLOSv state based
499 * on probability formulas, derived from: M. Boban, X.Gong, and W. Xu,
500 * “Modeling the evolution of line-of-sight blockage for V2V channels,”
501 * in IEEE 84th Vehicular Technology Conference (VTC-Fall), 2016.
502 *
503 */
509
511 : TestSuite("probabilistic-v2v-channel-condition-model", Type::SYSTEM)
512{
514 TestCase::Duration::QUICK); // test for a fully probabilistic model (NLOS vs LOS
515 // vs NLOSv), in V2V urban scenario
517 TestCase::Duration::QUICK); // test for a fully probabilistic model (NLOS vs LOS
518 // vs NLOSv), in V2V highway scenario*/
519}
520
521/// Static variable for test initialization
Test suite for the probabilistic V2V channel condition model.
Test case for the V2V Highway channel condition models using a fully probabilistic model to determine...
void EvaluateChannelCondition(Ptr< MobilityModel > a, Ptr< MobilityModel > b)
Evaluates the channel condition between two nodes by calling the method GetChannelCondition on m_cond...
Ptr< ProbabilisticV2vHighwayChannelConditionModel > 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
Test case for the V2V Urban channel condition models using a fully probabilistic model to determine L...
TestVectors< TestVector > m_testVectors
array containing all the test vectors
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< ProbabilisticV2vUrbanChannelConditionModel > m_condModel
the channel condition model
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
Computes the channel condition for the V2V Highway scenario.
Computes the channel condition for the V2V Urban scenario.
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
Hold variables of type string.
Definition string.h:45
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
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.
static ProbabilisticV2vChCondModelsTestSuite g_probabilisticV2vChCondModelsTestSuite
Static variable for test initialization.
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