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 ###############################################################################
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="Nitos first reserved node "
60 "(e.g. hostname must be of form: node0XX)",
62 parser.add_option("-z", "--nodez", dest="nodez",
63 help="Nitos second reserved node "
64 "(e.g. hostname must be of form: node0ZZ)",
66 parser.add_option("-c", "--channel", dest="channel",
67 help="Nitos reserved channel",
69 parser.add_option("-s", "--slice-name", dest="slicename",
70 help="Nitos slice name", type="str")
71 (options, args) = parser.parse_args()
75 slicename = options.slicename
76 chan = options.channel
79 ec = ExperimentController(exp_id="nitos_omf6_vlc")
81 # Create and Configure the Nodes
82 node1 = ec.register_resource("omf::Node")
83 ec.set(node1, "hostname", nodex)
84 ec.set(node1, "xmppUser", slicename)
85 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
86 ec.set(node1, "xmppPort", "5222")
87 ec.set(node1, "xmppPassword", "1234")
89 # Create and Configure the Interfaces
90 iface1 = ec.register_resource("omf::WifiInterface")
91 ec.set(iface1, "name", "wlan0")
92 ec.set(iface1, "mode", "adhoc")
93 ec.set(iface1, "hw_mode", "g")
94 ec.set(iface1, "essid", "vlc")
95 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
96 ec.register_connection(node1, iface1)
98 # Create and Configure the Nodes
99 node2 = ec.register_resource("omf::Node")
100 ec.set(node2, "hostname", nodez)
101 ec.set(node2, "xmppUser", slicename)
102 ec.set(node2, "xmppServer", "nitlab.inf.uth.gr")
103 ec.set(node2, "xmppPort", "5222")
104 ec.set(node2, "xmppPassword", "1234")
106 # Create and Configure the Interfaces
107 iface2 = ec.register_resource("omf::WifiInterface")
108 ec.set(iface2, "name", "wlan0")
109 ec.set(iface2, "mode", "adhoc")
110 ec.set(iface2, "hw_mode", "g")
111 ec.set(iface2, "essid", "vlc")
112 ec.set(iface2, "ip", "192.168.0.%s/24" % nodez[-2:])
113 ec.register_connection(node2, iface2)
115 # Create and Configure the Channel
116 channel = ec.register_resource("omf::Channel")
117 ec.set(channel, "channel", chan)
118 ec.set(channel, "xmppUser", slicename)
119 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
120 ec.set(channel, "xmppPort", "5222")
121 ec.set(channel, "xmppPassword", "1234")
122 ec.register_connection(iface1, channel)
123 ec.register_connection(iface2, channel)
125 client_ip = "192.168.0.%s" % nodez[-2:]
127 # Create and Configure the Application
128 app1 = ec.register_resource("omf::Application")
129 ec.set(app1, "command",
130 "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)
131 ec.register_connection(app1, node1)
133 ## Add a OMFApplication to run the client VLC and count the numer of bytes
134 ## transmitted, using wc.
135 app2 = ec.register_resource("omf::Application")
136 ec.set(app2, "command",
137 "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 | wc -c "% client_ip)
139 ## Alternativelly, you can try to send the video to standard output and
140 ## recover it using the stdout trace. However, it seems that sending
141 ## binary messages back to the client is not well supported by the OMF 6 RC
142 #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)
143 ec.register_connection(app2, node2)
145 ## stop app1 65s after it started
146 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "65s")
147 ## start app2 5s after app1
148 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "5s")
149 ## stop app2 5 seconds after app2
150 ec.register_condition(app2, ResourceAction.STOP, app1, ResourceState.STOPPED , "5s")
155 ec.wait_finished([app2])
157 # Retrieve the bytes transmitted count and print it
158 byte_count = ec.trace(app2, "stdout")
159 print "BYTES transmitted", byte_count
161 ## If you redirected the video to standard output, you can try to
162 ## retrieve the stdout of the VLC client
163 ## video = ec.trace(app2, "stdout")
164 #f = open("video.ts", "w")