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 information):
23 # python examples/linux/vlc_streaming.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
25 from nepi.execution.ec import ExperimentController
26 from nepi.execution.resource import ResourceState, ResourceAction
28 from optparse import OptionParser, SUPPRESS_HELP
31 usage = ("usage: %prog -a <hostanme1> -b <hostname2> -u <username> -i <ssh-key>")
33 parser = OptionParser(usage = usage)
34 parser.add_option("-a", "--hostname1", dest="hostname1",
35 help="Remote host 1", type="str")
36 parser.add_option("-b", "--hostname2", dest="hostname2",
37 help="Remote host 2", type="str")
38 parser.add_option("-u", "--username", dest="username",
39 help="Username to SSH to remote host", type="str")
40 parser.add_option("-i", "--ssh-key", dest="ssh_key",
41 help="Path to private SSH key to be used for connection",
43 (options, args) = parser.parse_args()
45 hostname1 = options.hostname1
46 hostname2 = options.hostname2
47 username = options.username
48 ssh_key = options.ssh_key
50 ## Create the experiment controller
51 ec = ExperimentController(exp_id = "vlc_streamming")
54 node1 = ec.register_resource("linux::Node")
55 # Set the hostname of the first node to use for the experiment
56 ec.set(node1, "hostname", hostname1)
57 # username should be your SSH user
58 ec.set(node1, "username", username)
59 # Absolute path to the SSH private key
60 ec.set(node1, "identity", ssh_key)
61 # Clean all files, results, etc, from previous experiments wit the same exp_id
62 ec.set(node1, "cleanExperiment", True)
63 # Kill all running processes in the node before running the experiment
64 ec.set(node1, "cleanProcesses", True)
67 node2 = ec.register_resource("linux::Node")
68 # Set the hostname of the first node to use for the experiment
69 ec.set(node2, "hostname", hostname2)
70 # username should be your SSH user
71 ec.set(node2, "username", username)
72 # Absolute path to the SSH private key
73 ec.set(node2, "identity", ssh_key)
74 # Clean all files, results, etc, from previous experiments wit the same exp_id
75 ec.set(node2, "cleanExperiment", True)
76 # Kill all running processes in the node before running the experiment
77 ec.set(node2, "cleanProcesses", True)
80 video = "big_buck_bunny_240p_mpeg4_lq.ts"
81 local_path_to_video = os.path.join(
82 os.path.dirname(os.path.realpath(__file__)),
85 command = ("sudo -S dbus-uuidgen --ensure; sleep 3;"
86 "vlc -I dummy -vvv ${SHARE}/%s "
87 "--sout '#rtp{dst=%s,port=5004,mux=ts}' vlc://quit") % \
90 server = ec.register_resource("linux::Application")
91 ec.set(server, "depends", "vlc")
92 ec.set(server, "files", local_path_to_video)
93 ec.set(server, "command", command)
94 ec.register_connection(server, node1)
97 command = ("sudo -S dbus-uuidgen --ensure; sleep 3; "
98 "vlc -I dummy rtp://%s:5004/%s "
99 "--sout '#std{access=file,mux=ts,dst=VIDEO}'") % \
102 client = ec.register_resource("linux::Application")
103 ec.set(client, "depends", "vlc")
104 ec.set(client, "command", command)
105 ec.register_connection(client, node2)
107 # The stream can only be retrieved after ccnd is running
108 ec.register_condition(server, ResourceAction.START,
109 client, ResourceState.STARTED)
111 ## Deploy all resources
114 # Wait until the ccncat is finished
115 ec.wait_finished([server])
117 video = ec.trace(client, "VIDEO")
118 f = open("video.ts", "w")
124 print "Streamed VIDEO stored localy at video.ts"