2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Example of how to run this experiment (replace with your credentials):
23 # $ PYTHONPATH=$PYTHONPATH:~/repos/nepi/src python examples/linux/vlc_streaming.py -u inria_nepi -i ~/.ssh/id_rsa_planetlab -a planetlab1.u-strasbg.fr -b planetlab1.utt.fr | vlc -
26 from nepi.execution.ec import ExperimentController
27 from nepi.execution.resource import ResourceState, ResourceAction
29 from optparse import OptionParser, SUPPRESS_HELP
32 usage = ("usage: %prog -a <hostanme1> -b <hostname2> -u <username> -i <ssh-key>")
34 parser = OptionParser(usage = usage)
35 parser.add_option("-a", "--hostname1", dest="hostname1",
36 help="Remote host 1", type="str")
37 parser.add_option("-b", "--hostname2", dest="hostname2",
38 help="Remote host 2", type="str")
39 parser.add_option("-u", "--username", dest="username",
40 help="Username to SSH to remote host", type="str")
41 parser.add_option("-i", "--ssh-key", dest="ssh_key",
42 help="Path to private SSH key to be used for connection",
44 (options, args) = parser.parse_args()
46 hostname1 = options.hostname1
47 hostname2 = options.hostname2
48 username = options.username
49 ssh_key = options.ssh_key
51 ## Create the experiment controller
52 ec = ExperimentController(exp_id = "vlc_streamming")
55 node1 = ec.register_resource("LinuxNode")
56 # Set the hostname of the first node to use for the experiment
57 ec.set(node1, "hostname", hostname1)
58 # username should be your SSH user
59 ec.set(node1, "username", username)
60 # Absolute path to the SSH private key
61 ec.set(node1, "identity", ssh_key)
62 # Clean all files, results, etc, from previous experiments wit the same exp_id
63 ec.set(node1, "cleanExperiment", True)
64 # Kill all running processes in the node before running the experiment
65 ec.set(node1, "cleanProcesses", True)
68 node2 = ec.register_resource("LinuxNode")
69 # Set the hostname of the first node to use for the experiment
70 ec.set(node2, "hostname", hostname2)
71 # username should be your SSH user
72 ec.set(node2, "username", username)
73 # Absolute path to the SSH private key
74 ec.set(node2, "identity", ssh_key)
75 # Clean all files, results, etc, from previous experiments wit the same exp_id
76 ec.set(node2, "cleanExperiment", True)
77 # Kill all running processes in the node before running the experiment
78 ec.set(node2, "cleanProcesses", True)
81 video = "big_buck_bunny_240p_mpeg4_lq.ts"
82 local_path_to_video = os.path.join(
83 os.path.dirname(os.path.realpath(__file__)),
86 command = ("sudo -S dbus-uuidgen --ensure; sleep 3;"
87 "vlc -I dummy -vvv ${SHARE}/%s "
88 "--sout '#rtp{dst=%s,port=5004,mux=ts}' vlc://quit") % \
91 server = ec.register_resource("LinuxApplication")
92 ec.set(server, "depends", "vlc")
93 ec.set(server, "files", local_path_to_video)
94 ec.set(server, "command", command)
95 ec.register_connection(server, node1)
98 command = ("sudo -S dbus-uuidgen --ensure; sleep 3; "
99 "vlc -I dummy rtp://%s:5004/%s "
100 "--sout '#std{access=file,mux=ts,dst=VIDEO}'") % \
103 client = ec.register_resource("LinuxApplication")
104 ec.set(client, "depends", "vlc")
105 ec.set(client, "command", command)
106 ec.register_connection(client, node2)
108 # The stream can only be retrieved after ccnd is running
109 ec.register_condition(server, ResourceAction.START,
110 client, ResourceState.STARTED)
112 ## Deploy all resources
115 # Wait until the ccncat is finished
116 ec.wait_finished([server])
118 print ec.trace(client, "VIDEO")