3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Julien Tribino <julien.tribino@inria.fr>
41 # - t2 (t1 + 10s) : Ping stop
42 # - t3 (t2 + 2s) : Kill the application
46 from nepi.execution.ec import ExperimentController
47 from nepi.execution.resource import ResourceAction, ResourceState
49 from optparse import OptionParser
52 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
54 parser = OptionParser(usage = usage)
55 parser.add_option("-x", "--nodex", dest="nodex",
56 help="Nitos first reserved node "
57 "(e.g. hostname must be of form: omf.nitos.node0XX)",
59 parser.add_option("-z", "--nodez", dest="nodez",
60 help="Nitos second reserved node "
61 "(e.g. hostname must be of form: omf.nitos.node0ZZ)",
63 parser.add_option("-c", "--channel", dest="channel",
64 help="Nitos reserved channel",
66 parser.add_option("-s", "--slice-name", dest="slicename",
67 help="Nitos slice name", type="str")
68 (options, args) = parser.parse_args()
72 slicename = options.slicename
73 chan = options.channel
76 ec = ExperimentController(exp_id="nitos_omf5_ping")
78 # Create and Configure the Nodes
79 node1 = ec.register_resource("OMFNode")
80 ec.set(node1, "hostname", nodex)
81 ec.set(node1, "xmppUser", slicename)
82 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
83 ec.set(node1, "xmppPort", "5222")
84 ec.set(node1, "xmppPassword", "1234")
85 ec.set(node1, "version", "5")
87 # Create and Configure the Interfaces
88 iface1 = ec.register_resource("OMFWifiInterface")
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.%s/24" % nodex[-2:])
94 ec.set(iface1, "version", "5")
95 ec.register_connection(node1, iface1)
97 # Create and Configure the Channel
98 channel = ec.register_resource("OMFChannel")
99 ec.set(channel, "channel", chan)
100 ec.set(channel, "xmppUser", slicename)
101 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
102 ec.set(channel, "xmppPort", "5222")
103 ec.set(channel, "xmppPassword", "1234")
104 ec.set(channel, "version", "5")
105 ec.register_connection(iface1, channel)
107 # Create and Configure the PING Application
108 app1 = ec.register_resource("OMFApplication")
109 ec.set(app1, "appid", "Ping#1")
110 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodex[-2:])
111 ec.set(app1, "version", "5")
112 ec.register_connection(app1, node1)
114 app2 = ec.register_resource("OMFApplication")
115 ec.set(app2, "appid", "Kill#1")
116 ec.set(app2, "command", "/usr/bin/killall ping")
117 ec.set(app2, "version", "5")
118 ec.register_connection(app2, node1)
121 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
122 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
123 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
128 ec.wait_finished([app1, app2])
130 print ec.trace(app1, "stdout")