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 pl_user = ######### <<< ASSIGN the username used to login to the PlanetLab website >>>
35 pl_pass = ######## <<< ASSIGN the password used to login to the PlanetLab website >>>
36 pl_ssh_key = ####### <<< ASSING the absolute path to the private SSH key used for Planetlab >>>
37 slicename = ####### <<< ASSING the PlanetLab slicename >>>
39 ## Create the experiment controller
40 ec = ExperimentController(exp_id = "demo_CCN")
43 node1 = ec.register_resource("PlanetlabNode")
44 # Configure NEPI to automatically find and allocate a node in France
45 # ec.set(node1, "country", "France")
46 # Else, if you want a node in particular set the hostname
47 ec.set(node1, "hostname", "peeramidion.irisa.fr")
48 # PlanetLab (website) account username
49 ec.set(node1, "pluser", pl_user)
50 # PlanetLab (website) account password
51 ec.set(node1, "plpassword", pl_pass)
52 # username should be your PlanetLab slice name
53 ec.set(node1, "username", slicename)
54 # Absolute path to the SSH private key for PlanetLab
55 ec.set(node1, "identity", pl_ssh_key)
56 # Clean all files, results, etc, from previous experiments wit the same exp_id
57 ec.set(node1, "cleanExperiment", True)
58 # Kill all running processes in the PlanetLab node before running the experiment
59 ec.set(node1, "cleanProcesses", True)
62 node2 = ec.register_resource("PlanetlabNode")
63 # Configure NEPI to automatically find and allocate a node in Spain
64 #ec.set(node2, "country", "Spain")
65 # Else, if you want a node in particular set the hostname
66 ec.set(node2, "hostname", "planetlab2.upc.es")
67 # PlanetLab (website) account username
68 ec.set(node2, "pluser", pl_user)
69 # PlanetLab (website) account password
70 ec.set(node2, "plpassword", pl_pass)
71 # username should be your PlanetLab slice name
72 ec.set(node2, "username", slicename)
73 # Absolute path to the SSH private key for PlanetLab
74 ec.set(node2, "identity", pl_ssh_key)
75 # Clean all files, results, etc, from previous experiments wit the same exp_id
76 ec.set(node2, "cleanExperiment", True)
77 # Kill all running processes in the PlanetLab node before running the experiment
78 ec.set(node2, "cleanProcesses", True)
80 ## Register a CCN daemon in node 1
81 ccnd1 = ec.register_resource("LinuxCCND")
82 # Set ccnd log level to 7
83 ec.set(ccnd1, "debug", 7)
84 ec.register_connection(ccnd1, node1)
86 ## Register a CCN daemon in node 2
87 ccnd2 = ec.register_resource("LinuxCCND")
88 # Set ccnd log level to 7
89 ec.set(ccnd2, "debug", 7)
90 ec.register_connection(ccnd2, node2)
92 ## Register a repository in node 1
93 ccnr1 = ec.register_resource("LinuxCCNR")
94 ec.register_connection(ccnr1, ccnd1)
96 ## Push the file into the repository
97 local_path_to_content = os.path.join(
98 os.path.dirname(os.path.realpath(__file__)),
100 "big_buck_bunny_240p_mpeg4_lq.ts")
102 co = ec.register_resource("LinuxCCNContent")
103 ec.set(co, "contentName", "ccnx:/test/FILE1")
104 # NEPI will upload the specified file to the remote node and write it
105 # into the CCN repository
106 ec.set(co, "content", local_path_to_content)
107 ec.register_connection(co, ccnr1)
109 ## Deploy all resources
112 ## Wait until node 1 and 2 are deployed, so we can retrieve the hostnames
113 ## of the nodes automatically allocated in planetlab
114 ec.wait_deployed([node1, node2])
116 ## Get the hostnames of the two PlanetLab nodes
117 hostname1 = ec.get(node1, "hostname")
118 print "hostname 1: ", hostname1
119 hostname2 = ec.get(node2, "hostname")
120 print "hostname 2: ", hostname2
122 # Register a FIB entry from node 1 to node 2
123 entry1 = ec.register_resource("LinuxFIBEntry")
124 ec.set(entry1, "host", hostname2)
125 ec.register_connection(entry1, ccnd1)
127 # Register a FIB entry from node 1 to node 2
128 entry2 = ec.register_resource("LinuxFIBEntry")
129 ec.set(entry2, "host", hostname1)
130 ec.register_connection(entry2, ccnd2)
132 ## Retrieve the file stored in node 1 from node 2
133 command = "ccncat ccnx:/test/FILE1"
134 app = ec.register_resource("LinuxCCNApplication")
135 ec.set(app, "command", command)
136 ec.register_connection(app, ccnd2)
138 # Register a collector to automatically collect the ccnd logs
139 # to a local directory
140 results_dir = "/tmp/demo_CCN_results"
141 col1 = ec.register_resource("Collector")
142 ec.set(col1, "traceName", "stderr")
143 ec.set(col1, "storeDir", results_dir)
144 ec.set(col1, "subDir", hostname1)
145 ec.register_connection(col1, ccnd1)
147 col2 = ec.register_resource("Collector")
148 ec.set(col2, "traceName", "stderr")
149 ec.set(col2, "storeDir", results_dir)
150 ec.set(col2, "subDir", hostname2)
151 ec.register_connection(col2, ccnd2)
153 ## Deploy the rest of the resources
154 ec.deploy(guids=[entry1, entry2, app, col1, col2])
156 # Wait until the ccncat is finished
157 ec.wait_finished([app])
159 ## CCND logs will be collected to the results_dir upon shutdown.
160 ## We can aldo get the content of the logs now:
161 #print "LOG2", ec.trace(ccnd1, "stderr")
162 #print "LOG 1", ec.trace(ccnd2, "stderr")