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