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
main-random-walk.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
3
#include "ns3/core-module.h"
4
#include "ns3/mobility-module.h"
5
6
using namespace
ns3;
7
8
static
void
9
CourseChange
(std::string foo,
Ptr<const MobilityModel>
mobility)
10
{
11
Vector
pos = mobility->
GetPosition
();
12
Vector
vel = mobility->
GetVelocity
();
13
std::cout <<
Simulator::Now
() <<
", model="
<< mobility <<
", POS: x="
<< pos.
x
<<
", y="
<< pos.
y
14
<<
", z="
<< pos.
z
<<
"; VEL:"
<< vel.
x
<<
", y="
<< vel.
y
15
<<
", z="
<< vel.
z
<< std::endl;
16
}
17
18
int
main
(
int
argc,
char
*argv[])
19
{
20
Config::SetDefault
(
"ns3::RandomWalk2dMobilityModel::Mode"
,
StringValue
(
"Time"
));
21
Config::SetDefault
(
"ns3::RandomWalk2dMobilityModel::Time"
,
StringValue
(
"2s"
));
22
Config::SetDefault
(
"ns3::RandomWalk2dMobilityModel::Speed"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1.0]"
));
23
Config::SetDefault
(
"ns3::RandomWalk2dMobilityModel::Bounds"
,
StringValue
(
"0|200|0|200"
));
24
25
CommandLine
cmd;
26
cmd.
Parse
(argc, argv);
27
28
NodeContainer
c;
29
c.
Create
(100);
30
31
MobilityHelper
mobility;
32
mobility.
SetPositionAllocator
(
"ns3::RandomDiscPositionAllocator"
,
33
"X"
,
StringValue
(
"100.0"
),
34
"Y"
,
StringValue
(
"100.0"
),
35
"Rho"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0|Max=30]"
));
36
mobility.
SetMobilityModel
(
"ns3::RandomWalk2dMobilityModel"
,
37
"Mode"
,
StringValue
(
"Time"
),
38
"Time"
,
StringValue
(
"2s"
),
39
"Speed"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1.0]"
),
40
"Bounds"
,
StringValue
(
"0|200|0|200"
));
41
mobility.
InstallAll
();
42
Config::Connect
(
"/NodeList/*/$ns3::MobilityModel/CourseChange"
,
43
MakeCallback
(&
CourseChange
));
44
45
Simulator::Stop
(
Seconds
(100.0));
46
47
Simulator::Run
();
48
49
Simulator::Destroy
();
50
return
0;
51
}
src
mobility
examples
main-random-walk.cc
Generated on Tue Oct 9 2012 16:45:42 for ns-3 by
1.8.1.2