use print() - import print_function - should be fine for both py2 and py3
[nepi.git] / examples / ns3 / multi_host / distributed.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2015 INRIA
5 #
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;
9 #
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.
14 #
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/>.
17 #
18 # Author: Damien Saucez <damien.saucez@inria.fr>
19 #         Alina Quereilhac <alina.quereilhac@inria.fr>
20 #
21
22 #
23 # Note: To run this experiment you need to have a PlanetLab account.
24 #
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
28 # the AP.
29 #
30 # The experiment uses 2 networks like the one described above, running in 2
31 # independent ns-3 instances in remote hosts, and transparently connected
32 # through a UDP tunnel.
33
34 #
35 # command line:
36 #
37 # PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/ditributed.py
38 #
39
40 from __future__ import print_function
41
42 import os
43
44 from nepi.execution.ec import ExperimentController
45 from nepi.execution.resource import ResourceState, ResourceManager
46
47 from topology import *
48
49 # tunning
50 os.environ["NEPI_NTHREADS"] = "1"
51 ResourceManager._reschedule_delay = "0s"
52
53 # list of hosts for running the experiment on
54 hostname1 = "onelab4.warsaw.rd.tp.pl"
55 hostname2 = "planet2.servers.ua.pt"
56
57 (username, pl_user, pl_password, ssh_key, node_count) = get_options()
58
59 ec = ExperimentController(exp_id="distributed")
60
61 host1, simu1 = add_host_simu(ec, hostname1, username, pl_user, pl_password, 
62         ssh_key)
63
64 ap1, agent1 = build_ns3_topology(ec, simu1, node_count, network="10.1.0.0", 
65         prefixlen="24", agent_ip="10.1.0.1")
66
67 host2, simu2 = add_host_simu(ec, hostname2, username, pl_user, pl_password, ssh_key)
68 ap2, agent2 = build_ns3_topology(ec, simu2, node_count, network="10.2.0.0", prefixlen="24", agent_ip="10.1.0.1")
69
70 fddev1 = add_fdnet_device(ec, ap1, "10.0.0.1", "30")
71 fddev2 = add_fdnet_device(ec, ap2, "10.0.0.2", "30")
72
73 connect_with_udp_tunnel(ec, fddev1, fddev2)
74
75 ec.deploy()
76
77 ec.wait_finished([simu1, simu2])
78
79 stdout = ec.trace(agent1, "stdout")
80 print(" Agent says:")
81 print(stdout)
82
83 ec.shutdown()
84