A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
outdoor-random-walk-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/building.h"
24
#include "ns3/building-position-allocator.h"
25
#include "ns3/random-walk-2d-outdoor-mobility-model.h"
26
#include "ns3/mobility-helper.h"
27
#include "ns3/log.h"
28
#include "ns3/simulator.h"
29
#include "ns3/double.h"
30
#include "ns3/pointer.h"
31
32
using namespace
ns3
;
33
34
NS_LOG_COMPONENT_DEFINE
(
"OutdoorRandomWalkTest"
);
35
40
class
OutdoorRandomWalkTestCase
:
public
TestCase
41
{
42
public
:
46
OutdoorRandomWalkTestCase
();
47
51
virtual
~
OutdoorRandomWalkTestCase
();
52
53
private
:
57
virtual
void
DoRun (
void
);
58
59
void
CheckPositionOutdoor (
Ptr<RandomWalk2dOutdoorMobilityModel>
model);
60
61
std::vector<Ptr<Building> >
m_buildings
;
62
};
63
64
OutdoorRandomWalkTestCase::OutdoorRandomWalkTestCase
()
65
:
TestCase
(
"Test case for the BuildingsChannelConditionModel"
), m_buildings ()
66
{}
67
68
OutdoorRandomWalkTestCase::~OutdoorRandomWalkTestCase
()
69
{}
70
71
void
72
OutdoorRandomWalkTestCase::CheckPositionOutdoor
(
Ptr<RandomWalk2dOutdoorMobilityModel>
model)
73
{
74
auto
position = model->
GetPosition
();
75
for
(
auto
building :
m_buildings
)
76
{
77
NS_TEST_ASSERT_MSG_EQ
(building->IsInside (position),
false
,
"Position "
<< position <<
" is inside"
);
78
}
79
}
80
81
void
82
OutdoorRandomWalkTestCase::DoRun
(
void
)
83
{
84
// create a grid of buildings
85
double
buildingSizeX = 100;
// m
86
double
buildingSizeY = 50;
// m
87
double
streetWidth = 25;
// m
88
double
buildingHeight = 10;
// m
89
uint32_t numBuildingsX = 20;
90
uint32_t numBuildingsY = 20;
91
double
maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
92
double
maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
93
94
for
(uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
95
{
96
for
(uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
97
{
98
Ptr < Building >
building;
99
building = CreateObject<Building> ();
100
101
building->
SetBoundaries
(
Box
(buildingIdX * (buildingSizeX + streetWidth),
102
buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
103
buildingIdY * (buildingSizeY + streetWidth),
104
buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
105
0.0, buildingHeight));
106
building->
SetNRoomsX
(1);
107
building->
SetNRoomsY
(1);
108
building->
SetNFloors
(1);
109
m_buildings
.push_back (building);
110
}
111
}
112
113
// create one node
114
NodeContainer
nodes
;
115
nodes
.Create (1);
116
117
// set the RandomWalk2dOutdoorMobilityModel mobility model
118
MobilityHelper
mobility
;
119
mobility
.SetMobilityModel (
"ns3::RandomWalk2dOutdoorMobilityModel"
,
120
"Bounds"
,
RectangleValue
(
121
Rectangle
(-streetWidth, maxAxisX, -streetWidth, maxAxisY)));
122
// create an OutdoorPositionAllocator and set its boundaries to match those of the mobility model
123
Ptr<OutdoorPositionAllocator>
position = CreateObject<OutdoorPositionAllocator> ();
124
Ptr<UniformRandomVariable>
xPos = CreateObject<UniformRandomVariable>();
125
xPos->
SetAttribute
(
"Min"
,
DoubleValue
(-streetWidth));
126
xPos->
SetAttribute
(
"Max"
,
DoubleValue
(maxAxisX));
127
Ptr<UniformRandomVariable>
yPos = CreateObject<UniformRandomVariable>();
128
yPos->
SetAttribute
(
"Min"
,
DoubleValue
(-streetWidth));
129
yPos->
SetAttribute
(
"Max"
,
DoubleValue
(maxAxisY));
130
position->
SetAttribute
(
"X"
,
PointerValue
(xPos));
131
position->
SetAttribute
(
"Y"
,
PointerValue
(yPos));
132
mobility
.SetPositionAllocator (position);
133
// install the mobility model
134
mobility
.Install (
nodes
.Get (0));
135
136
auto
mobilityModel =
nodes
.Get (0)->GetObject<
RandomWalk2dOutdoorMobilityModel
>();
137
138
// get maxChecks positions, check if they are outdoors
139
double
testStep = 10;
// s
140
int
maxChecks = 1000;
141
for
(
int
i = 0; i < maxChecks; ++i)
142
{
143
Simulator::Schedule (
Seconds
(i * testStep),
144
&
OutdoorRandomWalkTestCase::CheckPositionOutdoor
,
this
, mobilityModel);
145
}
146
147
Simulator::Stop (
Seconds
(maxChecks * testStep + 1));
148
Simulator::Run ();
149
Simulator::Destroy ();
150
}
151
155
class
OutdoorRandomWalkTestSuite
:
public
TestSuite
156
{
157
public
:
158
OutdoorRandomWalkTestSuite
();
159
};
160
161
OutdoorRandomWalkTestSuite::OutdoorRandomWalkTestSuite
()
162
:
TestSuite
(
"outdoor-random-walk-model"
, UNIT)
163
{
164
AddTestCase
(
new
OutdoorRandomWalkTestCase
, TestCase::QUICK);
165
}
166
167
static
OutdoorRandomWalkTestSuite
OutdoorRandomWalkTestSuite
;
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::RectangleValue
AttributeValue implementation for Rectangle.
Definition:
rectangle.h:97
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition:
pointer.h:37
ns3::ObjectBase::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition:
object-base.cc:185
ns3::Building::SetNRoomsX
void SetNRoomsX(uint16_t nroomx)
Definition:
building.cc:167
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition:
double.h:41
OutdoorRandomWalkTestCase::DoRun
virtual void DoRun(void)
Builds the simulation scenario and perform the tests.
Definition:
outdoor-random-walk-test.cc:82
first.nodes
nodes
Definition:
first.py:32
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
OutdoorRandomWalkTestCase::m_buildings
std::vector< Ptr< Building > > m_buildings
Definition:
outdoor-random-walk-test.cc:61
ns3::Building::SetBoundaries
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition:
building.cc:139
OutdoorRandomWalkTestCase::~OutdoorRandomWalkTestCase
virtual ~OutdoorRandomWalkTestCase()
Destructor.
Definition:
outdoor-random-walk-test.cc:68
OutdoorRandomWalkTestSuite::OutdoorRandomWalkTestSuite
OutdoorRandomWalkTestSuite()
Definition:
outdoor-random-walk-test.cc:161
ns3::Building::SetNRoomsY
void SetNRoomsY(uint16_t nroomy)
Definition:
building.cc:174
OutdoorRandomWalkTestCase
Test case for the class OutdoorRandomWalkTestCase.
Definition:
outdoor-random-walk-test.cc:41
OutdoorRandomWalkTestCase::CheckPositionOutdoor
void CheckPositionOutdoor(Ptr< RandomWalk2dOutdoorMobilityModel > model)
Definition:
outdoor-random-walk-test.cc:72
ns3::Rectangle
a 2d rectangle
Definition:
rectangle.h:35
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
OutdoorRandomWalkTestSuite
static OutdoorRandomWalkTestSuite OutdoorRandomWalkTestSuite
Definition:
outdoor-random-walk-test.cc:167
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
OutdoorRandomWalkTestCase::OutdoorRandomWalkTestCase
OutdoorRandomWalkTestCase()
Constructor.
Definition:
outdoor-random-walk-test.cc:64
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1289
ns3::Box
a 3d box
Definition:
box.h:35
OutdoorRandomWalkTestSuite
Test suite for the buildings channel condition model.
Definition:
outdoor-random-walk-test.cc:156
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:39
ns3::MobilityModel::GetPosition
Vector GetPosition(void) const
Definition:
mobility-model.cc:64
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition:
mobility-helper.h:43
third.mobility
mobility
Definition:
third.py:108
ns3::RandomWalk2dOutdoorMobilityModel
2D random walk mobility model which avoids buildings.
Definition:
random-walk-2d-outdoor-mobility-model.h:58
ns3::Building::SetNFloors
void SetNFloors(uint16_t nfloors)
Definition:
building.cc:160
src
buildings
test
outdoor-random-walk-test.cc
Generated on Fri Oct 1 2021 17:02:56 for ns-3 by
1.8.20