fc449c7037598b36a178496afa31f88c232e60ae
[nepi.git] / examples / manual_vlc_experiment_plexus.py
1 #!/usr/bin/env python
2 from nepi.execution.resource import ResourceFactory
3 from nepi.execution.ec import ExperimentController
4
5 from nepi.resources.omf.omf_node import OMFNode
6 from nepi.resources.omf.omf_application import OMFApplication
7 from nepi.resources.omf.omf_interface import OMFWifiInterface
8 from nepi.resources.omf.omf_channel import OMFChannel
9
10 import logging
11 import time
12
13 logging.basicConfig()
14
15 # Create the EC
16 ec = ExperimentController()
17
18 # Register the different RM that will be used
19 ResourceFactory.register_type(OMFNode)
20 ResourceFactory.register_type(OMFWifiInterface)
21 ResourceFactory.register_type(OMFChannel)
22 ResourceFactory.register_type(OMFApplication)
23
24 # Create and Configure the Nodes
25 guid = ec.register_resource("OMFNode")
26 node1 = ec.get_resource(guid)
27 node1.set('hostname', 'omf.plexus.wlab17')
28 node1.set('xmppSlice', "nepi")
29 node1.set('xmppHost', "xmpp-plexus.onelab.eu")
30 node1.set('xmppPort', "5222")
31 node1.set('xmppPassword', "1234")
32
33 guid = ec.register_resource("OMFNode")
34 node2 = ec.get_resource(guid)
35 node2.set('hostname', "omf.plexus.wlab37")
36 node2.set('xmppSlice', "nepi")
37 node2.set('xmppHost', "xmpp-plexus.onelab.eu")
38 node2.set('xmppPort', "5222")
39 node2.set('xmppPassword', "1234")
40
41 # Create and Configure the Interfaces
42 guid = ec.register_resource("OMFWifiInterface")
43 iface1 = ec.get_resource(guid)
44 iface1.set('alias', "w0")
45 iface1.set('mode', "adhoc")
46 iface1.set('type', "g")
47 iface1.set('essid', "helloworld")
48 iface1.set('ip', "10.0.0.17")
49 iface1.set('xmppSlice', "nepi")
50 iface1.set('xmppHost', "xmpp-plexus.onelab.eu")
51 iface1.set('xmppPort', "5222")
52 iface1.set('xmppPassword', "1234")
53
54 guid = ec.register_resource("OMFWifiInterface")
55 iface2 = ec.get_resource(guid)
56 iface2.set('alias', "w0")
57 iface2.set('mode', "adhoc")
58 iface2.set('type', 'g')
59 iface2.set('essid', "helloworld")
60 iface2.set('ip', "10.0.0.37")
61 iface2.set('xmppSlice', "nepi")
62 iface2.set('xmppHost', "xmpp-plexus.onelab.eu")
63 iface2.set('xmppPort', "5222")
64 iface2.set('xmppPassword', "1234")
65
66 # Create and Configure the Channel
67 guid = ec.register_resource("OMFChannel")
68 channel = ec.get_resource(guid)
69 channel.set('channel', "6")
70 channel.set('xmppSlice', "nepi")
71 channel.set('xmppHost', "xmpp-plexus.onelab.eu")
72 channel.set('xmppPort', "5222")
73 channel.set('xmppPassword', "1234")
74
75 # Create and Configure the Application
76 guid = ec.register_resource("OMFApplication")
77 app1 = ec.get_resource(guid)
78 app1.set('appid', 'Vlc#1')
79 app1.set('path', "/opt/vlc-1.1.13/cvlc")
80 app1.set('args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
81 app1.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
82 app1.set('xmppSlice', "nepi")
83 app1.set('xmppHost', "xmpp-plexus.onelab.eu")
84 app1.set('xmppPort', "5222")
85 app1.set('xmppPassword', "1234")
86
87 guid = ec.register_resource("OMFApplication")
88 app2 = ec.get_resource(guid)
89 app2.set('appid', 'Vlc#2')
90 app2.set('path', "/opt/vlc-1.1.13/cvlc")
91 app2.set('args', "rtp://10.0.0.37:1234")
92 app2.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
93 app2.set('xmppSlice', "nepi")
94 app2.set('xmppHost', "xmpp-plexus.onelab.eu")
95 app2.set('xmppPort', "5222")
96 app2.set('xmppPassword', "1234")
97
98 guid = ec.register_resource("OMFApplication")
99 app3 = ec.get_resource(guid)
100 app3.set('appid', 'Kill#2')
101 app3.set('path', "/usr/bin/killall")
102 app3.set('args', "vlc")
103 app3.set('env', " ")
104 app3.set('xmppSlice', "nepi")
105 app3.set('xmppHost', "xmpp-plexus.onelab.eu")
106 app3.set('xmppPort', "5222")
107 app3.set('xmppPassword', "1234")
108
109 # Connection
110 app3.connect(node1.guid)
111 node1.connect(app3.guid)
112
113 app1.connect(node1.guid)
114 node1.connect(app1.guid)
115
116 node1.connect(iface1.guid)
117 iface1.connect(node1.guid)
118
119 iface1.connect(channel.guid)
120 channel.connect(iface1.guid)
121
122 channel.connect(iface2.guid)
123 iface2.connect(channel.guid)
124
125 iface2.connect(node2.guid)
126 node2.connect(iface2.guid)
127
128 node2.connect(app2.guid)
129 app2.connect(node2.guid)
130
131 # Local Deploy
132 node1.deploy()
133 node2.deploy()
134 iface1.deploy()
135 iface2.deploy()
136 channel.deploy()
137 app1.deploy()
138 app2.deploy()
139 app3.deploy()
140
141 # Start the Nodes
142 node1.start()
143 node2.start()
144 time.sleep(2)
145
146 # Start the Interfaces
147 iface1.start()
148 iface2.start()
149
150 # Start the Channel
151 time.sleep(2)
152 channel.start()
153 time.sleep(2)
154
155 # Start the Application
156 app1.start()
157 time.sleep(2)
158 app2.start()
159
160 time.sleep(20)
161
162 # Stop the Application
163 app1.stop()
164 app2.stop()
165 time.sleep(1)
166 app3.start()
167 time.sleep(2)
168
169 # Stop Experiment
170 ec.shutdown()