3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from nepi.execution.ec import ExperimentController
20 from nepi.execution.resource import ResourceAction, ResourceState
26 # Set experiment for broadcast or vod mode
28 parser = argparse.ArgumentParser(description='NEPI VoD/Broadcast experiment')
29 parser.add_argument('-m', '--mode', help='Set vlc mode, possible values <vod> or <broadcast>', required=True)
30 args = parser.parse_args()
34 # Create the entity Experiment Controller
37 ec = ExperimentController(exp_id)
39 # Define SFA credentials
41 slicename = 'ple.inria.nepi'
42 sfauser = 'ple.inria.aquereilhac'
43 sfaPrivateKey = '/home/alina/.sfi/aquereilhac.pkey'
45 # Functions for nodes and ifaces registration
47 def create_planetlab_node(ec, host):
48 node = ec.register_resource("planetlab::sfa::Node")
49 ec.set(node, "hostname", host)
50 ec.set(node, "username", "inria_nepi")
51 ec.set(node, "sfauser", sfauser)
52 ec.set(node, "sfaPrivateKey", sfaPrivateKey)
53 ec.set(node, 'cleanExperiment', True)
56 def create_omf_node(ec, host):
57 node = ec.register_resource("wilabt::sfa::Node")
58 ec.set(node, "host", host)
59 ec.set(node, "slicename", slicename)
60 ec.set(node, "sfauser", sfauser)
61 ec.set(node, "sfaPrivateKey", sfaPrivateKey)
62 ec.set(node, "gatewayUser", "nepi")
63 ec.set(node, "gateway", "bastion.test.iminds.be")
64 ec.set(node, "disk_image", 'NepiVlcOMF6Baseline')
65 ec.set(node, 'xmppServer', "xmpp.ilabt.iminds.be")
66 ec.set(node, 'xmppUser', "nepi")
67 ec.set(node, 'xmppPort', "5222")
68 ec.set(node, 'xmppPassword', "1234")
71 def create_omf_iface(ec, ip, node):
72 iface = ec.register_resource("omf::WifiInterface")
73 ec.set(iface, 'name', 'wlan0')
74 ec.set(iface, 'mode', "adhoc")
75 ec.set(iface, 'hw_mode', "g")
76 ec.set(iface, 'essid', "vlc")
77 ec.set(iface, 'ip', ip)
78 ec.register_connection(iface, node)
81 # Register Internet VLC server
83 video_server = create_planetlab_node(ec, 'planetlab3.xeno.cl.cam.ac.uk')
85 # Register wifi media center and client nodes
87 wifi_center = create_omf_node(ec, 'zotacB1')
88 client1 = create_omf_node(ec, 'zotacB3')
89 client2 = create_omf_node(ec, 'zotacB5')
90 client3 = create_omf_node(ec, 'zotacC1')
91 client4 = create_omf_node(ec, 'zotacC3')
92 client5 = create_omf_node(ec, 'zotacB2')
94 omf_nodes = [wifi_center, client1, client2, client3, client4, client5]
96 # Register ifaces in wireless nodes
98 iface_center = create_omf_iface(ec, "192.168.0.1/24", wifi_center)
99 iface_client1 = create_omf_iface(ec, "192.168.0.2/24", client1)
100 iface_client2 = create_omf_iface(ec, "192.168.0.3/24", client2)
101 iface_client3 = create_omf_iface(ec, "192.168.0.4/24", client3)
102 iface_client4 = create_omf_iface(ec, "192.168.0.5/24", client4)
103 iface_client5 = create_omf_iface(ec, "192.168.0.6/24", client5)
105 omf_ifaces = [iface_center, iface_client1, iface_client2, iface_client3, iface_client4, iface_client5]
109 chan = ec.register_resource("omf::Channel")
110 ec.set(chan, 'channel', "6")
112 # Register connection ifaces - channel
114 ec.register_connection(iface_center, chan)
115 ec.register_connection(iface_client1, chan)
116 ec.register_connection(iface_client2, chan)
117 ec.register_connection(iface_client3, chan)
118 ec.register_connection(iface_client4, chan)
119 ec.register_connection(iface_client5, chan)
121 resources = [video_server] + omf_nodes + omf_ifaces + [chan]
123 # Deploy physical resources and wait until they become provisioned
127 ec.wait_deployed(resources)
131 # Functions for applications registration in the nodes
133 def create_vlc_server(ec, video_server, mode):
134 vlc_server = ec.register_resource("linux::Application")
135 ec.set(vlc_server, "depends", "vlc")
136 ec.set(vlc_server, "sources", "examples/omf/demo_openlab/big_buck_bunny_240p_mpeg4_lq.ts")
137 # Depending on the mode selected to run the experiment,
138 # different configuation files and command to run are
139 # uploaded to the server
141 ec.set(vlc_server, "files", "examples/omf/demo_openlab/conf_VoD.vlm")
142 ec.set(vlc_server, "command", "sudo -S dbus-uuidgen --ensure ; cvlc --vlm-conf ${SHARE}/conf_VoD.vlm --rtsp-host 128.232.103.203:5554 2>/tmp/logpl.txt")
143 elif mode == 'broadcast':
144 ec.set(vlc_server, "files", "examples/omf/demo_openlab/conf_Broadcast.vlm")
145 ec.set(vlc_server, "command", "sudo -S dbus-uuidgen --ensure ; cvlc --vlm-conf ${SHARE}/conf_Broadcast.vlm --rtsp-host 128.232.103.203:5554 2>/tmp/logpl.txt")
146 ec.register_connection(video_server, vlc_server)
149 def create_omf_app(ec, command, node):
150 app = ec.register_resource("omf::Application")
151 ec.set(app, 'command', command)
152 ec.register_connection(app, node)
156 # Run the VLC server in the Planetlab node
158 vlc_server = create_vlc_server(ec, video_server, mode)
160 # Upload configuration to the wifi media center and run VLC
163 update_file_wificenter = "echo -e 'new BUNNY vod enabled\\n"\
164 "setup BUNNY input rtsp://128.232.103.203:5554/BUNNY' > /root/wificenter.vlm"
165 command_wificenter = "/root/vlc/vlc-1.1.13/cvlc --vlm-conf /root/wificenter.vlm --rtsp-host 192.168.0.1:5554"
166 elif mode == 'broadcast':
167 update_file_wificenter = "echo -e 'new BUNNY broadcast enabled loop\\n"\
168 "setup BUNNY input rtsp://128.232.103.203:8554/BUNNY\\n"\
169 "setup BUNNY output #rtp{access=udp,mux=ts,sdp=rtsp://0.0.0.0:8554/BUNNY}\\n\\n"\
170 "new test_sched schedule enabled\\n"\
171 "setup test_sched append control BUNNY play' > /root/wificenter.vlm"
172 command_wificenter = "/root/vlc/vlc-1.1.13/cvlc --vlm-conf /root/wificenter.vlm --rtsp-host 192.168.0.1:8554"
174 upload_conf = create_omf_app(ec, update_file_wificenter , wifi_center)
175 vlc_wificenter = create_omf_app(ec, command_wificenter , wifi_center)
177 ec.register_condition(upload_conf, ResourceAction.START, vlc_server, ResourceState.STARTED , "2s")
178 ec.register_condition(vlc_wificenter, ResourceAction.START, upload_conf, ResourceState.STARTED , "2s")
180 # measurements in video server (PL node)
181 measure_videoserver = ec.register_resource("linux::Application")
182 ec.set(measure_videoserver, "depends", "tcpdump")
183 ec.set(measure_videoserver, "sudo", True)
184 command = "tcpdump -i eth0 not arp -n -w /tmp/capplserver_%s.pcap" % ("$(date +'%Y%m%d%H%M%S')")
185 ec.set(measure_videoserver, "command", command)
186 ec.register_connection(measure_videoserver, video_server)
189 ec.deploy([vlc_server, upload_conf, vlc_wificenter, measure_videoserver])
191 ec.wait_started([vlc_server, upload_conf, vlc_wificenter, measure_videoserver])
195 def deploy_experiment(ec, clients, wifi_center):
197 # measurements in transmitter eth0
198 command_measure_wificentereth0 = "/usr/sbin/tcpdump -i eth0 not arp -n -w /tmp/capwificen_eth0_%s_%s.pcap" % (len(clients), "$(date +'%Y%m%d%H%M%S')")
199 measure_wificentereth0 = create_omf_app(ec, command_measure_wificentereth0, wifi_center)
200 ec.register_condition(measure_wificentereth0, ResourceAction.STOP, measure_wificentereth0, ResourceState.STARTED , "65s")
202 # measurements in transmitter wlan0
203 command_measure_wificenterwlan0 = "/usr/sbin/tcpdump -i wlan0 not arp -n -w /tmp/capwificen_wlan0_%s_%s.pcap" % (len(clients), "$(date +'%Y%m%d%H%M%S')")
204 measure_wificenterwlan0 = create_omf_app(ec, command_measure_wificenterwlan0, wifi_center)
205 ec.register_condition(measure_wificenterwlan0, ResourceAction.STOP, measure_wificenterwlan0, ResourceState.STARTED , "65s")
207 # kill tcpdumps in wificenter
208 command_kill_measure_wificentereth0 = "killall /usr/sbin/tcpdump"
209 kill_measure_wificentereth0 = create_omf_app(ec, command_kill_measure_wificentereth0, wifi_center)
210 ec.register_condition(kill_measure_wificentereth0, ResourceAction.START, measure_wificentereth0, ResourceState.STARTED , "65s")
211 ec.register_condition(kill_measure_wificentereth0, ResourceAction.STOP, kill_measure_wificentereth0, ResourceState.STARTED , "2s")
214 apps = [measure_wificentereth0, measure_wificenterwlan0, kill_measure_wificentereth0]
216 for client in clients:
217 client_host = ec.get(client, 'host').split('.')[0]
218 # measurements in clients
219 command_measure_client = "/usr/sbin/tcpdump -i wlan0 not arp -n -w /tmp/capcli_%s_%s_%s.pcap" % (client_host, len(clients), "$(date +'%Y%m%d%H%M%S')")
221 if mode == 'broadcast':
222 command_client = "/root/vlc/vlc-1.1.13/cvlc rtsp://192.168.0.1:8554/BUNNY --sout=file/ts:%s_%s_%s.ts 2>/tmp/logcli.txt" % (client_host, len(clients), "$(date +'%Y%m%d%H%M%S')")
224 command_client = "/root/vlc/vlc-1.1.13/cvlc rtsp://192.168.0.1:5554/BUNNY --sout=file/ts:%s_%s_%s.ts 2>/tmp/logcli.txt" % (client_host, len(clients), "$(date +'%Y%m%d%H%M%S')")
226 # kill vlc client and tcpdump
227 command_client_killvlc = "killall vlc vlc_app"
228 command_client_killtcp = "killall /usr/sbin/tcpdump"
230 run_client = create_omf_app(ec, command_client, client)
231 measure_client = create_omf_app(ec, command_measure_client, client)
232 kill_clientvlc = create_omf_app(ec, command_client_killvlc, client)
233 kill_clienttcp = create_omf_app(ec, command_client_killtcp, client)
234 ec.register_condition(run_client, ResourceAction.START, measure_client, ResourceState.STARTED , delay)
235 ec.register_condition([run_client, measure_client], ResourceAction.STOP, run_client, ResourceState.STARTED , "60s")
236 ec.register_condition(kill_clientvlc, ResourceAction.START, run_client, ResourceState.STARTED , "60s")
237 ec.register_condition(kill_clienttcp, ResourceAction.START, measure_client, ResourceState.STARTED , "60s")
238 ec.register_condition(kill_clientvlc, ResourceAction.STOP, kill_clientvlc, ResourceState.STARTED , "2s")
239 ec.register_condition(kill_clienttcp, ResourceAction.STOP, kill_clienttcp, ResourceState.STARTED , "2s")
240 apps.append(run_client)
241 apps.append(measure_client)
242 apps.append(kill_clientvlc)
243 apps.append(kill_clienttcp)
251 apps1 = deploy_experiment(ec, [client1], wifi_center)
254 ec.wait_finished(apps1)
260 #apps3 = deploy_experiment(ec, [client1, client2, client3], wifi_center)
263 #ec.wait_finished(apps3)
269 #apps5 = deploy_experiment(ec, [client1, client2, client3, client4, client5], wifi_center)
272 #ec.wait_finished(apps5)