OMF examples
[nepi.git] / examples / omf / iminds_omf6_ping.py
1 #!/usr/bin/env python
2
3 ###############################################################################
4 #
5 #    NEPI, a framework to manage network experiments
6 #    Copyright (C) 2013 INRIA
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
22 #         Julien Tribino <julien.tribino@inria.fr>
23 #
24 ###############################################################################
25       
26 # Topology
27 #
28 #
29 #  Testbed : iMinds
30 #
31 #     Node
32 #     node0ZZ 
33 #     0
34 #     |
35 #     |
36 #     0
37 #     Node
38 #     node0ZZ 
39 #     PING
40 #   
41 #      - Experiment:
42 #        - t0 : Deployment
43 #        - t1 : Ping Start
44 #        - t2 (t1 + 10s) : Ping stop
45 #        - t3 (t2 + 2s) : Kill the application
46 #
47
48 from nepi.execution.resource import ResourceAction, ResourceState
49 from nepi.execution.ec import ExperimentController
50
51 from optparse import OptionParser
52 import os
53
54 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
55
56 parser = OptionParser(usage = usage)
57 parser.add_option("-x", "--nodex", dest="nodex", 
58         help="w-iLab.t first reserved node "
59             "(must be of form:  "
60             " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
61             " all letters in lowercase )", 
62         type="str")
63 parser.add_option("-z", "--nodez", dest="nodez", 
64         help="w-iLab.t first reserved node "
65              "(must be of form:  "
66             " nodex.<experiment_id>.<project_id>.wilab2.ilabt.iminds.be"
67             " all letters in lowercase )", 
68         type="str")
69 parser.add_option("-s", "--slice-name", dest="slicename", 
70         help="Nitos slice name", type="str")
71 (options, args) = parser.parse_args()
72
73 nodex = options.nodex
74 nodez = options.nodez
75 slicename = options.slicename
76
77 # Create the EC
78 ec = ExperimentController(exp_id="iminds_omf6_ping")
79
80 # Create and Configure the Nodes
81
82 node1 = ec.register_resource("OMFNode")
83 ec.set(node1, "hostname", nodex)
84 ec.set(node1, "xmppUser", slicename)
85 ec.set(node1, "xmppServer", "xmpp.ilabt.iminds.be")
86 ec.set(node1, "xmppPort", "5222")
87 ec.set(node1, "xmppPassword", "1234")
88
89 iface1 = ec.register_resource("OMFWifiInterface")
90 ec.set(iface1, "name", "wlan0")
91 ec.set(iface1, "mode", "adhoc")
92 ec.set(iface1, "hw_mode", "g")
93 ec.set(iface1, "essid", "ping")
94 ec.set(iface1, "ip", "192.168.0.1/24")
95 ec.register_connection(iface1, node1)
96
97 node2 = ec.register_resource("OMFNode")
98 ec.set(node2, "hostname", nodez)
99 ec.set(node2, "xmppUser", slicename)
100 ec.set(node2, "xmppServer", "xmpp.ilabt.iminds.be")
101 ec.set(node2, "xmppPort", "5222")
102 ec.set(node2, "xmppPassword", "1234")
103
104 iface2 = ec.register_resource("OMFWifiInterface")
105 ec.set(iface2, "name", "wlan0")
106 ec.set(iface2, "mode", "adhoc")
107 ec.set(iface2, "hw_mode", "g")
108 ec.set(iface2, "essid", "ping")
109 ec.set(iface2, "ip", "192.168.0.2/24")
110 ec.register_connection(iface2, node2)
111
112 channel = ec.register_resource("OMFChannel")
113 ec.set(channel, "channel", "6")
114 ec.register_connection(iface1, channel)
115 ec.register_connection(iface2, channel)
116
117 # Create and Configure the Application
118 app1 = ec.register_resource("OMFApplication")
119 ec.set(app1, "command", "ping -c3 192.168.0.2") 
120 ec.register_connection(app1, node1)
121
122 ## Make sure the ping stops after 30 seconds
123 ec.register_condition(app1, ResourceAction.STOP, app1, 
124         ResourceState.STARTED , "30s")
125
126 # Deploy
127 ec.deploy()
128
129 # Wait until the VLC client is finished
130 ec.wait_finished([app1])
131
132 # Retrieve the output of the ping command
133 ping_output = ec.trace(app1, "stdout")
134 print "\n PING OUTPUT\n", ping_output, "\n"
135
136 # Stop Experiment
137 ec.shutdown()
138