X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=examples%2Fomf%2Fnitos_omf6_ping.py;h=6deaf18e405cdccc46c17ad647275d034114c006;hb=039fbd9629d7570d4c175a5448d24badcd0f3aba;hp=8626af6ae834e0ba830d092703801b7967480794;hpb=19a601bf2df7a723df749f478e052978a8552154;p=nepi.git diff --git a/examples/omf/nitos_omf6_ping.py b/examples/omf/nitos_omf6_ping.py index 8626af6a..6deaf18e 100644 --- a/examples/omf/nitos_omf6_ping.py +++ b/examples/omf/nitos_omf6_ping.py @@ -1,12 +1,13 @@ #!/usr/bin/env python + +############################################################################### # # NEPI, a framework to manage network experiments # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,6 +19,8 @@ # # Authors: Alina Quereilhac # Julien Tribino +# +############################################################################### # Topology # @@ -41,7 +44,8 @@ # - t2 (t1 + 10s) : Ping stop # - t3 (t2 + 2s) : Kill the application # -# + +from __future__ import print_function from nepi.execution.ec import ExperimentController from nepi.execution.resource import ResourceAction, ResourceState @@ -49,42 +53,52 @@ from nepi.execution.resource import ResourceAction, ResourceState from optparse import OptionParser import os -usage = ("usage: %prog -x -z -s -c ") +usage = ("usage: %prog -x -y -c -u -g ") parser = OptionParser(usage = usage) parser.add_option("-x", "--nodex", dest="nodex", help="Nitos first reserved node " - "(e.g. hostname must be of form: node0XX)", + "(e.g. hostname must be of form: omf.nitos.node0XX)", type="str") -parser.add_option("-z", "--nodez", dest="nodez", +parser.add_option("-y", "--nodey", dest="nodey", help="Nitos second reserved node " - "(e.g. hostname must be of form: node0ZZ)", + "(e.g. hostname must be of form: omf.nitos.node0YY)", type="str") parser.add_option("-c", "--channel", dest="channel", help="Nitos reserved channel", type="str") -parser.add_option("-s", "--slice-name", dest="slicename", - help="Nitos slice name", type="str") +parser.add_option("-g", "--gateway", dest="gateway", + help="Nitos gateway hostname", + type="str", default="nitlab.inf.uth.gr") +parser.add_option("-u", "--slicename", dest="slicename", + help="Nitos gateway username (slicename)", + type="str") + (options, args) = parser.parse_args() -nodex = options.nodex -nodez = options.nodez +if not options.channel or not options.nodex or \ + not options.nodey or not options.slicename: + parser.error("Missing argument channel, nodex, nodey, or slicename!") + +nodex = options.nodex.split(".")[-1] +nodey = options.nodey.split(".")[-1] slicename = options.slicename chan = options.channel +gateway = options.gateway # Create the EC ec = ExperimentController(exp_id="nitos_omf6_ping") # Create and Configure the Nodes -node1 = ec.register_resource("OMFNode") +node1 = ec.register_resource("omf::Node") ec.set(node1, "hostname", nodex) ec.set(node1, "xmppUser", slicename) -ec.set(node1, "xmppServer", "nitlab.inf.uth.gr") +ec.set(node1, "xmppServer", gateway) ec.set(node1, "xmppPort", "5222") ec.set(node1, "xmppPassword", "1234") # Create and Configure the Interfaces -iface1 = ec.register_resource("OMFWifiInterface") +iface1 = ec.register_resource("omf::WifiInterface") ec.set(iface1, "name", "wlan0") ec.set(iface1, "mode", "adhoc") ec.set(iface1, "hw_mode", "g") @@ -93,55 +107,50 @@ ec.set(iface1, "ip", "192.168.0.%s/24" % nodex[-2:]) ec.register_connection(node1, iface1) # Create and Configure the Nodes -node2 = ec.register_resource("OMFNode") -ec.set(node2, "hostname", nodez) +node2 = ec.register_resource("omf::Node") +ec.set(node2, "hostname", nodey) ec.set(node2, "xmppUser", slicename) -ec.set(node2, "xmppServer", "nitlab.inf.uth.gr") +ec.set(node2, "xmppServer", gateway) ec.set(node2, "xmppPort", "5222") ec.set(node2, "xmppPassword", "1234") # Create and Configure the Interfaces -iface2 = ec.register_resource("OMFWifiInterface") +iface2 = ec.register_resource("omf::WifiInterface") ec.set(iface2, "name", "wlan0") ec.set(iface2, "mode", "adhoc") ec.set(iface2, "hw_mode", "g") ec.set(iface2, "essid", "ping") -ec.set(iface2, "ip", "192.168.0.%s/24" % nodez[-2:]) +ec.set(iface2, "ip", "192.168.0.%s/24" % nodey[-2:]) ec.register_connection(node2, iface2) - # Create and Configure the Channel -channel = ec.register_resource("OMFChannel") +channel = ec.register_resource("omf::Channel") ec.set(channel, "channel", chan) ec.set(channel, "xmppUser", slicename) -ec.set(channel, "xmppServer", "nitlab.inf.uth.gr") +ec.set(channel, "xmppServer", gateway) ec.set(channel, "xmppPort", "5222") ec.set(channel, "xmppPassword", "1234") ec.register_connection(iface1, channel) ec.register_connection(iface2, channel) # Create and Configure the PING Application -app1 = ec.register_resource("OMFApplication") +app1 = ec.register_resource("omf::Application") ec.set(app1, "appid", "Ping#1") -ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodez[-2:]) +ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodey[-2:]) ec.register_connection(app1, node1) -app2 = ec.register_resource("OMFApplication") -ec.set(app2, "appid", "Kill#1") -ec.set(app2, "command", "/usr/bin/killall ping") -ec.register_connection(app2, node1) - -# User Behaviour -ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "10s") -ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "12s") -ec.register_condition(app2, ResourceAction.STOP, app2, ResourceState.STARTED , "1s") +## Make sure the ping stops after 30 seconds +ec.register_condition(app1, ResourceAction.STOP, app1, + ResourceState.STARTED , "30s") # Deploy ec.deploy() -ec.wait_finished([app1, app2]) +ec.wait_finished([app1]) -print ec.trace(app1, "stdout") +# Retrieve the output of the ping command +ping_output = ec.trace(app1, "stdout") +print("\n PING OUTPUT\n", ping_output, "\n") # Stop Experiment ec.shutdown()