1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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;
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.
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
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"
25
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
28
main (int argc, char *argv[])
30
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
31
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
36
PointToPointHelper pointToPoint;
37
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
38
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
40
NetDeviceContainer devices;
41
devices = pointToPoint.Install (nodes);
43
InternetStackHelper stack;
44
stack.Install (nodes);
46
Ipv4AddressHelper address;
47
address.SetBase ("10.1.1.0", "255.255.255.0");
49
Ipv4InterfaceContainer interfaces = address.Assign (devices);
51
UdpEchoServerHelper echoServer (9);
53
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
54
serverApps.Start (Seconds (1.0));
55
serverApps.Stop (Seconds (10.0));
57
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
58
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
59
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
60
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
62
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
63
clientApps.Start (Seconds (2.0));
64
clientApps.Stop (Seconds (10.0));
67
Simulator::Destroy ();