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 nepi.execution.resource import ResourceAction, ResourceState
48 from nepi.execution.ec import ExperimentController
50 from optparse import OptionParser
53 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
55 parser = OptionParser(usage = usage)
56 parser.add_option("-x", "--nodex", dest="nodex",
57 help="w-iLab.t first reserved node "
59 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
60 " all letters in lowercase )",
62 parser.add_option("-z", "--nodez", dest="nodez",
63 help="w-iLab.t first reserved node "
65 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
66 " all letters in lowercase )",
68 parser.add_option("-s", "--slice-name", dest="slicename",
69 help="Nitos slice name", type="str")
70 (options, args) = parser.parse_args()
74 slicename = options.slicename
77 ec = ExperimentController(exp_id="iminds_omf6_ping")
79 # Create and Configure the Nodes
81 node1 = ec.register_resource("omf::Node")
82 ec.set(node1, "hostname", nodex)
83 ec.set(node1, "xmppUser", slicename)
84 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
85 ec.set(node1, "xmppPort", "5222")
86 ec.set(node1, "xmppPassword", "1234")
88 iface1 = ec.register_resource("omf::WifiInterface")
89 ec.set(iface1, "name", "wlan0")
90 ec.set(iface1, "mode", "adhoc")
91 ec.set(iface1, "hw_mode", "g")
92 ec.set(iface1, "essid", "ping")
93 ec.set(iface1, "ip", "192.168.0.1/24")
94 ec.register_connection(iface1, node1)
96 node2 = ec.register_resource("omf::Node")
97 ec.set(node2, "hostname", nodez)
98 ec.set(node2, "xmppUser", slicename)
99 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
100 ec.set(node2, "xmppPort", "5222")
101 ec.set(node2, "xmppPassword", "1234")
103 iface2 = ec.register_resource("omf::WifiInterface")
104 ec.set(iface2, "name", "wlan0")
105 ec.set(iface2, "mode", "adhoc")
106 ec.set(iface2, "hw_mode", "g")
107 ec.set(iface2, "essid", "ping")
108 ec.set(iface2, "ip", "192.168.0.2/24")
109 ec.register_connection(iface2, node2)
111 channel = ec.register_resource("omf::Channel")
112 ec.set(channel, "channel", "6")
113 ec.register_connection(iface1, channel)
114 ec.register_connection(iface2, channel)
116 # Create and Configure the Application
117 app1 = ec.register_resource("omf::Application")
118 ec.set(app1, "command", "ping -c3 192.168.0.2")
119 ec.register_connection(app1, node1)
121 ## Make sure the ping stops after 30 seconds
122 ec.register_condition(app1, ResourceAction.STOP, app1,
123 ResourceState.STARTED , "30s")
128 # Wait until the VLC client is finished
129 ec.wait_finished([app1])
131 # Retrieve the output of the ping command
132 ping_output = ec.trace(app1, "stdout")
133 print "\n PING OUTPUT\n", ping_output, "\n"