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 # $ PYTHONPATH=$PYTHONPATH:src/ python examples/openvswitch/ovs_ping.py -n "192.168.3.0/24" -s <slicename> -i /~/.ssh/id_rsa
36 from nepi.execution.ec import ExperimentController
39 from optparse import OptionParser
44 pl_slice = os.environ.get("PL_SLICE")
45 pl_user = os.environ.get("PL_USER")
46 pl_pass = os.environ.get("PL_PASS")
47 identity = os.environ.get("PL_SSHKEY")
49 usage = ("usage: %prog -a <host> -b <switch>"
50 "-n <vsys_vnet> -C <controller> -s <slicename> -u <pl-user> "
51 "-p <pl-password> -i <ssh-key> ")
53 switch = "planetlab2.virtues.fi"
54 host = "planetlab2.ionio.gr"
56 parser = OptionParser(usage = usage)
57 parser.add_option("-a", "--host", dest="host",
58 help="Hostname for PlanetLab host", default=host)
59 parser.add_option("-b", "--switch", dest="switch",
60 help="Hostname for PlanetLab switch", default=switch)
61 parser.add_option("-n", "--vsys_vnet", dest="vsys_vnet",
62 help="Overlay network address of the form x.x.x.x/yy. "
63 "Must correspond to the vsys_vnet tag on the PlanetLab slice")
64 parser.add_option("-C", "--controller", dest="controller",
65 help="IP address for the OpenFlow controller, if one has been deployed",
67 parser.add_option("-s", "--slicename", dest="slicename",
68 help="Name of PlanetLab slice",
70 parser.add_option("-u", "--pl_user", dest="pl_user",
71 help="PlanetLab user (email address)",
73 parser.add_option("-p", "--pl_pass", dest="pl_pass",
74 help="PlanetLab password",
76 parser.add_option("-i", "--identity", dest="identity",
77 help="Path to SSH key",
80 (options, args) = parser.parse_args()
82 return (options.host, options.switch,
83 options.vsys_vnet, options.controller, options.slicename,
84 options.pl_user, options.pl_pass, identity)
86 (host, switch, vsys_vnet, controller, slicename,
87 pl_user, pl_pass, identity) = parse_args()
90 ec = ExperimentController(exp_id = "ovs_ping")
92 net = vsys_vnet.split("/")
95 net_segs = network.split(".")
96 ip1 = "%s.1" % ".".join(net_segs[:-1]) # x.x.x.1
97 ip2 = "%s.2" % ".".join(net_segs[:-1]) # x.x.x.2
100 node1 = ec.register_resource("planetlab::Node")
101 ec.set(node1, "hostname", switch)
102 ec.set(node1, "username", slicename)
103 ec.set(node1, "identity", identity)
104 ec.set(node1, "pluser", pl_user)
105 ec.set(node1, "plpassword", pl_pass)
106 ec.set(node1, "cleanExperiment", True)
107 ec.set(node1, "cleanProcesses", True)
109 addr1 = "%s/%s" % (ip1, prefix) # x.x.x.1/prefix
110 ovs = ec.register_resource("planetlab::OVSSwitch")
111 ec.set(ovs, "bridge_name", "nepi_bridge")
112 ec.set(ovs, "virtual_ip_pref", addr1)
113 ec.set(ovs, "controller_ip", controller)
114 ec.set(ovs, "controller_port", "6633")
115 ec.register_connection(ovs, node1)
118 node2 = ec.register_resource("planetlab::Node")
119 ec.set(node2, "hostname", host)
120 ec.set(node2, "username", slicename)
121 ec.set(node2, "identity", identity)
122 ec.set(node2, "pluser", pl_user)
123 ec.set(node2, "plpassword", pl_pass)
124 ec.set(node2, "cleanExperiment", True)
125 ec.set(node2, "cleanProcesses", True)
129 tap = ec.register_resource("planetlab::Tap")
130 ec.set(tap, "ip", ip2)
131 ec.set(tap, "prefix", prefix)
132 ec.set(tap, "pointopoint", ip1)
133 ec.set(tap, "up", True)
134 ec.register_connection(tap, node2)
137 port = ec.register_resource("planetlab::OVSPort")
138 ec.set(port, "port_name", "nepi_port")
139 ec.set(port, "network", network)
140 ec.register_connection(port, ovs)
142 # Add tunnel between host and switch
143 tunnel = ec.register_resource("linux::UdpTunnel")
144 ec.register_connection(port, tunnel)
145 ec.register_connection(tunnel, tap)
147 ## Ping switch from host
148 app = ec.register_resource("linux::Application")
149 ec.set(app, "command", "ping -c5 %s" % ip1)
150 ec.register_connection(app, node2)
154 ec.wait_finished([app])
156 # Retreive ping results and save them in a file
157 ping = ec.trace(app, "stdout")
161 # Delete the overlay network