From eb8063fae5d4fb889d97bfc54187a7e99f6c6498 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Tue, 6 Mar 2018 14:16:20 -0600 Subject: [PATCH] python: fix examples for python 3.6 --- examples/realtime/realtime-udp-echo.py | 2 +- examples/routing/simple-routing-ping6.py | 8 ++++---- examples/tutorial/third.py | 2 +- examples/wireless/mixed-wired-wireless.py | 14 +++++++------- src/core/examples/sample-simulator.py | 10 +++++----- src/flow-monitor/examples/wifi-olsr-flowmon.py | 12 ++++++------ 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/realtime/realtime-udp-echo.py b/examples/realtime/realtime-udp-echo.py index 626ef3afb..b20cdf8c9 100644 --- a/examples/realtime/realtime-udp-echo.py +++ b/examples/realtime/realtime-udp-echo.py @@ -46,7 +46,7 @@ def main(argv): # # Explicitly create the nodes required by the topology (shown above). # - print "Create nodes." + print ("Create nodes.") n = ns.network.NodeContainer() n.Create(4) diff --git a/examples/routing/simple-routing-ping6.py b/examples/routing/simple-routing-ping6.py index 14843d396..fd08bbea7 100644 --- a/examples/routing/simple-routing-ping6.py +++ b/examples/routing/simple-routing-ping6.py @@ -40,7 +40,7 @@ def main(argv): cmd.Parse(argv); # Create nodes - print "Create nodes" + print ("Create nodes") n0 = ns.network.Node(); r = ns.network.Node(); n1 = ns.network.Node(); @@ -68,7 +68,7 @@ def main(argv): d2 = csma.Install(net2); # Create networks and assign IPv6 Addresses - print "Addressing" + print ("Addressing") ipv6 = ns.internet.Ipv6AddressHelper(); ipv6.SetBase(ns.network.Ipv6Address("2001:1::"), ns.network.Ipv6Prefix(64)); i1 = ipv6.Assign(d1); @@ -80,7 +80,7 @@ def main(argv): i2.SetDefaultRouteInAllNodes(0); # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r - print "Application" + print ("Application") packetSize = 1024; maxPacketCount = 5; interPacketInterval = ns.core.Seconds(1.); @@ -97,7 +97,7 @@ def main(argv): apps.Start(ns.core.Seconds(2.0)); apps.Stop(ns.core.Seconds(20.0)); - print "Tracing" + print ("Tracing") ascii = ns.network.AsciiTraceHelper() csma.EnableAsciiAll(ascii.CreateFileStream("simple-routing-ping6.tr")) csma.EnablePcapAll("simple-routing-ping6", True) diff --git a/examples/tutorial/third.py b/examples/tutorial/third.py index 12fa3218a..d022f8498 100644 --- a/examples/tutorial/third.py +++ b/examples/tutorial/third.py @@ -52,7 +52,7 @@ verbose = cmd.verbose nWifi = int(cmd.nWifi) if nWifi > 18: - print "Number of wifi nodes "+ str(nWifi)+ " specified exceeds the mobility bounding box" + print ("Number of wifi nodes "+ str(nWifi)+ " specified exceeds the mobility bounding box") sys.exit(1) if verbose == "True": diff --git a/examples/wireless/mixed-wired-wireless.py b/examples/wireless/mixed-wired-wireless.py index 55e8cbf2b..11e2a1857 100644 --- a/examples/wireless/mixed-wired-wireless.py +++ b/examples/wireless/mixed-wired-wireless.py @@ -112,7 +112,7 @@ def main(argv): stopTime = int(cmd.stopTime) if (stopTime < 10): - print "Use a simulation stop time >= 10 seconds" + print ("Use a simulation stop time >= 10 seconds") exit(1) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / # # @@ -142,7 +142,7 @@ def main(argv): # # Add the IPv4 protocol stack to the nodes in our container # - print "Enabling OLSR routing on all backbone nodes" + print ("Enabling OLSR routing on all backbone nodes") internet = ns.internet.InternetStackHelper() olsr = ns.olsr.OlsrHelper() internet.SetRoutingHelper(olsr); # has effect on the next Install () @@ -186,7 +186,7 @@ def main(argv): 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 + print ("Configuring local area network for backbone node ", i) # # Create a container to manage the nodes of the LAN. We need # two containers here; one with all of the new nodes, and one @@ -243,7 +243,7 @@ def main(argv): 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 + print ("Configuring wireless network for backbone node ", i) # # Create a container to manage the nodes of the LAN. We need # two containers here; one with all of the new nodes, and one @@ -311,7 +311,7 @@ def main(argv): # Create the OnOff application to send UDP datagrams of size # 210 bytes at a rate of 448 Kb/s, between two nodes - print "Create Applications." + print ("Create Applications.") port = 9 # Discard port(RFC 863) appSource = ns.network.NodeList.GetNode(backboneNodes) @@ -338,7 +338,7 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / - print "Configure Tracing." + print ("Configure Tracing.") csma = ns.csma.CsmaHelper() # # Let's set up some ns-2-like ascii traces, using another helper class @@ -367,7 +367,7 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - print "Run Simulation." + print ("Run Simulation.") ns.core.Simulator.Stop(ns.core.Seconds(stopTime)) ns.core.Simulator.Run() ns.core.Simulator.Destroy() diff --git a/src/core/examples/sample-simulator.py b/src/core/examples/sample-simulator.py index 8d126b4cd..b237da7d1 100755 --- a/src/core/examples/sample-simulator.py +++ b/src/core/examples/sample-simulator.py @@ -41,18 +41,18 @@ class MyModel(object): ## \return None. def HandleEvent(self, value): """Simple event handler.""" - print "Member method received event at", ns.core.Simulator.Now().GetSeconds(), \ - "s started at", value, "s" + 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.core.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.core.Simulator.Now().GetSeconds(), "s" + print ("RandomFunction received event at", ns.core.Simulator.Now().GetSeconds(), "s") def CancelledEvent(): - print "I should never be called... " + print ("I should never be called... ") def main(dummy_argv): ns.core.CommandLine().Parse(dummy_argv) diff --git a/src/flow-monitor/examples/wifi-olsr-flowmon.py b/src/flow-monitor/examples/wifi-olsr-flowmon.py index 80cecaa34..f2184617f 100644 --- a/src/flow-monitor/examples/wifi-olsr-flowmon.py +++ b/src/flow-monitor/examples/wifi-olsr-flowmon.py @@ -103,7 +103,7 @@ def main(argv): for i, node in enumerate(nodes): destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)] - #print i, destaddr + #print (i, destaddr) onOffHelper.SetAttribute("Remote", ns.network.AddressValue(ns.network.InetSocketAddress(destaddr, port))) app = onOffHelper.Install(ns.network.NodeContainer(node)) urv = ns.core.UniformRandomVariable() @@ -129,7 +129,7 @@ def main(argv): print >> os, " Lost Packets: ", st.lostPackets if st.rxPackets > 0: print >> os, " Mean{Delay}: ", (st.delaySum.GetSeconds() / st.rxPackets) - print >> os, " Mean{Jitter}: ", (st.jitterSum.GetSeconds() / (st.rxPackets-1)) + print >> os, " Mean{Jitter}: ", (st.jitterSum.GetSeconds() / (st.rxPackets-1)) print >> os, " Mean{Hop Count}: ", float(st.timesForwarded) / st.rxPackets + 1 if 0: @@ -147,7 +147,7 @@ def main(argv): st.packetSizeHistogram.GetBinEnd (i), "): ", st.packetSizeHistogram.GetBinCount (i) for reason, drops in enumerate(st.packetsDropped): - print " Packets dropped by reason %i: %i" % (reason, drops) + print (" Packets dropped by reason %i: %i" % (reason, drops)) #for reason, drops in enumerate(st.bytesDropped): # print "Bytes dropped by reason %i: %i" % (reason, drops) @@ -158,11 +158,11 @@ def main(argv): for flow_id, flow_stats in monitor.GetFlowStats(): t = classifier.FindFlow(flow_id) proto = {6: 'TCP', 17: 'UDP'} [t.protocol] - print "FlowID: %i (%s %s/%s --> %s/%i)" % \ - (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort) + print ("FlowID: %i (%s %s/%s --> %s/%i)" % \ + (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort)) print_stats(sys.stdout, flow_stats) else: - print monitor.SerializeToXmlFile(cmd.Results, True, True) + print (monitor.SerializeToXmlFile(cmd.Results, True, True)) if cmd.Plot is not None: