A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
buildings-channel-condition-model-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
3 * University of Padova
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/buildings-channel-condition-model.h"
21#include "ns3/buildings-module.h"
22#include "ns3/config.h"
23#include "ns3/constant-position-mobility-model.h"
24#include "ns3/log.h"
25#include "ns3/simulator.h"
26#include "ns3/test.h"
27
28using namespace ns3;
29
30NS_LOG_COMPONENT_DEFINE("BuildingsChannelConditionModelsTest");
31
32/**
33 * \ingroup building-test
34 *
35 * Test case for the class BuildingsChannelConditionModel. It checks if the
36 * channel condition is correctly determined when a building is deployed in the
37 * scenario
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 * Struct containing the parameters for each test
60 */
62 {
63 Vector m_positionA; //!< the position of the first node
64 Vector m_positionB; //!< the position of the second node
65 ChannelCondition::LosConditionValue m_losCond; //!< the correct channel condition
66 };
67
68 TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
69};
70
72 : TestCase("Test case for the BuildingsChannelConditionModel"),
73 m_testVectors()
74{
75}
76
78{
79}
80
81void
83{
84 TestVector testVector;
85
86 testVector.m_positionA = Vector(0.0, 5.0, 1.5);
87 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
88 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
89 m_testVectors.Add(testVector);
90
91 testVector.m_positionA = Vector(0.0, 11.0, 1.5);
92 testVector.m_positionB = Vector(20.0, 11.0, 1.5);
93 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
94 m_testVectors.Add(testVector);
95
96 testVector.m_positionA = Vector(5.0, 5.0, 1.5);
97 testVector.m_positionB = Vector(20.0, 5.0, 1.5);
98 testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
99 m_testVectors.Add(testVector);
100
101 testVector.m_positionA = Vector(4.0, 5.0, 1.5);
102 testVector.m_positionB = Vector(5.0, 5.0, 1.5);
103 testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
104 m_testVectors.Add(testVector);
105
106 // Deploy nodes and building and get the channel condition
108 nodes.Create(2);
109
110 Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel>();
112
113 Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel>();
115
116 Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel>();
117
118 Ptr<Building> building = Create<Building>();
119 building->SetNRoomsX(1);
120 building->SetNRoomsY(1);
121 building->SetNFloors(1);
122 building->SetBoundaries(Box(0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
123 building->SetExtWallsType(Building::ExtWallsType_t::Wood);
124
126
127 for (uint32_t i = 0; i < m_testVectors.GetN(); ++i)
128 {
129 testVector = m_testVectors.Get(i);
130 a->SetPosition(testVector.m_positionA);
131 b->SetPosition(testVector.m_positionB);
132 Ptr<MobilityBuildingInfo> buildingInfoA = a->GetObject<MobilityBuildingInfo>();
133 buildingInfoA->MakeConsistent(a);
134 Ptr<MobilityBuildingInfo> buildingInfoB = b->GetObject<MobilityBuildingInfo>();
135 buildingInfoA->MakeConsistent(b);
136 Ptr<ChannelCondition> cond = condModel->GetChannelCondition(a, b);
137
138 NS_LOG_DEBUG("Got " << cond->GetLosCondition() << " expected condition "
139 << testVector.m_losCond);
140 NS_TEST_ASSERT_MSG_EQ(cond->GetLosCondition(),
141 testVector.m_losCond,
142 " Got unexpected channel condition");
143 }
144
146}
147
148/**
149 * \ingroup building-test
150 * Test suite for the buildings channel condition model
151 */
153{
154 public:
156};
157
159 : TestSuite("buildings-channel-condition-model", Type::UNIT)
160{
161 AddTestCase(new BuildingsChannelConditionModelTestCase, TestCase::Duration::QUICK);
162}
163
164/// Static variable for test initialization
Test case for the class BuildingsChannelConditionModel.
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 buildings channel condition model.
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 AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:309
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1342
#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:145
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ChannelCondition::LosConditionValue m_losCond
the correct channel condition