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/double.h"
13#include "ns3/log.h"
14#include "ns3/node-container.h"
15#include "ns3/probabilistic-v2v-channel-condition-model.h"
16#include "ns3/rng-seed-manager.h"
17#include "ns3/simulator.h"
18#include "ns3/string.h"
19#include "ns3/test.h"
20#include "ns3/three-gpp-v2v-propagation-loss-model.h"
21#include "ns3/uinteger.h"
22
23using namespace ns3;
24
25NS_LOG_COMPONENT_DEFINE("ProbabilisticV2vChannelConditionModelsTest");
26
27/**
28 * @ingroup propagation-tests
29 *
30 * Test case for the V2V Urban channel condition models using a fully
31 * probabilistic model to determine LOS, NLOS and NLOSv states. The test
32 * determines the channel condition multiple times,
33 * estimates the LOS and NLOSv probabilities and compares them with the values
34 * given by M. Boban, X.Gong, and W. Xu, “Modeling the evolution of line-of-sight
35 * blockage for V2V channels,” in IEEE 84th Vehicular Technology
36 * Conference (VTC-Fall), 2016. Methodology from channel-condition-model-
37 * test-suite.cc is used, extended to a system with three states.
38 */
40{
41 public:
42 /**
43 * Constructor
44 */
46
47 /**
48 * Destructor
49 */
51
52 private:
53 /**
54 * Builds the simulation scenario and perform the tests
55 */
56 void DoRun() override;
57
58 /**
59 * Evaluates the channel condition between two nodes by calling the method
60 * GetChannelCondition on m_condModel. If the channel condition is LOS it
61 * increments m_numLos, if NLOSv it increments m_numNlosv
62 * @param a the mobility model of the first node
63 * @param b the mobility model of the second node
64 */
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 double m_pLos{0.0}; //!< LOS probability
75 double m_pNlosv{0.0}; //!< NLOSv probability
76 std::string m_density; //!< the vehicles density
77 TypeId m_typeId; //!< the type ID of the channel condition model to be used
78 };
79
80 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
82 uint64_t m_numLos{0}; //!< the number of LOS occurrences
83 uint64_t m_numNlosv{0}; //!< the number of NLOSv occurrences
84 double m_tolerance; //!< tolerance
85};
86
88 : TestCase("Test case for the class ProbabilisticV2vUrbanChannelConditionModel"),
90 m_tolerance(5e-3)
91{
92}
93
97
98void
101{
102 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
103 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
104 {
105 m_numLos++;
106 }
107 else if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::NLOSv)
108 {
109 m_numNlosv++;
110 }
111}
112
113void
115{
118
119 // create the test vector
120 TestVector testVector;
121
122 // tests for the V2v Urban scenario
123 testVector.m_positionA = Vector(0, 0, 1.6);
124 testVector.m_positionB = Vector(10, 0, 1.6);
125 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8548 * exp(-0.0064 * 10.0)));
127 testVector.m_pNlosv = std::min(
128 1.0,
129 std::max(0.0,
130 1 / (0.0396 * 10.0) * exp(-(log(10.0) - 5.2718) * (log(10.0) - 5.2718) / 3.4827)));
131 testVector.m_density = "Low";
132 m_testVectors.Add(testVector);
133
134 testVector.m_positionA = Vector(0, 0, 1.6);
135 testVector.m_positionB = Vector(100, 0, 1.6);
136 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8548 * exp(-0.0064 * 100.0)));
138 testVector.m_pNlosv =
139 std::min(1.0,
140 std::max(0.0,
141 1 / (0.0396 * 100.0) *
142 exp(-(log(100.0) - 5.2718) * (log(100.0) - 5.2718) / 3.4827)));
143 testVector.m_density = "Low";
144 m_testVectors.Add(testVector);
145
146 testVector.m_positionA = Vector(0, 0, 1.6);
147 testVector.m_positionB = Vector(10, 0, 1.6);
148 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8372 * exp(-0.0114 * 10.0)));
150 testVector.m_pNlosv = std::min(
151 1.0,
152 std::max(0.0,
153 1 / (0.0312 * 10.0) * exp(-(log(10.0) - 5.0063) * (log(10.0) - 5.0063) / 2.4544)));
154 testVector.m_density = "Medium";
155 m_testVectors.Add(testVector);
156
157 testVector.m_positionA = Vector(0, 0, 1.6);
158 testVector.m_positionB = Vector(100, 0, 1.6);
159 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8372 * exp(-0.0114 * 100.0)));
161 testVector.m_pNlosv =
162 std::min(1.0,
163 std::max(0.0,
164 1 / (0.0312 * 100.0) *
165 exp(-(log(100.0) - 5.0063) * (log(100.0) - 5.0063) / 2.4544)));
166 testVector.m_density = "Medium";
167 m_testVectors.Add(testVector);
168
169 testVector.m_positionA = Vector(0, 0, 1.6);
170 testVector.m_positionB = Vector(10, 0, 1.6);
171 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8962 * exp(-0.017 * 10.0)));
173 testVector.m_pNlosv = std::min(
174 1.0,
175 std::max(0.0,
176 1 / (0.0242 * 10.0) * exp(-(log(10.0) - 5.0115) * (log(10.0) - 5.0115) / 2.2092)));
177 testVector.m_density = "High";
178 m_testVectors.Add(testVector);
179
180 testVector.m_positionA = Vector(0, 0, 1.6);
181 testVector.m_positionB = Vector(100, 0, 1.6);
182 testVector.m_pLos = std::min(1.0, std::max(0.0, 0.8962 * exp(-0.017 * 100.0)));
184 testVector.m_pNlosv =
185 std::min(1.0,
186 std::max(0.0,
187 1 / (0.0242 * 100.0) *
188 exp(-(log(100.0) - 5.0115) * (log(100.0) - 5.0115) / 2.2092)));
189 testVector.m_density = "High";
190 m_testVectors.Add(testVector);
191
192 // create the factory for the channel condition models
193 ObjectFactory condModelFactory;
194
195 // create the two nodes
197 nodes.Create(2);
198
199 // create the mobility models
202
203 // aggregate the nodes and the mobility models
204 nodes.Get(0)->AggregateObject(a);
205 nodes.Get(1)->AggregateObject(b);
206
207 // Get the channel condition multiple times and compute the LOS probability
208 uint32_t numberOfReps = 500000;
209 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
210 {
211 testVector = m_testVectors.Get(i);
212
213 // set the distance between the two nodes
214 a->SetPosition(testVector.m_positionA);
215 b->SetPosition(testVector.m_positionB);
216
217 // create the channel condition model
218 condModelFactory.SetTypeId(testVector.m_typeId);
220 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
221 m_condModel->AssignStreams(1);
222 m_condModel->SetAttribute("Density", StringValue(testVector.m_density));
223
224 m_numLos = 0;
225 m_numNlosv = 0;
226 for (uint32_t j = 0; j < numberOfReps; j++)
227 {
230 this,
231 a,
232 b);
233 }
234
237
238 double resultPlos = double(m_numLos) / double(numberOfReps);
239 double resultPnlosv = double(m_numNlosv) / double(numberOfReps);
240 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
241 << testVector.m_positionB << " numLos " << m_numLos
242 << " numberOfReps " << numberOfReps << " resultPlos "
243 << resultPlos << " ref " << testVector.m_pLos);
244 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
245 testVector.m_pLos,
247 "Got unexpected LOS probability");
248 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
249 << testVector.m_positionB << " numNlosv " << m_numNlosv
250 << " numberOfReps " << numberOfReps << " resultPnlosv "
251 << resultPnlosv << " ref " << testVector.m_pNlosv);
252 NS_TEST_EXPECT_MSG_EQ_TOL(resultPnlosv,
253 testVector.m_pNlosv,
255 "Got unexpected NLOSv probability");
256 }
257}
258
259/**
260 * @ingroup propagation-tests
261 *
262 * Test case for the V2V Highway channel condition models using a fully
263 * probabilistic model to determine LOS, NLOS and NLOSv states. The test
264 * determines the channel condition multiple times,
265 * estimates the LOS and NLOS probabilities and compares them with the values
266 * given by M. Boban, X.Gong, and W. Xu, “Modeling the evolution of line-of-sight
267 * blockage for V2V channels,” in IEEE 84th Vehicular Technology
268 * Conference (VTC-Fall), 2016. Methodology from channel-condition-model-
269 * test-suite.cc is used, extended to a system with three states.
270 */
272{
273 public:
274 /**
275 * Constructor
276 */
278
279 /**
280 * Destructor
281 */
283
284 private:
285 /**
286 * Builds the simulation scenario and perform the tests
287 */
288 void DoRun() override;
289
290 /**
291 * Evaluates the channel condition between two nodes by calling the method
292 * GetChannelCondition on m_condModel. If the channel condition is LOS it
293 * increments m_numLos, if NLOS it increments m_numNlos
294 * @param a the mobility model of the first node
295 * @param b the mobility model of the second node
296 */
298
299 /**
300 * Struct containing the parameters for each test
301 */
303 {
304 Vector m_positionA; //!< the position of the first node
305 Vector m_positionB; //!< the position of the second node
306 double m_pLos{0.0}; //!< LOS probability
307 double m_pNlos{0.0}; //!< NLOS probability
308 std::string m_density; //!< the vehicles density
309 TypeId m_typeId; //!< the type ID of the channel condition model to be used
310 };
311
312 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
314 uint64_t m_numLos{0}; //!< the number of LOS occurrences
315 uint64_t m_numNlos{0}; //!< the number of NLOS occurrences
316 double m_tolerance; //!< tolerance
317};
318
320 : TestCase("Test case for the class ProbabilisticV2vHighwayChannelConditionModel"),
322 m_tolerance(5e-3)
323{
324}
325
329
330void
333{
334 Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition(a, b);
335 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
336 {
337 m_numLos++;
338 }
339 else if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::NLOS)
340 {
341 m_numNlos++;
342 }
343}
344
345void
347{
350
351 // create the test vector
352 TestVector testVector;
353
354 // tests for the V2v Highway scenario
355 testVector.m_positionA = Vector(0, 0, 1.6);
356 testVector.m_positionB = Vector(10, 0, 1.6);
357 double aLos = 1.5e-6;
358 double bLos = -0.0015;
359 double cLos = 1.0;
360 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
362 double aNlos = -2.9e-7;
363 double bNlos = 0.00059;
364 double cNlos = 0.0017;
365 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
366 testVector.m_density = "Low";
367 m_testVectors.Add(testVector);
368
369 testVector.m_positionA = Vector(0, 0, 1.6);
370 testVector.m_positionB = Vector(100, 0, 1.6);
371 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
373 testVector.m_pNlos =
374 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
375 testVector.m_density = "Low";
376 m_testVectors.Add(testVector);
377
378 testVector.m_positionA = Vector(0, 0, 1.6);
379 testVector.m_positionB = Vector(10, 0, 1.6);
380 aLos = 2.7e-6;
381 bLos = -0.0025;
382 cLos = 1.0;
383 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
385 aNlos = -3.7e-7;
386 bNlos = 0.00061;
387 cNlos = 0.015;
388 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
389 testVector.m_density = "Medium";
390 m_testVectors.Add(testVector);
391
392 testVector.m_positionA = Vector(0, 0, 1.6);
393 testVector.m_positionB = Vector(100, 0, 1.6);
394 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
396 testVector.m_pNlos =
397 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
398 testVector.m_density = "Medium";
399 m_testVectors.Add(testVector);
400
401 testVector.m_positionA = Vector(0, 0, 1.6);
402 testVector.m_positionB = Vector(10, 0, 1.6);
403 aLos = 3.2e-6;
404 bLos = -0.003;
405 cLos = 1.0;
406 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 10.0 * 10.0 + bLos * 10.0 + cLos));
408 aNlos = -4.1e-7;
409 bNlos = 0.00067;
410 cNlos = 0.0;
411 testVector.m_pNlos = std::min(1.0, std::max(0.0, aNlos * 10.0 * 10.0 + bNlos * 10.0 + cNlos));
412 testVector.m_density = "High";
413 m_testVectors.Add(testVector);
414
415 testVector.m_positionA = Vector(0, 0, 1.6);
416 testVector.m_positionB = Vector(100, 0, 1.6);
417 testVector.m_pLos = std::min(1.0, std::max(0.0, aLos * 100.0 * 100.0 + bLos * 100.0 + cLos));
419 testVector.m_pNlos =
420 std::min(1.0, std::max(0.0, aNlos * 100.0 * 100.0 + bNlos * 100.0 + cNlos));
421 testVector.m_density = "High";
422 m_testVectors.Add(testVector);
423
424 // create the factory for the channel condition models
425 ObjectFactory condModelFactory;
426
427 // create the two nodes
429 nodes.Create(2);
430
431 // create the mobility models
434
435 // aggregate the nodes and the mobility models
436 nodes.Get(0)->AggregateObject(a);
437 nodes.Get(1)->AggregateObject(b);
438
439 // Get the channel condition multiple times and compute the LOS probability
440 uint32_t numberOfReps = 500000;
441 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
442 {
443 testVector = m_testVectors.Get(i);
444
445 // set the distance between the two nodes
446 a->SetPosition(testVector.m_positionA);
447 b->SetPosition(testVector.m_positionB);
448
449 // create the channel condition model
450 condModelFactory.SetTypeId(testVector.m_typeId);
452 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
453 m_condModel->AssignStreams(1);
454 m_condModel->SetAttribute("Density", StringValue(testVector.m_density));
455
456 m_numLos = 0;
457 m_numNlos = 0;
458 for (uint32_t j = 0; j < numberOfReps; j++)
459 {
462 this,
463 a,
464 b);
465 }
466
469
470 double resultPlos = double(m_numLos) / double(numberOfReps);
471 double resultPnlos = double(m_numNlos) / double(numberOfReps);
472 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
473 << testVector.m_positionB << " numLos " << m_numLos
474 << " numberOfReps " << numberOfReps << " resultPlos "
475 << resultPlos << " ref " << testVector.m_pLos);
476 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
477 testVector.m_pLos,
479 "Got unexpected LOS probability");
480 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
481 << testVector.m_positionB << " numNlos " << m_numNlos
482 << " numberOfReps " << numberOfReps << " resultPnlos "
483 << resultPnlos << " ref " << testVector.m_pNlos);
484 NS_TEST_EXPECT_MSG_EQ_TOL(resultPnlos,
485 testVector.m_pNlos,
487 "Got unexpected NLOS probability");
488 }
489}
490
491/**
492 * @ingroup propagation-tests
493 *
494 * Test suite for the probabilistic V2V channel condition model
495 *
496 * The tests V2vUrbanProbChCondModelTestCase and
497 * V2vHighwayProbChCondModelTestCase test a fully probabilistic
498 * model for V2V channel condition, for Urban and Highway V2V scenarios,
499 * respectively. Basically, the model determines NLOS/LOS/NLOSv state based
500 * on probability formulas, derived from: M. Boban, X.Gong, and W. Xu,
501 * “Modeling the evolution of line-of-sight blockage for V2V channels,”
502 * in IEEE 84th Vehicular Technology Conference (VTC-Fall), 2016.
503 *
504 */
510
512 : TestSuite("probabilistic-v2v-channel-condition-model", Type::SYSTEM)
513{
515 TestCase::Duration::QUICK); // test for a fully probabilistic model (NLOS vs LOS
516 // vs NLOSv), in V2V urban scenario
518 TestCase::Duration::QUICK); // test for a fully probabilistic model (NLOS vs LOS
519 // vs NLOSv), in V2V highway scenario*/
520}
521
522/// 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
@ NLOSv
Non Line of Sight due to a vehicle.
keep track of a set of node pointers.
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.
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.
Definition ptr.h:70
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:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
Hold variables of type string.
Definition string.h:45
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
A simple way to store test vectors (for stimulus or from responses).
Definition test.h:1328
a unique identifier for an interface.
Definition type-id.h:50
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#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:499
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
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