dos2unix'ed
[nepi.git] / examples / openvswitch / ovs_ping_3switches_loop.py
index 3052b78..bd246da 100644 (file)
@@ -4,9 +4,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -70,10 +69,10 @@ def add_port(ec, port_name, network, ovs):
     ec.register_connection(port, ovs)
     return port
 
-def add_tap(ec, endpoint_ip, endpoint_prefix, pointopoint, node):
+def add_tap(ec, ip, prefix, pointopoint, node):
     tap = ec.register_resource("planetlab::Tap")
-    ec.set(tap, "endpoint_ip", endpoint_ip)
-    ec.set(tap, "endpoint_prefix", endpoint_prefix)
+    ec.set(tap, "ip", ip)
+    ec.set(tap, "prefix", prefix)
     ec.set(tap, "pointopoint", pointopoint)
     ec.set(tap, "up", True)
     ec.register_connection(tap, node)
@@ -139,9 +138,9 @@ h2_node = add_node(ec, host2, slicename, pl_user, pl_password)
 h3_node = add_node(ec, host3, slicename, pl_user, pl_password)
 
 # Add tap devices
-tap1 = add_tap(ec, "192.168.3.1", 24, "192.168.3.2", h1_node)
-tap2 = add_tap(ec, "192.168.3.3", 24, "192.168.3.4", h2_node)
-tap3 = add_tap(ec, "192.168.3.5", 24, "192.168.3.6", h3_node)
+tap1 = add_tap(ec, "192.168.3.1", "24", "192.168.3.2", h1_node)
+tap2 = add_tap(ec, "192.168.3.3", "24", "192.168.3.4", h2_node)
+tap3 = add_tap(ec, "192.168.3.5", "24", "192.168.3.6", h3_node)
 
 # Connect the nodes
 tunnel1 = add_tunnel(ec, port1, tap1)
@@ -185,36 +184,35 @@ ping11 = ec.trace(app11, 'stdout')
 ping12 = ec.trace(app12, 'stdout')
 
 
-f = open("examples/openvswitch/ovs_ping_3switches_loop.txt", 'w')
-
-if not ping12:
-  ec.shutdown()
-
-f.write("************ Ping From Switch 1 : 192.168.3.2 ********************\n\n")
-f.write(ping1)
-f.write("--------------------------------------\n")
-f.write(ping2)
-f.write("************ Ping From Switch 2 : 192.168.3.4 ********************\n\n")
-f.write(ping3)
-f.write("--------------------------------------\n")
-f.write(ping4)
-f.write("************ Ping From Switch 3 : 192.168.3.6 ********************\n\n")
-f.write(ping5)
-f.write("--------------------------------------\n")
-f.write(ping6)
-f.write("************ Ping From Host 1 : 192.168.3.1 ********************\n\n")
-f.write(ping7)
-f.write("--------------------------------------\n")
-f.write(ping8)
-f.write("************ Ping From Host 2 : 192.168.3.3 ********************\n\n")
-f.write(ping9)
-f.write("--------------------------------------\n")
-f.write(ping10)
-f.write("************ Ping From Host 3 : 192.168.3.5 ********************\n\n")
-f.write(ping11)
-f.write("--------------------------------------\n")
-f.write(ping12)
-f.close()
+with open("examples/openvswitch/ovs_ping_3switches_loop.txt", 'w') as f:
+
+    if not ping12:
+        ec.shutdown()
+
+    f.write("************ Ping From Switch 1 : 192.168.3.2 ********************\n\n")
+    f.write(ping1)
+    f.write("--------------------------------------\n")
+    f.write(ping2)
+    f.write("************ Ping From Switch 2 : 192.168.3.4 ********************\n\n")
+    f.write(ping3)
+    f.write("--------------------------------------\n")
+    f.write(ping4)
+    f.write("************ Ping From Switch 3 : 192.168.3.6 ********************\n\n")
+    f.write(ping5)
+    f.write("--------------------------------------\n")
+    f.write(ping6)
+    f.write("************ Ping From Host 1 : 192.168.3.1 ********************\n\n")
+    f.write(ping7)
+    f.write("--------------------------------------\n")
+    f.write(ping8)
+    f.write("************ Ping From Host 2 : 192.168.3.3 ********************\n\n")
+    f.write(ping9)
+    f.write("--------------------------------------\n")
+    f.write(ping10)
+    f.write("************ Ping From Host 3 : 192.168.3.5 ********************\n\n")
+    f.write(ping11)
+    f.write("--------------------------------------\n")
+    f.write(ping12)
 
 # Delete the overlay network
 ec.shutdown()