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>
21 from nepi.execution.resource import ResourceState, ResourceAction
22 from nepi.execution.ec import ExperimentController
26 pl_user = ######### <<< ASSIGN the username used to login to the PlanetLab website >>>
27 pl_pass = ######## <<< ASSIGN the password used to login to the PlanetLab website >>>
28 pl_ssh_key = ####### ASSING the absolute path to the private SSH key used for Planetlab >>>
29 slicename = ####### <<< ASSING the PlanetLab slicename >>>
31 ## Create the experiment controller
32 ec = ExperimentController(exp_id = "demo_CCN")
35 node1 = ec.register_resource("PlanetlabNode")
36 # Configure NEPI to automatically find and allocate a node in France
37 # ec.set(node1, "country", "France")
38 # Else, if you want a node in particular set the hostname
39 ec.set(node1, "hostname", "peeramidion.irisa.fr")
40 # PlanetLab (website) account username
41 ec.set(node1, "pluser", pl_user)
42 # PlanetLab (website) account password
43 ec.set(node1, "plpassword", pl_pass)
44 # username should be your PlanetLab slice name
45 ec.set(node1, "username", slicename)
46 # Absolute path to the SSH private key for PlanetLab
47 ec.set(node1, "identity", pl_ssh_key)
48 # Clean all files, results, etc, from previous experiments wit the same
50 ec.set(node1, "cleanExperiment", True)
51 ec.set(node1, "cleanHome", True)
52 # Kill all running processes in the PlanetLab node before
53 # running the experiment
54 ec.set(node1, "cleanProcesses", True)
57 node2 = ec.register_resource("PlanetlabNode")
58 # Configure NEPI to automatically find and allocate a node in Spain
59 #ec.set(node2, "country", "Spain")
60 # Else, if you want a node in particular set the hostname
61 ec.set(node2, "hostname", "planetlab2.upc.es")
62 # PlanetLab (website) account username
63 ec.set(node2, "pluser", pl_user)
64 # PlanetLab (website) account password
65 ec.set(node2, "plpassword", pl_pass)
66 # username should be your PlanetLab slice name
67 ec.set(node2, "username", slicename)
68 # Absolute path to the SSH private key for PlanetLab
69 ec.set(node1, "identity", pl_ssh_key)
70 # Clean all files, results, etc, from previous experiments wit the same
72 ec.set(node2, "cleanExperiment", True)
73 ec.set(node2, "cleanHome", True)
74 # Kill all running processes in the PlanetLab node before
75 # running the experiment
76 ec.set(node2, "cleanProcesses", True)
78 ## Register a CCN daemon in node 1
79 ccnd1 = ec.register_resource("LinuxCCND")
80 # Set ccnd log level to 7
81 ec.set(ccnd1, "debug", 7)
82 ec.register_connection(ccnd1, node1)
84 ## Register a CCN daemon in node 2
85 ccnd2 = ec.register_resource("LinuxCCND")
86 # Set ccnd log level to 7
87 ec.set(ccnd2, "debug", 7)
88 ec.register_connection(ccnd2, node2)
90 ## Register a repository in node 1
91 ccnr1 = ec.register_resource("LinuxCCNR")
92 ec.register_connection(ccnr1, ccnd1)
94 ## Push the file into the repository
95 local_path_to_content = ######### <<< ASSIGN the absolute path to a local file >>>
97 co = ec.register_resource("LinuxCCNContent")
98 ec.set(co, "contentName", "ccnx:/test/FILE1")
99 # NEPI will upload the specified file to the remote node and write it
100 # into the CCN repository
101 ec.set(co, "content", local_path_to_content)
102 ec.register_connection(co, ccnr1)
104 ## Deploy all resources
107 ## Wait until node 1 and 2 are deployed
108 ec.wait_deployed([node1, node2])
110 ## Get the hostnames of the two PlanetLab nodes
111 hostname1 = ec.get(node1, "hostname")
112 print "hostname 1: ", hostname1
113 hostname2 = ec.get(node2, "hostname")
114 print "hostname 2: ", hostname2
116 entry1 = ec.register_resource("LinuxFIBEntry")
117 ec.set(entry1, "host", hostname2)
118 ec.register_connection(entry1, ccnd1)
120 entry2 = ec.register_resource("LinuxFIBEntry")
121 ec.set(entry2, "host", hostname1)
122 ec.register_connection(entry2, ccnd2)
124 ## Retrieve the file stored in node 1 from node 2
125 command = "ccncat ccnx:/test/FILE1"
126 app = ec.register_resource("LinuxCCNApplication")
127 ec.set(app, "command", command)
128 ec.register_connection(app, ccnd2)
130 # Register a collector to automatically collect the ccnd logs
131 # to a local directory
132 results_dir = "/tmp/demo_CCN_results"
133 col1 = ec.register_resource("Collector")
134 ec.set(col1, "traceName", "stderr")
135 ec.set(col1, "storeDir", results_dir)
136 ec.set(col1, "subDir", hostname1)
137 ec.register_connection(col1, ccnd1)
139 col2 = ec.register_resource("Collector")
140 ec.set(col2, "traceName", "stderr")
141 ec.set(col2, "storeDir", results_dir)
142 ec.set(col2, "subDir", hostname2)
143 ec.register_connection(col2, ccnd2)
145 ## Deploy the rest of the resources
146 ec.deploy(guids=[entry1, entry2, app, col1, col2])
148 # Wait until the ccncat is finished
149 ec.wait_finished([app])
151 ## CCND logs will be collected to the results_dir upon shutdown.
152 ## We can aldo get the content of the logs now:
153 #print "LOG2", ec.trace(ccnd1, "stderr")
154 #print "LOG 1", ec.trace(ccnd2, "stderr")