3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Authors : Julien Tribino <julien.tribino@inria.fr>
19 # Alina Quereilhac <alina.quereilhac@inria.fr>
24 # Switch1 -------- Switch2
33 # $ 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
36 from __future__ import print_function
38 from nepi.execution.ec import ExperimentController
41 from optparse import OptionParser
45 def add_node(ec, host, user, pl_user, pl_password, identity):
46 node = ec.register_resource("planetlab::Node")
47 ec.set(node, "hostname", host)
48 ec.set(node, "username", user)
51 ec.set(node, "identity", identity)
53 ec.set(node, "pluser", pl_user)
55 ec.set(node, "plpassword", pl_password)
57 ec.set(node, "cleanExperiment", True)
58 ec.set(node, "cleanProcesses", True)
62 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
63 ovs = ec.register_resource("planetlab::OVSSwitch")
64 ec.set(ovs, "bridge_name", bridge_name)
65 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
66 ec.set(ovs, "controller_ip", controller_ip)
67 ec.set(ovs, "controller_port", controller_port)
68 ec.register_connection(ovs, node)
71 def add_port(ec, port_name, network, ovs):
72 port = ec.register_resource("planetlab::OVSPort")
73 ec.set(port, "port_name", port_name)
74 ec.set(port, "network", network)
75 ec.register_connection(port, ovs)
78 def add_tap(ec, ip, prefix, pointopoint, node):
79 tap = ec.register_resource("planetlab::Tap")
81 ec.set(tap, "prefix", prefix)
82 ec.set(tap, "pointopoint", pointopoint)
83 ec.register_connection(tap, node)
86 def add_tunnel(ec, port0, tap):
87 tunnel = ec.register_resource("linux::UdpTunnel")
88 ec.register_connection(port0, tunnel)
89 ec.register_connection(tunnel, tap)
92 def add_app(ec, command, node):
93 app = ec.register_resource("linux::Application")
94 ec.set(app, "command", command)
95 ec.register_connection(app, node)
99 pl_slice = os.environ.get("PL_SLICE")
100 pl_user = os.environ.get("PL_USER")
101 pl_pass = os.environ.get("PL_PASS")
102 identity = os.environ.get("PL_SSHKEY")
104 usage = ("usage: %prog -a <host1> -b <host2> -c <switch1> -d <switch2> "
105 "-n <vsys_vnet> -C <controller> -s <slicename> -u <pl-user> "
106 "-p <pl-password> -i <ssh-key> ")
108 switch1 = "planetlab2.virtues.fi"
109 switch2 = "planetlab2.upc.es"
110 host1 = "planetlab2.s3.kth.se"
111 host2 = "iraplab2.iralab.uni-karlsruhe.de"
113 parser = OptionParser(usage = usage)
114 parser.add_option("-a", "--host1", dest="host1",
115 help="Hostname for PlanetLab host 1", default=host1)
116 parser.add_option("-b", "--host2", dest="host2",
117 help="Hostname for PlanetLab host 2", default=host2)
118 parser.add_option("-c", "--switch1", dest="switch1",
119 help="Hostname for PlanetLab switch 1", default=switch1)
120 parser.add_option("-d", "--switch2", dest="switch2",
121 help="Hostname for PlanetLab switch 2", default=switch2)
122 parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet",
123 help="Overlay network address of the form x.x.x.x/yy. "
124 "Must correspond to the vsys_vnet tag on the PlanetLab slice")
125 parser.add_option("-C", "--controller", dest="controller",
126 help="IP address for the OpenFlow controller, if one has been deployed",
128 parser.add_option("-s", "--slicename", dest="slicename",
129 help="Name of PlanetLab slice",
131 parser.add_option("-u", "--pl_user", dest="pl_user",
132 help="PlanetLab user (email address)",
134 parser.add_option("-p", "--pl_pass", dest="pl_pass",
135 help="PlanetLab password",
137 parser.add_option("-i", "--identity", dest="identity",
138 help="Path to SSH key",
141 (options, args) = parser.parse_args()
143 return (options.host1, options.host2, options.switch1, options.switch2,
144 options.vsys_vnet, options.controller, options.slicename,
145 options.pl_user, options.pl_pass, identity)
147 (host1, host2, switch1, switch2, vsys_vnet, controller, slicename,
148 pl_user, pl_pass, identity) = parse_args()
151 ec = ExperimentController(exp_id = "ovs_2_switch")
153 net = vsys_vnet.split("/")
156 net_segs = network.split(".")
157 ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1
158 ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2
159 ip3 = "%s.3" % ".".join(net_segs[:-1]) # x.x.x.3
160 ip4 = "%s.4" % ".".join(net_segs[:-1]) # x.x.x.4
165 s1_node = add_node(ec, switch1, slicename, pl_user, pl_pass, identity)
166 s2_node = add_node(ec, switch2, slicename, pl_user, pl_pass, identity)
169 addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix
170 addr2 = "%s/%s" % (ip2, prefix) # x.x.x.2/prefix
171 ovs1 = add_ovs(ec, "nepi_bridge_1", addr1, controller, "6633", s1_node)
172 ovs2 = add_ovs(ec, "nepi_bridge_2", addr2, controller, "6633", s2_node)
175 port1 = add_port(ec, "nepi_port1", network, ovs1)
176 port3 = add_port(ec, "nepi_port3", network, ovs1)
177 port2 = add_port(ec, "nepi_port2", network, ovs2)
178 port4 = add_port(ec, "nepi_port4", network, ovs2)
181 h1_node = add_node(ec, host1, slicename, pl_user, pl_pass, identity)
182 h2_node = add_node(ec, host2, slicename, pl_user, pl_pass, identity)
186 tap1 = add_tap(ec, ip3, prefix, ip1, h1_node)
187 tap2 = add_tap(ec, ip4, prefix, ip2, h2_node)
190 tunnel1 = add_tunnel(ec, port1, tap1)
191 tunnel2 = add_tunnel(ec, port2, tap2)
192 tunnel3 = add_tunnel(ec, port3, port4)
195 app = add_app(ec, "ping -c5 %s" % ip4, h1_node)
199 ec.wait_finished([app])
201 # Retreive ping results and save them in a file
202 stdout = ec.trace(app, "stdout")
204 # Delete the overlay network