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 ###############################################################################
46 # - t2 (t1 + 10s) : Ping stop
47 # - t3 (t2 + 2s) : Kill the application
50 from nepi.execution.resource import ResourceAction, ResourceState
51 from nepi.execution.ec import ExperimentController
53 from optparse import OptionParser
56 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
58 parser = OptionParser(usage = usage)
59 parser.add_option("-x", "--nodex", dest="nodex",
60 help="Nitos first reserved node "
61 "(e.g. hostname must be of form: node0XX)",
63 parser.add_option("-z", "--nodez", dest="nodez",
64 help="Nitos second reserved node "
65 "(e.g. hostname must be of form: node0ZZ)",
67 parser.add_option("-c", "--channel", dest="channel",
68 help="Nitos reserved channel",
70 parser.add_option("-s", "--slice-name", dest="slicename",
71 help="Nitos slice name", type="str")
72 (options, args) = parser.parse_args()
76 slicename = options.slicename
77 chan = options.channel
80 ec = ExperimentController(exp_id="nitos_omf6_vlc")
82 # Create and Configure the Nodes
83 node1 = ec.register_resource("omf::Node")
84 ec.set(node1, "hostname", nodex)
85 ec.set(node1, "xmppUser", slicename)
86 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
87 ec.set(node1, "xmppPort", "5222")
88 ec.set(node1, "xmppPassword", "1234")
90 # Create and Configure the Interfaces
91 iface1 = ec.register_resource("omf::WifiInterface")
92 ec.set(iface1, "name", "wlan0")
93 ec.set(iface1, "mode", "adhoc")
94 ec.set(iface1, "hw_mode", "g")
95 ec.set(iface1, "essid", "vlc")
96 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
97 ec.register_connection(node1, iface1)
99 # Create and Configure the Nodes
100 node2 = ec.register_resource("omf::Node")
101 ec.set(node2, "hostname", nodez)
102 ec.set(node2, "xmppUser", slicename)
103 ec.set(node2, "xmppServer", "nitlab.inf.uth.gr")
104 ec.set(node2, "xmppPort", "5222")
105 ec.set(node2, "xmppPassword", "1234")
107 # Create and Configure the Interfaces
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.%s/24" % nodez[-2:])
114 ec.register_connection(node2, iface2)
116 # Create and Configure the Channel
117 channel = ec.register_resource("omf::Channel")
118 ec.set(channel, "channel", chan)
119 ec.set(channel, "xmppUser", slicename)
120 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
121 ec.set(channel, "xmppPort", "5222")
122 ec.set(channel, "xmppPassword", "1234")
123 ec.register_connection(iface1, channel)
124 ec.register_connection(iface2, channel)
126 client_ip = "192.168.0.%s" % nodez[-2:]
128 # Create and Configure the Application
129 app1 = ec.register_resource("omf::Application")
130 ec.set(app1, "command",
131 "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)
132 ec.register_connection(app1, node1)
134 ## Add a OMFApplication to run the client VLC and count the numer of bytes
135 ## transmitted, using wc.
136 app2 = ec.register_resource("omf::Application")
137 ec.set(app2, "command",
138 "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 | wc -c "% client_ip)
140 ## Alternativelly, you can try to send the video to standard output and
141 ## recover it using the stdout trace. However, it seems that sending
142 ## binary messages back to the client is not well supported by the OMF 6 RC
143 #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)
144 ec.register_connection(app2, node2)
146 ## stop app1 65s after it started
147 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "65s")
148 ## start app2 5s after app1
149 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "5s")
150 ## stop app2 5 seconds after app2
151 ec.register_condition(app2, ResourceAction.STOP, app1, ResourceState.STOPPED , "5s")
156 ec.wait_finished([app2])
158 # Retrieve the bytes transmitted count and print it
159 byte_count = ec.trace(app2, "stdout")
160 print "BYTES transmitted", byte_count
162 ## If you redirected the video to standard output, you can try to
163 ## retrieve the stdout of the VLC client
164 ## video = ec.trace(app2, "stdout")
165 #f = open("video.ts", "w")