1 #!/usr/bin/env python
\r
3 # NEPI, a framework to manage network experiments
\r
4 # Copyright (C) 2015 INRIA
\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
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
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
18 # Author: Damien Saucez <damien.saucez@inria.fr>
\r
19 # Alina Quereilhac <alina.quereilhac@inria.fr>
\r
23 # Note that to run this experiment you need to have a PlanetLab account.
\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
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
38 # PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/hybrid.py
\r
43 from nepi.execution.ec import ExperimentController
\r
44 from nepi.execution.resource import ResourceState, ResourceManager
\r
46 from topology import *
\r
49 os.environ["NEPI_NTHREADS"] = "1"
\r
50 ResourceManager._reschedule_delay = "0s"
\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
56 (username, pl_user, pl_password, ssh_key, node_count) = get_options()
\r
58 ec = ExperimentController(exp_id="hybrid")
\r
60 host, simu = add_host_simu(ec, hostname1, username, pl_user, pl_password,
\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
66 fddev = add_fdnet_device(ec, ap, "192.168.3.129", "25")
\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
74 connect_with_virtual_link(ec, tap, fddev)
\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
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
87 ec.wait_finished([simu, transmitter])
\r
89 stdout = ec.trace(agent, "stdout")
\r
90 print " Agent says: "
\r
93 stdout = ec.trace(transmitter, "stdout")
\r
94 print " Live transmitter output: "
\r