from nepi.execution.resource import ResourceState, ResourceAction from nepi.execution.ec import ExperimentController import os # == Experiement controller =================================================== ec = ExperimentController(exp_id = "demo_CCN") # == Specify nodes ============================================================ # first node node1 = ec.register_resource("PlanetlabNode") ec.set(node1, "hostname", "planetlab2.upc.es") ec.set(node1, "username", "inria_nepi") #ec.set(node1, "cleanExperiment", True) #ec.set(node1, "cleanHome", True) ec.set(node1, "cleanProcesses", True) # second node node2 = ec.register_resource("PlanetlabNode") ec.set(node2, "hostname", "planetlab2.s3.kth.se") ec.set(node2, "username", "inria_nepi") #ec.set(node2, "cleanExperiment", True) #ec.set(node2, "cleanHome", True) ec.set(node2, "cleanProcesses", True) # == Each nodes must run CCND ================================================= ccnd1 = ec.register_resource("LinuxCCND") ec.register_connection(ccnd1, node1) ccnd2 = ec.register_resource("LinuxCCND") ec.register_connection(ccnd2, node2) ccnr1 = ec.register_resource("LinuxCCNR") ec.register_connection(ccnr1, ccnd1) # == Setup forwarding information ============================================= entry1 = ec.register_resource("LinuxFIBEntry") ec.set(entry1, "host", "") ec.register_connection(entry1, ccnd1) entry2 = ec.register_resource("LinuxFIBEntry") ec.set(entry2, "host", "planetlab2.upc.es") ec.register_connection(entry2, ccnd2) # == node one to provide a video ============================================== # the video is copied from NEPI's machine to the experiment nodes co = ec.register_resource("LinuxCCNContent") ec.set(co, "contentName", "ccnx:/test/VIDEO1") ec.set(co, "content", "/Users/dsaucez/Documents/inria/ICNRG_NEPI_DEMO/nepi/examples/big_buck_bunny_240p_mpeg4_lq.ts") ec.register_connection(co, ccnr1) # == node two to retrieve the video via CCN =================================== # for later use, let's cat the content of the video to STDOUT command = "ccnpeek ccnx:/test/VIDEO1; ccncat ccnx:/test/VIDEO1" app = ec.register_resource("LinuxCCNApplication") ec.set(app, "command", command) ec.register_connection(app, ccnd2) # == deploy the experiment, that might take a while =========================== ec.deploy() ec.wait_started([app]) print "experiment started" # == time for a PAUSE, view src/nepi/resources/linux/ccn/ccnd.py:280 ========== # == time for a PAUSE, view NEPI directories on node2 ========================= # == let's process the trace locally ========================================== from nepi.execution.trace import TraceAttr import subprocess # == remember that video bytes are cat'ed to "app"' stdout rvideo_path = ec.trace(app, "stdout", attr = TraceAttr.PATH) command = 'tail -f %s' % rvideo_path print command # == get the video bytes on the remote machine, and put the result in a pipe = proc1 = subprocess.Popen(['ssh', '-o', 'StrictHostKeyChecking=no', '-l', "inria_nepi", "planetlab2.s3.kth.se", command], stdout = subprocess.PIPE, stderr = subprocess.PIPE) # == start VLC locally and feed it with the output of the previous process ==== proc2 = subprocess.Popen(['/Applications/VLC.app/Contents/MacOS/vlc', '--ffmpeg-threads=1', '--sub-filter', 'marq', '--marq-marquee', '(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org', '--marq-position=8', '--no-video-title-show', '-'], stdin=proc1.stdout, # VLC's stdin is proc1 stdout stdout=subprocess.PIPE, stderr=subprocess.PIPE) # == and voila ================================================================ (stdout, stderr) = proc2.communicate() # == shutdown the experiement corretly ======================================== ec.shutdown()