use print() - import print_function - should be fine for both py2 and py3
[nepi.git] / examples / openvswitch / ovs_ping_2_switches.py
index 6519dd2..a28bef2 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
 #          Alina Quereilhac <alina.quereilhac@inria.fr>
 #
 # Topology :
-# 
+#
+#         x.x.x.1          x.x.x.2
 #         Switch1 -------- Switch2         
 #            /                \           
 #           /                  \          
 #          /                    \         
 #       Host1                  Host2      
-#
+#       x.x.x.3                x.x.x.4
 #
 # Execution example:  
 # 
 # $ PYTHONPATH=$PYTHONPATH:src/ python examples/openvswitch/ovs_ping_2_switches.py -n "192.168.3.0/24" -C "1.1.1.1" -s <slicename> -i /~/.ssh/id_rsa
 #
 
+from __future__ import print_function
+
 from nepi.execution.ec import ExperimentController
 
 import os
@@ -78,7 +80,6 @@ def add_tap(ec, ip, prefix, pointopoint, node):
     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)
     return tap
 
@@ -190,90 +191,17 @@ tunnel1 = add_tunnel(ec, port1, tap1)
 tunnel2 = add_tunnel(ec, port2, tap2)
 tunnel3 = add_tunnel(ec, port3, port4)
 
-### Add Pings
-# Ping switch 1 to switch2
-app1 = add_app(ec, "ping -c5 %s" % ip2, s1_node)
-# Ping switch 1 to host1
-app2 = add_app(ec, "ping -c5 %s" % ip3, s1_node)
-# Ping switch 1 to host2
-app3 = add_app(ec, "ping -c5 %s" % ip4, s1_node)
-
-# Ping switch 2 to switch1
-app4 = add_app(ec, "ping -c5 %s" % ip1, s2_node)
-# Ping switch 2 to host1
-app5 = add_app(ec, "ping -c5 %s" % ip3, s2_node)
-# Ping switch 2 to host2
-app6 = add_app(ec, "ping -c5 %s" % ip4, s2_node)
-
-# Ping host 1 to switch 1
-app7 = add_app(ec, "ping -c5 %s" % ip1, h1_node)
-# Ping host 1 to switch 2
-app8 = add_app(ec, "ping -c5 %s" % ip2, h1_node)
-# Ping host 1 to host 2
-app9 = add_app(ec, "ping -c5 %s" % ip4, h1_node)
-
-# Ping host 2 to switch 1
-app10 = add_app(ec, "ping -c5 %s" % ip1, h2_node)
-# Ping host 2 to switch 2
-app11 = add_app(ec, "ping -c5 %s" % ip2, h2_node)
-# Ping host 2 to host1
-app12 = add_app(ec, "ping -c5 %s" % ip3, h2_node)
+### Add Ping
+app = add_app(ec, "ping -c5 %s" % ip4, h1_node)
 
 ec.deploy()
 
-ec.wait_finished([app1, app2, app3, app4, app5, app6, 
-    app7, app8, app9, app10, app11, app12])
+ec.wait_finished([app])
 
 # Retreive ping results and save them in a file
-ping1 = ec.trace(app1, "stdout")
-ping2 = ec.trace(app2, "stdout")
-ping3 = ec.trace(app3, "stdout")
-ping4 = ec.trace(app4, "stdout")
-ping5 = ec.trace(app5, "stdout")
-ping6 = ec.trace(app6, "stdout")
-ping7 = ec.trace(app7, "stdout")
-ping8 = ec.trace(app8, "stdout")
-ping9 = ec.trace(app9, "stdout")
-ping10 = ec.trace(app10, "stdout")
-ping11 = ec.trace(app11, "stdout")
-ping12 = ec.trace(app12, "stdout")
-
-if not ping12:
-  ec.shutdown()
-  sys.exit("No ping found")
-
-f = open("ovs_ping_2_switches.txt", 'w')
-f.write("************ Ping From Switch 1 : %s ********************\n\n\n" % ip1)
-f.write(ping1)
-f.write("----------------------------------------\n\n")
-f.write(ping2)
-f.write("----------------------------------------\n\n")
-f.write(ping3)
-
-f.write("************ Ping From Switch 2 : %s ********************\n\n\n" % ip2)
-f.write(ping4)
-f.write("----------------------------------------\n\n")
-f.write(ping5)
-f.write("----------------------------------------\n\n")
-f.write(ping6)
-
-f.write("************ Ping From Host 1 : %s ********************\n\n\n" % ip3)
-f.write(ping7)
-f.write("----------------------------------------\n\n")
-f.write(ping8)
-f.write("----------------------------------------\n\n")
-f.write(ping9)
-
-f.write("************ Ping From Host 2 : %s ********************\n\n\n" % ip4)
-f.write(ping10)
-f.write("----------------------------------------\n\n")
-f.write(ping11)
-f.write("----------------------------------------\n\n")
-f.write(ping12)
-
-f.close()
+stdout = ec.trace(app, "stdout")
 
 # Delete the overlay network
 ec.shutdown()
 
-
+print(stdout)