use print() - import print_function - should be fine for both py2 and py3
[nepi.git] / examples / omf / iminds_omf6_ping.py
index 08c3efe..d5e02c7 100644 (file)
@@ -6,9 +6,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    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
@@ -26,7 +25,7 @@
 # Topology
 #
 #
-#  Testbed : IMinds
+#  Testbed : iMinds
 #
 #     Node
 #     node0ZZ 
@@ -37,7 +36,6 @@
 #     Node
 #     node0ZZ 
 #     PING
-#     
 #   
 #      - Experiment:
 #        - t0 : Deployment
@@ -46,6 +44,8 @@
 #        - t3 (t2 + 2s) : Kill the application
 #
 
+from __future__ import print_function
+
 from nepi.execution.resource import ResourceAction, ResourceState
 from nepi.execution.ec import ExperimentController
 
@@ -67,9 +67,6 @@ parser.add_option("-z", "--nodez", dest="nodez",
             " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
             " all letters in lowercase )", 
         type="str")
-parser.add_option("-c", "--channel", dest="channel", 
-        help="Nitos reserved channel",
-        type="str")
 parser.add_option("-s", "--slice-name", dest="slicename", 
         help="Nitos slice name", type="str")
 (options, args) = parser.parse_args()
@@ -77,21 +74,20 @@ parser.add_option("-s", "--slice-name", dest="slicename",
 nodex = options.nodex
 nodez = options.nodez
 slicename = options.slicename
-chan = options.channel
 
 # Create the EC
 ec = ExperimentController(exp_id="iminds_omf6_ping")
 
 # Create and Configure the Nodes
 
-node1 = ec.register_resource("OMFNode")
+node1 = ec.register_resource("omf::Node")
 ec.set(node1, "hostname", nodex)
 ec.set(node1, "xmppUser", slicename)
 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
 ec.set(node1, "xmppPort", "5222")
 ec.set(node1, "xmppPassword", "1234")
 
-iface1 = ec.register_resource("OMFWifiInterface")
+iface1 = ec.register_resource("omf::WifiInterface")
 ec.set(iface1, "name", "wlan0")
 ec.set(iface1, "mode", "adhoc")
 ec.set(iface1, "hw_mode", "g")
@@ -99,14 +95,14 @@ ec.set(iface1, "essid", "ping")
 ec.set(iface1, "ip", "192.168.0.1/24")
 ec.register_connection(iface1, node1)
 
-node2 = ec.register_resource("OMFNode")
+node2 = ec.register_resource("omf::Node")
 ec.set(node2, "hostname", nodez)
 ec.set(node2, "xmppUser", slicename)
 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
 ec.set(node2, "xmppPort", "5222")
 ec.set(node2, "xmppPassword", "1234")
 
-iface2 = ec.register_resource("OMFWifiInterface")
+iface2 = ec.register_resource("omf::WifiInterface")
 ec.set(iface2, "name", "wlan0")
 ec.set(iface2, "mode", "adhoc")
 ec.set(iface2, "hw_mode", "g")
@@ -114,26 +110,29 @@ ec.set(iface2, "essid", "ping")
 ec.set(iface2, "ip", "192.168.0.2/24")
 ec.register_connection(iface2, node2)
 
-channel = ec.register_resource("OMFChannel")
+channel = ec.register_resource("omf::Channel")
 ec.set(channel, "channel", "6")
 ec.register_connection(iface1, channel)
 ec.register_connection(iface2, channel)
 
 # Create and Configure the Application
-app1 = ec.register_resource("OMFApplication")
+app1 = ec.register_resource("omf::Application")
 ec.set(app1, "command", "ping -c3 192.168.0.2") 
 ec.register_connection(app1, node1)
 
-ec.register_condition([app1], ResourceAction.STOP, [app1], 
+## Make sure the ping stops after 30 seconds
+ec.register_condition(app1, ResourceAction.STOP, app1, 
         ResourceState.STARTED , "30s")
 
 # Deploy
 ec.deploy()
 
+# Wait until the VLC client is finished
 ec.wait_finished([app1])
 
-# RESULT
-print ec.trace(app1, "stdout")
+# Retrieve the output of the ping command
+ping_output = ec.trace(app1, "stdout")
+print("\n PING OUTPUT\n", ping_output, "\n")
 
 # Stop Experiment
 ec.shutdown()