A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dumbbell-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: George F. Riley<riley@ece.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
28using namespace ns3;
29
30int
31main(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 nLeftLeaf = 5;
37 uint32_t nRightLeaf = 5;
38 uint32_t nLeaf = 0; // If non-zero, number of both left and right
39 std::string animFile = "dumbbell-animation.xml"; // Name of file for animation output
40
41 CommandLine cmd(__FILE__);
42 cmd.AddValue("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
43 cmd.AddValue("nRightLeaf", "Number of right side leaf nodes", nRightLeaf);
44 cmd.AddValue("nLeaf", "Number of left and right side leaf nodes", nLeaf);
45 cmd.AddValue("animFile", "File Name for Animation Output", animFile);
46
47 cmd.Parse(argc, argv);
48 if (nLeaf > 0)
49 {
50 nLeftLeaf = nLeaf;
51 nRightLeaf = nLeaf;
52 }
53
54 // Create the point-to-point link helpers
55 PointToPointHelper pointToPointRouter;
56 pointToPointRouter.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
57 pointToPointRouter.SetChannelAttribute("Delay", StringValue("1ms"));
58 PointToPointHelper pointToPointLeaf;
59 pointToPointLeaf.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
60 pointToPointLeaf.SetChannelAttribute("Delay", StringValue("1ms"));
61
63 pointToPointLeaf,
64 nRightLeaf,
65 pointToPointLeaf,
66 pointToPointRouter);
67
68 // Install Stack
70 d.InstallStack(stack);
71
72 // Assign IP Addresses
73 d.AssignIpv4Addresses(Ipv4AddressHelper("10.1.1.0", "255.255.255.0"),
74 Ipv4AddressHelper("10.2.1.0", "255.255.255.0"),
75 Ipv4AddressHelper("10.3.1.0", "255.255.255.0"));
76
77 // Install on/off app on all right side nodes
78 OnOffHelper clientHelper("ns3::UdpSocketFactory", Address());
79 clientHelper.SetAttribute("OnTime", StringValue("ns3::UniformRandomVariable"));
80 clientHelper.SetAttribute("OffTime", StringValue("ns3::UniformRandomVariable"));
82
83 for (uint32_t i = 0; i < ((d.RightCount() < d.LeftCount()) ? d.RightCount() : d.LeftCount());
84 ++i)
85 {
86 // Create an on/off app sending packets to the same leaf right side
87 AddressValue remoteAddress(InetSocketAddress(d.GetLeftIpv4Address(i), 1000));
88 clientHelper.SetAttribute("Remote", remoteAddress);
89 clientApps.Add(clientHelper.Install(d.GetRight(i)));
90 }
91
92 clientApps.Start(Seconds(0.0));
93 clientApps.Stop(Seconds(10.0));
94
95 // Set the bounding box for animation
96 d.BoundingBox(1, 1, 100, 100);
97
98 // Create the animation object and configure for specified output
99 AnimationInterface anim(animFile);
100 anim.EnablePacketMetadata(); // Optional
102
103 // Set up the actual simulation
105
107 std::cout << "Animation Trace file created:" << animFile << std::endl;
109 return 0;
110}
a polymophic address class
Definition: address.h:101
Interface to network animator.
void EnableIpv4L3ProtocolCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Ipv4 L3 Protocol Counters such as Tx, Rx, Drop.
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
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.
Definition: on-off-helper.h:37
A helper to make it easier to create a dumbbell topology with p2p links.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
Hold variables of type string.
Definition: string.h:56
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
AnimationInterface * anim
ns clientApps
Definition: first.py:64
ns stack
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:40