examples/first.cc ported to Python
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue Feb 10 17:15:06 2009 +0000 (12 months ago)
changeset 41389f4c2934473d
parent 4137 c1303bd63eb5
child 4162 d8019fbcc7fe
child 4189 3d72a7d0d864
examples/first.cc ported to Python
examples/first.py
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/first.py	Tue Feb 10 17:15:06 2009 +0000
     1.3 @@ -0,0 +1,57 @@
     1.4 +# /*
     1.5 +#  * This program is free software; you can redistribute it and/or modify
     1.6 +#  * it under the terms of the GNU General Public License version 2 as
     1.7 +#  * published by the Free Software Foundation;
     1.8 +#  *
     1.9 +#  * This program is distributed in the hope that it will be useful,
    1.10 +#  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11 +#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.12 +#  * GNU General Public License for more details.
    1.13 +#  *
    1.14 +#  * You should have received a copy of the GNU General Public License
    1.15 +#  * along with this program; if not, write to the Free Software
    1.16 +#  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.17 +#  */
    1.18 +
    1.19 +import ns3
    1.20 +
    1.21 +ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
    1.22 +ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)
    1.23 +
    1.24 +ns3.RandomVariable.UseGlobalSeed(1, 1, 2, 3, 5, 8)
    1.25 +
    1.26 +nodes = ns3.NodeContainer()
    1.27 +nodes.Create(2)
    1.28 +
    1.29 +pointToPoint = ns3.PointToPointHelper()
    1.30 +pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps"))
    1.31 +pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms"))
    1.32 +
    1.33 +devices = pointToPoint.Install(nodes)
    1.34 +
    1.35 +stack = ns3.InternetStackHelper()
    1.36 +stack.Install(nodes)
    1.37 +
    1.38 +address = ns3.Ipv4AddressHelper()
    1.39 +address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
    1.40 +
    1.41 +interfaces = address.Assign (devices);
    1.42 +
    1.43 +echoServer = ns3.UdpEchoServerHelper(9)
    1.44 +
    1.45 +serverApps = echoServer.Install(nodes.Get(1))
    1.46 +serverApps.Start(ns3.Seconds(1.0))
    1.47 +serverApps.Stop(ns3.Seconds(10.0))
    1.48 +
    1.49 +echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
    1.50 +echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
    1.51 +echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds (1.0)))
    1.52 +echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
    1.53 +
    1.54 +clientApps = echoClient.Install(nodes.Get(0))
    1.55 +clientApps.Start(ns3.Seconds(2.0))
    1.56 +clientApps.Stop(ns3.Seconds(10.0))
    1.57 +
    1.58 +ns3.Simulator.Run()
    1.59 +ns3.Simulator.Destroy()
    1.60 +