3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2015 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
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.
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/>.
18 # Author: Damien Saucez <damien.saucez@inria.fr>
19 # Alina Quereilhac <alina.quereilhac@inria.fr>
23 # Note that to run this experiment you need to have a PlanetLab account.
25 # This experiment consists of a simulated wireless sensor network (ns-3)
26 # with one fixed access point (AP), running an agent application, and several
27 # mobile stations that run a transmitter application to send messages to
30 # One of the transmitter applications runs outside the simulation, on
31 # the host, and sends messages to the AP through the FdNetDevice/TAP
38 # PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/hybrid.py
41 from __future__ import print_function
45 from nepi.execution.ec import ExperimentController
46 from nepi.execution.resource import ResourceState, ResourceManager
48 from topology import *
51 os.environ["NEPI_NTHREADS"] = "1"
52 ResourceManager._reschedule_delay = "0s"
54 # list of hosts for running the experiment on
55 hostname1 = "onelab4.warsaw.rd.tp.pl"
56 hostname2 = "planet2.servers.ua.pt"
58 (username, pl_user, pl_password, ssh_key, node_count) = get_options()
60 ec = ExperimentController(exp_id="hybrid")
62 host, simu = add_host_simu(ec, hostname1, username, pl_user, pl_password,
65 ap, agent = build_ns3_topology(ec, simu, node_count, network="192.168.3.0",
66 prefixlen="25", agent_ip="192.168.3.1")
68 fddev = add_fdnet_device(ec, ap, "192.168.3.129", "25")
70 tap = ec.register_resource("planetlab::Tap")
71 ec.set(tap, "ip", "192.168.3.130")
72 ec.set(tap, "prefix", "25")
73 ec.set(tap, "pointopoint", "192.168.3.129")
74 ec.register_connection(host, tap)
76 connect_with_virtual_link(ec, tap, fddev)
78 add_ns3_route(ec, ap, network="192.168.3.128", prefixlen="25", nexthop="192.168.3.1")
79 add_planetlab_route(ec, tap, network="192.168.3.0", prefixlen="25", nexthop="192.168.3.129")
81 transmitter = ec.register_resource("linux::Application")
82 ec.set(transmitter, "sources", "code/transmitter.c")
83 ec.set(transmitter, "build", "gcc ${SRC}/transmitter.c -o ${BIN}/transmitter")
84 ec.set(transmitter, "command", "${BIN}/transmitter 192.168.3.1")
85 ec.register_connection(transmitter, host)
89 ec.wait_finished([simu, transmitter])
91 stdout = ec.trace(agent, "stdout")
92 print(" Agent says: ")
95 stdout = ec.trace(transmitter, "stdout")
96 print(" Live transmitter output: ")