4a693fde72db3f02d34e67237f2c2086b53b4ed3
[nepi.git] / examples / planetlab / ping_experiment.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
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.
10 #
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.
15 #
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/>.
18 #
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
20
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceAction, ResourceState
23
24 import os
25
26 exp_id = "ping_exp"
27
28 # Create the entity Experiment Controller:
29 ec = ExperimentController(exp_id)
30
31 # Register the nodes resources:
32
33 # The username in this case is the slice name, the one to use for login in 
34 # via ssh into PlanetLab nodes. Replace with your own slice name.
35 username = "inria_sfatest"
36
37 # The pluser and plpassword are the ones used to login in the PlanetLab web 
38 # site. Replace with your own user and password account information.
39 pl_user = "lucia.guevgeozian_odizzio@inria.fr"
40 pl_password =  os.environ.get("PL_PASS")
41
42 # Define a Planetlab Node with no restriction, it can be any node
43 node = ec.register_resource('PlanetlabNode')
44 ec.set(node, "username", username)
45 ec.set(node, "pluser", pl_user)
46 ec.set(node, "plpassword", pl_password)
47 ec.set(node, "cleanHome", True)
48 ec.set(node, "cleanProcesses", True)
49
50 # Define a ping application
51 app = ec.register_resource('LinuxApplication')
52 ec.set(app, 'command', 'ping -c5 google.com > ping_google.txt')
53
54 # Connect the application to the node
55 ec.register_connection(node, app)
56     
57 # Deploy the experiment:
58 ec.deploy()
59
60 # Wait until the application is finish to retrive the trace:
61 ec.wait_finished(app)
62
63 trace = ec.trace(app, 'ping_google.txt')
64
65 # Choose a directory to store the traces locally, change to a convenient path for you:
66 directory = "examples/planetlab/"
67 trace_file = directory + "ping_google.txt"
68 f = open(trace_file, "w")
69 f.write(trace)
70 f.close()
71
72 # Do the experiment controller shutdown:
73 ec.shutdown()
74
75 # END