4 # NEPI, a framework to manage network experiments
5 # Copyright (C) 2013 INRIA
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
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 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
22 from nepi.execution.ec import ExperimentController, ECState
23 from nepi.execution.resource import ResourceState, ResourceAction, \
25 from nepi.resources.linux.node import OSType
27 from optparse import OptionParser, SUPPRESS_HELP
32 def add_node(ec, host, user, ssh_key = None):
33 node = ec.register_resource("LinuxNode")
34 ec.set(node, "hostname", host)
35 ec.set(node, "username", user)
36 ec.set(node, "identity", ssh_key)
37 #ec.set(node, "cleanHome", True)
38 ec.set(node, "cleanProcesses", True)
41 def add_ccnd(ec, os_type, peers):
42 if os_type == OSType.FEDORA:
43 depends = ( " autoconf openssl-devel expat-devel libpcap-devel "
44 " ecryptfs-utils-devel libxml2-devel automake gawk "
45 " gcc gcc-c++ git pcre-devel make ")
47 depends = ( " autoconf libssl-dev libexpat-dev libpcap-dev "
48 " libecryptfs0 libxml2-utils automake gawk gcc g++ "
49 " git-core pkg-config libpcre3-dev make ")
51 sources = "http://www.ccnx.org/releases/ccnx-0.7.1.tar.gz"
54 # Evaluate if ccnx binaries are already installed
56 " test -f ${EXP_HOME}/ccnx/bin/ccnd"
58 # If not, untar and build
60 " mkdir -p ${SOURCES}/ccnx && "
61 " tar xf ${SOURCES}/ccnx-0.7.1.tar.gz --strip-components=1 -C ${SOURCES}/ccnx "
63 "cd ${SOURCES}/ccnx && "
64 # Just execute and silence warnings...
65 "( ./configure && make ) "
69 # Evaluate if ccnx binaries are already installed
71 " test -f ${EXP_HOME}/ccnx/bin/ccnd"
73 " mkdir -p ${EXP_HOME}/ccnx/bin && "
74 " cp -r ${SOURCES}/ccnx ${EXP_HOME}"
78 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
80 # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr '
81 command = "ccndstart && "
82 peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers)
83 command += " ; ".join(peers) + " && "
86 app = ec.register_resource("LinuxApplication")
87 ec.set(app, "depends", depends)
88 ec.set(app, "sources", sources)
89 ec.set(app, "install", install)
90 ec.set(app, "build", build)
91 ec.set(app, "env", env)
92 ec.set(app, "command", command)
96 def add_publish(ec, movie):
97 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
98 command = "ccnseqwriter -r ccnx:/VIDEO"
100 app = ec.register_resource("LinuxApplication")
101 ec.set(app, "stdin", movie)
102 ec.set(app, "env", env)
103 ec.set(app, "command", command)
108 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
109 command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) "
111 app = ec.register_resource("LinuxApplication")
112 ec.set(app, "depends", "vlc")
113 ec.set(app, "forwardX11", True)
114 ec.set(app, "env", env)
115 ec.set(app, "command", command)
120 slicename = os.environ.get("PL_SLICE")
122 # We use a specific SSH private key for PL if the PL_SSHKEY is specified or the
123 # id_rsa_planetlab exists
124 default_key = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
125 default_key = default_key if os.path.exists(default_key) else None
126 pl_ssh_key = os.environ.get("PL_SSHKEY", default_key)
128 usage = "usage: %prog -s <pl-slice> -u <username> -m <movie> -l <exp-id> -i <ssh_key>"
130 parser = OptionParser(usage=usage)
131 parser.add_option("-s", "--pl-slice", dest="pl_slice",
132 help="PlanetLab slicename", default = slicename, type="str")
133 parser.add_option("-u", "--username", dest="username",
134 help="User for extra host (non PlanetLab)", type="str")
135 parser.add_option("-m", "--movie", dest="movie",
136 help="Stream movie", type="str")
137 parser.add_option("-l", "--exp-id", dest="exp_id",
138 help="Label to identify experiment", type="str")
139 parser.add_option("-i", "--pl-ssh-key", dest="pl_ssh_key",
140 help="Path to private SSH key to be used for connection",
141 default = pl_ssh_key, type="str")
143 (options, args) = parser.parse_args()
145 if not options.movie:
146 parser.error("movie is a required argument")
148 return (options.pl_slice, options.username, options.movie, options.exp_id,
151 if __name__ == '__main__':
152 ( pl_slice, username, movie, exp_id, pl_ssh_key ) = get_options()
154 # Search for available RMs
158 host1 = 'planetlab2.u-strasbg.fr'
161 # IMPORTANT NOTE: you must replace this host for another one
162 # you have access to. You must set up your SSH keys so
163 # the host can be accessed through SSH without prompting
164 # for a password. The host must allow X forwarding using SSH.
165 host2 = 'roseval.pl.sophia.inria.fr'
167 # Create the ExperimentController instance
168 ec = ExperimentController(exp_id = exp_id)
170 # Register a ResourceManager (RM) for the PlanetLab node
171 node1 = add_node(ec, host1, pl_slice, pl_ssh_key)
174 ccnd1 = add_ccnd(ec, OSType.FEDORA, peers)
176 ec.register_connection(ccnd1, node1)
178 pub = add_publish(ec, movie)
179 ec.register_connection(pub, node1)
181 # The movie can only be published after ccnd is running
182 ec.register_condition(pub, ResourceAction.START,
183 ccnd1, ResourceState.STARTED)
185 node2 = add_node(ec, host2, username)
187 ccnd2 = add_ccnd(ec, "ubuntu", peers)
188 ec.register_connection(ccnd2, node2)
190 stream = add_stream(ec)
191 ec.register_connection(stream, node2)
193 # The stream can only be retrieved after ccnd is running
194 ec.register_condition(stream, ResourceAction.START,
195 ccnd2, ResourceState.STARTED)
197 # And also, the stream can only be retrieved after it was published
198 ec.register_condition(stream, ResourceAction.START,
199 pub, ResourceState.STARTED)
201 # Deploy all ResourceManagers
204 # Wait until the applications are finished
205 apps = [ccnd1, pub, ccnd2, stream]
206 ec.wait_finished(apps)
208 # Shutdown the experiment controller