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 version 2 as
10 # published by the Free Software Foundation;
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.
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/>.
20 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # Julien Tribino <julien.tribino@inria.fr>
23 ###############################################################################
44 # - t2 (t1 + 10s) : Ping stop
45 # - t3 (t2 + 2s) : Kill the application
48 from nepi.execution.ec import ExperimentController
49 from nepi.execution.resource import ResourceAction, ResourceState
51 from optparse import OptionParser
54 usage = ("usage: %prog -x <nodex> -y <nodey> -c <channel> -u <slicename> -g <nitos-gateway>")
56 parser = OptionParser(usage = usage)
57 parser.add_option("-x", "--nodex", dest="nodex",
58 help="Nitos first reserved node "
59 "(e.g. hostname must be of form: omf.nitos.node0XX)",
61 parser.add_option("-y", "--nodey", dest="nodey",
62 help="Nitos second reserved node "
63 "(e.g. hostname must be of form: omf.nitos.node0YY)",
65 parser.add_option("-c", "--channel", dest="channel",
66 help="Nitos reserved channel",
68 parser.add_option("-g", "--gateway", dest="gateway",
69 help="Nitos gateway hostname",
70 type="str", default="nitlab.inf.uth.gr")
71 parser.add_option("-u", "--slicename", dest="slicename",
72 help="Nitos gateway username (slicename)",
75 (options, args) = parser.parse_args()
77 if not options.channel or not options.nodex or \
78 not options.nodey or not options.slicename:
79 parser.error("Missing argument channel, nodex, nodey, or slicename!")
81 nodex = options.nodex.split(".")[-1]
82 nodey = options.nodey.split(".")[-1]
83 slicename = options.slicename
84 chan = options.channel
85 gateway = options.gateway
88 ec = ExperimentController(exp_id="nitos_omf6_ping")
90 # Create and Configure the Nodes
91 node1 = ec.register_resource("omf::Node")
92 ec.set(node1, "hostname", nodex)
93 ec.set(node1, "xmppUser", slicename)
94 ec.set(node1, "xmppServer", gateway)
95 ec.set(node1, "xmppPort", "5222")
96 ec.set(node1, "xmppPassword", "1234")
98 # Create and Configure the Interfaces
99 iface1 = ec.register_resource("omf::WifiInterface")
100 ec.set(iface1, "name", "wlan0")
101 ec.set(iface1, "mode", "adhoc")
102 ec.set(iface1, "hw_mode", "g")
103 ec.set(iface1, "essid", "ping")
104 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
105 ec.register_connection(node1, iface1)
107 # Create and Configure the Nodes
108 node2 = ec.register_resource("omf::Node")
109 ec.set(node2, "hostname", nodey)
110 ec.set(node2, "xmppUser", slicename)
111 ec.set(node2, "xmppServer", gateway)
112 ec.set(node2, "xmppPort", "5222")
113 ec.set(node2, "xmppPassword", "1234")
115 # Create and Configure the Interfaces
116 iface2 = ec.register_resource("omf::WifiInterface")
117 ec.set(iface2, "name", "wlan0")
118 ec.set(iface2, "mode", "adhoc")
119 ec.set(iface2, "hw_mode", "g")
120 ec.set(iface2, "essid", "ping")
121 ec.set(iface2, "ip", "192.168.0.%s/24" % nodey[-2:])
122 ec.register_connection(node2, iface2)
124 # Create and Configure the Channel
125 channel = ec.register_resource("omf::Channel")
126 ec.set(channel, "channel", chan)
127 ec.set(channel, "xmppUser", slicename)
128 ec.set(channel, "xmppServer", gateway)
129 ec.set(channel, "xmppPort", "5222")
130 ec.set(channel, "xmppPassword", "1234")
131 ec.register_connection(iface1, channel)
132 ec.register_connection(iface2, channel)
134 # Create and Configure the PING Application
135 app1 = ec.register_resource("omf::Application")
136 ec.set(app1, "appid", "Ping#1")
137 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodey[-2:])
138 ec.register_connection(app1, node1)
140 ## Make sure the ping stops after 30 seconds
141 ec.register_condition(app1, ResourceAction.STOP, app1,
142 ResourceState.STARTED , "30s")
147 ec.wait_finished([app1])
149 # Retrieve the output of the ping command
150 ping_output = ec.trace(app1, "stdout")
151 print "\n PING OUTPUT\n", ping_output, "\n"