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>
23 # NOTE: This experiment example uses the generic LinuxApplication
24 # ResourceManager to do the CCN set up in the hosts.
25 # Alternatively, CCN specific ResourceManagers can be used
26 # (i.e. LinuxCCND, LinuxCCNR, etc...), and those require less
27 # manual configuration.
36 # Linux host Linux host
37 # 0 ------- Internet ------ 0
40 from nepi.execution.ec import ExperimentController, ECState
41 from nepi.execution.resource import ResourceState, ResourceAction
42 from nepi.resources.linux.node import OSType
44 from optparse import OptionParser, SUPPRESS_HELP
50 def add_node(ec, host, user, ssh_key = None):
51 node = ec.register_resource("linux::Node")
52 ec.set(node, "hostname", host)
53 ec.set(node, "username", user)
54 ec.set(node, "identity", ssh_key)
55 ec.set(node, "cleanExperiment", True)
56 ec.set(node, "cleanProcesses", True)
59 def add_ccnd(ec, os_type, peers):
60 if os_type == OSType.FEDORA:
61 depends = ( " autoconf openssl-devel expat-devel libpcap-devel "
62 " ecryptfs-utils-devel libxml2-devel automake gawk "
63 " gcc gcc-c++ git pcre-devel make ")
65 depends = ( " autoconf libssl-dev libexpat-dev libpcap-dev "
66 " libecryptfs0 libxml2-utils automake gawk gcc g++ "
67 " git-core pkg-config libpcre3-dev make ")
69 sources = "http://www.ccnx.org/releases/ccnx-0.7.1.tar.gz"
72 # Evaluate if ccnx binaries are already installed
74 " test -f ${BIN}/ccnx-0.7.1/bin/ccnd"
76 # If not, untar and build
78 " mkdir -p ${SRC}/ccnx-0.7.1 && "
79 " tar xf ${SRC}/ccnx-0.7.1.tar.gz --strip-components=1 -C ${SRC}/ccnx-0.7.1 "
81 "cd ${SRC}/ccnx-0.7.1 && "
82 # Just execute and silence warnings...
83 "( ./configure && make ) "
87 # Evaluate if ccnx binaries are already installed
89 " test -f ${BIN}/ccnx-0.7.1/bin/ccnd"
91 " mkdir -p ${BIN}/ccnx-0.7.1/bin && "
92 " cp -r ${SRC}/ccnx-0.7.1/bin ${BIN}/ccnx-0.7.1"
96 env = "PATH=$PATH:${BIN}/ccnx-0.7.1/bin"
98 # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr '
99 command = "ccndstart && "
100 peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers)
101 command += " ; ".join(peers) + " && "
102 command += " ccnr & "
104 app = ec.register_resource("linux::Application")
105 ec.set(app, "depends", depends)
106 ec.set(app, "sources", sources)
107 ec.set(app, "install", install)
108 ec.set(app, "build", build)
109 ec.set(app, "env", env)
110 ec.set(app, "command", command)
114 def add_publish(ec, movie):
115 env = "PATH=$PATH:${BIN}/ccnx-0.7.1/bin"
116 command = "ccnseqwriter -r ccnx:/VIDEO"
118 app = ec.register_resource("linux::Application")
119 ec.set(app, "stdin", movie)
120 ec.set(app, "env", env)
121 ec.set(app, "command", command)
126 env = "PATH=$PATH:${BIN}/ccnx-0.7.1/bin"
127 command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) "
129 app = ec.register_resource("linux::Application")
130 ec.set(app, "depends", "vlc")
131 ec.set(app, "forwardX11", True)
132 ec.set(app, "env", env)
133 ec.set(app, "command", command)
138 pl_slice = os.environ.get("PL_SLICE")
140 # We use a specific SSH private key for PL if the PL_SSHKEY is specified or the
141 # id_rsa_planetlab exists
142 default_key = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
143 default_key = default_key if os.path.exists(default_key) else None
144 pl_ssh_key = os.environ.get("PL_SSHKEY", default_key)
146 # Default planetlab host
147 pl_host = "planetlab2.u-strasbg.fr"
150 # IMPORTANT NOTE: you must replace this host for another one
151 # you have access to. You must set up your SSH keys so
152 # the host can be accessed through SSH without prompting
153 # for a password. The host must allow X forwarding using SSH.
154 linux_host = 'roseval.pl.sophia.inria.fr'
155 linux_user = getpass.getuser()
157 usage = "usage: %prog -p <pl-host> -s <pl-slice> -l <linux-host> -u <linux-user> -m <movie> -e <exp-id> -i <ssh_key>"
159 parser = OptionParser(usage=usage)
160 parser.add_option("-p", "--pl-host", dest="pl_host",
161 help="PlanetLab hostname (already added to the <pl-slice> on the web site)",
162 default = pl_host, type="str")
163 parser.add_option("-s", "--pl-slice", dest="pl_slice",
164 help="PlanetLab slicename", default = pl_slice, type="str")
165 parser.add_option("-l", "--linux-host", dest="linux_host",
166 help="Hostname of second Linux host (non PlanetLab)",
167 default = linux_host, type="str")
168 parser.add_option("-u", "--linux-user", dest="linux_user",
169 help="User for extra Linux host (non PlanetLab)",
170 default = linux_user, type="str")
171 parser.add_option("-m", "--movie", dest="movie",
172 help="Stream movie", type="str")
173 parser.add_option("-e", "--exp-id", dest="exp_id",
174 help="Label to identify experiment", type="str")
175 parser.add_option("-i", "--pl-ssh-key", dest="pl_ssh_key",
176 help="Path to private SSH key to be used for connection",
177 default = pl_ssh_key, type="str")
179 (options, args) = parser.parse_args()
181 if not options.movie:
182 parser.error("movie is a required argument")
184 return (options.pl_host, options.pl_slice, options.linux_host,
185 options.linux_user, options.movie, options.exp_id,
188 if __name__ == '__main__':
189 ( pl_host, pl_user, linux_host, linux_user, movie, exp_id, pl_ssh_key
192 # Create the ExperimentController instance
193 ec = ExperimentController(exp_id = exp_id)
195 # Register ResourceManager (RM)
197 # Register first PlanetLab host
198 node1 = add_node(ec, pl_host, pl_user, pl_ssh_key)
200 # Register CCN setup for PL host
202 ccnd1 = add_ccnd(ec, OSType.FEDORA, peers)
203 ec.register_connection(ccnd1, node1)
205 # Register content producer application (ccnseqwriter)
206 pub = add_publish(ec, movie)
207 ec.register_connection(pub, node1)
209 # The movie can only be published after ccnd is running
210 ec.register_condition(pub, ResourceAction.START,
211 ccnd1, ResourceState.STARTED)
213 # Register Linux host
214 node2 = add_node(ec, linux_host, linux_user)
216 # Register CCN setup for Linux host
218 ccnd2 = add_ccnd(ec, "ubuntu", peers)
219 ec.register_connection(ccnd2, node2)
221 # Register consumer application (ccncat)
222 stream = add_stream(ec)
223 ec.register_connection(stream, node2)
225 # The stream can only be retrieved after ccnd is running
226 ec.register_condition(stream, ResourceAction.START,
227 ccnd2, ResourceState.STARTED)
229 # And also, the stream can only be retrieved after it was published
230 ec.register_condition(stream, ResourceAction.START,
231 pub, ResourceState.STARTED)
233 # Deploy all ResourceManagers
236 # Wait until the applications are finished
237 apps = [ccnd1, pub, ccnd2, stream]
238 ec.wait_finished(apps)
240 # Shutdown the experiment controller