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, \
26 from optparse import OptionParser, SUPPRESS_HELP
31 def add_node(ec, host, user, ssh_key = None):
32 node = ec.register_resource("LinuxNode")
33 ec.set(node, "hostname", host)
34 ec.set(node, "username", user)
35 ec.set(node, "identity", ssh_key)
36 ec.set(node, "cleanHome", True)
37 ec.set(node, "cleanProcesses", True)
40 def add_ccnd(ec, os_type, peers):
42 depends = ( " autoconf openssl-devel expat-devel libpcap-devel "
43 " ecryptfs-utils-devel libxml2-devel automake gawk "
44 " gcc gcc-c++ git pcre-devel make ")
45 elif os_type == "ubuntu":
46 depends = ( " autoconf libssl-dev libexpat-dev libpcap-dev "
47 " libecryptfs0 libxml2-utils automake gawk gcc g++ "
48 " git-core pkg-config libpcre3-dev make ")
50 sources = "http://www.ccnx.org/releases/ccnx-0.7.1.tar.gz"
53 # Evaluate if ccnx binaries are already installed
55 " test -f ${EXP_HOME}/ccnx/bin/ccnd"
57 # If not, untar and build
59 " mkdir -p ${SOURCES}/ccnx && "
60 " tar xf ${SOURCES}/ccnx-0.7.1.tar.gz --strip-components=1 -C ${SOURCES}/ccnx "
62 "cd ${SOURCES}/ccnx && "
63 # Just execute and silence warnings...
64 "( ( ./configure && make ) 2>&1 )"
68 # Evaluate if ccnx binaries are already installed
70 " test -f ${EXP_HOME}/ccnx/bin/ccnd"
72 " mkdir -p ${EXP_HOME}/ccnx/bin && "
73 " cp -r ${SOURCES}/ccnx ${EXP_HOME}"
77 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
79 # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr '
80 command = "ccndstart ; "
81 peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers)
82 command += " ; ".join(peers) + " ; "
85 app = ec.register_resource("LinuxApplication")
86 ec.set(app, "depends", depends)
87 ec.set(app, "sources", sources)
88 ec.set(app, "install", install)
89 ec.set(app, "build", build)
90 ec.set(app, "env", env)
91 ec.set(app, "command", command)
95 def add_publish(ec, movie):
96 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
97 command = "ccnseqwriter -r ccnx:/VIDEO"
99 app = ec.register_resource("LinuxApplication")
100 ec.set(app, "stdin", movie)
101 ec.set(app, "env", env)
102 ec.set(app, "command", command)
107 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
108 command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) "
110 app = ec.register_resource("LinuxApplication")
111 ec.set(app, "depends", "vlc")
112 ec.set(app, "forwardX11", True)
113 ec.set(app, "env", env)
114 ec.set(app, "command", command)
119 slicename = os.environ.get("PL_SLICE")
121 # We use a specific SSH private key for PL if the PL_SSHKEY is specified or the
122 # id_rsa_planetlab exists
123 default_key = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
124 default_key = default_key if os.path.exists(default_key) else None
125 pl_ssh_key = os.environ.get("PL_SSHKEY", default_key)
127 usage = "usage: %prog -s <pl-slice> -u <username> -m <movie> -l <exp-id> -i <ssh_key>"
129 parser = OptionParser(usage=usage)
130 parser.add_option("-s", "--pl-slice", dest="pl_slice",
131 help="PlanetLab slicename", default = slicename, type="str")
132 parser.add_option("-u", "--username", dest="username",
133 help="User for extra host (non PlanetLab)", type="str")
134 parser.add_option("-m", "--movie", dest="movie",
135 help="Stream movie", type="str")
136 parser.add_option("-l", "--exp-id", dest="exp_id",
137 help="Label to identify experiment", type="str")
138 parser.add_option("-i", "--pl-ssh-key", dest="pl_ssh_key",
139 help="Path to private SSH key to be used for connection",
140 default = pl_ssh_key, type="str")
142 (options, args) = parser.parse_args()
144 if not options.movie:
145 parser.error("movie is a required argument")
147 return (options.pl_slice, options.username, options.movie, options.exp_id,
150 if __name__ == '__main__':
151 ( pl_slice, username, movie, exp_id, pl_ssh_key ) = get_options()
153 # Search for available RMs
157 host1 = 'planetlab2.u-strasbg.fr'
160 # IMPORTANT NOTE: you must replace this host for another one
161 # you have access to. You must set up your SSH keys so
162 # the host can be accessed through SSH without prompting
163 # for a password. The host must allow X forwarding using SSH.
164 host2 = 'roseval.pl.sophia.inria.fr'
166 # Create the ExperimentController instance
167 ec = ExperimentController(exp_id = exp_id)
169 # Register a ResourceManager (RM) for the PlanetLab node
170 node1 = add_node(ec, host1, pl_slice, pl_ssh_key)
173 ccnd1 = add_ccnd(ec, "f12", peers)
175 ec.register_connection(ccnd1, node1)
177 pub = add_publish(ec, movie)
178 ec.register_connection(pub, node1)
180 # The movie can only be published after ccnd is running
181 ec.register_condition(pub, ResourceAction.START,
182 ccnd1, ResourceState.STARTED)
184 node2 = add_node(ec, host2, username)
186 ccnd2 = add_ccnd(ec, "ubuntu", peers)
187 ec.register_connection(ccnd2, node2)
189 stream = add_stream(ec)
190 ec.register_connection(stream, node2)
192 # The stream can only be retrieved after ccnd is running
193 ec.register_condition(stream, ResourceAction.START,
194 ccnd2, ResourceState.STARTED)
196 # And also, the stream can only be retrieved after it was published
197 ec.register_condition(stream, ResourceAction.START,
198 pub, ResourceState.STARTED)
200 # Deploy all ResourceManagers
203 # Wait until the applications are finished
204 apps = [ccnd1, pub, ccnd2, stream]
205 ec.wait_finished(apps)
207 # Shutdown the experiment controller