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 __future__ import print_function
51 from nepi.execution.resource import ResourceAction, ResourceState
52 from nepi.execution.ec import ExperimentController
54 from optparse import OptionParser
57 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
59 parser = OptionParser(usage = usage)
60 parser.add_option("-x", "--nodex", dest="nodex",
61 help="Nitos first reserved node "
62 "(e.g. hostname must be of form: node0XX)",
64 parser.add_option("-z", "--nodez", dest="nodez",
65 help="Nitos second reserved node "
66 "(e.g. hostname must be of form: node0ZZ)",
68 parser.add_option("-c", "--channel", dest="channel",
69 help="Nitos reserved channel",
71 parser.add_option("-s", "--slice-name", dest="slicename",
72 help="Nitos slice name", type="str")
73 (options, args) = parser.parse_args()
77 slicename = options.slicename
78 chan = options.channel
81 ec = ExperimentController(exp_id="nitos_omf6_vlc")
83 # Create and Configure the Nodes
84 node1 = ec.register_resource("omf::Node")
85 ec.set(node1, "hostname", nodex)
86 ec.set(node1, "xmppUser", slicename)
87 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
88 ec.set(node1, "xmppPort", "5222")
89 ec.set(node1, "xmppPassword", "1234")
91 # Create and Configure the Interfaces
92 iface1 = ec.register_resource("omf::WifiInterface")
93 ec.set(iface1, "name", "wlan0")
94 ec.set(iface1, "mode", "adhoc")
95 ec.set(iface1, "hw_mode", "g")
96 ec.set(iface1, "essid", "vlc")
97 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
98 ec.register_connection(node1, iface1)
100 # Create and Configure the Nodes
101 node2 = ec.register_resource("omf::Node")
102 ec.set(node2, "hostname", nodez)
103 ec.set(node2, "xmppUser", slicename)
104 ec.set(node2, "xmppServer", "nitlab.inf.uth.gr")
105 ec.set(node2, "xmppPort", "5222")
106 ec.set(node2, "xmppPassword", "1234")
108 # Create and Configure the Interfaces
109 iface2 = ec.register_resource("omf::WifiInterface")
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.%s/24" % nodez[-2:])
115 ec.register_connection(node2, iface2)
117 # Create and Configure the Channel
118 channel = ec.register_resource("omf::Channel")
119 ec.set(channel, "channel", chan)
120 ec.set(channel, "xmppUser", slicename)
121 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
122 ec.set(channel, "xmppPort", "5222")
123 ec.set(channel, "xmppPassword", "1234")
124 ec.register_connection(iface1, channel)
125 ec.register_connection(iface2, channel)
127 client_ip = "192.168.0.%s" % nodez[-2:]
129 # Create and Configure the Application
130 app1 = ec.register_resource("omf::Application")
131 ec.set(app1, "command",
132 "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)
133 ec.register_connection(app1, node1)
135 ## Add a OMFApplication to run the client VLC and count the numer of bytes
136 ## transmitted, using wc.
137 app2 = ec.register_resource("omf::Application")
138 ec.set(app2, "command",
139 "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority /root/vlc/vlc-1.1.13/cvlc rtp://%s:5004 | wc -c "% client_ip)
141 ## Alternativelly, you can try to send the video to standard output and
142 ## recover it using the stdout trace. However, it seems that sending
143 ## binary messages back to the client is not well supported by the OMF 6 RC
144 #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)
145 ec.register_connection(app2, node2)
147 ## stop app1 65s after it started
148 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "65s")
149 ## start app2 5s after app1
150 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "5s")
151 ## stop app2 5 seconds after app2
152 ec.register_condition(app2, ResourceAction.STOP, app1, ResourceState.STOPPED , "5s")
157 ec.wait_finished([app2])
159 # Retrieve the bytes transmitted count and print it
160 byte_count = ec.trace(app2, "stdout")
161 print("BYTES transmitted", byte_count)
163 ## If you redirected the video to standard output, you can try to
164 ## retrieve the stdout of the VLC client
165 ## video = ec.trace(app2, "stdout")
166 #with open("video.ts", "w") as f: