Added LICENSE
[nepi.git] / examples / linux / scalability.py
1 """
2     NEPI, a framework to manage network experiments
3     Copyright (C) 2013 INRIA
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
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.
14
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/>.
17
18 """
19
20 #!/usr/bin/env python
21 from nepi.execution.ec import ExperimentController, ECState 
22 from nepi.execution.resource import ResourceState, ResourceAction, \
23         populate_factory
24
25 from optparse import OptionParser, SUPPRESS_HELP
26
27 import os
28 import time
29
30 def add_node(ec, host, user):
31     node = ec.register_resource("LinuxNode")
32     ec.set(node, "hostname", host)
33     ec.set(node, "username", user)
34     ec.set(node, "cleanHome", True)
35     ec.set(node, "cleanProcesses", True)
36     return node
37
38 def add_app(ec):
39     app = ec.register_resource("LinuxApplication")
40     ec.set(app, "command", "sleep 30; echo 'HOLA'")
41     return app
42
43 def get_options():
44     slicename = os.environ.get("PL_SLICE")
45
46     usage = "usage: %prog -s <pl-slice>"
47
48     parser = OptionParser(usage=usage)
49     parser.add_option("-s", "--pl-slice", dest="pl_slice", 
50             help="PlanetLab slicename", default=slicename, type="str")
51     parser.add_option("-l", "--exp-id", dest="exp_id", 
52             help="Label to identify experiment", type="str")
53
54     (options, args) = parser.parse_args()
55
56     return (options.pl_slice, options.exp_id)
57
58 if __name__ == '__main__':
59     ( pl_slice, exp_id ) = get_options()
60
61     # Search for available RMs
62     populate_factory()
63     
64     apps = []
65   
66     hostnames = [
67              "planetlab-2.research.netlab.hut.fi",
68              "planetlab2.willab.fi",
69              "planetlab3.hiit.fi",
70              "planetlab4.hiit.fi",
71              "planetlab1.willab.fi",
72              "planetlab1.s3.kth.se",
73              "itchy.comlab.bth.se",
74              "planetlab-1.ida.liu.se",
75              "planetlab2.s3.kth.se",
76              "planetlab1.sics.se",
77              "planetlab1.tlm.unavarra.es",
78              "planetlab2.uc3m.es",
79              "planetlab1.uc3m.es",
80              "planetlab2.um.es",
81              "planet1.servers.ua.pt",
82              "planetlab2.fct.ualg.pt",
83              "planetlab-1.tagus.ist.utl.pt",
84              "planetlab-2.tagus.ist.utl.pt",
85              "planetlab-um00.di.uminho.pt",
86              "planet2.servers.ua.pt",
87              "planetlab1.mini.pw.edu.pl",
88              "roti.mimuw.edu.pl",
89              "planetlab1.ci.pwr.wroc.pl",
90              "planetlab1.pjwstk.edu.pl",
91              "ple2.tu.koszalin.pl",
92              "planetlab2.ci.pwr.wroc.pl",
93              "planetlab2.cyfronet.pl",
94              "plab2.ple.silweb.pl",
95              "planetlab1.cyfronet.pl",
96              "plab4.ple.silweb.pl",
97              "ple2.dmcs.p.lodz.pl",
98              "planetlab2.pjwstk.edu.pl",
99              "ple1.dmcs.p.lodz.pl",
100              "gschembra3.diit.unict.it",
101              "planetlab1.science.unitn.it",
102              "planetlab-1.ing.unimo.it",
103              "gschembra4.diit.unict.it",
104              "iraplab1.iralab.uni-karlsruhe.de",
105              "planetlab-1.fokus.fraunhofer.de",
106              "iraplab2.iralab.uni-karlsruhe.de",
107              "planet2.zib.de",
108              "pl2.uni-rostock.de",
109              "onelab-1.fhi-fokus.de",
110              "planet2.l3s.uni-hannover.de",
111              "planetlab1.exp-math.uni-essen.de",
112              "planetlab-2.fokus.fraunhofer.de",
113              "planetlab02.tkn.tu-berlin.de",
114              "planetlab1.informatik.uni-goettingen.de",
115              "planetlab1.informatik.uni-erlangen.de",
116              "planetlab2.lkn.ei.tum.de",
117              "planetlab1.wiwi.hu-berlin.de",
118              "planet1.l3s.uni-hannover.de",
119              "planetlab1.informatik.uni-wuerzburg.de",
120              "host3-plb.loria.fr",
121              "inriarennes1.irisa.fr",
122              "inriarennes2.irisa.fr",
123              "peeramide.irisa.fr",
124              "planetlab-1.imag.fr",
125              "planetlab-2.imag.fr",
126              "ple2.ipv6.lip6.fr",
127              "planetlab1.u-strasbg.fr",
128              "planetlab1.ionio.gr",
129              "planetlab2.ionio.gr",
130              "stella.planetlab.ntua.gr",
131              "vicky.planetlab.ntua.gr",
132              "planetlab1.cs.uoi.gr",
133              "pl002.ece.upatras.gr",
134              "planetlab04.cnds.unibe.ch",
135              "lsirextpc01.epfl.ch",
136              "planetlab2.csg.uzh.ch",
137              "planetlab1.csg.uzh.ch",
138              "planetlab-2.cs.unibas.ch",
139              "planetlab-1.cs.unibas.ch",
140              "planetlab4.cs.st-andrews.ac.uk",
141              "planetlab3.xeno.cl.cam.ac.uk",
142              "planetlab1.xeno.cl.cam.ac.uk",
143              "planetlab2.xeno.cl.cam.ac.uk",
144              "planetlab3.cs.st-andrews.ac.uk",
145              "planetlab1.aston.ac.uk",
146              "planetlab1.nrl.eecs.qmul.ac.uk",
147              "chimay.infonet.fundp.ac.be",
148              "orval.infonet.fundp.ac.be",
149              "rochefort.infonet.fundp.ac.be",
150             ]
151  
152     ec = ExperimentController(exp_id = exp_id)
153
154     for host in hostnames:
155         node = add_node(ec, host, pl_slice)
156         for i in xrange(20):
157             app = add_app(ec)
158             ec.register_connection(app, node)
159             apps.append(app)
160
161     ec.deploy()
162
163     ec.wait_finished(apps)
164
165     ec.shutdown()