A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
grid-animation.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
* Author: Josh Pelkey <jpelkey@gatech.edu>
16
*/
17
18
#include "ns3/applications-module.h"
19
#include "ns3/core-module.h"
20
#include "ns3/internet-module.h"
21
#include "ns3/netanim-module.h"
22
#include "ns3/network-module.h"
23
#include "ns3/point-to-point-layout-module.h"
24
#include "ns3/point-to-point-module.h"
25
26
#include <iostream>
27
28
using namespace
ns3
;
29
30
int
31
main(
int
argc,
char
* argv[])
32
{
33
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(512));
34
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"500kb/s"
));
35
36
uint32_t xSize = 5;
37
uint32_t ySize = 5;
38
std::string animFile =
"grid-animation.xml"
;
39
40
CommandLine
cmd
(__FILE__);
41
cmd
.AddValue(
"xSize"
,
"Number of rows of nodes"
, xSize);
42
cmd
.AddValue(
"ySize"
,
"Number of columns of nodes"
, ySize);
43
cmd
.AddValue(
"animFile"
,
"File Name for Animation Output"
, animFile);
44
45
cmd
.Parse(argc, argv);
46
if
(xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
47
{
48
NS_FATAL_ERROR
(
"Need more nodes for grid."
);
49
}
50
51
PointToPointHelper
pointToPoint
;
52
pointToPoint
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
53
pointToPoint
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
54
55
// Create Grid
56
PointToPointGridHelper
grid
(xSize, ySize,
pointToPoint
);
57
58
// Install stack on Grid
59
InternetStackHelper
stack
;
60
grid
.InstallStack(
stack
);
61
62
// Assign Addresses to Grid
63
grid
.AssignIpv4Addresses(
Ipv4AddressHelper
(
"10.1.1.0"
,
"255.255.255.0"
),
64
Ipv4AddressHelper
(
"10.2.1.0"
,
"255.255.255.0"
));
65
66
OnOffHelper
clientHelper(
"ns3::UdpSocketFactory"
,
Address
());
67
clientHelper.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
68
clientHelper.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
69
ApplicationContainer
clientApps
;
70
71
// Create an on/off app sending packets
72
AddressValue
remoteAddress
(
InetSocketAddress
(
grid
.GetIpv4Address(xSize - 1, ySize - 1), 1000));
73
clientHelper.SetAttribute(
"Remote"
,
remoteAddress
);
74
clientApps
.Add(clientHelper.Install(
grid
.GetNode(0, 0)));
75
76
clientApps
.Start(
Seconds
(0.0));
77
clientApps
.Stop(
Seconds
(1.5));
78
79
// Set the bounding box for animation
80
grid
.BoundingBox(1, 1, 100, 100);
81
82
// Create the animation object and configure for specified output
83
AnimationInterface
anim
(animFile);
84
85
// Set up the actual simulation
86
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
87
88
Simulator::Run
();
89
Simulator::Destroy
();
90
return
0;
91
}
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::AnimationInterface
Interface to network animator.
Definition:
animation-interface.h:88
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition:
application-container.h:44
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:42
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:92
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition:
ipv4-address-helper.h:49
ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
Definition:
ipv4-global-routing-helper.cc:61
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition:
on-off-helper.h:44
ns3::PointToPointGridHelper
A helper to make it easier to create a grid topology with p2p links.
Definition:
point-to-point-grid.h:43
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition:
point-to-point-helper.h:44
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::StringValue
Hold variables of type string.
Definition:
string.h:56
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:45
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition:
config.cc:890
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
anim
AnimationInterface * anim
Definition:
lr-wpan-bootstrap.cc:55
first.pointToPoint
pointToPoint
Definition:
first.py:38
first.clientApps
clientApps
Definition:
first.py:64
first.stack
stack
Definition:
first.py:44
grid
Definition:
grid.py:1
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.remoteAddress
remoteAddress
Definition:
nsclick-simple-lan.py:74
second.cmd
cmd
Definition:
second.py:40
src
netanim
examples
grid-animation.cc
Generated on Sun Mar 3 2024 17:11:05 for ns-3 by
1.9.1