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: node0XX)",
59 parser.add_option("-z", "--nodez", dest="nodez",
60 help="Nitos second reserved node "
61 "(e.g. hostname must be of form: 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_omf6_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")
86 # Create and Configure the Interfaces
87 iface1 = ec.register_resource("OMFWifiInterface")
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.register_connection(node1, iface1)
95 # Create and Configure the Nodes
96 node2 = ec.register_resource("OMFNode")
97 ec.set(node2, "hostname", nodez)
98 ec.set(node2, "xmppUser", slicename)
99 ec.set(node2, "xmppServer", "nitlab.inf.uth.gr")
100 ec.set(node2, "xmppPort", "5222")
101 ec.set(node2, "xmppPassword", "1234")
103 # Create and Configure the Interfaces
104 iface2 = ec.register_resource("OMFWifiInterface")
105 ec.set(iface2, "name", "wlan0")
106 ec.set(iface2, "mode", "adhoc")
107 ec.set(iface2, "hw_mode", "g")
108 ec.set(iface2, "essid", "ping")
109 ec.set(iface2, "ip", "192.168.0.%s/24" % nodez[-2:])
110 ec.register_connection(node2, iface2)
113 # Create and Configure the Channel
114 channel = ec.register_resource("OMFChannel")
115 ec.set(channel, "channel", chan)
116 ec.set(channel, "xmppUser", slicename)
117 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
118 ec.set(channel, "xmppPort", "5222")
119 ec.set(channel, "xmppPassword", "1234")
120 ec.register_connection(iface1, channel)
121 ec.register_connection(iface2, channel)
123 # Create and Configure the PING Application
124 app1 = ec.register_resource("OMFApplication")
125 ec.set(app1, "appid", "Ping#1")
126 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodez[-2:])
127 ec.register_connection(app1, node1)
129 app2 = ec.register_resource("OMFApplication")
130 ec.set(app2, "appid", "Kill#1")
131 ec.set(app2, "command", "/usr/bin/killall ping")
132 ec.register_connection(app2, node1)
135 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
136 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
137 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
142 ec.wait_finished([app1, app2])
144 print ec.trace(app1, "stdout")