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 version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 # Example of how to run this experiment (replace with your information):
22 # python examples/linux/vlc_streaming.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
24 from nepi.execution.ec import ExperimentController
25 from nepi.execution.resource import ResourceState, ResourceAction
27 from optparse import OptionParser, SUPPRESS_HELP
30 usage = ("usage: %prog -a <hostanme1> -b <hostname2> -u <username> -i <ssh-key>")
32 parser = OptionParser(usage = usage)
33 parser.add_option("-a", "--hostname1", dest="hostname1",
34 help="Remote host 1", type="str")
35 parser.add_option("-b", "--hostname2", dest="hostname2",
36 help="Remote host 2", type="str")
37 parser.add_option("-u", "--username", dest="username",
38 help="Username to SSH to remote host", type="str")
39 parser.add_option("-i", "--ssh-key", dest="ssh_key",
40 help="Path to private SSH key to be used for connection",
42 (options, args) = parser.parse_args()
44 hostname1 = options.hostname1
45 hostname2 = options.hostname2
46 username = options.username
47 ssh_key = options.ssh_key
49 ## Create the experiment controller
50 ec = ExperimentController(exp_id = "vlc_streamming")
53 node1 = ec.register_resource("linux::Node")
54 # Set the hostname of the first node to use for the experiment
55 ec.set(node1, "hostname", hostname1)
56 # username should be your SSH user
57 ec.set(node1, "username", username)
58 # Absolute path to the SSH private key
59 ec.set(node1, "identity", ssh_key)
60 # Clean all files, results, etc, from previous experiments wit the same exp_id
61 ec.set(node1, "cleanExperiment", True)
62 # Kill all running processes in the node before running the experiment
63 ec.set(node1, "cleanProcesses", True)
66 node2 = ec.register_resource("linux::Node")
67 # Set the hostname of the first node to use for the experiment
68 ec.set(node2, "hostname", hostname2)
69 # username should be your SSH user
70 ec.set(node2, "username", username)
71 # Absolute path to the SSH private key
72 ec.set(node2, "identity", ssh_key)
73 # Clean all files, results, etc, from previous experiments wit the same exp_id
74 ec.set(node2, "cleanExperiment", True)
75 # Kill all running processes in the node before running the experiment
76 ec.set(node2, "cleanProcesses", True)
79 video = "big_buck_bunny_240p_mpeg4_lq.ts"
80 local_path_to_video = os.path.join(
81 os.path.dirname(os.path.realpath(__file__)),
84 command = ("sudo -S dbus-uuidgen --ensure; sleep 3;"
85 "vlc -I dummy -vvv ${SHARE}/%s "
86 "--sout '#rtp{dst=%s,port=5004,mux=ts}' vlc://quit") % \
89 server = ec.register_resource("linux::Application")
90 ec.set(server, "depends", "vlc")
91 ec.set(server, "files", local_path_to_video)
92 ec.set(server, "command", command)
93 ec.register_connection(server, node1)
96 command = ("sudo -S dbus-uuidgen --ensure; sleep 3; "
97 "vlc -I dummy rtp://%s:5004/%s "
98 "--sout '#std{access=file,mux=ts,dst=VIDEO}'") % \
101 client = ec.register_resource("linux::Application")
102 ec.set(client, "depends", "vlc")
103 ec.set(client, "command", command)
104 ec.register_connection(client, node2)
106 # The stream can only be retrieved after ccnd is running
107 ec.register_condition(server, ResourceAction.START,
108 client, ResourceState.STARTED)
110 ## Deploy all resources
113 # Wait until the ccncat is finished
114 ec.wait_finished([server])
116 video = ec.trace(client, "VIDEO")
117 f = open("video.ts", "w")
123 print "Streamed VIDEO stored localy at video.ts"