A Discrete-Event Network Simulator
API
three-gpp-v2v-channel-condition-model-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  * Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #include "ns3/abort.h"
21 #include "ns3/test.h"
22 #include "ns3/config.h"
23 #include "ns3/buildings-channel-condition-model.h"
24 #include "ns3/channel-condition-model.h"
25 #include "ns3/three-gpp-v2v-channel-condition-model.h"
26 #include "ns3/three-gpp-v2v-propagation-loss-model.h"
27 #include "ns3/constant-position-mobility-model.h"
28 #include "ns3/buildings-module.h"
29 #include "ns3/log.h"
30 #include "ns3/simulator.h"
31 #include "ns3/double.h"
32 #include "ns3/uinteger.h"
33 #include "ns3/boolean.h"
34 #include "ns3/core-module.h"
35 
36 using namespace ns3;
37 
38 NS_LOG_COMPONENT_DEFINE ("ThreeGppV2vChannelConditionModelsTest");
39 
51 {
52 public:
57 
62 
63 private:
67  virtual void DoRun (void);
68 
72  typedef struct
73  {
74  Vector m_positionA;
75  Vector m_positionB;
78  } TestVector;
79 
81 };
82 
84  : TestCase ("Test case for the ThreeGppV2vUrban and ThreeGppV2vHighway ChannelConditionModel with building"), m_testVectors ()
85 {}
86 
88 {}
89 
90 void
92 {
93  RngSeedManager::SetSeed (1);
94  RngSeedManager::SetRun (1);
95 
96  TestVector testVector;
97  //Add vectors for ThreeGppV2vUrbanChannelConditionModel
98  testVector.m_positionA = Vector (-5.0, 5.0, 1.5);
99  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
100  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
101  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
102  m_testVectors.Add (testVector);
103 
104  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
105  testVector.m_positionB = Vector (4.0, 11.0, 1.5);
106  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
107  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
108  m_testVectors.Add (testVector);
109 
110  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
111  testVector.m_positionB = Vector (1000.0, 11.0, 1.5);
112  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
113  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
114  m_testVectors.Add (testVector);
115 
116  //Now add same vectors for ThreeGppV2vHighwayChannelConditionModel
117  testVector.m_positionA = Vector (-5.0, 5.0, 1.5);
118  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
119  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
120  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
121  m_testVectors.Add (testVector);
122 
123  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
124  testVector.m_positionB = Vector (4.0, 11.0, 1.5);
125  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
126  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
127  m_testVectors.Add (testVector);
128 
129  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
130  testVector.m_positionB = Vector (1000.0, 11.0, 1.5);
131  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOSv;
132  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
133  m_testVectors.Add (testVector);
134 
135  // create the factory for the channel condition models
136  ObjectFactory condModelFactory;
137 
138  // Deploy nodes and building and get the channel condition
140  nodes.Create (2);
141 
142  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
143  nodes.Get (0)->AggregateObject (a);
144 
145  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
146  nodes.Get (1)->AggregateObject (b);
147 
148  Ptr<Building> building = Create<Building> ();
149  building->SetNRoomsX (1);
150  building->SetNRoomsY (1);
151  building->SetNFloors (1);
152  building->SetBoundaries (Box (0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
153 
154  BuildingsHelper::Install (nodes);
155 
156  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
157  {
158  testVector = m_testVectors.Get (i);
159  condModelFactory.SetTypeId (testVector.m_typeId);
160  Ptr<ChannelConditionModel> condModel = DynamicCast<ChannelConditionModel> (condModelFactory.Create ());
161  condModel->AssignStreams (1);
162 
163  a->SetPosition (testVector.m_positionA);
164  b->SetPosition (testVector.m_positionB);
166  buildingInfoA->MakeConsistent (a);
168  buildingInfoB->MakeConsistent (b);
170  cond = condModel->GetChannelCondition (a, b);
171 
172  NS_LOG_DEBUG ("Got " << cond->GetLosCondition () << " expected condition " << testVector.m_losCond);
173  NS_TEST_ASSERT_MSG_EQ (cond->GetLosCondition (), testVector.m_losCond, "Got unexpected channel condition");
174  }
175 
176  Simulator::Destroy ();
177 }
178 
187 {
188 public:
193 
198 
199 private:
203  virtual void DoRun (void);
204 
213 
217  typedef struct
218  {
219  Vector m_positionA;
220  Vector m_positionB;
221  double m_pLos;
223  } TestVector;
224 
227  uint64_t m_numLos {0};
228  double m_tolerance;
229 };
230 
232  : TestCase ("Test case for the class ThreeGppV2vUrbanChannelConditionModel"),
233  m_testVectors (),
234  m_tolerance (2e-3)
235 {}
236 
238 {}
239 
240 void
242 {
244  if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::LOS)
245  {
246  m_numLos++;
247  }
248 }
249 
250 void
252 {
253  RngSeedManager::SetSeed (1);
254  RngSeedManager::SetRun (1);
255 
256  // create the test vector
257  TestVector testVector;
258 
259  // tests for the V2v Urban scenario
260  testVector.m_positionA = Vector (0, 0, 1.6);
261  testVector.m_positionB = Vector (10, 0, 1.6);
262  testVector.m_pLos = std::min (1.0, 1.05 * exp (-0.0114 * 10.0));
263  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
264  m_testVectors.Add (testVector);
265 
266  testVector.m_positionA = Vector (0, 0, 1.6);
267  testVector.m_positionB = Vector (100, 0, 1.6);
268  testVector.m_pLos = std::min (1.0, 1.05 * exp (-0.0114 * 100.0));
269  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
270  m_testVectors.Add (testVector);
271 
272  testVector.m_positionA = Vector (0, 0, 1.6);
273  testVector.m_positionB = Vector (1000, 0, 1.6);
274  testVector.m_pLos = std::min (1.0, 1.05 * exp (-0.0114 * 1000.0));
275  testVector.m_typeId = ThreeGppV2vUrbanChannelConditionModel::GetTypeId ();
276  m_testVectors.Add (testVector);
277 
278  // create the factory for the channel condition models
279  ObjectFactory condModelFactory;
280 
281  // create the two nodes
283  nodes.Create (2);
284 
285  // create the mobility models
286  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
287  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
288 
289  // aggregate the nodes and the mobility models
290  nodes.Get (0)->AggregateObject (a);
291  nodes.Get (1)->AggregateObject (b);
292 
293  BuildingsHelper::Install (nodes);
294 
295  // Get the channel condition multiple times and compute the LOS probability
296  uint32_t numberOfReps = 500000;
297  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
298  {
299  testVector = m_testVectors.Get (i);
300 
301  // set the distance between the two nodes
302  a->SetPosition (testVector.m_positionA);
303  b->SetPosition (testVector.m_positionB);
305  buildingInfoA->MakeConsistent (a);
307  buildingInfoB->MakeConsistent (b);
308 
309  // create the channel condition model
310  condModelFactory.SetTypeId (testVector.m_typeId);
312  m_condModel->SetAttribute ("UpdatePeriod", TimeValue (MilliSeconds (9)));
314 
315  m_numLos = 0;
316  for (uint32_t j = 0; j < numberOfReps; j++)
317  {
318  Simulator::Schedule (MilliSeconds (10 * j), &ThreeGppV2vUrbanLosNlosvChCondModelTestCase::EvaluateChannelCondition, this, a, b);
319  }
320 
321  Simulator::Run ();
322  Simulator::Destroy ();
323 
324  double resultPlos = double (m_numLos) / double (numberOfReps);
325  NS_LOG_DEBUG (testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos " << testVector.m_positionB << " numLos " << m_numLos << " numberOfReps " << numberOfReps << " resultPlos " << resultPlos << " ref " << testVector.m_pLos);
326  NS_TEST_EXPECT_MSG_EQ_TOL (resultPlos, testVector.m_pLos, m_tolerance, "Got unexpected LOS probability");
327  }
328 }
329 
338 {
339 public:
344 
349 
350 private:
354  virtual void DoRun (void);
355 
364 
368  typedef struct
369  {
370  Vector m_positionA;
371  Vector m_positionB;
372  double m_pLos;
374  } TestVector;
375 
378  uint64_t m_numLos {0};
379  double m_tolerance;
380 };
381 
383  : TestCase ("Test case for the class ThreeGppV2vHighwayChannelConditionModel"),
384  m_testVectors (),
385  m_tolerance (2e-3)
386 {}
387 
389 {}
390 
391 void
393 {
395  if (cond->GetLosCondition () == ChannelCondition::LosConditionValue::LOS)
396  {
397  m_numLos++;
398  }
399 }
400 
401 void
403 {
404  RngSeedManager::SetSeed (1);
405  RngSeedManager::SetRun (1);
406 
407  // create the test vector
408  TestVector testVector;
409 
410  // tests for the V2v Highway scenario
411  testVector.m_positionA = Vector (0, 0, 1.6);
412  testVector.m_positionB = Vector (10, 0, 1.6);
413  testVector.m_pLos = std::min (1.0, 0.0000021013 * 10.0 * 10.0 - 0.002 * 10.0 + 1.0193);
414  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
415  m_testVectors.Add (testVector);
416 
417  testVector.m_positionA = Vector (0, 0, 1.6);
418  testVector.m_positionB = Vector (100, 0, 1.6);
419  testVector.m_pLos = std::min (1.0, 0.0000021013 * 100.0 * 100.0 - 0.002 * 100.0 + 1.0193);
420  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
421  m_testVectors.Add (testVector);
422 
423  testVector.m_positionA = Vector (0, 0, 1.6);
424  testVector.m_positionB = Vector (1000, 0, 1.6);
425  testVector.m_pLos = std::max (0.0, 0.54 - 0.001 * (1000.0 - 475));
426  testVector.m_typeId = ThreeGppV2vHighwayChannelConditionModel::GetTypeId ();
427  m_testVectors.Add (testVector);
428 
429  // create the factory for the channel condition models
430  ObjectFactory condModelFactory;
431 
432  // create the two nodes
434  nodes.Create (2);
435 
436  // create the mobility models
437  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
438  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
439 
440  // aggregate the nodes and the mobility models
441  nodes.Get (0)->AggregateObject (a);
442  nodes.Get (1)->AggregateObject (b);
443 
444  BuildingsHelper::Install (nodes);
445 
446  // Get the channel condition multiple times and compute the LOS probability
447  uint32_t numberOfReps = 500000;
448  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
449  {
450  testVector = m_testVectors.Get (i);
451 
452  // set the distance between the two nodes
453  a->SetPosition (testVector.m_positionA);
454  b->SetPosition (testVector.m_positionB);
455 
456  // create the channel condition model
457  condModelFactory.SetTypeId (testVector.m_typeId);
459  m_condModel->SetAttribute ("UpdatePeriod", TimeValue (MilliSeconds (9)));
461 
462  m_numLos = 0;
463  for (uint32_t j = 0; j < numberOfReps; j++)
464  {
466  }
467 
468  Simulator::Run ();
469  Simulator::Destroy ();
470 
471  double resultPlos = static_cast<double> (m_numLos) / static_cast<double> (numberOfReps);
472  NS_LOG_DEBUG (testVector.m_typeId << " a pos " << testVector.m_positionA << " b pos " << testVector.m_positionB << " numLos " << m_numLos << " numberOfReps " << numberOfReps << " resultPlos " << resultPlos << " ref " << testVector.m_pLos);
473  NS_TEST_EXPECT_MSG_EQ_TOL (resultPlos, testVector.m_pLos, m_tolerance, "Got unexpected LOS probability");
474  }
475 }
476 
477 
502 {
503 public:
505 };
506 
508  : TestSuite ("three-gpp-v2v-channel-condition-model", SYSTEM)
509 {
510  AddTestCase (new ThreeGppV2vBuildingsChCondModelTestCase, TestCase::QUICK); // test for the deterministic procedure (NLOS vs LOS/NLOSv), based on buildings
511  AddTestCase (new ThreeGppV2vUrbanLosNlosvChCondModelTestCase, TestCase::QUICK); // test for the probabilistic procedure (LOS vs NLOSv), in V2V urban scenario
512  AddTestCase (new ThreeGppV2vHighwayLosNlosvChCondModelTestCase, TestCase::QUICK); // test for the probabilistic procedure (LOS vs NLOSv), in V2V highway scenario
513 }
514 
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Test case for the classes ThreeGppV2vUrbanChannelConditionModel, and ThreeGppV2vHighwayChannelConditi...
virtual void DoRun(void)
Builds the simulation scenario and perform the tests.
TestVectors< TestVector > m_testVectors
array containg 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...
virtual void DoRun(void)
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
virtual void DoRun(void)
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 SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) 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(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1251
virtual int64_t AssignStreams(int64_t stream) override
If this model uses objects of type RandomVariableStream, set the stream numbers to the integers start...
virtual 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:1308
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:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:141
#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:491
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
nodes
Definition: first.py:32
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.