#!/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 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 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Authors: Alina Quereilhac # Julien Tribino # ############################################################################### # Topology # # # Testbed : Nitos # # Node # node0ZZ # 0 # | # | # 0 # Node # node0ZZ # PING # # # - Experiment: # - t0 : Deployment # - t1 : Ping Start # - 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 from optparse import OptionParser import os 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: omf.nitos.node0XX)", type="str") parser.add_option("-y", "--nodey", dest="nodey", help="Nitos second reserved node " "(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("-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() 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("omf::Node") ec.set(node1, "hostname", nodex) ec.set(node1, "xmppUser", slicename) ec.set(node1, "xmppServer", gateway) ec.set(node1, "xmppPort", "5222") ec.set(node1, "xmppPassword", "1234") # Create and Configure the Interfaces iface1 = ec.register_resource("omf::WifiInterface") ec.set(iface1, "name", "wlan0") ec.set(iface1, "mode", "adhoc") ec.set(iface1, "hw_mode", "g") ec.set(iface1, "essid", "ping") 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("omf::Node") ec.set(node2, "hostname", nodey) ec.set(node2, "xmppUser", slicename) ec.set(node2, "xmppServer", gateway) ec.set(node2, "xmppPort", "5222") ec.set(node2, "xmppPassword", "1234") # Create and Configure the Interfaces 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" % nodey[-2:]) ec.register_connection(node2, iface2) # Create and Configure the Channel channel = ec.register_resource("omf::Channel") ec.set(channel, "channel", chan) ec.set(channel, "xmppUser", slicename) 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("omf::Application") ec.set(app1, "appid", "Ping#1") ec.set(app1, "command", "/bin/ping -c3 192.168.0.%s" % nodey[-2:]) ec.register_connection(app1, node1) ## 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]) # 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()