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 nepi.execution.ec import ExperimentController
39 from optparse import OptionParser
43 def add_node(ec, host, user, pl_user, pl_password, identity):
44 node = ec.register_resource("planetlab::Node")
45 ec.set(node, "hostname", host)
46 ec.set(node, "username", user)
49 ec.set(node, "identity", identity)
51 ec.set(node, "pluser", pl_user)
53 ec.set(node, "plpassword", pl_password)
55 ec.set(node, "cleanExperiment", True)
56 ec.set(node, "cleanProcesses", True)
60 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
61 ovs = ec.register_resource("planetlab::OVSSwitch")
62 ec.set(ovs, "bridge_name", bridge_name)
63 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
64 ec.set(ovs, "controller_ip", controller_ip)
65 ec.set(ovs, "controller_port", controller_port)
66 ec.register_connection(ovs, node)
69 def add_port(ec, port_name, network, ovs):
70 port = ec.register_resource("planetlab::OVSPort")
71 ec.set(port, "port_name", port_name)
72 ec.set(port, "network", network)
73 ec.register_connection(port, ovs)
76 def add_tap(ec, ip, prefix, pointopoint, node):
77 tap = ec.register_resource("planetlab::Tap")
79 ec.set(tap, "prefix", prefix)
80 ec.set(tap, "pointopoint", pointopoint)
81 ec.register_connection(tap, node)
84 def add_tunnel(ec, port0, tap):
85 tunnel = ec.register_resource("linux::UdpTunnel")
86 ec.register_connection(port0, tunnel)
87 ec.register_connection(tunnel, tap)
90 def add_app(ec, command, node):
91 app = ec.register_resource("linux::Application")
92 ec.set(app, "command", command)
93 ec.register_connection(app, node)
97 pl_slice = os.environ.get("PL_SLICE")
98 pl_user = os.environ.get("PL_USER")
99 pl_pass = os.environ.get("PL_PASS")
100 identity = os.environ.get("PL_SSHKEY")
102 usage = ("usage: %prog -a <host1> -b <host2> -c <switch1> -d <switch2> "
103 "-n <vsys_vnet> -C <controller> -s <slicename> -u <pl-user> "
104 "-p <pl-password> -i <ssh-key> ")
106 switch1 = "planetlab2.virtues.fi"
107 switch2 = "planetlab2.upc.es"
108 host1 = "planetlab2.s3.kth.se"
109 host2 = "iraplab2.iralab.uni-karlsruhe.de"
111 parser = OptionParser(usage = usage)
112 parser.add_option("-a", "--host1", dest="host1",
113 help="Hostname for PlanetLab host 1", default=host1)
114 parser.add_option("-b", "--host2", dest="host2",
115 help="Hostname for PlanetLab host 2", default=host2)
116 parser.add_option("-c", "--switch1", dest="switch1",
117 help="Hostname for PlanetLab switch 1", default=switch1)
118 parser.add_option("-d", "--switch2", dest="switch2",
119 help="Hostname for PlanetLab switch 2", default=switch2)
120 parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet",
121 help="Overlay network address of the form x.x.x.x/yy. "
122 "Must correspond to the vsys_vnet tag on the PlanetLab slice")
123 parser.add_option("-C", "--controller", dest="controller",
124 help="IP address for the OpenFlow controller, if one has been deployed",
126 parser.add_option("-s", "--slicename", dest="slicename",
127 help="Name of PlanetLab slice",
129 parser.add_option("-u", "--pl_user", dest="pl_user",
130 help="PlanetLab user (email address)",
132 parser.add_option("-p", "--pl_pass", dest="pl_pass",
133 help="PlanetLab password",
135 parser.add_option("-i", "--identity", dest="identity",
136 help="Path to SSH key",
139 (options, args) = parser.parse_args()
141 return (options.host1, options.host2, options.switch1, options.switch2,
142 options.vsys_vnet, options.controller, options.slicename,
143 options.pl_user, options.pl_pass, identity)
145 (host1, host2, switch1, switch2, vsys_vnet, controller, slicename,
146 pl_user, pl_pass, identity) = parse_args()
149 ec = ExperimentController(exp_id = "ovs_2_switch")
151 net = vsys_vnet.split("/")
154 net_segs = network.split(".")
155 ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1
156 ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2
157 ip3 = "%s.3" % ".".join(net_segs[:-1]) # x.x.x.3
158 ip4 = "%s.4" % ".".join(net_segs[:-1]) # x.x.x.4
163 s1_node = add_node(ec, switch1, slicename, pl_user, pl_pass, identity)
164 s2_node = add_node(ec, switch2, slicename, pl_user, pl_pass, identity)
167 addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix
168 addr2 = "%s/%s" % (ip2, prefix) # x.x.x.2/prefix
169 ovs1 = add_ovs(ec, "nepi_bridge_1", addr1, controller, "6633", s1_node)
170 ovs2 = add_ovs(ec, "nepi_bridge_2", addr2, controller, "6633", s2_node)
173 port1 = add_port(ec, "nepi_port1", network, ovs1)
174 port3 = add_port(ec, "nepi_port3", network, ovs1)
175 port2 = add_port(ec, "nepi_port2", network, ovs2)
176 port4 = add_port(ec, "nepi_port4", network, ovs2)
179 h1_node = add_node(ec, host1, slicename, pl_user, pl_pass, identity)
180 h2_node = add_node(ec, host2, slicename, pl_user, pl_pass, identity)
184 tap1 = add_tap(ec, ip3, prefix, ip1, h1_node)
185 tap2 = add_tap(ec, ip4, prefix, ip2, h2_node)
188 tunnel1 = add_tunnel(ec, port1, tap1)
189 tunnel2 = add_tunnel(ec, port2, tap2)
190 tunnel3 = add_tunnel(ec, port3, port4)
193 app = add_app(ec, "ping -c5 %s" % ip4, h1_node)
197 ec.wait_finished([app])
199 # Retreive ping results and save them in a file
200 stdout = ec.trace(app, "stdout")
202 # Delete the overlay network