1cae09a6f81e426d2a7cfc09190ae2277c11828b
[nepi.git] / examples / automated_vlc_experiment_plexus.py
1 #!/usr/bin/env python
2 from neco.execution.resource import ResourceFactory, ResourceAction, ResourceState
3 from neco.execution.ec import ExperimentController
4
5 from neco.resources.omf.omf_node import OMFNode
6 from neco.resources.omf.omf_application import OMFApplication
7 from neco.resources.omf.omf_interface import OMFWifiInterface
8 from neco.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 node1 = ec.register_resource("OMFNode")
26 ec.set(node1, 'hostname', 'omf.plexus.wlab17')
27 ec.set(node1, 'xmppSlice', "nepi")
28 ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu")
29 ec.set(node1, 'xmppPort', "5222")
30 ec.set(node1, 'xmppPassword', "1234")
31
32 node2 = ec.register_resource("OMFNode")
33 ec.set(node2, 'hostname', "omf.plexus.wlab37")
34 ec.set(node2, 'xmppSlice', "nepi")
35 ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu")
36 ec.set(node2, 'xmppPort', "5222")
37 ec.set(node2, 'xmppPassword', "1234")
38
39 # Create and Configure the Interfaces
40 iface1 = ec.register_resource("OMFWifiInterface")
41 ec.set(iface1, 'alias', "w0")
42 ec.set(iface1, 'mode', "adhoc")
43 ec.set(iface1, 'type', "g")
44 ec.set(iface1, 'essid', "vlcexp")
45 #ec.set(iface1, 'ap', "11:22:33:44:55:66")
46 ec.set(iface1, 'ip', "10.0.0.17")
47 ec.set(iface1, 'xmppSlice', "nepi")
48 ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
49 ec.set(iface1, 'xmppPort', "5222")
50 ec.set(iface1, 'xmppPassword', "1234")
51
52 iface2 = ec.register_resource("OMFWifiInterface")
53 ec.set(iface2, 'alias', "w0")
54 ec.set(iface2, 'mode', "adhoc")
55 ec.set(iface2, 'type', 'g')
56 ec.set(iface2, 'essid', "vlcexp")
57 #ec.set(iface2, 'ap', "11:22:33:44:55:66")
58 ec.set(iface2, 'ip', "10.0.0.37")
59 ec.set(iface2, 'xmppSlice', "nepi")
60 ec.set(iface2, 'xmppHost', "xmpp-plexus.onelab.eu")
61 ec.set(iface2, 'xmppPort', "5222")
62 ec.set(iface2, 'xmppPassword', "1234")
63
64 # Create and Configure the Channel
65 channel = ec.register_resource("OMFChannel")
66 ec.set(channel, 'channel', "6")
67 ec.set(channel, 'xmppSlice', "nepi")
68 ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu")
69 ec.set(channel, 'xmppPort', "5222")
70 ec.set(channel, 'xmppPassword', "1234")
71
72 # Create and Configure the Application
73 app1 = ec.register_resource("OMFApplication")
74 ec.set(app1, 'appid', 'Vlc#1')
75 ec.set(app1, 'path', "/opt/vlc-1.1.13/cvlc")
76 ec.set(app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
77 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
78 ec.set(app1, 'xmppSlice', "nepi")
79 ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu")
80 ec.set(app1, 'xmppPort', "5222")
81 ec.set(app1, 'xmppPassword', "1234")
82
83 app2 = ec.register_resource("OMFApplication")
84 ec.set(app2, 'appid', 'Vlc#2')
85 ec.set(app2, 'path', "/opt/vlc-1.1.13/cvlc")
86 ec.set(app2, 'args', "rtp://10.0.0.37:1234")
87 ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
88 ec.set(app2, 'xmppSlice', "nepi")
89 ec.set(app2, 'xmppHost', "xmpp-plexus.onelab.eu")
90 ec.set(app2, 'xmppPort', "5222")
91 ec.set(app2, 'xmppPassword', "1234")
92
93 app3 = ec.register_resource("OMFApplication")
94 ec.set(app3, 'appid', 'Kill#2')
95 ec.set(app3, 'path', "/usr/bin/killall")
96 ec.set(app3, 'args', "vlc")
97 ec.set(app3, 'env', " ")
98 ec.set(app3, 'xmppSlice', "nepi")
99 ec.set(app3, 'xmppHost', "xmpp-plexus.onelab.eu")
100 ec.set(app3, 'xmppPort', "5222")
101 ec.set(app3, 'xmppPassword', "1234")
102
103 # Connection
104 ec.register_connection(app3, node1)
105 ec.register_connection(app1, node1)
106 ec.register_connection(node1, iface1)
107 ec.register_connection(iface1, channel)
108 ec.register_connection(iface2, channel)
109 ec.register_connection(node2, iface2)
110 ec.register_connection(app2, node2)
111
112 # Condition
113 #      Topology behaviour : It should not be done by the user, but ....
114 #ec.register_condition([iface1, iface2, channel], ResourceAction.START, [node1, node2], ResourceState.STARTED , 2)
115 #ec.register_condition(channel, ResourceAction.START, [iface1, iface2], ResourceState.STARTED , 1)
116 #ec.register_condition(app1, ResourceAction.START, channel, ResourceState.STARTED , 1)
117
118 #      User Behaviour
119 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "4s")
120 ec.register_condition([app1, app2], ResourceAction.STOP, app2, ResourceState.STARTED , "20s")
121 ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STARTED , "25s")
122
123 # Deploy
124 ec.deploy()
125
126 # Stop Experiment
127 time.sleep(50)
128 ec.shutdown()