d531c1ad09737992fc4c7b97fe0cf4b5d6bd0a56
[nepi.git] / examples / linux / ccn / vlc_2_hosts_ccndrms.py
1 #!/usr/bin/env python
2
3 #
4 #    NEPI, a framework to manage network experiments
5 #    Copyright (C) 2013 INRIA
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21
22 #
23 # topology:
24 #
25 #           0
26 #         /   \
27 #  0 --- 0     0 --- 0
28 #         \   /
29 #           0
30 #
31 #
32
33 from nepi.execution.ec import ExperimentController, ECState 
34 from nepi.execution.resource import ResourceState, ResourceAction, \
35         populate_factory
36 from nepi.resources.linux.node import OSType
37
38 from optparse import OptionParser, SUPPRESS_HELP
39
40 import os
41 import time
42
43 def add_node(ec, host, user, ssh_key = None):
44     node = ec.register_resource("LinuxNode")
45     ec.set(node, "hostname", host)
46     ec.set(node, "username", user)
47     ec.set(node, "identity", ssh_key)
48     ec.set(node, "cleanHome", True)
49     ec.set(node, "cleanProcesses", True)
50     return node
51
52 def add_ccnd(ec, node):
53     ccnd = ec.register_resource("LinuxCCND")
54     ec.set(ccnd, "debug", 7)
55     ec.register_connection(ccnd, node)
56     return ccnd
57
58 def add_ccnr(ec, ccnd):
59     ccnr = ec.register_resource("LinuxCCNR")
60     ec.register_connection(ccnr, ccnd)
61     return ccnr
62
63 def add_fib_entry(ec, ccnd, peer_host):
64     entry = ec.register_resource("LinuxFIBEntry")
65     ec.set(entry, "host", peer_host)
66     ec.register_connection(entry, ccnd)
67     return entry
68
69 def add_content(ec, ccnr, content_name, content):
70     co = ec.register_resource("LinuxCCNContent")
71     ec.set(co, "contentName", content_name)
72     ec.set(co, "content", content)
73     ec.register_connection(co, ccnr)
74     return co
75
76 def add_stream(ec, ccnd, content_name):
77     command = "sudo -S dbus-uuidgen --ensure ; ( ccncat %s | vlc - ) " % \
78             content_name
79
80     app = ec.register_resource("LinuxCCNDApplication")
81     ec.set(app, "depends", "vlc")
82     ec.set(app, "forwardX11", True)
83     ec.set(app, "command", command)
84     ec.register_connection(app, ccnd)
85
86     return app
87
88 if __name__ == '__main__':
89     # Search for available RMs
90     populate_factory()
91     
92     ec = ExperimentController(exp_id = "olahh")
93     
94     # hosts
95     host1 = 'planetlab2.u-strasbg.fr'
96     host2 = 'roseval.pl.sophia.inria.fr'
97
98     # users
99     user1 = "inria_alina"
100     user2 = "alina"
101
102     content_name = "ccnx:/VIDEO"
103     video = "/home/alina/repos/nepi/examples/big_buck_bunny_240p_mpeg4_lq.ts"
104
105     # Register a ResourceManagers (RMs)
106
107     node1 = add_node(ec, host1, user1)
108     ccnd1 = add_ccnd(ec, node1)
109     ccnr1 = add_ccnr(ec, ccnd1)
110     fibentry1 = add_fib_entry(ec, ccnd1, host2)
111     co = add_content(ec, ccnr1, content_name, video)
112
113     node2 = add_node(ec, host2, user2)
114     ccnd2 = add_ccnd(ec, node2)
115     ccnr2 = add_ccnr(ec, ccnd2)
116     fibentry2 = add_fib_entry(ec, ccnd2, host1)
117     app = add_stream(ec, ccnd2, content_name)
118  
119     # Deploy all ResourceManagers
120     ec.deploy()
121
122     ec.wait_finished([app])
123
124     # Shutdown the experiment controller
125     ec.shutdown()
126