forked from keeferrourke/f20-gcc-ns3-sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobility-walk2d-default.cc
95 lines (81 loc) · 3.08 KB
/
mobility-walk2d-default.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
//
// 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 optVelocity = 2; // m/sec
CommandLine cmd;
cmd.AddValue ("nodes", "Number of nodes", optNodes);
cmd.AddValue ("runtime", "Simulation runtime", optRuntime);
cmd.AddValue ("velocity", "Node velocity", optVelocity);
cmd.Parse (argc, argv);
NodeContainer adhocNodes;
adhocNodes.Create (optNodes);
Ptr<ConstantRandomVariable> velocityGenerator
= CreateObject<ConstantRandomVariable> ();
velocityGenerator->SetAttribute ("Constant", DoubleValue (optVelocity));
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);
// Defaults are all set to really small values, so we get "jitter".
MobilityHelper mobility;
mobility.SetPositionAllocator (alloc);
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Speed",
PointerValue (velocityGenerator));
mobility.Install (adhocNodes);
AnimationInterface anim ("gcc-random-walk-2d-mobility.xml");
Simulator::Stop (Seconds (optRuntime));
Simulator::Run ();
Simulator::Destroy ();
return EX_OK;
}