A Discrete-Event Network Simulator
API
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 
35 using namespace ns3;
36 
37 NS_LOG_COMPONENT_DEFINE("ThreeGppV2vChannelConditionModelsTest");
38 
50 {
51  public:
56 
61 
62  private:
66  void DoRun() override;
67 
71  struct TestVector
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 
93 void
95 {
96  RngSeedManager::SetSeed(1);
97  RngSeedManager::SetRun(1);
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;
104  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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;
110  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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;
116  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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;
123  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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;
129  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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;
135  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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>();
146  nodes.Get(0)->AggregateObject(a);
147 
148  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
149  nodes.Get(1)->AggregateObject(b);
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 
157  BuildingsHelper::Install(nodes);
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);
163  Ptr<ChannelConditionModel> condModel =
164  DynamicCast<ChannelConditionModel>(condModelFactory.Create());
165  condModel->AssignStreams(1);
166 
167  a->SetPosition(testVector.m_positionA);
168  b->SetPosition(testVector.m_positionB);
170  buildingInfoA->MakeConsistent(a);
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 
183  Simulator::Destroy();
184 }
185 
194 {
195  public:
200 
205 
206  private:
210  void DoRun() override;
211 
220 
224  struct TestVector
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 
249 void
252 {
254  if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
255  {
256  m_numLos++;
257  }
258 }
259 
260 void
262 {
263  RngSeedManager::SetSeed(1);
264  RngSeedManager::SetRun(1);
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));
273  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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));
279  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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));
285  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId();
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
300  nodes.Get(0)->AggregateObject(a);
301  nodes.Get(1)->AggregateObject(b);
302 
303  BuildingsHelper::Install(nodes);
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);
315  buildingInfoA->MakeConsistent(a);
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  {
328  Simulator::Schedule(
329  MilliSeconds(10 * j),
331  this,
332  a,
333  b);
334  }
335 
336  Simulator::Run();
337  Simulator::Destroy();
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,
346  m_tolerance,
347  "Got unexpected LOS probability");
348  }
349 }
350 
359 {
360  public:
365 
370 
371  private:
375  void DoRun() override;
376 
385 
389  struct TestVector
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 
414 void
417 {
419  if (cond->GetLosCondition() == ChannelCondition::LosConditionValue::LOS)
420  {
421  m_numLos++;
422  }
423 }
424 
425 void
427 {
428  RngSeedManager::SetSeed(1);
429  RngSeedManager::SetRun(1);
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);
438  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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);
444  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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));
450  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId();
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
465  nodes.Get(0)->AggregateObject(a);
466  nodes.Get(1)->AggregateObject(b);
467 
468  BuildingsHelper::Install(nodes);
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  {
489  Simulator::Schedule(
490  MilliSeconds(10 * j),
492  this,
493  a,
494  b);
495  }
496 
497  Simulator::Run();
498  Simulator::Destroy();
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,
507  m_tolerance,
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 
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
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
LosConditionValue
Possible values for Line-of-Sight condition.
mobility buildings information (to be used by mobility models)
void SetPosition(const Vector &position)
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:204
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
encapsulates test code
Definition: test.h:1060
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.
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:1338
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
static ThreeGppV2vChCondModelsTestSuite ThreeGppV2vChCondModelsTestSuite
Static variable for test initialization.