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