update omf part with last changes for the demo
[nepi.git] / examples / omf / nepi_omf_xeyes_nitos.py
1 """
2     NEPI, a framework to manage network experiments
3     Copyright (C) 2013 INRIA
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
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.
14
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/>.
17
18     Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19             Julien Tribino <julien.tribino@inria.fr>
20
21 """
22
23 #!/usr/bin/env python
24 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
25 from nepi.execution.ec import ExperimentController
26
27 # Create the EC
28 ec = ExperimentController()
29
30 # Create and Configure the Nodes
31 node1 = ec.register_resource("OMFNode")
32 ec.set(node1, 'hostname', 'omf.nitos.node0XX')
33 ec.set(node1, 'xmppSlice', "ZZZ")
34 ec.set(node1, 'xmppHost', "nitlab.inf.uth.gr")
35 ec.set(node1, 'xmppPort', "5222")
36 ec.set(node1, 'xmppPassword', "1234")
37
38 # Create and Configure the Interfaces
39 iface1 = ec.register_resource("OMFWifiInterface")
40 ec.set(iface1, 'alias', "w0")
41 ec.set(iface1, 'mode', "adhoc")
42 ec.set(iface1, 'type', "g")
43 ec.set(iface1, 'essid', "xeyes")
44 ec.set(iface1, 'ip', "192.168.0.XX")
45 ec.set(iface1, 'xmppSlice', "ZZZ")
46 ec.set(iface1, 'xmppHost', "nitlab.inf.uth.gr")
47 ec.set(iface1, 'xmppPort', "5222")
48 ec.set(iface1, 'xmppPassword', "1234")
49
50 # Create and Configure the Channel
51 channel = ec.register_resource("OMFChannel")
52 ec.set(channel, 'channel', "6")
53 ec.set(channel, 'xmppSlice', "ZZZ")
54 ec.set(channel, 'xmppHost', "nitlab.inf.uth.gr")
55 ec.set(channel, 'xmppPort', "5222")
56 ec.set(channel, 'xmppPassword', "1234")
57
58 # Create and Configure the Application
59 app1 = ec.register_resource("OMFApplication")
60 ec.set(app1, 'appid', 'XEyes#1')
61 ec.set(app1, 'path', "/usr/bin/xeyes")
62 ec.set(app1, 'args', " ")
63 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
64
65 app2 = ec.register_resource("OMFApplication")
66 ec.set(app2, 'appid', 'Kill#1')
67 ec.set(app2, 'path', "/usr/bin/kill")
68 ec.set(app2, 'args', "xeyes")
69 ec.set(app2, 'env', " ")
70
71 # Connection
72 ec.register_connection(app2, node1)
73 ec.register_connection(app1, node1)
74 ec.register_connection(node1, iface1)
75 ec.register_connection(iface1, channel)
76
77 # User Behaviour
78 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
79 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
80 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
81
82 # Deploy
83 ec.deploy()
84
85 ec.wait_finished([app1, app2])
86
87 # Stop Experiment
88 ec.shutdown()