A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
waypoint-mobility-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) 2009 Phillip Sitbon
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
* Author: Phillip Sitbon <phillip@sitbon.net>
19
*/
20
21
#include "ns3/simulator.h"
22
#include "ns3/boolean.h"
23
#include "ns3/config.h"
24
#include "ns3/waypoint-mobility-model.h"
25
#include "ns3/test.h"
26
27
namespace
ns3 {
28
29
class
WaypointMobilityModelNotifyTest
:
public
TestCase
30
{
31
public
:
32
WaypointMobilityModelNotifyTest
(
bool
lazy)
33
:
TestCase
(lazy ?
"Check Waypoint Mobility Model LAZY notification accuracy"
34
:
"Check Waypoint Mobility Model NON-LAZY notification accuracy"
),
35
lazyNotify
(lazy)
36
{
37
}
38
virtual
~WaypointMobilityModelNotifyTest
()
39
{
40
}
41
42
private
:
43
std::vector<Ptr<MobilityModel> >
mobilityStack
;
44
uint32_t
mobilityCount
;
45
uint32_t
waypointCount
;
46
std::deque<Waypoint>
waypoints
;
47
bool
lazyNotify
;
48
private
:
49
virtual
void
DoRun
(
void
);
50
virtual
void
DoTeardown
(
void
);
51
void
ForceUpdates
(
void
);
52
void
CourseChangeCallback
(std::string path,
Ptr<const MobilityModel>
model);
53
};
54
55
void
56
WaypointMobilityModelNotifyTest::DoTeardown
(
void
)
57
{
58
mobilityStack
.clear();
59
waypoints
.clear();
60
}
61
62
void
63
WaypointMobilityModelNotifyTest::DoRun
(
void
)
64
{
65
mobilityCount
= 1;
66
waypointCount
= 100;
67
68
ObjectFactory
mobilityFactory;
69
mobilityFactory.
SetTypeId
(
"ns3::WaypointMobilityModel"
);
70
mobilityFactory.
Set
(
"LazyNotify"
,
BooleanValue
(
lazyNotify
));
71
72
// Populate the vector of mobility models.
73
for
(uint32_t i = 0; i <
mobilityCount
; i++)
74
{
75
// Create a new mobility model.
76
Ptr<MobilityModel>
model = mobilityFactory.
Create
()->
GetObject
<
MobilityModel
> ();
77
78
// Add this mobility model to the stack.
79
mobilityStack
.push_back (model);
80
Simulator::Schedule
(
Seconds
(0.0), &
Object::Start
, model);
81
}
82
83
Waypoint
wpt (
Seconds
(0.0),
Vector
(0.0, 0.0, 0.0));
84
85
// Create waypoints
86
for
( uint32_t iw = 0; iw <
waypointCount
; ++iw )
87
{
88
wpt.
time
+=
Seconds
(1.0);
89
waypoints
.push_back (wpt);
90
}
91
92
// Add the same waypoints to each node
93
std::vector<Ptr<MobilityModel> >::iterator i;
94
for
(i =
mobilityStack
.begin (); i !=
mobilityStack
.end (); ++i)
95
{
96
Ptr<WaypointMobilityModel>
mob = (*i)->
GetObject
<
WaypointMobilityModel
> ();
97
98
for
( std::deque<Waypoint>::iterator
w
=
waypoints
.begin ();
w
!=
waypoints
.end (); ++
w
)
99
{
100
mob->
AddWaypoint
(*
w
);
101
}
102
}
103
104
// Schedule updates at non-waypoint times to make sure lazy notifications don't happen
105
for
(
double
updateTime = 0.5; updateTime <= ((double)waypointCount + 1.5); updateTime += 1.0 )
106
{
107
Simulator::Schedule
(
Seconds
(updateTime), &
WaypointMobilityModelNotifyTest::ForceUpdates
,
this
);
108
}
109
110
Config::Connect
(
"/NodeList/*/$ns3::WaypointMobilityModel/CourseChange"
,
111
MakeCallback
(&
WaypointMobilityModelNotifyTest::CourseChangeCallback
,
this
));
112
113
Simulator::Stop
(
Seconds
((
double
)waypointCount + 2.0));
114
Simulator::Run
();
115
Simulator::Destroy
();
116
}
117
void
118
WaypointMobilityModelNotifyTest::ForceUpdates
(
void
)
119
{
120
std::vector<Ptr<MobilityModel> >::iterator i;
121
for
(i =
mobilityStack
.begin (); i !=
mobilityStack
.end (); ++i)
122
{
123
Ptr<WaypointMobilityModel>
mob = (*i)->
GetObject
<
WaypointMobilityModel
> ();
124
mob->
Update
();
125
}
126
}
127
void
128
WaypointMobilityModelNotifyTest::CourseChangeCallback
(std::string path,
Ptr<const MobilityModel>
model)
129
{
130
const
Time
now =
Simulator::Now
();
131
const
double
sec = now.
GetSeconds
();
132
Ptr<const WaypointMobilityModel>
mob = model->
GetObject
<
WaypointMobilityModel
> ();
133
134
NS_TEST_EXPECT_MSG_EQ
(now, mob->m_current.time,
"Waypoint time not properly updated"
);
135
136
if
( !
lazyNotify
)
137
{
138
// All waypoints are on second boundaries only
139
NS_TEST_EXPECT_MSG_EQ
(sec - ((
double
)((
int
)sec)) + sec, sec,
140
"Course didn't change on one second time boundary with NON-LAZY notifcations"
);
141
}
142
else
143
{
144
// Updates should happen at the times they are forced, in between waypoints.
145
NS_TEST_EXPECT_MSG_EQ
(sec - ((
double
)((
int
)sec)), 0.5,
146
"Course didn't change between waypoints with LAZY notifications"
);
147
}
148
}
149
150
static
struct
WaypointMobilityModelTestSuite
:
public
TestSuite
151
{
152
WaypointMobilityModelTestSuite
() :
TestSuite
(
"waypoint-mobility-model"
,
UNIT
)
153
{
154
AddTestCase
(
new
WaypointMobilityModelNotifyTest
(
true
));
155
AddTestCase
(
new
WaypointMobilityModelNotifyTest
(
false
));
156
}
157
}
g_waypointMobilityModelTestSuite
;
158
159
}
// namespace ns3
160
src
mobility
test
waypoint-mobility-model-test.cc
Generated on Fri Dec 21 2012 19:00:43 for ns-3 by
1.8.1.2