Adding trace Collector RM
[nepi.git] / examples / omf / manual_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
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 # Register the different RM that will be used
38 ResourceFactory.register_type(OMFNode)
39 ResourceFactory.register_type(OMFWifiInterface)
40 ResourceFactory.register_type(OMFChannel)
41 ResourceFactory.register_type(OMFApplication)
42
43 # Create and Configure the Nodes
44 guid = ec.register_resource("OMFNode")
45 node1 = ec.get_resource(guid)
46 node1.set('hostname', 'omf.plexus.wlab17')
47 node1.set('xmppSlice', "nepi")
48 node1.set('xmppHost', "xmpp-plexus.onelab.eu")
49 node1.set('xmppPort', "5222")
50 node1.set('xmppPassword', "1234")
51
52 guid = ec.register_resource("OMFNode")
53 node2 = ec.get_resource(guid)
54 node2.set('hostname', "omf.plexus.wlab37")
55 node2.set('xmppSlice', "nepi")
56 node2.set('xmppHost', "xmpp-plexus.onelab.eu")
57 node2.set('xmppPort', "5222")
58 node2.set('xmppPassword', "1234")
59
60 # Create and Configure the Interfaces
61 guid = ec.register_resource("OMFWifiInterface")
62 iface1 = ec.get_resource(guid)
63 iface1.set('alias', "w0")
64 iface1.set('mode', "adhoc")
65 iface1.set('type', "g")
66 iface1.set('essid', "helloworld")
67 iface1.set('ip', "10.0.0.17")
68 iface1.set('xmppSlice', "nepi")
69 iface1.set('xmppHost', "xmpp-plexus.onelab.eu")
70 iface1.set('xmppPort', "5222")
71 iface1.set('xmppPassword', "1234")
72
73 guid = ec.register_resource("OMFWifiInterface")
74 iface2 = ec.get_resource(guid)
75 iface2.set('alias', "w0")
76 iface2.set('mode', "adhoc")
77 iface2.set('type', 'g')
78 iface2.set('essid', "helloworld")
79 iface2.set('ip', "10.0.0.37")
80 iface2.set('xmppSlice', "nepi")
81 iface2.set('xmppHost', "xmpp-plexus.onelab.eu")
82 iface2.set('xmppPort', "5222")
83 iface2.set('xmppPassword', "1234")
84
85 # Create and Configure the Channel
86 guid = ec.register_resource("OMFChannel")
87 channel = ec.get_resource(guid)
88 channel.set('channel', "6")
89 channel.set('xmppSlice', "nepi")
90 channel.set('xmppHost', "xmpp-plexus.onelab.eu")
91 channel.set('xmppPort', "5222")
92 channel.set('xmppPassword', "1234")
93
94 # Create and Configure the Application
95 guid = ec.register_resource("OMFApplication")
96 app1 = ec.get_resource(guid)
97 app1.set('appid', 'Vlc#1')
98 app1.set('path', "/opt/vlc-1.1.13/cvlc")
99 app1.set('args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
100 app1.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
101 app1.set('xmppSlice', "nepi")
102 app1.set('xmppHost', "xmpp-plexus.onelab.eu")
103 app1.set('xmppPort', "5222")
104 app1.set('xmppPassword', "1234")
105
106 guid = ec.register_resource("OMFApplication")
107 app2 = ec.get_resource(guid)
108 app2.set('appid', 'Vlc#2')
109 app2.set('path', "/opt/vlc-1.1.13/cvlc")
110 app2.set('args', "rtp://10.0.0.37:1234")
111 app2.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
112 app2.set('xmppSlice', "nepi")
113 app2.set('xmppHost', "xmpp-plexus.onelab.eu")
114 app2.set('xmppPort', "5222")
115 app2.set('xmppPassword', "1234")
116
117 guid = ec.register_resource("OMFApplication")
118 app3 = ec.get_resource(guid)
119 app3.set('appid', 'Kill#2')
120 app3.set('path', "/usr/bin/killall")
121 app3.set('args', "vlc")
122 app3.set('env', " ")
123 app3.set('xmppSlice', "nepi")
124 app3.set('xmppHost', "xmpp-plexus.onelab.eu")
125 app3.set('xmppPort', "5222")
126 app3.set('xmppPassword', "1234")
127
128 # register_connection
129 app3.register_connection(node1.guid)
130 node1.register_connection(app3.guid)
131
132 app1.register_connection(node1.guid)
133 node1.register_connection(app1.guid)
134
135 node1.register_connection(iface1.guid)
136 iface1.register_connection(node1.guid)
137
138 iface1.register_connection(channel.guid)
139 channel.register_connection(iface1.guid)
140
141 channel.register_connection(iface2.guid)
142 iface2.register_connection(channel.guid)
143
144 iface2.register_connection(node2.guid)
145 node2.register_connection(iface2.guid)
146
147 node2.register_connection(app2.guid)
148 app2.register_connection(node2.guid)
149
150 # Local Deploy
151 node1.deploy()
152 node2.deploy()
153 iface1.deploy()
154 iface2.deploy()
155 channel.deploy()
156 app1.deploy()
157 app2.deploy()
158 app3.deploy()
159
160 # Start the Nodes
161 node1.start()
162 node2.start()
163 time.sleep(2)
164
165 # Start the Interfaces
166 iface1.start()
167 iface2.start()
168
169 # Start the Channel
170 time.sleep(2)
171 channel.start()
172 time.sleep(2)
173
174 # Start the Application
175 app1.start()
176 time.sleep(2)
177 app2.start()
178
179 time.sleep(20)
180
181 # Stop the Application
182 app1.stop()
183 app2.stop()
184 time.sleep(1)
185 app3.start()
186 time.sleep(2)
187
188 # Stop Experiment
189 ec.shutdown()