A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dumbbell-animation.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: George F. Riley<riley@ece.gatech.edu>
17  */
18 
19 #include <iostream>
20 
21 #include "ns3/core-module.h"
22 #include "ns3/network-module.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/point-to-point-module.h"
25 #include "ns3/netanim-module.h"
26 #include "ns3/applications-module.h"
27 #include "ns3/point-to-point-layout-module.h"
28 
29 using namespace ns3;
30 
31 int 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 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;
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 
62  PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
63  nRightLeaf, pointToPointLeaf,
64  pointToPointRouter);
65 
66  // Install Stack
68  d.InstallStack (stack);
69 
70  // Assign IP Addresses
71  d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
72  Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
73  Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
74 
75  // Install on/off app on all right side nodes
76  OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
77  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable"));
78  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable"));
80 
81  for (uint32_t i = 0; i < d.RightCount (); ++i)
82  {
83  // Create an on/off app sending packets to the same leaf right side
84  AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
85  clientHelper.SetAttribute ("Remote", remoteAddress);
86  clientApps.Add (clientHelper.Install (d.GetRight (i)));
87  }
88 
89  clientApps.Start (Seconds (0.0));
90  clientApps.Stop (Seconds (10.0));
91 
92  // Set the bounding box for animation
93  d.BoundingBox (1, 1, 100, 100);
94 
95  // Create the animation object and configure for specified output
96  AnimationInterface anim (animFile);
97 
98  // Set up the acutal simulation
100 
101  Simulator::Run ();
102  std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
104  return 0;
105 }
holds a vector of ns3::Application pointers.
an Inet address class
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
hold variables of type string
Definition: string.h:19
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the dumbbell.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
a polymophic address class
Definition: address.h:86
tuple clientApps
Definition: first.py:53
int main(int argc, char *argv[])
Hold an unsigned integer type.
Definition: uinteger.h:46
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:152
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
void AssignIpv4Addresses(Ipv4AddressHelper leftIp, Ipv4AddressHelper rightIp, Ipv4AddressHelper routerIp)
tuple stack
Definition: first.py:34
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
hold objects of type ns3::Address
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
void InstallStack(InternetStackHelper stack)
Interface to network animator.
A helper to make it easier to create a dumbbell topology with p2p links.
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4Address GetLeftIpv4Address(uint32_t i) const
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.