forked from keeferrourke/f20-gcc-ns3-sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobility-waypoint.cc
109 lines (94 loc) · 3.81 KB
/
mobility-waypoint.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation;
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include <sysexits.h>
#include "ns3/animation-interface.h"
#include "ns3/aodv-helper.h"
#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/core-module.h"
#include "ns3/double.h"
#include "ns3/dsdv-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/ipv4-interface-container.h"
#include "ns3/ipv4-routing-helper.h"
#include "ns3/ipv6-address-helper.h"
#include "ns3/log-macros-enabled.h"
#include "ns3/mobility-helper.h"
#include "ns3/mobility-model.h"
#include "ns3/netanim-module.h"
#include "ns3/node-container.h"
#include "ns3/nstime.h"
#include "ns3/object.h"
#include "ns3/random-variable-stream.h"
#include "ns3/random-walk-2d-mobility-model.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/wifi-phy.h"
#include "ns3/wifi-standards.h"
#include "ns3/yans-wifi-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("GCCDEMO");
int
main (int argc, char *argv[])
{
uint32_t optNodes = 32;
double optRuntime = 300; // seconds
double optPauseTime = 10; // seconds
double optVelocity = 2; // m/sec
double optChangeDirectionAfter = 2; // seconds
CommandLine cmd;
cmd.AddValue ("nodes", "Number of nodes", optNodes);
cmd.AddValue ("runtime", "Simulation runtime", optRuntime);
cmd.AddValue ("velocity", "Node velocity", optVelocity);
cmd.AddValue ("pause-time", "How long nodes should wait at waypoints",
optPauseTime);
cmd.AddValue ("change-direction-every",
"Nodes change direction after this period",
optChangeDirectionAfter);
cmd.Parse (argc, argv);
NodeContainer adhocNodes;
adhocNodes.Create (optNodes);
Ptr<ConstantRandomVariable> velocityGenerator
= CreateObject<ConstantRandomVariable> ();
velocityGenerator->SetAttribute ("Constant", DoubleValue (optVelocity));
Ptr<ConstantRandomVariable> pauseTimeGenerator
= CreateObject<ConstantRandomVariable> ();
pauseTimeGenerator->SetAttribute ("Constant", DoubleValue (optPauseTime));
ns3::Ptr<ns3::UniformRandomVariable> x
= ns3::CreateObject<ns3::UniformRandomVariable> ();
x->SetAttribute ("Min", ns3::DoubleValue (0.0));
x->SetAttribute ("Max", ns3::DoubleValue (100.0));
ns3::Ptr<ns3::UniformRandomVariable> y
= ns3::CreateObject<ns3::UniformRandomVariable> ();
y->SetAttribute ("Min", ns3::DoubleValue (0.0));
y->SetAttribute ("Max", ns3::DoubleValue (100.0));
auto alloc = ns3::CreateObject<ns3::RandomRectanglePositionAllocator> ();
alloc->SetX (x);
alloc->SetY (y);
// Setting the model to change direction after a certain amount of time looks
// like more natural movement.
MobilityHelper mobility;
mobility.SetPositionAllocator (alloc);
mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed",
PointerValue (velocityGenerator), "Pause",
PointerValue (pauseTimeGenerator),
"PositionAllocator", PointerValue (alloc));
mobility.Install (adhocNodes);
AnimationInterface anim ("animations/gcc-random-waypoint-mobility.xml");
Simulator::Stop (Seconds (optRuntime));
Simulator::Run ();
Simulator::Destroy ();
return EX_OK;
}