A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
* SPDX-License-Identifier: GPL-2.0-only
6
*/
7
8
#include "ns3/abort.h"
9
#include "ns3/buildings-channel-condition-model.h"
10
#include "ns3/buildings-module.h"
11
#include "ns3/config.h"
12
#include "ns3/constant-position-mobility-model.h"
13
#include "ns3/log.h"
14
#include "ns3/simulator.h"
15
#include "ns3/test.h"
16
17
using namespace
ns3
;
18
19
NS_LOG_COMPONENT_DEFINE
(
"BuildingsChannelConditionModelsTest"
);
20
21
/**
22
* @ingroup building-test
23
*
24
* Test case for the class BuildingsChannelConditionModel. It checks if the
25
* channel condition is correctly determined when a building is deployed in the
26
* scenario
27
*/
28
class
BuildingsChannelConditionModelTestCase
:
public
TestCase
29
{
30
public
:
31
/**
32
* Constructor
33
*/
34
BuildingsChannelConditionModelTestCase
();
35
36
/**
37
* Destructor
38
*/
39
~BuildingsChannelConditionModelTestCase
()
override
;
40
41
private
:
42
/**
43
* Builds the simulation scenario and perform the tests
44
*/
45
void
DoRun
()
override
;
46
47
/**
48
* Struct containing the parameters for each test
49
*/
50
struct
TestVector
51
{
52
Vector
m_positionA
;
//!< the position of the first node
53
Vector
m_positionB
;
//!< the position of the second node
54
ChannelCondition::LosConditionValue
m_losCond
;
//!< the correct channel condition
55
};
56
57
TestVectors<TestVector>
m_testVectors
;
//!< array containing all the test vectors
58
};
59
60
BuildingsChannelConditionModelTestCase::BuildingsChannelConditionModelTestCase
()
61
:
TestCase
(
"Test case for the BuildingsChannelConditionModel"
),
62
m_testVectors
()
63
{
64
}
65
66
BuildingsChannelConditionModelTestCase::~BuildingsChannelConditionModelTestCase
()
67
{
68
}
69
70
void
71
BuildingsChannelConditionModelTestCase::DoRun
()
72
{
73
TestVector
testVector;
74
75
testVector.
m_positionA
= Vector(0.0, 5.0, 1.5);
76
testVector.
m_positionB
= Vector(20.0, 5.0, 1.5);
77
testVector.
m_losCond
=
ChannelCondition::LosConditionValue::NLOS
;
78
m_testVectors
.Add(testVector);
79
80
testVector.
m_positionA
= Vector(0.0, 11.0, 1.5);
81
testVector.
m_positionB
= Vector(20.0, 11.0, 1.5);
82
testVector.
m_losCond
=
ChannelCondition::LosConditionValue::LOS
;
83
m_testVectors
.Add(testVector);
84
85
testVector.
m_positionA
= Vector(5.0, 5.0, 1.5);
86
testVector.
m_positionB
= Vector(20.0, 5.0, 1.5);
87
testVector.
m_losCond
=
ChannelCondition::LosConditionValue::NLOS
;
88
m_testVectors
.Add(testVector);
89
90
testVector.
m_positionA
= Vector(4.0, 5.0, 1.5);
91
testVector.
m_positionB
= Vector(5.0, 5.0, 1.5);
92
testVector.
m_losCond
=
ChannelCondition::LosConditionValue::LOS
;
93
m_testVectors
.Add(testVector);
94
95
// Deploy nodes and building and get the channel condition
96
NodeContainer
nodes
;
97
nodes
.Create(2);
98
99
Ptr<MobilityModel>
a =
CreateObject<ConstantPositionMobilityModel>
();
100
nodes
.Get(0)->AggregateObject(a);
101
102
Ptr<MobilityModel>
b =
CreateObject<ConstantPositionMobilityModel>
();
103
nodes
.Get(1)->AggregateObject(b);
104
105
Ptr<BuildingsChannelConditionModel>
condModel =
CreateObject<BuildingsChannelConditionModel>
();
106
107
auto
building =
CreateObject<Building>
();
108
building->SetNRoomsX(1);
109
building->SetNRoomsY(1);
110
building->SetNFloors(1);
111
building->SetBoundaries(
Box
(0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
112
building->SetExtWallsType(
Building::ExtWallsType_t::Wood
);
113
114
BuildingsHelper::Install
(
nodes
);
115
116
for
(
uint32_t
i = 0; i <
m_testVectors
.GetN(); ++i)
117
{
118
testVector =
m_testVectors
.Get(i);
119
a->SetPosition(testVector.
m_positionA
);
120
b->SetPosition(testVector.
m_positionB
);
121
Ptr<MobilityBuildingInfo>
buildingInfoA = a->GetObject<
MobilityBuildingInfo
>();
122
buildingInfoA->MakeConsistent(a);
123
Ptr<MobilityBuildingInfo>
buildingInfoB = b->GetObject<
MobilityBuildingInfo
>();
124
buildingInfoA->MakeConsistent(b);
125
Ptr<ChannelCondition>
cond = condModel->GetChannelCondition(a, b);
126
127
NS_LOG_DEBUG
(
"Got "
<< cond->GetLosCondition() <<
" expected condition "
128
<< testVector.
m_losCond
);
129
NS_TEST_ASSERT_MSG_EQ
(cond->GetLosCondition(),
130
testVector.
m_losCond
,
131
" Got unexpected channel condition"
);
132
}
133
134
Simulator::Destroy
();
135
}
136
137
/**
138
* @ingroup building-test
139
* Test suite for the buildings channel condition model
140
*/
141
class
BuildingsChannelConditionModelsTestSuite
:
public
TestSuite
142
{
143
public
:
144
BuildingsChannelConditionModelsTestSuite
();
145
};
146
147
BuildingsChannelConditionModelsTestSuite::BuildingsChannelConditionModelsTestSuite
()
148
:
TestSuite
(
"buildings-channel-condition-model"
,
Type
::
UNIT
)
149
{
150
AddTestCase
(
new
BuildingsChannelConditionModelTestCase
,
TestCase::Duration::QUICK
);
151
}
152
153
/// Static variable for test initialization
154
static
BuildingsChannelConditionModelsTestSuite
BuildingsChannelConditionModelsTestSuite
;
BuildingsChannelConditionModelTestCase
Test case for the class BuildingsChannelConditionModel.
Definition
buildings-channel-condition-model-test.cc:29
BuildingsChannelConditionModelTestCase::DoRun
void DoRun() override
Builds the simulation scenario and perform the tests.
Definition
buildings-channel-condition-model-test.cc:71
BuildingsChannelConditionModelTestCase::~BuildingsChannelConditionModelTestCase
~BuildingsChannelConditionModelTestCase() override
Destructor.
Definition
buildings-channel-condition-model-test.cc:66
BuildingsChannelConditionModelTestCase::BuildingsChannelConditionModelTestCase
BuildingsChannelConditionModelTestCase()
Constructor.
Definition
buildings-channel-condition-model-test.cc:60
BuildingsChannelConditionModelTestCase::m_testVectors
TestVectors< TestVector > m_testVectors
array containing all the test vectors
Definition
buildings-channel-condition-model-test.cc:57
BuildingsChannelConditionModelsTestSuite
Test suite for the buildings channel condition model.
Definition
buildings-channel-condition-model-test.cc:142
BuildingsChannelConditionModelsTestSuite::BuildingsChannelConditionModelsTestSuite
BuildingsChannelConditionModelsTestSuite()
Definition
buildings-channel-condition-model-test.cc:147
ns3::Box
a 3d box
Definition
box.h:24
ns3::Building::Wood
@ Wood
Definition
building.h:57
ns3::BuildingsHelper::Install
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
Definition
buildings-helper.cc:34
ns3::ChannelCondition::LosConditionValue
LosConditionValue
Possible values for Line-of-Sight condition.
Definition
channel-condition-model.h:39
ns3::ChannelCondition::NLOS
@ NLOS
Non Line of Sight.
Definition
channel-condition-model.h:41
ns3::ChannelCondition::LOS
@ LOS
Line of Sight.
Definition
channel-condition-model.h:40
ns3::MobilityBuildingInfo
mobility buildings information (to be used by mobility models)
Definition
mobility-building-info.h:37
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:67
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestCase::Duration::QUICK
@ QUICK
Fast test.
Definition
test.h:1055
ns3::TestCase::TestCase
TestCase(const TestCase &)=delete
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::TestSuite
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition
test.cc:490
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::TestVectors
A simple way to store test vectors (for stimulus or from responses)
Definition
test.h:1348
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition
log.h:257
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
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:134
nodes
NodeContainer nodes
Definition
lr-wpan-bootstrap.cc:43
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
BuildingsChannelConditionModelTestCase::TestVector
Struct containing the parameters for each test.
Definition
buildings-channel-condition-model-test.cc:51
BuildingsChannelConditionModelTestCase::TestVector::m_positionB
Vector m_positionB
the position of the second node
Definition
buildings-channel-condition-model-test.cc:53
BuildingsChannelConditionModelTestCase::TestVector::m_losCond
ChannelCondition::LosConditionValue m_losCond
the correct channel condition
Definition
buildings-channel-condition-model-test.cc:54
BuildingsChannelConditionModelTestCase::TestVector::m_positionA
Vector m_positionA
the position of the first node
Definition
buildings-channel-condition-model-test.cc:52
src
buildings
test
buildings-channel-condition-model-test.cc
Generated on Mon Sep 1 2025 18:20:45 for ns-3 by
1.13.2