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 as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
22 # Julien Tribino <julien.tribino@inria.fr>
24 ###############################################################################
45 # - t2 (t1 + 10s) : Ping stop
46 # - t3 (t2 + 2s) : Kill the application
49 from nepi.execution.resource import ResourceAction, ResourceState
50 from nepi.execution.ec import ExperimentController
52 from optparse import OptionParser
55 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
57 parser = OptionParser(usage = usage)
58 parser.add_option("-x", "--nodex", dest="nodex",
59 help="w-iLab.t first reserved node "
61 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
62 " all letters in lowercase )",
64 parser.add_option("-z", "--nodez", dest="nodez",
65 help="w-iLab.t first reserved node "
67 " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
68 " all letters in lowercase )",
70 parser.add_option("-c", "--channel", dest="channel",
71 help="Nitos reserved channel",
73 parser.add_option("-s", "--slice-name", dest="slicename",
74 help="Nitos slice name", type="str")
75 (options, args) = parser.parse_args()
79 slicename = options.slicename
80 chan = options.channel
83 ec = ExperimentController(exp_id="iminds_omf6_ping")
85 # Create and Configure the Nodes
87 node1 = ec.register_resource("OMFNode")
88 ec.set(node1, "hostname", nodex)
89 ec.set(node1, "xmppUser", slicename)
90 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
91 ec.set(node1, "xmppPort", "5222")
92 ec.set(node1, "xmppPassword", "1234")
94 iface1 = ec.register_resource("OMFWifiInterface")
95 ec.set(iface1, "name", "wlan0")
96 ec.set(iface1, "mode", "adhoc")
97 ec.set(iface1, "hw_mode", "g")
98 ec.set(iface1, "essid", "ping")
99 ec.set(iface1, "ip", "192.168.0.1/24")
100 ec.register_connection(iface1, node1)
102 node2 = ec.register_resource("OMFNode")
103 ec.set(node2, "hostname", nodez)
104 ec.set(node2, "xmppUser", slicename)
105 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
106 ec.set(node2, "xmppPort", "5222")
107 ec.set(node2, "xmppPassword", "1234")
109 iface2 = ec.register_resource("OMFWifiInterface")
110 ec.set(iface2, "name", "wlan0")
111 ec.set(iface2, "mode", "adhoc")
112 ec.set(iface2, "hw_mode", "g")
113 ec.set(iface2, "essid", "vlc")
114 ec.set(iface2, "ip", "192.168.0.2/24")
115 ec.register_connection(iface2, node2)
117 channel = ec.register_resource("OMFChannel")
118 ec.set(channel, "channel", "6")
119 ec.register_connection(iface1, channel)
120 ec.register_connection(iface2, channel)
122 client_ip = "192.168.0.2"
124 # Create and Configure the Application
125 app1 = ec.register_resource("OMFApplication")
126 ec.set(app1, "command",
127 "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc /root/10-by-p0d.avi --sout '#rtp{dst=%s,port=5004,mux=ts}'" % client_ip)
128 ec.register_connection(app1, node1)
130 ## Add a OMFApplication to run the client VLC and count the numer of bytes
131 ## transmitted, using wc.
132 app2 = ec.register_resource("OMFApplication")
133 ## Send the transmitted video to a file.
134 ec.set(app2, "command", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 --sout '#standard{access=file,mux=ts,dst=/root/video}'" % client_ip)
136 ## Alternativelly, you can try to send the video to standard output and
137 ## recover it using the stdout trace. However, it seems that sending
138 ## binary messages back to the client is not well supported by the OMF 6 RC
139 #ec.set(app2, "command", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 --sout '#standard{access=file,mux=ts,dst=-}'" % client_ip)
140 ec.register_connection(app2, node2)
142 ## stop app1 65s after it started
143 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "65s")
144 ## start app2 5s after app1
145 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "5s")
146 ## stop app2 5 seconds after app2
147 ec.register_condition(app2, ResourceAction.STOP, app1, ResourceState.STOPPED , "5s")
152 ec.wait_finished([app2])
154 # Retrieve the bytes transmitted count and print it
155 byte_count = ec.trace(app2, "stdout")
156 print "BYTES transmitted", byte_count
158 ## If you redirected the video to standard output, you can try to
159 ## retrieve the stdout of the VLC client
160 ## video = ec.trace(app2, "stdout")
161 #f = open("video.ts", "w")
168 print ec.trace(app1, "stdout")