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>
27 # content l1 / \ l2 ccncat
29 # 0 ----- h1 0 --- 0 h3 ------ 0
35 # - t0 : b2 retrives video published in b1
41 from nepi.execution.ec import ExperimentController, ECState
42 from nepi.execution.resource import ResourceState, ResourceAction, \
44 from nepi.resources.linux.node import OSType
46 from optparse import OptionParser, SUPPRESS_HELP
52 def add_node(ec, host, user, ssh_key = None):
53 node = ec.register_resource("LinuxNode")
54 ec.set(node, "hostname", host)
55 ec.set(node, "username", user)
56 ec.set(node, "identity", ssh_key)
57 ec.set(node, "cleanHome", True)
58 ec.set(node, "cleanProcesses", True)
61 def add_ccnd(ec, node):
62 ccnd = ec.register_resource("LinuxCCND")
63 ec.set(ccnd, "debug", 7)
64 ec.register_connection(ccnd, node)
67 def add_ccnr(ec, ccnd):
68 ccnr = ec.register_resource("LinuxCCNR")
69 ec.register_connection(ccnr, ccnd)
72 def add_fib_entry(ec, ccnd, peer_host):
73 entry = ec.register_resource("LinuxFIBEntry")
74 ec.set(entry, "host", peer_host)
75 ec.register_connection(entry, ccnd)
78 def add_content(ec, ccnr, content_name, content):
79 co = ec.register_resource("LinuxCCNContent")
80 ec.set(co, "contentName", content_name)
81 ec.set(co, "content", content)
82 ec.register_connection(co, ccnr)
85 def add_stream(ec, ccnd, content_name):
86 command = "sudo -S dbus-uuidgen --ensure ; ccncat %s | vlc - " % \
89 app = ec.register_resource("LinuxCCNApplication")
90 ec.set(app, "depends", "vlc")
91 ec.set(app, "forwardX11", True)
92 ec.set(app, "command", command)
93 ec.register_connection(app, ccnd)
97 if __name__ == '__main__':
98 # Search for available RMs
101 ec = ExperimentController(exp_id = "olahh")
104 host1 = "planetlab2.u-strasbg.fr"
105 host2 = "planet1.servers.ua.pt"
106 host3 = "planetlab1.cs.uoi.gr"
107 host4 = "planetlab1.aston.ac.uk"
108 host5 = "itchy.comlab.bth.se"
109 host6 = "roseval.pl.sophia.inria.fr"
112 pluser = "inria_alina"
115 content_name = "ccnx:/VIDEO"
116 video = "/home/alina/repos/nepi/examples/big_buck_bunny_240p_mpeg4_lq.ts"
118 # describe nodes in the central ring
119 ring_hosts = [host1, host2, host3, host4]
122 for i in xrange(len(ring_hosts)):
124 node = add_node(ec, host, pluser)
125 ccnd = add_ccnd(ec, node)
126 ccnr = add_ccnr(ec, ccnd)
129 ## Add ccn ring links
130 # l1 : h1 - h2 , h2 - h1
131 l1u = add_fib_entry(ec, ccnds[host1], host2)
132 l1d = add_fib_entry(ec, ccnds[host2], host1)
134 # l2 : h2 - h3 , h3 - h2
135 l2u = add_fib_entry(ec, ccnds[host2], host3)
136 l2d = add_fib_entry(ec, ccnds[host3], host2)
138 # l3 : h3 - h4 , h4 - h3
139 l3u = add_fib_entry(ec, ccnds[host3], host4)
140 l3d = add_fib_entry(ec, ccnds[host4], host3)
142 # l4 : h4 - h1 , h1 - h4
143 l4u = add_fib_entry(ec, ccnds[host4], host1)
144 l4d = add_fib_entry(ec, ccnds[host1], host4)
146 # l5 : h1 - h3 , h3 - h1
147 l5u = add_fib_entry(ec, ccnds[host1], host3)
148 l5d = add_fib_entry(ec, ccnds[host3], host1)
151 bnode1 = add_node(ec, host5, pluser)
152 ccndb1 = add_ccnd(ec, bnode1)
153 ccnrb1 = add_ccnr(ec, ccndb1)
154 co = add_content(ec, ccnrb1, content_name, video)
157 bnode2 = add_node(ec, host6, user)
158 ccndb2 = add_ccnd(ec, bnode2)
159 ccnrb2 = add_ccnr(ec, ccndb2)
160 app = add_stream(ec, ccndb2, content_name)
162 # connect border nodes
163 #add_fib_entry(ec, ccndb1, host1)
164 #add_fib_entry(ec, ccnds[host1], host5)
166 #add_fib_entry(ec, ccndb2, host3)
167 #add_fib_entry(ec, ccnds[host3], host6)
169 add_fib_entry(ec, ccndb2, host5)
170 add_fib_entry(ec, ccndb1, host6)
172 # deploy all ResourceManagers
175 ec.wait_finished([app])
178 proc2 = subprocess.Popen(['vlc',
179 '--ffmpeg-threads=1',
180 '--sub-filter', 'marq',
182 '(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org',
184 '--no-video-title-show', '-'],
185 stdin=proc1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
187 dirpath = tempfile.mkdtemp()
190 # shutdown the experiment controller