python: fix examples for python 3.6

This commit is contained in:
Tommaso Pecorella
2018-03-06 14:16:20 -06:00
parent 2cb872f436
commit eb8063fae5
6 changed files with 24 additions and 24 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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":

View File

@@ -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()

View File

@@ -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)

View File

@@ -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: