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 # BASH command -> ' ccndstart 2>&1 ; ccndc add ccnx:/ udp host ; ccnr 2>&1 '
59 command = "ccndstart 2>&1 ; "
60 peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers)
61 command += " ; ".join(peers) + " ; "
62 command += " ccnr 2>&1 "
64 app = ec.register_resource("LinuxApplication")
65 ec.set(app, "depends", depends)
66 ec.set(app, "sources", sources)
67 ec.set(app, "install", install)
68 ec.set(app, "build", build)
69 ec.set(app, "env", env)
70 ec.set(app, "command", command)
74 def add_publish(ec, movie):
75 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
76 command = "ccnseqwriter -r ccnx:/VIDEO"
78 app = ec.register_resource("LinuxApplication")
79 ec.set(app, "stdin", movie)
80 ec.set(app, "env", env)
81 ec.set(app, "command", command)
86 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin"
87 command = "sudo -S dbus-uuidgen --ensure ; ( ccncat ccnx:/VIDEO | vlc - ) 2>&1"
89 app = ec.register_resource("LinuxApplication")
90 ec.set(app, "depends", "vlc")
91 ec.set(app, "forwardX11", True)
92 ec.set(app, "env", env)
93 ec.set(app, "command", command)
98 slicename = os.environ.get("PL_SLICE")
100 usage = "usage: %prog -s <pl-slice> -u <user-2> -m <movie> -l <exp-id>"
102 parser = OptionParser(usage=usage)
103 parser.add_option("-s", "--pl-slice", dest="pl_slice",
104 help="PlanetLab slicename", default=slicename, type="str")
105 parser.add_option("-u", "--user-2", dest="user2",
106 help="User for non PlanetLab machine", type="str")
107 parser.add_option("-m", "--movie", dest="movie",
108 help="Stream movie", type="str")
109 parser.add_option("-l", "--exp-id", dest="exp_id",
110 help="Label to identify experiment", type="str")
112 (options, args) = parser.parse_args()
114 if not options.movie:
115 parser.error("movie is a required argument")
117 return (options.pl_slice, options.user2, options.movie, options.exp_id)
119 if __name__ == '__main__':
120 ( pl_slice, user2, movie, exp_id ) = get_options()
122 # Search for available RMs
125 #host1 = 'nepi2.pl.sophia.inria.fr'
126 host1 = 'planetlab2.u-strasbg.fr'
127 host2 = 'roseval.pl.sophia.inria.fr'
129 ec = ExperimentController(exp_id = exp_id)
131 node1 = add_node(ec, host1, pl_slice)
134 ccnd1 = add_ccnd(ec, "f12", peers)
136 ec.register_connection(ccnd1, node1)
138 pub = add_publish(ec, movie)
139 ec.register_connection(pub, node1)
140 # The movie can only be published after ccnd is running
141 ec.register_condition(pub, ResourceAction.START,
142 ccnd1, ResourceState.STARTED)
144 node2 = add_node(ec, host2, user2)
146 ccnd2 = add_ccnd(ec, "ubuntu", peers)
147 ec.register_connection(ccnd2, node2)
149 stream = add_stream(ec)
150 ec.register_connection(stream, node2)
151 # The stream can only be retrieved after ccnd is running
152 ec.register_condition(stream, ResourceAction.START,
153 ccnd2, ResourceState.STARTED)
154 # And also, the stream can only be retrieved after it was published
155 ec.register_condition(stream, ResourceAction.START,
156 pub, ResourceState.STARTED)
160 apps = [ccnd1, pub, ccnd2, stream]
161 ec.wait_finished(apps)