2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Instructions to run this example:
22 # 1. First edit the script file where required (See ASSING messages)
24 # 2. Then, run the script:
27 # $ PYTHONPATH=$PYTHONPATHS:src python examples/linux/ccn/two_nodes_file_retrieval.py
30 from nepi.execution.ec import ExperimentController
34 ssh_key = ####### <<< ASSING the absolute path to the private SSH key to login into the remote host >>>
35 ssh_user = ####### <<< ASSING the SSH username >>>
37 results_dir = "/tmp/demo_CCN_results"
39 ## Create the experiment controller
40 ec = ExperimentController(exp_id = "demo_CCN", local_dir = results_dir)
43 node1 = ec.register_resource("LinuxNode")
44 # Set the hostname of the first node to use for the experiment
45 hostname1 = "peeramidion.irisa.fr" ##### <<< ASSIGN the hostname of a host you have SSSH access to >>>
46 ec.set(node1, "hostname", hostname1)
47 # username should be your SSH user
48 ec.set(node1, "username", ssh_user)
49 # Absolute path to the SSH private key
50 ec.set(node1, "identity", ssh_key)
51 # Clean all files, results, etc, from previous experiments wit the same exp_id
52 ec.set(node1, "cleanExperiment", True)
53 # Kill all running processes in the node before running the experiment
54 ec.set(node1, "cleanProcesses", True)
57 node2 = ec.register_resource("LinuxNode")
58 # Set the hostname of the first node to use for the experiment
59 hostname2 = "planetlab2.upc.es" ##### <<< ASSIGN the hostname of a host you have SSSH access to >>>
60 ec.set(node2, "hostname", hostname2)
61 # username should be your SSH user
62 ec.set(node2, "username", ssh_user)
63 # Absolute path to the SSH private key
64 ec.set(node2, "identity", ssh_key)
65 # Clean all files, results, etc, from previous experiments wit the same exp_id
66 ec.set(node2, "cleanExperiment", True)
67 # Kill all running processes in the node before running the experiment
68 ec.set(node2, "cleanProcesses", True)
70 ## Register a CCN daemon in node 1
71 ccnd1 = ec.register_resource("LinuxCCND")
72 # Set ccnd log level to 7
73 ec.set(ccnd1, "debug", 7)
74 ec.register_connection(ccnd1, node1)
76 ## Register a CCN daemon in node 2
77 ccnd2 = ec.register_resource("LinuxCCND")
78 # Set ccnd log level to 7
79 ec.set(ccnd2, "debug", 7)
80 ec.register_connection(ccnd2, node2)
82 ## Register a repository in node 1
83 ccnr1 = ec.register_resource("LinuxCCNR")
84 ec.register_connection(ccnr1, ccnd1)
86 ## Push the file into the repository
87 local_path_to_content = os.path.join(
88 os.path.dirname(os.path.realpath(__file__)),
90 "big_buck_bunny_240p_mpeg4_lq.ts")
92 # Register a FIB entry from node 1 to node 2
93 co = ec.register_resource("LinuxCCNContent")
94 ec.set(co, "contentName", "ccnx:/test/FILE1")
95 # NEPI will upload the specified file to the remote node and write it
96 # into the CCN repository
97 ec.set(co, "content", local_path_to_content)
98 ec.register_connection(co, ccnr1)
100 # Register a FIB entry from node 1 to node 2
101 entry1 = ec.register_resource("LinuxFIBEntry")
102 ec.set(entry1, "host", hostname2)
103 ec.register_connection(entry1, ccnd1)
105 # Register a FIB entry from node 2 to node 1
106 entry2 = ec.register_resource("LinuxFIBEntry")
107 ec.set(entry2, "host", hostname1)
108 ec.register_connection(entry2, ccnd2)
110 ## Retrieve the file stored in node 1 from node 2
111 command = "ccncat ccnx:/test/FILE1"
112 app = ec.register_resource("LinuxCCNApplication")
113 ec.set(app, "command", command)
114 ec.register_connection(app, ccnd2)
116 # Register a collector to automatically collect the ccnd logs
117 # to a local directory
118 col1 = ec.register_resource("Collector")
119 ec.set(col1, "traceName", "stderr")
120 ec.set(col1, "subDir", hostname1)
121 ec.register_connection(col1, ccnd1)
123 col2 = ec.register_resource("Collector")
124 ec.set(col2, "traceName", "stderr")
125 ec.set(col2, "subDir", hostname2)
126 ec.register_connection(col2, ccnd2)
128 ## Deploy all resources
131 # Wait until the ccncat is finished
132 ec.wait_finished([app])
134 ## CCND logs will be collected to the results_dir upon shutdown.
135 ## We can aldo get the content of the logs now:
136 #print "LOG2", ec.trace(ccnd1, "stderr")
137 #print "LOG 1", ec.trace(ccnd2, "stderr")