From c2acc774e82685942698b64e8ca7b4a27200e5dc Mon Sep 17 00:00:00 2001 From: Julien Tribino Date: Fri, 14 Feb 2014 16:54:44 +0100 Subject: [PATCH 1/1] Updated 1st version working of Openflow with examples. It still need to merge the tunnel --- ...{ovs_ping_exp.py => ovs_ping_2switches.py} | 24 +- .../openvswitch/ovs_ping_3switches_line.py | 210 +++++++++++++ .../openvswitch/ovs_ping_3switches_loop.py | 210 +++++++++++++ src/nepi/resources/linux/udptunnel.py | 2 +- .../resources/planetlab/openvswitch/ovs.py | 143 ++++----- .../planetlab/openvswitch/ovsport.py | 95 +++--- .../resources/planetlab/openvswitch/tunnel.py | 288 +++++++++--------- src/nepi/resources/planetlab/tap.py | 2 +- 8 files changed, 711 insertions(+), 263 deletions(-) rename examples/openvswitch/{ovs_ping_exp.py => ovs_ping_2switches.py} (83%) create mode 100644 examples/openvswitch/ovs_ping_3switches_line.py create mode 100644 examples/openvswitch/ovs_ping_3switches_loop.py diff --git a/examples/openvswitch/ovs_ping_exp.py b/examples/openvswitch/ovs_ping_2switches.py similarity index 83% rename from examples/openvswitch/ovs_ping_exp.py rename to examples/openvswitch/ovs_ping_2switches.py index 18c2f158..6b1c3142 100644 --- a/examples/openvswitch/ovs_ping_exp.py +++ b/examples/openvswitch/ovs_ping_2switches.py @@ -29,6 +29,7 @@ from nepi.execution.ec import ExperimentController import os, time +import sys def add_node(ec, host, user, pl_user, pl_password): node = ec.register_resource("PlanetlabNode") @@ -88,6 +89,7 @@ switch2 = "planetlab2.upc.es" host1 = "planetlab2.ionio.gr" host2 = "iraplab2.iralab.uni-karlsruhe.de" +ip_controller = "194.254.215.12" network = "192.168.3.0" slicename = "inria_nepi" @@ -99,8 +101,8 @@ s1_node = add_node(ec, switch1, slicename, pl_user, pl_password) s2_node = add_node(ec, switch2, slicename, pl_user, pl_password) # Add switches -ovs1 = add_ovs(ec, "nepi_bridge", "192.168.3.1/24", "85.23.168.77", "6633", s1_node) -ovs2 = add_ovs(ec, "nepi_bridge", "192.168.3.2/24", "85.23.168.77", "6633", s2_node) +ovs1 = add_ovs(ec, "nepi_bridge_1", "192.168.3.1/24", ip_controller, "6633", s1_node) +ovs2 = add_ovs(ec, "nepi_bridge_2", "192.168.3.2/24", ip_controller, "6633", s2_node) # Add ports on ovs port1 = add_port(ec, "nepi_port1", ovs1) @@ -153,24 +155,36 @@ ping10 = ec.trace(app10, 'stdout') ping11 = ec.trace(app11, 'stdout') ping12 = ec.trace(app12, 'stdout') - -f = open("examples/openvswitch/ping_res.txt", 'w') - if not ping12: ec.shutdown() + sys.exit("No ping found") +f = open("examples/openvswitch/ovs_ping_2switches.txt", 'w') +f.write("************ Ping From Switch 1 : 192.168.3.1 ********************\n\n") f.write(ping1) +f.write("----------------------------------------\n\n") f.write(ping2) +f.write("----------------------------------------\n\n") f.write(ping3) +f.write("************ Ping From Switch 2 : 192.168.3.2 ********************\n\n") f.write(ping4) +f.write("----------------------------------------\n\n") f.write(ping5) +f.write("----------------------------------------\n\n") f.write(ping6) +f.write("************ Ping From Host 1 : 192.168.3.3 ********************\n\n") f.write(ping7) +f.write("----------------------------------------\n\n") f.write(ping8) +f.write("----------------------------------------\n\n") f.write(ping9) +f.write("************ Ping From Host 2 : 192.168.3.4 ********************\n\n") f.write(ping10) +f.write("----------------------------------------\n\n") f.write(ping11) +f.write("----------------------------------------\n\n") f.write(ping12) + f.close() # Delete the overlay network diff --git a/examples/openvswitch/ovs_ping_3switches_line.py b/examples/openvswitch/ovs_ping_3switches_line.py new file mode 100644 index 00000000..4980a771 --- /dev/null +++ b/examples/openvswitch/ovs_ping_3switches_line.py @@ -0,0 +1,210 @@ +#!/usr/bin/env python +# +# NEPI, a framework to manage network experiments +# 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac +# Alexandros Kouvakas +# +# Switch1 ------- Switch2 +# / \ +# / \ +# / \ +# Host1 Host2 + + + +from nepi.execution.ec import ExperimentController +import os, time + +def add_node(ec, host, user, pl_user, pl_password): + node = ec.register_resource("PlanetlabNode") + ec.set(node, "hostname", host) + ec.set(node, "username", user) + if pl_user: + ec.set(node, "pluser", pl_user) + if pl_password: + ec.set(node, "plpassword", pl_password) + ec.set(node, "cleanHome", True) + ec.set(node, "cleanProcesses", True) + + return node + +def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node): + ovs = ec.register_resource("OVSWitch") + ec.set(ovs, "bridge_name", bridge_name) + ec.set(ovs, "virtual_ip_pref", virtual_ip_pref) + ec.set(ovs, "controller_ip", controller_ip) + ec.set(ovs, "controller_port", controller_port) + ec.register_connection(ovs, node) + return ovs + +def add_port(ec, port_name, ovs): + port = ec.register_resource("OVSPort") + ec.set(port, "port_name", port_name) + ec.register_connection(port, ovs) + return port + +def add_tap(ec, ip4, prefix4, pointopoint, node): + tap = ec.register_resource("PlanetlabTap") + ec.set(tap, "ip4", ip4) + ec.set(tap, "prefix4", prefix4) + ec.set(tap, "pointopoint", pointopoint) + ec.set(tap, "up", True) + ec.register_connection(tap, node) + return tap + +def add_tunnel(ec, network, port0, tap): + tunnel = ec.register_resource("OVSTunnel") + ec.set(tunnel, "network", network) + ec.register_connection(port0, tunnel) + ec.register_connection(tunnel, tap) + return tunnel + +def add_app(ec, command, node): + app = ec.register_resource("LinuxApplication") + ec.set(app, "command", command) + ec.register_connection(app, node) + return app + +# Create the EC +ec = ExperimentController(exp_id = "test-tr") + +switch1 = "planetlab2.virtues.fi" +switch2 = "planetlab2.upc.es" +switch3 = "planetlab2.cs.aueb.gr" +host1 = "planetlab2.ionio.gr" +host2 = "iraplab2.iralab.uni-karlsruhe.de" +host3 = "planetlab2.diku.dk" + +ip_controller = "194.254.215.12" +network = "192.168.3.0" + +slicename = "inria_nepi" + +pl_user = os.environ.get("PL_USER") +pl_password = os.environ.get("PL_PASS") + +s1_node = add_node(ec, switch1, slicename, pl_user, pl_password) +s2_node = add_node(ec, switch2, slicename, pl_user, pl_password) +s3_node = add_node(ec, switch3, slicename, pl_user, pl_password) + +# Add switches +ovs1 = add_ovs(ec, "nepi_bridge_1", "192.168.3.2/24", ip_controller, "6633", s1_node) +ovs2 = add_ovs(ec, "nepi_bridge_2", "192.168.3.4/24", ip_controller, "6633", s2_node) +ovs3 = add_ovs(ec, "nepi_bridge_3", "192.168.3.6/24", ip_controller, "6633", s3_node) + +# Add ports on ovs +port1 = add_port(ec, "nepi_port1", ovs1) +port4 = add_port(ec, "nepi_port4", ovs1) +port7 = add_port(ec, "nepi_port7", ovs1) +port2 = add_port(ec, "nepi_port2", ovs2) +port5 = add_port(ec, "nepi_port5", ovs2) +#port8 = add_port(ec, "nepi_port8", ovs2) +port3 = add_port(ec, "nepi_port3", ovs3) +port6 = add_port(ec, "nepi_port6", ovs3) +#port9 = add_port(ec, "nepi_port9", ovs3) + +h1_node = add_node(ec, host1, slicename, pl_user, pl_password) +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) + +# Connect the nodes +tunnel1 = add_tunnel(ec, network, port1, tap1) +tunnel2 = add_tunnel(ec, network, port2, tap2) +tunnel3 = add_tunnel(ec, network, port3, tap3) +tunnel4 = add_tunnel(ec, network, port4, port5) +tunnel5 = add_tunnel(ec, network, port7, port6) +#tunnel6 = add_tunnel(ec, network, port8, port9) + +# Add ping commands +app1 = add_app(ec, "ping -c5 192.168.3.4", s1_node) +app2 = add_app(ec, "ping -c5 192.168.3.6", s1_node) +app3 = add_app(ec, "ping -c5 192.168.3.2", s2_node) +app4 = add_app(ec, "ping -c5 192.168.3.6", s2_node) +app5 = add_app(ec, "ping -c5 192.168.3.2", s3_node) +app6 = add_app(ec, "ping -c5 192.168.3.4", s3_node) + +app7 = add_app(ec, "ping -c5 192.168.3.3", h1_node) +app8 = add_app(ec, "ping -c5 192.168.3.5", h1_node) +app9 = add_app(ec, "ping -c5 192.168.3.1", h2_node) +app10 = add_app(ec, "ping -c5 192.168.3.5", h2_node) +app11 = add_app(ec, "ping -c5 192.168.3.1", h3_node) +app12 = add_app(ec, "ping -c5 192.168.3.3", h3_node) + +ec.deploy() + +ec.wait_finished([app1, app2, app3, app4, app5, app6, app7, app8, app9, app10, app11, app12]) + +# 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') + + +f = open("examples/openvswitch/ovs_ping_3switches_line.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() + +# Delete the overlay network +ec.shutdown() + + + + + diff --git a/examples/openvswitch/ovs_ping_3switches_loop.py b/examples/openvswitch/ovs_ping_3switches_loop.py new file mode 100644 index 00000000..9465f082 --- /dev/null +++ b/examples/openvswitch/ovs_ping_3switches_loop.py @@ -0,0 +1,210 @@ +#!/usr/bin/env python +# +# NEPI, a framework to manage network experiments +# 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac +# Alexandros Kouvakas +# +# Switch1 ------- Switch2 +# / \ +# / \ +# / \ +# Host1 Host2 + + + +from nepi.execution.ec import ExperimentController +import os, time + +def add_node(ec, host, user, pl_user, pl_password): + node = ec.register_resource("PlanetlabNode") + ec.set(node, "hostname", host) + ec.set(node, "username", user) + if pl_user: + ec.set(node, "pluser", pl_user) + if pl_password: + ec.set(node, "plpassword", pl_password) + ec.set(node, "cleanHome", True) + ec.set(node, "cleanProcesses", True) + + return node + +def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node): + ovs = ec.register_resource("OVSWitch") + ec.set(ovs, "bridge_name", bridge_name) + ec.set(ovs, "virtual_ip_pref", virtual_ip_pref) + ec.set(ovs, "controller_ip", controller_ip) + ec.set(ovs, "controller_port", controller_port) + ec.register_connection(ovs, node) + return ovs + +def add_port(ec, port_name, ovs): + port = ec.register_resource("OVSPort") + ec.set(port, "port_name", port_name) + ec.register_connection(port, ovs) + return port + +def add_tap(ec, ip4, prefix4, pointopoint, node): + tap = ec.register_resource("PlanetlabTap") + ec.set(tap, "ip4", ip4) + ec.set(tap, "prefix4", prefix4) + ec.set(tap, "pointopoint", pointopoint) + ec.set(tap, "up", True) + ec.register_connection(tap, node) + return tap + +def add_tunnel(ec, network, port0, tap): + tunnel = ec.register_resource("OVSTunnel") + ec.set(tunnel, "network", network) + ec.register_connection(port0, tunnel) + ec.register_connection(tunnel, tap) + return tunnel + +def add_app(ec, command, node): + app = ec.register_resource("LinuxApplication") + ec.set(app, "command", command) + ec.register_connection(app, node) + return app + +# Create the EC +ec = ExperimentController(exp_id = "test-tr") + +switch1 = "planetlab2.virtues.fi" +switch2 = "planetlab2.upc.es" +switch3 = "planetlab2.cs.aueb.gr" +host1 = "planetlab2.ionio.gr" +host2 = "iraplab2.iralab.uni-karlsruhe.de" +host3 = "planetlab2.diku.dk" + +ip_controller = "194.254.215.12" +network = "192.168.3.0" + +slicename = "inria_nepi" + +pl_user = os.environ.get("PL_USER") +pl_password = os.environ.get("PL_PASS") + +s1_node = add_node(ec, switch1, slicename, pl_user, pl_password) +s2_node = add_node(ec, switch2, slicename, pl_user, pl_password) +s3_node = add_node(ec, switch3, slicename, pl_user, pl_password) + +# Add switches +ovs1 = add_ovs(ec, "nepi_bridge_1", "192.168.3.2/24", ip_controller, "6633", s1_node) +ovs2 = add_ovs(ec, "nepi_bridge_2", "192.168.3.4/24", ip_controller, "6633", s2_node) +ovs3 = add_ovs(ec, "nepi_bridge_3", "192.168.3.6/24", ip_controller, "6633", s3_node) + +# Add ports on ovs +port1 = add_port(ec, "nepi_port1", ovs1) +port4 = add_port(ec, "nepi_port4", ovs1) +port7 = add_port(ec, "nepi_port7", ovs1) +port2 = add_port(ec, "nepi_port2", ovs2) +port5 = add_port(ec, "nepi_port5", ovs2) +port8 = add_port(ec, "nepi_port8", ovs2) +port3 = add_port(ec, "nepi_port3", ovs3) +port6 = add_port(ec, "nepi_port6", ovs3) +port9 = add_port(ec, "nepi_port9", ovs3) + +h1_node = add_node(ec, host1, slicename, pl_user, pl_password) +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) + +# Connect the nodes +tunnel1 = add_tunnel(ec, network, port1, tap1) +tunnel2 = add_tunnel(ec, network, port2, tap2) +tunnel3 = add_tunnel(ec, network, port3, tap3) +tunnel4 = add_tunnel(ec, network, port4, port5) +tunnel5 = add_tunnel(ec, network, port7, port6) +tunnel6 = add_tunnel(ec, network, port8, port9) + +# Add ping commands +app1 = add_app(ec, "ping -c5 192.168.3.4", s1_node) +app2 = add_app(ec, "ping -c5 192.168.3.6", s1_node) +app3 = add_app(ec, "ping -c5 192.168.3.2", s2_node) +app4 = add_app(ec, "ping -c5 192.168.3.6", s2_node) +app5 = add_app(ec, "ping -c5 192.168.3.2", s3_node) +app6 = add_app(ec, "ping -c5 192.168.3.4", s3_node) + +app7 = add_app(ec, "ping -c5 192.168.3.3", h1_node) +app8 = add_app(ec, "ping -c5 192.168.3.5", h1_node) +app9 = add_app(ec, "ping -c5 192.168.3.1", h2_node) +app10 = add_app(ec, "ping -c5 192.168.3.5", h2_node) +app11 = add_app(ec, "ping -c5 192.168.3.1", h3_node) +app12 = add_app(ec, "ping -c5 192.168.3.3", h3_node) + +ec.deploy() + +ec.wait_finished([app1, app2, app3, app4, app5, app6, app7, app8, app9, app10, app11, app12]) + +# 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') + + +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() + +# Delete the overlay network +ec.shutdown() + + + + + diff --git a/src/nepi/resources/linux/udptunnel.py b/src/nepi/resources/linux/udptunnel.py index 6372729e..a1f05e13 100644 --- a/src/nepi/resources/linux/udptunnel.py +++ b/src/nepi/resources/linux/udptunnel.py @@ -290,7 +290,7 @@ class UdpTunnel(LinuxApplication): result = None delay = 1.0 - for i in xrange(4): + for i in xrange(20): (out, err), proc = endpoint.node.check_output( self.run_home(endpoint), filename) diff --git a/src/nepi/resources/planetlab/openvswitch/ovs.py b/src/nepi/resources/planetlab/openvswitch/ovs.py index b3ce59d8..65a1ec59 100644 --- a/src/nepi/resources/planetlab/openvswitch/ovs.py +++ b/src/nepi/resources/planetlab/openvswitch/ovs.py @@ -30,7 +30,6 @@ reschedule_delay = "0.5s" @clsinit_copy class OVSWitch(LinuxApplication): - _rtype = "OVSWitch" _help = "Runs an OpenVSwitch on a PlanetLab host" _backend = "planetlab" @@ -122,6 +121,23 @@ class OVSWitch(LinuxApplication): self.node.mkdir(self.ovs_checks) super(OVSWitch, self).do_provision() + + def do_deploy(self): + """ Wait until node is associated and deployed + """ + if not self.node or self.node.state < ResourceState.READY: + self.ec.schedule(reschedule_delay, self.deploy) + return + + self.do_discover() + self.do_provision() + self.check_sliver_ovs() + self.servers_on() + self.create_bridge() + self.assign_controller() + self.ovs_status() + + super(OVSWitch, self).do_deploy() def check_sliver_ovs(self): """ Check if sliver-ovs exists. If it does not exist, we interrupt @@ -146,34 +162,15 @@ class OVSWitch(LinuxApplication): raise RuntimeError, msg msg = "Command sliver-ovs exists" - self.debug(msg) - - def do_deploy(self): - """ Wait until node is associated and deployed - """ - node = self.node - if not node or node.state < ResourceState.READY: - #self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state ) - self.ec.schedule(reschedule_delay, self.deploy) - return - - self.do_discover() - self.do_provision() - self.check_sliver_ovs() - self.servers_on() - self.create_bridge() - self.assign_controller() - self.ovs_status() - - super(OVSWitch, self).do_deploy() + self.debug(msg) def servers_on(self): """ Start the openvswitch servers and also checking if they started successfully """ - self.info("Starting the OVSWitch servers") - command = ("sliver-ovs start") - + + # Start the server + command = "sliver-ovs start" out = err = "" (out, err), proc = self.node.run_and_wait(command, self.ovs_checks, shfile = "start_srv.sh", @@ -183,13 +180,13 @@ class OVSWitch(LinuxApplication): raise_on_error = True, stdout = "start_srv_stdout", stderr = "start_srv_stderr") - (out, err), proc = self.node.check_output(self.ovs_checks, 'start_srv_exitcode') if out != "0\n": self.error("Servers have not started") raise RuntimeError, msg + # Check if the servers are running or not cmd = "ps -A | grep ovsdb-server" out = err = "" (out, err), proc = self.node.run_and_wait(cmd, self.ovs_checks, @@ -199,42 +196,35 @@ class OVSWitch(LinuxApplication): sudo = True, stdout = "status_srv_stdout", stderr = "status_srv_stderr") - - # Check if the servers are running or not (out, err), proc = self.node.check_output(self.ovs_checks, 'status_srv_exitcode') if out != "0\n": - self.error("Servers are not running") + msg = "Servers are not running" + self.error(msg) raise RuntimeError, msg - self.info("Servers started") + self.info("Server OVS Started Correctly") - def del_old_br(self): - # TODO: Delete old bridges that might exist maybe by adding atribute - """ With ovs-vsctl list-br - """ - pass +# def del_old_br(self): +# # TODO: Delete old bridges that might exist maybe by adding atribute +# """ With ovs-vsctl list-br +# """ +# pass def create_bridge(self): """ Create the bridge/switch and we check if we have any error during the SSH connection """ # TODO: Add check for virtual_ip belonging to vsys_tag - self.del_old_br() + #self.del_old_br() if not (self.get("bridge_name") and self.get("virtual_ip_pref")): msg = "No assignment in one or both attributes" self.error(msg) - self.debug("Bridge name is %s and virtual_ip_pref is %s" %\ - (self.get("bridge_name"), self.get("virtual_ip_pref")) ) raise AttributeError, msg - - bridge_name = self.get("bridge_name") - virtual_ip_pref = self.get("virtual_ip_pref") - self.info(" Creating the bridge %s and assigning %s" %\ - (bridge_name, virtual_ip_pref) ) + cmd = "sliver-ovs create-bridge '%s' '%s'" %\ - (bridge_name, virtual_ip_pref) + (self.get("bridge_name"), self.get("virtual_ip_pref")) out = err = "" (out, err), proc = self.node.run_and_wait(cmd, self.ovs_checks, shfile = "create_br.sh", @@ -243,37 +233,43 @@ class OVSWitch(LinuxApplication): sudo = True, stdout = "create_br_stdout", stderr = "create_br_stderr") - (out, err), proc = self.node.check_output(self.ovs_checks, 'create_br_exitcode') + if out != "0\n": msg = "No such pltap netdev\novs-appctl: ovs-vswitchd: server returned an error" - self.debug("Check again the virtual IP") + self.error(msg) raise RuntimeError, msg - self.info("Bridge %s created" % bridge_name) + self.info(" Bridge %s Created and Assigned to %s" %\ + (self.get("bridge_name"), self.get("virtual_ip_pref")) ) def assign_controller(self): """ Set the controller IP """ - if self.get("controller_ip") and self.get("controller_port"): - controller_ip = self.get("controller_ip") - controller_port = self.get("controller_port") - self.info("Assigning the controller to the %s" % self.get("bridge_name")) - cmd = "ovs-vsctl set-controller %s tcp:%s:%s" %\ - (self.get("bridge_name"), controller_ip, controller_port) - out = err = "" - (out, err), proc = self.node.run(cmd, self.ovs_checks, - sudo = True, - stdout = "stdout", - stderr = "stderr") - if err != "": - self.debug("SSH connection refusing in assign_contr") - raise RuntimeError, msg - self.info("Controller assigned") + + if not (self.get("controller_ip") and self.get("controller_port")): + msg = "No assignment in one or both attributes" + self.error(msg) + raise AttributeError, msg + + cmd = "ovs-vsctl set-controller %s tcp:%s:%s" %\ + (self.get("bridge_name"), self.get("controller_ip"), self.get("controller_port")) + out = err = "" + (out, err), proc = self.node.run(cmd, self.ovs_checks, + sudo = True, + stdout = "stdout", + stderr = "stderr") + + if err != "": + msg = "SSH connection in the method assign_controller" + self.error(msg) + raise RuntimeError, msg + + self.info("Controller assigned to the bridge %s" % self.get("bridge_name")) def ovs_status(self): - """ Print the status of the created bridge + """ Print the status of the bridge """ cmd = "sliver-ovs show | tail -n +2" out = err = "" @@ -282,29 +278,38 @@ class OVSWitch(LinuxApplication): stdout = "show_stdout", stderr = "show_stderr") (out, err), proc = self.node.check_output(self.ovs_home, 'show_stdout') + + if out == "": + msg = "Error when checking the status of the OpenVswitch" + self.error(msg) + raise RuntimeError, msg + self.info(out) def do_release(self): - """ Delete the bridge and - close the servers + """ Delete the bridge and close the servers. + It need to wait for the others RM (OVSPort and OVSTunnel) + to be released before releasing itself + """ - # Node needs to wait until all associated RMs are released - # to be released + from nepi.resources.planetlab.openvswitch.ovsport import OVSPort rm = self.get_connected(OVSPort.get_rtype()) - if rm[0].state < ResourceState.STOPPED: + if rm[0].state < ResourceState.RELEASED: self.ec.schedule(reschedule_delay, self.release) return - msg = "Deleting the bridge %s" % self.get('bridge_name') - self.info(msg) cmd = "sliver-ovs del-bridge %s" % self.get('bridge_name') (out, err), proc = self.node.run(cmd, self.ovs_checks, sudo = True) + cmd = "sliver-ovs stop" (out, err), proc = self.node.run(cmd, self.ovs_checks, sudo = True) + + msg = "Deleting the bridge %s" % self.get('bridge_name') + self.info(msg) if proc.poll(): self.error(msg, out, err) diff --git a/src/nepi/resources/planetlab/openvswitch/ovsport.py b/src/nepi/resources/planetlab/openvswitch/ovsport.py index 57b6f16c..74a8baa0 100644 --- a/src/nepi/resources/planetlab/openvswitch/ovsport.py +++ b/src/nepi/resources/planetlab/openvswitch/ovsport.py @@ -106,51 +106,51 @@ class OVSPort(LinuxApplication): # msg = "Connection between %s %s and %s %s refused" % (self.get_rtype(), self._guid, rm.get_rtype(), guid) # self.debug(msg) - def get_host_ip(self): - """ Get the hostname of the node that - the port belongs to. We use it for tunnel. + def get_ip(self): + """ Return the ip of the node. This data is necessary to + create the tunnel. """ - get_host_ip = self.node - if not get_host_ip: - msg = "info_list is empty" - self.debug(msg) - raise RuntimeError, msg import socket - self.port_info.append(get_host_ip.get('hostname')) - self.port_info.append(socket.gethostbyname(self.port_info[0])) + return socket.gethostbyname(self.node.get('hostname')) def create_port(self): """ Create the desired port """ - port_name = self.get('port_name') + msg = "Creating the port %s" % self.get('port_name') + self.debug(msg) - if not (port_name or self.ovswitch): - msg = "The rm_list is empty or the port name is not assigned\n Failed to create port" + if not self.get('port_name'): + msg = "The port name is not assigned" self.error(msg) - self.debug("ovswitch_list = %s and port_name = %s" % (self.ovswitch, port_name) ) raise AttributeError, msg - self.info("Create the port %s on switch %s" % (port_name, self.ovswitch.get('bridge_name'))) - self.port_info.append(port_name) - self.port_info.append(self.ovswitch.get('virtual_ip_pref')) - cmd = "sliver-ovs create-port %s %s" % (self.ovswitch.get('bridge_name'), port_name) + if not self.ovswitch: + msg = "The OVSwitch RM is not running" + self.error(msg) + raise AttributeError, msg + + cmd = "sliver-ovs create-port %s %s" % (self.ovswitch.get('bridge_name'), + self.get('port_name')) self.node.run(cmd, self.ovswitch.ovs_checks, - stderr = "stdout-%s" % port_name, - stdout = "stderr-%s" % port_name, + stderr = "stdout-%s" % self.get('port_name'), + stdout = "stderr-%s" % self.get('port_name'), sudo = True) + + self.info("Created the port %s on switch %s" % (self.get('port_name'), + self.ovswitch.get('bridge_name'))) def get_local_end(self): """ Get the local_endpoint of the port """ - msg = "Discovering the number of the port %s"\ - % self.get('port_name') - self.info(msg) - command = "sliver-ovs get-local-endpoint %s"\ - % self.get('port_name') + msg = "Discovering the number of the port %s" % self.get('port_name') + self.debug(msg) + + command = "sliver-ovs get-local-endpoint %s" % self.get('port_name') out = err = "" - (out, err), proc = self.node.run_and_wait(command, self.ovswitch.ovs_checks, + (out, err), proc = self.node.run_and_wait(command, + self.ovswitch.ovs_checks, shfile = "port_number-%s.sh" % self.get('port_name'), pidfile = "port_number_pidfile-%s" % self.get('port_name'), ecodefile = "port_number_exitcode-%s" % self.get('port_name'), @@ -159,16 +159,25 @@ class OVSPort(LinuxApplication): stderr = "stderr-%s" % self.get('port_name')) if err != "": - msg = "No assignment in attribute port_name" + msg = "Error retrieving the local endpoint of the port" self.error(msg) - self.debug("You are in the method get_local_end and the port_name = %s" % self.get('port_name')) raise AttributeError, msg - self._port_number = None - self._port_number = int(out) - self.port_info.append(self._port_number) - self.info("The number of the %s is %s" % (self.get('port_name'), self._port_number)) + if out: + self._port_number = int(out) + + self.info("The number of the %s is %s" % (self.get('port_name'), + self.port_number)) + def set_port_info(self, ip): + info = [] + info.append(self.node.get('hostname')) + info.append(ip) + info.append(self.get('port_name')) + info.append(self.ovswitch.get('virtual_ip_pref')) + info.append(self.port_number) + return info + def switch_connect_command(self, local_port_name, remote_ip, remote_port_num): """ Script for switch links @@ -185,40 +194,42 @@ class OVSPort(LinuxApplication): def do_deploy(self): """ Wait until ovswitch is started """ - ovswitch = self.ovswitch - if not ovswitch or ovswitch.state < ResourceState.READY: - self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.ovswitch.state ) + if not self.ovswitch or self.ovswitch.state < ResourceState.READY: + self.debug("---- RESCHEDULING DEPLOY ---- OVSwitch state %s " % self.ovswitch.state ) self.ec.schedule(reschedule_delay, self.deploy) return self.do_discover() self.do_provision() - self.get_host_ip() + ip = self.get_ip() self.create_port() self.get_local_end() self.ovswitch.ovs_status() + self.port_info = self.set_port_info(ip) + super(OVSPort, self).do_deploy() def do_release(self): - """ Release the port RM means delete the ports + """ Delete the port on the OVSwitch. It needs to wait for the tunnel + to be released. """ - # OVS needs to wait until all associated RMs are released - # to be released + from nepi.resources.planetlab.openvswitch.tunnel import OVSTunnel rm = self.get_connected(OVSTunnel.get_rtype()) - if rm and rm[0].state < ResourceState.STOPPED: + if rm and rm[0].state < ResourceState.RELEASED: self.ec.schedule(reschedule_delay, self.release) return - msg = "Deleting the port %s" % self.get('port_name') - self.info(msg) cmd = "sliver-ovs del_port %s" % self.get('port_name') (out, err), proc = self.node.run(cmd, self.ovswitch.ovs_checks, sudo = True) + msg = "Deleting the port %s" % self.get('port_name') + self.info(msg) + if proc.poll(): self.error(msg, out, err) raise RuntimeError, msg diff --git a/src/nepi/resources/planetlab/openvswitch/tunnel.py b/src/nepi/resources/planetlab/openvswitch/tunnel.py index 0b28327e..c9c27119 100644 --- a/src/nepi/resources/planetlab/openvswitch/tunnel.py +++ b/src/nepi/resources/planetlab/openvswitch/tunnel.py @@ -103,50 +103,89 @@ class OVSTunnel(LinuxApplication): super(OVSTunnel, self).__init__(ec, guid) self._home = "tunnel-%s" % self.guid self.port_info_tunl = [] - self._nodes = [] self._pid = None self._ppid = None self._vroute = None - + self._node_endpoint1 = None + self._node_endpoint2 = None def log_message(self, msg): return " guid %d - Tunnel - %s " % (self.guid, msg) - @property - def node(self): - if self._nodes: - return self._nodes[0] - def app_home(self, node): - return os.path.join(self.node.exp_home, self._home) + return os.path.join(node.exp_home, self._home) def run_home(self, node): return os.path.join(self.app_home(node), self.ec.run_id) - def port_endpoints(self): - # Switch-Switch connection - connected = [] + @property + def tap(self): + ''' Return the Tap RM if it exists ''' + rclass = ResourceFactory.get_resource_type(PlanetlabTap.get_rtype()) for guid in self.connections: rm = self.ec.get_resource(guid) - if hasattr(rm, "create_port"): - connected.append(rm) - return connected + if isinstance(rm, rclass): + return rm - - def mixed_endpoints(self): - # Switch-Host connection - connected = [1, 2] + @property + def ovswitch(self): + ''' Return the 1st switch ''' + for guid in self.connections: + rm_port = self.ec.get_resource(guid) + if hasattr(rm_port, "create_port"): + rm_list = rm_port.get_connected(OVSWitch.get_rtype()) + if rm_list: + return rm_list[0] + + @property + def check_switch_host_link(self): + ''' Check if the links are between switches + or switch-host. Return False for latter. + ''' + if self.tap : + return True + return False + + + def endpoints(self): + ''' Return the list with the two connected elements. + Either Switch-Switch or Switch-Host + ''' + connected = [1, 1] + position = 0 for guid in self.connections: rm = self.ec.get_resource(guid) if hasattr(rm, "create_port"): - connected[0] = rm + connected[position] = rm + position += 1 elif hasattr(rm, "udp_connect_command"): connected[1] = rm return connected +# def port_endpoints(self): +# # Switch-Switch connection +# connected = [] +# for guid in self.connections: +# rm = self.ec.get_resource(guid) +# if hasattr(rm, "create_port"): +# connected.append(rm) +# return connected + +# +# def mixed_endpoints(self): +# # Switch-Host connection +# connected = [1, 2] +# for guid in self.connections: +# rm = self.ec.get_resource(guid) +# if hasattr(rm, "create_port"): +# connected[0] = rm +# elif hasattr(rm, "udp_connect_command"): +# connected[1] = rm +# return connected + def get_node(self, endpoint): # Get connected to the nodes - res = [] + rm = [] if hasattr(endpoint, "create_port"): rm_list = endpoint.get_connected(OVSWitch.get_rtype()) if rm_list: @@ -155,119 +194,95 @@ class OVSTunnel(LinuxApplication): rm = endpoint.get_connected(PlanetlabNode.get_rtype()) if rm : - res.append(rm[0]) - return res + return rm[0] @property def endpoint1(self): - if self.check_endpoints: - port_endpoints = self.port_endpoints() - if port_endpoints: return port_endpoints[0] - else: - mixed_endpoints = self.mixed_endpoints() - if mixed_endpoints: return mixed_endpoints[0] + endpoint = self.endpoints() + return endpoint[0] @property def endpoint2(self): - if self.check_endpoints: - port_endpoints = self.port_endpoints() - if port_endpoints: return port_endpoints[1] - else: - mixed_endpoints = self.mixed_endpoints() - if mixed_endpoints: return mixed_endpoints[1] - - @property - def check_endpoints(self): - """ Check if the links are between switches - or switch-host. Return False for latter. - """ - port_endpoints = self.port_endpoints() - if len(port_endpoints) == 2: - return True - return False - - def get_port_info(self, endpoint, rem_endpoint): + endpoint = self.endpoints() + return endpoint[1] + +# @property +# def check_endpoints(self): +# """ Check if the links are between switches +# or switch-host. Return False for latter. +# """ +# port_endpoints = self.port_endpoints() +# if len(port_endpoints) == 2: +# return True +# return False + + def get_port_info(self, endpoint1, endpoint2): + # Need to change it. Not good to have method that return different type of things !!!!! """ Retrieve the port_info list for each port - :param port_info_tunl: [hostname, publ_IP_addr, port_name, - virtual_ip, local_port_Numb] - :type port_info_tunl: list """ - self.port_info_tunl = [] - if self.check_endpoints: - # Use for the link switch-->switch - self.port_info_tunl.append(endpoint.port_info) - host0, ip0, pname0, virt_ip0, pnumber0 = self.port_info_tunl[0] - self.port_info_tunl.append(rem_endpoint.port_info) - host1, ip1, pname1, virt_ip1, pnumber1 = self.port_info_tunl[1] - return (pname0, ip1, pnumber1) - - # Use for the link host-->switch - self.port_info_tunl.append(endpoint.port_info) - host0, ip0, pname0, virt_ip0, pnumber0 = self.port_info_tunl[0] - return pnumber0 + if self.check_switch_host_link : + host0, ip0, pname0, virt_ip0, pnumber0 = endpoint1.port_info + return pnumber0 + + host0, ip0, pname0, virt_ip0, pnumber0 = endpoint1.port_info + host1, ip1, pname1, virt_ip1, pnumber1 = endpoint2.port_info + + return pname0, ip1, pnumber1 - def udp_connect(self, endpoint, rem_endpoint): + def host_to_switch_connect(self, tap_endpoint, sw_endpoint): # Collect info from rem_endpoint - self._nodes = self.get_node(rem_endpoint) - remote_ip = socket.gethostbyname(self.node.get("hostname")) + remote_ip = socket.gethostbyname(self.node_endpoint1.get("hostname")) + # Collect info from endpoint - self._nodes = self.get_node(endpoint) - local_port_file = os.path.join(self.run_home(self.node), - "local_port") - remote_port_file = os.path.join(self.run_home(self.node), - "remote_port") - ret_file = os.path.join(self.run_home(self.node), - "ret_file") + local_port_file = os.path.join(self.run_home(self.node_endpoint2), "local_port") + rem_port_file = os.path.join(self.run_home(self.node_endpoint2), "remote_port") + ret_file = os.path.join(self.run_home(self.node_endpoint2), "ret_file") cipher = self.get("cipher") cipher_key = self.get("cipherKey") bwlimit = self.get("bwLimit") txqueuelen = self.get("txQueueLen") - rem_port = str(self.get_port_info(rem_endpoint, endpoint)) + rem_port = str(self.get_port_info( sw_endpoint,tap_endpoint)) + # Upload the remote port in a file - self.node.upload(rem_port, - remote_port_file, + self.node_endpoint2.upload(rem_port, rem_port_file, text = True, overwrite = False) - udp_connect_command = endpoint.udp_connect_command( - remote_ip, local_port_file, remote_port_file, + udp_connect_command = tap_endpoint.udp_connect_command( + remote_ip, local_port_file, rem_port_file, ret_file, cipher, cipher_key, bwlimit, txqueuelen) # upload command to host_connect.sh script - shfile = os.path.join(self.app_home(self.node), "host_connect.sh") - self.node.upload(udp_connect_command, - shfile, + shfile = os.path.join(self.app_home(self.node_endpoint2), "host_connect.sh") + self.node_endpoint2.upload(udp_connect_command, shfile, text = True, overwrite = False) # invoke connect script cmd = "bash %s" % shfile - (out, err), proc = self.node.run(cmd, self.run_home(self.node), + (out, err), proc = self.node_endpoint2.run(cmd, self.run_home(self.node_endpoint2), sudo = True, stdout = "udp_stdout", stderr = "udp_stderr") # check if execution errors - msg = "Failed to connect endpoints" - if proc.poll(): + msg = "Failed to connect endpoints" self.error(msg, out, err) raise RuntimeError, msg - msg = "Connection on host %s configured" \ - % self.node.get("hostname") + msg = "Connection on host %s configured" % self.node_endpoint2.get("hostname") self.debug(msg) # Wait for pid file to be generated - self._nodes = self.get_node(endpoint) - pid, ppid = self.node.wait_pid(self.run_home(self.node)) + pid, ppid = self.node_endpoint2.wait_pid(self.run_home(self.node_endpoint2)) # If the process is not running, check for error information # on the remote machine if not pid or not ppid: - (out, err), proc = self.node.check_errors(self.run_home(self.node)) + (out, err), proc = self.node_endpoint2.check_errors(self.run_home(self.node_endpoint2)) # Out is what was written in the stderr file if err: msg = " Failed to start command '%s' " % command @@ -276,26 +291,28 @@ class OVSTunnel(LinuxApplication): return (pid, ppid) - def switch_connect(self, endpoint, rem_endpoint): + def switch_to_switch_connect(self, endpoint, rem_endpoint): """ Get switch connect command """ # Get and configure switch connection command - (local_port_name, remote_ip, remote_port_num) = self.get_port_info( - endpoint, rem_endpoint) + + local_port_name, remote_ip, remote_port_num = self.get_port_info(endpoint, rem_endpoint) + + switch_connect_command = endpoint.switch_connect_command( local_port_name, remote_ip, remote_port_num) - self._nodes = self.get_node(endpoint) + node_endpoint = self.get_node(endpoint) # Upload command to the file sw_connect.sh - shfile = os.path.join(self.app_home(self.node), "sw_connect.sh") - self.node.upload(switch_connect_command, + shfile = os.path.join(self.app_home(node_endpoint), "sw_connect.sh") + node_endpoint.upload(switch_connect_command, shfile, text = True, overwrite = False) #invoke connect script cmd = "bash %s" % shfile - (out, err), proc = self.node.run(cmd, self.run_home(self.node), + (out, err), proc = node_endpoint.run(cmd, self.run_home(node_endpoint), sudo = True, stdout = "sw_stdout", stderr = "sw_stderr") @@ -317,8 +334,7 @@ class OVSTunnel(LinuxApplication): delay = 1.0 for i in xrange(10): - (out, err), proc = self.node.check_output(self.run_home(self.node), 'local_port') - + (out, err), proc = self.node_endpoint2.check_output(self.run_home(self.node_endpoint2), 'local_port') if out: local_port = int(out) break @@ -332,31 +348,28 @@ class OVSTunnel(LinuxApplication): return local_port - def sw_host_connect(self, endpoint, rem_endpoint): + def switch_to_host_connect(self, sw_endpoint, host_endpoint): """Link switch--> host """ - # Retrieve remote port number from rem_endpoint - local_port_name = endpoint.get('port_name') - self._nodes = self.get_node(rem_endpoint) + # Retrieve remote port number from sw_endpoint + local_port_name = sw_endpoint.get('port_name') - # time.sleep(4) # Without this, sometimes I get nothing in remote_port_num out = err= '' remote_port_num = self.wait_local_port() - remote_ip = socket.gethostbyname(self.node.get("hostname")) - switch_connect_command = endpoint.switch_connect_command( + remote_ip = socket.gethostbyname(self.node_endpoint2.get("hostname")) + switch_connect_command = sw_endpoint.switch_connect_command( local_port_name, remote_ip, remote_port_num) # Upload command to the file sw_connect.sh - self._nodes = self.get_node(endpoint) - shfile = os.path.join(self.app_home(self.node), "sw_connect.sh") - self.node.upload(switch_connect_command, + shfile = os.path.join(self.app_home(self.node_endpoint1), "sw_connect.sh") + self.node_endpoint1.upload(switch_connect_command, shfile, text = True, overwrite = False) # Invoke connect script cmd = "bash %s" % shfile - (out, err), proc = self.node.run(cmd, self.run_home(self.node), + (out, err), proc = self.node_endpoint1.run(cmd, self.run_home(self.node_endpoint1), sudo = True, stdout = "sw_stdout", stderr = "sw_stderr") @@ -374,44 +387,30 @@ class OVSTunnel(LinuxApplication): def do_provision(self): """ Provision the tunnel + + ..note : Endpoint 1 is always a OVSPort. + Endpoint 2 can be either a OVSPort or a Tap + """ - # Create folders - self._nodes = self.get_node(self.endpoint1) - self.node.mkdir(self.run_home(self.node)) - self._nodes = self.get_node(self.endpoint2) - self.node.mkdir(self.run_home(self.node)) + self.node_endpoint1 = self.get_node(self.endpoint1) + self.node_endpoint1.mkdir(self.run_home(self.node_endpoint1)) - if self.check_endpoints: - #Invoke connect script between switches - self.switch_connect(self.endpoint1, self.endpoint2) - self.switch_connect(self.endpoint2, self.endpoint1) + self.node_endpoint2 = self.get_node(self.endpoint2) + self.node_endpoint2.mkdir(self.run_home(self.node_endpoint2)) + if not self.check_switch_host_link: + # Invoke connect script between switches + self.switch_to_switch_connect(self.endpoint1, self.endpoint2) + self.switch_to_switch_connect(self.endpoint2, self.endpoint1) else: # Invoke connect script between switch & host - (self._pid, self._ppid) = self.udp_connect(self.endpoint2, self.endpoint1) - self.sw_host_connect(self.endpoint1, self.endpoint2) - - super(OVSTunnel, self).do_provision() - - @property - def tap(self): - rclass = ResourceFactory.get_resource_type(PlanetlabTap.get_rtype()) - for guid in self.connections: - rm = self.ec.get_resource(guid) - if isinstance(rm, rclass): - return rm + (self._pid, self._ppid) = self.host_to_switch_connect(self.endpoint2, self.endpoint1) + self.switch_to_host_connect(self.endpoint1, self.endpoint2) - @property - def ovswitch(self): - for guid in self.connections: - rm_port = self.ec.get_resource(guid) - if hasattr(rm_port, "create_port"): - rm_list = rm_port.get_connected(OVSWitch.get_rtype()) - if rm_list: - return rm_list[0] + #super(OVSTunnel, self).do_provision() def configure(self): - if not self.check_endpoints: + if self.check_switch_host_link: self._vroute = self.ec.register_resource("PlanetlabVroute") self.ec.set(self._vroute, "action", "add") self.ec.set(self._vroute, "network", self.get("network")) @@ -420,7 +419,6 @@ class OVSTunnel(LinuxApplication): # schedule deploy self.ec.deploy(guids=[self._vroute], group = self.deployment_group) - def do_deploy(self): if (not self.endpoint1 or self.endpoint1.state < ResourceState.READY) or \ (not self.endpoint2 or self.endpoint2.state < ResourceState.READY): @@ -431,23 +429,23 @@ class OVSTunnel(LinuxApplication): self.do_provision() self.configure() - super(OVSTunnel, self).do_deploy() + self.set_ready() + #super(OVSTunnel, self).do_deploy() def do_release(self): """ Release the udp_tunnel on endpoint2. On endpoint1 means nothing special. """ - if not self.check_endpoints: + if not self.check_switch_host_link: # Kill the TAP devices # TODO: Make more generic Release method of PLTAP if self._pid and self._ppid: - self._nodes = self.get_node(self.endpoint2) - (out, err), proc = self.node.kill(self._pid, + (out, err), proc = self.node_enpoint2.kill(self._pid, self._ppid, sudo = True) + if err or proc.poll(): - # check if execution errors occurred msg = " Failed to delete TAP device" - self.error(msg, err, err) + self.error(msg, out, err) super(OVSTunnel, self).do_release() diff --git a/src/nepi/resources/planetlab/tap.py b/src/nepi/resources/planetlab/tap.py index b6b1744c..dc42a309 100644 --- a/src/nepi/resources/planetlab/tap.py +++ b/src/nepi/resources/planetlab/tap.py @@ -231,7 +231,7 @@ class PlanetlabTap(LinuxApplication): if_name = None delay = 1.0 - for i in xrange(10): + for i in xrange(20): (out, err), proc = self.node.check_output(self.run_home, "if_name") if out: -- 2.43.0