A Discrete-Event Network Simulator
API
buildings-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) 2019 SIGNET Lab, Department of Information Engineering,
4  * University of Padova
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/constant-position-mobility-model.h"
25 #include "ns3/buildings-module.h"
26 #include "ns3/log.h"
27 #include "ns3/simulator.h"
28 
29 using namespace ns3;
30 
31 NS_LOG_COMPONENT_DEFINE ("BuildingsChannelConditionModelsTest");
32 
39 {
40 public:
45 
50 
51 private:
55  virtual void DoRun (void);
56 
60  typedef struct
61  {
62  Vector m_positionA;
63  Vector m_positionB;
65  } TestVector;
66 
68 };
69 
71  : TestCase ("Test case for the BuildingsChannelConditionModel"), m_testVectors ()
72 {
73 }
74 
76 {
77 }
78 
79 void
81 {
82  TestVector testVector;
83 
84  testVector.m_positionA = Vector (0.0, 5.0, 1.5);
85  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
86  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
87  m_testVectors.Add (testVector);
88 
89  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
90  testVector.m_positionB = Vector (20.0, 11.0, 1.5);
91  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
92  m_testVectors.Add (testVector);
93 
94  testVector.m_positionA = Vector (5.0, 5.0, 1.5);
95  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
96  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
97  m_testVectors.Add (testVector);
98 
99  testVector.m_positionA = Vector (4.0, 5.0, 1.5);
100  testVector.m_positionB = Vector (5.0, 5.0, 1.5);
101  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
102  m_testVectors.Add (testVector);
103 
104  // Deploy nodes and building and get the channel condition
106  nodes.Create (2);
107 
108  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
109  nodes.Get (0)->AggregateObject (a);
110 
111  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
112  nodes.Get (1)->AggregateObject (b);
113 
114  Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel> ();
115 
116  Ptr<Building> building = Create<Building> ();
117  building->SetNRoomsX (1);
118  building->SetNRoomsY (1);
119  building->SetNFloors (1);
120  building->SetBoundaries (Box (0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
121 
122  BuildingsHelper::Install (nodes);
123 
124  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
125  {
126  testVector = m_testVectors.Get (i);
127  a->SetPosition (testVector.m_positionA);
128  b->SetPosition (testVector.m_positionB);
130  buildingInfoA->MakeConsistent (a);
132  buildingInfoA->MakeConsistent (b);
133  Ptr<ChannelCondition> cond = condModel->GetChannelCondition (a, b);
134 
135  NS_LOG_DEBUG ("Got " << cond->GetLosCondition () << " expected condition " << testVector.m_losCond);
136  NS_TEST_ASSERT_MSG_EQ (cond->GetLosCondition (), testVector.m_losCond, " Got unexpected channel condition");
137  }
138 
139  Simulator::Destroy ();
140 }
141 
146 {
147 public:
149 };
150 
152  : TestSuite ("buildings-channel-condition-model", UNIT)
153 {
155 }
156 
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::MobilityModel::SetPosition
void SetPosition(const Vector &position)
Definition: mobility-model.cc:88
BuildingsChannelConditionModelTestCase
Test case for the class BuildingsChannelConditionModel.
Definition: buildings-channel-condition-model-test.cc:39
ns3::ChannelCondition::LosConditionValue
LosConditionValue
Possible values for Line-of-Sight condition.
Definition: channel-condition-model.h:49
BuildingsChannelConditionModelTestCase::~BuildingsChannelConditionModelTestCase
virtual ~BuildingsChannelConditionModelTestCase()
Destructor.
Definition: buildings-channel-condition-model-test.cc:75
BuildingsChannelConditionModelTestCase::TestVector::m_positionB
Vector m_positionB
the position of the second node
Definition: buildings-channel-condition-model-test.cc:63
ns3::Building::SetNRoomsX
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:167
first.nodes
nodes
Definition: first.py:32
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::Ptr< MobilityModel >
BuildingsChannelConditionModelTestCase::m_testVectors
TestVectors< TestVector > m_testVectors
array containg all the test vectors
Definition: buildings-channel-condition-model-test.cc:67
BuildingsChannelConditionModelTestCase::TestVector::m_losCond
ChannelCondition::LosConditionValue m_losCond
the correct channel condition
Definition: buildings-channel-condition-model-test.cc:64
ns3::MobilityBuildingInfo::MakeConsistent
void MakeConsistent(Ptr< MobilityModel > mm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
Definition: mobility-building-info.cc:170
BuildingsChannelConditionModelsTestSuite::BuildingsChannelConditionModelsTestSuite
BuildingsChannelConditionModelsTestSuite()
Definition: buildings-channel-condition-model-test.cc:151
ns3::MobilityBuildingInfo
mobility buildings information (to be used by mobility models)
Definition: mobility-building-info.h:49
BuildingsChannelConditionModelTestCase::TestVector
Struct containing the parameters for each test.
Definition: buildings-channel-condition-model-test.cc:61
ns3::Building::SetBoundaries
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:139
ns3::ChannelCondition::GetLosCondition
LosConditionValue GetLosCondition() const
Get the LosConditionValue contaning the information about the LOS/NLOS state of the channel.
Definition: channel-condition-model.cc:60
BuildingsChannelConditionModelTestCase::BuildingsChannelConditionModelTestCase
BuildingsChannelConditionModelTestCase()
Constructor.
Definition: buildings-channel-condition-model-test.cc:70
ns3::BuildingsChannelConditionModel::GetChannelCondition
virtual Ptr< ChannelCondition > GetChannelCondition(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Computes the condition of the channel between a and b.
Definition: buildings-channel-condition-model.cc:55
BuildingsChannelConditionModelTestCase::TestVector::m_positionA
Vector m_positionA
the position of the first node
Definition: buildings-channel-condition-model-test.cc:62
ns3::Building::SetNRoomsY
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:174
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
BuildingsChannelConditionModelTestCase::DoRun
virtual void DoRun(void)
Builds the simulation scenario and perform the tests.
Definition: buildings-channel-condition-model-test.cc:80
NS_TEST_ASSERT_MSG_EQ
#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:166
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::Box
a 3d box
Definition: box.h:35
BuildingsChannelConditionModelsTestSuite
Test suite for the buildings channel condition model.
Definition: buildings-channel-condition-model-test.cc:146
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
BuildingsChannelConditionModelsTestSuite
static BuildingsChannelConditionModelsTestSuite BuildingsChannelConditionModelsTestSuite
Definition: buildings-channel-condition-model-test.cc:157
ns3::TestVectors
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1407
ns3::Building::SetNFloors
void SetNFloors(uint16_t nfloors)
Definition: building.cc:160