|
qasimj@4634
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
qasimj@4634
|
2 |
/*
|
|
qasimj@4634
|
3 |
* This program is free software; you can redistribute it and/or modify
|
|
qasimj@4634
|
4 |
* it under the terms of the GNU General Public License version 2 as
|
|
qasimj@4634
|
5 |
* published by the Free Software Foundation;
|
|
qasimj@4634
|
6 |
*
|
|
qasimj@4634
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
qasimj@4634
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
qasimj@4634
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
qasimj@4634
|
10 |
* GNU General Public License for more details.
|
|
qasimj@4634
|
11 |
*
|
|
qasimj@4634
|
12 |
* You should have received a copy of the GNU General Public License
|
|
qasimj@4634
|
13 |
* along with this program; if not, write to the Free Software
|
|
qasimj@4634
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
qasimj@4634
|
15 |
*/
|
|
qasimj@4634
|
16 |
|
|
qasimj@4634
|
17 |
#include "ns3/core-module.h"
|
|
qasimj@4634
|
18 |
#include "ns3/simulator-module.h"
|
|
qasimj@4634
|
19 |
#include "ns3/node-module.h"
|
|
qasimj@4634
|
20 |
#include "ns3/helper-module.h"
|
|
qasimj@4634
|
21 |
|
|
qasimj@4634
|
22 |
using namespace ns3;
|
|
qasimj@4634
|
23 |
|
|
qasimj@4634
|
24 |
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
|
|
qasimj@4634
|
25 |
|
|
qasimj@4634
|
26 |
int
|
|
qasimj@4634
|
27 |
main (int argc, char *argv[])
|
|
qasimj@4634
|
28 |
{
|
|
qasimj@4634
|
29 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
|
qasimj@4634
|
30 |
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
|
|
qasimj@4634
|
31 |
|
|
qasimj@4634
|
32 |
NodeContainer nodes;
|
|
qasimj@4634
|
33 |
nodes.Create (2);
|
|
qasimj@4634
|
34 |
|
|
qasimj@4634
|
35 |
PointToPointHelper pointToPoint;
|
|
qasimj@4634
|
36 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
|
qasimj@4634
|
37 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
|
qasimj@4634
|
38 |
|
|
qasimj@4634
|
39 |
NetDeviceContainer devices;
|
|
qasimj@4634
|
40 |
devices = pointToPoint.Install (nodes);
|
|
qasimj@4634
|
41 |
|
|
qasimj@4634
|
42 |
InternetStackHelper stack;
|
|
qasimj@4634
|
43 |
stack.Install (nodes);
|
|
qasimj@4634
|
44 |
|
|
qasimj@4634
|
45 |
Ipv4AddressHelper address;
|
|
qasimj@4634
|
46 |
address.SetBase ("10.1.1.0", "255.255.255.0");
|
|
qasimj@4634
|
47 |
|
|
qasimj@4634
|
48 |
Ipv4InterfaceContainer interfaces = address.Assign (devices);
|
|
qasimj@4634
|
49 |
|
|
qasimj@4634
|
50 |
UdpEchoServerHelper echoServer (9);
|
|
qasimj@4634
|
51 |
|
|
qasimj@4634
|
52 |
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
|
|
qasimj@4634
|
53 |
serverApps.Start (Seconds (1.0));
|
|
qasimj@4634
|
54 |
serverApps.Stop (Seconds (10.0));
|
|
qasimj@4634
|
55 |
|
|
qasimj@4634
|
56 |
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
|
|
qasimj@4638
|
57 |
echoClient.SetAttribute ("MaxPackets", UintegerValue (2));
|
|
qasimj@4634
|
58 |
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
|
|
qasimj@4634
|
59 |
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
|
|
qasimj@4634
|
60 |
|
|
qasimj@4634
|
61 |
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
|
|
qasimj@4634
|
62 |
clientApps.Start (Seconds (2.0));
|
|
qasimj@4634
|
63 |
clientApps.Stop (Seconds (10.0));
|
|
qasimj@4638
|
64 |
|
|
qasimj@4638
|
65 |
PointToPointHelper::EnablePcapAll ("netfilter");
|
|
qasimj@4635
|
66 |
|
|
qasimj@4634
|
67 |
Simulator::Run ();
|
|
qasimj@4634
|
68 |
Simulator::Destroy ();
|
|
qasimj@4634
|
69 |
return 0;
|
|
qasimj@4634
|
70 |
}
|