Add openvswitch example
[nepi.git] / examples / omf / nepi_omf_vlc_experiment.py
1 """
2     NEPI, a framework to manage network experiments
3     Copyright (C) 2013 INRIA
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
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 """
19
20 #!/usr/bin/env python
21 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState, populate_factory
22 from nepi.execution.ec import ExperimentController
23
24 # Create the EC
25 ec = ExperimentController()
26
27 # Register the different RM that will be used
28 populate_factory()
29
30 # Create and Configure the Nodes
31 node1 = ec.register_resource("OMFNode")
32 ec.set(node1, 'hostname', 'omf.plexus.wlab17')
33 ec.set(node1, 'xmppSlice', "nepi")
34 ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu")
35 ec.set(node1, 'xmppPort', "5222")
36 ec.set(node1, 'xmppPassword', "1234")
37
38 node2 = ec.register_resource("OMFNode")
39 ec.set(node2, 'hostname', "omf.plexus.wlab37")
40 ec.set(node2, 'xmppSlice', "nepi")
41 ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu")
42 ec.set(node2, 'xmppPort', "5222")
43 ec.set(node2, 'xmppPassword', "1234")
44
45 # Create and Configure the Interfaces
46 iface1 = ec.register_resource("OMFWifiInterface")
47 ec.set(iface1, 'alias', "w0")
48 ec.set(iface1, 'mode', "adhoc")
49 ec.set(iface1, 'type', "g")
50 ec.set(iface1, 'essid', "vlcexp")
51 ec.set(iface1, 'ip', "10.0.0.17")
52 ec.set(iface1, 'xmppSlice', "nepi")
53 ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
54 ec.set(iface1, 'xmppPort', "5222")
55 ec.set(iface1, 'xmppPassword', "1234")
56
57 iface2 = ec.register_resource("OMFWifiInterface")
58 ec.set(iface2, 'alias', "w0")
59 ec.set(iface2, 'mode', "adhoc")
60 ec.set(iface2, 'type', 'g')
61 ec.set(iface2, 'essid', "vlcexp")
62 ec.set(iface2, 'ip', "10.0.0.37")
63 ec.set(iface2, 'xmppSlice', "nepi")
64 ec.set(iface2, 'xmppHost', "xmpp-plexus.onelab.eu")
65 ec.set(iface2, 'xmppPort', "5222")
66 ec.set(iface2, 'xmppPassword', "1234")
67
68 # Create and Configure the Channel
69 channel = ec.register_resource("OMFChannel")
70 ec.set(channel, 'channel', "6")
71 ec.set(channel, 'xmppSlice', "nepi")
72 ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu")
73 ec.set(channel, 'xmppPort', "5222")
74 ec.set(channel, 'xmppPassword', "1234")
75
76 # Create and Configure the Application
77 app1 = ec.register_resource("OMFApplication")
78 ec.set(app1, 'appid', 'Vlc#1')
79 ec.set(app1, 'path', "/opt/vlc-1.1.13/cvlc")
80 ec.set(app1, 'args', "--quiet /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
81 #ec.set(app1, 'args', "--quiet /opt/big_buck_bunny_240p_mpeg4.ts --sout '#rtp{dst=10.0.0.XX,port=1234,mux=ts} '")
82 #ec.set(app1, 'args', "--quiet /opt/big_buck_bunny_240p_mpeg4_lq.ts --sout '#rtp{dst=10.0.0.XX,port=1234,mux=ts} '")
83 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
84 ec.set(app1, 'xmppSlice', "nepi")
85 ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu")
86 ec.set(app1, 'xmppPort', "5222")
87 ec.set(app1, 'xmppPassword', "1234")
88
89 app2 = ec.register_resource("OMFApplication")
90 ec.set(app2, 'appid', 'Vlc#2')
91 ec.set(app2, 'path', "/opt/vlc-1.1.13/cvlc")
92 ec.set(app2, 'args', "--quiet rtp://10.0.0.37:1234")
93 ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
94 ec.set(app2, 'xmppSlice', "nepi")
95 ec.set(app2, 'xmppHost', "xmpp-plexus.onelab.eu")
96 ec.set(app2, 'xmppPort', "5222")
97 ec.set(app2, 'xmppPassword', "1234")
98
99 app3 = ec.register_resource("OMFApplication")
100 ec.set(app3, 'appid', 'Kill#2')
101 ec.set(app3, 'path', "/usr/bin/killall")
102 ec.set(app3, 'args', "vlc")
103 ec.set(app3, 'env', " ")
104 ec.set(app3, 'xmppSlice', "nepi")
105 ec.set(app3, 'xmppHost', "xmpp-plexus.onelab.eu")
106 ec.set(app3, 'xmppPort', "5222")
107 ec.set(app3, 'xmppPassword', "1234")
108
109 # Connection
110 ec.register_connection(app3, node1)
111 ec.register_connection(app1, node1)
112 ec.register_connection(node1, iface1)
113 ec.register_connection(iface1, channel)
114 ec.register_connection(iface2, channel)
115 ec.register_connection(node2, iface2)
116 ec.register_connection(app2, node2)
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 , "22s")
121 ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STARTED , "25s")
122 ec.register_condition(app3, ResourceAction.STOP, app3, ResourceState.STARTED , "1s")
123
124 # Deploy
125 ec.deploy()
126
127 ec.wait_finished([app1, app2, app3])
128
129 # Stop Experiment
130 ec.shutdown()