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 version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
19 # Alina Quereilhac <alina.quereilhac@inria.fr>
22 # Example of how to run this experiment (replace with your information):
25 # python examples/planetlab/ping.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>
27 from __future__ import print_function
29 from nepi.execution.ec import ExperimentController
31 from optparse import OptionParser
34 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
37 parser = OptionParser(usage = usage)
38 parser.add_option("-s", "--pl-slice", dest="pl_slice",
39 help="PlanetLab slicename", type="str")
40 parser.add_option("-u", "--pl-user", dest="pl_user",
41 help="PlanetLab web username", type="str")
42 parser.add_option("-p", "--pl-password", dest="pl_password",
43 help="PlanetLab web password", type="str")
44 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
45 help="Path to private SSH key associated with the PL account",
48 (options, args) = parser.parse_args()
50 pl_slice = options.pl_slice
51 pl_ssh_key = options.pl_ssh_key
52 pl_user = options.pl_user
53 pl_password = options.pl_password
55 ## Create the experiment controller
56 ec = ExperimentController(exp_id = "pl_ping")
58 # Register a Planetlab Node with no restrictions, it can be any node
59 node = ec.register_resource("planetlab::Node")
61 # The username in this case is the slice name, the one to use for login in
62 # via ssh into PlanetLab nodes. Replace with your own slice name.
63 ec.set(node, "username", pl_slice)
64 ec.set(node, "identity", pl_ssh_key)
66 # The pluser and plpassword are the ones used to login in the PlanetLab web
67 # site. Replace with your own user and password account information.
68 ec.set(node, "pluser", pl_user)
69 ec.set(node, "plpassword", pl_password)
71 # Remove previous results
72 ec.set(node, "cleanExperiment", True)
73 ec.set(node, "cleanProcesses", True)
75 # Define a ping application
76 app = ec.register_resource("linux::Application")
77 ec.set(app, "command", "ping -c3 nepi.inria.fr")
79 # Connect the application to the node
80 ec.register_connection(node, app)
82 # Deploy the experiment:
85 # Wait until the application is finish to retrive the trace:
88 trace = ec.trace(app, "stdout")
90 print("PING outout ", trace)
92 # Do the experiment controller shutdown