examples/first.py
author Mirko Banchi <mk.banchi@gmail.com>
Fri, 24 Apr 2009 09:07:00 +0200
changeset 4401 427cec7079f3
parent 4138 9f4c2934473d
permissions -rw-r--r--
add amsdu field
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4138
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
# /*
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
#  * This program is free software; you can redistribute it and/or modify
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
#  * it under the terms of the GNU General Public License version 2 as
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
#  * published by the Free Software Foundation;
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
#  *
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
#  * This program is distributed in the hope that it will be useful,
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
#  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
#  * GNU General Public License for more details.
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#  *
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
#  * You should have received a copy of the GNU General Public License
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
#  * along with this program; if not, write to the Free Software
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
#  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
#  */
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
import ns3
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
ns3.RandomVariable.UseGlobalSeed(1, 1, 2, 3, 5, 8)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
nodes = ns3.NodeContainer()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
nodes.Create(2)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
pointToPoint = ns3.PointToPointHelper()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps"))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms"))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
devices = pointToPoint.Install(nodes)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
stack = ns3.InternetStackHelper()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
stack.Install(nodes)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
address = ns3.Ipv4AddressHelper()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
interfaces = address.Assign (devices);
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
echoServer = ns3.UdpEchoServerHelper(9)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
serverApps = echoServer.Install(nodes.Get(1))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
serverApps.Start(ns3.Seconds(1.0))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
serverApps.Stop(ns3.Seconds(10.0))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds (1.0)))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
clientApps = echoClient.Install(nodes.Get(0))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
clientApps.Start(ns3.Seconds(2.0))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
clientApps.Stop(ns3.Seconds(10.0))
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
ns3.Simulator.Run()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
ns3.Simulator.Destroy()
9f4c2934473d examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57