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 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Alexandros Kouvakas <alexandros.kouvakas@gmail.com>
22 # Switch1 ------- Switch2
30 from nepi.execution.ec import ExperimentController
33 def add_node(ec, host, user, pl_user, pl_password):
34 node = ec.register_resource("PlanetlabNode")
35 ec.set(node, "hostname", host)
36 ec.set(node, "username", user)
38 ec.set(node, "pluser", pl_user)
40 ec.set(node, "plpassword", pl_password)
41 ec.set(node, "cleanHome", True)
42 ec.set(node, "cleanProcesses", True)
46 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
47 ovs = ec.register_resource("OVSWitch")
48 ec.set(ovs, "bridge_name", bridge_name)
49 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
50 ec.set(ovs, "controller_ip", controller_ip)
51 ec.set(ovs, "controller_port", controller_port)
52 ec.register_connection(ovs, node)
55 def add_port(ec, port_name, ovs):
56 port = ec.register_resource("OVSPort")
57 ec.set(port, "port_name", port_name)
58 ec.register_connection(port, ovs)
61 def add_tap(ec, ip4, prefix4, pointopoint, node):
62 tap = ec.register_resource("PlanetlabTap")
63 ec.set(tap, "ip4", ip4)
64 ec.set(tap, "prefix4", prefix4)
65 ec.set(tap, "pointopoint", pointopoint)
66 ec.set(tap, "up", True)
67 ec.register_connection(tap, node)
70 def add_tunnel(ec, network, port0, tap):
71 tunnel = ec.register_resource("OVSTunnel")
72 ec.set(tunnel, "network", network)
73 ec.register_connection(port0, tunnel)
74 ec.register_connection(tunnel, tap)
77 def add_app(ec, command, node):
78 app = ec.register_resource("LinuxApplication")
79 ec.set(app, "command", command)
80 ec.register_connection(app, node)
84 ec = ExperimentController(exp_id = "test")
86 switch1 = "planetlab2.virtues.fi"
87 switch2 = "planetlab2.upc.es"
88 host1 = "planetlab2.ionio.gr"
89 host2 = "iraplab2.iralab.uni-karlsruhe.de"
91 network = "192.168.3.0"
93 slicename = "inria_nepi"
95 pl_user = os.environ.get("PL_USER")
96 pl_password = os.environ.get("PL_PASS")
98 s1_node = add_node(ec, switch1, slicename, pl_user, pl_password)
99 s2_node = add_node(ec, switch2, slicename, pl_user, pl_password)
102 ovs1 = add_ovs(ec, "nepi_bridge", "192.168.3.1/24", "85.23.168.77", "6633", s1_node)
103 ovs2 = add_ovs(ec, "nepi_bridge", "192.168.3.2/24", "85.23.168.77", "6633", s2_node)
106 port1 = add_port(ec, "nepi_port1", ovs1)
107 port3 = add_port(ec, "nepi_port3", ovs1)
108 port2 = add_port(ec, "nepi_port2", ovs2)
109 port4 = add_port(ec, "nepi_port4", ovs2)
111 h1_node = add_node(ec, host1, slicename, pl_user, pl_password)
112 h2_node = add_node(ec, host2, slicename, pl_user, pl_password)
115 tap1 = add_tap(ec, "192.168.3.3", 24, "192.168.3.1", h1_node)
116 tap2 = add_tap(ec, "192.168.3.4", 24, "192.168.3.2", h2_node)
119 tunnel1 = add_tunnel(ec, network, port1, tap1)
120 tunnel2 = add_tunnel(ec, network, port2, tap2)
121 tunnel3 = add_tunnel(ec, network, port3, port4)
124 app1 = add_app(ec, "ping -c5 192.168.3.2", s1_node)
125 app2 = add_app(ec, "ping -c5 192.168.3.3", s1_node)
126 app3 = add_app(ec, "ping -c5 192.168.3.4", s1_node)
127 app4 = add_app(ec, "ping -c5 192.168.3.1", s2_node)
128 app5 = add_app(ec, "ping -c5 192.168.3.3", s2_node)
129 app6 = add_app(ec, "ping -c5 192.168.3.4", s2_node)
130 app7 = add_app(ec, "ping -c5 192.168.3.1", h1_node)
131 app8 = add_app(ec, "ping -c5 192.168.3.2", h1_node)
132 app9 = add_app(ec, "ping -c5 192.168.3.4", h1_node)
133 app10 = add_app(ec, "ping -c5 192.168.3.1", h2_node)
134 app11 = add_app(ec, "ping -c5 192.168.3.2", h2_node)
135 app12 = add_app(ec, "ping -c5 192.168.3.3", h2_node)
139 ec.wait_finished([app1, app2, app3, app4, app5, app6, app7, app8, app9, app10, app11, app12])
141 # Retreive ping results and save
143 ping1 = ec.trace(app1, 'stdout')
144 ping2 = ec.trace(app2, 'stdout')
145 ping3 = ec.trace(app3, 'stdout')
146 ping4 = ec.trace(app4, 'stdout')
147 ping5 = ec.trace(app5, 'stdout')
148 ping6 = ec.trace(app6, 'stdout')
149 ping7 = ec.trace(app7, 'stdout')
150 ping8 = ec.trace(app8, 'stdout')
151 ping9 = ec.trace(app9, 'stdout')
152 ping10 = ec.trace(app10, 'stdout')
153 ping11 = ec.trace(app11, 'stdout')
154 ping12 = ec.trace(app12, 'stdout')
157 f = open("examples/openvswitch/ping_res.txt", 'w')
176 # Delete the overlay network