def udp_echo_app(network, client_node, server_node, server_device, start, stop, packets=1, interval=1.0, port=9, packet_size=1024): """Set up a UDP echo client/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 echoServer = ns3.UdpEchoServerHelper(port) serverApps = echoServer.Install(server.ns3_node) serverApps.Start(ns3.Seconds(start)) serverApps.Stop(ns3.Seconds(stop)) client = network.nodes[client_node] echoClient = ns3.UdpEchoClientHelper(server_address, 9) echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(packets)) echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(interval))) echoClient.SetAttribute("PacketSize", ns3.UintegerValue(packet_size)) clientApps = echoClient.Install(client.ns3_node) clientApps.Start(ns3.Seconds(start)) clientApps.Stop(ns3.Seconds(stop))
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))
def main(dummy_argv): model = MyModel() v = ns.UniformVariable(10, 20) ns.Simulator.Schedule(ns.Seconds(10.0), ExampleFunction, model) ns.Simulator.Schedule(ns.Seconds(v.GetValue()), RandomFunction, model) id = ns.Simulator.Schedule(ns.Seconds(30.0), CancelledEvent) ns.Simulator.Cancel(id) ns.Simulator.Run() ns.Simulator.Destroy()
def enable_monitor(network, interval=None): """Enable FlowMonitor and return a structure with state.""" def _ip2info_pairs(): for node_name, node_attrs in network.nodes.iteritems(): for device_name, device_attrs in node_attrs.devices.iteritems(): info = dict(device_name=device_name, node_name=node_name) yield str(device_attrs.interfaces[0].address), info def _monitor_step(flow_stats_steps): """Called every 'interval' seconds. Save flow-stats for later processing.""" simtime = ns3.Simulator.Now().GetSeconds() for flow_id, flow_stats in monitor.GetFlowStats(): flow_stats_steps.setdefault(flow_id, []).append( (simtime, flow_stats)) ns3.Simulator.Schedule(ns3.Seconds(interval), _monitor_step, flow_stats_steps) flowmon_helper = ns3.FlowMonitorHelper() monitor = flowmon_helper.InstallAll() ip2info = dict(_ip2info_pairs()) flow_stats_steps = {} if interval is not None: ns3.Simulator.Schedule(ns3.Seconds(interval), _monitor_step, flow_stats_steps) monitor_info = dict(helper=flowmon_helper, monitor=monitor, ip2info=ip2info, flow_stats_steps=flow_stats_steps) return monitor_info
def AdvancePosition(node): pos = GetPosition(node) pos.x += 5.0 if pos.x >= 210.0: return SetPosition(node, pos) ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, node)
def after(self, t, method, *args, **kwargs): """schedue a even after t seconds""" def void_return_method(*args, **kwargs): method(*args, **kwargs) return ns3.Simulator.Schedule(ns3.Simulator.Now() + ns3.Seconds(t), void_return_method, *args, **kwargs)
def _monitor_step(flow_stats_steps): """Called every 'interval' seconds. Save flow-stats for later processing.""" simtime = ns3.Simulator.Now().GetSeconds() for flow_id, flow_stats in monitor.GetFlowStats(): flow_stats_steps.setdefault(flow_id, []).append( (simtime, flow_stats)) ns3.Simulator.Schedule(ns3.Seconds(interval), _monitor_step, flow_stats_steps)
def set_wifi_timeouts(device, max_distance): """ Set MacPropagationDelay and timeouts (AckTimeout, SlotTimeout, CtsTimeout) in a Wifi device suitable for a given distance. """ max_propagation_delay = max_distance / 3e8 mac = device.GetMac() mac.SetMaxPropagationDelay(ns3.Seconds(max_propagation_delay)) ack_timeout = ns3.Seconds(mac.GetEifsNoDifs().GetSeconds() + mac.GetSlot().GetSeconds() + max_propagation_delay * 2) ack_timeout = ns3.Time(ns3.NanoSeconds(int(ack_timeout.GetNanoSeconds()))) mac.SetAckTimeout(ack_timeout) mac.SetCtsTimeout(ack_timeout) slot_time = ns3.NanoSeconds(mac.GetSlot().GetNanoSeconds() + mac.GetMaxPropagationDelay().GetNanoSeconds() * 2) mac.SetSlot(slot_time)
def testSchedule(self): def callback(args): self._args_received = args self._cb_time = ns3.Simulator.Now() ns3.Simulator.Destroy() self._args_received = None self._cb_time = None ns3.Simulator.Schedule(ns3.Seconds(123), callback, "args") ns3.Simulator.Run() self.assertEqual(self._args_received, "args") self.assertEqual(self._cb_time.GetSeconds(), 123.0)
def main(argv): # # We are interacting with the outside, real, world. This means we have to # interact in real-time and therefore we have to use the real-time simulator # and take the time to calculate checksums. # ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl")) ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true")) # # Create two ghost nodes. The first will represent the virtual machine host # on the left side of the network; and the second will represent the VM on # the right side. # nodes = ns3.NodeContainer() nodes.Create(2) # # Use a CsmaHelper to get a CSMA channel created, and the needed net # devices installed on both of the nodes. The data rate and delay for the # channel can be set through the command-line parser. # csma = ns3.CsmaHelper() devices = csma.Install(nodes) # # Use the TapBridgeHelper to connect to the pre-configured tap devices for # the left side. We go with "UseLocal" mode since the wifi devices do not # support promiscuous mode (because of their natures0. This is a special # case mode that allows us to extend a linux bridge into ns-3 IFF we will # only see traffic from one other device on that bridge. That is the case # for this configuration. # tapBridge = ns3.TapBridgeHelper() tapBridge.SetAttribute("Mode", ns3.StringValue("UseLocal")) tapBridge.SetAttribute("DeviceName", ns3.StringValue("tap-left")) tapBridge.Install(nodes.Get(0), devices.Get(0)) # # Connect the right side tap to the right side wifi device on the right-side # ghost node. # tapBridge.SetAttribute("DeviceName", ns3.StringValue("tap-right")) tapBridge.Install(nodes.Get(1), devices.Get(1)) # # Run the simulation for ten minutes to give the user time to play around # ns3.Simulator.Stop(ns3.Seconds(600)) ns3.Simulator.Run(signal_check_frequency=-1) ns3.Simulator.Destroy() return 0
def run_simulation(network): #print "distance between CCATCCA and URCOS", distance # Applications server = network.nodes["CCATCCA"] server_address = server.devices["Uuario Final PCMCIA"].interfaces[ 0].address echoServer = ns3.UdpEchoServerHelper(9) serverApps = echoServer.Install(server.ns3_node) serverApps.Start(ns3.Seconds(1.0)) serverApps.Stop(ns3.Seconds(10.0)) client = network.nodes["URCOS"] echoClient = ns3.UdpEchoClientHelper(server_address, 9) echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1)) echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0))) echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024)) clientApps = echoClient.Install(client.ns3_node) clientApps.Start(ns3.Seconds(2.0)) clientApps.Stop(ns3.Seconds(10.0)) # Tracing josjo1 = network.nodes["JOSJOJAHUARINA 1"] device = josjo1.devices['Josjo 1 Sectorial PC'].ns3_device phy = josjo1.devices['Josjo 1 Sectorial PC'].phy_helper phy.EnablePcap("udp_echo", device) # Run simulation ns3.Simulator.Stop(ns3.Seconds(10.0)) ns3.Simulator.Run() ns3.Simulator.Destroy()
def run_simulation(network, stop=None): """Run simulation until 'stop' time.""" # In the current implementation of ns-3, if you try to use a WiMax # link where no service flow was configure, it will simply throw a # Segmentation Fault. So we have to add default flows (only # unconfigured ss device). add_default_wimax_service_flows(network) if stop: logging.debug("Set simulation duration: %0.2f seconds" % stop) ns3.Simulator.Stop(ns3.Seconds(stop)) logging.debug("Run simulation") ns3.Simulator.Run() logging.debug("Simulation finished") ns3.Simulator.Destroy()
def Start(self): ns.Simulator.Schedule(ns.Seconds(10.0), self.HandleEvent, ns.Simulator.Now().GetSeconds())
olsr = ns3.OlsrHelper() #Add the IPv4 protocol stack to the nodes in our container internet=ns3.InternetStackHelper() internet.SetRoutingHelper (olsr) internet.Install (nodes) ipAddrss= ns3.Ipv4AddressHelper() ipAddrss.SetBase( ns3.Ipv4Address("192.168.0.0"), ns3.Ipv4Mask("255.255.255.0")); ipContainer = ipAddrss.Assign(devices); mobility = ns3.MobilityHelper() positionAlloc = ns3.ListPositionAllocator() positionAlloc.Add(ns3.Vector (100,100,0.0)) positionAlloc.Add(ns3.Vector (100,200,0.0)) mobility.SetPositionAllocator(positionAlloc) mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install(nodes) pingHelper = ns3.V4PingHelper(ipContainer.GetAddress(0)) pingHelper.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0))) apps = pingHelper.Install(nodes.Get(0)) apps.Start(ns.core.Seconds(1.0)) apps.Stop(ns.core.Seconds(10.0)) ns.core.Simulator.Run() ns.core.Simulator.Destroy()
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): # # 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()
def testTimeNumericOperations(self): self.assertEqual(ns3.Seconds(10) + ns3.Seconds(5), ns3.Seconds(15)) self.assertEqual(ns3.Seconds(10) - ns3.Seconds(5), ns3.Seconds(5)) v1 = ns3.Scalar(5) * ns3.Seconds(10) self.assertEqual(v1, ns3.Seconds(50))
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
def main(argv): # # We are interacting with the outside, real, world. This means we have to # interact in real-time and therefore we have to use the real-time simulator # and take the time to calculate checksums. # ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl")) ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true")) # # Create two ghost nodes. The first will represent the virtual machine host # on the left side of the network; and the second will represent the VM on # the right side. # nodes = ns3.NodeContainer() nodes.Create(2) # # We're going to use 802.11 A so set up a wifi helper to reflect that. # wifi = ns3.WifiHelper.Default() wifi.SetStandard(ns3.WIFI_PHY_STANDARD_80211a) wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", ns3.StringValue("wifia-54mbs")) # # No reason for pesky access points, so we'll use an ad-hoc network. # wifiMac = ns3.NqosWifiMacHelper.Default() wifiMac.SetType("ns3::AdhocWifiMac") # # Configure the physcial layer. # wifiChannel = ns3.YansWifiChannelHelper.Default() wifiPhy = ns3.YansWifiPhyHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) # # Install the wireless devices onto our ghost nodes. # devices = wifi.Install(wifiPhy, wifiMac, nodes) # # We need location information since we are talking about wifi, so add a # constant position to the ghost nodes. # mobility = ns3.MobilityHelper() positionAlloc = ns3.ListPositionAllocator() positionAlloc.Add(ns3.Vector(0.0, 0.0, 0.0)) positionAlloc.Add(ns3.Vector(5.0, 0.0, 0.0)) mobility.SetPositionAllocator(positionAlloc) mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel") mobility.Install(nodes) # # Use the TapBridgeHelper to connect to the pre-configured tap devices for # the left side. We go with "UseLocal" mode since the wifi devices do not # support promiscuous mode (because of their natures0. This is a special # case mode that allows us to extend a linux bridge into ns-3 IFF we will # only see traffic from one other device on that bridge. That is the case # for this configuration. # tapBridge = ns3.TapBridgeHelper() tapBridge.SetAttribute("Mode", ns3.StringValue("UseLocal")) tapBridge.SetAttribute("DeviceName", ns3.StringValue("tap-left")) tapBridge.Install(nodes.Get(0), devices.Get(0)) # # Connect the right side tap to the right side wifi device on the right-side # ghost node. # tapBridge.SetAttribute("DeviceName", ns3.StringValue("tap-right")) tapBridge.Install(nodes.Get(1), devices.Get(1)) # # Run the simulation for ten minutes to give the user time to play around # ns3.Simulator.Stop(ns3.Seconds(600)) ns3.Simulator.Run(signal_check_frequency=-1) ns3.Simulator.Destroy() return 0
pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps")) pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms")) devices = pointToPoint.Install(nodes) stack = ns3.InternetStackHelper() stack.Install(nodes) address = ns3.Ipv4AddressHelper() address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0")) interfaces = address.Assign(devices) echoServer = ns3.UdpEchoServerHelper(9) serverApps = echoServer.Install(nodes.Get(1)) serverApps.Start(ns3.Seconds(1.0)) serverApps.Stop(ns3.Seconds(10.0)) echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9) echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1)) echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0))) echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024)) clientApps = echoClient.Install(nodes.Get(0)) clientApps.Start(ns3.Seconds(2.0)) clientApps.Stop(ns3.Seconds(10.0)) ns3.Simulator.Run() ns3.Simulator.Destroy()
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
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel") mobility.Install(nodes) port = 5000 #On off Application onoff = ns3.OnOffHelper( "ns3::UdpSocketFactory", ns3.Address(ns3.InetSocketAddress(ipcontainer.GetAddress(1), port))) onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(42))) onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0))) #onoff.SetAttribute ("Remote", ns3.AddressValue (ns3.InetSocketAddress(ipcontainer.GetAddress(1),port))); apps = onoff.Install(nodes.Get(0)) apps.Start(ns3.Seconds(0.1)) apps.Stop(ns3.Seconds(90.0)) sink = ns3.PacketSinkHelper( "ns3::UdpSocketFactory", ns3.InetSocketAddress(ipcontainer.GetAddress(1), port)) appsink = sink.Install(nodes.Get(1)) appsink.Start(ns3.Seconds(0.5)) appsink.Stop(ns3.Seconds(90.0)) ns3.Simulator.Stop(ns3.Seconds(100)) #ns3.Simulator.Run() visualizer.start() ns3.Simulator.Destroy()
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()
def main(dummy_argv): model = MyModel() ns.Simulator.Schedule(ns.Seconds(10.0), random_function, model) ns.Simulator.Run() ns.Simulator.Destroy()
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()
def testTimeComparison(self): self.assert_(ns3.Seconds(123) == ns3.Seconds(123)) self.assert_(ns3.Seconds(123) >= ns3.Seconds(123)) self.assert_(ns3.Seconds(123) <= ns3.Seconds(123)) self.assert_(ns3.Seconds(124) > ns3.Seconds(123)) self.assert_(ns3.Seconds(123) < ns3.Seconds(124))
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.")
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)