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 version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
19 # Julien Tribino <julien.tribino@inria.fr>
40 # - t2 (t1 + 10s) : Ping stop
41 # - t3 (t2 + 2s) : Kill the application
45 from nepi.execution.ec import ExperimentController
46 from nepi.execution.resource import ResourceAction, ResourceState
48 from optparse import OptionParser
51 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
53 parser = OptionParser(usage = usage)
54 parser.add_option("-x", "--nodex", dest="nodex",
55 help="Nitos first reserved node "
56 "(e.g. hostname must be of form: omf.nitos.node0XX)",
58 parser.add_option("-z", "--nodez", dest="nodez",
59 help="Nitos second reserved node "
60 "(e.g. hostname must be of form: omf.nitos.node0ZZ)",
62 parser.add_option("-c", "--channel", dest="channel",
63 help="Nitos reserved channel",
65 parser.add_option("-s", "--slice-name", dest="slicename",
66 help="Nitos slice name", type="str")
67 (options, args) = parser.parse_args()
71 slicename = options.slicename
72 chan = options.channel
75 ec = ExperimentController(exp_id="nitos_omf5_ping")
77 # Create and Configure the Nodes
78 node1 = ec.register_resource("omf::Node")
79 ec.set(node1, "hostname", nodex)
80 ec.set(node1, "xmppUser", slicename)
81 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
82 ec.set(node1, "xmppPort", "5222")
83 ec.set(node1, "xmppPassword", "1234")
84 ec.set(node1, "version", "5")
86 # Create and Configure the Interfaces
87 iface1 = ec.register_resource("omf::WifiInterface")
88 ec.set(iface1, "name", "wlan0")
89 ec.set(iface1, "mode", "adhoc")
90 ec.set(iface1, "hw_mode", "g")
91 ec.set(iface1, "essid", "ping")
92 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
93 ec.set(iface1, "version", "5")
94 ec.register_connection(node1, iface1)
96 # Create and Configure the Channel
97 channel = ec.register_resource("omf::Channel")
98 ec.set(channel, "channel", chan)
99 ec.set(channel, "xmppUser", slicename)
100 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
101 ec.set(channel, "xmppPort", "5222")
102 ec.set(channel, "xmppPassword", "1234")
103 ec.set(channel, "version", "5")
104 ec.register_connection(iface1, channel)
106 # Create and Configure the PING Application
107 app1 = ec.register_resource("omf::Application")
108 ec.set(app1, "appid", "Ping#1")
109 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodex[-2:])
110 ec.set(app1, "version", "5")
111 ec.register_connection(app1, node1)
113 app2 = ec.register_resource("omf::Application")
114 ec.set(app2, "appid", "Kill#1")
115 ec.set(app2, "command", "/usr/bin/killall ping")
116 ec.set(app2, "version", "5")
117 ec.register_connection(app2, node1)
120 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
121 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
122 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
127 ec.wait_finished([app1, app2])
129 print ec.trace(app1, "stdout")