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