diff --git a/examples/routing/simple-routing-ping6.py b/examples/routing/simple-routing-ping6.py index fc0507f45..93ee3239a 100644 --- a/examples/routing/simple-routing-ping6.py +++ b/examples/routing/simple-routing-ping6.py @@ -27,53 +27,53 @@ # router # -from ns.applications import * -from ns.core import * -from ns.csma import * -from ns.internet import * -from ns.network import * +import ns.applications +import ns.core +import ns.csma +import ns.internet +import ns.network def main(argv): - cmd = CommandLine(); + cmd = ns.core.CommandLine(); cmd.Parse(argv); # Create nodes print "Create nodes" - n0 = Node(); - r = Node(); - n1 = Node(); + n0 = ns.network.Node(); + r = ns.network.Node(); + n1 = ns.network.Node(); - net1 = NodeContainer(); + net1 = ns.network.NodeContainer(); net1.Add(n0); net1.Add(r); - net2 = NodeContainer(); + net2 = ns.network.NodeContainer(); net2.Add(r); net2.Add(n1); - all = NodeContainer(); + all = ns.network.NodeContainer(); all.Add(n0); all.Add(r); all.Add(n1); # Create IPv6 Internet Stack - internetv6 = InternetStackHelper(); + internetv6 = ns.internet.InternetStackHelper(); internetv6.Install(all); # Create channels - csma = CsmaHelper(); - csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000))); - csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2))); + csma = ns.csma.CsmaHelper(); + csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))); + csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))); d1 = csma.Install(net1); d2 = csma.Install(net2); # Create networks and assign IPv6 Addresses print "Addressing" - ipv6 = Ipv6AddressHelper(); - ipv6.NewNetwork(Ipv6Address("2001:1::"), Ipv6Prefix(64)); + ipv6 = ns.internet.Ipv6AddressHelper(); + ipv6.NewNetwork(ns.network.Ipv6Address("2001:1::"), ns.network.Ipv6Prefix(64)); i1 = ipv6.Assign(d1); i1.SetRouter(1, True); - ipv6.NewNetwork(Ipv6Address("2001:2::"), Ipv6Prefix(64)); + ipv6.NewNetwork(ns.network.Ipv6Address("2001:2::"), ns.network.Ipv6Prefix(64)); i2 = ipv6.Assign(d2); i2.SetRouter(0, True); @@ -81,28 +81,28 @@ def main(argv): print "Application" packetSize = 1024; maxPacketCount = 5; - interPacketInterval = Seconds(1.); - ping6 = Ping6Helper(); + interPacketInterval = ns.core.Seconds(1.); + ping6 = ns.applications.Ping6Helper(); ping6.SetLocal(i1.GetAddress(0, 1)); ping6.SetRemote(i2.GetAddress(1, 1)); - ping6.SetAttribute("MaxPackets", UintegerValue(maxPacketCount)); - ping6.SetAttribute("Interval", TimeValue(interPacketInterval)); - ping6.SetAttribute("PacketSize", UintegerValue(packetSize)); + ping6.SetAttribute("MaxPackets", ns.core.UintegerValue(maxPacketCount)); + ping6.SetAttribute("Interval", ns.core.TimeValue(interPacketInterval)); + ping6.SetAttribute("PacketSize", ns.core.UintegerValue(packetSize)); - apps = ping6.Install(NodeContainer(net1.Get(0))); - apps.Start(Seconds(2.0)); - apps.Stop(Seconds(20.0)); + apps = ping6.Install(ns.network.NodeContainer(net1.Get(0))); + apps.Start(ns.core.Seconds(2.0)); + apps.Stop(ns.core.Seconds(20.0)); print "Tracing" - ascii = AsciiTraceHelper() + ascii = ns.network.AsciiTraceHelper() csma.EnableAsciiAll(ascii.CreateFileStream("simple-routing-ping6.tr")) csma.EnablePcapAll("simple-routing-ping6", True) # Run Simulation - Simulator.Run() - Simulator.Destroy() + ns.core.Simulator.Run() + ns.core.Simulator.Destroy() if __name__ == '__main__': import sys diff --git a/examples/tutorial/first.py b/examples/tutorial/first.py index 09df62833..ba8b138bb 100644 --- a/examples/tutorial/first.py +++ b/examples/tutorial/first.py @@ -13,47 +13,47 @@ # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # */ -from ns.applications import * -from ns.core import * -from ns.internet import * -from ns.network import * -from ns.point_to_point import * +import ns.applications +import ns.core +import ns.internet +import ns.network +import ns.point_to_point -LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO) -LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO) +ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) +ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) -nodes = NodeContainer() +nodes = ns.network.NodeContainer() nodes.Create(2) -pointToPoint = PointToPointHelper() -pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")) -pointToPoint.SetChannelAttribute("Delay", StringValue("2ms")) +pointToPoint = ns.point_to_point.PointToPointHelper() +pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) +pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) devices = pointToPoint.Install(nodes) -stack = InternetStackHelper() +stack = ns.internet.InternetStackHelper() stack.Install(nodes) -address = Ipv4AddressHelper() -address.SetBase(Ipv4Address("10.1.1.0"), Ipv4Mask("255.255.255.0")) +address = ns.internet.Ipv4AddressHelper() +address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) interfaces = address.Assign (devices); -echoServer = UdpEchoServerHelper(9) +echoServer = ns.applications.UdpEchoServerHelper(9) serverApps = echoServer.Install(nodes.Get(1)) -serverApps.Start(Seconds(1.0)) -serverApps.Stop(Seconds(10.0)) +serverApps.Start(ns.core.Seconds(1.0)) +serverApps.Stop(ns.core.Seconds(10.0)) -echoClient = UdpEchoClientHelper(interfaces.GetAddress(1), 9) -echoClient.SetAttribute("MaxPackets", UintegerValue(1)) -echoClient.SetAttribute("Interval", TimeValue(Seconds (1.0))) -echoClient.SetAttribute("PacketSize", UintegerValue(1024)) +echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 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)) clientApps = echoClient.Install(nodes.Get(0)) -clientApps.Start(Seconds(2.0)) -clientApps.Stop(Seconds(10.0)) +clientApps.Start(ns.core.Seconds(2.0)) +clientApps.Stop(ns.core.Seconds(10.0)) -Simulator.Run() -Simulator.Destroy() +ns.core.Simulator.Run() +ns.core.Simulator.Destroy() diff --git a/examples/wireless/mixed-wireless.py b/examples/wireless/mixed-wireless.py index 2e1b2311d..d5bf3db12 100644 --- a/examples/wireless/mixed-wireless.py +++ b/examples/wireless/mixed-wireless.py @@ -51,7 +51,14 @@ # +----------------+ +----------------+ # -import ns3 +import ns.applications +import ns.core +import ns.csma +import ns.internet +import ns.mobility +import ns.network +import ns.olsr +import ns.wifi # # # # This function will be used below as a trace sink @@ -77,15 +84,15 @@ def main(argv): # 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")) + ns.core.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.StringValue("210")) + ns.core.Config.SetDefault("ns3::OnOffApplication::DataRate", ns.core.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 = ns.core.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) @@ -107,27 +114,27 @@ 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 = ns3.NodeContainer() + backbone = ns.network.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() + wifi = ns.wifi.WifiHelper() + mac = ns.wifi.NqosWifiMacHelper.Default() mac.SetType("ns3::AdhocWifiMac") wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", - "DataMode", ns3.StringValue("OfdmRate54Mbps")) - wifiPhy = ns3.YansWifiPhyHelper.Default() - wifiChannel = ns3.YansWifiChannelHelper.Default() + "DataMode", ns.core.StringValue("OfdmRate54Mbps")) + wifiPhy = ns.wifi.YansWifiPhyHelper.Default() + wifiChannel = ns.wifi.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 = ns.internet.InternetStackHelper() + olsr = ns.olsr.OlsrHelper() internet.SetRoutingHelper(olsr); internet.Install(backbone); # re-initialize for non-olsr routing. @@ -136,25 +143,25 @@ def main(argv): # 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 = ns.internet.Ipv4AddressHelper() + ipAddrs.SetBase(ns.network.Ipv4Address("192.168.0.0"), ns.network.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() + mobility = ns.mobility.MobilityHelper() + positionAlloc = ns.mobility.ListPositionAllocator() x = 0.0 for i in range(backboneNodes): - positionAlloc.Add(ns3.Vector(x, 0.0, 0.0)) + positionAlloc.Add(ns.core.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))) + "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(0, 1000, 0, 1000)), + "Speed", ns.core.RandomVariableValue(ns.core.ConstantVariable(2000)), + "Pause", ns.core.RandomVariableValue(ns.core.ConstantVariable(0.2))) mobility.Install(backbone) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / @@ -165,7 +172,7 @@ def main(argv): # 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")) + ipAddrs.SetBase(ns.network.Ipv4Address("172.16.0.0"), ns.network.Ipv4Mask("255.255.255.0")) for i in range(backboneNodes): print "Configuring local area network for backbone node ", i @@ -174,17 +181,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 = ns3.NodeContainer() + newLanNodes = ns.network.NodeContainer() newLanNodes.Create(lanNodes - 1) # Now, create the container with all nodes on this link - lan = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), newLanNodes) + lan = ns.network.NodeContainer(ns.network.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))) + csma = ns.csma.CsmaHelper() + csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))) + csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))) lanDevices = csma.Install(lan) # # Add the IPv4 protocol stack to the new LAN nodes @@ -209,7 +216,7 @@ def main(argv): # 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")) + ipAddrs.SetBase(ns.network.Ipv4Address("10.0.0.0"), ns.network.Ipv4Mask("255.255.255.0")) for i in range(backboneNodes): print "Configuring wireless network for backbone node ", i @@ -218,32 +225,32 @@ 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 = ns3.NodeContainer() + stas = ns.network.NodeContainer() stas.Create(infraNodes - 1) # Now, create the container with all nodes on this link - infra = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), stas) + infra = ns.network.NodeContainer(ns.network.NodeContainer(backbone.Get(i)), stas) # # Create another ad hoc network and devices # - ssid = ns3.Ssid('wifi-infra' + str(i)) - wifiInfra = ns3.WifiHelper.Default() + ssid = ns.wifi.Ssid('wifi-infra' + str(i)) + wifiInfra = ns.wifi.WifiHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) wifiInfra.SetRemoteStationManager('ns3::ArfWifiManager') - macInfra = ns3.NqosWifiMacHelper.Default(); + macInfra = ns.wifi.NqosWifiMacHelper.Default(); macInfra.SetType("ns3::StaWifiMac", - "Ssid", ns3.SsidValue(ssid), - "ActiveProbing", ns3.BooleanValue(False)) + "Ssid", ns.wifi.SsidValue(ssid), + "ActiveProbing", ns.core.BooleanValue(False)) # setup stas staDevices = wifiInfra.Install(wifiPhy, macInfra, stas) # setup ap. macInfra.SetType("ns3::ApWifiMac", - "Ssid", ns3.SsidValue(ssid), - "BeaconGeneration", ns3.BooleanValue(True), - "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5))) + "Ssid", ns.wifi.SsidValue(ssid), + "BeaconGeneration", ns.core.BooleanValue(True), + "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5))) apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i)) # Collect all of these new devices - infraDevices = ns3.NetDeviceContainer(apDevices, staDevices) + infraDevices = ns.network.NetDeviceContainer(apDevices, staDevices) # Add the IPv4 protocol stack to the nodes in our container # @@ -262,16 +269,16 @@ def main(argv): # The new wireless nodes need a mobility model so we aggregate one # to each of the nodes we just finished building. # - subnetAlloc = ns3.ListPositionAllocator() + subnetAlloc = ns.mobility.ListPositionAllocator() for j in range(infra.GetN()): - subnetAlloc.Add(ns3.Vector(0.0, j, 0.0)) + subnetAlloc.Add(ns.core.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))) + "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(-25, 25, -25, 25)), + "Speed", ns.core.RandomVariableValue(ns.core.ConstantVariable(30)), + "Pause", ns.core.RandomVariableValue(ns.core.ConstantVariable(0.4))) mobility.Install(infra) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / @@ -288,23 +295,23 @@ def main(argv): # 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") + appSource = ns.network.NodeList.GetNode(11) + appSink = ns.network.NodeList.GetNode(13) + remoteAddr = ns.network.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)) + onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", + ns.network.Address(ns.network.InetSocketAddress(remoteAddr, port))) + onoff.SetAttribute("OnTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(1))) + onoff.SetAttribute("OffTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(0))) + apps = onoff.Install(ns.network.NodeContainer(appSource)) + apps.Start(ns.core.Seconds(3.0)) + apps.Stop(ns.core.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)) + sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory", + ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port)) + apps = sink.Install(ns.network.NodeContainer(appSink)) + apps.Start(ns.core.Seconds(3.0)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / # # @@ -317,7 +324,7 @@ def main(argv): # Let's set up some ns-2-like ascii traces, using another helper class # #std.ofstream ascii - #ascii = ns3.AsciiTraceHelper(); + #ascii = ns.core.AsciiTraceHelper(); #stream = ascii.CreateFileStream("mixed-wireless.tr"); #wifiPhy.EnableAsciiAll(stream); #csma.EnableAsciiAll(stream); @@ -329,7 +336,7 @@ def main(argv): # 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 = ns.csma.CsmaHelper() csma.EnablePcapAll("mixed-wireless", False) # #ifdef ENABLE_FOR_TRACING_EXAMPLE @@ -345,11 +352,13 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "Run Simulation." - ns3.Simulator.Stop(ns3.Seconds(stopTime)) - ns3.Simulator.Run() - ns3.Simulator.Destroy() + ns.core.Simulator.Stop(ns.core.Seconds(stopTime)) + ns.core.Simulator.Run() + ns.core.Simulator.Destroy() if __name__ == '__main__': import sys main(sys.argv) + + diff --git a/examples/wireless/wifi-ap.py b/examples/wireless/wifi-ap.py index 512323334..fe67d460b 100644 --- a/examples/wireless/wifi-ap.py +++ b/examples/wireless/wifi-ap.py @@ -22,14 +22,13 @@ import sys -from ns.applications import * -from ns.core import * -from ns.internet import * -from ns.mobility import * -from ns.network import * -from ns.point_to_point import * -from ns.wifi import * - +import ns.applications +import ns.core +import ns.internet +import ns.mobility +import ns.network +import ns.point_to_point +import ns.wifi # void # DevTxTrace (std::string context, Ptr p, Mac48Address address) @@ -78,12 +77,12 @@ from ns.wifi import * # } def SetPosition(node, position): - mobility = node.GetObject(MobilityModel.GetTypeId()) + mobility = node.GetObject(ns.mobility.MobilityModel.GetTypeId()) mobility.SetPosition(position) def GetPosition(node): - mobility = node.GetObject(MobilityModel.GetTypeId()) + mobility = node.GetObject(ns.mobility.MobilityModel.GetTypeId()) return mobility.GetPosition() def AdvancePosition(node): @@ -92,23 +91,23 @@ def AdvancePosition(node): if pos.x >= 210.0: return SetPosition(node, pos) - Simulator.Schedule(Seconds(1.0), AdvancePosition, node) + ns.core.Simulator.Schedule(ns.core.Seconds(1.0), AdvancePosition, node) def main(argv): - Packet.EnablePrinting(); + ns.network.Packet.EnablePrinting(); # enable rts cts all the time. - Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("0")) + ns.core.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns.core.StringValue("0")) # disable fragmentation - Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")) + ns.core.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns.core.StringValue("2200")) - wifi = WifiHelper.Default() - mobility = MobilityHelper() - stas = NodeContainer() - ap = NodeContainer() + wifi = ns.wifi.WifiHelper.Default() + mobility = ns.mobility.MobilityHelper() + stas = ns.network.NodeContainer() + ap = ns.network.NodeContainer() #NetDeviceContainer staDevs; - packetSocket = PacketSocketHelper() + packetSocket = ns.network.PacketSocketHelper() stas.Create(2) ap.Create(1) @@ -117,46 +116,46 @@ def main(argv): packetSocket.Install(stas) packetSocket.Install(ap) - wifiPhy = YansWifiPhyHelper.Default() - wifiChannel = YansWifiChannelHelper.Default() + wifiPhy = ns.wifi.YansWifiPhyHelper.Default() + wifiChannel = ns.wifi.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) - ssid = Ssid("wifi-default") + ssid = ns.wifi.Ssid("wifi-default") wifi.SetRemoteStationManager("ns3::ArfWifiManager") - wifiMac = NqosWifiMacHelper.Default() + wifiMac = ns.wifi.NqosWifiMacHelper.Default() # setup stas. wifiMac.SetType("ns3::StaWifiMac", - "Ssid", SsidValue(ssid), - "ActiveProbing", BooleanValue(False)) + "Ssid", ns.wifi.SsidValue(ssid), + "ActiveProbing", ns.core.BooleanValue(False)) staDevs = wifi.Install(wifiPhy, wifiMac, stas) # setup ap. wifiMac.SetType("ns3::ApWifiMac", - "Ssid", SsidValue(ssid), - "BeaconGeneration", BooleanValue(True), - "BeaconInterval", TimeValue(Seconds(2.5))) + "Ssid", ns.wifi.SsidValue(ssid), + "BeaconGeneration", ns.core.BooleanValue(True), + "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5))) wifi.Install(wifiPhy, wifiMac, ap) # mobility. mobility.Install(stas) mobility.Install(ap) - Simulator.Schedule(Seconds(1.0), AdvancePosition, ap.Get(0)) + ns.core.Simulator.Schedule(ns.core.Seconds(1.0), AdvancePosition, ap.Get(0)) - socket = PacketSocketAddress() + socket = ns.network.PacketSocketAddress() socket.SetSingleDevice(staDevs.Get(0).GetIfIndex()) socket.SetPhysicalAddress(staDevs.Get(1).GetAddress()) socket.SetProtocol(1) - onoff = OnOffHelper("ns3::PacketSocketFactory", Address(socket)) - onoff.SetAttribute("OnTime", RandomVariableValue(ConstantVariable(42))) - onoff.SetAttribute("OffTime", RandomVariableValue(ConstantVariable(0))) + onoff = ns.applications.OnOffHelper("ns3::PacketSocketFactory", ns.network.Address(socket)) + onoff.SetAttribute("OnTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(42))) + onoff.SetAttribute("OffTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(0))) - apps = onoff.Install(NodeContainer(stas.Get(0))) - apps.Start(Seconds(0.5)) - apps.Stop(Seconds(43.0)) + apps = onoff.Install(ns.network.NodeContainer(stas.Get(0))) + apps.Start(ns.core.Seconds(0.5)) + apps.Stop(ns.core.Seconds(43.0)) - Simulator.Stop(Seconds(44.0)) + ns.core.Simulator.Stop(ns.core.Seconds(44.0)) # Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace)); @@ -166,8 +165,8 @@ def main(argv): # Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace)); - Simulator.Run() - Simulator.Destroy() + ns.core.Simulator.Run() + ns.core.Simulator.Destroy() return 0 diff --git a/examples/wireless/wscript b/examples/wireless/wscript index d399869da..773b253bb 100644 --- a/examples/wireless/wscript +++ b/examples/wireless/wscript @@ -6,7 +6,7 @@ def build(bld): obj.source = 'mixed-wireless.cc' bld.register_ns3_script('mixed-wireless.py', ['core', 'mobility', 'wifi', 'applications', 'point-to-point', - 'internet', 'csma', 'olsr', 'config-store', 'tools']) + 'internet', 'csma', 'olsr']) obj = bld.create_ns3_program('wifi-adhoc', ['core', 'mobility', 'wifi', 'applications', 'tools']) obj.source = 'wifi-adhoc.cc' @@ -17,7 +17,7 @@ def build(bld): obj = bld.create_ns3_program('wifi-ap', ['core', 'mobility', 'wifi', 'applications', 'config-store', 'tools']) obj.source = 'wifi-ap.cc' - bld.register_ns3_script('wifi-ap.py', ['internet', 'mobility', 'wifi', 'applications', 'point-to-point']) + bld.register_ns3_script('wifi-ap.py', ['core', 'mobility', 'wifi', 'applications', 'point-to-point']) obj = bld.create_ns3_program('wifi-wired-bridging', ['internet', 'mobility', 'wifi', 'csma', 'bridge', 'applications']) obj.source = 'wifi-wired-bridging.cc' diff --git a/src/bridge/examples/csma-bridge.py b/src/bridge/examples/csma-bridge.py index 31d654dcc..56303e84c 100644 --- a/src/bridge/examples/csma-bridge.py +++ b/src/bridge/examples/csma-bridge.py @@ -28,7 +28,12 @@ # - DropTail queues # - Tracing of queues and packet receptions to file "csma-bridge.tr" -import ns3 +import ns.applications +import ns.bridge +import ns.core +import ns.csma +import ns.internet +import ns.network def main(argv): @@ -37,51 +42,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 = ns3.CommandLine() + cmd = ns.core.CommandLine() cmd.Parse(argv) # # Explicitly create the nodes required by the topology(shown above). # #print "Create nodes." - terminals = ns3.NodeContainer() + terminals = ns.network.NodeContainer() terminals.Create(4) - csmaSwitch = ns3.NodeContainer() + csmaSwitch = ns.network.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))) + csma = ns.csma.CsmaHelper() + csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))) + csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))) # Create the csma links, from each terminal to the switch - terminalDevices = ns3.NetDeviceContainer() - switchDevices = ns3.NetDeviceContainer() + terminalDevices = ns.network.NetDeviceContainer() + switchDevices = ns.network.NetDeviceContainer() for i in range(4): - link = csma.Install(ns3.NodeContainer(ns3.NodeContainer(terminals.Get(i)), csmaSwitch)) + link = csma.Install(ns.network.NodeContainer(ns.network.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() + bridgeDevice = ns.bridge.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 = ns.internet.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 = ns.internet.Ipv4AddressHelper() + ipv4.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) ipv4.Assign(terminalDevices) # @@ -90,40 +95,40 @@ def main(argv): #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))) + onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", + ns.network.Address(ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.2"), port))) + onoff.SetAttribute("OnTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(1))) + onoff.SetAttribute("OffTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(0))) - app = onoff.Install(ns3.NodeContainer(terminals.Get(0))) + app = onoff.Install(ns.network.NodeContainer(terminals.Get(0))) # Start the application - app.Start(ns3.Seconds(1.0)) - app.Stop(ns3.Seconds(10.0)) + app.Start(ns.core.Seconds(1.0)) + app.Stop(ns.core.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)) + sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory", + ns.network.Address(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port))) + app = sink.Install(ns.network.NodeContainer(terminals.Get(1))) + app.Start(ns.core.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)) + ns.network.AddressValue(ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.1"), port))) + app = onoff.Install(ns.network.NodeContainer(terminals.Get(3))) + app.Start(ns.core.Seconds(1.1)) + app.Stop(ns.core.Seconds(10.0)) - app = sink.Install(ns3.NodeContainer(terminals.Get(0))) - app.Start(ns3.Seconds(0.0)) + app = sink.Install(ns.network.NodeContainer(terminals.Get(0))) + app.Start(ns.core.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(); + #ascii = ns.network.AsciiTraceHelper(); #csma.EnableAsciiAll(ascii.CreateFileStream ("csma-bridge.tr")); # @@ -139,8 +144,8 @@ def main(argv): # Now, do the actual simulation. # #print "Run Simulation." - ns3.Simulator.Run() - ns3.Simulator.Destroy() + ns.core.Simulator.Run() + ns.core.Simulator.Destroy() #print "Done." diff --git a/src/core/examples/sample-rng-plot.py b/src/core/examples/sample-rng-plot.py index eace4c601..eef70a851 100644 --- a/src/core/examples/sample-rng-plot.py +++ b/src/core/examples/sample-rng-plot.py @@ -19,10 +19,10 @@ import numpy as np import matplotlib.pyplot as plt -import ns3 +import ns.core # mu, var = 100, 225 -rng = ns3.NormalVariable(100.0, 225.0) +rng = ns.core.NormalVariable(100.0, 225.0) x = [rng.GetValue() for t in range(10000)] # the histogram of the data diff --git a/src/core/examples/sample-simulator.py b/src/core/examples/sample-simulator.py index cca50e4f0..3c8acc4c3 100644 --- a/src/core/examples/sample-simulator.py +++ b/src/core/examples/sample-simulator.py @@ -20,23 +20,23 @@ # # Python version of sample-simulator.cc -import ns3 as ns +import ns.core class MyModel(object): def Start(self): - ns.Simulator.Schedule(ns.Seconds(10.0), self.HandleEvent, ns.Simulator.Now().GetSeconds()) + ns.core.Simulator.Schedule(ns.core.Seconds(10.0), self.HandleEvent, ns.core.Simulator.Now().GetSeconds()) def HandleEvent(self, value): - print "Member method received event at", ns.Simulator.Now().GetSeconds(), \ + print "Member method received event at", ns.core.Simulator.Now().GetSeconds(), \ "s started at", value, "s" def ExampleFunction(model): - print "ExampleFunction received event at", ns.Simulator.Now().GetSeconds(), "s" + print "ExampleFunction received event at", ns.core.Simulator.Now().GetSeconds(), "s" model.Start() def RandomFunction(model): - print "RandomFunction received event at", ns.Simulator.Now().GetSeconds(), "s" + print "RandomFunction received event at", ns.core.Simulator.Now().GetSeconds(), "s" def CancelledEvent(): print "I should never be called... " @@ -44,18 +44,18 @@ def CancelledEvent(): def main(dummy_argv): model = MyModel() - v = ns.UniformVariable(10,20) + v = ns.core.UniformVariable(10,20) - ns.Simulator.Schedule(ns.Seconds(10.0), ExampleFunction, model) + ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ExampleFunction, model) - ns.Simulator.Schedule(ns.Seconds(v.GetValue()), RandomFunction, model) + ns.core.Simulator.Schedule(ns.core.Seconds(v.GetValue()), RandomFunction, model) - id = ns.Simulator.Schedule(ns.Seconds(30.0), CancelledEvent) - ns.Simulator.Cancel(id) + id = ns.core.Simulator.Schedule(ns.core.Seconds(30.0), CancelledEvent) + ns.core.Simulator.Cancel(id) - ns.Simulator.Run() + ns.core.Simulator.Run() - ns.Simulator.Destroy() + ns.core.Simulator.Destroy() if __name__ == '__main__': import sys diff --git a/src/flow-monitor/examples/wifi-olsr-flowmon.py b/src/flow-monitor/examples/wifi-olsr-flowmon.py index e0475a816..9ac6a740d 100644 --- a/src/flow-monitor/examples/wifi-olsr-flowmon.py +++ b/src/flow-monitor/examples/wifi-olsr-flowmon.py @@ -17,14 +17,22 @@ # Authors: Gustavo Carneiro import sys -import ns3 + +import ns.applications +import ns.core +import ns.flow_monitor +import ns.internet +import ns.mobility +import ns.network +import ns.olsr +import ns.wifi DISTANCE = 100 # (m) NUM_NODES_SIDE = 3 def main(argv): - cmd = ns3.CommandLine() + cmd = ns.core.CommandLine() cmd.NumNodesSide = None cmd.AddValue("NumNodesSide", "Grid side number of nodes (total number of nodes will be this number squared)") @@ -37,33 +45,33 @@ def main(argv): cmd.Parse(argv) - wifi = ns3.WifiHelper.Default() - wifiMac = ns3.NqosWifiMacHelper.Default() - wifiPhy = ns3.YansWifiPhyHelper.Default() - wifiChannel = ns3.YansWifiChannelHelper.Default() + wifi = ns.wifi.WifiHelper.Default() + wifiMac = ns.wifi.NqosWifiMacHelper.Default() + wifiPhy = ns.wifi.YansWifiPhyHelper.Default() + wifiChannel = ns.wifi.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) - ssid = ns3.Ssid("wifi-default") + ssid = ns.wifi.Ssid("wifi-default") wifi.SetRemoteStationManager("ns3::ArfWifiManager") wifiMac.SetType ("ns3::AdhocWifiMac", - "Ssid", ns3.SsidValue(ssid)) + "Ssid", ns.wifi.SsidValue(ssid)) - internet = ns3.InternetStackHelper() - list_routing = ns3.Ipv4ListRoutingHelper() - olsr_routing = ns3.OlsrHelper() - static_routing = ns3.Ipv4StaticRoutingHelper() + internet = ns.internet.InternetStackHelper() + list_routing = ns.internet.Ipv4ListRoutingHelper() + olsr_routing = ns.olsr.OlsrHelper() + static_routing = ns.internet.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")) + ipv4Addresses = ns.internet.Ipv4AddressHelper() + ipv4Addresses.SetBase(ns.network.Ipv4Address("10.0.0.0"), ns.network.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))) + onOffHelper = ns.applications.OnOffHelper("ns3::UdpSocketFactory", + ns.network.Address(ns.network.InetSocketAddress(ns.network.Ipv4Address("10.0.0.1"), port))) + onOffHelper.SetAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate("100kbps"))) + onOffHelper.SetAttribute("OnTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(1))) + onOffHelper.SetAttribute("OffTime", ns.core.RandomVariableValue(ns.core.ConstantVariable(0))) addresses = [] nodes = [] @@ -76,13 +84,13 @@ def main(argv): for xi in range(num_nodes_side): for yi in range(num_nodes_side): - node = ns3.Node() + node = ns.network.Node() nodes.append(node) - internet.Install(ns3.NodeContainer(node)) + internet.Install(ns.network.NodeContainer(node)) - mobility = ns3.ConstantPositionMobilityModel() - mobility.SetPosition(ns3.Vector(xi*DISTANCE, yi*DISTANCE, 0)) + mobility = ns.mobility.ConstantPositionMobilityModel() + mobility.SetPosition(ns.core.Vector(xi*DISTANCE, yi*DISTANCE, 0)) node.AggregateObject(mobility) devices = wifi.Install(wifiPhy, wifiMac, node) @@ -92,20 +100,20 @@ def main(argv): 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())) + onOffHelper.SetAttribute("Remote", ns.network.AddressValue(ns.network.InetSocketAddress(destaddr, port))) + app = onOffHelper.Install(ns.network.NodeContainer(node)) + app.Start(ns.core.Seconds(ns.core.UniformVariable(20, 30).GetValue())) #internet.EnablePcapAll("wifi-olsr") - flowmon_helper = ns3.FlowMonitorHelper() - #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31))) + flowmon_helper = ns.flow_monitor.FlowMonitorHelper() + #flowmon_helper.SetMonitorAttribute("StartTime", ns.core.TimeValue(ns.core.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)) + monitor.SetAttribute("DelayBinWidth", ns.core.DoubleValue(0.001)) + monitor.SetAttribute("JitterBinWidth", ns.core.DoubleValue(0.001)) + monitor.SetAttribute("PacketSizeBinWidth", ns.core.DoubleValue(20)) - ns3.Simulator.Stop(ns3.Seconds(44.0)) - ns3.Simulator.Run() + ns.core.Simulator.Stop(ns.core.Seconds(44.0)) + ns.core.Simulator.Run() def print_stats(os, st): print >> os, " Tx Bytes: ", st.txBytes diff --git a/src/flow-monitor/examples/wscript b/src/flow-monitor/examples/wscript index c8e3657bd..19d41b7e7 100644 --- a/src/flow-monitor/examples/wscript +++ b/src/flow-monitor/examples/wscript @@ -1,4 +1,4 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - bld.register_ns3_script('wifi-olsr-flowmon.py', ['flow-monitor', 'internet', 'tools', 'config-store', 'wifi', 'olsr', 'applications', 'mobility', 'csma', 'network', 'point-to-point']) + bld.register_ns3_script('wifi-olsr-flowmon.py', ['flow-monitor', 'internet', 'wifi', 'olsr', 'applications', 'mobility'])