2 from neco.execution.ec import ExperimentController, ECState
3 from neco.execution.resource import ResourceState, ResourceAction, \
6 from optparse import OptionParser, SUPPRESS_HELP
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)
19 def add_ccnd(ec, os_type, peers):
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 ")
29 sources = "http://www.ccnx.org/releases/ccnx-0.7.1.tar.gz"
32 # Evaluate if ccnx binaries are already installed
34 " test -d ${EXP_HOME}/ccnx/bin"
36 # If not, untar and build
38 " mkdir -p ${SOURCES}/ccnx && "
39 " tar xf ${SOURCES}/ccnx-0.7.1.tar.gz --strip-components=1 -C ${SOURCES}/ccnx "
41 "cd ${SOURCES}/ccnx && "
42 # Just execute and silence warnings...
43 "( ( ./configure && make ) 2>&1 )"
47 # Evaluate if ccnx binaries are already installed
49 " test -d ${EXP_HOME}/ccnx/bin "
51 " mkdir -p ${EXP_HOME}/ccnx/bin && "
52 " cp -r ${SOURCES}/ccnx ${EXP_HOME}"
56 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
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 "
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)
73 def add_publish(ec, movie):
74 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
75 command = "ccnseqwriter -r ccnx:/VIDEO"
77 app = ec.register_resource("LinuxApplication")
78 ec.set(app, "stdin", movie)
79 ec.set(app, "env", env)
80 ec.set(app, "command", command)
85 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
86 command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) 2>&1"
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)
97 slicename = os.environ.get("PL_SLICE")
99 usage = "usage: %prog -s <pl-slice> -u <user-2> -m <movie> -l <exp-id>"
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")
111 (options, args) = parser.parse_args()
113 if not options.movie:
114 parser.error("movie is a required argument")
116 return (options.pl_slice, options.user2, options.movie, options.exp_id)
118 if __name__ == '__main__':
119 ( pl_slice, user2, movie, exp_id ) = get_options()
121 # Search for available RMs
124 host1 = 'nepi2.pl.sophia.inria.fr'
125 host2 = 'roseval.pl.sophia.inria.fr'
127 ec = ExperimentController(exp_id = exp_id)
129 node1 = add_node(ec, host1, pl_slice)
132 ccnd1 = add_ccnd(ec, "f12", peers)
134 ec.register_connection(ccnd1, node1)
136 pub = add_publish(ec, movie)
137 ec.register_connection(pub, node1)
138 # The movie can only be published after ccnd is running
139 ec.register_condition(pub, ResourceAction.START,
140 ccnd1, ResourceState.STARTED)
142 node2 = add_node(ec, host2, user2)
144 ccnd2 = add_ccnd(ec, "ubuntu", peers)
145 ec.register_connection(ccnd2, node2)
147 stream = add_stream(ec)
148 ec.register_connection(stream, node2)
149 # The stream can only be retrieved after ccnd is running
150 ec.register_condition(stream, ResourceAction.START,
151 ccnd2, ResourceState.STARTED)
152 # And also, the stream can only be retrieved after it was published
153 ec.register_condition(stream, ResourceAction.START,
154 pub, ResourceState.STARTED)
158 apps = [ccnd1, pub, ccnd2, stream]
159 ec.wait_finished(apps)