Adding Linux Application scalability tests
[nepi.git] / examples / linux / ccnx / simple_topo.py
1 #!/usr/bin/env python
2 from neco.execution.ec import ExperimentController, ECState 
3 from neco.execution.resource import ResourceState, ResourceAction, \
4         populate_factory
5
6 from optparse import OptionParser, SUPPRESS_HELP
7
8 import os
9 import time
10
11 def add_node(ec, host, user):
12     node = ec.register_resource("LinuxNode")
13     ec.set(node, "hostname", host)
14     ec.set(node, "username", user)
15     #ec.set(node, "cleanHome", True)
16     ec.set(node, "cleanProcesses", True)
17     return node
18
19 def add_ccnd(ec, os_type, peers):
20     if os_type == "f12":
21         depends = ( " autoconf openssl-devel  expat-devel libpcap-devel "
22                 " ecryptfs-utils-devel libxml2-devel automake gawk " 
23                 " gcc gcc-c++ git pcre-devel ")
24     elif os_type == "ubuntu":
25         depends = ( " autoconf libssl-dev libexpat-dev libpcap-dev "
26                 " libecryptfs0 libxml2-utils automake gawk gcc g++ "
27                 " git-core pkg-config libpcre3-dev ")
28
29     sources = "http://www.ccnx.org/releases/ccnx-0.7.1.tar.gz"
30
31     build = (
32         # Evaluate if ccnx binaries are already installed
33         " ( "
34             "  test -d ${EXP_HOME}/ccnx/bin"
35         " ) || ( "
36         # If not, untar and build
37             " ( "
38                 " mkdir -p ${SOURCES}/ccnx && "
39                 " tar xf ${SOURCES}/ccnx-0.7.1.tar.gz --strip-components=1 -C ${SOURCES}/ccnx "
40              " ) && "
41                 "cd ${SOURCES}/ccnx && "
42                 # Just execute and silence warnings...
43                 "(  ( ./configure && make )  2>&1 )"
44          " )") 
45
46     install = (
47         # Evaluate if ccnx binaries are already installed
48         " ( "
49             "  test -d ${EXP_HOME}/ccnx/bin "
50         " ) || ( "
51             "  mkdir -p ${EXP_HOME}/ccnx/bin && "
52             "  cp -r ${SOURCES}/ccnx ${EXP_HOME}"
53         " )"
54     )
55
56     env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
57
58     command = "ccndstart 2>&1 ; "
59     peers = map(lambda peer: "ccndc add ccnx:/ udp  %s" % peer, peers)
60     command += " ; ".join(peers) + " ; "
61     command += " ccnr 2>&1 "
62
63     app = ec.register_resource("LinuxApplication")
64     ec.set(app, "depends", depends)
65     ec.set(app, "sources", sources)
66     ec.set(app, "install", install)
67     ec.set(app, "build", build)
68     ec.set(app, "env", env)
69     ec.set(app, "command", command)
70
71     return app
72
73 def add_publish(ec, movie):
74     env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
75     command = "ccnseqwriter -r ccnx:/VIDEO"
76
77     app = ec.register_resource("LinuxApplication")
78     ec.set(app, "stdin", movie)
79     ec.set(app, "env", env)
80     ec.set(app, "command", command)
81
82     return app
83
84 def add_stream(ec):
85     env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
86     command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) 2>&1"
87
88     app = ec.register_resource("LinuxApplication")
89     ec.set(app, "depends", "vlc")
90     ec.set(app, "forwardX11", True)
91     ec.set(app, "env", env)
92     ec.set(app, "command", command)
93
94     return app
95
96 def get_options():
97     slicename = os.environ.get("PL_SLICE")
98
99     usage = "usage: %prog -s <pl-slice> -u <user-2> -m <movie> -l <exp-id>"
100
101     parser = OptionParser(usage=usage)
102     parser.add_option("-s", "--pl-slice", dest="pl_slice", 
103             help="PlanetLab slicename", default=slicename, type="str")
104     parser.add_option("-u", "--user-2", dest="user2", 
105             help="User for non PlanetLab machine", type="str")
106     parser.add_option("-m", "--movie", dest="movie", 
107             help="Stream movie", type="str")
108     parser.add_option("-l", "--exp-id", dest="exp_id", 
109             help="Label to identify experiment", type="str")
110
111     (options, args) = parser.parse_args()
112
113     if not options.movie:
114         parser.error("movie is a required argument")
115
116     return (options.pl_slice, options.user2, options.movie, options.exp_id)
117
118 if __name__ == '__main__':
119     ( pl_slice, user2, movie, exp_id ) = get_options()
120
121     # Search for available RMs
122     populate_factory()
123     
124     #host1 = 'nepi2.pl.sophia.inria.fr'
125     host1 = 'planetlab2.u-strasbg.fr'
126     host2 = 'roseval.pl.sophia.inria.fr'
127
128     ec = ExperimentController(exp_id = exp_id)
129
130     node1 = add_node(ec, host1, pl_slice)
131     
132     peers = [host2]
133     ccnd1 = add_ccnd(ec, "f12", peers)
134
135     ec.register_connection(ccnd1, node1)
136
137     pub = add_publish(ec, movie)
138     ec.register_connection(pub, node1)
139     # The movie can only be published after ccnd is running
140     ec.register_condition(pub, ResourceAction.START, 
141             ccnd1, ResourceState.STARTED)
142     
143     node2 = add_node(ec, host2, user2)
144     peers = [host1]
145     ccnd2 = add_ccnd(ec, "ubuntu", peers)
146     ec.register_connection(ccnd2, node2)
147      
148     stream = add_stream(ec)
149     ec.register_connection(stream, node2)
150     # The stream can only be retrieved after ccnd is running
151     ec.register_condition(stream, ResourceAction.START, 
152             ccnd2, ResourceState.STARTED)
153     # And also, the stream can only be retrieved after it was published
154     ec.register_condition(stream, ResourceAction.START, 
155             pub, ResourceState.STARTED)
156  
157     ec.deploy()
158
159     apps = [ccnd1, pub, ccnd2, stream]
160     ec.wait_finished(apps)
161
162     ec.shutdown()
163