A Discrete-Event Network Simulator
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  */
17 #include "ns3/core-module.h"
18 #include "ns3/network-module.h"
19 #include "ns3/internet-module.h"
20 #include "ns3/point-to-point-module.h"
21 #include "ns3/applications-module.h"
23 using namespace ns3;
25 NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
27 int
28 main (int argc, char *argv[])
29 {
31  cmd.Parse (argc, argv);
34  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
35  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
38  nodes.Create (2);
41  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
42  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
45  devices = pointToPoint.Install (nodes);
48  stack.Install (nodes);
51  address.SetBase ("", "");
53  Ipv4InterfaceContainer interfaces = address.Assign (devices);
57  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
58  serverApps.Start (Seconds (1.0));
59  serverApps.Stop (Seconds (10.0));
61  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
62  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
63  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
64  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
66  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
67  clientApps.Start (Seconds (2.0));
68  clientApps.Stop (Seconds (10.0));
70  Simulator::Run ();
72  return 0;
73 }
holds a vector of ns3::Application pointers.
tuple pointToPoint
Definition: first.py:28
tuple devices
Definition: first.py:32
holds a vector of std::pair of Ptr and interface index.
Hold variables of type string.
Definition: string.h:41
NetDeviceContainer Install(NodeContainer c)
tuple echoServer
Definition: first.py:43
Create an application which sends a UDP packet and waits for an echo of this packet.
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
Define a Log component with a specific name.
Definition: log.h:201
aggregate IP/TCP/UDP functionality to existing Nodes.
LOG_INFO and above.
Definition: log.h:103
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.
tuple cmd
Definition: second.py:35
tuple clientApps
Definition: first.py:54
tuple nodes
Definition: first.py:25
Create a server application which waits for input UDP packets and sends them back to the original sen...
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
tuple interfaces
Definition: first.py:41
holds a vector of ns3::NetDevice pointers
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:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
tuple echoClient
Definition: first.py:49
tuple serverApps
Definition: first.py:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
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 Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: nstime.h:117
tuple address
Definition: first.py:37
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const