3 ###############################################################################
5 # NEPI, a framework to manage network experiments
6 # Copyright (C) 2013 INRIA
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.
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.
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/>.
21 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
22 # Julien Tribino <julien.tribino@inria.fr>
24 ###############################################################################
45 # - t2 (t1 + 10s) : Ping stop
46 # - t3 (t2 + 2s) : Kill the application
49 from nepi.execution.ec import ExperimentController
50 from nepi.execution.resource import ResourceAction, ResourceState
52 from optparse import OptionParser
55 usage = ("usage: %prog -x <nodex> -z <nodez> -s <slice-name> -c <channel>")
57 parser = OptionParser(usage = usage)
58 parser.add_option("-x", "--nodex", dest="nodex",
59 help="Nitos first reserved node "
60 "(e.g. hostname must be of form: node0XX)",
62 parser.add_option("-z", "--nodez", dest="nodez",
63 help="Nitos second reserved node "
64 "(e.g. hostname must be of form: node0ZZ)",
66 parser.add_option("-c", "--channel", dest="channel",
67 help="Nitos reserved channel",
69 parser.add_option("-s", "--slice-name", dest="slicename",
70 help="Nitos slice name", type="str")
71 (options, args) = parser.parse_args()
75 slicename = options.slicename
76 chan = options.channel
79 ec = ExperimentController(exp_id="nitos_omf6_ping")
81 # Create and Configure the Nodes
82 node1 = ec.register_resource("omf::Node")
83 ec.set(node1, "hostname", nodex)
84 ec.set(node1, "xmppUser", slicename)
85 ec.set(node1, "xmppServer", "nitlab.inf.uth.gr")
86 ec.set(node1, "xmppPort", "5222")
87 ec.set(node1, "xmppPassword", "1234")
89 # Create and Configure the Interfaces
90 iface1 = ec.register_resource("omf::WifiInterface")
91 ec.set(iface1, "name", "wlan0")
92 ec.set(iface1, "mode", "adhoc")
93 ec.set(iface1, "hw_mode", "g")
94 ec.set(iface1, "essid", "ping")
95 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
96 ec.register_connection(node1, iface1)
98 # Create and Configure the Nodes
99 node2 = ec.register_resource("omf::Node")
100 ec.set(node2, "hostname", nodez)
101 ec.set(node2, "xmppUser", slicename)
102 ec.set(node2, "xmppServer", "nitlab.inf.uth.gr")
103 ec.set(node2, "xmppPort", "5222")
104 ec.set(node2, "xmppPassword", "1234")
106 # Create and Configure the Interfaces
107 iface2 = ec.register_resource("omf::WifiInterface")
108 ec.set(iface2, "name", "wlan0")
109 ec.set(iface2, "mode", "adhoc")
110 ec.set(iface2, "hw_mode", "g")
111 ec.set(iface2, "essid", "ping")
112 ec.set(iface2, "ip", "192.168.0.%s/24" % nodez[-2:])
113 ec.register_connection(node2, iface2)
115 # Create and Configure the Channel
116 channel = ec.register_resource("omf::Channel")
117 ec.set(channel, "channel", chan)
118 ec.set(channel, "xmppUser", slicename)
119 ec.set(channel, "xmppServer", "nitlab.inf.uth.gr")
120 ec.set(channel, "xmppPort", "5222")
121 ec.set(channel, "xmppPassword", "1234")
122 ec.register_connection(iface1, channel)
123 ec.register_connection(iface2, channel)
125 # Create and Configure the PING Application
126 app1 = ec.register_resource("omf::Application")
127 ec.set(app1, "appid", "Ping#1")
128 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodez[-2:])
129 ec.register_connection(app1, node1)
131 ## Make sure the ping stops after 30 seconds
132 ec.register_condition(app1, ResourceAction.STOP, app1,
133 ResourceState.STARTED , "30s")
138 ec.wait_finished([app1])
140 # Retrieve the output of the ping command
141 ping_output = ec.trace(app1, "stdout")
142 print "\n PING OUTPUT\n", ping_output, "\n"