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
dumbbell-animation.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
* Author: George F. Riley<riley@ece.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
nLeftLeaf
= 5;
26
uint32_t
nRightLeaf
= 5;
27
uint32_t
nLeaf
= 0;
// If non-zero, number of both left and right
28
std::string
animFile
=
"dumbbell-animation.xml"
;
// Name of file for animation output
29
30
CommandLine
cmd
(
__FILE__
);
31
cmd
.AddValue(
"nLeftLeaf"
,
"Number of left side leaf nodes"
,
nLeftLeaf
);
32
cmd
.AddValue(
"nRightLeaf"
,
"Number of right side leaf nodes"
,
nRightLeaf
);
33
cmd
.AddValue(
"nLeaf"
,
"Number of left and right side leaf nodes"
,
nLeaf
);
34
cmd
.AddValue(
"animFile"
,
"File Name for Animation Output"
,
animFile
);
35
36
cmd
.Parse(
argc
,
argv
);
37
if
(
nLeaf
> 0)
38
{
39
nLeftLeaf
=
nLeaf
;
40
nRightLeaf
=
nLeaf
;
41
}
42
43
// Create the point-to-point link helpers
44
PointToPointHelper
pointToPointRouter
;
45
pointToPointRouter
.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"10Mbps"
));
46
pointToPointRouter
.SetChannelAttribute(
"Delay"
,
StringValue
(
"1ms"
));
47
PointToPointHelper
pointToPointLeaf
;
48
pointToPointLeaf
.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"10Mbps"
));
49
pointToPointLeaf
.SetChannelAttribute(
"Delay"
,
StringValue
(
"1ms"
));
50
51
PointToPointDumbbellHelper
d
(
nLeftLeaf
,
52
pointToPointLeaf
,
53
nRightLeaf
,
54
pointToPointLeaf
,
55
pointToPointRouter
);
56
57
// Install Stack
58
InternetStackHelper
stack
;
59
d
.InstallStack(stack);
60
61
// Assign IP Addresses
62
d
.AssignIpv4Addresses(
Ipv4AddressHelper
(
"10.1.1.0"
,
"255.255.255.0"
),
63
Ipv4AddressHelper
(
"10.2.1.0"
,
"255.255.255.0"
),
64
Ipv4AddressHelper
(
"10.3.1.0"
,
"255.255.255.0"
));
65
66
// Install on/off app on all right side nodes
67
OnOffHelper
clientHelper
(
"ns3::UdpSocketFactory"
,
Address
());
68
clientHelper
.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::UniformRandomVariable"
));
69
clientHelper
.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::UniformRandomVariable"
));
70
ApplicationContainer
clientApps
;
71
72
for
(
uint32_t
i
= 0;
i
< ((
d
.RightCount() <
d
.LeftCount()) ?
d
.RightCount() :
d
.LeftCount());
73
++
i
)
74
{
75
// Create an on/off app sending packets to the same leaf right side
76
AddressValue
remoteAddress
(
InetSocketAddress
(
d
.GetLeftIpv4Address(
i
), 1000));
77
clientHelper
.SetAttribute(
"Remote"
, remoteAddress);
78
clientApps
.Add(
clientHelper
.Install(
d
.GetRight(
i
)));
79
}
80
81
clientApps
.Start(
Seconds
(0));
82
clientApps
.Stop(
Seconds
(10));
83
84
// Set the bounding box for animation
85
d
.BoundingBox(1, 1, 100, 100);
86
87
// Create the animation object and configure for specified output
88
AnimationInterface
anim
(
animFile
);
89
anim
.
EnablePacketMetadata
();
// Optional
90
anim
.
EnableIpv4L3ProtocolCounters
(
Seconds
(0),
Seconds
(10));
// Optional
91
92
// Set up the actual simulation
93
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
94
95
Simulator::Run
();
96
std::cout <<
"Animation Trace file created:"
<<
animFile
<< std::endl;
97
Simulator::Destroy
();
98
return
0;
99
}
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::AddressValue
AttributeValue implementation for Address.
Definition
address.h:275
ns3::AnimationInterface
Interface to network animator.
Definition
animation-interface.h:77
ns3::AnimationInterface::EnableIpv4L3ProtocolCounters
void EnableIpv4L3ProtocolCounters(Time startTime, Time stopTime, Time pollInterval=Seconds(1))
Enable tracking of Ipv4 L3 Protocol Counters such as Tx, Rx, Drop.
Definition
animation-interface.cc:184
ns3::AnimationInterface::EnablePacketMetadata
void EnablePacketMetadata(bool enable=true)
Enable Packet metadata.
Definition
animation-interface.cc:274
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::PointToPointDumbbellHelper
A helper to make it easier to create a dumbbell topology with p2p links.
Definition
point-to-point-dumbbell.h:31
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition
point-to-point-helper.h:33
ns3::PointToPointHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
Definition
point-to-point-helper.cc:43
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
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
anim
AnimationInterface * anim
Definition
lr-wpan-bootstrap.cc:45
first.clientApps
clientApps
Definition
first.py:53
first.stack
stack
Definition
first.py:33
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
dumbbell-animation.cc
Generated on Mon Dec 15 2025 15:22:00 for ns-3 by
1.9.8