a0be0a9a4fa14606d20cdc0451aae2469d18a539
[nepi.git] / examples / ns3 / multi_host / parallel.py
1 #!/usr/bin/env python\r
2 #\r
3 #    NEPI, a framework to manage network experiments\r
4 #    Copyright (C) 2015 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 \r
22 #\r
23 # Note: To run this experiment you need to have a PlanetLab account.\r
24 #\r
25 # This experiment consists of a simulated wireless sensor network (ns-3)\r
26 # with one fixed access point (AP), running an agent application, and several\r
27 # mobile stations that run a transmitter application to send messages to\r
28 # the AP.\r
29 #\r
30 # The same experiment described above is run in parallel with different\r
31 # number of mobile stations in 2 PlanetLab hosts.\r
32 #\r
33 \r
34 #\r
35 # command line:\r
36 #\r
37 # PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/parallel.py\r
38 #\r
39 \r
40 import os\r
41 \r
42 from topology import *\r
43 \r
44 from nepi.execution.ec import ExperimentController\r
45 from nepi.execution.resource import ResourceState, ResourceManager\r
46 \r
47 # tunning\r
48 os.environ["NEPI_NTHREADS"] = "1"\r
49 ResourceManager._reschedule_delay = "0s"\r
50 \r
51 # list of hosts for running the experiment on\r
52 hostname1 = "onelab4.warsaw.rd.tp.pl"\r
53 hostname2 = "planet2.servers.ua.pt"\r
54 \r
55 (username, pl_user, pl_password, ssh_key, node_count) = get_options()\r
56 \r
57 ec = ExperimentController(exp_id="parallel")\r
58 counts = [node_count, 10]\r
59 hosts = [hostname1, hostname2]\r
60 \r
61 simulations = []\r
62 agents = []\r
63 \r
64 for hostname in hosts:\r
65     host, simu = add_host_simu(ec, hostname, username, pl_user, pl_password, \r
66             ssh_key)\r
67     simulations.append(simu)\r
68 \r
69     node_count = counts.pop()\r
70     ap, agent = build_ns3_topology(ec, simu, node_count, network="10.1.0.0", \r
71             prefixlen="24", agent_ip="10.1.0.1")\r
72     agents.append(agent)\r
73 \r
74 ec.deploy()\r
75 \r
76 ec.wait_finished(simulations)\r
77 \r
78 for agent in agents:\r
79     stdout = ec.trace(agent, "stdout")\r
80     print " Agent says:"\r
81     print stdout\r
82 \r
83 ec.shutdown()\r
84 \r
85 \r