3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 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: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceAction, ResourceState
26 def create_node(ec, username, pl_user, pl_password, hostname=None, country=None,
27 operatingSystem=None, minBandwidth=None, minCpu=None):
29 node = ec.register_resource("PlanetlabNode")
32 ec.set(node, "username", username)
34 ec.set(node, "pluser", pl_user)
36 ec.set(node, "plpassword", pl_password)
39 ec.set(node, "hostname", hostname)
41 ec.set(node, "country", country)
43 ec.set(node, "operatingSystem", operatingSystem)
45 ec.set(node, "minBandwidth", minBandwidth)
47 ec.set(node, "minCpu", minCpu)
49 ec.set(node, "cleanHome", True)
50 ec.set(node, "cleanProcesses", True)
54 def add_app(ec, command, node, sudo=None, video=None, depends=None, forward_x11=None, \
56 app = ec.register_resource("LinuxApplication")
58 ec.set(app, "sudo", sudo)
60 ec.set(app, "sources", video)
61 if depends is not None:
62 ec.set(app, "depends", depends)
63 if forward_x11 is not None:
64 ec.set(app, "forwardX11", forward_x11)
66 ec.set(app, "env", env)
67 ec.set(app, "command", command)
69 ec.register_connection(app, node)
75 # Create the entity Experiment Controller:
76 ec = ExperimentController(exp_id)
78 # Register the nodes resources:
80 # The username in this case is the slice name, the one to use for login in
81 # via ssh into PlanetLab nodes. Replace with your own slice name.
82 username = "inria_sfatest"
84 # The pluser and plpassword are the ones used to login in the PlanetLab web
85 # site. Replace with your own user and password account information.
86 pl_user = "lucia.guevgeozian_odizzio@inria.fr"
87 pl_password = os.environ.get("PL_PASS")
89 # Choose the PlanetLab nodes for the experiment, in this example 5 nodes are
90 # used, and they are picked according to different criterias.
92 # First node will be the one defined by its hostname.
93 hostname = "planetlab2.utt.fr"
94 node1 = create_node(ec, username, pl_user, pl_password, hostname=hostname)
96 # Second node will be any node in France.
98 node2 = create_node(ec, username, pl_user, pl_password, country=country)
100 # Third node will be a node in France that has Fedora 14 installed.
101 operatingSystem = "f14"
102 node3 = create_node(ec, username, pl_user, pl_password, country=country,
103 operatingSystem=operatingSystem)
105 # Forth node will have at least 50% of CPU available
107 node4 = create_node(ec, username, pl_user, pl_password, minCpu=minCpu)
109 # Fifth node can be any node, constrains are not important.
110 node5 = create_node(ec, username, pl_user, pl_password)
112 # Register the applications to run in the nodes, in this case just ping to the
114 apps_per_node = dict()
116 for node in [node2, node3, node4, node5]:
117 command = "ping -c5 %s > ping%s.txt" % (hostname, node)
118 app = add_app(ec, command, node)
119 apps_per_node[node] = app
122 # Register conditions
124 # The nodes that are completely identified by their hostnames have to be provisioned
125 # before the rest of the nodes. This assures that no other resource will use the
126 # identified node even if the constraints matchs.
127 # In this example node2, node3, node4 and node5, are deployed after node1 is
128 # provisioned. node1 must be the node planetlab2.utt.fr, meanwhile node2, node3,
129 # node4 and node5 just need to fulfill certain constraints.
130 # Applications are always deployed after nodes, so no need to register conditions
131 # for the apps in this example.
133 ec.register_condition(node2, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
134 ec.register_condition(node3, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
135 ec.register_condition(node4, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
136 ec.register_condition(node5, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
138 # Deploy the experiment:
141 # Wait until the applications are finish to retrive the traces:
142 ec.wait_finished(apps)
145 for node, app in apps_per_node.iteritems():
146 ping_string = "ping%s.txt" % node
147 trace = ec.trace(app, ping_string)
150 # Choose a directory to store the traces locally, change to a convenient path for you:
151 directory = "examples/planetlab/"
152 for node, trace in traces.iteritems():
153 trace_file = directory + "ping%s.txt" % node
154 f = open(trace_file, "w")
158 # Do the experiment controller shutdown: