Adding omf generic resource manager, and change attributes for omf node
[nepi.git] / examples / omf / automated_vlc_experiment_plexus.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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
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.
15 #
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/>.
18 #
19 # Author: Julien Tribino <julien.tribino@inria.fr>
20
21 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
22 from nepi.execution.ec import ExperimentController
23
24 from nepi.resources.omf.node import OMFNode
25 from nepi.resources.omf.application import OMFApplication
26 from nepi.resources.omf.interface import OMFWifiInterface
27 from nepi.resources.omf.channel import OMFChannel
28
29 import logging
30 import time
31
32 logging.basicConfig()
33
34 # Create the EC
35 ec = ExperimentController()
36
37 # Create and Configure the Nodes
38 node1 = ec.register_resource("OMFNode")
39 ec.set(node1, 'hostname', 'omf.plexus.wlab17')
40 ec.set(node1, 'xmppSlice', "nepi")
41 ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu")
42 ec.set(node1, 'xmppPort', "5222")
43 ec.set(node1, 'xmppPassword', "1234")
44 ec.set(node1, 'xmppSlice', "nepi")
45 ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu")
46 ec.set(node1, 'xmppPort', "5222")
47 ec.set(node1, 'xmppPassword', "1234")
48
49 node2 = ec.register_resource("OMFNode")
50 ec.set(node2, 'hostname', "omf.plexus.wlab37")
51 ec.set(node2, 'xmppSlice', "nepi")
52 ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu")
53 ec.set(node2, 'xmppPort', "5222")
54 ec.set(node2, 'xmppPassword', "1234")
55 ec.set(node2, 'xmppSlice', "nepi")
56 ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu")
57 ec.set(node2, 'xmppPort', "5222")
58 ec.set(node2, 'xmppPassword', "1234")
59
60 # Create and Configure the Interfaces
61 iface1 = ec.register_resource("OMFWifiInterface")
62 ec.set(iface1, 'alias', "w0")
63 ec.set(iface1, 'mode', "adhoc")
64 ec.set(iface1, 'type', "g")
65 ec.set(iface1, 'essid', "vlcexp")
66 #ec.set(iface1, 'ap', "11:22:33:44:55:66")
67 ec.set(iface1, 'ip', "10.0.0.17")
68 ec.set(iface1, 'xmppSlice', "nepi")
69 ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
70 ec.set(iface1, 'xmppPort', "5222")
71 ec.set(iface1, 'xmppPassword', "1234")
72
73 iface2 = ec.register_resource("OMFWifiInterface")
74 ec.set(iface2, 'alias', "w0")
75 ec.set(iface2, 'mode', "adhoc")
76 ec.set(iface2, 'type', 'g')
77 ec.set(iface2, 'essid', "vlcexp")
78 #ec.set(iface2, 'ap', "11:22:33:44:55:66")
79 ec.set(iface2, 'ip', "10.0.0.37")
80 ec.set(iface2, 'xmppSlice', "nepi")
81 ec.set(iface2, 'xmppHost', "xmpp-plexus.onelab.eu")
82 ec.set(iface2, 'xmppPort', "5222")
83 ec.set(iface2, 'xmppPassword', "1234")
84
85 # Create and Configure the Channel
86 channel = ec.register_resource("OMFChannel")
87 ec.set(channel, 'channel', "6")
88 ec.set(channel, 'xmppSlice', "nepi")
89 ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu")
90 ec.set(channel, 'xmppPort', "5222")
91 ec.set(channel, 'xmppPassword', "1234")
92
93 # Create and Configure the Application
94 app1 = ec.register_resource("OMFApplication")
95 ec.set(app1, 'appid', 'Vlc#1')
96 ec.set(app1, 'path', "/opt/vlc-1.1.13/cvlc")
97 ec.set(app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
98 #ec.set(app1, 'args', "--quiet /opt/big_buck_bunny_240p_mpeg4.ts --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts} '")
99 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
100 ec.set(app1, 'xmppSlice', "nepi")
101 ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu")
102 ec.set(app1, 'xmppPort', "5222")
103 ec.set(app1, 'xmppPassword', "1234")
104
105 app2 = ec.register_resource("OMFApplication")
106 ec.set(app2, 'appid', 'Vlc#2')
107 ec.set(app2, 'path', "/opt/vlc-1.1.13/cvlc")
108 ec.set(app2, 'args', "--quiet rtp://10.0.0.37:1234")
109 ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
110 ec.set(app2, 'xmppSlice', "nepi")
111 ec.set(app2, 'xmppHost', "xmpp-plexus.onelab.eu")
112 ec.set(app2, 'xmppPort', "5222")
113 ec.set(app2, 'xmppPassword', "1234")
114
115 app3 = ec.register_resource("OMFApplication")
116 ec.set(app3, 'appid', 'Kill#2')
117 ec.set(app3, 'path', "/usr/bin/killall")
118 ec.set(app3, 'args', "vlc")
119 ec.set(app3, 'env', " ")
120 ec.set(app3, 'xmppSlice', "nepi")
121 ec.set(app3, 'xmppHost', "xmpp-plexus.onelab.eu")
122 ec.set(app3, 'xmppPort', "5222")
123 ec.set(app3, 'xmppPassword', "1234")
124
125 # Connection
126 ec.register_connection(app3, node1)
127 ec.register_connection(app1, node1)
128 ec.register_connection(node1, iface1)
129 ec.register_connection(iface1, channel)
130 ec.register_connection(iface2, channel)
131 ec.register_connection(node2, iface2)
132 ec.register_connection(app2, node2)
133
134 #      User Behaviour
135 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "4s")
136 ec.register_condition([app1, app2], ResourceAction.STOP, app2, ResourceState.STARTED , "22s")
137 ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STARTED , "25s")
138 ec.register_condition(app3, ResourceAction.STOP, app3, ResourceState.STARTED , "1s")
139
140 # Deploy
141 ec.deploy()
142
143 ec.wait_finished([app1, app2, app3])
144
145 # Stop Experiment
146 #time.sleep(55)
147 ec.shutdown()