0b36478955e245b345be466e46d75c2ec916c110
[nepi.git] / examples / ns3 / multi_host / hybrid.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 that 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 # One of the transmitter applications runs outside the simulation, on\r
31 # the host, and sends messages to the AP through the FdNetDevice/TAP\r
32 # link.\r
33 #\r
34 \r
35 #\r
36 # command line:\r
37 #\r
38 # PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/hybrid.py\r
39 #\r
40 \r
41 import os\r
42 \r
43 from nepi.execution.ec import ExperimentController\r
44 from nepi.execution.resource import ResourceState, ResourceManager\r
45 \r
46 from topology import *\r
47 \r
48 # tunning\r
49 os.environ["NEPI_NTHREADS"] = "1"\r
50 ResourceManager._reschedule_delay = "0s"\r
51 \r
52 # list of hosts for running the experiment on\r
53 hostname1 = "onelab4.warsaw.rd.tp.pl"\r
54 hostname2 = "planet2.servers.ua.pt"\r
55 \r
56 (username, pl_user, pl_password, ssh_key, node_count) = get_options()\r
57 \r
58 ec = ExperimentController(exp_id="hybrid")\r
59 \r
60 host, simu = add_host_simu(ec, hostname1, username, pl_user, pl_password, \r
61         ssh_key)\r
62 \r
63 ap, agent = build_ns3_topology(ec, simu, node_count, network="192.168.3.0", \r
64         prefixlen="25", agent_ip="192.168.3.1")\r
65 \r
66 fddev = add_fdnet_device(ec, ap, "192.168.3.129", "25")\r
67 \r
68 tap = ec.register_resource("planetlab::Tap")\r
69 ec.set(tap, "ip", "192.168.3.130")\r
70 ec.set(tap, "prefix", "25")\r
71 ec.set(tap, "pointopoint", "192.168.3.129")\r
72 ec.register_connection(host, tap)  \r
73 \r
74 connect_with_virtual_link(ec, tap, fddev)\r
75 \r
76 add_ns3_route(ec, ap, network="192.168.3.128", prefixlen="25", nexthop="192.168.3.1")\r
77 add_planetlab_route(ec, tap, network="192.168.3.0", prefixlen="25", nexthop="192.168.3.129")\r
78 \r
79 transmitter = ec.register_resource("linux::Application")\r
80 ec.set(transmitter, "sources", "code/transmitter.c")\r
81 ec.set(transmitter, "build", "gcc ${SRC}/transmitter.c -o ${BIN}/transmitter")\r
82 ec.set(transmitter, "command", "${BIN}/transmitter 192.168.3.1")\r
83 ec.register_connection(transmitter, host)\r
84 \r
85 ec.deploy()\r
86 \r
87 ec.wait_finished([simu, transmitter])\r
88 \r
89 stdout = ec.trace(agent, "stdout")\r
90 print " Agent says: "\r
91 print stdout\r
92 \r
93 stdout = ec.trace(transmitter, "stdout")\r
94 print " Live transmitter output: "\r
95 print stdout\r
96 \r
97 ec.shutdown()\r
98 \r
99 \r