A Discrete-Event Network Simulator
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
17using namespace ns3;
18
19int
20main(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
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
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]"));
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
76
79 return 0;
80}
a polymophic address class
Definition address.h:90
Interface to network animator.
holds a vector of ns3::Application pointers.
Parse command-line arguments.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to create a grid topology with p2p links.
Build a set of PointToPointNetDevice objects.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
AnimationInterface * anim
pointToPoint
Definition first.py:27
clientApps
Definition first.py:53
stack
Definition first.py:33
Definition grid.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.