8fd81febf3bebe67b19f34c37442e1ea66d629e5
[nepi.git] / examples / omf / nepi_omf5_nitos_xeyes.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     Example :
22       - Testbed : Nitos
23       - Explanation :
24
25        VLC Streaming on VLC
26                    
27      Node
28      omf.nitos.node0xx 
29      0
30      |
31      |
32      0
33      xEyes
34    
35       - Experiment:
36         - t0 : Deployment
37         - t1 : xEeyes Start
38         - t2 (t1 + 10s) : xEyes stop
39         - t3 (t2 + 2s) : Kill the application
40 """
41
42 #!/usr/bin/env python
43 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
44 from nepi.execution.ec import ExperimentController
45
46 # Create the EC
47 ec = ExperimentController()
48
49 # Create and Configure the Nodes
50 node1 = ec.register_resource("OMFNode")
51 ec.set(node1, 'hostname', 'omf.nitos.node0XX')
52 ec.set(node1, 'xmppServer', "ZZZ")
53 ec.set(node1, 'xmppUser', "nitlab.inf.uth.gr")
54 ec.set(node1, 'xmppPort', "5222")
55 ec.set(node1, 'xmppPassword', "1234")
56 ec.set(node1, 'version', "5")
57
58 # Create and Configure the Interfaces
59 iface1 = ec.register_resource("OMFWifiInterface")
60 ec.set(iface1, 'name', "wlan0")
61 ec.set(iface1, 'mode', "adhoc")
62 ec.set(iface1, 'hw_mode', "g")
63 ec.set(iface1, 'essid', "xeyes")
64 ec.set(iface1, 'ip', "192.168.0.XX/24")
65 ec.set(iface1, 'version', "5")
66
67 # Create and Configure the Channel
68 channel = ec.register_resource("OMFChannel")
69 ec.set(channel, 'channel', "6")
70 ec.set(channel, 'xmppServer', "ZZZ")
71 ec.set(channel, 'xmppUser', "nitlab.inf.uth.gr")
72 ec.set(channel, 'xmppPort', "5222")
73 ec.set(channel, 'xmppPassword', "1234")
74 ec.set(channel, 'version', "5")
75
76 # Create and Configure the Application
77 app1 = ec.register_resource("OMFApplication")
78 ec.set(app1, 'appid', 'XEyes#1')
79 ec.set(app1, 'command', "/usr/bin/xeyes")
80 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
81 ec.set(app1, 'version', "5")
82
83 app2 = ec.register_resource("OMFApplication")
84 ec.set(app2, 'appid', 'Kill#1')
85 ec.set(app2, 'path', "/usr/bin/kill")
86 ec.set(app2, 'args', "xeyes")
87 ec.set(app2, 'env', " ")
88 ec.set(app2, 'version', "5")
89
90 # Connection
91 ec.register_connection(app2, node1)
92 ec.register_connection(app1, node1)
93 ec.register_connection(node1, iface1)
94 ec.register_connection(iface1, channel)
95
96 # User Behaviour
97 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
98 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
99 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
100
101 # Deploy
102 ec.deploy()
103
104 ec.wait_finished([app1, app2])
105
106 # Stop Experiment
107 ec.shutdown()