Fixing wrong license
[nepi.git] / examples / omf / testing / nepi_omf5_nitos_vlc.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 version 2 as
8 #    published by the Free Software Foundation;
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 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 #         Julien Tribino <julien.tribino@inria.fr>
20
21 """
22
23     Example :
24       - Testbed : Nitos
25       - Explanation :
26
27        VLC Streaming on VLC
28                    
29      Node                                               Node   
30      omf.nitos.node0xx                                  omf.nitos.node0xx
31      0--------------------------------------------------0
32      |                                                  |
33      |                                                  |
34      0                                                  0
35      VLC Server                                         VLC Client
36    
37       - Experiment:
38         - t0 : Deployment
39         - t1 : VLC Server start
40         - t2 (t1 + 4s) : VLC Client start
41         - t3 (t2 + 22s) : Client and Server Stop
42         - t4 (t3 + 3s): Kill all the applications
43
44 """
45
46 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
47 from nepi.execution.ec import ExperimentController
48
49 # Create the EC
50 ec = ExperimentController()
51
52 # Create and Configure the Nodes
53 node1 = ec.register_resource("omf::Node")
54 ec.set(node1, 'hostname', 'omf.nitos.node0XX')
55 ec.set(node1, 'xmppServer', "ZZZ")
56 ec.set(node1, 'xmppUser', "nitlab.inf.uth.gr")
57 ec.set(node1, 'xmppPort', "5222")
58 ec.set(node1, 'xmppPassword', "1234")
59 ec.set(node1, 'version', "5")
60
61 node2 = ec.register_resource("omf::Node")
62 ec.set(node2, 'hostname', "omf.nitos.node0YY")
63 ec.set(node2, 'xmppServer', "ZZZ")
64 ec.set(node2, 'xmppUser', "nitlab.inf.uth.gr")
65 ec.set(node2, 'xmppPort', "5222")
66 ec.set(node2, 'xmppPassword', "1234")
67 ec.set(node2, 'version', "5")
68
69 # Create and Configure the Interfaces
70 iface1 = ec.register_resource("omf::WifiInterface")
71 ec.set(iface1, 'name', "wlan0")
72 ec.set(iface1, 'mode', "adhoc")
73 ec.set(iface1, 'hw_mode', "g")
74 ec.set(iface1, 'essid', "vlcexp")
75 ec.set(iface1, 'ip', "192.168.0.XX/24")
76 ec.set(iface1, 'version', "5")
77
78 iface2 = ec.register_resource("omf::WifiInterface")
79 ec.set(iface2, 'name', "wlan0")
80 ec.set(iface2, 'mode', "adhoc")
81 ec.set(iface2, 'hw_mode', 'g')
82 ec.set(iface2, 'essid', "vlcexp")
83 ec.set(iface2, 'ip', "192.168.0.YY/24")
84 ec.set(iface2, 'version', "5")
85
86 # Create and Configure the Channel
87 channel = ec.register_resource("omf::Channel")
88 ec.set(channel, 'channel', "6")
89 ec.set(channel, 'xmppServer', "ZZZ")
90 ec.set(channel, 'xmppUser', "nitlab.inf.uth.gr")
91 ec.set(channel, 'xmppPort', "5222")
92 ec.set(channel, 'xmppPassword', "1234")
93 ec.set(channel, 'version', "5")
94
95 # Create and Configure the Application
96 app1 = ec.register_resource("omf::Application")
97 ec.set(app1, 'appid', 'Vlc#1')
98 ec.set(app1, 'command', "/root/vlc/vlc-1.1.13/cvlc /root/10-by-p0d.avi --sout '#rtp{dst=192.168.0.YY,port=1234,mux=ts}'")
99 ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
100 ec.set(app1, 'version', "5")
101
102 app2 = ec.register_resource("omf::Application")
103 ec.set(app2, 'appid', 'Vlc#2')
104 ec.set(app2, 'command', "/root/vlc/vlc-1.1.13/cvlc rtp://192.168.0.YY:1234")
105 ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
106 ec.set(app2, 'version', "5")
107
108 app3 = ec.register_resource("omf::Application")
109 ec.set(app3, 'appid', 'Kill#2')
110 ec.set(app3, 'command', "/usr/bin/killall vlc_app")
111 ec.set(app3, 'env', " ")
112 ec.set(app3, 'version', "5")
113
114 app4 = ec.register_resource("omf::Application")
115 ec.set(app4, 'appid', 'Kill#1')
116 ec.set(app4, 'command', "/usr/bin/killall vlc_app")
117 ec.set(app4, 'env', " ")
118 ec.set(app4, 'version', "5")
119
120 # Connection
121 ec.register_connection(app3, node1)
122 ec.register_connection(app1, node1)
123 ec.register_connection(node1, iface1)
124 ec.register_connection(iface1, channel)
125 ec.register_connection(iface2, channel)
126 ec.register_connection(node2, iface2)
127 ec.register_connection(app2, node2)
128 ec.register_connection(app4, node2)
129
130 # User Behaviour
131 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "4s")
132 ec.register_condition([app1, app2], ResourceAction.STOP, app2, ResourceState.STARTED , "22s")
133 ec.register_condition([app3, app4], ResourceAction.START, app2, ResourceState.STARTED , "25s")
134 ec.register_condition([app3, app4], ResourceAction.STOP, app3, ResourceState.STARTED , "1s")
135
136 # Deploy
137 ec.deploy()
138
139 ec.wait_finished([app1, app2, app3, app4])
140
141 # Stop Experiment
142 ec.shutdown()