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 as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Authors : Julien Tribino <julien.tribino@inria.fr>
20 # 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.set(tap, "up", True)
82 ec.register_connection(tap, node)
85 def add_tunnel(ec, port0, tap):
86 tunnel = ec.register_resource("linux::UdpTunnel")
87 ec.register_connection(port0, tunnel)
88 ec.register_connection(tunnel, tap)
91 def add_app(ec, command, node):
92 app = ec.register_resource("linux::Application")
93 ec.set(app, "command", command)
94 ec.register_connection(app, node)
98 pl_slice = os.environ.get("PL_SLICE")
99 pl_user = os.environ.get("PL_USER")
100 pl_pass = os.environ.get("PL_PASS")
101 identity = os.environ.get("PL_SSHKEY")
103 usage = ("usage: %prog -a <host1> -b <host2> -c <switch1> -d <switch2> "
104 "-n <vsys_vnet> -C <controller> -s <slicename> -u <pl-user> "
105 "-p <pl-password> -i <ssh-key> ")
107 switch1 = "planetlab2.virtues.fi"
108 switch2 = "planetlab2.upc.es"
109 host1 = "planetlab2.ionio.gr"
110 host2 = "iraplab2.iralab.uni-karlsruhe.de"
112 parser = OptionParser(usage = usage)
113 parser.add_option("-a", "--host1", dest="host1",
114 help="Hostname for PlanetLab host 1", default=host1)
115 parser.add_option("-b", "--host2", dest="host2",
116 help="Hostname for PlanetLab host 2", default=host2)
117 parser.add_option("-c", "--switch1", dest="switch1",
118 help="Hostname for PlanetLab switch 1", default=switch1)
119 parser.add_option("-d", "--switch2", dest="switch2",
120 help="Hostname for PlanetLab switch 2", default=switch2)
121 parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet",
122 help="Overlay network address of the form x.x.x.x/yy. "
123 "Must correspond to the vsys_vnet tag on the PlanetLab slice")
124 parser.add_option("-C", "--controller", dest="controller",
125 help="IP address for the OpenFlow controller, if one has been deployed",
127 parser.add_option("-s", "--slicename", dest="slicename",
128 help="Name of PlanetLab slice",
130 parser.add_option("-u", "--pl_user", dest="pl_user",
131 help="PlanetLab user (email address)",
133 parser.add_option("-p", "--pl_pass", dest="pl_pass",
134 help="PlanetLab password",
136 parser.add_option("-i", "--identity", dest="identity",
137 help="Path to SSH key",
140 (options, args) = parser.parse_args()
142 return (options.host1, options.host2, options.switch1, options.switch2,
143 options.vsys_vnet, options.controller, options.slicename,
144 options.pl_user, options.pl_pass, identity)
146 (host1, host2, switch1, switch2, vsys_vnet, controller, slicename,
147 pl_user, pl_pass, identity) = parse_args()
150 ec = ExperimentController(exp_id = "ovs_2_switch")
152 net = vsys_vnet.split("/")
155 net_segs = network.split(".")
156 ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1
157 ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2
158 ip3 = "%s.3" % ".".join(net_segs[:-1]) # x.x.x.3
159 ip4 = "%s.4" % ".".join(net_segs[:-1]) # x.x.x.4
164 s1_node = add_node(ec, switch1, slicename, pl_user, pl_pass, identity)
165 s2_node = add_node(ec, switch2, slicename, pl_user, pl_pass, identity)
168 addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix
169 addr2 = "%s/%s" % (ip2, prefix) # x.x.x.2/prefix
170 ovs1 = add_ovs(ec, "nepi_bridge_1", addr1, controller, "6633", s1_node)
171 ovs2 = add_ovs(ec, "nepi_bridge_2", addr2, controller, "6633", s2_node)
174 port1 = add_port(ec, "nepi_port1", network, ovs1)
175 port3 = add_port(ec, "nepi_port3", network, ovs1)
176 port2 = add_port(ec, "nepi_port2", network, ovs2)
177 port4 = add_port(ec, "nepi_port4", network, ovs2)
180 h1_node = add_node(ec, host1, slicename, pl_user, pl_pass, identity)
181 h2_node = add_node(ec, host2, slicename, pl_user, pl_pass, identity)
185 tap1 = add_tap(ec, ip3, prefix, ip1, h1_node)
186 tap2 = add_tap(ec, ip4, prefix, ip2, h2_node)
189 tunnel1 = add_tunnel(ec, port1, tap1)
190 tunnel2 = add_tunnel(ec, port2, tap2)
191 tunnel3 = add_tunnel(ec, port3, port4)
194 # Ping switch 1 to switch2
195 app1 = add_app(ec, "ping -c5 %s" % ip2, s1_node)
196 # Ping switch 1 to host1
197 app2 = add_app(ec, "ping -c5 %s" % ip3, s1_node)
198 # Ping switch 1 to host2
199 app3 = add_app(ec, "ping -c5 %s" % ip4, s1_node)
201 # Ping switch 2 to switch1
202 app4 = add_app(ec, "ping -c5 %s" % ip1, s2_node)
203 # Ping switch 2 to host1
204 app5 = add_app(ec, "ping -c5 %s" % ip3, s2_node)
205 # Ping switch 2 to host2
206 app6 = add_app(ec, "ping -c5 %s" % ip4, s2_node)
208 # Ping host 1 to switch 1
209 app7 = add_app(ec, "ping -c5 %s" % ip1, h1_node)
210 # Ping host 1 to switch 2
211 app8 = add_app(ec, "ping -c5 %s" % ip2, h1_node)
212 # Ping host 1 to host 2
213 app9 = add_app(ec, "ping -c5 %s" % ip4, h1_node)
215 # Ping host 2 to switch 1
216 app10 = add_app(ec, "ping -c5 %s" % ip1, h2_node)
217 # Ping host 2 to switch 2
218 app11 = add_app(ec, "ping -c5 %s" % ip2, h2_node)
219 # Ping host 2 to host1
220 app12 = add_app(ec, "ping -c5 %s" % ip3, h2_node)
224 ec.wait_finished([app1, app2, app3, app4, app5, app6,
225 app7, app8, app9, app10, app11, app12])
227 # Retreive ping results and save them in a file
228 ping1 = ec.trace(app1, "stdout")
229 ping2 = ec.trace(app2, "stdout")
230 ping3 = ec.trace(app3, "stdout")
231 ping4 = ec.trace(app4, "stdout")
232 ping5 = ec.trace(app5, "stdout")
233 ping6 = ec.trace(app6, "stdout")
234 ping7 = ec.trace(app7, "stdout")
235 ping8 = ec.trace(app8, "stdout")
236 ping9 = ec.trace(app9, "stdout")
237 ping10 = ec.trace(app10, "stdout")
238 ping11 = ec.trace(app11, "stdout")
239 ping12 = ec.trace(app12, "stdout")
243 sys.exit("No ping found")
245 f = open("ovs_ping_2_switches.txt", 'w')
246 f.write("************ Ping From Switch 1 : %s ********************\n\n\n" % ip1)
248 f.write("----------------------------------------\n\n")
250 f.write("----------------------------------------\n\n")
253 f.write("************ Ping From Switch 2 : %s ********************\n\n\n" % ip2)
255 f.write("----------------------------------------\n\n")
257 f.write("----------------------------------------\n\n")
260 f.write("************ Ping From Host 1 : %s ********************\n\n\n" % ip3)
262 f.write("----------------------------------------\n\n")
264 f.write("----------------------------------------\n\n")
267 f.write("************ Ping From Host 2 : %s ********************\n\n\n" % ip4)
269 f.write("----------------------------------------\n\n")
271 f.write("----------------------------------------\n\n")
276 # Delete the overlay network