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
50 from nepi.execution.ec import ExperimentController
51 from nepi.execution.resource import ResourceAction, ResourceState
53 from optparse import OptionParser
56 usage = ("usage: %prog -x <nodex> -y <nodey> -c <channel> -u <slicename> -g <nitos-gateway>")
58 parser = OptionParser(usage = usage)
59 parser.add_option("-x", "--nodex", dest="nodex",
60 help="Nitos first reserved node "
61 "(e.g. hostname must be of form: omf.nitos.node0XX)",
63 parser.add_option("-y", "--nodey", dest="nodey",
64 help="Nitos second reserved node "
65 "(e.g. hostname must be of form: omf.nitos.node0YY)",
67 parser.add_option("-c", "--channel", dest="channel",
68 help="Nitos reserved channel",
70 parser.add_option("-g", "--gateway", dest="gateway",
71 help="Nitos gateway hostname",
72 type="str", default="nitlab.inf.uth.gr")
73 parser.add_option("-u", "--slicename", dest="slicename",
74 help="Nitos gateway username (slicename)",
77 (options, args) = parser.parse_args()
79 if not options.channel or not options.nodex or \
80 not options.nodey or not options.slicename:
81 parser.error("Missing argument channel, nodex, nodey, or slicename!")
83 nodex = options.nodex.split(".")[-1]
84 nodey = options.nodey.split(".")[-1]
85 slicename = options.slicename
86 chan = options.channel
87 gateway = options.gateway
90 ec = ExperimentController(exp_id="nitos_omf6_ping")
92 # Create and Configure the Nodes
93 node1 = ec.register_resource("omf::Node")
94 ec.set(node1, "hostname", nodex)
95 ec.set(node1, "xmppUser", slicename)
96 ec.set(node1, "xmppServer", gateway)
97 ec.set(node1, "xmppPort", "5222")
98 ec.set(node1, "xmppPassword", "1234")
100 # Create and Configure the Interfaces
101 iface1 = ec.register_resource("omf::WifiInterface")
102 ec.set(iface1, "name", "wlan0")
103 ec.set(iface1, "mode", "adhoc")
104 ec.set(iface1, "hw_mode", "g")
105 ec.set(iface1, "essid", "ping")
106 ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:])
107 ec.register_connection(node1, iface1)
109 # Create and Configure the Nodes
110 node2 = ec.register_resource("omf::Node")
111 ec.set(node2, "hostname", nodey)
112 ec.set(node2, "xmppUser", slicename)
113 ec.set(node2, "xmppServer", gateway)
114 ec.set(node2, "xmppPort", "5222")
115 ec.set(node2, "xmppPassword", "1234")
117 # Create and Configure the Interfaces
118 iface2 = ec.register_resource("omf::WifiInterface")
119 ec.set(iface2, "name", "wlan0")
120 ec.set(iface2, "mode", "adhoc")
121 ec.set(iface2, "hw_mode", "g")
122 ec.set(iface2, "essid", "ping")
123 ec.set(iface2, "ip", "192.168.0.%s/24" % nodey[-2:])
124 ec.register_connection(node2, iface2)
126 # Create and Configure the Channel
127 channel = ec.register_resource("omf::Channel")
128 ec.set(channel, "channel", chan)
129 ec.set(channel, "xmppUser", slicename)
130 ec.set(channel, "xmppServer", gateway)
131 ec.set(channel, "xmppPort", "5222")
132 ec.set(channel, "xmppPassword", "1234")
133 ec.register_connection(iface1, channel)
134 ec.register_connection(iface2, channel)
136 # Create and Configure the PING Application
137 app1 = ec.register_resource("omf::Application")
138 ec.set(app1, "appid", "Ping#1")
139 ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodey[-2:])
140 ec.register_connection(app1, node1)
142 ## Make sure the ping stops after 30 seconds
143 ec.register_condition(app1, ResourceAction.STOP, app1,
144 ResourceState.STARTED , "30s")
149 ec.wait_finished([app1])
151 # Retrieve the output of the ping command
152 ping_output = ec.trace(app1, "stdout")
153 print("\n PING OUTPUT\n", ping_output, "\n")