use print() - import print_function - should be fine for both py2 and py3
[nepi.git] / examples / ns3 / multi_host / hybrid.py
index 0b36478..630fec2 100644 (file)
-#!/usr/bin/env python\r
-#\r
-#    NEPI, a framework to manage network experiments\r
-#    Copyright (C) 2015 INRIA\r
-#\r
-#    This program is free software: you can redistribute it and/or modify\r
-#    it under the terms of the GNU General Public License version 2 as\r
-#    published by the Free Software Foundation;\r
-#\r
-#    This program is distributed in the hope that it will be useful,\r
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-#    GNU General Public License for more details.\r
-#\r
-#    You should have received a copy of the GNU General Public License\r
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
-#\r
-# Author: Damien Saucez <damien.saucez@inria.fr>\r
-#         Alina Quereilhac <alina.quereilhac@inria.fr>\r
-#\r
-\r
-#\r
-# Note that to run this experiment you need to have a PlanetLab account.\r
-#\r
-# This experiment consists of a simulated wireless sensor network (ns-3)\r
-# with one fixed access point (AP), running an agent application, and several\r
-# mobile stations that run a transmitter application to send messages to\r
-# the AP.\r
-#\r
-# One of the transmitter applications runs outside the simulation, on\r
-# the host, and sends messages to the AP through the FdNetDevice/TAP\r
-# link.\r
-#\r
-\r
-#\r
-# command line:\r
-#\r
-# PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/hybrid.py\r
-#\r
-\r
-import os\r
-\r
-from nepi.execution.ec import ExperimentController\r
-from nepi.execution.resource import ResourceState, ResourceManager\r
-\r
-from topology import *\r
-\r
-# tunning\r
-os.environ["NEPI_NTHREADS"] = "1"\r
-ResourceManager._reschedule_delay = "0s"\r
-\r
-# list of hosts for running the experiment on\r
-hostname1 = "onelab4.warsaw.rd.tp.pl"\r
-hostname2 = "planet2.servers.ua.pt"\r
-\r
-(username, pl_user, pl_password, ssh_key, node_count) = get_options()\r
-\r
-ec = ExperimentController(exp_id="hybrid")\r
-\r
-host, simu = add_host_simu(ec, hostname1, username, pl_user, pl_password, \r
-        ssh_key)\r
-\r
-ap, agent = build_ns3_topology(ec, simu, node_count, network="192.168.3.0", \r
-        prefixlen="25", agent_ip="192.168.3.1")\r
-\r
-fddev = add_fdnet_device(ec, ap, "192.168.3.129", "25")\r
-\r
-tap = ec.register_resource("planetlab::Tap")\r
-ec.set(tap, "ip", "192.168.3.130")\r
-ec.set(tap, "prefix", "25")\r
-ec.set(tap, "pointopoint", "192.168.3.129")\r
-ec.register_connection(host, tap)  \r
-\r
-connect_with_virtual_link(ec, tap, fddev)\r
-\r
-add_ns3_route(ec, ap, network="192.168.3.128", prefixlen="25", nexthop="192.168.3.1")\r
-add_planetlab_route(ec, tap, network="192.168.3.0", prefixlen="25", nexthop="192.168.3.129")\r
-\r
-transmitter = ec.register_resource("linux::Application")\r
-ec.set(transmitter, "sources", "code/transmitter.c")\r
-ec.set(transmitter, "build", "gcc ${SRC}/transmitter.c -o ${BIN}/transmitter")\r
-ec.set(transmitter, "command", "${BIN}/transmitter 192.168.3.1")\r
-ec.register_connection(transmitter, host)\r
-\r
-ec.deploy()\r
-\r
-ec.wait_finished([simu, transmitter])\r
-\r
-stdout = ec.trace(agent, "stdout")\r
-print " Agent says: "\r
-print stdout\r
-\r
-stdout = ec.trace(transmitter, "stdout")\r
-print " Live transmitter output: "\r
-print stdout\r
-\r
-ec.shutdown()\r
-\r
-\r
+#!/usr/bin/env python
+#
+#    NEPI, a framework to manage network experiments
+#    Copyright (C) 2015 INRIA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Damien Saucez <damien.saucez@inria.fr>
+#         Alina Quereilhac <alina.quereilhac@inria.fr>
+#
+
+#
+# Note that to run this experiment you need to have a PlanetLab account.
+#
+# This experiment consists of a simulated wireless sensor network (ns-3)
+# with one fixed access point (AP), running an agent application, and several
+# mobile stations that run a transmitter application to send messages to
+# the AP.
+#
+# One of the transmitter applications runs outside the simulation, on
+# the host, and sends messages to the AP through the FdNetDevice/TAP
+# link.
+#
+
+#
+# command line:
+#
+# PYTHONPATH=$PYTHONPATH:src python examples/ns3/multi_host/hybrid.py
+#
+
+from __future__ import print_function
+
+import os
+
+from nepi.execution.ec import ExperimentController
+from nepi.execution.resource import ResourceState, ResourceManager
+
+from topology import *
+
+# tunning
+os.environ["NEPI_NTHREADS"] = "1"
+ResourceManager._reschedule_delay = "0s"
+
+# list of hosts for running the experiment on
+hostname1 = "onelab4.warsaw.rd.tp.pl"
+hostname2 = "planet2.servers.ua.pt"
+
+(username, pl_user, pl_password, ssh_key, node_count) = get_options()
+
+ec = ExperimentController(exp_id="hybrid")
+
+host, simu = add_host_simu(ec, hostname1, username, pl_user, pl_password, 
+        ssh_key)
+
+ap, agent = build_ns3_topology(ec, simu, node_count, network="192.168.3.0", 
+        prefixlen="25", agent_ip="192.168.3.1")
+
+fddev = add_fdnet_device(ec, ap, "192.168.3.129", "25")
+
+tap = ec.register_resource("planetlab::Tap")
+ec.set(tap, "ip", "192.168.3.130")
+ec.set(tap, "prefix", "25")
+ec.set(tap, "pointopoint", "192.168.3.129")
+ec.register_connection(host, tap)  
+
+connect_with_virtual_link(ec, tap, fddev)
+
+add_ns3_route(ec, ap, network="192.168.3.128", prefixlen="25", nexthop="192.168.3.1")
+add_planetlab_route(ec, tap, network="192.168.3.0", prefixlen="25", nexthop="192.168.3.129")
+
+transmitter = ec.register_resource("linux::Application")
+ec.set(transmitter, "sources", "code/transmitter.c")
+ec.set(transmitter, "build", "gcc ${SRC}/transmitter.c -o ${BIN}/transmitter")
+ec.set(transmitter, "command", "${BIN}/transmitter 192.168.3.1")
+ec.register_connection(transmitter, host)
+
+ec.deploy()
+
+ec.wait_finished([simu, transmitter])
+
+stdout = ec.trace(agent, "stdout")
+print(" Agent says: ")
+print(stdout)
+
+stdout = ec.trace(transmitter, "stdout")
+print(" Live transmitter output: ")
+print(stdout)
+
+ec.shutdown()
+
+