From 4a0091ba6c5f07947e35ae8f8e892c28df66abe8 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 15 May 2024 00:01:33 -0300 Subject: [PATCH] bindings: Remove injected namespaces --- bindings/python/ns__init__.py | 11 +- examples/realtime/realtime-udp-echo.py | 50 ++++--- examples/routing/simple-routing-ping6.py | 2 +- examples/tutorial/first.py | 40 +++--- examples/tutorial/second.py | 54 ++++---- examples/tutorial/third.py | 92 +++++++------ examples/wireless/mixed-wired-wireless.py | 124 +++++++++--------- examples/wireless/wifi-ap.py | 48 +++---- src/bridge/examples/csma-bridge.py | 68 +++++----- src/core/examples/sample-simulator.py | 18 +-- .../generic-battery-discharge-example.py | 30 ++--- .../examples/wifi-olsr-flowmon.py | 54 ++++---- .../examples/tap-csma-virtual-machine.py | 26 ++-- .../examples/tap-wifi-virtual-machine.py | 44 +++---- .../visualizer/plugins/show_last_packets.py | 22 ++-- .../plugins/wifi_intrastructure_link.py | 10 +- utils/python-unit-tests.py | 72 +++++----- 17 files changed, 365 insertions(+), 400 deletions(-) diff --git a/bindings/python/ns__init__.py b/bindings/python/ns__init__.py index 6ac5df90c..70ef3aecb 100644 --- a/bindings/python/ns__init__.py +++ b/bindings/python/ns__init__.py @@ -86,7 +86,9 @@ def _search_libraries() -> dict: libraries = [] for search_path in library_search_paths: if os.path.exists(search_path): - libraries += glob.glob("%s/**/*.%s*" % (search_path, LIBRARY_EXTENSION), recursive=True) + libraries += glob.glob( + "%s/**/*.%s*" % (search_path, LIBRARY_EXTENSION), recursive=False + ) # Search system library directories (too slow for recursive search) for search_path in SYSTEM_LIBRARY_DIRECTORIES: @@ -513,13 +515,6 @@ def load_modules(): # We expose cppyy to consumers of this module as ns.cppyy setattr(cppyy.gbl.ns3, "cppyy", cppyy) - # To maintain compatibility with pybindgen scripts, - # we set an attribute per module that just redirects to the upper object - for module in modules: - moduleNamespace = module.replace("-", "_") - if moduleNamespace not in dir(cppyy.gbl.ns3): - setattr(cppyy.gbl.ns3, moduleNamespace, cppyy.gbl.ns3) - # Set up a few tricks cppyy.cppdef( """ diff --git a/examples/realtime/realtime-udp-echo.py b/examples/realtime/realtime-udp-echo.py index 494d616ed..17fd2088a 100644 --- a/examples/realtime/realtime-udp-echo.py +++ b/examples/realtime/realtime-udp-echo.py @@ -38,43 +38,41 @@ def main(argv): # Allow the user to override any of the defaults and the above Bind() at # run-time, via command-line arguments # - cmd = ns.core.CommandLine() + cmd = ns.CommandLine() cmd.Parse(argv) # # But since this is a realtime script, don't allow the user to mess with # that. # - ns.core.GlobalValue.Bind( - "SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl") - ) + ns.GlobalValue.Bind("SimulatorImplementationType", ns.StringValue("ns3::RealtimeSimulatorImpl")) # # Explicitly create the nodes required by the topology (shown above). # print("Create nodes.") - n = ns.network.NodeContainer() + n = ns.NodeContainer() n.Create(4) - internet = ns.internet.InternetStackHelper() + internet = ns.InternetStackHelper() internet.Install(n) # # Explicitly create the channels required by the topology (shown above). # print("Create channels.") - csma = ns.csma.CsmaHelper() - csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))) - csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))) - csma.SetDeviceAttribute("Mtu", ns.core.UintegerValue(1400)) + csma = ns.CsmaHelper() + csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000))) + csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2))) + csma.SetDeviceAttribute("Mtu", ns.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 = ns.internet.Ipv4AddressHelper() - ipv4.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipv4 = ns.Ipv4AddressHelper() + ipv4.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) i = ipv4.Assign(d) print("Create Applications.") @@ -83,10 +81,10 @@ def main(argv): # Create a UdpEchoServer application on node one. # port = 9 # well-known echo port number - server = ns.applications.UdpEchoServerHelper(port) + server = ns.UdpEchoServerHelper(port) apps = server.Install(n.Get(1)) - apps.Start(ns.core.Seconds(1.0)) - apps.Stop(ns.core.Seconds(10.0)) + apps.Start(ns.Seconds(1.0)) + apps.Stop(ns.Seconds(10.0)) # # Create a UdpEchoClient application to send UDP datagrams from node zero to @@ -94,16 +92,16 @@ def main(argv): # packetSize = 1024 maxPacketCount = 500 - interPacketInterval = ns.core.Seconds(0.01) - client = ns.applications.UdpEchoClientHelper(i.GetAddress(1).ConvertTo(), port) - client.SetAttribute("MaxPackets", ns.core.UintegerValue(maxPacketCount)) - client.SetAttribute("Interval", ns.core.TimeValue(interPacketInterval)) - client.SetAttribute("PacketSize", ns.core.UintegerValue(packetSize)) + interPacketInterval = ns.Seconds(0.01) + client = ns.UdpEchoClientHelper(i.GetAddress(1).ConvertTo(), port) + client.SetAttribute("MaxPackets", ns.UintegerValue(maxPacketCount)) + client.SetAttribute("Interval", ns.TimeValue(interPacketInterval)) + client.SetAttribute("PacketSize", ns.UintegerValue(packetSize)) apps = client.Install(n.Get(0)) - apps.Start(ns.core.Seconds(2.0)) - apps.Stop(ns.core.Seconds(10.0)) + apps.Start(ns.Seconds(2.0)) + apps.Stop(ns.Seconds(10.0)) - ascii = ns.network.AsciiTraceHelper() + ascii = ns.AsciiTraceHelper() csma.EnableAsciiAll(ascii.CreateFileStream("realtime-udp-echo.tr")) csma.EnablePcapAll("realtime-udp-echo", False) @@ -111,9 +109,9 @@ def main(argv): # Now, do the actual simulation. # print("Run Simulation.") - ns.core.Simulator.Stop(ns.Seconds(10)) - ns.core.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Stop(ns.Seconds(10)) + ns.Simulator.Run() + ns.Simulator.Destroy() print("Done.") diff --git a/examples/routing/simple-routing-ping6.py b/examples/routing/simple-routing-ping6.py index 501cfb13e..b8a0f0b4e 100644 --- a/examples/routing/simple-routing-ping6.py +++ b/examples/routing/simple-routing-ping6.py @@ -58,7 +58,7 @@ def main(argv): internetv6.Install(all) # Create channels - csma = ns.csma.CsmaHelper() + csma = ns.CsmaHelper() csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000))) csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2))) d1 = csma.Install(net1) diff --git a/examples/tutorial/first.py b/examples/tutorial/first.py index 42311ad2f..8a10ae7e3 100644 --- a/examples/tutorial/first.py +++ b/examples/tutorial/first.py @@ -29,41 +29,41 @@ except ModuleNotFoundError: # // point-to-point # // -ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) -ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) +ns.LogComponentEnable("UdpEchoClientApplication", ns.LOG_LEVEL_INFO) +ns.LogComponentEnable("UdpEchoServerApplication", ns.LOG_LEVEL_INFO) -nodes = ns.network.NodeContainer() +nodes = ns.NodeContainer() nodes.Create(2) -pointToPoint = ns.point_to_point.PointToPointHelper() -pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) -pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) +pointToPoint = ns.PointToPointHelper() +pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps")) +pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms")) devices = pointToPoint.Install(nodes) -stack = ns.internet.InternetStackHelper() +stack = ns.InternetStackHelper() stack.Install(nodes) -address = ns.internet.Ipv4AddressHelper() -address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) +address = ns.Ipv4AddressHelper() +address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) interfaces = address.Assign(devices) -echoServer = ns.applications.UdpEchoServerHelper(9) +echoServer = ns.UdpEchoServerHelper(9) serverApps = echoServer.Install(nodes.Get(1)) -serverApps.Start(ns.core.Seconds(1.0)) -serverApps.Stop(ns.core.Seconds(10.0)) +serverApps.Start(ns.Seconds(1.0)) +serverApps.Stop(ns.Seconds(10.0)) address = interfaces.GetAddress(1).ConvertTo() -echoClient = ns.applications.UdpEchoClientHelper(address, 9) -echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1)) -echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0))) -echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024)) +echoClient = ns.UdpEchoClientHelper(address, 9) +echoClient.SetAttribute("MaxPackets", ns.UintegerValue(1)) +echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.0))) +echoClient.SetAttribute("PacketSize", ns.UintegerValue(1024)) clientApps = echoClient.Install(nodes.Get(0)) -clientApps.Start(ns.core.Seconds(2.0)) -clientApps.Stop(ns.core.Seconds(10.0)) +clientApps.Start(ns.Seconds(2.0)) +clientApps.Stop(ns.Seconds(10.0)) -ns.core.Simulator.Run() -ns.core.Simulator.Destroy() +ns.Simulator.Run() +ns.Simulator.Destroy() diff --git a/examples/tutorial/second.py b/examples/tutorial/second.py index 0d01b9367..e5621fe28 100644 --- a/examples/tutorial/second.py +++ b/examples/tutorial/second.py @@ -43,61 +43,59 @@ cmd.AddValue("verbose", "Tell echo applications to log if true", verbose) cmd.Parse(sys.argv) if verbose.value: - ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) - ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) + ns.LogComponentEnable("UdpEchoClientApplication", ns.LOG_LEVEL_INFO) + ns.LogComponentEnable("UdpEchoServerApplication", ns.LOG_LEVEL_INFO) nCsma.value = 1 if nCsma.value == 0 else nCsma.value -p2pNodes = ns.network.NodeContainer() +p2pNodes = ns.NodeContainer() p2pNodes.Create(2) -csmaNodes = ns.network.NodeContainer() +csmaNodes = ns.NodeContainer() csmaNodes.Add(p2pNodes.Get(1)) csmaNodes.Create(nCsma.value) -pointToPoint = ns.point_to_point.PointToPointHelper() -pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) -pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) +pointToPoint = ns.PointToPointHelper() +pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps")) +pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms")) p2pDevices = pointToPoint.Install(p2pNodes) -csma = ns.csma.CsmaHelper() -csma.SetChannelAttribute("DataRate", ns.core.StringValue("100Mbps")) -csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.NanoSeconds(6560))) +csma = ns.CsmaHelper() +csma.SetChannelAttribute("DataRate", ns.StringValue("100Mbps")) +csma.SetChannelAttribute("Delay", ns.TimeValue(ns.NanoSeconds(6560))) csmaDevices = csma.Install(csmaNodes) -stack = ns.internet.InternetStackHelper() +stack = ns.InternetStackHelper() stack.Install(p2pNodes.Get(0)) stack.Install(csmaNodes) -address = ns.internet.Ipv4AddressHelper() -address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) +address = ns.Ipv4AddressHelper() +address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) p2pInterfaces = address.Assign(p2pDevices) -address.SetBase(ns.network.Ipv4Address("10.1.2.0"), ns.network.Ipv4Mask("255.255.255.0")) +address.SetBase(ns.Ipv4Address("10.1.2.0"), ns.Ipv4Mask("255.255.255.0")) csmaInterfaces = address.Assign(csmaDevices) -echoServer = ns.applications.UdpEchoServerHelper(9) +echoServer = ns.UdpEchoServerHelper(9) serverApps = echoServer.Install(csmaNodes.Get(nCsma.value)) -serverApps.Start(ns.core.Seconds(1.0)) -serverApps.Stop(ns.core.Seconds(10.0)) +serverApps.Start(ns.Seconds(1.0)) +serverApps.Stop(ns.Seconds(10.0)) -echoClient = ns.applications.UdpEchoClientHelper( - csmaInterfaces.GetAddress(nCsma.value).ConvertTo(), 9 -) -echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1)) -echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0))) -echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024)) +echoClient = ns.UdpEchoClientHelper(csmaInterfaces.GetAddress(nCsma.value).ConvertTo(), 9) +echoClient.SetAttribute("MaxPackets", ns.UintegerValue(1)) +echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.0))) +echoClient.SetAttribute("PacketSize", ns.UintegerValue(1024)) clientApps = echoClient.Install(p2pNodes.Get(0)) -clientApps.Start(ns.core.Seconds(2.0)) -clientApps.Stop(ns.core.Seconds(10.0)) +clientApps.Start(ns.Seconds(2.0)) +clientApps.Stop(ns.Seconds(10.0)) -ns.internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables() +ns.Ipv4GlobalRoutingHelper.PopulateRoutingTables() pointToPoint.EnablePcapAll("second") csma.EnablePcap("second", csmaDevices.Get(1), True) -ns.core.Simulator.Run() -ns.core.Simulator.Destroy() +ns.Simulator.Run() +ns.Simulator.Destroy() diff --git a/examples/tutorial/third.py b/examples/tutorial/third.py index fdc6b2133..0bd70e068 100644 --- a/examples/tutorial/third.py +++ b/examples/tutorial/third.py @@ -59,112 +59,108 @@ if nWifi.value > 18: sys.exit(1) if verbose.value: - ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) - ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) + ns.LogComponentEnable("UdpEchoClientApplication", ns.LOG_LEVEL_INFO) + ns.LogComponentEnable("UdpEchoServerApplication", ns.LOG_LEVEL_INFO) -p2pNodes = ns.network.NodeContainer() +p2pNodes = ns.NodeContainer() p2pNodes.Create(2) -pointToPoint = ns.point_to_point.PointToPointHelper() -pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) -pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) +pointToPoint = ns.PointToPointHelper() +pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps")) +pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms")) p2pDevices = pointToPoint.Install(p2pNodes) -csmaNodes = ns.network.NodeContainer() +csmaNodes = ns.NodeContainer() csmaNodes.Add(p2pNodes.Get(1)) csmaNodes.Create(nCsma.value) -csma = ns.csma.CsmaHelper() -csma.SetChannelAttribute("DataRate", ns.core.StringValue("100Mbps")) -csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.NanoSeconds(6560))) +csma = ns.CsmaHelper() +csma.SetChannelAttribute("DataRate", ns.StringValue("100Mbps")) +csma.SetChannelAttribute("Delay", ns.TimeValue(ns.NanoSeconds(6560))) csmaDevices = csma.Install(csmaNodes) -wifiStaNodes = ns.network.NodeContainer() +wifiStaNodes = ns.NodeContainer() wifiStaNodes.Create(nWifi.value) wifiApNode = p2pNodes.Get(0) -channel = ns.wifi.YansWifiChannelHelper.Default() -phy = ns.wifi.YansWifiPhyHelper() +channel = ns.YansWifiChannelHelper.Default() +phy = ns.YansWifiPhyHelper() phy.SetChannel(channel.Create()) -mac = ns.wifi.WifiMacHelper() -ssid = ns.wifi.Ssid("ns-3-ssid") +mac = ns.WifiMacHelper() +ssid = ns.Ssid("ns-3-ssid") -wifi = ns.wifi.WifiHelper() +wifi = ns.WifiHelper() -mac.SetType( - "ns3::StaWifiMac", "Ssid", ns.wifi.SsidValue(ssid), "ActiveProbing", ns.core.BooleanValue(False) -) +mac.SetType("ns3::StaWifiMac", "Ssid", ns.SsidValue(ssid), "ActiveProbing", ns.BooleanValue(False)) staDevices = wifi.Install(phy, mac, wifiStaNodes) -mac.SetType("ns3::ApWifiMac", "Ssid", ns.wifi.SsidValue(ssid)) +mac.SetType("ns3::ApWifiMac", "Ssid", ns.SsidValue(ssid)) apDevices = wifi.Install(phy, mac, wifiApNode) -mobility = ns.mobility.MobilityHelper() +mobility = ns.MobilityHelper() mobility.SetPositionAllocator( "ns3::GridPositionAllocator", "MinX", - ns.core.DoubleValue(0.0), + ns.DoubleValue(0.0), "MinY", - ns.core.DoubleValue(0.0), + ns.DoubleValue(0.0), "DeltaX", - ns.core.DoubleValue(5.0), + ns.DoubleValue(5.0), "DeltaY", - ns.core.DoubleValue(10.0), + ns.DoubleValue(10.0), "GridWidth", - ns.core.UintegerValue(3), + ns.UintegerValue(3), "LayoutType", - ns.core.StringValue("RowFirst"), + ns.StringValue("RowFirst"), ) mobility.SetMobilityModel( "ns3::RandomWalk2dMobilityModel", "Bounds", - ns.mobility.RectangleValue(ns.mobility.Rectangle(-50, 50, -50, 50)), + ns.RectangleValue(ns.Rectangle(-50, 50, -50, 50)), ) mobility.Install(wifiStaNodes) mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel") mobility.Install(wifiApNode) -stack = ns.internet.InternetStackHelper() +stack = ns.InternetStackHelper() stack.Install(csmaNodes) stack.Install(wifiApNode) stack.Install(wifiStaNodes) -address = ns.internet.Ipv4AddressHelper() -address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) +address = ns.Ipv4AddressHelper() +address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) p2pInterfaces = address.Assign(p2pDevices) -address.SetBase(ns.network.Ipv4Address("10.1.2.0"), ns.network.Ipv4Mask("255.255.255.0")) +address.SetBase(ns.Ipv4Address("10.1.2.0"), ns.Ipv4Mask("255.255.255.0")) csmaInterfaces = address.Assign(csmaDevices) -address.SetBase(ns.network.Ipv4Address("10.1.3.0"), ns.network.Ipv4Mask("255.255.255.0")) +address.SetBase(ns.Ipv4Address("10.1.3.0"), ns.Ipv4Mask("255.255.255.0")) address.Assign(staDevices) address.Assign(apDevices) -echoServer = ns.applications.UdpEchoServerHelper(9) +echoServer = ns.UdpEchoServerHelper(9) serverApps = echoServer.Install(csmaNodes.Get(nCsma.value)) -serverApps.Start(ns.core.Seconds(1.0)) -serverApps.Stop(ns.core.Seconds(10.0)) +serverApps.Start(ns.Seconds(1.0)) +serverApps.Stop(ns.Seconds(10.0)) -echoClient = ns.applications.UdpEchoClientHelper( - csmaInterfaces.GetAddress(nCsma.value).ConvertTo(), 9 -) -echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1)) -echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0))) -echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024)) +echoClient = ns.UdpEchoClientHelper(csmaInterfaces.GetAddress(nCsma.value).ConvertTo(), 9) +echoClient.SetAttribute("MaxPackets", ns.UintegerValue(1)) +echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.0))) +echoClient.SetAttribute("PacketSize", ns.UintegerValue(1024)) clientApps = echoClient.Install(wifiStaNodes.Get(nWifi.value - 1)) -clientApps.Start(ns.core.Seconds(2.0)) -clientApps.Stop(ns.core.Seconds(10.0)) +clientApps.Start(ns.Seconds(2.0)) +clientApps.Stop(ns.Seconds(10.0)) -ns.internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables() +ns.Ipv4GlobalRoutingHelper.PopulateRoutingTables() -ns.core.Simulator.Stop(ns.core.Seconds(10.0)) +ns.Simulator.Stop(ns.Seconds(10.0)) if tracing.value: phy.SetPcapDataLinkType(phy.DLT_IEEE802_11_RADIO) @@ -172,5 +168,5 @@ if tracing.value: phy.EnablePcap("third", apDevices.Get(0)) csma.EnablePcap("third", csmaDevices.Get(0), True) -ns.core.Simulator.Run() -ns.core.Simulator.Destroy() +ns.Simulator.Run() +ns.Simulator.Destroy() diff --git a/examples/wireless/mixed-wired-wireless.py b/examples/wireless/mixed-wired-wireless.py index d34f099c4..2132135b7 100644 --- a/examples/wireless/mixed-wired-wireless.py +++ b/examples/wireless/mixed-wired-wireless.py @@ -88,8 +88,8 @@ def main(argv): # Simulation defaults are typically set next, before command line # arguments are parsed. # - ns.core.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.StringValue("1472")) - ns.core.Config.SetDefault("ns3::OnOffApplication::DataRate", ns.core.StringValue("100kb/s")) + ns.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.StringValue("1472")) + ns.Config.SetDefault("ns3::OnOffApplication::DataRate", ns.StringValue("100kb/s")) # # For convenience, we add the local variables to the command line argument @@ -121,29 +121,29 @@ def main(argv): # 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 = ns.network.NodeContainer() + backbone = ns.NodeContainer() backbone.Create(backboneNodes.value) # # Create the backbone wifi net devices and install them into the nodes in # our container # - wifi = ns.wifi.WifiHelper() - mac = ns.wifi.WifiMacHelper() + wifi = ns.WifiHelper() + mac = ns.WifiMacHelper() mac.SetType("ns3::AdhocWifiMac") wifi.SetRemoteStationManager( - "ns3::ConstantRateWifiManager", "DataMode", ns.core.StringValue("OfdmRate54Mbps") + "ns3::ConstantRateWifiManager", "DataMode", ns.StringValue("OfdmRate54Mbps") ) - wifiPhy = ns.wifi.YansWifiPhyHelper() + wifiPhy = ns.YansWifiPhyHelper() wifiPhy.SetPcapDataLinkType(wifiPhy.DLT_IEEE802_11_RADIO) - wifiChannel = ns.wifi.YansWifiChannelHelper.Default() + wifiChannel = ns.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 = ns.internet.InternetStackHelper() - olsr = ns.olsr.OlsrHelper() + internet = ns.InternetStackHelper() + olsr = ns.OlsrHelper() internet.SetRoutingHelper(olsr) # has effect on the next Install () internet.Install(backbone) @@ -153,38 +153,38 @@ def main(argv): # Assign IPv4 addresses to the device drivers(actually to the associated # IPv4 interfaces) we just created. # - ipAddrs = ns.internet.Ipv4AddressHelper() - ipAddrs.SetBase(ns.network.Ipv4Address("192.168.0.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipAddrs = ns.Ipv4AddressHelper() + ipAddrs.SetBase(ns.Ipv4Address("192.168.0.0"), ns.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 = ns.mobility.MobilityHelper() + mobility = ns.MobilityHelper() mobility.SetPositionAllocator( "ns3::GridPositionAllocator", "MinX", - ns.core.DoubleValue(20.0), + ns.DoubleValue(20.0), "MinY", - ns.core.DoubleValue(20.0), + ns.DoubleValue(20.0), "DeltaX", - ns.core.DoubleValue(20.0), + ns.DoubleValue(20.0), "DeltaY", - ns.core.DoubleValue(20.0), + ns.DoubleValue(20.0), "GridWidth", - ns.core.UintegerValue(5), + ns.UintegerValue(5), "LayoutType", - ns.core.StringValue("RowFirst"), + ns.StringValue("RowFirst"), ) mobility.SetMobilityModel( "ns3::RandomDirection2dMobilityModel", "Bounds", - ns.mobility.RectangleValue(ns.mobility.Rectangle(-500, 500, -500, 500)), + ns.RectangleValue(ns.Rectangle(-500, 500, -500, 500)), "Speed", - ns.core.StringValue("ns3::ConstantRandomVariable[Constant=2]"), + ns.StringValue("ns3::ConstantRandomVariable[Constant=2]"), "Pause", - ns.core.StringValue("ns3::ConstantRandomVariable[Constant=0.2]"), + ns.StringValue("ns3::ConstantRandomVariable[Constant=0.2]"), ) mobility.Install(backbone) @@ -196,7 +196,7 @@ def main(argv): # Reset the address base-- all of the CSMA networks will be in # the "172.16 address space - ipAddrs.SetBase(ns.network.Ipv4Address("172.16.0.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipAddrs.SetBase(ns.Ipv4Address("172.16.0.0"), ns.Ipv4Mask("255.255.255.0")) for i in range(backboneNodes.value): print("Configuring local area network for backbone node ", i) @@ -205,17 +205,17 @@ def main(argv): # two containers here; one with all of the new nodes, and one # with all of the nodes including new and existing nodes # - newLanNodes = ns.network.NodeContainer() + newLanNodes = ns.NodeContainer() newLanNodes.Create(lanNodes.value - 1) # Now, create the container with all nodes on this link - lan = ns.network.NodeContainer(ns.network.NodeContainer(backbone.Get(i)), newLanNodes) + lan = ns.NodeContainer(ns.NodeContainer(backbone.Get(i)), newLanNodes) # # Create the CSMA net devices and install them into the nodes in our # collection. # - csma = ns.csma.CsmaHelper() - csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))) - csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))) + csma = ns.CsmaHelper() + csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000))) + csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2))) lanDevices = csma.Install(lan) # # Add the IPv4 protocol stack to the new LAN nodes @@ -235,10 +235,10 @@ def main(argv): # The new LAN nodes need a mobility model so we aggregate one # to each of the nodes we just finished building. # - mobilityLan = ns.mobility.MobilityHelper() - positionAlloc = ns.mobility.ListPositionAllocator() + mobilityLan = ns.MobilityHelper() + positionAlloc = ns.ListPositionAllocator() for j in range(newLanNodes.GetN()): - positionAlloc.Add(ns.core.Vector(0.0, (j * 10 + 10), 0.0)) + positionAlloc.Add(ns.Vector(0.0, (j * 10 + 10), 0.0)) mobilityLan.SetPositionAllocator(positionAlloc) mobilityLan.PushReferenceMobilityModel(backbone.Get(i)) @@ -253,7 +253,7 @@ def main(argv): # Reset the address base-- all of the 802.11 networks will be in # the "10.0" address space - ipAddrs.SetBase(ns.network.Ipv4Address("10.0.0.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipAddrs.SetBase(ns.Ipv4Address("10.0.0.0"), ns.Ipv4Mask("255.255.255.0")) tempRef = [] # list of references to be held to prevent garbage collection for i in range(backboneNodes.value): print("Configuring wireless network for backbone node ", i) @@ -262,26 +262,26 @@ def main(argv): # two containers here; one with all of the new nodes, and one # with all of the nodes including new and existing nodes # - stas = ns.network.NodeContainer() + stas = ns.NodeContainer() stas.Create(infraNodes.value - 1) # Now, create the container with all nodes on this link - infra = ns.network.NodeContainer(ns.network.NodeContainer(backbone.Get(i)), stas) + infra = ns.NodeContainer(ns.NodeContainer(backbone.Get(i)), stas) # # Create another ad hoc network and devices # - ssid = ns.wifi.Ssid("wifi-infra" + str(i)) - wifiInfra = ns.wifi.WifiHelper() + ssid = ns.Ssid("wifi-infra" + str(i)) + wifiInfra = ns.WifiHelper() wifiPhy.SetChannel(wifiChannel.Create()) - macInfra = ns.wifi.WifiMacHelper() - macInfra.SetType("ns3::StaWifiMac", "Ssid", ns.wifi.SsidValue(ssid)) + macInfra = ns.WifiMacHelper() + macInfra.SetType("ns3::StaWifiMac", "Ssid", ns.SsidValue(ssid)) # setup stas staDevices = wifiInfra.Install(wifiPhy, macInfra, stas) # setup ap. - macInfra.SetType("ns3::ApWifiMac", "Ssid", ns.wifi.SsidValue(ssid)) + macInfra.SetType("ns3::ApWifiMac", "Ssid", ns.SsidValue(ssid)) apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i)) # Collect all of these new devices - infraDevices = ns.network.NetDeviceContainer(apDevices, staDevices) + infraDevices = ns.NetDeviceContainer(apDevices, staDevices) # Add the IPv4 protocol stack to the nodes in our container # @@ -299,7 +299,7 @@ def main(argv): # This call returns an instance that needs to be stored in the outer scope # not to be garbage collected when overwritten in the next iteration - subnetAlloc = ns.mobility.ListPositionAllocator() + subnetAlloc = ns.ListPositionAllocator() # Appending the object to a list is enough to prevent the garbage collection tempRef.append(subnetAlloc) @@ -309,18 +309,18 @@ def main(argv): # to each of the nodes we just finished building. # for j in range(infra.GetN()): - subnetAlloc.Add(ns.core.Vector(0.0, j, 0.0)) + subnetAlloc.Add(ns.Vector(0.0, j, 0.0)) mobility.PushReferenceMobilityModel(backbone.Get(i)) mobility.SetPositionAllocator(subnetAlloc) mobility.SetMobilityModel( "ns3::RandomDirection2dMobilityModel", "Bounds", - ns.mobility.RectangleValue(ns.mobility.Rectangle(-10, 10, -10, 10)), + ns.RectangleValue(ns.Rectangle(-10, 10, -10, 10)), "Speed", - ns.core.StringValue("ns3::ConstantRandomVariable[Constant=3]"), + ns.StringValue("ns3::ConstantRandomVariable[Constant=3]"), "Pause", - ns.core.StringValue("ns3::ConstantRandomVariable[Constant=0.4]"), + ns.StringValue("ns3::ConstantRandomVariable[Constant=0.4]"), ) mobility.Install(stas) @@ -335,14 +335,14 @@ def main(argv): print("Create Applications.") port = 9 # Discard port(RFC 863) - appSource = ns.network.NodeList.GetNode(backboneNodes.value) + appSource = ns.NodeList.GetNode(backboneNodes.value) lastNodeIndex = ( backboneNodes.value + backboneNodes.value * (lanNodes.value - 1) + backboneNodes.value * (infraNodes.value - 1) - 1 ) - appSink = ns.network.NodeList.GetNode(lastNodeIndex) + appSink = ns.NodeList.GetNode(lastNodeIndex) ns.cppyy.cppdef( """ @@ -353,22 +353,20 @@ def main(argv): ) # Let's fetch the IP address of the last node, which is on Ipv4Interface 1 remoteAddr = ns.cppyy.gbl.getIpv4AddressFromNode(appSink) - socketAddr = ns.network.InetSocketAddress(remoteAddr, port) - onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", socketAddr.ConvertTo()) - apps = onoff.Install(ns.network.NodeContainer(appSource)) - apps.Start(ns.core.Seconds(3)) - apps.Stop(ns.core.Seconds(stopTime.value - 1)) + socketAddr = ns.InetSocketAddress(remoteAddr, port) + onoff = ns.OnOffHelper("ns3::UdpSocketFactory", socketAddr.ConvertTo()) + apps = onoff.Install(ns.NodeContainer(appSource)) + apps.Start(ns.Seconds(3)) + apps.Stop(ns.Seconds(stopTime.value - 1)) # Create a packet sink to receive these packets - sink = ns.applications.PacketSinkHelper( + sink = ns.PacketSinkHelper( "ns3::UdpSocketFactory", - ns.network.InetSocketAddress( - ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port) - ).ConvertTo(), + ns.InetSocketAddress(ns.InetSocketAddress(ns.Ipv4Address.GetAny(), port)).ConvertTo(), ) - sinkContainer = ns.network.NodeContainer(appSink) + sinkContainer = ns.NodeContainer(appSink) apps = sink.Install(sinkContainer) - apps.Start(ns.core.Seconds(3)) + apps.Start(ns.Seconds(3)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / # # @@ -377,11 +375,11 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / print("Configure Tracing.") - csma = ns.csma.CsmaHelper() + csma = ns.CsmaHelper() # # Let's set up some ns-2-like ascii traces, using another helper class # - ascii = ns.network.AsciiTraceHelper() + ascii = ns.AsciiTraceHelper() stream = ascii.CreateFileStream("mixed-wireless.tr") wifiPhy.EnableAsciiAll(stream) csma.EnableAsciiAll(stream) @@ -405,9 +403,9 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print("Run Simulation.") - ns.core.Simulator.Stop(ns.core.Seconds(stopTime.value)) - ns.core.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Stop(ns.Seconds(stopTime.value)) + ns.Simulator.Run() + ns.Simulator.Destroy() if __name__ == "__main__": diff --git a/examples/wireless/wifi-ap.py b/examples/wireless/wifi-ap.py index 464d9dfe5..e97f0ff9a 100644 --- a/examples/wireless/wifi-ap.py +++ b/examples/wireless/wifi-ap.py @@ -93,16 +93,16 @@ ns.cppyy.cppdef( def main(argv): - ns.core.CommandLine().Parse(argv) + ns.CommandLine().Parse(argv) - ns.network.Packet.EnablePrinting() + ns.Packet.EnablePrinting() - wifi = ns.wifi.WifiHelper() - mobility = ns.mobility.MobilityHelper() - stas = ns.network.NodeContainer() - ap = ns.network.NodeContainer() + wifi = ns.WifiHelper() + mobility = ns.MobilityHelper() + stas = ns.NodeContainer() + ap = ns.NodeContainer() # NetDeviceContainer staDevs; - packetSocket = ns.network.PacketSocketHelper() + packetSocket = ns.PacketSocketHelper() stas.Create(2) ap.Create(1) @@ -111,45 +111,45 @@ def main(argv): packetSocket.Install(stas) packetSocket.Install(ap) - wifiPhy = ns.wifi.YansWifiPhyHelper() - wifiChannel = ns.wifi.YansWifiChannelHelper.Default() + wifiPhy = ns.YansWifiPhyHelper() + wifiChannel = ns.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) - ssid = ns.wifi.Ssid("wifi-default") - wifiMac = ns.wifi.WifiMacHelper() + ssid = ns.Ssid("wifi-default") + wifiMac = ns.WifiMacHelper() # setup stas. wifiMac.SetType( "ns3::StaWifiMac", "ActiveProbing", - ns.core.BooleanValue(True), + ns.BooleanValue(True), "Ssid", - ns.wifi.SsidValue(ssid), + ns.SsidValue(ssid), ) staDevs = wifi.Install(wifiPhy, wifiMac, stas) # setup ap. - wifiMac.SetType("ns3::ApWifiMac", "Ssid", ns.wifi.SsidValue(ssid)) + wifiMac.SetType("ns3::ApWifiMac", "Ssid", ns.SsidValue(ssid)) wifi.Install(wifiPhy, wifiMac, ap) # mobility. mobility.Install(stas) mobility.Install(ap) - ns.core.Simulator.Schedule(ns.core.Seconds(1.0), ns.cppyy.gbl.AdvancePosition, ap.Get(0)) + ns.Simulator.Schedule(ns.Seconds(1.0), ns.cppyy.gbl.AdvancePosition, ap.Get(0)) - socket = ns.network.PacketSocketAddress() + socket = ns.PacketSocketAddress() socket.SetSingleDevice(staDevs.Get(0).GetIfIndex()) socket.SetPhysicalAddress(staDevs.Get(1).GetAddress()) socket.SetProtocol(1) - onoff = ns.applications.OnOffHelper("ns3::PacketSocketFactory", socket.ConvertTo()) - onoff.SetConstantRate(ns.network.DataRate("500kb/s")) + onoff = ns.OnOffHelper("ns3::PacketSocketFactory", socket.ConvertTo()) + onoff.SetConstantRate(ns.DataRate("500kb/s")) - apps = onoff.Install(ns.network.NodeContainer(stas.Get(0))) - apps.Start(ns.core.Seconds(0.5)) - apps.Stop(ns.core.Seconds(43.0)) + apps = onoff.Install(ns.NodeContainer(stas.Get(0))) + apps.Start(ns.Seconds(0.5)) + apps.Stop(ns.Seconds(43.0)) - ns.core.Simulator.Stop(ns.core.Seconds(44.0)) + ns.Simulator.Stop(ns.Seconds(44.0)) # Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace)); @@ -158,8 +158,8 @@ def main(argv): # Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace)); - ns.core.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Run() + ns.Simulator.Destroy() return 0 diff --git a/src/bridge/examples/csma-bridge.py b/src/bridge/examples/csma-bridge.py index 73294e672..1d152429a 100644 --- a/src/bridge/examples/csma-bridge.py +++ b/src/bridge/examples/csma-bridge.py @@ -48,53 +48,51 @@ def main(argv): # Allow the user to override any of the defaults and the above Bind() at # run-time, via command-line arguments # - cmd = ns.core.CommandLine() + cmd = ns.CommandLine() cmd.Parse(argv) # # Explicitly create the nodes required by the topology(shown above). # # print "Create nodes." - terminals = ns.network.NodeContainer() + terminals = ns.NodeContainer() terminals.Create(4) - csmaSwitch = ns.network.NodeContainer() + csmaSwitch = ns.NodeContainer() csmaSwitch.Create(1) # print "Build Topology" - csma = ns.csma.CsmaHelper() - csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))) - csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))) + csma = ns.CsmaHelper() + csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000))) + csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2))) # Create the csma links, from each terminal to the switch - terminalDevices = ns.network.NetDeviceContainer() - switchDevices = ns.network.NetDeviceContainer() + terminalDevices = ns.NetDeviceContainer() + switchDevices = ns.NetDeviceContainer() for i in range(4): - link = csma.Install( - ns.network.NodeContainer(ns.network.NodeContainer(terminals.Get(i)), csmaSwitch) - ) + link = csma.Install(ns.NodeContainer(ns.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 = ns.bridge.BridgeNetDevice() + bridgeDevice = ns.BridgeNetDevice() switchNode.AddDevice(bridgeDevice) for portIter in range(switchDevices.GetN()): bridgeDevice.AddBridgePort(switchDevices.Get(portIter)) # Add internet stack to the terminals - internet = ns.internet.InternetStackHelper() + internet = ns.InternetStackHelper() internet.Install(terminals) # We've got the "hardware" in place. Now we need to add IP addresses. # # print "Assign IP Addresses." - ipv4 = ns.internet.Ipv4AddressHelper() - ipv4.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipv4 = ns.Ipv4AddressHelper() + ipv4.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) ipv4.Assign(terminalDevices) # @@ -103,39 +101,39 @@ def main(argv): # print "Create Applications." port = 9 # Discard port(RFC 863) - inet_sock_address = ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.2"), port) - onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", inet_sock_address.ConvertTo()) - onoff.SetConstantRate(ns.network.DataRate("500kb/s")) + inet_sock_address = ns.InetSocketAddress(ns.Ipv4Address("10.1.1.2"), port) + onoff = ns.OnOffHelper("ns3::UdpSocketFactory", inet_sock_address.ConvertTo()) + onoff.SetConstantRate(ns.DataRate("500kb/s")) - app = onoff.Install(ns.network.NodeContainer(terminals.Get(0))) + app = onoff.Install(ns.NodeContainer(terminals.Get(0))) # Start the application - app.Start(ns.core.Seconds(1.0)) - app.Stop(ns.core.Seconds(10.0)) + app.Start(ns.Seconds(1.0)) + app.Stop(ns.Seconds(10.0)) # Create an optional packet sink to receive these packets - inet_address = ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port) - sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory", inet_address.ConvertTo()) - app = sink.Install(ns.network.NodeContainer(terminals.Get(1))) - app.Start(ns.core.Seconds(0.0)) + inet_address = ns.InetSocketAddress(ns.Ipv4Address.GetAny(), port) + sink = ns.PacketSinkHelper("ns3::UdpSocketFactory", inet_address.ConvertTo()) + app = sink.Install(ns.NodeContainer(terminals.Get(1))) + app.Start(ns.Seconds(0.0)) # # Create a similar flow from n3 to n0, starting at time 1.1 seconds # - inet_address = ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.1"), port) - onoff.SetAttribute("Remote", ns.network.AddressValue(inet_address.ConvertTo())) - app = onoff.Install(ns.network.NodeContainer(terminals.Get(3))) - app.Start(ns.core.Seconds(1.1)) - app.Stop(ns.core.Seconds(10.0)) + inet_address = ns.InetSocketAddress(ns.Ipv4Address("10.1.1.1"), port) + onoff.SetAttribute("Remote", ns.AddressValue(inet_address.ConvertTo())) + app = onoff.Install(ns.NodeContainer(terminals.Get(3))) + app.Start(ns.Seconds(1.1)) + app.Stop(ns.Seconds(10.0)) - app = sink.Install(ns.network.NodeContainer(terminals.Get(0))) - app.Start(ns.core.Seconds(0.0)) + app = sink.Install(ns.NodeContainer(terminals.Get(0))) + app.Start(ns.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 = ns.network.AsciiTraceHelper(); + # ascii = ns.AsciiTraceHelper(); # csma.EnableAsciiAll(ascii.CreateFileStream ("csma-bridge.tr")); # @@ -151,8 +149,8 @@ def main(argv): # Now, do the actual simulation. # # print "Run Simulation." - ns.core.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Run() + ns.Simulator.Destroy() # print "Done." diff --git a/src/core/examples/sample-simulator.py b/src/core/examples/sample-simulator.py index b52330f91..ff09c012b 100755 --- a/src/core/examples/sample-simulator.py +++ b/src/core/examples/sample-simulator.py @@ -38,7 +38,7 @@ except ModuleNotFoundError: ## Example function - triggered at a random time. ## \return None. def RandomFunction(): - print("RandomFunction received event at", ns.core.Simulator.Now().GetSeconds(), "s") + print("RandomFunction received event at", ns.Simulator.Now().GetSeconds(), "s") ## Example function - triggered if an event is canceled (should not be called). @@ -120,22 +120,22 @@ def main(argv): model = ns.cppyy.gbl.MyModel() v = ns.CreateObject("UniformRandomVariable") - v.SetAttribute("Min", ns.core.DoubleValue(10)) - v.SetAttribute("Max", ns.core.DoubleValue(20)) + v.SetAttribute("Min", ns.DoubleValue(10)) + v.SetAttribute("Max", ns.DoubleValue(20)) ev = ns.cppyy.gbl.ExampleFunctionEvent(model) - ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ev) + ns.Simulator.Schedule(ns.Seconds(10.0), ev) ev2 = ns.cppyy.gbl.RandomFunctionEvent(model) - ns.core.Simulator.Schedule(ns.core.Seconds(v.GetValue()), ev2) + ns.Simulator.Schedule(ns.Seconds(v.GetValue()), ev2) ev3 = ns.cppyy.gbl.CancelledFunctionEvent() - id = ns.core.Simulator.Schedule(ns.core.Seconds(30.0), ev3) - ns.core.Simulator.Cancel(id) + id = ns.Simulator.Schedule(ns.Seconds(30.0), ev3) + ns.Simulator.Cancel(id) - ns.core.Simulator.Run() + ns.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Destroy() if __name__ == "__main__": diff --git a/src/energy/examples/generic-battery-discharge-example.py b/src/energy/examples/generic-battery-discharge-example.py index 379c564d9..d93b65ed0 100644 --- a/src/energy/examples/generic-battery-discharge-example.py +++ b/src/energy/examples/generic-battery-discharge-example.py @@ -37,27 +37,27 @@ def main(argv): argv: System parameters to use if necessary """ - ns.core.LogComponentEnable("GenericBatteryModel", ns.core.LOG_LEVEL_DEBUG) + ns.LogComponentEnable("GenericBatteryModel", ns.LOG_LEVEL_DEBUG) - node = ns.network.Node() + node = ns.Node() batteryHelper = ns.energy.GenericBatteryModelHelper() batteryModel = ns.CreateObject("GenericBatteryModel") devicesEnergyModel = ns.energy.SimpleDeviceEnergyModel() - batteryModel.SetAttribute("FullVoltage", ns.core.DoubleValue(1.39)) # Vfull - batteryModel.SetAttribute("MaxCapacity", ns.core.DoubleValue(7.0)) # Q + batteryModel.SetAttribute("FullVoltage", ns.DoubleValue(1.39)) # Vfull + batteryModel.SetAttribute("MaxCapacity", ns.DoubleValue(7.0)) # Q - batteryModel.SetAttribute("NominalVoltage", ns.core.DoubleValue(1.18)) # Vnom - batteryModel.SetAttribute("NominalCapacity", ns.core.DoubleValue(6.25)) # QNom + batteryModel.SetAttribute("NominalVoltage", ns.DoubleValue(1.18)) # Vnom + batteryModel.SetAttribute("NominalCapacity", ns.DoubleValue(6.25)) # QNom - batteryModel.SetAttribute("ExponentialVoltage", ns.core.DoubleValue(1.28)) # Vexp - batteryModel.SetAttribute("ExponentialCapacity", ns.core.DoubleValue(1.3)) # Qexp + batteryModel.SetAttribute("ExponentialVoltage", ns.DoubleValue(1.28)) # Vexp + batteryModel.SetAttribute("ExponentialCapacity", ns.DoubleValue(1.3)) # Qexp - batteryModel.SetAttribute("InternalResistance", ns.core.DoubleValue(0.0046)) # R - batteryModel.SetAttribute("TypicalDischargeCurrent", ns.core.DoubleValue(1.3)) # i typical - batteryModel.SetAttribute("CutoffVoltage", ns.core.DoubleValue(1.0)) # End of charge. + batteryModel.SetAttribute("InternalResistance", ns.DoubleValue(0.0046)) # R + batteryModel.SetAttribute("TypicalDischargeCurrent", ns.DoubleValue(1.3)) # i typical + batteryModel.SetAttribute("CutoffVoltage", ns.DoubleValue(1.0)) # End of charge. - batteryModel.SetAttribute("BatteryType", ns.core.EnumValue(ns.NIMH_NICD)) # Battery type + batteryModel.SetAttribute("BatteryType", ns.EnumValue(ns.NIMH_NICD)) # Battery type devicesEnergyModel.SetEnergySource(batteryModel) batteryModel.AppendDeviceEnergyModel(devicesEnergyModel) @@ -65,9 +65,9 @@ def main(argv): devicesEnergyModel.SetCurrentA(6.5) - ns.core.Simulator.Stop(ns.core.Seconds(3600)) - ns.core.Simulator.Run() - ns.core.Simulator.Destroy() + ns.Simulator.Stop(ns.Seconds(3600)) + ns.Simulator.Run() + ns.Simulator.Destroy() if __name__ == "__main__": diff --git a/src/flow-monitor/examples/wifi-olsr-flowmon.py b/src/flow-monitor/examples/wifi-olsr-flowmon.py index 3c45f8a5f..6d9bd0304 100644 --- a/src/flow-monitor/examples/wifi-olsr-flowmon.py +++ b/src/flow-monitor/examples/wifi-olsr-flowmon.py @@ -55,32 +55,28 @@ def main(argv): wifi = ns.CreateObject("WifiHelper") wifiMac = ns.CreateObject("WifiMacHelper") wifiPhy = ns.CreateObject("YansWifiPhyHelper") - wifiChannel = ns.wifi.YansWifiChannelHelper.Default() + wifiChannel = ns.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) - ssid = ns.wifi.Ssid("wifi-default") - wifiMac.SetType("ns3::AdhocWifiMac", "Ssid", ns.wifi.SsidValue(ssid)) + ssid = ns.Ssid("wifi-default") + wifiMac.SetType("ns3::AdhocWifiMac", "Ssid", ns.SsidValue(ssid)) - internet = ns.internet.InternetStackHelper() - list_routing = ns.internet.Ipv4ListRoutingHelper() - olsr_routing = ns.olsr.OlsrHelper() - static_routing = ns.internet.Ipv4StaticRoutingHelper() + internet = ns.InternetStackHelper() + list_routing = ns.Ipv4ListRoutingHelper() + olsr_routing = ns.OlsrHelper() + static_routing = ns.Ipv4StaticRoutingHelper() list_routing.Add(static_routing, 0) list_routing.Add(olsr_routing, 100) internet.SetRoutingHelper(list_routing) - ipv4Addresses = ns.internet.Ipv4AddressHelper() - ipv4Addresses.SetBase(ns.network.Ipv4Address("10.0.0.0"), ns.network.Ipv4Mask("255.255.255.0")) + ipv4Addresses = ns.Ipv4AddressHelper() + ipv4Addresses.SetBase(ns.Ipv4Address("10.0.0.0"), ns.Ipv4Mask("255.255.255.0")) port = 9 # Discard port(RFC 863) - inetAddress = ns.network.InetSocketAddress(ns.network.Ipv4Address("10.0.0.1"), port) - onOffHelper = ns.applications.OnOffHelper("ns3::UdpSocketFactory", inetAddress.ConvertTo()) - onOffHelper.SetAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate("100kbps"))) - onOffHelper.SetAttribute( - "OnTime", ns.core.StringValue("ns3::ConstantRandomVariable[Constant=1]") - ) - onOffHelper.SetAttribute( - "OffTime", ns.core.StringValue("ns3::ConstantRandomVariable[Constant=0]") - ) + inetAddress = ns.InetSocketAddress(ns.Ipv4Address("10.0.0.1"), port) + onOffHelper = ns.OnOffHelper("ns3::UdpSocketFactory", inetAddress.ConvertTo()) + onOffHelper.SetAttribute("DataRate", ns.DataRateValue(ns.DataRate("100kbps"))) + onOffHelper.SetAttribute("OnTime", ns.StringValue("ns3::ConstantRandomVariable[Constant=1]")) + onOffHelper.SetAttribute("OffTime", ns.StringValue("ns3::ConstantRandomVariable[Constant=0]")) addresses = [] nodes = [] @@ -96,11 +92,11 @@ def main(argv): for yi in range(num_nodes_side): node = nodes.Get(accumulator) accumulator += 1 - container = ns.network.NodeContainer(node) + container = ns.NodeContainer(node) internet.Install(container) mobility = ns.CreateObject("ConstantPositionMobilityModel") - mobility.SetPosition(ns.core.Vector(xi * DISTANCE, yi * DISTANCE, 0)) + mobility.SetPosition(ns.Vector(xi * DISTANCE, yi * DISTANCE, 0)) node.AggregateObject(mobility) device = wifi.Install(wifiPhy, wifiMac, node) @@ -112,25 +108,25 @@ def main(argv): # print (i, destaddr) onOffHelper.SetAttribute( "Remote", - ns.network.AddressValue(ns.network.InetSocketAddress(destaddr, port).ConvertTo()), + ns.AddressValue(ns.InetSocketAddress(destaddr, port).ConvertTo()), ) - container = ns.network.NodeContainer(node) + container = ns.NodeContainer(node) app = onOffHelper.Install(container) urv = ns.CreateObject("UniformRandomVariable") # ns.cppyy.gbl.get_rng() startDelay = ns.Seconds(urv.GetValue(20, 30)) app.Start(startDelay) # internet.EnablePcapAll("wifi-olsr") - flowmon_helper = ns.flow_monitor.FlowMonitorHelper() - # flowmon_helper.SetMonitorAttribute("StartTime", ns.core.TimeValue(ns.core.Seconds(31))) + flowmon_helper = ns.FlowMonitorHelper() + # flowmon_helper.SetMonitorAttribute("StartTime", ns.TimeValue(ns.Seconds(31))) monitor = flowmon_helper.InstallAll() monitor = flowmon_helper.GetMonitor() - monitor.SetAttribute("DelayBinWidth", ns.core.DoubleValue(0.001)) - monitor.SetAttribute("JitterBinWidth", ns.core.DoubleValue(0.001)) - monitor.SetAttribute("PacketSizeBinWidth", ns.core.DoubleValue(20)) + monitor.SetAttribute("DelayBinWidth", ns.DoubleValue(0.001)) + monitor.SetAttribute("JitterBinWidth", ns.DoubleValue(0.001)) + monitor.SetAttribute("PacketSizeBinWidth", ns.DoubleValue(20)) - ns.core.Simulator.Stop(ns.core.Seconds(44.0)) - ns.core.Simulator.Run() + ns.Simulator.Stop(ns.Seconds(44.0)) + ns.Simulator.Run() def print_stats(os, st): print(" Tx Bytes: ", st.txBytes, file=os) diff --git a/src/tap-bridge/examples/tap-csma-virtual-machine.py b/src/tap-bridge/examples/tap-csma-virtual-machine.py index 4f96860dd..ae0fd807c 100644 --- a/src/tap-bridge/examples/tap-csma-virtual-machine.py +++ b/src/tap-bridge/examples/tap-csma-virtual-machine.py @@ -29,24 +29,22 @@ except ModuleNotFoundError: def main(argv): - ns.core.CommandLine().Parse(argv) + ns.CommandLine().Parse(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. # - ns.core.GlobalValue.Bind( - "SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl") - ) - ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue(True)) + ns.GlobalValue.Bind("SimulatorImplementationType", ns.StringValue("ns3::RealtimeSimulatorImpl")) + ns.GlobalValue.Bind("ChecksumEnabled", ns.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 = ns.network.NodeContainer() + nodes = ns.NodeContainer() nodes.Create(2) # @@ -54,7 +52,7 @@ def main(argv): # devices installed on both of the nodes. The data rate and delay for the # channel can be set through the command-line parser. # - csma = ns.csma.CsmaHelper() + csma = ns.CsmaHelper() devices = csma.Install(nodes) # @@ -65,24 +63,24 @@ def main(argv): # only see traffic from one other device on that bridge. That is the case # for this configuration. # - tapBridge = ns.tap_bridge.TapBridgeHelper() - tapBridge.SetAttribute("Mode", ns.core.StringValue("UseLocal")) - tapBridge.SetAttribute("DeviceName", ns.core.StringValue("tap-left")) + tapBridge = ns.TapBridgeHelper() + tapBridge.SetAttribute("Mode", ns.StringValue("UseLocal")) + tapBridge.SetAttribute("DeviceName", ns.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", ns.core.StringValue("tap-right")) + tapBridge.SetAttribute("DeviceName", ns.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 # - ns.core.Simulator.Stop(ns.core.Seconds(600)) - ns.core.Simulator.Run() # signal_check_frequency = -1 - ns.core.Simulator.Destroy() + ns.Simulator.Stop(ns.Seconds(600)) + ns.Simulator.Run() # signal_check_frequency = -1 + ns.Simulator.Destroy() return 0 diff --git a/src/tap-bridge/examples/tap-wifi-virtual-machine.py b/src/tap-bridge/examples/tap-wifi-virtual-machine.py index 82d3cc4d4..a9d970de7 100644 --- a/src/tap-bridge/examples/tap-wifi-virtual-machine.py +++ b/src/tap-bridge/examples/tap-wifi-virtual-machine.py @@ -29,46 +29,44 @@ except ModuleNotFoundError: def main(argv): - ns.core.CommandLine().Parse(argv) + ns.CommandLine().Parse(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. # - ns.core.GlobalValue.Bind( - "SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl") - ) - ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue(True)) + ns.GlobalValue.Bind("SimulatorImplementationType", ns.StringValue("ns3::RealtimeSimulatorImpl")) + ns.GlobalValue.Bind("ChecksumEnabled", ns.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 = ns.network.NodeContainer() + nodes = ns.NodeContainer() nodes.Create(2) # # We're going to use 802.11 A so set up a wifi helper to reflect that. # - wifi = ns.wifi.WifiHelper() - wifi.SetStandard(ns.wifi.WIFI_STANDARD_80211a) + wifi = ns.WifiHelper() + wifi.SetStandard(ns.WIFI_STANDARD_80211a) wifi.SetRemoteStationManager( - "ns3::ConstantRateWifiManager", "DataMode", ns.core.StringValue("OfdmRate54Mbps") + "ns3::ConstantRateWifiManager", "DataMode", ns.StringValue("OfdmRate54Mbps") ) # # No reason for pesky access points, so we'll use an ad-hoc network. # - wifiMac = ns.wifi.WifiMacHelper() + wifiMac = ns.WifiMacHelper() wifiMac.SetType("ns3::AdhocWifiMac") # # Configure the physical layer. # - wifiChannel = ns.wifi.YansWifiChannelHelper.Default() - wifiPhy = ns.wifi.YansWifiPhyHelper() + wifiChannel = ns.YansWifiChannelHelper.Default() + wifiPhy = ns.YansWifiPhyHelper() wifiPhy.SetChannel(wifiChannel.Create()) # @@ -80,10 +78,10 @@ def main(argv): # We need location information since we are talking about wifi, so add a # constant position to the ghost nodes. # - mobility = ns.mobility.MobilityHelper() - positionAlloc = ns.mobility.ListPositionAllocator() - positionAlloc.Add(ns.core.Vector(0.0, 0.0, 0.0)) - positionAlloc.Add(ns.core.Vector(5.0, 0.0, 0.0)) + mobility = ns.MobilityHelper() + positionAlloc = ns.ListPositionAllocator() + positionAlloc.Add(ns.Vector(0.0, 0.0, 0.0)) + positionAlloc.Add(ns.Vector(5.0, 0.0, 0.0)) mobility.SetPositionAllocator(positionAlloc) mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel") mobility.Install(nodes) @@ -96,24 +94,24 @@ def main(argv): # only see traffic from one other device on that bridge. That is the case # for this configuration. # - tapBridge = ns.tap_bridge.TapBridgeHelper() - tapBridge.SetAttribute("Mode", ns.core.StringValue("UseLocal")) - tapBridge.SetAttribute("DeviceName", ns.core.StringValue("tap-left")) + tapBridge = ns.TapBridgeHelper() + tapBridge.SetAttribute("Mode", ns.StringValue("UseLocal")) + tapBridge.SetAttribute("DeviceName", ns.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", ns.core.StringValue("tap-right")) + tapBridge.SetAttribute("DeviceName", ns.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 # - ns.core.Simulator.Stop(ns.core.Seconds(600)) - ns.core.Simulator.Run() # signal_check_frequency = -1 - ns.core.Simulator.Destroy() + ns.Simulator.Stop(ns.Seconds(600)) + ns.Simulator.Run() # signal_check_frequency = -1 + ns.Simulator.Destroy() return 0 diff --git a/src/visualizer/visualizer/plugins/show_last_packets.py b/src/visualizer/visualizer/plugins/show_last_packets.py index b5702f1eb..d6ea8422a 100644 --- a/src/visualizer/visualizer/plugins/show_last_packets.py +++ b/src/visualizer/visualizer/plugins/show_last_packets.py @@ -106,7 +106,7 @@ class ShowLastPackets(InformationWindow): if sample.device is None: interface_name = "(unknown)" else: - interface_name = ns.core.Names.FindName(sample.device) + interface_name = ns.Names.FindName(sample.device) if not interface_name: interface_name = "(interface %i)" % sample.device.GetIfIndex() self.table_model.set( @@ -138,7 +138,7 @@ class ShowLastPackets(InformationWindow): self.win.set_title("Last packets for node %i" % node_index) self.visualizer = visualizer self.viz_node = visualizer.get_node(node_index) - self.node = ns.network.NodeList.GetNode(node_index) + self.node = ns.NodeList.GetNode(node_index) def smart_expand(expander, vbox): if expander.get_expanded(): @@ -184,7 +184,7 @@ class ShowLastPackets(InformationWindow): # Packet Filter # - options - self.packet_capture_options = ns.visualizer.PyViz.PacketCaptureOptions() + self.packet_capture_options = ns.PyViz.PacketCaptureOptions() self.packet_capture_options.numLastPackets = 100 packet_filter_vbox = Gtk.VBox(False, 4) @@ -214,10 +214,10 @@ class ShowLastPackets(InformationWindow): self.packet_filter_list = [] # list of TypeIdConfig instances - Header = ns.core.TypeId.LookupByName("ns3::Header") - Trailer = ns.core.TypeId.LookupByName("ns3::Trailer") - for typeid_i in range(ns.core.TypeId.GetRegisteredN()): - typeid = ns.core.TypeId.GetRegistered(typeid_i) + Header = ns.TypeId.LookupByName("ns3::Header") + Trailer = ns.TypeId.LookupByName("ns3::Trailer") + for typeid_i in range(ns.TypeId.GetRegisteredN()): + typeid = ns.TypeId.GetRegistered(typeid_i) # check if this is a header or trailer subtype typeid_tmp = typeid type_is_good = False @@ -242,13 +242,9 @@ class ShowLastPackets(InformationWindow): def update_capture_options(): if self.op_AND_button.props.active: - self.packet_capture_options.mode = ( - ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_AND - ) + self.packet_capture_options.mode = ns.PyViz.PACKET_CAPTURE_FILTER_HEADERS_AND else: - self.packet_capture_options.mode = ( - ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_OR - ) + self.packet_capture_options.mode = ns.PyViz.PACKET_CAPTURE_FILTER_HEADERS_OR self.packet_capture_options.numLastPackets = 100 self.packet_capture_options.headers = [ c.typeid for c in self.packet_filter_list if c.selected diff --git a/src/visualizer/visualizer/plugins/wifi_intrastructure_link.py b/src/visualizer/visualizer/plugins/wifi_intrastructure_link.py index 0ace27b99..3a8d2b9ed 100644 --- a/src/visualizer/visualizer/plugins/wifi_intrastructure_link.py +++ b/src/visualizer/visualizer/plugins/wifi_intrastructure_link.py @@ -151,17 +151,17 @@ class WifiLinkMonitor(object): self.stations = [] for node in viz.nodes.values(): - ns3_node = ns.network.NodeList.GetNode(node.node_index) + ns3_node = ns.NodeList.GetNode(node.node_index) for devI in range(ns3_node.GetNDevices()): dev = ns3_node.GetDevice(devI) - if not isinstance(dev, ns.wifi.WifiNetDevice): + if not isinstance(dev, ns.WifiNetDevice): continue wifi_mac = dev.GetMac() - if isinstance(wifi_mac, ns.wifi.StaWifiMac): + if isinstance(wifi_mac, ns.StaWifiMac): wifi_link = WifiLink(viz.links_group, node, dev) self.stations.append((dev, node, wifi_link)) - elif isinstance(wifi_mac, ns.wifi.ApWifiMac): - bssid = ns.network.Mac48Address.ConvertFrom(dev.GetAddress()) + elif isinstance(wifi_mac, ns.ApWifiMac): + bssid = ns.Mac48Address.ConvertFrom(dev.GetAddress()) self.access_points[str(bssid)] = node # print "APs: ", self.access_points # print "STAs: ", self.stations diff --git a/utils/python-unit-tests.py b/utils/python-unit-tests.py index 9482cc0ce..8073013dd 100644 --- a/utils/python-unit-tests.py +++ b/utils/python-unit-tests.py @@ -202,7 +202,7 @@ class TestSimulator(unittest.TestCase): @param self this object @return None """ - ns.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123)) + ns.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.UintegerValue(123)) # hm.. no Config.Get? def testSocket(self): @@ -228,19 +228,15 @@ class TestSimulator(unittest.TestCase): """ ) - sink = ns.network.Socket.CreateSocket( - node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory") - ) - sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80).ConvertTo()) + sink = ns.Socket.CreateSocket(node, ns.TypeId.LookupByName("ns3::UdpSocketFactory")) + sink.Bind(ns.InetSocketAddress(ns.Ipv4Address.GetAny(), 80).ConvertTo()) sink.SetRecvCallback(ns.cppyy.gbl.make_rx_callback_test_socket(python_rx_callback)) - source = ns.network.Socket.CreateSocket( - node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory") - ) + source = ns.Socket.CreateSocket(node, ns.TypeId.LookupByName("ns3::UdpSocketFactory")) source.SendTo( - ns.network.Packet(19), + ns.Packet(19), 0, - ns.network.InetSocketAddress(ns.network.Ipv4Address("127.0.0.1"), 80).ConvertTo(), + ns.InetSocketAddress(ns.Ipv4Address("127.0.0.1"), 80).ConvertTo(), ) ns.Simulator.Run() @@ -257,26 +253,26 @@ class TestSimulator(unittest.TestCase): """ # Templated class DropTailQueue in C++ queue = ns.CreateObject("DropTailQueue") - queueSizeValue = ns.network.QueueSizeValue(ns.network.QueueSize("500p")) + queueSizeValue = ns.QueueSizeValue(ns.QueueSize("500p")) queue.SetAttribute("MaxSize", queueSizeValue) - limit = ns.network.QueueSizeValue() + limit = ns.QueueSizeValue() queue.GetAttribute("MaxSize", limit) - self.assertEqual(limit.Get(), ns.network.QueueSize("500p")) + self.assertEqual(limit.Get(), ns.QueueSize("500p")) ## -- object pointer values mobility = ns.CreateObject("RandomWaypointMobilityModel") ptr = ns.CreateObject("PointerValue") mobility.GetAttribute("PositionAllocator", ptr) - self.assertEqual(ptr.GetObject(), ns.core.Ptr["Object"](ns.cppyy.nullptr)) + self.assertEqual(ptr.GetObject(), ns.Ptr["Object"](ns.cppyy.nullptr)) - pos = ns.mobility.ListPositionAllocator() + pos = ns.ListPositionAllocator() ptr.SetObject(pos) mobility.SetAttribute("PositionAllocator", ptr) ptr2 = ns.CreateObject("PointerValue") mobility.GetAttribute("PositionAllocator", ptr2) - self.assertNotEqual(ptr.GetObject(), ns.core.Ptr["Object"](ns.cppyy.nullptr)) + self.assertNotEqual(ptr.GetObject(), ns.Ptr["Object"](ns.cppyy.nullptr)) # Delete Ptr<>'s on the python side to let C++ clean them del queue, mobility, ptr, ptr2 @@ -324,7 +320,7 @@ class TestSimulator(unittest.TestCase): test4Buffer = create_string_buffer(b"this is a test option", BUFFLEN) test4 = c_char_p(test4Buffer.raw) - cmd = ns.core.CommandLine(__file__) + cmd = ns.CommandLine(__file__) cmd.AddValue("Test1", "this is a test option", test1) cmd.AddValue("Test2", "this is a test option", test2) cmd.AddValue["double"]("Test3", "this is a test option", test3) @@ -351,7 +347,7 @@ class TestSimulator(unittest.TestCase): """ ## MyNode class - class MyNode(ns.network.Node): + class MyNode(ns.Node): def GetLocalTime(self) -> ns.Time: return ns.Seconds(10) @@ -367,20 +363,20 @@ class TestSimulator(unittest.TestCase): """ ns.Simulator.Destroy() - nodes = ns.network.NodeContainer() + nodes = ns.NodeContainer() nodes.Create(2) - pointToPoint = ns.point_to_point.PointToPointHelper() - pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) - pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) + pointToPoint = ns.PointToPointHelper() + pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps")) + pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms")) devices = pointToPoint.Install(nodes) - stack = ns.internet.InternetStackHelper() + stack = ns.InternetStackHelper() stack.Install(nodes) - address = ns.internet.Ipv4AddressHelper() - address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) + address = ns.Ipv4AddressHelper() + address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0")) interfaces = address.Assign(devices) @@ -401,7 +397,7 @@ class TestSimulator(unittest.TestCase): ) ## EchoServer application class - class EchoServer(ns.applications.Application): + class EchoServer(ns.Application): LOGGING = False ECHO_PORT = 1234 socketToInstanceDict = {} @@ -419,13 +415,11 @@ class TestSimulator(unittest.TestCase): ## Listen port for the server self.port = port ## Socket used by the server to listen to port - self.m_socket = ns.network.Socket.CreateSocket( - node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory") + self.m_socket = ns.Socket.CreateSocket( + node, ns.TypeId.LookupByName("ns3::UdpSocketFactory") ) self.m_socket.Bind( - ns.network.InetSocketAddress( - ns.network.Ipv4Address.GetAny(), self.port - ).ConvertTo() + ns.InetSocketAddress(ns.Ipv4Address.GetAny(), self.port).ConvertTo() ) self.m_socket.SetRecvCallback(ns.make_rx_callback(EchoServer._Receive)) EchoServer.socketToInstanceDict[self.m_socket] = self @@ -507,18 +501,18 @@ class TestSimulator(unittest.TestCase): serverApps = ns.ApplicationContainer() serverApps.Add(echoServer) - serverApps.Start(ns.core.Seconds(1.0)) - serverApps.Stop(ns.core.Seconds(10.0)) + serverApps.Start(ns.Seconds(1.0)) + serverApps.Stop(ns.Seconds(10.0)) address = interfaces.GetAddress(1).ConvertTo() - echoClient = ns.applications.UdpEchoClientHelper(address, EchoServer.ECHO_PORT) - echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(10)) - echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0))) - echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(101)) + echoClient = ns.UdpEchoClientHelper(address, EchoServer.ECHO_PORT) + echoClient.SetAttribute("MaxPackets", ns.UintegerValue(10)) + echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.0))) + echoClient.SetAttribute("PacketSize", ns.UintegerValue(101)) clientApps = echoClient.Install(nodes.Get(0)) - clientApps.Start(ns.core.Seconds(2.0)) - clientApps.Stop(ns.core.Seconds(10.0)) + clientApps.Start(ns.Seconds(2.0)) + clientApps.Stop(ns.Seconds(10.0)) ns.Simulator.Run() ns.Simulator.Destroy()