From 52e9a80764b98226727f1362d7c1f6246c06f92e Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Mon, 12 Jan 2015 04:06:33 +0100 Subject: [PATCH] efficiency plots --- examples/openvswitch/ovs_ping.py | 164 +++++++++++++ examples/openvswitch/ovs_ping_2_switches.py | 6 + examples/openvswitch/ovs_ping_3_switches.py | 246 ++++++++++++-------- 3 files changed, 314 insertions(+), 102 deletions(-) create mode 100644 examples/openvswitch/ovs_ping.py diff --git a/examples/openvswitch/ovs_ping.py b/examples/openvswitch/ovs_ping.py new file mode 100644 index 00000000..ab3ea2e0 --- /dev/null +++ b/examples/openvswitch/ovs_ping.py @@ -0,0 +1,164 @@ +#!/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 . +# +# Authors : Julien Tribino +# Alina Quereilhac +# +# Topology : +# +# Switch1 +# / +# / +# / +# Host1 +# +# +# Execution example: +# +# $ PYTHONPATH=$PYTHONPATH:src/ python examples/openvswitch/ovs_ping.py -n "192.168.3.0/24" -s -i /~/.ssh/id_rsa +# + +from nepi.execution.ec import ExperimentController + +import os +from optparse import OptionParser +import sys +import time + +def parse_args(): + pl_slice = os.environ.get("PL_SLICE") + pl_user = os.environ.get("PL_USER") + pl_pass = os.environ.get("PL_PASS") + identity = os.environ.get("PL_SSHKEY") + + usage = ("usage: %prog -a -b " + "-n -C -s -u " + "-p -i ") + + switch = "planetlab2.virtues.fi" + host = "planetlab2.ionio.gr" + + parser = OptionParser(usage = usage) + parser.add_option("-a", "--host", dest="host", + help="Hostname for PlanetLab host", default=host) + parser.add_option("-b", "--switch", dest="switch", + help="Hostname for PlanetLab switch", default=switch) + parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet", + help="Overlay network address of the form x.x.x.x/yy. " + "Must correspond to the vsys_vnet tag on the PlanetLab slice") + parser.add_option("-C", "--controller", dest="controller", + help="IP address for the OpenFlow controller, if one has been deployed", + default="1.1.1.1") + parser.add_option("-s", "--slicename", dest="slicename", + help="Name of PlanetLab slice", + default=pl_slice) + parser.add_option("-u", "--pl_user", dest="pl_user", + help="PlanetLab user (email address)", + default=pl_user) + parser.add_option("-p", "--pl_pass", dest="pl_pass", + help="PlanetLab password", + default=pl_pass) + parser.add_option("-i", "--identity", dest="identity", + help="Path to SSH key", + default=identity) + + (options, args) = parser.parse_args() + + return (options.host, options.switch, + options.vsys_vnet, options.controller, options.slicename, + options.pl_user, options.pl_pass, identity) + +(host, switch, vsys_vnet, controller, slicename, + pl_user, pl_pass, identity) = parse_args() + +# Create the EC +ec = ExperimentController(exp_id = "ovs_ping") + +net = vsys_vnet.split("/") +prefix = net[-1] +network = net[0] +net_segs = network.split(".") +ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1 +ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2 + +# Add OVS switch +node1 = ec.register_resource("planetlab::Node") +ec.set(node1, "hostname", switch) +ec.set(node1, "username", slicename) +ec.set(node1, "identity", identity) +ec.set(node1, "pluser", pl_user) +ec.set(node1, "plpassword", pl_pass) +ec.set(node1, "cleanExperiment", True) +ec.set(node1, "cleanProcesses", True) + +addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix +ovs = ec.register_resource("planetlab::OVSSwitch") +ec.set(ovs, "bridge_name", "nepi_bridge") +ec.set(ovs, "virtual_ip_pref", addr1) +ec.set(ovs, "controller_ip", controller) +ec.set(ovs, "controller_port", "6633") +ec.register_connection(ovs, node1) + +# Add host +node2 = ec.register_resource("planetlab::Node") +ec.set(node2, "hostname", host) +ec.set(node2, "username", slicename) +ec.set(node2, "identity", identity) +ec.set(node2, "pluser", pl_user) +ec.set(node2, "plpassword", pl_pass) +ec.set(node2, "cleanExperiment", True) +ec.set(node2, "cleanProcesses", True) + +# Creating overlay +# Add tap device +tap = ec.register_resource("planetlab::Tap") +ec.set(tap, "ip", ip2) +ec.set(tap, "prefix", prefix) +ec.set(tap, "pointopoint", ip1) +ec.set(tap, "up", True) +ec.register_connection(tap, node2) + +# Add ports on OVS +port = ec.register_resource("planetlab::OVSPort") +ec.set(port, "port_name", "nepi_port") +ec.set(port, "network", network) +ec.register_connection(port, ovs) + +# Add tunnel between host and switch +tunnel = ec.register_resource("linux::UdpTunnel") +ec.register_connection(port, tunnel) +ec.register_connection(tunnel, tap) + +## Ping switch from host +app = ec.register_resource("linux::Application") +ec.set(app, "command", "ping -c5 %s" % ip1) +ec.register_connection(app, node2) + +ec.deploy() + +ec.wait_finished([app]) + +# Retreive ping results and save them in a file +ping = ec.trace(app, "stdout") + +print ping + +# Delete the overlay network +ec.shutdown() + + diff --git a/examples/openvswitch/ovs_ping_2_switches.py b/examples/openvswitch/ovs_ping_2_switches.py index 3fe3d173..fe9962e4 100644 --- a/examples/openvswitch/ovs_ping_2_switches.py +++ b/examples/openvswitch/ovs_ping_2_switches.py @@ -158,6 +158,9 @@ ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2 ip3 = "%s.3" % ".".join(net_segs[:-1]) # x.x.x.3 ip4 = "%s.4" % ".".join(net_segs[:-1]) # x.x.x.4 +### Define topology + +# Add switches s1_node = add_node(ec, switch1, slicename, pl_user, pl_pass, identity) s2_node = add_node(ec, switch2, slicename, pl_user, pl_pass, identity) @@ -173,9 +176,11 @@ port3 = add_port(ec, "nepi_port3", network, ovs1) port2 = add_port(ec, "nepi_port2", network, ovs2) port4 = add_port(ec, "nepi_port4", network, ovs2) +# Add hosts h1_node = add_node(ec, host1, slicename, pl_user, pl_pass, identity) h2_node = add_node(ec, host2, slicename, pl_user, pl_pass, identity) +### Add overlay # Add tap devices tap1 = add_tap(ec, ip3, prefix, ip1, h1_node) tap2 = add_tap(ec, ip4, prefix, ip2, h2_node) @@ -185,6 +190,7 @@ 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 diff --git a/examples/openvswitch/ovs_ping_3_switches.py b/examples/openvswitch/ovs_ping_3_switches.py index d686ef32..60efc350 100644 --- a/examples/openvswitch/ovs_ping_3_switches.py +++ b/examples/openvswitch/ovs_ping_3_switches.py @@ -25,20 +25,36 @@ # / | \ # / | \ # / | \ -# Host1 Host3 Host2 +# Host1 Host3 Host2 +# +# +# Execution example: +# +# $ PYTHONPATH=$PYTHONPATH:src/ python examples/openvswitch/ovs_ping_3_switches.py -n "192.168.3.0/24" -C "1.1.1.1" -s -i /~/.ssh/id_rsa +# + from nepi.execution.ec import ExperimentController -import os, time -def add_node(ec, host, user, pl_user, pl_password): +import os +from optparse import OptionParser +import sys +import time + +def add_node(ec, host, user, pl_user, pl_password, identity): node = ec.register_resource("planetlab::Node") ec.set(node, "hostname", host) ec.set(node, "username", user) + ec.set(node, "identity", identity) + if pl_user: ec.set(node, "pluser", pl_user) if pl_password: ec.set(node, "plpassword", pl_password) + if identity: + ec.set(node, "identity", identity) + ec.set(node, "cleanExperiment", True) ec.set(node, "cleanProcesses", True) @@ -79,38 +95,97 @@ def add_app(ec, command, node): app = ec.register_resource("linux::Application") ec.set(app, "command", command) ec.register_connection(app, node) - return app - -# Create the EC -ec = ExperimentController(exp_id = "test-tr") - -#XXX : Need to put 6 working nodes or to let Nepi find for you -switch1 = "planetlab2.virtues.fi" -switch2 = "planetlab2.upc.es" -switch3 = "planetlab1.informatik.uni-erlangen.de" -host1 = "planetlab2.ionio.gr" -host2 = "iraplab2.iralab.uni-karlsruhe.de" -host3 = "planetlab2.diku.dk" - -ip_controller = "xxx.yyy.zzz.ttt" - -#XXX : Depends on the Vsys_tag of your slice -network = "192.168.3.0" - -#XXX : Name of your slice -slicename = "inria_nepi" -pl_user = os.environ.get("PL_USER") -pl_password = os.environ.get("PL_PASS") + return app -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) +def parse_args(): + pl_slice = os.environ.get("PL_SLICE") + pl_user = os.environ.get("PL_USER") + pl_pass = os.environ.get("PL_PASS") + identity = os.environ.get("PL_SSHKEY") + + usage = ("usage: %prog -a -b -c " + "-d -e -f " + "-n -C -s -u " + "-p -i ") + + switch1 = "planetlab2.virtues.fi" + switch2 = "planetlab2.upc.es" + switch3 = "inriarennes1.irisa.fr" + host1 = "planetlab2.ionio.gr" + host2 = "iraplab2.iralab.uni-karlsruhe.de" + host3 = "planetlab2.diku.dk" + + parser = OptionParser(usage = usage) + parser.add_option("-a", "--host1", dest="host1", + help="Hostname for PlanetLab host 1", default=host1) + parser.add_option("-b", "--host2", dest="host2", + help="Hostname for PlanetLab host 2", default=host2) + parser.add_option("-c", "--host3", dest="host3", + help="Hostname for PlanetLab host 3", default=host3) + parser.add_option("-d", "--switch1", dest="switch1", + help="Hostname for PlanetLab switch 1", default=switch1) + parser.add_option("-e", "--switch2", dest="switch2", + help="Hostname for PlanetLab switch 2", default=switch2) + parser.add_option("-f", "--switch3", dest="switch3", + help="Hostname for PlanetLab switch 3", default=switch3) + parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet", + help="Overlay network address of the form x.x.x.x/yy. " + "Must correspond to the vsys_vnet tag on the PlanetLab slice") + parser.add_option("-C", "--controller", dest="controller", + help="IP address for the OpenFlow controller, if one has been deployed", + default="1.1.1.1") + parser.add_option("-s", "--slicename", dest="slicename", + help="Name of PlanetLab slice", + default=pl_slice) + parser.add_option("-u", "--pl_user", dest="pl_user", + help="PlanetLab user (email address)", + default=pl_user) + parser.add_option("-p", "--pl_pass", dest="pl_pass", + help="PlanetLab password", + default=pl_pass) + parser.add_option("-i", "--identity", dest="identity", + help="Path to SSH key", + default=identity) + + (options, args) = parser.parse_args() + + return (options.host1, options.host2, options.host3, options.switch1, + options.switch2, options.switch3, options.vsys_vnet, + options.controller, options.slicename, options.pl_user, + options.pl_pass, identity) + +(host1, host2, host3, switch1, switch2, switch3, vsys_vnet, controller, + slicename, pl_user, pl_pass, identity) = parse_args() -# 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) +# Create the EC +ec = ExperimentController(exp_id = "ovs_3_switch") + +net = vsys_vnet.split("/") +prefix = net[-1] +network = net[0] +net_segs = network.split(".") +ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1 +ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2 +ip3 = "%s.3" % ".".join(net_segs[:-1]) # x.x.x.3 +ip4 = "%s.4" % ".".join(net_segs[:-1]) # x.x.x.4 +ip5 = "%s.5" % ".".join(net_segs[:-1]) # x.x.x.5 +ip6 = "%s.6" % ".".join(net_segs[:-1]) # x.x.x.6 + +### Define topology + +# Add switches +s1_node = add_node(ec, switch1, slicename, pl_user, pl_pass, identity) +s2_node = add_node(ec, switch2, slicename, pl_user, pl_pass, identity) +s3_node = add_node(ec, switch3, slicename, pl_user, pl_pass, identity) + +# Add OVS switches +addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix +addr2 = "%s/%s" % (ip2, prefix) # x.x.x.2/prefix +addr3 = "%s/%s" % (ip3, prefix) # x.x.x.3/prefix +ovs1 = add_ovs(ec, "nepi_bridge_1", addr1, controller, "6633", s1_node) +ovs2 = add_ovs(ec, "nepi_bridge_2", addr2, controller, "6633", s2_node) +ovs3 = add_ovs(ec, "nepi_bridge_3", addr3, controller, "6633", s3_node) # Add ports on ovs port1 = add_port(ec, "nepi_port1", network, ovs1) @@ -121,88 +196,55 @@ port5 = add_port(ec, "nepi_port5", network, ovs2) port3 = add_port(ec, "nepi_port3", network, ovs3) port6 = add_port(ec, "nepi_port6", network, 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 hosts +h1_node = add_node(ec, host1, slicename, pl_user, pl_pass, identity) +h2_node = add_node(ec, host2, slicename, pl_user, pl_pass, identity) +h3_node = add_node(ec, host3, slicename, pl_user, pl_pass, identity) +### Add overlay # 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, ip3, prefix, ip1, h1_node) +tap2 = add_tap(ec, ip4, prefix, ip2, h2_node) +tap3 = add_tap(ec, ip5, prefix, ip6, h3_node) +### Add Pings # Connect the nodes tunnel1 = add_tunnel(ec, port1, tap1) tunnel2 = add_tunnel(ec, port2, tap2) tunnel3 = add_tunnel(ec, port3, tap3) tunnel4 = add_tunnel(ec, port4, port5) tunnel5 = add_tunnel(ec, 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) + +apps = dict() +r2ip = dict({ + s1_node: ("Switch 1", ip1), + s2_node: ("Switch 2", ip2), + s3_node: ("Switch 3", ip3), + h1_node: ("Host 1", ip4), + h2_node: ("Host 2", ip5), + h3_node: ("Host 3", ip6), + }) + +# Ping from all resources to all other resources +for r1, (n1, ip1) in r2ip.iteritems(): + for r2, (n2, ip2) in r2ip.iteritems(): + if r1 == r2: + continue + + app = add_app(ec, "ping -c5 %s" % ip2, r1) + key = "Ping from %s to %s" % (n1, n2) + apps[key] = app 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() +ec.wait_finished(apps.values()) + +# collect results +for key, app in apps.iteritems(): + stdout = ec.trace(app, "stdout") + print "***************************", key, "************************" + print stdout + print "\n" # Delete the overlay network ec.shutdown() -- 2.43.0