A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
first.py
Go to the documentation of this file.
1 # /*
2 # * This program is free software; you can redistribute it and/or modify
3 # * it under the terms of the GNU General Public License version 2 as
4 # * published by the Free Software Foundation;
5 # *
6 # * This program is distributed in the hope that it will be useful,
7 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # * GNU General Public License for more details.
10 # *
11 # * You should have received a copy of the GNU General Public License
12 # * along with this program; if not, write to the Free Software
13 # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 # */
15 
16 import ns.applications
17 import ns.core
18 import ns.internet
19 import ns.network
20 import ns.point_to_point
21 
22 ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
23 ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
24 
25 nodes = ns.network.NodeContainer()
26 nodes.Create(2)
27 
28 pointToPoint = ns.point_to_point.PointToPointHelper()
29 pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps"))
30 pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms"))
31 
32 devices = pointToPoint.Install(nodes)
33 
34 stack = ns.internet.InternetStackHelper()
35 stack.Install(nodes)
36 
37 address = ns.internet.Ipv4AddressHelper()
38 address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0"))
39 
40 interfaces = address.Assign (devices);
41 
42 echoServer = ns.applications.UdpEchoServerHelper(9)
43 
44 serverApps = echoServer.Install(nodes.Get(1))
45 serverApps.Start(ns.core.Seconds(1.0))
46 serverApps.Stop(ns.core.Seconds(10.0))
47 
48 echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
49 echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1))
50 echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds (1.0)))
51 echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024))
52 
53 clientApps = echoClient.Install(nodes.Get(0))
54 clientApps.Start(ns.core.Seconds(2.0))
55 clientApps.Stop(ns.core.Seconds(10.0))
56 
57 ns.core.Simulator.Run()
58 ns.core.Simulator.Destroy()
59