A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
16from ns import ns
17
18# // Default Network Topology
19# //
20# // 10.1.1.0
21# // n0 -------------- n1
22# // point-to-point
23# //
24
25ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
26ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
27
28nodes = ns.network.NodeContainer()
29nodes.Create(2)
30
31pointToPoint = ns.point_to_point.PointToPointHelper()
32pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps"))
33pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms"))
34
35devices = pointToPoint.Install(nodes)
36
37stack = ns.internet.InternetStackHelper()
38stack.Install(nodes)
39
40address = ns.internet.Ipv4AddressHelper()
41address.SetBase(ns.network.Ipv4Address("10.1.1.0"),
42 ns.network.Ipv4Mask("255.255.255.0"))
43
44interfaces = address.Assign(devices)
45
46echoServer = ns.applications.UdpEchoServerHelper(9)
47
48serverApps = echoServer.Install(nodes.Get(1))
49serverApps.Start(ns.core.Seconds(1.0))
50serverApps.Stop(ns.core.Seconds(10.0))
51
52address = interfaces.GetAddress(1).ConvertTo()
53echoClient = ns.applications.UdpEchoClientHelper(address, 9)
54echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1))
55echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
56echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024))
57
58clientApps = echoClient.Install(nodes.Get(0))
59clientApps.Start(ns.core.Seconds(2.0))
60clientApps.Stop(ns.core.Seconds(10.0))
61
62ns.core.Simulator.Run()
63ns.core.Simulator.Destroy()
64