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 ------- Switch2
31 from nepi.execution.ec import ExperimentController
34 def add_node(ec, host, user, pl_user, pl_password):
35 node = ec.register_resource("planetlab::Node")
36 ec.set(node, "hostname", host)
37 ec.set(node, "username", user)
39 ec.set(node, "pluser", pl_user)
41 ec.set(node, "plpassword", pl_password)
42 ec.set(node, "cleanExperiment", True)
43 ec.set(node, "cleanProcesses", True)
47 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
48 ovs = ec.register_resource("planetlab::OVSSwitch")
49 ec.set(ovs, "bridge_name", bridge_name)
50 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
51 ec.set(ovs, "controller_ip", controller_ip)
52 ec.set(ovs, "controller_port", controller_port)
53 ec.register_connection(ovs, node)
56 def add_port(ec, port_name, network, ovs):
57 port = ec.register_resource("planetlab::OVSPort")
58 ec.set(port, "port_name", port_name)
59 ec.set(port, "network", network)
60 ec.register_connection(port, ovs)
63 def add_tap(ec, endpoint_ip, endpoint_prefix, pointopoint, node):
64 tap = ec.register_resource("planetlab::Tap")
65 ec.set(tap, "endpoint_ip", endpoint_ip)
66 ec.set(tap, "endpoint_prefix", endpoint_prefix)
67 ec.set(tap, "pointopoint", pointopoint)
68 ec.set(tap, "up", True)
69 ec.register_connection(tap, node)
72 def add_tunnel(ec, port0, tap):
73 tunnel = ec.register_resource("linux::UdpTunnel")
74 ec.register_connection(port0, tunnel)
75 ec.register_connection(tunnel, tap)
78 def add_app(ec, command, node):
79 app = ec.register_resource("linux::Application")
80 ec.set(app, "command", command)
81 ec.register_connection(app, node)
85 ec = ExperimentController(exp_id = "test-tr")
87 #XXX : Need to put 6 working nodes or to let Nepi find for you
88 switch1 = "planetlab2.virtues.fi"
89 switch2 = "planetlab2.upc.es"
90 switch3 = "planetlab1.informatik.uni-erlangen.de"
91 host1 = "planetlab2.ionio.gr"
92 host2 = "iraplab2.iralab.uni-karlsruhe.de"
93 host3 = "planetlab2.diku.dk"
95 ip_controller = "xxx.yyy.zzz.ttt"
97 #XXX : Depends on the Vsys_tag of your slice
98 network = "192.168.3.0"
100 #XXX : Name of your slice
101 slicename = "inria_nepi"
103 pl_user = os.environ.get("PL_USER")
104 pl_password = os.environ.get("PL_PASS")
106 s1_node = add_node(ec, switch1, slicename, pl_user, pl_password)
107 s2_node = add_node(ec, switch2, slicename, pl_user, pl_password)
108 s3_node = add_node(ec, switch3, slicename, pl_user, pl_password)
111 ovs1 = add_ovs(ec, "nepi_bridge_1", "192.168.3.2/24", ip_controller, "6633", s1_node)
112 ovs2 = add_ovs(ec, "nepi_bridge_2", "192.168.3.4/24", ip_controller, "6633", s2_node)
113 ovs3 = add_ovs(ec, "nepi_bridge_3", "192.168.3.6/24", ip_controller, "6633", s3_node)
116 port1 = add_port(ec, "nepi_port1", network, ovs1)
117 port4 = add_port(ec, "nepi_port4", network, ovs1)
118 port7 = add_port(ec, "nepi_port7", network, ovs1)
119 port2 = add_port(ec, "nepi_port2", network, ovs2)
120 port5 = add_port(ec, "nepi_port5", network, ovs2)
121 port3 = add_port(ec, "nepi_port3", network, ovs3)
122 port6 = add_port(ec, "nepi_port6", network, ovs3)
124 h1_node = add_node(ec, host1, slicename, pl_user, pl_password)
125 h2_node = add_node(ec, host2, slicename, pl_user, pl_password)
126 h3_node = add_node(ec, host3, slicename, pl_user, pl_password)
129 tap1 = add_tap(ec, "192.168.3.1", 24, "192.168.3.2", h1_node)
130 tap2 = add_tap(ec, "192.168.3.3", 24, "192.168.3.4", h2_node)
131 tap3 = add_tap(ec, "192.168.3.5", 24, "192.168.3.6", h3_node)
134 tunnel1 = add_tunnel(ec, port1, tap1)
135 tunnel2 = add_tunnel(ec, port2, tap2)
136 tunnel3 = add_tunnel(ec, port3, tap3)
137 tunnel4 = add_tunnel(ec, port4, port5)
138 tunnel5 = add_tunnel(ec, port7, port6)
139 #tunnel6 = add_tunnel(ec, network, port8, port9)
142 app1 = add_app(ec, "ping -c5 192.168.3.4", s1_node)
143 app2 = add_app(ec, "ping -c5 192.168.3.6", s1_node)
144 app3 = add_app(ec, "ping -c5 192.168.3.2", s2_node)
145 app4 = add_app(ec, "ping -c5 192.168.3.6", s2_node)
146 app5 = add_app(ec, "ping -c5 192.168.3.2", s3_node)
147 app6 = add_app(ec, "ping -c5 192.168.3.4", s3_node)
149 app7 = add_app(ec, "ping -c5 192.168.3.3", h1_node)
150 app8 = add_app(ec, "ping -c5 192.168.3.5", h1_node)
151 app9 = add_app(ec, "ping -c5 192.168.3.1", h2_node)
152 app10 = add_app(ec, "ping -c5 192.168.3.5", h2_node)
153 app11 = add_app(ec, "ping -c5 192.168.3.1", h3_node)
154 app12 = add_app(ec, "ping -c5 192.168.3.3", h3_node)
158 ec.wait_finished([app1, app2, app3, app4, app5, app6, app7, app8, app9, app10, app11, app12])
160 # Retreive ping results and save
162 ping1 = ec.trace(app1, 'stdout')
163 ping2 = ec.trace(app2, 'stdout')
164 ping3 = ec.trace(app3, 'stdout')
165 ping4 = ec.trace(app4, 'stdout')
166 ping5 = ec.trace(app5, 'stdout')
167 ping6 = ec.trace(app6, 'stdout')
168 ping7 = ec.trace(app7, 'stdout')
169 ping8 = ec.trace(app8, 'stdout')
170 ping9 = ec.trace(app9, 'stdout')
171 ping10 = ec.trace(app10, 'stdout')
172 ping11 = ec.trace(app11, 'stdout')
173 ping12 = ec.trace(app12, 'stdout')
176 f = open("examples/openvswitch/ovs_ping_3switches_line.txt", 'w')
181 f.write("************ Ping From Switch 1 : 192.168.3.2 ********************\n\n")
183 f.write("--------------------------------------\n")
185 f.write("************ Ping From Switch 2 : 192.168.3.4 ********************\n\n")
187 f.write("--------------------------------------\n")
189 f.write("************ Ping From Switch 3 : 192.168.3.6 ********************\n\n")
191 f.write("--------------------------------------\n")
193 f.write("************ Ping From Host 1 : 192.168.3.1 ********************\n\n")
195 f.write("--------------------------------------\n")
197 f.write("************ Ping From Host 2 : 192.168.3.3 ********************\n\n")
199 f.write("--------------------------------------\n")
201 f.write("************ Ping From Host 3 : 192.168.3.5 ********************\n\n")
203 f.write("--------------------------------------\n")
207 # Delete the overlay network