examples/csma-bridge.py
author Florian Westphal <fw@strlen.de>
Wed, 03 Sep 2008 23:24:59 +0200
changeset 3595 693faf7f4e9b
parent 3458 f289e2045bfc
child 3696 559a7114a1e6
permissions -rw-r--r--
nsc: Fix build problem if gtk config store is disabled gtk config store pulled in libdl.so for us, so things fail to link of the config store isn't enabled. This makes nsc pull in libdl itself when its enabled.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3458
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
# /*
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
#  * published by the Free Software Foundation
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
#  *
f289e2045bfc Add csma-bridge example 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,
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
#  * GNU General Public License for more details.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#  *
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example 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
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
#  */
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
# Network topology
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
#
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
#        n0     n1  
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
#        |      | 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
#       ----------
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
#       | Switch |
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
#       ----------
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
#        |      | 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
#        n2     n3  
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
#
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
#
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
# - CBR/UDP flows from n0 to n1 and from n3 to n0
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
# - DropTail queues 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
# - Tracing of queues and packet receptions to file "csma-bridge.tr"
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
import ns3
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
def main(argv):
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
    # Make the random number generators generate reproducible results.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
    ns3.RandomVariable.UseGlobalSeed(1, 1, 2, 3, 5, 8)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
    # Allow the user to override any of the defaults and the above Bind() at
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
    # run-time, via command-line arguments
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
    cmd = ns3.CommandLine()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
    cmd.Parse(argv)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
    # Explicitly create the nodes required by the topology(shown above).
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
    print "Create nodes."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
    terminals = ns3.NodeContainer()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
    terminals.Create(4)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    csmaSwitch = ns3.NodeContainer()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
    csmaSwitch.Create(1)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
    print "Build Topology"
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
    csma = ns3.CsmaHelper()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
    csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
    # Create the csma links, from each terminal to the switch
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
    terminalDevices = ns3.NetDeviceContainer()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
    switchDevices = ns3.NetDeviceContainer()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
    for i in range(4):
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
        link = csma.Install(ns3.NodeContainer(ns3.NodeContainer(terminals.Get(i)), csmaSwitch))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
        terminalDevices.Add(link.Get(0))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
        switchDevices.Add(link.Get(1))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
    # Create the bridge netdevice, which will do the packet switching
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
    switchNode = csmaSwitch.Get(0)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
    bridgeDevice = ns3.BridgeNetDevice()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
    switchNode.AddDevice(bridgeDevice)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
    for portIter in range(switchDevices.GetN()):
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
        bridgeDevice.AddBridgePort(switchDevices.Get(portIter))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
    # Add internet stack to the terminals
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
    internet = ns3.InternetStackHelper()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
    internet.Install(terminals)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
    # We've got the "hardware" in place.  Now we need to add IP addresses.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
    print "Assign IP Addresses."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
    ipv4 = ns3.Ipv4AddressHelper()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
    ipv4.Assign(terminalDevices)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    # Create an OnOff application to send UDP datagrams from node zero to node 1.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    print "Create Applications."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
    port = 9   # Discard port(RFC 863)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
    onoff = ns3.OnOffHelper("ns3::UdpSocketFactory", 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
                            ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.2"), port)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
    onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
    onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
    app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    # Start the application
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    app.Start(ns3.Seconds(1.0))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
    app.Stop(ns3.Seconds(10.0))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
    # Create an optional packet sink to receive these packets
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
    sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
                                ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
    sink.Install(ns3.NodeContainer(terminals.Get(1)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
    # 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
    # Create a similar flow from n3 to n0, starting at time 1.1 seconds
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
    onoff.SetAttribute("Remote", 
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
                       ns3.AddressValue(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
    app2 = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
    sink.Install(ns3.NodeContainer(terminals.Get(0)))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
    app2.Start(ns3.Seconds(1.1))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
    app2.Stop(ns3.Seconds(10.0))
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
    # Configure tracing of all enqueue, dequeue, and NetDevice receive events.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
    # Trace output will be sent to the file "csma-bridge.tr"
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
    #print "Configure Tracing."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
    #std.ofstream ascii
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
    #ascii.open("csma-bridge.tr")
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
    #CsmaHelper.EnableAsciiAll(ascii)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
    # Also configure some tcpdump traces; each interface will be traced.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
    # The output files will be named:
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
    #     csma-bridge.pcap-<nodeId>-<interfaceId>
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
    # and can be read by the "tcpdump -r" command(use "-tt" option to
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
    # display timestamps correctly)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
    ns3.CsmaHelper.EnablePcapAll("csma-bridge")
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
    # Now, do the actual simulation.
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
    #
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
    print "Run Simulation."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
    ns3.Simulator.Run()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
    ns3.Simulator.Destroy()
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
    print "Done."
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
if __name__ == '__main__':
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
    import sys
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
    main(sys.argv)
f289e2045bfc Add csma-bridge example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155