A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
outdoor-random-walk-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/building-position-allocator.h"
21#include "ns3/building.h"
22#include "ns3/config.h"
23#include "ns3/double.h"
24#include "ns3/enum.h"
25#include "ns3/log.h"
26#include "ns3/mobility-helper.h"
27#include "ns3/pointer.h"
28#include "ns3/random-walk-2d-outdoor-mobility-model.h"
29#include "ns3/simulator.h"
30#include "ns3/test.h"
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("OutdoorRandomWalkTest");
35
44{
45 public:
48
49 private:
50 void DoRun() override;
51
57
58 std::vector<Ptr<Building>> m_buildings;
59};
60
62 : TestCase("Test case for the BuildingsChannelConditionModel"),
63 m_buildings()
64{
65}
66
68{
69}
70
71void
73{
74 auto position = model->GetPosition();
75 for (auto building : m_buildings)
76 {
77 NS_TEST_ASSERT_MSG_EQ(building->IsInside(position),
78 false,
79 "Position " << position << " is inside");
80 }
81}
82
83void
85{
86 // Samples to test and time steps
87 constexpr double TEST_STEP_S = 10; // s
88 constexpr int MAX_CHECKS = 1000;
89
90 // create a grid of buildings
91 double buildingSizeX = 100; // m
92 double buildingSizeY = 50; // m
93 double streetWidth = 25; // m
94 double buildingHeight = 10; // m
95 uint32_t numBuildingsX = 20;
96 uint32_t numBuildingsY = 20;
97 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
98 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
99
100 for (uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
101 {
102 for (uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
103 {
104 Ptr<Building> building;
105 building = CreateObject<Building>();
106
107 building->SetBoundaries(Box(buildingIdX * (buildingSizeX + streetWidth),
108 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
109 buildingIdY * (buildingSizeY + streetWidth),
110 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
111 0.0,
112 buildingHeight));
113 building->SetNRoomsX(1);
114 building->SetNRoomsY(1);
115 building->SetNFloors(1);
116 m_buildings.push_back(building);
117 }
118 }
119
120 // create one node
122 nodes.Create(1);
123
124 // set the RandomWalk2dOutdoorMobilityModel mobility model
125 MobilityHelper mobility;
126 mobility.SetMobilityModel(
127 "ns3::RandomWalk2dOutdoorMobilityModel",
128 "Bounds",
129 RectangleValue(Rectangle(-streetWidth, maxAxisX, -streetWidth, maxAxisY)),
130 "Mode",
132 "Time",
133 TimeValue(Seconds(TEST_STEP_S * MAX_CHECKS)));
134 // create an OutdoorPositionAllocator and set its boundaries to match those of the mobility
135 // model
136 Ptr<OutdoorPositionAllocator> position = CreateObject<OutdoorPositionAllocator>();
137 Ptr<UniformRandomVariable> xPos = CreateObject<UniformRandomVariable>();
138 xPos->SetAttribute("Min", DoubleValue(-streetWidth));
139 xPos->SetAttribute("Max", DoubleValue(maxAxisX));
140 Ptr<UniformRandomVariable> yPos = CreateObject<UniformRandomVariable>();
141 yPos->SetAttribute("Min", DoubleValue(-streetWidth));
142 yPos->SetAttribute("Max", DoubleValue(maxAxisY));
143 position->SetAttribute("X", PointerValue(xPos));
144 position->SetAttribute("Y", PointerValue(yPos));
145 mobility.SetPositionAllocator(position);
146 // install the mobility model
147 mobility.Install(nodes.Get(0));
148
149 auto mobilityModel = nodes.Get(0)->GetObject<RandomWalk2dOutdoorMobilityModel>();
150
151 // get MAX_CHECKS positions, check if they are outdoors
152 for (int i = 0; i < MAX_CHECKS; i++)
153 {
154 Simulator::Schedule(Seconds(i * TEST_STEP_S),
156 this,
157 mobilityModel);
158 }
159
160 Simulator::Stop(Seconds(MAX_CHECKS * TEST_STEP_S + 1));
163}
164
172{
173 public:
175};
176
178 : TestSuite("outdoor-random-walk-model", UNIT)
179{
181}
182
Test case for the class OutdoorRandomWalkTestCase.
void DoRun() override
Implementation to actually run this TestCase.
std::vector< Ptr< Building > > m_buildings
Buildings.
void CheckPositionOutdoor(Ptr< RandomWalk2dOutdoorMobilityModel > model)
Check that the position is the expected one.
Test suite for the buildings channel condition model.
a 3d box
Definition: box.h:35
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:62
Helper class used to assign positions and mobility models to nodes.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
2D random walk mobility model which avoids buildings.
a 2d rectangle
Definition: rectangle.h:35
AttributeValue implementation for Rectangle.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
AttributeValue implementation for Time.
Definition: nstime.h:1413
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.