3 ###############################################################################
5 # NEPI, a framework to manage network experiments
6 # Copyright (C) 2013 INRIA
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 as
10 # published by the Free Software Foundation;
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # Julien Tribino <julien.tribino@inria.fr>
23 ###############################################################################
44 # - t2 (t1 + 10s) : Ping stop
45 # - t3 (t2 + 2s) : Kill the application
48 from nepi.execution.resource import ResourceAction, ResourceState
49 from nepi.execution.ec import ExperimentController
51 from optparse import OptionParser
54 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
56 parser = OptionParser(usage = usage)
57 parser.add_option("-x", "--nodex", dest="nodex",
58 help="w-iLab.t first reserved node "
60 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
61 " all letters in lowercase )",
63 parser.add_option("-z", "--nodez", dest="nodez",
64 help="w-iLab.t first reserved node "
66 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
67 " all letters in lowercase )",
69 parser.add_option("-c", "--channel", dest="channel",
70 help="Nitos reserved channel",
72 parser.add_option("-s", "--slice-name", dest="slicename",
73 help="Nitos slice name", type="str")
74 (options, args) = parser.parse_args()
78 slicename = options.slicename
79 chan = options.channel
82 ec = ExperimentController(exp_id="iminds_omf6_ping")
84 # Create and Configure the Nodes
86 node1 = ec.register_resource("omf::Node")
87 ec.set(node1, "hostname", nodex)
88 ec.set(node1, "xmppUser", slicename)
89 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
90 ec.set(node1, "xmppPort", "5222")
91 ec.set(node1, "xmppPassword", "1234")
93 iface1 = ec.register_resource("omf::WifiInterface")
94 ec.set(iface1, "name", "wlan0")
95 ec.set(iface1, "mode", "adhoc")
96 ec.set(iface1, "hw_mode", "g")
97 ec.set(iface1, "essid", "vlc")
98 ec.set(iface1, "ip", "192.168.0.1/24")
99 ec.register_connection(iface1, node1)
101 node2 = ec.register_resource("omf::Node")
102 ec.set(node2, "hostname", nodez)
103 ec.set(node2, "xmppUser", slicename)
104 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
105 ec.set(node2, "xmppPort", "5222")
106 ec.set(node2, "xmppPassword", "1234")
108 iface2 = ec.register_resource("omf::WifiInterface")
109 ec.set(iface2, "name", "wlan0")
110 ec.set(iface2, "mode", "adhoc")
111 ec.set(iface2, "hw_mode", "g")
112 ec.set(iface2, "essid", "vlc")
113 ec.set(iface2, "ip", "192.168.0.2/24")
114 ec.register_connection(iface2, node2)
116 channel = ec.register_resource("omf::Channel")
117 ec.set(channel, "channel", "6")
118 ec.register_connection(iface1, channel)
119 ec.register_connection(iface2, channel)
121 client_ip = "192.168.0.2"
123 # Create and Configure the Application
124 app1 = ec.register_resource("omf::Application")
125 ec.set(app1, "command",
126 "/root/vlc/vlc-1.1.13/cvlc /root/10-by-p0d.avi --sout '#rtp{dst=%s,port=5004,mux=ts}'" % client_ip)
127 ec.register_connection(app1, node1)
129 ## Add a OMFApplication to run the client VLC
130 app2 = ec.register_resource("omf::Application")
131 ## Send the transmitted video to a file.
132 ec.set(app2, "command", "/root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 --sout '#standard{access=file,mux=ts,dst=/root/video.ts}'" % client_ip)
133 ec.register_connection(app2, node2)
135 ## Add a OMFApplication to count the number of bytes in the transmitted video
136 app3 = ec.register_resource("omf::Application")
137 ## Send the transmitted video to a file.
138 ec.set(app3, "command", "ls -lah /root/video.ts")
139 ec.register_connection(app3, node2)
141 app4 = ec.register_resource("omf::Application")
142 ec.set(app4, "command", "/usr/bin/killall vlc_app")
143 ec.register_connection(app4, node1)
145 app5 = ec.register_resource("omf::Application")
146 ec.set(app5, "command", "/usr/bin/killall vlc_app")
147 ec.register_connection(app5, node2)
149 ## start app2 5s after app1
150 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "5s")
151 # start app3 after app2 stopped
152 ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STOPPED , "5s")
153 # start the kill of vlc processes after they stopped
154 ec.register_condition(app4, ResourceAction.START, app1, ResourceState.STOPPED , "5s")
155 ec.register_condition(app5, ResourceAction.START, app2, ResourceState.STOPPED , "5s")
157 ## We need to explicitly STOP all applications
158 ## stop app1 65s after it started
159 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "65s")
160 ## stop app2 5 seconds after app2
161 ec.register_condition(app2, ResourceAction.STOP, app1, ResourceState.STOPPED , "5s")
163 ec.register_condition(app3, ResourceAction.STOP, app3, ResourceState.STOPPED , "5s")
165 ec.register_condition(app4, ResourceAction.STOP, app4, ResourceState.STARTED , "5s")
167 ec.register_condition(app5, ResourceAction.STOP, app5, ResourceState.STARTED , "5s")
172 # DO NOT WAIT FOR THE VLC applications or it will never stop
173 ec.wait_finished([app4, app5])
175 # Retrieve the bytes transmitted output and print it
176 byte_count = ec.trace(app3, "stdout")
177 print "BYTES transmitted", byte_count