A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
grid-animation.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
* Author: Josh Pelkey <jpelkey@gatech.edu>
5
*/
6
7
#include "ns3/applications-module.h"
8
#include "ns3/core-module.h"
9
#include "ns3/internet-module.h"
10
#include "ns3/netanim-module.h"
11
#include "ns3/network-module.h"
12
#include "ns3/point-to-point-layout-module.h"
13
#include "ns3/point-to-point-module.h"
14
15
#include <iostream>
16
17
using namespace
ns3
;
18
19
int
20
main(
int
argc,
char
* argv[])
21
{
22
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(512));
23
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"500kb/s"
));
24
25
uint32_t
xSize = 5;
26
uint32_t
ySize = 5;
27
std::string animFile =
"grid-animation.xml"
;
28
29
CommandLine
cmd
(__FILE__);
30
cmd
.AddValue(
"xSize"
,
"Number of rows of nodes"
, xSize);
31
cmd
.AddValue(
"ySize"
,
"Number of columns of nodes"
, ySize);
32
cmd
.AddValue(
"animFile"
,
"File Name for Animation Output"
, animFile);
33
34
cmd
.Parse(argc, argv);
35
if
(xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
36
{
37
NS_FATAL_ERROR
(
"Need more nodes for grid."
);
38
}
39
40
PointToPointHelper
pointToPoint
;
41
pointToPoint
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
42
pointToPoint
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
43
44
// Create Grid
45
PointToPointGridHelper
grid
(xSize, ySize, pointToPoint);
46
47
// Install stack on Grid
48
InternetStackHelper
stack
;
49
grid
.InstallStack(stack);
50
51
// Assign Addresses to Grid
52
grid
.AssignIpv4Addresses(
Ipv4AddressHelper
(
"10.1.1.0"
,
"255.255.255.0"
),
53
Ipv4AddressHelper
(
"10.2.1.0"
,
"255.255.255.0"
));
54
55
OnOffHelper
clientHelper(
"ns3::UdpSocketFactory"
,
Address
());
56
clientHelper.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
57
clientHelper.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
58
ApplicationContainer
clientApps
;
59
60
// Create an on/off app sending packets
61
AddressValue
remoteAddress
(
InetSocketAddress
(
grid
.GetIpv4Address(xSize - 1, ySize - 1), 1000));
62
clientHelper.SetAttribute(
"Remote"
, remoteAddress);
63
clientApps
.Add(clientHelper.Install(
grid
.GetNode(0, 0)));
64
65
clientApps
.Start(
Seconds
(0.0));
66
clientApps
.Stop(
Seconds
(1.5));
67
68
// Set the bounding box for animation
69
grid
.BoundingBox(1, 1, 100, 100);
70
71
// Create the animation object and configure for specified output
72
AnimationInterface
anim
(animFile);
73
74
// Set up the actual simulation
75
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
76
77
Simulator::Run
();
78
Simulator::Destroy
();
79
return
0;
80
}
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::AddressValue
Definition
address.h:275
ns3::AnimationInterface
Interface to network animator.
Definition
animation-interface.h:77
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition
application-container.h:33
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::InetSocketAddress
an Inet address class
Definition
inet-socket-address.h:31
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition
ipv4-address-helper.h:38
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:50
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition
on-off-helper.h:26
ns3::PointToPointGridHelper
A helper to make it easier to create a grid topology with p2p links.
Definition
point-to-point-grid.h:32
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition
point-to-point-helper.h:33
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
uint32_t
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition
config.cc:883
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition
fatal-error.h:168
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
anim
AnimationInterface * anim
Definition
lr-wpan-bootstrap.cc:45
first.pointToPoint
pointToPoint
Definition
first.py:27
first.clientApps
clientApps
Definition
first.py:53
first.stack
stack
Definition
first.py:33
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:63
second.cmd
cmd
Definition
second.py:29
src
netanim
examples
grid-animation.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0