Пример #1
0
def onoff_app(network,
              client_node,
              server_node,
              server_device,
              start,
              stop,
              rate,
              port=9,
              packet_size=1024,
              access_class=None,
              ontime=1,
              offtime=0):
    """Set up a OnOff client + sink server."""
    server = network.nodes[server_node]
    assert server_device in server.devices, \
        "Device '%s' not found, available: %s" % (server_device, ", ".join(server.devices))
    server_address = server.devices[server_device].interfaces[0].address

    local_address = ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)
    sink_helper = ns3.PacketSinkHelper("ns3::UdpSocketFactory", local_address)

    server_apps = sink_helper.Install(server.ns3_node)
    server_apps.Start(ns3.Seconds(start))
    server_apps.Stop(ns3.Seconds(stop))

    client = network.nodes[client_node]
    remote_address = ns3.InetSocketAddress(server_address, port)
    onoff_helper = ns3.OnOffHelper("ns3::UdpSocketFactory", ns3.Address())
    onoff_helper.SetAttribute(
        "OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(ontime)))
    onoff_helper.SetAttribute(
        "OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(offtime)))
    onoff_helper.SetAttribute("DataRate",
                              ns3.DataRateValue(ns3.DataRate(rate)))
    onoff_helper.SetAttribute("PacketSize", ns3.UintegerValue(packet_size))
    onoff_helper.SetAttribute("Remote", ns3.AddressValue(remote_address))

    # Set QoS Access Class -> Tid
    # Note that this only works with a patched OnOffApplication with QosTid attribute
    if access_class is not None:
        access_class_to_qos_tid = {
            "ac_vo": 6,  # AC_VO (Tid: 6, 7)
            "ac_vi": 4,  # AC_VI (Tid: 4, 5)
            "ac_be": 0,  # AC_BE (Tid: 0)
            "ac_bk": 1,  # AC_BK (Tid: 1, 2)
            "ac_be_nqos": 3,  # AC_BE_NQOS (Tid: 3)
        }
        qos_tid = access_class_to_qos_tid[access_class.lower()]
        onoff_helper.SetAttribute("QosTid", ns3.UintegerValue(qos_tid))

    client_apps = onoff_helper.Install(client.ns3_node)
    client_apps.Start(ns3.Seconds(start))
    client_apps.Stop(ns3.Seconds(stop))
Пример #2
0
def main(argv):
    #
    # Allow the user to override any of the defaults and the above Bind() at
    # run-time, via command-line arguments
    #
    cmd = ns3.CommandLine()
    cmd.Parse(argv)

    #
    # But since this is a realtime script, don't allow the user to mess with
    # that.
    #
    ns3.GlobalValue.Bind("SimulatorImplementationType",
                         ns3.StringValue("ns3::RealtimeSimulatorImpl"))

    #
    # Explicitly create the nodes required by the topology (shown above).
    #
    print "Create nodes."
    n = ns3.NodeContainer()
    n.Create(4)

    internet = ns3.InternetStackHelper()
    internet.Install(n)

    #
    # Explicitly create the channels required by the topology (shown above).
    #
    print("Create channels.")
    csma = ns3.CsmaHelper()
    csma.SetChannelAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate(5000000)))
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
    csma.SetDeviceAttribute("Mtu", ns3.UintegerValue(1400))
    d = csma.Install(n)

    #
    # We've got the "hardware" in place.  Now we need to add IP addresses.
    #
    print("Assign IP Addresses.")
    ipv4 = ns3.Ipv4AddressHelper()
    ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
    i = ipv4.Assign(d)

    print("Create Applications.")

    #
    # Create a UdpEchoServer application on node one.
    #
    port = 9  # well-known echo port number
    server = ns3.UdpEchoServerHelper(port)
    apps = server.Install(n.Get(1))
    apps.Start(ns3.Seconds(1.0))
    apps.Stop(ns3.Seconds(10.0))

    #
    # Create a UdpEchoClient application to send UDP datagrams from node zero to
    # node one.
    #
    packetSize = 1024
    maxPacketCount = 500
    interPacketInterval = ns3.Seconds(0.01)
    client = ns3.UdpEchoClientHelper(i.GetAddress(1), port)
    client.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
    client.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
    client.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))
    apps = client.Install(n.Get(0))
    apps.Start(ns3.Seconds(2.0))
    apps.Stop(ns3.Seconds(10.0))

    ascii = ns3.AsciiTraceHelper()
    csma.EnableAsciiAll(ascii.CreateFileStream("realtime-udp-echo.tr"))
    csma.EnablePcapAll("realtime-udp-echo", False)

    #
    # Now, do the actual simulation.
    #
    print("Run Simulation.")
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
    print("Done.")
Пример #3
0
def main(argv):

    cmd = ns3.CommandLine()

    cmd.Parse(argv)

    # Create nodes
    print "Create nodes"
    n0 = ns3.Node()
    r = ns3.Node()
    n1 = ns3.Node()

    net1 = ns3.NodeContainer()
    net1.Add(n0)
    net1.Add(r)
    net2 = ns3.NodeContainer()
    net2.Add(r)
    net2.Add(n1)
    all = ns3.NodeContainer()
    all.Add(n0)
    all.Add(r)
    all.Add(n1)

    # Create IPv6 Internet Stack
    internetv6 = ns3.InternetStackHelper()
    internetv6.Install(all)

    # Create channels
    csma = ns3.CsmaHelper()
    csma.SetChannelAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate(5000000)))
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
    d1 = csma.Install(net1)
    d2 = csma.Install(net2)

    # Create networks and assign IPv6 Addresses
    print "Addressing"
    ipv6 = ns3.Ipv6AddressHelper()
    ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64))
    i1 = ipv6.Assign(d1)
    i1.SetRouter(1, True)
    ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64))
    i2 = ipv6.Assign(d2)
    i2.SetRouter(0, True)

    # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
    print "Application"
    packetSize = 1024
    maxPacketCount = 5
    interPacketInterval = ns3.Seconds(1.)
    ping6 = ns3.Ping6Helper()

    ping6.SetLocal(i1.GetAddress(0, 1))
    ping6.SetRemote(i2.GetAddress(1, 1))

    ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
    ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
    ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))

    apps = ping6.Install(ns3.NodeContainer(net1.Get(0)))
    apps.Start(ns3.Seconds(2.0))
    apps.Stop(ns3.Seconds(20.0))

    print "Tracing"
    ascii = ns3.ofstream("simple-routing-ping6.tr")
    ns3.CsmaHelper.EnableAsciiAll(ascii)
    ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True)

    # Run Simulation
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
Пример #4
0
def main(argv):
    #
    #  First, we declare and initialize a few local variables that control some
    #  simulation parameters.
    #
    backboneNodes = 10
    infraNodes = 5
    lanNodes = 5
    stopTime = 10

    #
    #  Simulation defaults are typically set next, before command line
    #  arguments are parsed.
    #
    ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize",
                          ns3.StringValue("210"))
    ns3.Config.SetDefault("ns3::OnOffApplication::DataRate",
                          ns3.StringValue("448kb/s"))

    #
    #  For convenience, we add the local variables to the command line argument
    #  system so that they can be overridden with flags such as
    #  "--backboneNodes=20"
    #
    cmd = ns3.CommandLine()
    #cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes)
    #cmd.AddValue("infraNodes", "number of leaf nodes", infraNodes)
    #cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes)
    #cmd.AddValue("stopTime", "simulation stop time(seconds)", stopTime)

    #
    #  The system global variables and the local values added to the argument
    #  system can be overridden by command line arguments by using this call.
    #
    cmd.Parse(argv)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
    #                                                                        #
    #  Construct the backbone                                                #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /

    #
    #  Create a container to manage the nodes of the adhoc(backbone) network.
    #  Later we'll create the rest of the nodes we'll need.
    #
    backbone = ns3.NodeContainer()
    backbone.Create(backboneNodes)
    #
    #  Create the backbone wifi net devices and install them into the nodes in
    #  our container
    #
    wifi = ns3.WifiHelper()
    mac = ns3.NqosWifiMacHelper.Default()
    mac.SetType("ns3::AdhocWifiMac")
    wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
                                 ns3.StringValue("OfdmRate54Mbps"))
    wifiPhy = ns3.YansWifiPhyHelper.Default()
    wifiChannel = ns3.YansWifiChannelHelper.Default()
    wifiPhy.SetChannel(wifiChannel.Create())
    backboneDevices = wifi.Install(wifiPhy, mac, backbone)
    #
    #  Add the IPv4 protocol stack to the nodes in our container
    #
    print "Enabling OLSR routing on all backbone nodes"
    internet = ns3.InternetStackHelper()
    olsr = ns3.OlsrHelper()
    internet.SetRoutingHelper(olsr)
    internet.Install(backbone)
    # re-initialize for non-olsr routing.
    internet.Reset()
    #
    #  Assign IPv4 addresses to the device drivers(actually to the associated
    #  IPv4 interfaces) we just created.
    #
    ipAddrs = ns3.Ipv4AddressHelper()
    ipAddrs.SetBase(ns3.Ipv4Address("192.168.0.0"),
                    ns3.Ipv4Mask("255.255.255.0"))
    ipAddrs.Assign(backboneDevices)

    #
    #  The ad-hoc network nodes need a mobility model so we aggregate one to
    #  each of the nodes we just finished building.
    #
    mobility = ns3.MobilityHelper()
    positionAlloc = ns3.ListPositionAllocator()
    x = 0.0
    for i in range(backboneNodes):
        positionAlloc.Add(ns3.Vector(x, 0.0, 0.0))
        x += 5.0
    mobility.SetPositionAllocator(positionAlloc)
    mobility.SetMobilityModel(
        "ns3::RandomDirection2dMobilityModel", "Bounds",
        ns3.RectangleValue(ns3.Rectangle(0, 1000, 0, 1000)), "Speed",
        ns3.RandomVariableValue(ns3.ConstantVariable(2000)), "Pause",
        ns3.RandomVariableValue(ns3.ConstantVariable(0.2)))
    mobility.Install(backbone)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
    #                                                                        #
    #  Construct the LANs                                                    #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /

    #  Reset the address base-- all of the CSMA networks will be in
    #  the "172.16 address space
    ipAddrs.SetBase(ns3.Ipv4Address("172.16.0.0"),
                    ns3.Ipv4Mask("255.255.255.0"))

    for i in range(backboneNodes):
        print "Configuring local area network for backbone node ", i
        #
        #  Create a container to manage the nodes of the LAN.  We need
        #  two containers here; one with all of the new nodes, and one
        #  with all of the nodes including new and existing nodes
        #
        newLanNodes = ns3.NodeContainer()
        newLanNodes.Create(lanNodes - 1)
        #  Now, create the container with all nodes on this link
        lan = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)),
                                newLanNodes)
        #
        #  Create the CSMA net devices and install them into the nodes in our
        #  collection.
        #
        csma = ns3.CsmaHelper()
        csma.SetChannelAttribute("DataRate",
                                 ns3.DataRateValue(ns3.DataRate(5000000)))
        csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
        lanDevices = csma.Install(lan)
        #
        #  Add the IPv4 protocol stack to the new LAN nodes
        #
        internet.Install(newLanNodes)
        #
        #  Assign IPv4 addresses to the device drivers(actually to the
        #  associated IPv4 interfaces) we just created.
        #
        ipAddrs.Assign(lanDevices)
        #
        #  Assign a new network prefix for the next LAN, according to the
        #  network mask initialized above
        #
        ipAddrs.NewNetwork()

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
    #                                                                        #
    #  Construct the mobile networks                                         #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /

    #  Reset the address base-- all of the 802.11 networks will be in
    #  the "10.0" address space
    ipAddrs.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))

    for i in range(backboneNodes):
        print "Configuring wireless network for backbone node ", i
        #
        #  Create a container to manage the nodes of the LAN.  We need
        #  two containers here; one with all of the new nodes, and one
        #  with all of the nodes including new and existing nodes
        #
        stas = ns3.NodeContainer()
        stas.Create(infraNodes - 1)
        #  Now, create the container with all nodes on this link
        infra = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), stas)
        #
        #  Create another ad hoc network and devices
        #
        ssid = ns3.Ssid('wifi-infra' + str(i))
        wifiInfra = ns3.WifiHelper.Default()
        wifiPhy.SetChannel(wifiChannel.Create())
        wifiInfra.SetRemoteStationManager('ns3::ArfWifiManager')
        macInfra = ns3.NqosWifiMacHelper.Default()
        macInfra.SetType("ns3::NqstaWifiMac", "Ssid", ns3.SsidValue(ssid),
                         "ActiveProbing", ns3.BooleanValue(False))

        # setup stas
        staDevices = wifiInfra.Install(wifiPhy, macInfra, stas)
        # setup ap.
        macInfra.SetType("ns3::NqapWifiMac", "Ssid",
                         ns3.SsidValue(ssid), "BeaconGeneration",
                         ns3.BooleanValue(True), "BeaconInterval",
                         ns3.TimeValue(ns3.Seconds(2.5)))
        apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i))
        # Collect all of these new devices
        infraDevices = ns3.NetDeviceContainer(apDevices, staDevices)

        #  Add the IPv4 protocol stack to the nodes in our container
        #
        internet.Install(stas)
        #
        #  Assign IPv4 addresses to the device drivers(actually to the associated
        #  IPv4 interfaces) we just created.
        #
        ipAddrs.Assign(infraDevices)
        #
        #  Assign a new network prefix for each mobile network, according to
        #  the network mask initialized above
        #
        ipAddrs.NewNetwork()
        #
        #  The new wireless nodes need a mobility model so we aggregate one
        #  to each of the nodes we just finished building.
        #
        subnetAlloc = ns3.ListPositionAllocator()
        for j in range(infra.GetN()):
            subnetAlloc.Add(ns3.Vector(0.0, j, 0.0))

        mobility.PushReferenceMobilityModel(backbone.Get(i))
        mobility.SetPositionAllocator(subnetAlloc)
        mobility.SetMobilityModel(
            "ns3::RandomDirection2dMobilityModel", "Bounds",
            ns3.RectangleValue(ns3.Rectangle(-25, 25, -25, 25)), "Speed",
            ns3.RandomVariableValue(ns3.ConstantVariable(30)), "Pause",
            ns3.RandomVariableValue(ns3.ConstantVariable(0.4)))
        mobility.Install(infra)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
    #                                                                        #
    #  Application configuration                                             #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /

    #  Create the OnOff application to send UDP datagrams of size
    #  210 bytes at a rate of 448 Kb/s, between two nodes
    print "Create Applications."
    port = 9  #  Discard port(RFC 863)

    #  Let's make sure that the user does not define too few LAN nodes
    #  to make this example work.  We need lanNodes >= 5
    assert (lanNodes >= 5)
    appSource = ns3.NodeList.GetNode(11)
    appSink = ns3.NodeList.GetNode(13)
    remoteAddr = ns3.Ipv4Address("172.16.0.5")

    onoff = ns3.OnOffHelper(
        "ns3::UdpSocketFactory",
        ns3.Address(ns3.InetSocketAddress(remoteAddr, port)))
    onoff.SetAttribute("OnTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(1)))
    onoff.SetAttribute("OffTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(0)))
    apps = onoff.Install(ns3.NodeContainer(appSource))
    apps.Start(ns3.Seconds(3.0))
    apps.Stop(ns3.Seconds(20.0))

    #  Create a packet sink to receive these packets
    sink = ns3.PacketSinkHelper(
        "ns3::UdpSocketFactory",
        ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port))
    apps = sink.Install(ns3.NodeContainer(appSink))
    apps.Start(ns3.Seconds(3.0))

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
    #                                                                        #
    #  Tracing configuration                                                 #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /

    print "Configure Tracing."
    #
    #  Let's set up some ns-2-like ascii traces, using another helper class
    #
    #std.ofstream ascii
    #ascii = ns3.AsciiTraceHelper();
    #stream = ascii.CreateFileStream("mixed-wireless.tr");
    #wifiPhy.EnableAsciiAll(stream);
    #csma.EnableAsciiAll(stream);
    print "(tracing not done for Python)"
    #  Look at nodes 11, 13 only
    # WifiHelper.EnableAscii(ascii, 11, 0);
    # WifiHelper.EnableAscii(ascii, 13, 0);

    #  Let's do a pcap trace on the backbone devices
    wifiPhy.EnablePcap("mixed-wireless", backboneDevices)
    #  Let's additionally trace the application Sink, ifIndex 0
    csma = ns3.CsmaHelper()
    csma.EnablePcapAll("mixed-wireless", False)

    #   #ifdef ENABLE_FOR_TRACING_EXAMPLE
    #     Config.Connect("/NodeList/*/$MobilityModel/CourseChange",
    #       MakeCallback(&CourseChangeCallback))
    #   #endif

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    #                                                                        #
    #  Run simulation                                                        #
    #                                                                        #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    print "Run Simulation."
    ns3.Simulator.Stop(ns3.Seconds(stopTime))
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
Пример #5
0
def main(argv):

    #
    # Allow the user to override any of the defaults and the above Bind() at
    # run-time, via command-line arguments
    #
    cmd = ns3.CommandLine()
    cmd.Parse(argv)

    #
    # Explicitly create the nodes required by the topology(shown above).
    #
    #print "Create nodes."
    terminals = ns3.NodeContainer()
    terminals.Create(4)

    csmaSwitch = ns3.NodeContainer()
    csmaSwitch.Create(1)

    #print "Build Topology"
    csma = ns3.CsmaHelper()
    csma.SetChannelAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate(5000000)))
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))

    # Create the csma links, from each terminal to the switch

    terminalDevices = ns3.NetDeviceContainer()
    switchDevices = ns3.NetDeviceContainer()

    for i in range(4):
        link = csma.Install(
            ns3.NodeContainer(ns3.NodeContainer(terminals.Get(i)), csmaSwitch))
        terminalDevices.Add(link.Get(0))
        switchDevices.Add(link.Get(1))

    # Create the bridge netdevice, which will do the packet switching
    switchNode = csmaSwitch.Get(0)
    bridgeDevice = ns3.BridgeNetDevice()
    switchNode.AddDevice(bridgeDevice)

    for portIter in range(switchDevices.GetN()):
        bridgeDevice.AddBridgePort(switchDevices.Get(portIter))

    # Add internet stack to the terminals
    internet = ns3.InternetStackHelper()
    internet.Install(terminals)

    # We've got the "hardware" in place.  Now we need to add IP addresses.
    #
    #print "Assign IP Addresses."
    ipv4 = ns3.Ipv4AddressHelper()
    ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
    ipv4.Assign(terminalDevices)

    #
    # Create an OnOff application to send UDP datagrams from node zero to node 1.
    #
    #print "Create Applications."
    port = 9  # Discard port(RFC 863)

    onoff = ns3.OnOffHelper(
        "ns3::UdpSocketFactory",
        ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.2"), port)))
    onoff.SetAttribute("OnTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(1)))
    onoff.SetAttribute("OffTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(0)))

    app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
    # Start the application
    app.Start(ns3.Seconds(1.0))
    app.Stop(ns3.Seconds(10.0))

    # Create an optional packet sink to receive these packets
    sink = ns3.PacketSinkHelper(
        "ns3::UdpSocketFactory",
        ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)))
    app = sink.Install(ns3.NodeContainer(terminals.Get(1)))
    app.Start(ns3.Seconds(0.0))

    #
    # Create a similar flow from n3 to n0, starting at time 1.1 seconds
    #
    onoff.SetAttribute(
        "Remote",
        ns3.AddressValue(
            ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
    app = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
    app.Start(ns3.Seconds(1.1))
    app.Stop(ns3.Seconds(10.0))

    app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
    app.Start(ns3.Seconds(0.0))

    #
    # Configure tracing of all enqueue, dequeue, and NetDevice receive events.
    # Trace output will be sent to the file "csma-bridge.tr"
    #
    #print "Configure Tracing."
    #ascii = ns3.AsciiTraceHelper();
    #csma.EnableAsciiAll(ascii.CreateFileStream ("csma-bridge.tr"));

    #
    # Also configure some tcpdump traces; each interface will be traced.
    # The output files will be named:
    #     csma-bridge.pcap-<nodeId>-<interfaceId>
    # and can be read by the "tcpdump -r" command(use "-tt" option to
    # display timestamps correctly)
    #
    csma.EnablePcapAll("csma-bridge", False)

    #
    # Now, do the actual simulation.
    #
    #print "Run Simulation."
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
def main(argv):

    cmd = ns3.CommandLine()

    cmd.NumNodesSide = None
    cmd.AddValue(
        "NumNodesSide",
        "Grid side number of nodes (total number of nodes will be this number squared)"
    )

    cmd.Results = None
    cmd.AddValue("Results", "Write XML results to file")

    cmd.Plot = None
    cmd.AddValue("Plot", "Plot the results using the matplotlib python module")

    cmd.Parse(argv)

    wifi = ns3.WifiHelper.Default()
    wifiMac = ns3.NqosWifiMacHelper.Default()
    wifiPhy = ns3.YansWifiPhyHelper.Default()
    wifiChannel = ns3.YansWifiChannelHelper.Default()
    wifiPhy.SetChannel(wifiChannel.Create())
    ssid = ns3.Ssid("wifi-default")
    wifi.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac.SetType("ns3::AdhocWifiMac", "Ssid", ns3.SsidValue(ssid))

    internet = ns3.InternetStackHelper()
    list_routing = ns3.Ipv4ListRoutingHelper()
    olsr_routing = ns3.OlsrHelper()
    static_routing = ns3.Ipv4StaticRoutingHelper()
    list_routing.Add(static_routing, 0)
    list_routing.Add(olsr_routing, 100)
    internet.SetRoutingHelper(list_routing)

    ipv4Addresses = ns3.Ipv4AddressHelper()
    ipv4Addresses.SetBase(ns3.Ipv4Address("10.0.0.0"),
                          ns3.Ipv4Mask("255.255.255.0"))

    port = 9  # Discard port(RFC 863)
    onOffHelper = ns3.OnOffHelper(
        "ns3::UdpSocketFactory",
        ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.0.0.1"), port)))
    onOffHelper.SetAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate("100kbps")))
    onOffHelper.SetAttribute("OnTime",
                             ns3.RandomVariableValue(ns3.ConstantVariable(1)))
    onOffHelper.SetAttribute("OffTime",
                             ns3.RandomVariableValue(ns3.ConstantVariable(0)))

    addresses = []
    nodes = []

    if cmd.NumNodesSide is None:
        num_nodes_side = NUM_NODES_SIDE
    else:
        num_nodes_side = int(cmd.NumNodesSide)

    for xi in range(num_nodes_side):
        for yi in range(num_nodes_side):

            node = ns3.Node()
            nodes.append(node)

            internet.Install(ns3.NodeContainer(node))

            mobility = ns3.ConstantPositionMobilityModel()
            mobility.SetPosition(ns3.Vector(xi * DISTANCE, yi * DISTANCE, 0))
            node.AggregateObject(mobility)

            devices = wifi.Install(wifiPhy, wifiMac, node)
            ipv4_interfaces = ipv4Addresses.Assign(devices)
            addresses.append(ipv4_interfaces.GetAddress(0))

    for i, node in enumerate(nodes):
        destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)]
        #print i, destaddr
        onOffHelper.SetAttribute(
            "Remote", ns3.AddressValue(ns3.InetSocketAddress(destaddr, port)))
        app = onOffHelper.Install(ns3.NodeContainer(node))
        app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))

    #internet.EnablePcapAll("wifi-olsr")
    flowmon_helper = ns3.FlowMonitorHelper()
    #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31)))
    monitor = flowmon_helper.InstallAll()
    monitor.SetAttribute("DelayBinWidth", ns3.DoubleValue(0.001))
    monitor.SetAttribute("JitterBinWidth", ns3.DoubleValue(0.001))
    monitor.SetAttribute("PacketSizeBinWidth", ns3.DoubleValue(20))

    ns3.Simulator.Stop(ns3.Seconds(44.0))
    ns3.Simulator.Run()

    def print_stats(os, st):
        print >> os, "  Tx Bytes: ", st.txBytes
        print >> os, "  Rx Bytes: ", st.rxBytes
        print >> os, "  Tx Packets: ", st.txPackets
        print >> os, "  Rx Packets: ", st.rxPackets
        print >> os, "  Lost Packets: ", st.lostPackets
        if st.rxPackets > 0:
            print >> os, "  Mean{Delay}: ", (st.delaySum.GetSeconds() /
                                             st.rxPackets)
            print >> os, "  Mean{Jitter}: ", (st.jitterSum.GetSeconds() /
                                              (st.rxPackets - 1))
            print >> os, "  Mean{Hop Count}: ", float(
                st.timesForwarded) / st.rxPackets + 1

        if 0:
            print >> os, "Delay Histogram"
            for i in range(st.delayHistogram.GetNBins()):
                print >> os, " ",i,"(", st.delayHistogram.GetBinStart (i), "-", \
                    st.delayHistogram.GetBinEnd (i), "): ", st.delayHistogram.GetBinCount (i)
            print >> os, "Jitter Histogram"
            for i in range(st.jitterHistogram.GetNBins()):
                print >> os, " ",i,"(", st.jitterHistogram.GetBinStart (i), "-", \
                    st.jitterHistogram.GetBinEnd (i), "): ", st.jitterHistogram.GetBinCount (i)
            print >> os, "PacketSize Histogram"
            for i in range(st.packetSizeHistogram.GetNBins()):
                print >> os, " ",i,"(", st.packetSizeHistogram.GetBinStart (i), "-", \
                    st.packetSizeHistogram.GetBinEnd (i), "): ", st.packetSizeHistogram.GetBinCount (i)

        for reason, drops in enumerate(st.packetsDropped):
            print "  Packets dropped by reason %i: %i" % (reason, drops)
        #for reason, drops in enumerate(st.bytesDropped):
        #    print "Bytes dropped by reason %i: %i" % (reason, drops)

    monitor.CheckForLostPackets()
    classifier = flowmon_helper.GetClassifier()

    if cmd.Results is None:
        for flow_id, flow_stats in monitor.GetFlowStats():
            t = classifier.FindFlow(flow_id)
            proto = {6: 'TCP', 17: 'UDP'}[t.protocol]
            print "FlowID: %i (%s %s/%s --> %s/%i)" % \
                (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort)
            print_stats(sys.stdout, flow_stats)
    else:
        print monitor.SerializeToXmlFile(cmd.Results, True, True)

    if cmd.Plot is not None:
        import pylab
        delays = []
        for flow_id, flow_stats in monitor.GetFlowStats():
            tupl = classifier.FindFlow(flow_id)
            if tupl.protocol == 17 and tupl.sourcePort == 698:
                continue
            delays.append(flow_stats.delaySum.GetSeconds() /
                          flow_stats.rxPackets)
        pylab.hist(delays, 20)
        pylab.xlabel("Delay (s)")
        pylab.ylabel("Number of Flows")
        pylab.show()

    return 0
Пример #7
0
def main(argv):

    cmd = ns3.CommandLine()
    cmd.AddValue("deviceName_emu_0", "device name", emuDevice_emu_0)
    cmd.AddValue("deviceName_emu_1", "device name", emuDevice_emu_1)
    cmd.AddValue("deviceName_emu_2", "device name", emuDevice_emu_2)
    cmd.AddValue("mode_tap_0", "Mode Setting of TapBridge", mode_tap_0)
    cmd.AddValue("tapName_tap_0", "Name of the OS tap device", tapName_tap_0)
    cmd.AddValue("mode_tap_1", "Mode Setting of TapBridge", mode_tap_1)
    cmd.AddValue("tapName_tap_1", "Name of the OS tap device", tapName_tap_1)
    cmd.AddValue("mode_tap_2", "Mode Setting of TapBridge", mode_tap_2)
    cmd.AddValue("tapName_tap_2", "Name of the OS tap device", tapName_tap_2)
    cmd.AddValue("deviceName_emu_0", "device name", emuDevice_emu_0)
    cmd.AddValue("deviceName_emu_1", "device name", emuDevice_emu_1)
    cmd.AddValue("deviceName_emu_2", "device name", emuDevice_emu_2)
    cmd.AddValue("mode_tap_0", "Mode Setting of TapBridge", mode_tap_0)
    cmd.AddValue("tapName_tap_0", "Name of the OS tap device", tapName_tap_0)
    cmd.AddValue("mode_tap_1", "Mode Setting of TapBridge", mode_tap_1)
    cmd.AddValue("tapName_tap_1", "Name of the OS tap device", tapName_tap_1)
    cmd.AddValue("mode_tap_2", "Mode Setting of TapBridge", mode_tap_2)
    cmd.AddValue("tapName_tap_2", "Name of the OS tap device", tapName_tap_2)
    cmd.Parse (argv)

    # Configuration.
    GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
    GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
    ns3.GlobalValue.Bind ("SimulatorImplementationType", ns3.StringValue ("ns3::RealtimeSimulatorImpl"));
    ns3.GlobalValue.Bind ("ChecksumEnabled", ns3.BooleanValue (true));

    # Build nodes
    term_0 = ns3.NodeContainer()
    term_0.Create (10)
    term_1 = ns3.NodeContainer()
    term_1.Create (10)
    term_2 = ns3.NodeContainer()
    term_2.Create (10)
    bridge_0 = ns3.NodeContainer()
    bridge_0.Create (1)
    ap_0 = ns3.NodeContainer()
    ap_0.Create (1)
    station_0 = ns3.NodeContainer()
    station_0.Create (1)
    station_1 = ns3.NodeContainer()
    station_1.Create (1)
    station_2 = ns3.NodeContainer()
    station_2.Create (1)
    station_3 = ns3.NodeContainer()
    station_3.Create (1)
    station_4 = ns3.NodeContainer()
    station_4.Create (1)
    station_5 = ns3.NodeContainer()
    station_5.Create (1)
    station_6 = ns3.NodeContainer()
    station_6.Create (1)
    term_3 = ns3.NodeContainer()
    term_3.Create (1)
    term_4 = ns3.NodeContainer()
    term_4.Create (1)
    term_5 = ns3.NodeContainer()
    term_5.Create (1)
    term_6 = ns3.NodeContainer()
    term_6.Create (1)
    bridge_1 = ns3.NodeContainer()
    bridge_1.Create (1)
    bridge_2 = ns3.NodeContainer()
    bridge_2.Create (1)
    emu_0 = ns3.NodeContainer()
    emu_0.Create (1)
    emu_1 = ns3.NodeContainer()
    emu_1.Create (1)
    term_7 = ns3.NodeContainer()
    term_7.Create (1)
    term_8 = ns3.NodeContainer()
    term_8.Create (1)
    term_9 = ns3.NodeContainer()
    term_9.Create (1)
    term_10 = ns3.NodeContainer()
    term_10.Create (1)
    term_11 = ns3.NodeContainer()
    term_11.Create (1)
    term_12 = ns3.NodeContainer()
    term_12.Create (10)
    term_13 = ns3.NodeContainer()
    term_13.Create (10)
    term_14 = ns3.NodeContainer()
    term_14.Create (10)
    bridge_3 = ns3.NodeContainer()
    bridge_3.Create (1)
    term_15 = ns3.NodeContainer()
    term_15.Create (1)
    term_16 = ns3.NodeContainer()
    term_16.Create (1)
    term_17 = ns3.NodeContainer()
    term_17.Create (1)
    term_18 = ns3.NodeContainer()
    term_18.Create (1)
    term_19 = ns3.NodeContainer()
    term_19.Create (1)
    term_20 = ns3.NodeContainer()
    term_20.Create (1)
    term_21 = ns3.NodeContainer()
    term_21.Create (1)
    term_22 = ns3.NodeContainer()
    term_22.Create (1)
    term_23 = ns3.NodeContainer()
    term_23.Create (1)
    term_24 = ns3.NodeContainer()
    term_24.Create (1)
    bridge_4 = ns3.NodeContainer()
    bridge_4.Create (1)
    ap_1 = ns3.NodeContainer()
    ap_1.Create (1)
    station_7 = ns3.NodeContainer()
    station_7.Create (1)
    station_8 = ns3.NodeContainer()
    station_8.Create (1)
    station_9 = ns3.NodeContainer()
    station_9.Create (1)
    station_10 = ns3.NodeContainer()
    station_10.Create (1)
    station_11 = ns3.NodeContainer()
    station_11.Create (1)
    station_12 = ns3.NodeContainer()
    station_12.Create (1)
    station_13 = ns3.NodeContainer()
    station_13.Create (1)
    emu_2 = ns3.NodeContainer()
    emu_2.Create (1)
    tap_0 = ns3.NodeContainer()
    tap_0.Create (1)
    tap_1 = ns3.NodeContainer()
    tap_1.Create (1)
    tap_2 = ns3.NodeContainer()
    tap_2.Create (1)
    term_0 = ns3.NodeContainer()
    term_0.Create (10)
    term_1 = ns3.NodeContainer()
    term_1.Create (10)
    term_2 = ns3.NodeContainer()
    term_2.Create (10)
    bridge_0 = ns3.NodeContainer()
    bridge_0.Create (1)
    router_0 = ns3.NodeContainer()
    router_0.Create (1)
    ap_0 = ns3.NodeContainer()
    ap_0.Create (1)
    station_0 = ns3.NodeContainer()
    station_0.Create (1)
    station_1 = ns3.NodeContainer()
    station_1.Create (1)
    station_2 = ns3.NodeContainer()
    station_2.Create (1)
    station_3 = ns3.NodeContainer()
    station_3.Create (1)
    station_4 = ns3.NodeContainer()
    station_4.Create (1)
    station_5 = ns3.NodeContainer()
    station_5.Create (1)
    station_6 = ns3.NodeContainer()
    station_6.Create (1)
    term_3 = ns3.NodeContainer()
    term_3.Create (1)
    term_4 = ns3.NodeContainer()
    term_4.Create (1)
    term_5 = ns3.NodeContainer()
    term_5.Create (1)
    term_6 = ns3.NodeContainer()
    term_6.Create (1)
    bridge_1 = ns3.NodeContainer()
    bridge_1.Create (1)
    bridge_2 = ns3.NodeContainer()
    bridge_2.Create (1)
    emu_0 = ns3.NodeContainer()
    emu_0.Create (1)
    emu_1 = ns3.NodeContainer()
    emu_1.Create (1)
    term_7 = ns3.NodeContainer()
    term_7.Create (1)
    term_8 = ns3.NodeContainer()
    term_8.Create (1)
    term_9 = ns3.NodeContainer()
    term_9.Create (1)
    term_10 = ns3.NodeContainer()
    term_10.Create (1)
    term_11 = ns3.NodeContainer()
    term_11.Create (1)
    term_12 = ns3.NodeContainer()
    term_12.Create (10)
    term_13 = ns3.NodeContainer()
    term_13.Create (10)
    term_14 = ns3.NodeContainer()
    term_14.Create (10)
    bridge_3 = ns3.NodeContainer()
    bridge_3.Create (1)
    term_15 = ns3.NodeContainer()
    term_15.Create (1)
    term_16 = ns3.NodeContainer()
    term_16.Create (1)
    term_17 = ns3.NodeContainer()
    term_17.Create (1)
    term_18 = ns3.NodeContainer()
    term_18.Create (1)
    term_19 = ns3.NodeContainer()
    term_19.Create (1)
    term_20 = ns3.NodeContainer()
    term_20.Create (1)
    term_21 = ns3.NodeContainer()
    term_21.Create (1)
    term_22 = ns3.NodeContainer()
    term_22.Create (1)
    term_23 = ns3.NodeContainer()
    term_23.Create (1)
    term_24 = ns3.NodeContainer()
    term_24.Create (1)
    bridge_4 = ns3.NodeContainer()
    bridge_4.Create (1)
    ap_1 = ns3.NodeContainer()
    ap_1.Create (1)
    station_7 = ns3.NodeContainer()
    station_7.Create (1)
    station_8 = ns3.NodeContainer()
    station_8.Create (1)
    station_9 = ns3.NodeContainer()
    station_9.Create (1)
    station_10 = ns3.NodeContainer()
    station_10.Create (1)
    station_11 = ns3.NodeContainer()
    station_11.Create (1)
    station_12 = ns3.NodeContainer()
    station_12.Create (1)
    station_13 = ns3.NodeContainer()
    station_13.Create (1)
    emu_2 = ns3.NodeContainer()
    emu_2.Create (1)
    tap_0 = ns3.NodeContainer()
    tap_0.Create (1)
    tap_1 = ns3.NodeContainer()
    tap_1.Create (1)
    tap_2 = ns3.NodeContainer()
    tap_2.Create (1)
    router_2 = ns3.NodeContainer()
    router_2.Create (1)
    term_50 = ns3.NodeContainer()
    term_50.Create (1)
    term_51 = ns3.NodeContainer()
    term_51.Create (1)

    # Build link.
    csma_bridge_0 = ns3.CsmaHelper();
    csma_bridge_0.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_0.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    wifiPhy_ap_0 = ns3.YansWifiPhyHelper.Default()
    wifiChannel_ap_0 = ns3.YansWifiChannelHelper.Default()
    wifiPhy_ap_0.SetChannel(wifiChannel_ap_0.Create())
    csma_bridge_1 = ns3.CsmaHelper();
    csma_bridge_1.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_1.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_bridge_2 = ns3.CsmaHelper();
    csma_bridge_2.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_2.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_hub_0 = ns3.CsmaHelper()
    csma_hub_0.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_0.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    emu_0 = ns3.EmuHelper()
    emu_0.SetAttribute ("DeviceName", StringValue (emuDevice_emu_0))
    emu_1 = ns3.EmuHelper()
    emu_1.SetAttribute ("DeviceName", StringValue (emuDevice_emu_1))
    csma_hub_1 = ns3.CsmaHelper()
    csma_hub_1.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_1.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_hub_2 = ns3.CsmaHelper()
    csma_hub_2.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_2.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_bridge_3 = ns3.CsmaHelper();
    csma_bridge_3.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_3.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_bridge_4 = ns3.CsmaHelper();
    csma_bridge_4.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_4.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    wifiPhy_ap_1 = ns3.YansWifiPhyHelper.Default()
    wifiChannel_ap_1 = ns3.YansWifiChannelHelper.Default()
    wifiPhy_ap_1.SetChannel(wifiChannel_ap_1.Create())
    emu_2 = ns3.EmuHelper()
    emu_2.SetAttribute ("DeviceName", StringValue (emuDevice_emu_2))
    csma_hub_3 = ns3.CsmaHelper()
    csma_hub_3.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_3.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_tap_0 = ns3.CsmaHelper()
    csma_tap_0.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_0.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_hub_4 = ns3.CsmaHelper()
    csma_hub_4.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_4.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_tap_1 = ns3.CsmaHelper()
    csma_tap_1.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_1.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_tap_2 = ns3.CsmaHelper()
    csma_tap_2.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_2.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_hub_5 = ns3.CsmaHelper()
    csma_hub_5.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_5.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_hub_6 = ns3.CsmaHelper()
    csma_hub_6.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_6.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_bridge_0 = ns3.CsmaHelper();
    csma_bridge_0.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_0.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    wifiPhy_ap_0 = ns3.YansWifiPhyHelper.Default()
    wifiChannel_ap_0 = ns3.YansWifiChannelHelper.Default()
    wifiPhy_ap_0.SetChannel(wifiChannel_ap_0.Create())
    p2p_p2p_0 = ns3.PointToPointHelper()
    p2p_p2p_0.SetDeviceAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    p2p_p2p_0.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_bridge_1 = ns3.CsmaHelper();
    csma_bridge_1.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_1.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_bridge_2 = ns3.CsmaHelper();
    csma_bridge_2.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_2.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_hub_0 = ns3.CsmaHelper()
    csma_hub_0.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_0.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    emu_0 = ns3.EmuHelper()
    emu_0.SetAttribute ("DeviceName", StringValue (emuDevice_emu_0))
    emu_1 = ns3.EmuHelper()
    emu_1.SetAttribute ("DeviceName", StringValue (emuDevice_emu_1))
    csma_hub_1 = ns3.CsmaHelper()
    csma_hub_1.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_1.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_hub_2 = ns3.CsmaHelper()
    csma_hub_2.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_2.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_bridge_3 = ns3.CsmaHelper();
    csma_bridge_3.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_3.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    csma_bridge_4 = ns3.CsmaHelper();
    csma_bridge_4.SetChannelAttribute("DataRate", ns3.DataRateValue (ns3.DataRate(100000000)))
    csma_bridge_4.SetChannelAttribute("Delay",  ns3.TimeValue (ns3.MilliSeconds(10000)))
    wifiPhy_ap_1 = ns3.YansWifiPhyHelper.Default()
    wifiChannel_ap_1 = ns3.YansWifiChannelHelper.Default()
    wifiPhy_ap_1.SetChannel(wifiChannel_ap_1.Create())
    p2p_p2p_1 = ns3.PointToPointHelper()
    p2p_p2p_1.SetDeviceAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    p2p_p2p_1.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)))
    emu_2 = ns3.EmuHelper()
    emu_2.SetAttribute ("DeviceName", StringValue (emuDevice_emu_2))
    csma_hub_3 = ns3.CsmaHelper()
    csma_hub_3.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_3.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_tap_0 = ns3.CsmaHelper()
    csma_tap_0.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_0.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_hub_4 = ns3.CsmaHelper()
    csma_hub_4.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_4.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_tap_1 = ns3.CsmaHelper()
    csma_tap_1.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_1.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_tap_2 = ns3.CsmaHelper()
    csma_tap_2.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)));
    csma_tap_2.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)));
    csma_hub_5 = ns3.CsmaHelper()
    csma_hub_5.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_5.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    csma_hub_6 = ns3.CsmaHelper()
    csma_hub_6.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    csma_hub_6.SetChannelAttribute("Delay",  ns3.TimeValue(ns3.MilliSeconds(10000)))
    p2p_p2p_4 = ns3.PointToPointHelper()
    p2p_p2p_4.SetDeviceAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(100000000)))
    p2p_p2p_4.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(10000)))

    # Build link net device container.
    all_bridge_0 = ns3.NodeContainer()
    all_bridge_0.Add (term_0)
    all_bridge_0.Add (term_1)
    all_bridge_0.Add (term_2)
    terminalDevices_bridge_0 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_0 = ns3.NetDeviceContainer()
    for i in range(3):
        link = csma_bridge_0.Install(NodeContainer(all_bridge_0.Get(i), bridge_0))
        terminalDevices_bridge_0.Add(link.Get(0))
        BridgeDevices_bridge_0.Add(link.Get(1))
    bridge_bridge_0 = ns3.BridgeHelper
    bridge_bridge_0.Install(bridge_0.Get(0), BridgeDevices_bridge_0)
    ndc_bridge_0 = terminalDevices_bridge_0
    all_ap_0 = ns3.NodeContainer()
    ndc_ap_0 = ns3.NetDeviceContainer()
    ssid_ap_0 = ns3.Ssid("wifi-default-0")
    wifi_ap_0 = ns3.WifiHelper.Default()
    wifiMac_ap_0 = ns3.NqosWifiMacHelper.Default()
    wifi_ap_0.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac_ap_0.SetType ("ns3::ApWifiMac", 
       "Ssid", ns3.SsidValue(ssid_ap_0), 
       "BeaconGeneration", ns3.BooleanValue(True),
       "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
    ndc_ap_0.Add(wifi_ap_0.Install(wifiPhy_ap_0, wifiMac_ap_0, ap_0))
    wifiMac_ap_0.SetType("ns3::StaWifiMac",
       "Ssid", ns3.SsidValue(ssid_ap_0), 
       "ActiveProbing", ns3.BooleanValue(False))
    ndc_ap_0.Add(wifi_ap_0.Install(wifiPhy_ap_0, wifiMac_ap_0, all_ap_0 ))
    mobility_ap_0 = ns3.MobilityHelper()
    mobility_ap_0.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
    mobility_ap_0.Install(ap_0)
    mobility_ap_0.Install(all_ap_0)
    all_bridge_1 = ns3.NodeContainer()
    all_bridge_1.Add (term_6)
    all_bridge_1.Add (term_4)
    all_bridge_1.Add (term_5)
    all_bridge_1.Add (term_3)
    all_bridge_1.Add (term_11)
    all_bridge_1.Add (term_10)
    all_bridge_1.Add (term_9)
    all_bridge_1.Add (term_8)
    terminalDevices_bridge_1 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_1 = ns3.NetDeviceContainer()
    for i in range(8):
        link = csma_bridge_1.Install(NodeContainer(all_bridge_1.Get(i), bridge_1))
        terminalDevices_bridge_1.Add(link.Get(0))
        BridgeDevices_bridge_1.Add(link.Get(1))
    bridge_bridge_1 = ns3.BridgeHelper
    bridge_bridge_1.Install(bridge_1.Get(0), BridgeDevices_bridge_1)
    ndc_bridge_1 = terminalDevices_bridge_1
    all_bridge_2 = ns3.NodeContainer()
    terminalDevices_bridge_2 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_2 = ns3.NetDeviceContainer()
    for i in range(0):
        link = csma_bridge_2.Install(NodeContainer(all_bridge_2.Get(i), bridge_2))
        terminalDevices_bridge_2.Add(link.Get(0))
        BridgeDevices_bridge_2.Add(link.Get(1))
    bridge_bridge_2 = ns3.BridgeHelper
    bridge_bridge_2.Install(bridge_2.Get(0), BridgeDevices_bridge_2)
    ndc_bridge_2 = terminalDevices_bridge_2
    all_hub_0 = ns3.NodeContainer()
    all_hub_0.Add (bridge_1)
    all_hub_0.Add (bridge_2)
    ndc_hub_0 = csma_hub_0.Install(all_hub_0)
    all_emu_0 = ns3.NodeContainer()
    all_emu_0.Add (emu_0)
    ndc_emu_0 = emu_0.Install (all_emu_0)
    all_emu_1 = ns3.NodeContainer()
    all_emu_1.Add (emu_1)
    ndc_emu_1 = emu_1.Install (all_emu_1)
    all_hub_1 = ns3.NodeContainer()
    all_hub_1.Add (bridge_2)
    all_hub_1.Add (emu_0)
    ndc_hub_1 = csma_hub_1.Install(all_hub_1)
    all_hub_2 = ns3.NodeContainer()
    all_hub_2.Add (bridge_2)
    all_hub_2.Add (emu_1)
    ndc_hub_2 = csma_hub_2.Install(all_hub_2)
    all_bridge_3 = ns3.NodeContainer()
    all_bridge_3.Add (term_12)
    all_bridge_3.Add (term_13)
    all_bridge_3.Add (term_14)
    terminalDevices_bridge_3 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_3 = ns3.NetDeviceContainer()
    for i in range(3):
        link = csma_bridge_3.Install(NodeContainer(all_bridge_3.Get(i), bridge_3))
        terminalDevices_bridge_3.Add(link.Get(0))
        BridgeDevices_bridge_3.Add(link.Get(1))
    bridge_bridge_3 = ns3.BridgeHelper
    bridge_bridge_3.Install(bridge_3.Get(0), BridgeDevices_bridge_3)
    ndc_bridge_3 = terminalDevices_bridge_3
    all_bridge_4 = ns3.NodeContainer()
    all_bridge_4.Add (term_21)
    all_bridge_4.Add (term_22)
    all_bridge_4.Add (term_20)
    all_bridge_4.Add (term_7)
    all_bridge_4.Add (term_24)
    all_bridge_4.Add (term_23)
    all_bridge_4.Add (term_15)
    all_bridge_4.Add (term_19)
    all_bridge_4.Add (term_16)
    all_bridge_4.Add (term_17)
    all_bridge_4.Add (term_18)
    all_bridge_4.Add (term_51)
    all_bridge_4.Add (term_50)
    terminalDevices_bridge_4 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_4 = ns3.NetDeviceContainer()
    for i in range(13):
        link = csma_bridge_4.Install(NodeContainer(all_bridge_4.Get(i), bridge_4))
        terminalDevices_bridge_4.Add(link.Get(0))
        BridgeDevices_bridge_4.Add(link.Get(1))
    bridge_bridge_4 = ns3.BridgeHelper
    bridge_bridge_4.Install(bridge_4.Get(0), BridgeDevices_bridge_4)
    ndc_bridge_4 = terminalDevices_bridge_4
    all_ap_1 = ns3.NodeContainer()
    ndc_ap_1 = ns3.NetDeviceContainer()
    ssid_ap_1 = ns3.Ssid("wifi-default-1")
    wifi_ap_1 = ns3.WifiHelper.Default()
    wifiMac_ap_1 = ns3.NqosWifiMacHelper.Default()
    wifi_ap_1.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac_ap_1.SetType ("ns3::ApWifiMac", 
       "Ssid", ns3.SsidValue(ssid_ap_1), 
       "BeaconGeneration", ns3.BooleanValue(True),
       "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
    ndc_ap_1.Add(wifi_ap_1.Install(wifiPhy_ap_1, wifiMac_ap_1, ap_1))
    wifiMac_ap_1.SetType("ns3::StaWifiMac",
       "Ssid", ns3.SsidValue(ssid_ap_1), 
       "ActiveProbing", ns3.BooleanValue(False))
    ndc_ap_1.Add(wifi_ap_1.Install(wifiPhy_ap_1, wifiMac_ap_1, all_ap_1 ))
    mobility_ap_1 = ns3.MobilityHelper()
    mobility_ap_1.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
    mobility_ap_1.Install(ap_1)
    mobility_ap_1.Install(all_ap_1)
    all_emu_2 = ns3.NodeContainer()
    all_emu_2.Add (emu_2)
    ndc_emu_2 = emu_2.Install (all_emu_2)
    all_hub_3 = ns3.NodeContainer()
    all_hub_3.Add (bridge_2)
    all_hub_3.Add (emu_2)
    ndc_hub_3 = csma_hub_3.Install(all_hub_3)
    NodeContainer all_tap_0;
    all_tap_0.Add (tap_0);
    ndc_tap_0 = csma_tap_0.Install(all_tap_0);
    all_hub_4 = ns3.NodeContainer()
    all_hub_4.Add (emu_2)
    all_hub_4.Add (tap_0)
    ndc_hub_4 = csma_hub_4.Install(all_hub_4)
    NodeContainer all_tap_1;
    all_tap_1.Add (tap_1);
    ndc_tap_1 = csma_tap_1.Install(all_tap_1);
    NodeContainer all_tap_2;
    all_tap_2.Add (tap_2);
    ndc_tap_2 = csma_tap_2.Install(all_tap_2);
    all_hub_5 = ns3.NodeContainer()
    all_hub_5.Add (emu_0)
    all_hub_5.Add (tap_2)
    ndc_hub_5 = csma_hub_5.Install(all_hub_5)
    all_hub_6 = ns3.NodeContainer()
    all_hub_6.Add (emu_1)
    all_hub_6.Add (tap_1)
    ndc_hub_6 = csma_hub_6.Install(all_hub_6)
    all_bridge_6 = ns3.NodeContainer()
    all_bridge_6.Add (router_0)
    all_bridge_6.Add (term_0)
    all_bridge_6.Add (term_1)
    all_bridge_6.Add (term_2)
    terminalDevices_bridge_0 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_0 = ns3.NetDeviceContainer()
    for i in range(4):
        link = csma_bridge_0.Install(NodeContainer(all_bridge_6.Get(i), bridge_0))
        terminalDevices_bridge_0.Add(link.Get(0))
        BridgeDevices_bridge_0.Add(link.Get(1))
    bridge_bridge_0 = ns3.BridgeHelper
    bridge_bridge_0.Install(bridge_0.Get(0), BridgeDevices_bridge_0)
    ndc_bridge_0 = terminalDevices_bridge_0
    all_ap_2 = ns3.NodeContainer()
    ndc_ap_2 = ns3.NetDeviceContainer()
    ssid_ap_0 = ns3.Ssid("wifi-default-2")
    wifi_ap_0 = ns3.WifiHelper.Default()
    wifiMac_ap_0 = ns3.NqosWifiMacHelper.Default()
    wifi_ap_0.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac_ap_0.SetType ("ns3::ApWifiMac", 
       "Ssid", ns3.SsidValue(ssid_ap_0), 
       "BeaconGeneration", ns3.BooleanValue(True),
       "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
    ndc_ap_2.Add(wifi_ap_0.Install(wifiPhy_ap_0, wifiMac_ap_0, ap_0))
    wifiMac_ap_0.SetType("ns3::StaWifiMac",
       "Ssid", ns3.SsidValue(ssid_ap_0), 
       "ActiveProbing", ns3.BooleanValue(False))
    ndc_ap_2.Add(wifi_ap_0.Install(wifiPhy_ap_0, wifiMac_ap_0, all_ap_2 ))
    mobility_ap_0 = ns3.MobilityHelper()
    mobility_ap_0.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
    mobility_ap_0.Install(ap_0)
    mobility_ap_0.Install(all_ap_2)
    all_p2p_2 = ns3.NodeContainer()
    all_p2p_2.Add (router_0)
    ndc_p2p_2 = p2p_p2p_0.Install(all_p2p_2)
    all_bridge_7 = ns3.NodeContainer()
    all_bridge_7.Add (term_6)
    all_bridge_7.Add (term_4)
    all_bridge_7.Add (term_5)
    all_bridge_7.Add (term_3)
    all_bridge_7.Add (term_11)
    all_bridge_7.Add (term_10)
    all_bridge_7.Add (term_9)
    all_bridge_7.Add (term_8)
    terminalDevices_bridge_1 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_1 = ns3.NetDeviceContainer()
    for i in range(8):
        link = csma_bridge_1.Install(NodeContainer(all_bridge_7.Get(i), bridge_1))
        terminalDevices_bridge_1.Add(link.Get(0))
        BridgeDevices_bridge_1.Add(link.Get(1))
    bridge_bridge_1 = ns3.BridgeHelper
    bridge_bridge_1.Install(bridge_1.Get(0), BridgeDevices_bridge_1)
    ndc_bridge_1 = terminalDevices_bridge_1
    all_bridge_8 = ns3.NodeContainer()
    all_bridge_8.Add (router_0)
    terminalDevices_bridge_2 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_2 = ns3.NetDeviceContainer()
    for i in range(1):
        link = csma_bridge_2.Install(NodeContainer(all_bridge_8.Get(i), bridge_2))
        terminalDevices_bridge_2.Add(link.Get(0))
        BridgeDevices_bridge_2.Add(link.Get(1))
    bridge_bridge_2 = ns3.BridgeHelper
    bridge_bridge_2.Install(bridge_2.Get(0), BridgeDevices_bridge_2)
    ndc_bridge_2 = terminalDevices_bridge_2
    all_hub_7 = ns3.NodeContainer()
    all_hub_7.Add (bridge_1)
    all_hub_7.Add (bridge_2)
    ndc_hub_7 = csma_hub_0.Install(all_hub_7)
    all_emu_3 = ns3.NodeContainer()
    all_emu_3.Add (emu_0)
    all_emu_3.Add (emu_0)
    ndc_emu_3 = emu_0.Install (all_emu_3)
    all_emu_4 = ns3.NodeContainer()
    all_emu_4.Add (emu_1)
    all_emu_4.Add (emu_1)
    ndc_emu_4 = emu_1.Install (all_emu_4)
    all_hub_8 = ns3.NodeContainer()
    all_hub_8.Add (bridge_2)
    all_hub_8.Add (emu_0)
    ndc_hub_8 = csma_hub_1.Install(all_hub_8)
    all_hub_9 = ns3.NodeContainer()
    all_hub_9.Add (bridge_2)
    all_hub_9.Add (emu_1)
    ndc_hub_9 = csma_hub_2.Install(all_hub_9)
    all_bridge_9 = ns3.NodeContainer()
    all_bridge_9.Add (router_0)
    all_bridge_9.Add (term_12)
    all_bridge_9.Add (term_13)
    all_bridge_9.Add (term_14)
    terminalDevices_bridge_3 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_3 = ns3.NetDeviceContainer()
    for i in range(4):
        link = csma_bridge_3.Install(NodeContainer(all_bridge_9.Get(i), bridge_3))
        terminalDevices_bridge_3.Add(link.Get(0))
        BridgeDevices_bridge_3.Add(link.Get(1))
    bridge_bridge_3 = ns3.BridgeHelper
    bridge_bridge_3.Install(bridge_3.Get(0), BridgeDevices_bridge_3)
    ndc_bridge_3 = terminalDevices_bridge_3
    all_bridge_10 = ns3.NodeContainer()
    all_bridge_10.Add (router_0)
    all_bridge_10.Add (term_21)
    all_bridge_10.Add (term_22)
    all_bridge_10.Add (term_20)
    all_bridge_10.Add (term_7)
    all_bridge_10.Add (term_24)
    all_bridge_10.Add (term_23)
    all_bridge_10.Add (term_15)
    all_bridge_10.Add (term_19)
    all_bridge_10.Add (term_16)
    all_bridge_10.Add (term_17)
    all_bridge_10.Add (term_18)
    terminalDevices_bridge_4 = ns3.NetDeviceContainer()
    BridgeDevices_bridge_4 = ns3.NetDeviceContainer()
    for i in range(12):
        link = csma_bridge_4.Install(NodeContainer(all_bridge_10.Get(i), bridge_4))
        terminalDevices_bridge_4.Add(link.Get(0))
        BridgeDevices_bridge_4.Add(link.Get(1))
    bridge_bridge_4 = ns3.BridgeHelper
    bridge_bridge_4.Install(bridge_4.Get(0), BridgeDevices_bridge_4)
    ndc_bridge_4 = terminalDevices_bridge_4
    all_ap_3 = ns3.NodeContainer()
    ndc_ap_3 = ns3.NetDeviceContainer()
    ssid_ap_1 = ns3.Ssid("wifi-default-3")
    wifi_ap_1 = ns3.WifiHelper.Default()
    wifiMac_ap_1 = ns3.NqosWifiMacHelper.Default()
    wifi_ap_1.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac_ap_1.SetType ("ns3::ApWifiMac", 
       "Ssid", ns3.SsidValue(ssid_ap_1), 
       "BeaconGeneration", ns3.BooleanValue(True),
       "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
    ndc_ap_3.Add(wifi_ap_1.Install(wifiPhy_ap_1, wifiMac_ap_1, ap_1))
    wifiMac_ap_1.SetType("ns3::StaWifiMac",
       "Ssid", ns3.SsidValue(ssid_ap_1), 
       "ActiveProbing", ns3.BooleanValue(False))
    ndc_ap_3.Add(wifi_ap_1.Install(wifiPhy_ap_1, wifiMac_ap_1, all_ap_3 ))
    mobility_ap_1 = ns3.MobilityHelper()
    mobility_ap_1.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
    mobility_ap_1.Install(ap_1)
    mobility_ap_1.Install(all_ap_3)
    all_p2p_3 = ns3.NodeContainer()
    all_p2p_3.Add (router_0)
    ndc_p2p_3 = p2p_p2p_1.Install(all_p2p_3)
    all_emu_5 = ns3.NodeContainer()
    all_emu_5.Add (emu_2)
    all_emu_5.Add (emu_2)
    ndc_emu_5 = emu_2.Install (all_emu_5)
    all_hub_10 = ns3.NodeContainer()
    all_hub_10.Add (bridge_2)
    all_hub_10.Add (emu_2)
    ndc_hub_10 = csma_hub_3.Install(all_hub_10)
    NodeContainer all_tap_3;
    all_tap_3.Add (tap_0);
    all_tap_3.Add (tap_0);
    ndc_tap_3 = csma_tap_0.Install(all_tap_3);
    all_hub_11 = ns3.NodeContainer()
    all_hub_11.Add (emu_2)
    all_hub_11.Add (tap_0)
    ndc_hub_11 = csma_hub_4.Install(all_hub_11)
    NodeContainer all_tap_4;
    all_tap_4.Add (tap_1);
    all_tap_4.Add (tap_1);
    ndc_tap_4 = csma_tap_1.Install(all_tap_4);
    NodeContainer all_tap_5;
    all_tap_5.Add (tap_2);
    all_tap_5.Add (tap_2);
    ndc_tap_5 = csma_tap_2.Install(all_tap_5);
    all_hub_12 = ns3.NodeContainer()
    all_hub_12.Add (emu_0)
    all_hub_12.Add (tap_2)
    ndc_hub_12 = csma_hub_5.Install(all_hub_12)
    all_hub_13 = ns3.NodeContainer()
    all_hub_13.Add (emu_1)
    all_hub_13.Add (tap_1)
    ndc_hub_13 = csma_hub_6.Install(all_hub_13)
    all_p2p_4 = ns3.NodeContainer()
    all_p2p_4.Add (router_2)
    all_p2p_4.Add (router_0)
    ndc_p2p_4 = p2p_p2p_4.Install(all_p2p_4)

    # Install the IP stack.
    internetStackH = ns3.InternetStackHelper()
    internetStackH.Install (term_0)
    internetStackH.Install (term_1)
    internetStackH.Install (term_2)
    internetStackH.Install (ap_0)
    internetStackH.Install (station_0)
    internetStackH.Install (station_1)
    internetStackH.Install (station_2)
    internetStackH.Install (station_3)
    internetStackH.Install (station_4)
    internetStackH.Install (station_5)
    internetStackH.Install (station_6)
    internetStackH.Install (term_3)
    internetStackH.Install (term_4)
    internetStackH.Install (term_5)
    internetStackH.Install (term_6)
    internetStackH.Install (emu_0)
    internetStackH.Install (emu_1)
    internetStackH.Install (term_7)
    internetStackH.Install (term_8)
    internetStackH.Install (term_9)
    internetStackH.Install (term_10)
    internetStackH.Install (term_11)
    internetStackH.Install (term_12)
    internetStackH.Install (term_13)
    internetStackH.Install (term_14)
    internetStackH.Install (term_15)
    internetStackH.Install (term_16)
    internetStackH.Install (term_17)
    internetStackH.Install (term_18)
    internetStackH.Install (term_19)
    internetStackH.Install (term_20)
    internetStackH.Install (term_21)
    internetStackH.Install (term_22)
    internetStackH.Install (term_23)
    internetStackH.Install (term_24)
    internetStackH.Install (ap_1)
    internetStackH.Install (station_7)
    internetStackH.Install (station_8)
    internetStackH.Install (station_9)
    internetStackH.Install (station_10)
    internetStackH.Install (station_11)
    internetStackH.Install (station_12)
    internetStackH.Install (station_13)
    internetStackH.Install (emu_2)
    internetStackH.Install (tap_0)
    internetStackH.Install (tap_1)
    internetStackH.Install (tap_2)
    internetStackH.Install (term_0)
    internetStackH.Install (term_1)
    internetStackH.Install (term_2)
    internetStackH.Install (router_0)
    internetStackH.Install (ap_0)
    internetStackH.Install (station_0)
    internetStackH.Install (station_1)
    internetStackH.Install (station_2)
    internetStackH.Install (station_3)
    internetStackH.Install (station_4)
    internetStackH.Install (station_5)
    internetStackH.Install (station_6)
    internetStackH.Install (term_3)
    internetStackH.Install (term_4)
    internetStackH.Install (term_5)
    internetStackH.Install (term_6)
    internetStackH.Install (emu_0)
    internetStackH.Install (emu_1)
    internetStackH.Install (term_7)
    internetStackH.Install (term_8)
    internetStackH.Install (term_9)
    internetStackH.Install (term_10)
    internetStackH.Install (term_11)
    internetStackH.Install (term_12)
    internetStackH.Install (term_13)
    internetStackH.Install (term_14)
    internetStackH.Install (term_15)
    internetStackH.Install (term_16)
    internetStackH.Install (term_17)
    internetStackH.Install (term_18)
    internetStackH.Install (term_19)
    internetStackH.Install (term_20)
    internetStackH.Install (term_21)
    internetStackH.Install (term_22)
    internetStackH.Install (term_23)
    internetStackH.Install (term_24)
    internetStackH.Install (ap_1)
    internetStackH.Install (station_7)
    internetStackH.Install (station_8)
    internetStackH.Install (station_9)
    internetStackH.Install (station_10)
    internetStackH.Install (station_11)
    internetStackH.Install (station_12)
    internetStackH.Install (station_13)
    internetStackH.Install (emu_2)
    internetStackH.Install (tap_0)
    internetStackH.Install (tap_1)
    internetStackH.Install (tap_2)
    internetStackH.Install (router_2)
    internetStackH.Install (term_50)
    internetStackH.Install (term_51)

    # IP assign.
    ipv4 = ns3.Ipv4AddressHelper()
    ipv4.SetBase (ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_0 = ipv4.Assign (ndc_bridge_0)
    ipv4.SetBase (ns3.Ipv4Address("10.0.1.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_ap_0 = ipv4.Assign (ndc_ap_0)
    ipv4.SetBase (ns3.Ipv4Address("10.0.2.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_1 = ipv4.Assign (ndc_bridge_1)
    ipv4.SetBase (ns3.Ipv4Address("10.0.3.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_2 = ipv4.Assign (ndc_bridge_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.4.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_0 = ipv4.Assign (ndc_hub_0)
    ipv4.SetBase (ns3.Ipv4Address("10.0.5.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_0 = ipv4.Assign (ndc_emu_0)
    ipv4.SetBase (ns3.Ipv4Address("10.0.6.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_1 = ipv4.Assign (ndc_emu_1)
    ipv4.SetBase (ns3.Ipv4Address("10.0.7.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_1 = ipv4.Assign (ndc_hub_1)
    ipv4.SetBase (ns3.Ipv4Address("10.0.8.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_2 = ipv4.Assign (ndc_hub_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.9.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_3 = ipv4.Assign (ndc_bridge_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.10.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_4 = ipv4.Assign (ndc_bridge_4)
    ipv4.SetBase (ns3.Ipv4Address("10.0.11.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_ap_1 = ipv4.Assign (ndc_ap_1)
    ipv4.SetBase (ns3.Ipv4Address("10.0.12.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_2 = ipv4.Assign (ndc_emu_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.13.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_3 = ipv4.Assign (ndc_hub_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.14.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_0 = ipv4.Assign (ndc_tap_0)
    ipv4.SetBase (ns3.Ipv4Address("10.0.15.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_4 = ipv4.Assign (ndc_hub_4)
    ipv4.SetBase (ns3.Ipv4Address("10.0.16.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_1 = ipv4.Assign (ndc_tap_1)
    ipv4.SetBase (ns3.Ipv4Address("10.0.17.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_2 = ipv4.Assign (ndc_tap_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.18.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_5 = ipv4.Assign (ndc_hub_5)
    ipv4.SetBase (ns3.Ipv4Address("10.0.19.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_6 = ipv4.Assign (ndc_hub_6)
    ipv4.SetBase (ns3.Ipv4Address("10.0.20.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_6 = ipv4.Assign (ndc_bridge_6)
    ipv4.SetBase (ns3.Ipv4Address("10.0.21.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_ap_2 = ipv4.Assign (ndc_ap_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.22.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_p2p_2 = ipv4.Assign (ndc_p2p_2)
    ipv4.SetBase (ns3.Ipv4Address("10.0.23.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_7 = ipv4.Assign (ndc_bridge_7)
    ipv4.SetBase (ns3.Ipv4Address("10.0.24.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_8 = ipv4.Assign (ndc_bridge_8)
    ipv4.SetBase (ns3.Ipv4Address("10.0.25.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_7 = ipv4.Assign (ndc_hub_7)
    ipv4.SetBase (ns3.Ipv4Address("10.0.26.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_3 = ipv4.Assign (ndc_emu_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.27.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_4 = ipv4.Assign (ndc_emu_4)
    ipv4.SetBase (ns3.Ipv4Address("10.0.28.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_8 = ipv4.Assign (ndc_hub_8)
    ipv4.SetBase (ns3.Ipv4Address("10.0.29.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_9 = ipv4.Assign (ndc_hub_9)
    ipv4.SetBase (ns3.Ipv4Address("10.0.30.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_9 = ipv4.Assign (ndc_bridge_9)
    ipv4.SetBase (ns3.Ipv4Address("10.0.31.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_bridge_10 = ipv4.Assign (ndc_bridge_10)
    ipv4.SetBase (ns3.Ipv4Address("10.0.32.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_ap_3 = ipv4.Assign (ndc_ap_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.33.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_p2p_3 = ipv4.Assign (ndc_p2p_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.34.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_emu_5 = ipv4.Assign (ndc_emu_5)
    ipv4.SetBase (ns3.Ipv4Address("10.0.35.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_10 = ipv4.Assign (ndc_hub_10)
    ipv4.SetBase (ns3.Ipv4Address("10.0.36.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_3 = ipv4.Assign (ndc_tap_3)
    ipv4.SetBase (ns3.Ipv4Address("10.0.37.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_11 = ipv4.Assign (ndc_hub_11)
    ipv4.SetBase (ns3.Ipv4Address("10.0.38.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_4 = ipv4.Assign (ndc_tap_4)
    ipv4.SetBase (ns3.Ipv4Address("10.0.39.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_tap_5 = ipv4.Assign (ndc_tap_5)
    ipv4.SetBase (ns3.Ipv4Address("10.0.40.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_12 = ipv4.Assign (ndc_hub_12)
    ipv4.SetBase (ns3.Ipv4Address("10.0.41.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_hub_13 = ipv4.Assign (ndc_hub_13)
    ipv4.SetBase (ns3.Ipv4Address("10.0.42.0"), ns3.Ipv4Mask("255.255.255.0"))
    iface_ndc_p2p_4 = ipv4.Assign (ndc_p2p_4)

    # Tap Bridge.
    tapBridge_tap_0 = ns3.TapBridgeHelper(iface_ndc_tap_0.GetAddress(1))
    tapBridge_tap_0.SetAttribute("Mode", ns3.StringValue (mode_tap_0))
    tapBridge_tap_0.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_0))
    tapBridge_tap_0.Install(tap_0.Get(0), ndc_tap_0.Get(0))
    tapBridge_tap_1 = ns3.TapBridgeHelper(iface_ndc_tap_1.GetAddress(1))
    tapBridge_tap_1.SetAttribute("Mode", ns3.StringValue (mode_tap_1))
    tapBridge_tap_1.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_1))
    tapBridge_tap_1.Install(tap_1.Get(0), ndc_tap_1.Get(0))
    tapBridge_tap_2 = ns3.TapBridgeHelper(iface_ndc_tap_2.GetAddress(1))
    tapBridge_tap_2.SetAttribute("Mode", ns3.StringValue (mode_tap_2))
    tapBridge_tap_2.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_2))
    tapBridge_tap_2.Install(tap_2.Get(0), ndc_tap_2.Get(0))
    tapBridge_tap_0 = ns3.TapBridgeHelper(iface_ndc_tap_3.GetAddress(1))
    tapBridge_tap_0.SetAttribute("Mode", ns3.StringValue (mode_tap_0))
    tapBridge_tap_0.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_0))
    tapBridge_tap_0.Install(tap_0.Get(0), ndc_tap_3.Get(0))
    tapBridge_tap_1 = ns3.TapBridgeHelper(iface_ndc_tap_4.GetAddress(1))
    tapBridge_tap_1.SetAttribute("Mode", ns3.StringValue (mode_tap_1))
    tapBridge_tap_1.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_1))
    tapBridge_tap_1.Install(tap_1.Get(0), ndc_tap_4.Get(0))
    tapBridge_tap_2 = ns3.TapBridgeHelper(iface_ndc_tap_5.GetAddress(1))
    tapBridge_tap_2.SetAttribute("Mode", ns3.StringValue (mode_tap_2))
    tapBridge_tap_2.SetAttribute("DeviceName", ns3.StringValue (tapName_tap_2))
    tapBridge_tap_2.Install(tap_2.Get(0), ndc_tap_5.Get(0))

    # Generate Route.
    ns3.Ipv4GlobalRoutingHelper.PopulateRoutingTables ()

    # Generate Application.

    # Simulation.
    # Pcap output.
    # Stop the simulation after x seconds.
    stopTime = 1
    ns3.Simulator.Stop (ns3.Seconds(stopTime))
    # Start and clean simulation.
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()