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 
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"
22 
23 // Default Network Topology
24 //
25 //       10.1.1.0
26 // n0 -------------- n1
27 //    point-to-point
28 //
29 
30 using namespace ns3;
31 
32 NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
33 
34 int
main(int argc,char * argv[])35 main (int argc, char *argv[])
36 {
37   CommandLine cmd (__FILE__);
38   cmd.Parse (argc, argv);
39 
40   Time::SetResolution (Time::NS);
41   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
42   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
43 
44   NodeContainer nodes;
45   nodes.Create (2);
46 
47   PointToPointHelper pointToPoint;
48   pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
49   pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
50 
51   NetDeviceContainer devices;
52   devices = pointToPoint.Install (nodes);
53 
54   InternetStackHelper stack;
55   stack.Install (nodes);
56 
57   Ipv4AddressHelper address;
58   address.SetBase ("10.1.1.0", "255.255.255.0");
59 
60   Ipv4InterfaceContainer interfaces = address.Assign (devices);
61 
62   UdpEchoServerHelper echoServer (9);
63 
64   ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
65   serverApps.Start (Seconds (1.0));
66   serverApps.Stop (Seconds (10.0));
67 
68   UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
69   echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
70   echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
71   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
72 
73   ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
74   clientApps.Start (Seconds (2.0));
75   clientApps.Stop (Seconds (10.0));
76 
77   Simulator::Run ();
78   Simulator::Destroy ();
79   return 0;
80 }
81