Cleaning up examples folder
[nepi.git] / examples / linux / ccn_simple_transfer.py
similarity index 80%
rename from examples/linux/ccn/ccn_simple_transfer.py
rename to examples/linux/ccn_simple_transfer.py
index 19c7841..7e06207 100644 (file)
 #
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 #
-# Instructions to run this example:
-#
-# 1. First edit the script file where required (See ASSING messages)
-#
-# 2. Then, run the script:
+
+# Example of how to run this experiment (replace with your information):
 #
 # $ cd <path-to-nepi>
-# $ PYTHONPATH=$PYTHONPATHS:src python examples/linux/ccn/two_nodes_file_retrieval.py
+# python examples/linux/ccn_simple_transfer.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
+
+# CCN topology:
+#
+#                
+#                 
+#  content                  ccncat
+#  Linux host               Linux host
+#     0 ------- network -------- 1
 #
 
 from nepi.execution.ec import ExperimentController
@@ -54,6 +59,8 @@ ssh_key = options.ssh_key
 ## Create the experiment controller
 ec = ExperimentController(exp_id = "ccn_simple_transfer")
 
+##### CONFIGURING NODE 1
+
 ## Register node 1
 node1 = ec.register_resource("LinuxNode")
 # Set the hostname of the first node to use for the experiment
@@ -67,6 +74,33 @@ ec.set(node1, "cleanExperiment", True)
 # Kill all running processes in the node before running the experiment
 ec.set(node1, "cleanProcesses", True)
 
+## Register a CCN daemon in node 1
+ccnd1 = ec.register_resource("LinuxCCND")
+# Set ccnd log level to 7
+ec.set(ccnd1, "debug", 7)
+ec.register_connection(ccnd1, node1)
+
+## Register a repository in node 1
+ccnr1 = ec.register_resource("LinuxCCNR")
+ec.register_connection(ccnr1, ccnd1)
+
+## Push the file into the repository
+local_path_to_content = os.path.join(
+        os.path.dirname(os.path.realpath(__file__)),
+            "..", "big_buck_bunny_240p_mpeg4_lq.ts")
+
+content_name = "ccnx:/test/FILE"
+
+# Add a content to the repository
+co = ec.register_resource("LinuxCCNContent")
+ec.set(co, "contentName", content_name)
+# NEPI will upload the specified file to the remote node and write it
+# into the CCN repository
+ec.set(co, "content", local_path_to_content)
+ec.register_connection(co, ccnr1)
+
+##### CONFIGURING NODE 2
+
 ## Register node 2 
 node2 = ec.register_resource("LinuxNode")
 # Set the hostname of the first node to use for the experiment
@@ -80,35 +114,18 @@ ec.set(node2, "cleanExperiment", True)
 # Kill all running processes in the node before running the experiment
 ec.set(node2, "cleanProcesses", True)
 
-## Register a CCN daemon in node 1
-ccnd1 = ec.register_resource("LinuxCCND")
-# Set ccnd log level to 7
-ec.set(ccnd1, "debug", 7)
-ec.register_connection(ccnd1, node1)
-
 ## Register a CCN daemon in node 2
 ccnd2 = ec.register_resource("LinuxCCND")
 # Set ccnd log level to 7
 ec.set(ccnd2, "debug", 7)
 ec.register_connection(ccnd2, node2)
 
-## Register a repository in node 1
-ccnr1 = ec.register_resource("LinuxCCNR")
-ec.register_connection(ccnr1, ccnd1)
-
-## Push the file into the repository
-local_path_to_content = os.path.join(
-        os.path.dirname(os.path.realpath(__file__)),
-            "..", "..",
-            "big_buck_bunny_240p_mpeg4_lq.ts")
+## Retrieve the file stored in node 1 from node 2
+ccncat = ec.register_resource("LinuxCCNCat")
+ec.set(ccncat, "contentName", content_name)
+ec.register_connection(ccncat, ccnd2)
 
-# Register a FIB entry from node 1 to node 2
-co = ec.register_resource("LinuxCCNContent")
-ec.set(co, "contentName", "ccnx:/test/FILE1")
-# NEPI will upload the specified file to the remote node and write it
-# into the CCN repository
-ec.set(co, "content", local_path_to_content)
-ec.register_connection(co, ccnr1)
+##### INTERCONNECTING CCN NODES ...
 
 # Register a FIB entry from node 1 to node 2
 entry1 = ec.register_resource("LinuxFIBEntry")
@@ -120,30 +137,19 @@ entry2 = ec.register_resource("LinuxFIBEntry")
 ec.set(entry2, "host", hostname1)
 ec.register_connection(entry2, ccnd2)
 
-## Retrieve the file stored in node 1 from node 2
-command = "ccncat ccnx:/test/FILE1"
-app = ec.register_resource("LinuxCCNApplication")
-ec.set(app, "command", command)
-ec.register_connection(app, ccnd2)
-
-# Register a collector to automatically collect the ccnd logs
-# to a local directory
-col1 = ec.register_resource("Collector")
-ec.set(col1, "traceName", "stderr")
-ec.set(col1, "subDir", hostname1)
-ec.register_connection(col1, ccnd1)
-
-col2 = ec.register_resource("Collector")
-ec.set(col2, "traceName", "stderr")
-ec.set(col2, "subDir", hostname2)
-ec.register_connection(col2, ccnd2)
-
-print "Results stored at", ec.exp_dir
+##### STARTING THE EXPERIMENT
 
 ## Deploy all resources
 ec.deploy()
 
 # Wait until the ccncat is finished
-ec.wait_finished([app])
+ec.wait_finished([ccncat])
+
+stdout = ec.trace(ccncat, "stdout")
+f = open("video.ts", "w")
+f.write(stdout)
+f.close()
 
 ec.shutdown()
+
+print "Transfered FILE stored localy at video.ts"