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>
33 # Switch1 ----- Switch2
41 from nepi.execution.ec import ExperimentController
44 def add_node(ec, host, user, pl_user, pl_password):
45 node = ec.register_resource("planetlab::Node")
46 ec.set(node, "hostname", host)
47 ec.set(node, "username", user)
49 ec.set(node, "pluser", pl_user)
51 ec.set(node, "plpassword", pl_password)
52 ec.set(node, "cleanExperiment", True)
53 ec.set(node, "cleanProcesses", True)
57 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
58 ovs = ec.register_resource("planetlab::OVSSwitch")
59 ec.set(ovs, "bridge_name", bridge_name)
60 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
61 ec.set(ovs, "controller_ip", controller_ip)
62 ec.set(ovs, "controller_port", controller_port)
63 ec.register_connection(ovs, node)
66 def add_port(ec, port_name, network, ovs):
67 port = ec.register_resource("planetlab::OVSPort")
68 ec.set(port, "port_name", port_name)
69 ec.set(port, "network", network)
70 ec.register_connection(port, ovs)
73 def add_tap(ec, ip, prefix, pointopoint, node):
74 tap = ec.register_resource("planetlab::Tap")
76 ec.set(tap, "prefix", prefix)
77 ec.set(tap, "pointopoint", pointopoint)
78 ec.set(tap, "up", True)
79 ec.register_connection(tap, node)
82 def add_tunnel(ec, port0, tap):
83 tunnel = ec.register_resource("linux::UdpTunnel")
84 ec.register_connection(port0, tunnel)
85 ec.register_connection(tunnel, tap)
88 def add_app(ec, command, node):
89 app = ec.register_resource("linux::Application")
90 ec.set(app, "command", command)
91 ec.register_connection(app, node)
95 ec = ExperimentController(exp_id = "test-tr")
97 #XXX : Need to put 6 working nodes or to let Nepi find for you
98 switch1 = "planetlab2.virtues.fi"
99 switch2 = "planetlab2.upc.es"
100 switch3 = "planetlab1.informatik.uni-erlangen.de"
101 host1 = "planetlab2.ionio.gr"
102 host2 = "iraplab2.iralab.uni-karlsruhe.de"
103 host3 = "planetlab2.diku.dk"
105 #ip_controller = "194.254.215.12"
106 ip_controller = "xxx.yyy.zzz.ttt"
108 #XXX : Depends on the Vsys_tag of your slice
109 network = "192.168.3.0"
111 #XXX : Name of your slice
112 slicename = "inria_nepi"
114 pl_user = os.environ.get("PL_USER")
115 pl_password = os.environ.get("PL_PASS")
117 s1_node = add_node(ec, switch1, slicename, pl_user, pl_password)
118 s2_node = add_node(ec, switch2, slicename, pl_user, pl_password)
119 s3_node = add_node(ec, switch3, slicename, pl_user, pl_password)
122 ovs1 = add_ovs(ec, "nepi_bridge_1", "192.168.3.2/24", ip_controller, "6633", s1_node)
123 ovs2 = add_ovs(ec, "nepi_bridge_2", "192.168.3.4/24", ip_controller, "6633", s2_node)
124 ovs3 = add_ovs(ec, "nepi_bridge_3", "192.168.3.6/24", ip_controller, "6633", s3_node)
127 port1 = add_port(ec, "nepi_port1", network, ovs1)
128 port4 = add_port(ec, "nepi_port4", network, ovs1)
129 port7 = add_port(ec, "nepi_port7", network, ovs1)
130 port2 = add_port(ec, "nepi_port2", network, ovs2)
131 port5 = add_port(ec, "nepi_port5", network, ovs2)
132 port8 = add_port(ec, "nepi_port8", network, ovs2)
133 port3 = add_port(ec, "nepi_port3", network, ovs3)
134 port6 = add_port(ec, "nepi_port6", network, ovs3)
135 port9 = add_port(ec, "nepi_port9", network, ovs3)
137 h1_node = add_node(ec, host1, slicename, pl_user, pl_password)
138 h2_node = add_node(ec, host2, slicename, pl_user, pl_password)
139 h3_node = add_node(ec, host3, slicename, pl_user, pl_password)
142 tap1 = add_tap(ec, "192.168.3.1", "24", "192.168.3.2", h1_node)
143 tap2 = add_tap(ec, "192.168.3.3", "24", "192.168.3.4", h2_node)
144 tap3 = add_tap(ec, "192.168.3.5", "24", "192.168.3.6", h3_node)
147 tunnel1 = add_tunnel(ec, port1, tap1)
148 tunnel2 = add_tunnel(ec, port2, tap2)
149 tunnel3 = add_tunnel(ec, port3, tap3)
150 tunnel4 = add_tunnel(ec, port4, port5)
151 tunnel5 = add_tunnel(ec, port7, port6)
152 tunnel6 = add_tunnel(ec, port8, port9)
155 app1 = add_app(ec, "ping -c5 192.168.3.4", s1_node)
156 app2 = add_app(ec, "ping -c5 192.168.3.6", s1_node)
157 app3 = add_app(ec, "ping -c5 192.168.3.2", s2_node)
158 app4 = add_app(ec, "ping -c5 192.168.3.6", s2_node)
159 app5 = add_app(ec, "ping -c5 192.168.3.2", s3_node)
160 app6 = add_app(ec, "ping -c5 192.168.3.4", s3_node)
162 app7 = add_app(ec, "ping -c5 192.168.3.3", h1_node)
163 app8 = add_app(ec, "ping -c5 192.168.3.5", h1_node)
164 app9 = add_app(ec, "ping -c5 192.168.3.1", h2_node)
165 app10 = add_app(ec, "ping -c5 192.168.3.5", h2_node)
166 app11 = add_app(ec, "ping -c5 192.168.3.1", h3_node)
167 app12 = add_app(ec, "ping -c5 192.168.3.3", h3_node)
171 ec.wait_finished([app1, app2, app3, app4, app5, app6, app7, app8, app9, app10, app11, app12])
173 # Retreive ping results and save them in a file
174 ping1 = ec.trace(app1, 'stdout')
175 ping2 = ec.trace(app2, 'stdout')
176 ping3 = ec.trace(app3, 'stdout')
177 ping4 = ec.trace(app4, 'stdout')
178 ping5 = ec.trace(app5, 'stdout')
179 ping6 = ec.trace(app6, 'stdout')
180 ping7 = ec.trace(app7, 'stdout')
181 ping8 = ec.trace(app8, 'stdout')
182 ping9 = ec.trace(app9, 'stdout')
183 ping10 = ec.trace(app10, 'stdout')
184 ping11 = ec.trace(app11, 'stdout')
185 ping12 = ec.trace(app12, 'stdout')
188 f = open("examples/openvswitch/ovs_ping_3switches_loop.txt", 'w')
193 f.write("************ Ping From Switch 1 : 192.168.3.2 ********************\n\n")
195 f.write("--------------------------------------\n")
197 f.write("************ Ping From Switch 2 : 192.168.3.4 ********************\n\n")
199 f.write("--------------------------------------\n")
201 f.write("************ Ping From Switch 3 : 192.168.3.6 ********************\n\n")
203 f.write("--------------------------------------\n")
205 f.write("************ Ping From Host 1 : 192.168.3.1 ********************\n\n")
207 f.write("--------------------------------------\n")
209 f.write("************ Ping From Host 2 : 192.168.3.3 ********************\n\n")
211 f.write("--------------------------------------\n")
213 f.write("************ Ping From Host 3 : 192.168.3.5 ********************\n\n")
215 f.write("--------------------------------------\n")
219 # Delete the overlay network