3 ###############################################################################
5 # NEPI, a framework to manage network experiments
6 # Copyright (C) 2013 INRIA
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 as
10 # published by the Free Software Foundation;
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # Julien Tribino <julien.tribino@inria.fr>
23 ###############################################################################
43 # - t2 (t1 + 10s) : Ping stop
44 # - t3 (t2 + 2s) : Kill the application
47 from __future__ import print_function
49 from nepi.execution.resource import ResourceAction, ResourceState
50 from nepi.execution.ec import ExperimentController
52 from optparse import OptionParser
55 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
57 parser = OptionParser(usage = usage)
58 parser.add_option("-x", "--nodex", dest="nodex",
59 help="w-iLab.t first reserved node "
61 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
62 " all letters in lowercase )",
64 parser.add_option("-z", "--nodez", dest="nodez",
65 help="w-iLab.t first reserved node "
67 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
68 " all letters in lowercase )",
70 parser.add_option("-s", "--slice-name", dest="slicename",
71 help="Nitos slice name", type="str")
72 (options, args) = parser.parse_args()
76 slicename = options.slicename
79 ec = ExperimentController(exp_id="iminds_omf6_ping")
81 # Create and Configure the Nodes
83 node1 = ec.register_resource("omf::Node")
84 ec.set(node1, "hostname", nodex)
85 ec.set(node1, "xmppUser", slicename)
86 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
87 ec.set(node1, "xmppPort", "5222")
88 ec.set(node1, "xmppPassword", "1234")
90 iface1 = ec.register_resource("omf::WifiInterface")
91 ec.set(iface1, "name", "wlan0")
92 ec.set(iface1, "mode", "adhoc")
93 ec.set(iface1, "hw_mode", "g")
94 ec.set(iface1, "essid", "ping")
95 ec.set(iface1, "ip", "192.168.0.1/24")
96 ec.register_connection(iface1, node1)
98 node2 = ec.register_resource("omf::Node")
99 ec.set(node2, "hostname", nodez)
100 ec.set(node2, "xmppUser", slicename)
101 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
102 ec.set(node2, "xmppPort", "5222")
103 ec.set(node2, "xmppPassword", "1234")
105 iface2 = ec.register_resource("omf::WifiInterface")
106 ec.set(iface2, "name", "wlan0")
107 ec.set(iface2, "mode", "adhoc")
108 ec.set(iface2, "hw_mode", "g")
109 ec.set(iface2, "essid", "ping")
110 ec.set(iface2, "ip", "192.168.0.2/24")
111 ec.register_connection(iface2, node2)
113 channel = ec.register_resource("omf::Channel")
114 ec.set(channel, "channel", "6")
115 ec.register_connection(iface1, channel)
116 ec.register_connection(iface2, channel)
118 # Create and Configure the Application
119 app1 = ec.register_resource("omf::Application")
120 ec.set(app1, "command", "ping -c3 192.168.0.2")
121 ec.register_connection(app1, node1)
123 ## Make sure the ping stops after 30 seconds
124 ec.register_condition(app1, ResourceAction.STOP, app1,
125 ResourceState.STARTED , "30s")
130 # Wait until the VLC client is finished
131 ec.wait_finished([app1])
133 # Retrieve the output of the ping command
134 ping_output = ec.trace(app1, "stdout")
135 print("\n PING OUTPUT\n", ping_output, "\n")