Changing ResourceManager naming for platform::ResourceName
[nepi.git] / examples / omf / testing / nitos_omf5_ping.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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
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.
15 #
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/>.
18 #
19 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
20 #         Julien Tribino <julien.tribino@inria.fr>
21       
22 # Topology
23 #
24 #
25 #  Testbed : Nitos
26 #
27 #     Node
28 #     omf.nitos.node0ZZ 
29 #     0
30 #     |
31 #     |
32 #     0
33 #     Node
34 #     omf.nitos.node0ZZ 
35 #     PING
36 #     
37 #   
38 #      - Experiment:
39 #        - t0 : Deployment
40 #        - t1 : Ping Start
41 #        - t2 (t1 + 10s) : Ping stop
42 #        - t3 (t2 + 2s) : Kill the application
43 #
44 #
45
46 from nepi.execution.ec import ExperimentController
47 from nepi.execution.resource import ResourceAction, ResourceState
48
49 from optparse import OptionParser
50 import os
51
52 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
53
54 parser = OptionParser(usage = usage)
55 parser.add_option("-x", "--nodex", dest="nodex", 
56         help="Nitos first reserved node "
57             "(e.g. hostname must be of form: omf.nitos.node0XX)", 
58         type="str")
59 parser.add_option("-z", "--nodez", dest="nodez", 
60         help="Nitos second reserved node "
61             "(e.g. hostname must be of form: omf.nitos.node0ZZ)", 
62         type="str")
63 parser.add_option("-c", "--channel", dest="channel", 
64         help="Nitos reserved channel",
65         type="str")
66 parser.add_option("-s", "--slice-name", dest="slicename", 
67         help="Nitos slice name", type="str")
68 (options, args) = parser.parse_args()
69
70 nodex = options.nodex
71 nodez = options.nodez
72 slicename = options.slicename
73 chan = options.channel
74
75 # Create the EC
76 ec = ExperimentController(exp_id="nitos_omf5_ping")
77
78 # Create and Configure the Nodes
79 node1 = ec.register_resource("omf::Node")
80 ec.set(node1, "hostname", nodex)
81 ec.set(node1, "xmppUser", slicename)
82 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
83 ec.set(node1, "xmppPort", "5222")
84 ec.set(node1, "xmppPassword", "1234")
85 ec.set(node1, "version", "5")
86
87 # Create and Configure the Interfaces
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.%s/24" % nodex[-2:]) 
94 ec.set(iface1, "version", "5")
95 ec.register_connection(node1, iface1)
96
97 # Create and Configure the Channel
98 channel = ec.register_resource("omf::Channel")
99 ec.set(channel, "channel", chan)
100 ec.set(channel, "xmppUser", slicename)
101 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
102 ec.set(channel, "xmppPort", "5222")
103 ec.set(channel, "xmppPassword", "1234")
104 ec.set(channel, "version", "5")
105 ec.register_connection(iface1, channel)
106
107 # Create and Configure the PING Application
108 app1 = ec.register_resource("omf::Application")
109 ec.set(app1, "appid", "Ping#1")
110 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodex[-2:])
111 ec.set(app1, "version", "5")
112 ec.register_connection(app1, node1)
113
114 app2 = ec.register_resource("omf::Application")
115 ec.set(app2, "appid", "Kill#1")
116 ec.set(app2, "command", "/usr/bin/killall ping")
117 ec.set(app2, "version", "5")
118 ec.register_connection(app2, node1)
119
120 # User Behaviour
121 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s")
122 ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s")
123 ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s")
124
125 # Deploy
126 ec.deploy()
127
128 ec.wait_finished([app1, app2])
129
130 print ec.trace(app1, "stdout")
131
132 # Stop Experiment
133 ec.shutdown()
134