9c342267319a7f1a4a92585b5ca7b868a0efeb48
[nepi.git] / examples / ns3 / multi_host / case_a.py
1 #!/usr/bin/env python\r
2 #\r
3 #    NEPI, a framework to manage network experiments\r
4 #    Copyright (C) 2013 INRIA\r
5 #\r
6 #    This program is free software: you can redistribute it and/or modify\r
7 #    it under the terms of the GNU General Public License version 2 as\r
8 #    published by the Free Software Foundation;\r
9 #\r
10 #    This program is distributed in the hope that it will be useful,\r
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 #    GNU General Public License for more details.\r
14 #\r
15 #    You should have received a copy of the GNU General Public License\r
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
17 #\r
18 # Author: Damien Saucez <damien.saucez@inria.fr>\r
19 #         Alina Quereilhac <alina.quereilhac@inria.fr>\r
20 \r
21 import os\r
22 from experiment imptort Experiment\r
23 from nepi.execution.ec import ExperimentController\r
24 from nepi.execution.resource import ResourceState, ResourceManager\r
25 \r
26 # Experiment parameters\r
27 experiment_id = "case_a"\r
28 agent = "10.0.1.1"\r
29 netblock = "10.0.1.0"\r
30 prefix = "24"\r
31 # number of nodes to test\r
32 parameters = [3]\r
33 \r
34 # list of hosts for running the experiment on                                                     \r
35 node_info = [\r
36         {"hostname":"onelab4.warsaw.rd.tp.pl", \r
37         "username":"inria_nepi", \r
38         "identity": "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])}]\r
39 \r
40 # tunning\r
41 os.environ["NEPI_NTHREADS"] = "1"\r
42 ResourceManager._reschedule_delay = "0s"\r
43 \r
44 # == Experimentation setup ====================================================\r
45 def main():\r
46     # Prepare the ExperimentController\r
47     ec = ExperimentController(exp_id = experiment_id)\r
48 \r
49     # run experimentation as long as there is something to do\r
50     while len(parameters) > 0:\r
51         # Collection of application being processed\r
52         jobs = list()\r
53 \r
54         # Collection of experiments launched\r
55         xps = list()\r
56 \r
57         # Push a job on each node in the cluster\r
58         for node in node_info:\r
59             # Stop if nothing else to do\r
60             if len(parameters) == 0:\r
61                 break\r
62 \r
63             # Determine what network size to test\r
64             nb_nodes = parameters.pop(0)\r
65 \r
66             # Create the simulated network\r
67             xp = Experiment(ec, node, nb_nodes, False)\r
68             xp.build_topology(netblock, prefix, agent)\r
69 \r
70             # Remember the experiments just created\r
71             xps.append(xp)\r
72 \r
73             # Remember the applications to be executed\r
74             jobs += xp.apps\r
75         \r
76         # Let's run the experiment\r
77         ec.deploy()\r
78         ec.wait_finished(jobs)\r
79 \r
80         # Check if everything went well for each experiment\r
81         for xp in xps:\r
82             # and see the output\r
83             stdout = ec.trace(xp.apps[0], "stdout")\r
84             print "[", stdout, "]"\r
85             # check if one transmitter failed (if everything goes well, all trasmitters\r
86             # must have stopped properly) (ignore the agent)\r
87             for app in xp.apps[1:len(xp.apps)]:\r
88                 if ec.state(app, hr=False) != ResourceState.STOPPED:\r
89                     raise Exception("Crashed at size %d" % xp.nb_nodes)\r
90     # et voila \r
91     ec.shutdown()\r
92 \r
93 main()\r