Пример #1
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()
Пример #2
0
def create_network(report):
    """Create a network Struct from a RadioMobile parsed text report."""
    nodes = {}
    for name, attrs in report.units.iteritems():
        node = Struct("Node", name=name, ns3_node=ns3.Node(), devices={})
        nodes[name] = node
    ns3node_to_node = dict(
        (node.ns3_node.GetId(), node) for node in nodes.values())

    # Internet stack
    stack = ns3.InternetStackHelper()
    for name, node in nodes.iteritems():
        stack.Install(node.ns3_node)

    for net_index, (name, network) in enumerate(report.nets.iteritems()):
        node_members = radiomobile.get_units_for_network(network, "Node")
        if not node_members:
            continue
        node_member = node_members[0]
        terminal_members = radiomobile.get_units_for_network(
            network, "Terminal")
        ap_node = nodes[node_member].ns3_node
        sta_nodes = ns3.NodeContainer()
        debug("Add network '%s'\n  ap_node = '%s'\n  sta_nodes = %s" %
              (name, node_member, terminal_members))
        for name in terminal_members:
            sta_nodes.Add(nodes[name].ns3_node)

        # Wifi channel
        channel = ns3.YansWifiChannelHelper.Default()
        phy = ns3.YansWifiPhyHelper.Default()
        phy.SetChannel(channel.Create())

        # STA devices
        wifi = ns3.WifiHelper.Default()
        wifi.SetRemoteStationManager("ns3::AarfWifiManager")
        mac = ns3.NqosWifiMacHelper.Default()
        ssid = ns3.Ssid("ns-3-ssid")
        mac.SetType("ns3::NqstaWifiMac", "Ssid", ns3.SsidValue(ssid),
                    "ActiveProbing", ns3.BooleanValue(False))
        sta_devices = wifi.Install(phy, mac, sta_nodes)
        add_devices_to_node(network, ns3node_to_node, sta_nodes, sta_devices,
                            phy)

        # AP devices
        mac = ns3.NqosWifiMacHelper.Default()
        mac.SetType("ns3::NqapWifiMac", "Ssid",
                    ns3.SsidValue(ssid), "BeaconGeneration",
                    ns3.BooleanValue(True), "BeaconInterval",
                    ns3.TimeValue(ns3.Seconds(2.5)))
        ap_devices = wifi.Install(phy, mac, ap_node)
        add_devices_to_node(network, ns3node_to_node, ap_node, ap_devices, phy)

        # Set IP addresses
        address = ns3.Ipv4AddressHelper()
        netaddr = "10.1.%d.0" % net_index
        address.SetBase(ns3.Ipv4Address(netaddr),
                        ns3.Ipv4Mask("255.255.255.0"))
        ap_interfaces = address.Assign(ap_devices)
        sta_interfaces = address.Assign(sta_devices)
        add_interfaces_to_device(network, ns3node_to_node, ap_node,
                                 ap_interfaces)
        add_interfaces_to_device(network, ns3node_to_node, sta_nodes,
                                 sta_interfaces)

        # Mobility
        mobility = ns3.MobilityHelper()
        mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel")
        mobility.Install(ap_node)

        mobility = ns3.MobilityHelper()
        mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel")
        mobility.Install(sta_nodes)

    ns3.Ipv4GlobalRoutingHelper.PopulateRoutingTables()
    return Struct("Network", nodes=nodes)
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
Пример #4
0
def main(argv):
    ns3.Packet.EnablePrinting()

    # enable rts cts all the time.
    ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",
                          ns3.StringValue("0"))
    # disable fragmentation
    ns3.Config.SetDefault(
        "ns3::WifiRemoteStationManager::FragmentationThreshold",
        ns3.StringValue("2200"))

    wifi = ns3.WifiHelper.Default()
    mobility = ns3.MobilityHelper()
    stas = ns3.NodeContainer()
    ap = ns3.NodeContainer()
    #NetDeviceContainer staDevs;
    packetSocket = ns3.PacketSocketHelper()

    stas.Create(2)
    ap.Create(1)

    # give packet socket powers to nodes.
    packetSocket.Install(stas)
    packetSocket.Install(ap)

    wifiPhy = ns3.YansWifiPhyHelper.Default()
    wifiChannel = ns3.YansWifiChannelHelper.Default()
    wifiPhy.SetChannel(wifiChannel.Create())

    ssid = ns3.Ssid("wifi-default")
    wifi.SetRemoteStationManager("ns3::ArfWifiManager")
    wifiMac = ns3.NqosWifiMacHelper.Default()

    # setup stas.
    wifiMac.SetType("ns3::NqstaWifiMac", "Ssid", ns3.SsidValue(ssid),
                    "ActiveProbing", ns3.BooleanValue(False))
    staDevs = wifi.Install(wifiPhy, wifiMac, stas)
    # setup ap.
    wifiMac.SetType("ns3::NqapWifiMac", "Ssid",
                    ns3.SsidValue(ssid), "BeaconGeneration",
                    ns3.BooleanValue(True), "BeaconInterval",
                    ns3.TimeValue(ns3.Seconds(2.5)))
    wifi.Install(wifiPhy, wifiMac, ap)

    # mobility.
    mobility.Install(stas)
    mobility.Install(ap)

    ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, ap.Get(0))

    socket = ns3.PacketSocketAddress()
    socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
    socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
    socket.SetProtocol(1)

    onoff = ns3.OnOffHelper("ns3::PacketSocketFactory", ns3.Address(socket))
    onoff.SetAttribute("OnTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(42)))
    onoff.SetAttribute("OffTime",
                       ns3.RandomVariableValue(ns3.ConstantVariable(0)))

    apps = onoff.Install(ns3.NodeContainer(stas.Get(0)))
    apps.Start(ns3.Seconds(0.5))
    apps.Stop(ns3.Seconds(43.0))

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

    #   Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace));
    #   Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace));
    #   Config::Connect("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback(&PhyRxOkTrace));
    #   Config::Connect("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback(&PhyRxErrorTrace));
    #   Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace));
    #   Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace));

    ns3.Simulator.Run()
    ns3.Simulator.Destroy()

    return 0
Пример #5
0
def wifi_network(network_info, net_index, short_net_name, ns3_mode, nodes,
                 get_node_from_ns3node, node_member, terminal_members):
    """Configure a WiFi network (1 AP - n STAs)."""
    max_distance = get_max_distance_in_network(nodes, node_member,
                                               terminal_members)

    logging.info("Network '%s': AP-node = '%s', STA-nodes = %s" %
                 (short_net_name, node_member, terminal_members))
    logging.info("Network '%s': ns-3 mode: %s, max_distance: %d meters" %
                 (short_net_name, ns3_mode, max_distance))

    # Wifi channel
    channel = ns3.YansWifiChannelHelper.Default()
    phy = ns3.YansWifiPhyHelper.Default()
    channel = ns3.YansWifiChannelHelper.Default()
    channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel")
    channel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss",
                               ns3.DoubleValue(0))
    phy.SetChannel(channel.Create())

    address_helper = ns3.Ipv4AddressHelper()
    netaddr = "10.1.%d.0" % net_index
    address_helper.SetBase(ns3.Ipv4Address(netaddr),
                           ns3.Ipv4Mask("255.255.255.0"))

    def configure_node(wifi_helper, name):
        ns3_node = nodes[name].ns3_node
        sta_device = wifi_helper.Install(phy, mac, ns3_node)
        node = get_node_from_ns3node(ns3_node)
        add_device_to_node(node,
                           short_net_name,
                           network_info,
                           sta_device.Get(0),
                           helper=wifi_helper,
                           phy_helper=phy)
        set_wifi_timeouts(sta_device.Get(0), max_distance)
        sta_interface = address_helper.Assign(sta_device)
        address = sta_interface.GetAddress(0)
        add_interface_to_device_node(node, short_net_name, network_info,
                                     address)

    # STA devices & and interfaces
    wifi_helper = ns3.WifiHelper.Default()
    wifi_helper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                        "DataMode", ns3.StringValue(ns3_mode),
                                        "RtsCtsThreshold",
                                        ns3.StringValue("2200"))

    mac = ns3.NqosWifiMacHelper.Default()
    ssid = ns3.Ssid("%s%d" % (short_net_name[:5], net_index))
    mac.SetType("ns3::QstaWifiMac", "Ssid", ns3.SsidValue(ssid),
                "ActiveProbing", ns3.BooleanValue(False))

    for terminal_member in terminal_members:
        configure_node(wifi_helper, terminal_member)

    # AP devices & interfaces
    wifi_helper = ns3.WifiHelper.Default()
    mac = ns3.NqosWifiMacHelper.Default()
    mac.SetType("ns3::QapWifiMac", "Ssid", ns3.SsidValue(ssid),
                "BeaconGeneration", ns3.BooleanValue(True), "BeaconInterval",
                ns3.TimeValue(ns3.Seconds(2.5)))
    configure_node(wifi_helper, node_member)
Пример #6
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()