Fixing wrong license
[nepi.git] / examples / planetlab / testing / scalability.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License version 2 as
8 #    published by the Free Software Foundation;
9 #
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.
14 #
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/>.
17 #
18 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
19
20 from nepi.execution.ec import ExperimentController
21 from nepi.execution.resource import ResourceAction, ResourceState
22
23 import os
24 import time
25
26 def create_node(ec, username, pl_user, pl_password, critical=True, hostname=None, 
27                 country=None, operatingSystem=None, minBandwidth=None, minCpu=None):
28
29     node = ec.register_resource("planetlab::Node")
30
31     if username:
32         ec.set(node, "username", username)
33     if pl_user:
34         ec.set(node, "pluser", pl_user)
35     if pl_password:
36         ec.set(node, "plpassword", pl_password)
37
38     if hostname:
39         ec.set(node, "hostname", hostname)
40     if country:
41         ec.set(node, "country", country)
42     if operatingSystem:
43         ec.set(node, "operatingSystem", operatingSystem)
44     if minBandwidth:
45         ec.set(node, "minBandwidth", minBandwidth)
46     if minCpu:
47         ec.set(node, "minCpu", minCpu)
48     ec.set(node, "critical", critical)
49
50     #ec.set(node, "cleanExperiment", True)
51     #ec.set(node, "cleanProcesses", True)
52     
53     return node
54
55 exp_id = "scalability_exp"
56
57 # Create the entity Experiment Controller:
58 ec = ExperimentController(exp_id)
59
60 # Register the nodes resources:
61
62 # The username in this case is the slice name, the one to use for login in 
63 # via ssh into PlanetLab nodes. Replace with your own slice name.
64 username = os.environ.get("PL_SLICE")
65
66 # The pluser and plpassword are the ones used to login in the PlanetLab web 
67 # site. Replace with your own user and password account information.
68 pl_user = os.environ.get("PL_USER")
69 pl_password =  os.environ.get("PL_PASS")
70
71 # Choose the PlanetLab nodes for the experiment, in this example 5 nodes are
72 # used, and they are picked according to different criterias.
73
74 first_set_nodes = []
75 second_set_nodes = []
76 third_set_nodes = []
77
78 # First set of nodes will be defined by its hostname.
79 hostnames = ['planetlab2.utt.fr',
80 'planetlab-2.man.poznan.pl',
81 'planetlab-1.ing.unimo.it',
82 'gschembra3.diit.unict.it',
83 'planetlab2.ionio.gr',
84 'planetlab-1.imag.fr',
85 'node2pl.planet-lab.telecom-lille1.eu',
86 'planetlab1.xeno.cl.cam.ac.uk',
87 'planetlab3.hiit.fi',
88 'planetlab2.fri.uni-lj.si',
89 'planetlab1.informatik.uni-erlangen.de',
90 'node1pl.planet-lab.telecom-lille1.eu',
91 'planet2.servers.ua.pt',
92 'iraplab1.iralab.uni-karlsruhe.de',
93 'planetlab-node3.it-sudparis.eu',
94 'planet1.elte.hu',
95 'planet1.l3s.uni-hannover.de',
96 'planetlab1.fct.ualg.pt',
97 'host1.planetlab.informatik.tu-darmstadt.de',
98 'vicky.planetlab.ntua.gr',
99 'planetlab1.rutgers.edu']
100
101 for hostname in hostnames:
102     node = create_node(ec, username, pl_user, pl_password, hostname=hostname,
103             critical=False)
104     first_set_nodes.append(node)
105
106 # Second set of nodes will be U.S.A. nodes.
107 country = "United States"
108 for i in range(15):
109     node = create_node(ec, username, pl_user, pl_password, country=country,
110             critical=False)
111     second_set_nodes.append(node)
112
113 # Third set of nodes can be any node in Planetlab testbed.
114 for i in range(70):
115     node = create_node(ec, username, pl_user, pl_password, critical=False)
116     third_set_nodes.append(node)
117
118 # Register conditions
119
120 # The nodes that are completely identified by their hostnames have to be provisioned 
121 # before the rest of the nodes. This assures that no other resource will use the
122 # identified node even if the constraints matchs. 
123 # In this example the nodes from the first need to be provisioned before the ones in
124 # the second and third group. Using the same logic, is convenient that nodes from the
125 # second group are provisioned before nodes from the third group.
126
127 ec.register_condition(second_set_nodes, ResourceAction.DEPLOY, first_set_nodes, ResourceState.PROVISIONED)
128 ec.register_condition(third_set_nodes, ResourceAction.DEPLOY, second_set_nodes, ResourceState.PROVISIONED)
129  
130 # Deploy the experiment:
131 ec.deploy()
132
133 # Wait until all nodes are provisioned:
134 ec.wait_deployed(first_set_nodes)
135 ec.wait_deployed(second_set_nodes)
136 ec.wait_deployed(third_set_nodes)
137
138 # Do the experiment controller shutdown:
139 ec.shutdown()
140
141 # END