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 __future__ import print_function
47 from nepi.execution.ec import ExperimentController
48 from nepi.execution.resource import ResourceAction, ResourceState
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="Nitos first reserved node "
58 "(e.g. hostname must be of form: omf.nitos.node0XX)",
60 parser.add_option("-z", "--nodez", dest="nodez",
61 help="Nitos second reserved node "
62 "(e.g. hostname must be of form: omf.nitos.node0ZZ)",
64 parser.add_option("-c", "--channel", dest="channel",
65 help="Nitos reserved channel",
67 parser.add_option("-s", "--slice-name", dest="slicename",
68 help="Nitos slice name", type="str")
69 (options, args) = parser.parse_args()
73 slicename = options.slicename
74 chan = options.channel
77 ec = ExperimentController(exp_id="nitos_omf5_ping")
79 # Create and Configure the Nodes
80 node1 = ec.register_resource("omf::Node")
81 ec.set(node1, "hostname", nodex)
82 ec.set(node1, "xmppUser", slicename)
83 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
84 ec.set(node1, "xmppPort", "5222")
85 ec.set(node1, "xmppPassword", "1234")
86 ec.set(node1, "version", "5")
88 # Create and Configure the Interfaces
89 iface1 = ec.register_resource("omf::WifiInterface")
90 ec.set(iface1, "name", "wlan0")
91 ec.set(iface1, "mode", "adhoc")
92 ec.set(iface1, "hw_mode", "g")
93 ec.set(iface1, "essid", "ping")
94 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
95 ec.set(iface1, "version", "5")
96 ec.register_connection(node1, iface1)
98 # Create and Configure the Channel
99 channel = ec.register_resource("omf::Channel")
100 ec.set(channel, "channel", chan)
101 ec.set(channel, "xmppUser", slicename)
102 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
103 ec.set(channel, "xmppPort", "5222")
104 ec.set(channel, "xmppPassword", "1234")
105 ec.set(channel, "version", "5")
106 ec.register_connection(iface1, channel)
108 # Create and Configure the PING Application
109 app1 = ec.register_resource("omf::Application")
110 ec.set(app1, "appid", "Ping#1")
111 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodex[-2:])
112 ec.set(app1, "version", "5")
113 ec.register_connection(app1, node1)
115 app2 = ec.register_resource("omf::Application")
116 ec.set(app2, "appid", "Kill#1")
117 ec.set(app2, "command", "/usr/bin/killall ping")
118 ec.set(app2, "version", "5")
119 ec.register_connection(app2, node1)
122 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
123 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
124 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
129 ec.wait_finished([app1, app2])
131 print(ec.trace(app1, "stdout"))