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
32 def add_node(ec, host, user):
33 node = ec.register_resource("PlanetlabNode")
34 ec.set(node, "hostname", host)
35 ec.set(node, "username", user)
36 ec.set(node, "cleanHome", True)
37 ec.set(node, "cleanProcesses", True)
40 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
41 ovs = ec.register_resource("OVSWitch")
42 ec.set(ovs, "bridge_name", bridge_name)
43 ec.set(ovs, "virtual_ip_pref", virtual_ip_pref)
44 ec.set(ovs, "controller_ip", controller_ip)
45 ec.set(ovs, "controller_port", controller_port)
46 ec.register_connection(ovs, node)
49 def add_port(ec, port_name, ovs):
50 port = ec.register_resource("OVSPort")
51 ec.set(port, "port_name", port_name)
52 ec.register_connection(port, ovs)
55 def add_tap(ec, ip4, prefix4, pointopoint, node):
56 tap = ec.register_resource("PlanetlabTap")
57 ec.set(tap, "ip4", ip4)
58 ec.set(tap, "prefix4", prefix4)
59 ec.set(tap, "pointopoint", pointopoint)
60 ec.set(tap, "up", True)
61 ec.register_connection(tap, node)
64 def add_tunnel(ec, port0, tap):
65 tunnel = ec.register_resource("Tunnel")
66 ec.register_connection(port0, tunnel)
67 ec.register_connection(tunnel, tap)
70 def add_app(ec, command, node):
71 app = ec.register_resource("LinuxApplication")
72 ec.set(app, "command", command)
73 ec.register_connection(app, node)
77 ec = ExperimentController(exp_id = "one")
79 switch1 = "planetlab2.virtues.fi"
80 switch2 = "planetlab2.upc.es"
81 host1 = "planetlab2.ionio.gr"
82 host2 = "planetlab2.cs.aueb.gr"
84 slicename = "inria_nepi"
86 s1_node = add_node(ec, switch1, slicename)
87 s2_node = add_node(ec, switch2, slicename)
90 ovs1 = add_ovs(ec, "nepi_bridge", "192.168.3.1/24", "85.23.168.77", "6633", s1_node)
91 ovs2 = add_ovs(ec, "nepi_bridge", "192.168.3.2/24", "85.23.168.77", "6633", s2_node)
94 port1 = add_port(ec, "nepi_port1", ovs1)
95 port3 = add_port(ec, "nepi_port3", ovs1)
96 port2 = add_port(ec, "nepi_port2", ovs2)
97 port4 = add_port(ec, "nepi_port4", ovs2)
99 h1_node = add_node(ec, host1, slicename)
100 h2_node = add_node(ec, host2, slicename)
103 tap1 = add_tap(ec, "192.168.3.3", 24, "192.168.3.1", h1_node)
104 tap2 = add_tap(ec, "192.168.3.4", 24, "192.168.3.1", h2_node)
107 tunnel1 = add_tunnel(ec, port1, tap1)
108 tunnel2 = add_tunnel(ec, port2, tap2)
109 tunnel3 = add_tunnel(ec, port3, port4)
112 app1 = add_app(ec, "ping -c3 192.168.3.3", s1_node)
113 app2 = add_app(ec, "ping -c3 192.168.3.4", s2_node)
116 ec.wait_finished([app2])
118 # Retreive ping results and save
120 ping1 = ec.trace(app1, 'stdout')
121 ping2 = ec.trace(app2, 'stdout')
122 f = open("examples/openvswitch/ping_res.txt", 'w').close()
123 f = open("examples/openvswitch/ping_res.txt", 'a')
128 # Delete the overlay network