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 # Author: Julien Tribino <julien.tribino@inria.fr>
22 from nepi.execution.resource import ResourceFactory, ResourceManager, ResourceAction, ResourceState
23 from nepi.execution.ec import ExperimentController
25 from nepi.resources.omf.node import OMFNode
26 from nepi.resources.omf.application import OMFApplication
27 from nepi.resources.omf.interface import OMFWifiInterface
28 from nepi.resources.omf.channel import OMFChannel
29 from nepi.resources.omf.omf_api_factory import OMFAPIFactory
31 from nepi.util.timefuncs import *
36 class OMFVLCWrongCaseAllCritical(unittest.TestCase):
41 self.ec = ExperimentController(exp_id = str(OMFVLCWrongCaseAllCritical.id))
42 OMFVLCWrongCaseAllCritical.id += 1
44 self.node1 = self.ec.register_resource("OMFNode")
45 self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
46 self.ec.set(self.node1, 'xmppUser', "nepi")
47 self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
48 self.ec.set(self.node1, 'xmppPort', "5222")
49 self.ec.set(self.node1, 'xmppPassword', "1234")
50 self.ec.set(self.node1, 'version', "5")
52 self.iface1 = self.ec.register_resource("OMFWifiInterface")
53 self.ec.set(self.iface1, 'name', "wlan0")
54 self.ec.set(self.iface1, 'mode', "adhoc")
55 self.ec.set(self.iface1, 'hw_mode', "g")
56 self.ec.set(self.iface1, 'essid', "vlcexp")
57 self.ec.set(self.iface1, 'ip', "10.0.0.17/24")
58 self.ec.set(self.iface1, 'version', "5")
60 self.app1 = self.ec.register_resource("OMFApplication")
61 self.ec.set(self.app1, 'appid', 'Vlc#1')
62 self.ec.set(self.app1, 'command', "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
63 self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
64 self.ec.set(self.app1, 'version', "5")
66 self.ec.register_connection(self.app1, self.node1)
67 self.ec.register_connection(self.node1, self.iface1)
69 def test_deploy_wo_node(self):
70 self.node2 = self.ec.register_resource("OMFNode")
71 self.ec.set(self.node2, 'version', "5")
73 self.iface2 = self.ec.register_resource("OMFWifiInterface")
74 self.ec.set(self.iface2, 'name', "wlan0")
75 self.ec.set(self.iface2, 'mode', "adhoc")
76 self.ec.set(self.iface2, 'hw_mode', "g")
77 self.ec.set(self.iface2, 'essid', "vlcexp")
78 self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
79 self.ec.set(self.iface2, 'version', "5")
81 self.channel = self.ec.register_resource("OMFChannel")
82 self.ec.set(self.channel, 'channel', "6")
83 self.ec.set(self.channel, 'xmppUser', "nepi")
84 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
85 self.ec.set(self.channel, 'xmppPort', "5222")
86 self.ec.set(self.channel, 'xmppPassword', "1234")
87 self.ec.set(self.channel, 'version', "5")
89 self.ec.register_connection(self.iface1, self.channel)
90 self.ec.register_connection(self.node2, self.iface2)
91 self.ec.register_connection(self.iface2, self.channel)
93 self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
97 self.ec.wait_finished([self.app1])
99 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
103 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
104 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
105 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
106 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
107 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
108 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
110 def test_deploy_wo_hostname(self):
112 self.node2 = self.ec.register_resource("OMFNode")
113 self.ec.set(self.node2, 'xmppUser', "nepi")
114 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
115 self.ec.set(self.node2, 'xmppPort', "5222")
116 self.ec.set(self.node2, 'xmppPassword', "1234")
117 self.ec.set(self.node2, 'version', "5")
119 self.iface2 = self.ec.register_resource("OMFWifiInterface")
120 self.ec.set(self.iface2, 'name', "wlan0")
121 self.ec.set(self.iface2, 'mode', "adhoc")
122 self.ec.set(self.iface2, 'hw_mode', "g")
123 self.ec.set(self.iface2, 'essid', "vlcexp")
124 self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
125 self.ec.set(self.iface2, 'version', "5")
127 self.channel = self.ec.register_resource("OMFChannel")
128 self.ec.set(self.channel, 'channel', "6")
129 self.ec.set(self.channel, 'xmppUser', "nepi")
130 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
131 self.ec.set(self.channel, 'xmppPort', "5222")
132 self.ec.set(self.channel, 'xmppPassword', "1234")
133 self.ec.set(self.channel, 'version', "5")
135 self.ec.register_connection(self.iface1, self.channel)
136 self.ec.register_connection(self.node2, self.iface2)
137 self.ec.register_connection(self.iface2, self.channel)
139 self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
143 self.ec.wait_finished([self.app1])
145 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
149 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
150 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
151 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
152 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
153 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
154 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
156 def test_deploy_wo_iface(self):
157 self.node2 = self.ec.register_resource("OMFNode")
158 self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
159 self.ec.set(self.node2, 'xmppUser', "nepi")
160 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
161 self.ec.set(self.node2, 'xmppPort', "5222")
162 self.ec.set(self.node2, 'xmppPassword', "1234")
163 self.ec.set(self.node2, 'version', "5")
165 self.iface2 = self.ec.register_resource("OMFWifiInterface")
166 self.ec.set(self.iface2, 'version', "5")
168 self.channel = self.ec.register_resource("OMFChannel")
169 self.ec.set(self.channel, 'channel', "6")
170 self.ec.set(self.channel, 'xmppUser', "nepi")
171 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
172 self.ec.set(self.channel, 'xmppPort', "5222")
173 self.ec.set(self.channel, 'xmppPassword', "1234")
174 self.ec.set(self.channel, 'version', "5")
176 self.ec.register_connection(self.iface1, self.channel)
177 self.ec.register_connection(self.node2, self.iface2)
178 self.ec.register_connection(self.iface2, self.channel)
180 self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
184 self.ec.wait_finished([self.app1])
186 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.FAILED)
190 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
191 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
192 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
193 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
194 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
195 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
197 def test_deploy_wo_ip(self):
198 self.node2 = self.ec.register_resource("OMFNode")
199 self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
200 self.ec.set(self.node2, 'xmppUser', "nepi")
201 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
202 self.ec.set(self.node2, 'xmppPort', "5222")
203 self.ec.set(self.node2, 'xmppPassword', "1234")
204 self.ec.set(self.node2, 'version', "5")
206 self.iface2 = self.ec.register_resource("OMFWifiInterface")
207 self.ec.set(self.iface2, 'name', "wlan0")
208 self.ec.set(self.iface2, 'mode', "adhoc")
209 self.ec.set(self.iface2, 'hw_mode', "g")
210 self.ec.set(self.iface2, 'essid', "vlcexp")
211 self.ec.set(self.iface2, 'version', "5")
213 self.channel = self.ec.register_resource("OMFChannel")
214 self.ec.set(self.channel, 'channel', "6")
215 self.ec.set(self.channel, 'xmppUser', "nepi")
216 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
217 self.ec.set(self.channel, 'xmppPort', "5222")
218 self.ec.set(self.channel, 'xmppPassword', "1234")
219 self.ec.set(self.channel, 'version', "5")
221 self.ec.register_connection(self.iface1, self.channel)
222 self.ec.register_connection(self.node2, self.iface2)
223 self.ec.register_connection(self.iface2, self.channel)
225 self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
229 self.ec.wait_finished([self.app1])
231 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.FAILED)
235 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
236 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
237 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
238 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
239 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
240 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
242 def test_deploy_wo_channel(self):
243 self.node2 = self.ec.register_resource("OMFNode")
244 self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
245 self.ec.set(self.node2, 'xmppUser', "nepi")
246 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
247 self.ec.set(self.node2, 'xmppPort', "5222")
248 self.ec.set(self.node2, 'xmppPassword', "1234")
249 self.ec.set(self.node2, 'version', "5")
251 self.iface2 = self.ec.register_resource("OMFWifiInterface")
252 self.ec.set(self.iface2, 'name', "wlan0")
253 self.ec.set(self.iface2, 'mode', "adhoc")
254 self.ec.set(self.iface2, 'hw_mode', "g")
255 self.ec.set(self.iface2, 'essid', "vlcexp")
256 self.ec.set(self.iface2, 'version', "5")
258 self.channel = self.ec.register_resource("OMFChannel")
259 self.ec.set(self.channel, 'version', "5")
261 self.ec.register_connection(self.iface1, self.channel)
262 self.ec.register_connection(self.node2, self.iface2)
263 self.ec.register_connection(self.iface2, self.channel)
265 self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
269 self.ec.wait_finished([self.app1])
271 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.FAILED)
275 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
276 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
277 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
278 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
279 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
280 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
282 def test_deploy_wo_app(self):
283 self.node2 = self.ec.register_resource("OMFNode")
284 self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
285 self.ec.set(self.node2, 'xmppUser', "nepi")
286 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
287 self.ec.set(self.node2, 'xmppPort', "5222")
288 self.ec.set(self.node2, 'xmppPassword', "1234")
289 self.ec.set(self.node2, 'version', "5")
291 self.iface2 = self.ec.register_resource("OMFWifiInterface")
292 self.ec.set(self.iface2, 'name', "wlan0")
293 self.ec.set(self.iface2, 'mode', "adhoc")
294 self.ec.set(self.iface2, 'hw_mode', "g")
295 self.ec.set(self.iface2, 'essid', "vlcexp")
296 self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
297 self.ec.set(self.iface2, 'version', "5")
299 self.channel = self.ec.register_resource("OMFChannel")
300 self.ec.set(self.channel, 'channel', "6")
301 self.ec.set(self.channel, 'xmppUser', "nepi")
302 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
303 self.ec.set(self.channel, 'xmppPort', "5222")
304 self.ec.set(self.channel, 'xmppPassword', "1234")
305 self.ec.set(self.channel, 'version', "5")
307 self.app2 = self.ec.register_resource("OMFApplication")
308 self.ec.set(self.app2, 'version', "5")
310 self.ec.register_connection(self.iface1, self.channel)
311 self.ec.register_connection(self.iface2, self.channel)
312 self.ec.register_connection(self.node2, self.iface2)
313 self.ec.register_connection(self.app2, self.node2)
315 self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "2s")
316 self.ec.register_condition([self.app1, self.app2], ResourceAction.STOP, self.app1, ResourceState.STARTED , "4s")
320 self.ec.wait_finished([self.app1, self.app2])
322 self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
326 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
327 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
328 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
329 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
330 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
331 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
332 self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.RELEASED)
334 def test_deploy_wo_app_path(self):
335 self.node2 = self.ec.register_resource("OMFNode")
336 self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
337 self.ec.set(self.node2, 'xmppUser', "nepi")
338 self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
339 self.ec.set(self.node2, 'xmppPort', "5222")
340 self.ec.set(self.node2, 'xmppPassword', "1234")
341 self.ec.set(self.node2, 'version', "5")
343 self.iface2 = self.ec.register_resource("OMFWifiInterface")
344 self.ec.set(self.iface2, 'name', "wlan0")
345 self.ec.set(self.iface2, 'mode', "adhoc")
346 self.ec.set(self.iface2, 'hw_mode', "g")
347 self.ec.set(self.iface2, 'essid', "vlcexp")
348 self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
349 self.ec.set(self.iface2, 'version', "5")
351 self.channel = self.ec.register_resource("OMFChannel")
352 self.ec.set(self.channel, 'channel', "6")
353 self.ec.set(self.channel, 'xmppUser', "nepi")
354 self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
355 self.ec.set(self.channel, 'xmppPort', "5222")
356 self.ec.set(self.channel, 'xmppPassword', "1234")
357 self.ec.set(self.channel, 'version', "5")
359 self.app2 = self.ec.register_resource("OMFApplication")
360 self.ec.set(self.app2, 'appid', 'Vlc#2')
361 self.ec.set(self.app2, 'version', "5")
363 self.ec.register_connection(self.iface1, self.channel)
364 self.ec.register_connection(self.iface2, self.channel)
365 self.ec.register_connection(self.node2, self.iface2)
366 self.ec.register_connection(self.app2, self.node2)
368 self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "2s")
369 self.ec.register_condition([self.app1, self.app2], ResourceAction.STOP, self.app1, ResourceState.STARTED , "4s")
373 self.ec.wait_finished([self.app1, self.app2])
375 self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
379 self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
380 self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
381 self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
382 self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
383 self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
384 self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
385 self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.RELEASED)
388 if __name__ == '__main__':