A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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: Josh Pelkey <jpelkey@gatech.edu>
17  */
19 #include <iostream>
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"
29 using namespace ns3;
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"));
36  uint32_t xSize = 5;
37  uint32_t ySize = 5;
38  std::string animFile = "grid-animation.xml";
40  CommandLine cmd;
41  cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
42  cmd.AddValue ("ySize", "Number of columns of nodes", ySize);
43  cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
45  cmd.Parse (argc,argv);
46  if (xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
47  {
48  NS_FATAL_ERROR ("Need more nodes for grid.");
49  }
52  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
53  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
55  // Create Grid
56  PointToPointGridHelper grid (xSize, ySize, pointToPoint);
58  // Install stack on Grid
60  grid.InstallStack (stack);
62  // Assign Addresses to Grid
63  grid.AssignIpv4Addresses (Ipv4AddressHelper ("", ""),
64  Ipv4AddressHelper ("", ""));
67  OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
68  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
69  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
72  // Create an on/off app sending packets
73  AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000));
74  clientHelper.SetAttribute ("Remote", remoteAddress);
75  clientApps.Add (clientHelper.Install (grid.GetNode (0,0)));
77  clientApps.Start (Seconds (0.0));
78  clientApps.Stop (Seconds (1.5));
80  // Set the bounding box for animation
81  grid.BoundingBox (1, 1, 100, 100);
83  // Create the animation object and configure for specified output
84  AnimationInterface anim (animFile);
86  // Set up the actual simulation
89  Simulator::Run ();
91  return 0;
92 }
holds a vector of ns3::Application pointers.
tuple pointToPoint
Definition: first.py:28
an Inet address class
void AssignIpv4Addresses(Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp)
Assigns Ipv4 addresses to all the row and column interfaces.
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:18
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.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
A helper to make it easier to create a grid topology with p2p links.
Build a set of PointToPointNetDevice objects.
Ptr< Node > GetNode(uint32_t row, uint32_t col)
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:177
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
Ipv4Address GetIpv4Address(uint32_t row, uint32_t col)
This returns an Ipv4 address at the node specified by the (row, col) address.
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
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:435
void InstallStack(InternetStackHelper stack)
Interface to network animator.
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.
void BoundingBox(double ulx, double uly, double lrx, double lry)
Sets up the node canvas locations for every node in the grid.
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.