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
50{
51 public:
56
61
62 private:
66 void DoRun() override;
67
72 {
73 Vector m_positionA;
74 Vector m_positionB;
77 };
78
80};
81
83 : TestCase("Test case for the ThreeGppV2vUrban and ThreeGppV2vHighway ChannelConditionModel "
84 "with building"),
85 m_testVectors()
86{
87}
88
90{
91}
92
93void
95{
98
99 TestVector testVector;
100 // Add vectors for ThreeGppV2vUrbanChannelConditionModel
101 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
102 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
103 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
105 m_testVectors.Add(testVector);
106
107 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
108 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
109 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
111 m_testVectors.Add(testVector);
112
113 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
114 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
115 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
117 m_testVectors.Add(testVector);
118
119 // Now add same vectors for ThreeGppV2vHighwayChannelConditionModel
120 testVector.m_positionA = Vector(-5.0, 5.0, 1.5);
121 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
122 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
124 m_testVectors.Add(testVector);
125
126 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
127 testVector.m_positionB = Vector(4.0, 11.0, 1.5);
128 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
130 m_testVectors.Add(testVector);
131
132 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
133 testVector.m_positionB = Vector(1000.0, 11.0, 1.5);
134 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
136 m_testVectors.Add(testVector);
137
138 // create the factory for the channel condition models
139 ObjectFactory condModelFactory;
140
141 // Deploy nodes and building and get the channel condition
143 nodes.Create(2);
144
145 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
147
148 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
150
151 Ptr<Building> building = Create<Building>();
152 building->SetNRoomsX(1);
153 building->SetNRoomsY(1);
154 building->SetNFloors(1);
155 building->SetBoundaries(Box(0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
156
158
159 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
160 {
161 testVector = m_testVectors.Get(i);
162 condModelFactory.SetTypeId(testVector.m_typeId);
164 DynamicCast<ChannelConditionModel>(condModelFactory.Create());
165 condModel->AssignStreams(1);
166
167 a->SetPosition(testVector.m_positionA);
168 b->SetPosition(testVector.m_positionB);
169 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
170 buildingInfoA->MakeConsistent(a);
171 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
172 buildingInfoB->MakeConsistent(b);
174 cond = condModel->GetChannelCondition(a, b);
175
176 NS_LOG_DEBUG("Got " << cond->GetLosCondition() << " expected condition "
177 << testVector.m_losCond);
178 NS_TEST_ASSERT_MSG_EQ(cond->GetLosCondition(),
179 testVector.m_losCond,
180 "Got unexpected channel condition");
181 }
182
184}
185
194{
195 public:
200
205
206 private:
210 void DoRun() override;
211
220
225 {
226 Vector m_positionA;
227 Vector m_positionB;
228 double m_pLos;
230 };
231
234 uint64_t m_numLos{0};
235 double m_tolerance;
236};
237
239 : TestCase("Test case for the class ThreeGppV2vUrbanChannelConditionModel"),
240 m_testVectors(),
241 m_tolerance(2e-3)
242{
243}
244
246{
247}
248
249void
252{
254 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
255 {
256 m_numLos++;
257 }
258}
259
260void
262{
265
266 // create the test vector
267 TestVector testVector;
268
269 // tests for the V2v Urban scenario
270 testVector.m_positionA = Vector(0, 0, 1.6);
271 testVector.m_positionB = Vector(10, 0, 1.6);
272 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 10.0));
274 m_testVectors.Add(testVector);
275
276 testVector.m_positionA = Vector(0, 0, 1.6);
277 testVector.m_positionB = Vector(100, 0, 1.6);
278 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 100.0));
280 m_testVectors.Add(testVector);
281
282 testVector.m_positionA = Vector(0, 0, 1.6);
283 testVector.m_positionB = Vector(1000, 0, 1.6);
284 testVector.m_pLos = std::min(1.0, 1.05 * exp(-0.0114 * 1000.0));
286 m_testVectors.Add(testVector);
287
288 // create the factory for the channel condition models
289 ObjectFactory condModelFactory;
290
291 // create the two nodes
293 nodes.Create(2);
294
295 // create the mobility models
296 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
297 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
298
299 // aggregate the nodes and the mobility models
302
304
305 // Get the channel condition multiple times and compute the LOS probability
306 uint32_t numberOfReps = 500000;
307 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
308 {
309 testVector = m_testVectors.Get(i);
310
311 // set the distance between the two nodes
312 a->SetPosition(testVector.m_positionA);
313 b->SetPosition(testVector.m_positionB);
314 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
315 buildingInfoA->MakeConsistent(a);
316 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
317 buildingInfoB->MakeConsistent(b);
318
319 // create the channel condition model
320 condModelFactory.SetTypeId(testVector.m_typeId);
322 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
324
325 m_numLos = 0;
326 for (uint32_t j = 0; j < numberOfReps; j++)
327 {
329 MilliSeconds(10 * j),
331 this,
332 a,
333 b);
334 }
335
338
339 double resultPlos = double(m_numLos) / double(numberOfReps);
340 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
341 << testVector.m_positionB << " numLos " << m_numLos
342 << " numberOfReps " << numberOfReps << " resultPlos "
343 << resultPlos << " ref " << testVector.m_pLos);
344 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
345 testVector.m_pLos,
347 "Got unexpected LOS probability");
348 }
349}
350
359{
360 public:
365
370
371 private:
375 void DoRun() override;
376
385
390 {
391 Vector m_positionA;
392 Vector m_positionB;
393 double m_pLos;
395 };
396
399 uint64_t m_numLos{0};
400 double m_tolerance;
401};
402
404 : TestCase("Test case for the class ThreeGppV2vHighwayChannelConditionModel"),
405 m_testVectors(),
406 m_tolerance(2e-3)
407{
408}
409
411{
412}
413
414void
417{
419 if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
420 {
421 m_numLos++;
422 }
423}
424
425void
427{
430
431 // create the test vector
432 TestVector testVector;
433
434 // tests for the V2v Highway scenario
435 testVector.m_positionA = Vector(0, 0, 1.6);
436 testVector.m_positionB = Vector(10, 0, 1.6);
437 testVector.m_pLos = std::min(1.0, 0.0000021013 * 10.0 * 10.0 - 0.002 * 10.0 + 1.0193);
439 m_testVectors.Add(testVector);
440
441 testVector.m_positionA = Vector(0, 0, 1.6);
442 testVector.m_positionB = Vector(100, 0, 1.6);
443 testVector.m_pLos = std::min(1.0, 0.0000021013 * 100.0 * 100.0 - 0.002 * 100.0 + 1.0193);
445 m_testVectors.Add(testVector);
446
447 testVector.m_positionA = Vector(0, 0, 1.6);
448 testVector.m_positionB = Vector(1000, 0, 1.6);
449 testVector.m_pLos = std::max(0.0, 0.54 - 0.001 * (1000.0 - 475));
451 m_testVectors.Add(testVector);
452
453 // create the factory for the channel condition models
454 ObjectFactory condModelFactory;
455
456 // create the two nodes
458 nodes.Create(2);
459
460 // create the mobility models
461 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
462 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
463
464 // aggregate the nodes and the mobility models
467
469
470 // Get the channel condition multiple times and compute the LOS probability
471 uint32_t numberOfReps = 500000;
472 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
473 {
474 testVector = m_testVectors.Get(i);
475
476 // set the distance between the two nodes
477 a->SetPosition(testVector.m_positionA);
478 b->SetPosition(testVector.m_positionB);
479
480 // create the channel condition model
481 condModelFactory.SetTypeId(testVector.m_typeId);
483 m_condModel->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(9)));
485
486 m_numLos = 0;
487 for (uint32_t j = 0; j < numberOfReps; j++)
488 {
490 MilliSeconds(10 * j),
492 this,
493 a,
494 b);
495 }
496
499
500 double resultPlos = static_cast<double>(m_numLos) / static_cast<double>(numberOfReps);
501 NS_LOG_DEBUG(testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos "
502 << testVector.m_positionB << " numLos " << m_numLos
503 << " numberOfReps " << numberOfReps << " resultPlos "
504 << resultPlos << " ref " << testVector.m_pLos);
505 NS_TEST_EXPECT_MSG_EQ_TOL(resultPlos,
506 testVector.m_pLos,
508 "Got unexpected LOS probability");
509 }
510}
511
536{
537 public:
539};
540
542 : TestSuite("three-gpp-v2v-channel-condition-model", SYSTEM)
543{
545 TestCase::QUICK); // test for the deterministic procedure (NLOS vs LOS/NLOSv), based
546 // on buildings
548 TestCase::QUICK); // test for the probabilistic procedure (LOS vs NLOSv), in V2V
549 // urban scenario
551 TestCase::QUICK); // test for the probabilistic procedure (LOS vs NLOSv), in V2V
552 // highway scenario
553}
554
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:200
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:259
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1319
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:1423
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:144
#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:510
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
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