From 38cae419a35e2f1847dcb279a3e25597e79c80ee Mon Sep 17 00:00:00 2001 From: Julien Tribino Date: Thu, 3 Oct 2013 16:40:08 +0200 Subject: [PATCH] add set_hook test and add the OMFResource mother classes --- .../linux/ccn/ccncat_extended_ring_topo.py | 10 +- .../omf/automated_vlc_experiment_plexus.py | 147 -------------- examples/omf/manual_vlc_experiment_plexus.py | 189 ------------------ examples/omf/nepi_omf_vlc_experiment.py | 5 +- src/nepi/resources/omf/application.py | 35 ++-- src/nepi/resources/omf/channel.py | 15 +- src/nepi/resources/omf/interface.py | 25 ++- src/nepi/resources/omf/messages_5_4.py | 20 ++ src/nepi/resources/omf/node.py | 14 +- src/nepi/resources/omf/omf_api.py | 17 ++ src/nepi/resources/omf/omf_resource.py | 7 +- test/resources/omf/set_hook.py | 104 ++++++++++ test/resources/omf/vlc.py | 1 - 13 files changed, 193 insertions(+), 396 deletions(-) delete mode 100755 examples/omf/automated_vlc_experiment_plexus.py delete mode 100755 examples/omf/manual_vlc_experiment_plexus.py create mode 100644 test/resources/omf/set_hook.py diff --git a/examples/linux/ccn/ccncat_extended_ring_topo.py b/examples/linux/ccn/ccncat_extended_ring_topo.py index 4bf5dc80..7accb3a5 100755 --- a/examples/linux/ccn/ccncat_extended_ring_topo.py +++ b/examples/linux/ccn/ccncat_extended_ring_topo.py @@ -137,14 +137,6 @@ if __name__ == '__main__': ( pl_user, movie, exp_id, pl_ssh_key, results_dir ) = get_options() ec = ExperimentController(exp_id = exp_id) - - # hosts in Europe - #host1 = "planetlab2.u-strasbg.fr" - #host2 = "planet1.servers.ua.pt" - #host3 = "planetlab1.cs.uoi.gr" - #host4 = "planetlab1.aston.ac.uk" - #host5 = "planetlab2.willab.fi" - #host6 = "planetlab-1.fokus.fraunhofer.de" # host in the US host1 = "planetlab4.wail.wisc.edu" @@ -154,7 +146,7 @@ if __name__ == '__main__': host5 = "earth.cs.brown.edu" host6 = "planetlab2.engr.uconn.edu" - # describe nodes in the central ring + # describe nodes in the central ring ring_hosts = [host1, host2, host3, host4] ccnds = dict() diff --git a/examples/omf/automated_vlc_experiment_plexus.py b/examples/omf/automated_vlc_experiment_plexus.py deleted file mode 100755 index e1e99fa6..00000000 --- a/examples/omf/automated_vlc_experiment_plexus.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/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. -# -# 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 . -# -# Author: Julien Tribino - -from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState -from nepi.execution.ec import ExperimentController - -from nepi.resources.omf.node import OMFNode -from nepi.resources.omf.application import OMFApplication -from nepi.resources.omf.interface import OMFWifiInterface -from nepi.resources.omf.channel import OMFChannel - -import logging -import time - -logging.basicConfig() - -# Create the EC -ec = ExperimentController() - -# Create and Configure the Nodes -node1 = ec.register_resource("OMFNode") -ec.set(node1, 'hostname', 'omf.plexus.wlab17') -ec.set(node1, 'xmppSlice', "nepi") -ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(node1, 'xmppPort', "5222") -ec.set(node1, 'xmppPassword', "1234") -ec.set(node1, 'xmppSlice', "nepi") -ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(node1, 'xmppPort', "5222") -ec.set(node1, 'xmppPassword', "1234") - -node2 = ec.register_resource("OMFNode") -ec.set(node2, 'hostname', "omf.plexus.wlab37") -ec.set(node2, 'xmppSlice', "nepi") -ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(node2, 'xmppPort', "5222") -ec.set(node2, 'xmppPassword', "1234") -ec.set(node2, 'xmppSlice', "nepi") -ec.set(node2, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(node2, 'xmppPort', "5222") -ec.set(node2, 'xmppPassword', "1234") - -# Create and Configure the Interfaces -iface1 = ec.register_resource("OMFWifiInterface") -ec.set(iface1, 'alias', "w0") -ec.set(iface1, 'mode', "adhoc") -ec.set(iface1, 'type', "g") -ec.set(iface1, 'essid', "vlcexp") -#ec.set(iface1, 'ap', "11:22:33:44:55:66") -ec.set(iface1, 'ip', "10.0.0.17") -ec.set(iface1, 'xmppSlice', "nepi") -ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(iface1, 'xmppPort', "5222") -ec.set(iface1, 'xmppPassword', "1234") - -iface2 = ec.register_resource("OMFWifiInterface") -ec.set(iface2, 'alias', "w0") -ec.set(iface2, 'mode', "adhoc") -ec.set(iface2, 'type', 'g') -ec.set(iface2, 'essid', "vlcexp") -#ec.set(iface2, 'ap', "11:22:33:44:55:66") -ec.set(iface2, 'ip', "10.0.0.37") -ec.set(iface2, 'xmppSlice', "nepi") -ec.set(iface2, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(iface2, 'xmppPort', "5222") -ec.set(iface2, 'xmppPassword', "1234") - -# Create and Configure the Channel -channel = ec.register_resource("OMFChannel") -ec.set(channel, 'channel', "6") -ec.set(channel, 'xmppSlice', "nepi") -ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(channel, 'xmppPort', "5222") -ec.set(channel, 'xmppPassword', "1234") - -# Create and Configure the Application -app1 = ec.register_resource("OMFApplication") -ec.set(app1, 'appid', 'Vlc#1') -ec.set(app1, 'path', "/opt/vlc-1.1.13/cvlc") -ec.set(app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") -#ec.set(app1, 'args', "--quiet /opt/big_buck_bunny_240p_mpeg4.ts --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts} '") -ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") -ec.set(app1, 'xmppSlice', "nepi") -ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(app1, 'xmppPort', "5222") -ec.set(app1, 'xmppPassword', "1234") - -app2 = ec.register_resource("OMFApplication") -ec.set(app2, 'appid', 'Vlc#2') -ec.set(app2, 'path', "/opt/vlc-1.1.13/cvlc") -ec.set(app2, 'args', "--quiet rtp://10.0.0.37:1234") -ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") -ec.set(app2, 'xmppSlice', "nepi") -ec.set(app2, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(app2, 'xmppPort', "5222") -ec.set(app2, 'xmppPassword', "1234") - -app3 = ec.register_resource("OMFApplication") -ec.set(app3, 'appid', 'Kill#2') -ec.set(app3, 'path', "/usr/bin/killall") -ec.set(app3, 'args', "vlc") -ec.set(app3, 'env', " ") -ec.set(app3, 'xmppSlice', "nepi") -ec.set(app3, 'xmppHost', "xmpp-plexus.onelab.eu") -ec.set(app3, 'xmppPort', "5222") -ec.set(app3, 'xmppPassword', "1234") - -# Connection -ec.register_connection(app3, node1) -ec.register_connection(app1, node1) -ec.register_connection(node1, iface1) -ec.register_connection(iface1, channel) -ec.register_connection(iface2, channel) -ec.register_connection(node2, iface2) -ec.register_connection(app2, node2) - -# User Behaviour -ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "4s") -ec.register_condition([app1, app2], ResourceAction.STOP, app2, ResourceState.STARTED , "22s") -ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STARTED , "25s") -ec.register_condition(app3, ResourceAction.STOP, app3, ResourceState.STARTED , "1s") - -# Deploy -ec.deploy() - -ec.wait_finished([app1, app2, app3]) - -# Stop Experiment -#time.sleep(55) -ec.shutdown() diff --git a/examples/omf/manual_vlc_experiment_plexus.py b/examples/omf/manual_vlc_experiment_plexus.py deleted file mode 100755 index 1b9ec405..00000000 --- a/examples/omf/manual_vlc_experiment_plexus.py +++ /dev/null @@ -1,189 +0,0 @@ -#!/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. -# -# 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 . -# -# Author: Julien Tribino - -from nepi.execution.resource import ResourceFactory -from nepi.execution.ec import ExperimentController - -from nepi.resources.omf.node import OMFNode -from nepi.resources.omf.application import OMFApplication -from nepi.resources.omf.interface import OMFWifiInterface -from nepi.resources.omf.channel import OMFChannel - -import logging -import time - -logging.basicConfig() - -# Create the EC -ec = ExperimentController() - -# Register the different RM that will be used -ResourceFactory.register_type(OMFNode) -ResourceFactory.register_type(OMFWifiInterface) -ResourceFactory.register_type(OMFChannel) -ResourceFactory.register_type(OMFApplication) - -# Create and Configure the Nodes -guid = ec.register_resource("OMFNode") -node1 = ec.get_resource(guid) -node1.set('hostname', 'omf.plexus.wlab17') -node1.set('xmppSlice', "nepi") -node1.set('xmppHost', "xmpp-plexus.onelab.eu") -node1.set('xmppPort', "5222") -node1.set('xmppPassword', "1234") - -guid = ec.register_resource("OMFNode") -node2 = ec.get_resource(guid) -node2.set('hostname', "omf.plexus.wlab37") -node2.set('xmppSlice', "nepi") -node2.set('xmppHost', "xmpp-plexus.onelab.eu") -node2.set('xmppPort', "5222") -node2.set('xmppPassword', "1234") - -# Create and Configure the Interfaces -guid = ec.register_resource("OMFWifiInterface") -iface1 = ec.get_resource(guid) -iface1.set('alias', "w0") -iface1.set('mode', "adhoc") -iface1.set('type', "g") -iface1.set('essid', "helloworld") -iface1.set('ip', "10.0.0.17") -iface1.set('xmppSlice', "nepi") -iface1.set('xmppHost', "xmpp-plexus.onelab.eu") -iface1.set('xmppPort', "5222") -iface1.set('xmppPassword', "1234") - -guid = ec.register_resource("OMFWifiInterface") -iface2 = ec.get_resource(guid) -iface2.set('alias', "w0") -iface2.set('mode', "adhoc") -iface2.set('type', 'g') -iface2.set('essid', "helloworld") -iface2.set('ip', "10.0.0.37") -iface2.set('xmppSlice', "nepi") -iface2.set('xmppHost', "xmpp-plexus.onelab.eu") -iface2.set('xmppPort', "5222") -iface2.set('xmppPassword', "1234") - -# Create and Configure the Channel -guid = ec.register_resource("OMFChannel") -channel = ec.get_resource(guid) -channel.set('channel', "6") -channel.set('xmppSlice', "nepi") -channel.set('xmppHost', "xmpp-plexus.onelab.eu") -channel.set('xmppPort', "5222") -channel.set('xmppPassword', "1234") - -# Create and Configure the Application -guid = ec.register_resource("OMFApplication") -app1 = ec.get_resource(guid) -app1.set('appid', 'Vlc#1') -app1.set('path', "/opt/vlc-1.1.13/cvlc") -app1.set('args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") -app1.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") -app1.set('xmppSlice', "nepi") -app1.set('xmppHost', "xmpp-plexus.onelab.eu") -app1.set('xmppPort', "5222") -app1.set('xmppPassword', "1234") - -guid = ec.register_resource("OMFApplication") -app2 = ec.get_resource(guid) -app2.set('appid', 'Vlc#2') -app2.set('path', "/opt/vlc-1.1.13/cvlc") -app2.set('args', "rtp://10.0.0.37:1234") -app2.set('env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") -app2.set('xmppSlice', "nepi") -app2.set('xmppHost', "xmpp-plexus.onelab.eu") -app2.set('xmppPort', "5222") -app2.set('xmppPassword', "1234") - -guid = ec.register_resource("OMFApplication") -app3 = ec.get_resource(guid) -app3.set('appid', 'Kill#2') -app3.set('path', "/usr/bin/killall") -app3.set('args', "vlc") -app3.set('env', " ") -app3.set('xmppSlice', "nepi") -app3.set('xmppHost', "xmpp-plexus.onelab.eu") -app3.set('xmppPort', "5222") -app3.set('xmppPassword', "1234") - -# register_connection -app3.register_connection(node1.guid) -node1.register_connection(app3.guid) - -app1.register_connection(node1.guid) -node1.register_connection(app1.guid) - -node1.register_connection(iface1.guid) -iface1.register_connection(node1.guid) - -iface1.register_connection(channel.guid) -channel.register_connection(iface1.guid) - -channel.register_connection(iface2.guid) -iface2.register_connection(channel.guid) - -iface2.register_connection(node2.guid) -node2.register_connection(iface2.guid) - -node2.register_connection(app2.guid) -app2.register_connection(node2.guid) - -# Local Deploy -node1.deploy() -node2.deploy() -iface1.deploy() -iface2.deploy() -channel.deploy() -app1.deploy() -app2.deploy() -app3.deploy() - -# Start the Nodes -node1.start() -node2.start() -time.sleep(2) - -# Start the Interfaces -iface1.start() -iface2.start() - -# Start the Channel -time.sleep(2) -channel.start() -time.sleep(2) - -# Start the Application -app1.start() -time.sleep(2) -app2.start() - -time.sleep(20) - -# Stop the Application -app1.stop() -app2.stop() -time.sleep(1) -app3.start() -time.sleep(2) - -# Stop Experiment -ec.shutdown() diff --git a/examples/omf/nepi_omf_vlc_experiment.py b/examples/omf/nepi_omf_vlc_experiment.py index 3e5e7c4c..84e9eaa9 100644 --- a/examples/omf/nepi_omf_vlc_experiment.py +++ b/examples/omf/nepi_omf_vlc_experiment.py @@ -18,15 +18,12 @@ """ #!/usr/bin/env python -from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState, populate_factory +from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState from nepi.execution.ec import ExperimentController # Create the EC ec = ExperimentController() -# Register the different RM that will be used -populate_factory() - # Create and Configure the Nodes node1 = ec.register_resource("OMFNode") ec.set(node1, 'hostname', 'omf.plexus.wlab17') diff --git a/src/nepi/resources/omf/application.py b/src/nepi/resources/omf/application.py index 673f8100..e9389d08 100644 --- a/src/nepi/resources/omf/application.py +++ b/src/nepi/resources/omf/application.py @@ -18,15 +18,16 @@ # Author: Alina Quereilhac # Julien Tribino -from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \ +from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \ reschedule_delay from nepi.execution.attribute import Attribute, Flags +from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource from nepi.resources.omf.node import OMFNode from nepi.resources.omf.omf_api import OMFAPIFactory -@clsinit -class OMFApplication(ResourceManager): +@clsinit_copy +class OMFApplication(OMFResource): """ .. class:: Class Args : @@ -46,29 +47,25 @@ class OMFApplication(ResourceManager): _rtype = "OMFApplication" _authorized_connections = ["OMFNode"] + @classmethod + def stdin_send(cls, old_value, new_value): + print "AAHHHHHHHH" + @classmethod def _register_attributes(cls): """ Register the attributes of an OMF application """ - appid = Attribute("appid", "Name of the application") path = Attribute("path", "Path of the application") args = Attribute("args", "Argument of the application") env = Attribute("env", "Environnement variable of the application") - xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential) - xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential) - xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential) - xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential) + stdin = Attribute("stdin", "Input of the application", default = "", set_hook = cls.stdin_send ) cls._register_attribute(appid) cls._register_attribute(path) cls._register_attribute(args) cls._register_attribute(env) - cls._register_attribute(xmppSlice) - cls._register_attribute(xmppHost) - cls._register_attribute(xmppPort) - cls._register_attribute(xmppPassword) - + cls._register_attribute(stdin) def __init__(self, ec, guid): """ @@ -91,12 +88,20 @@ class OMFApplication(ResourceManager): self._omf_api = None + @property + def exp_id(self): + if self.ec.exp_id.startswith('exp-'): + return None + return self.ec.exp_id + @property def node(self): rm_list = self.get_connected(OMFNode.rtype()) if rm_list: return rm_list[0] return None + + def valid_connection(self, guid): """ Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. @@ -139,7 +144,7 @@ class OMFApplication(ResourceManager): if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) if not self._omf_api : msg = "Credentials are not initialzed. XMPP Connections impossible" @@ -206,7 +211,7 @@ class OMFApplication(ResourceManager): if self._omf_api : OMFAPIFactory.release_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) super(OMFApplication, self).release() diff --git a/src/nepi/resources/omf/channel.py b/src/nepi/resources/omf/channel.py index b51cd895..20c60b57 100644 --- a/src/nepi/resources/omf/channel.py +++ b/src/nepi/resources/omf/channel.py @@ -18,15 +18,16 @@ # Author: Alina Quereilhac # Julien Tribino -from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \ +from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \ reschedule_delay from nepi.execution.attribute import Attribute, Flags +from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource from nepi.resources.omf.omf_api import OMFAPIFactory -@clsinit -class OMFChannel(ResourceManager): +@clsinit_copy +class OMFChannel(OMFResource): """ .. class:: Class Args : @@ -51,15 +52,7 @@ class OMFChannel(ResourceManager): """ channel = Attribute("channel", "Name of the application") - xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential) - xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential) - xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential) - xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential) cls._register_attribute(channel) - cls._register_attribute(xmppSlice) - cls._register_attribute(xmppHost) - cls._register_attribute(xmppPort) - cls._register_attribute(xmppPassword) def __init__(self, ec, guid): """ diff --git a/src/nepi/resources/omf/interface.py b/src/nepi/resources/omf/interface.py index a3b9c3a3..0aea5bb1 100644 --- a/src/nepi/resources/omf/interface.py +++ b/src/nepi/resources/omf/interface.py @@ -18,16 +18,17 @@ # Author: Alina Quereilhac # Julien Tribino -from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \ +from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \ reschedule_delay from nepi.execution.attribute import Attribute, Flags from nepi.resources.omf.node import OMFNode +from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource from nepi.resources.omf.channel import OMFChannel from nepi.resources.omf.omf_api import OMFAPIFactory -@clsinit -class OMFWifiInterface(ResourceManager): +@clsinit_copy +class OMFWifiInterface(OMFResource): """ .. class:: Class Args : @@ -59,15 +60,7 @@ class OMFWifiInterface(ResourceManager): type = Attribute("type","Type of the interface") essid = Attribute("essid","Essid of the interface") ip = Attribute("ip","IP of the interface") - xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential) - xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential) - xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential) - xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential) cls._register_attribute(alias) - cls._register_attribute(xmppSlice) - cls._register_attribute(xmppHost) - cls._register_attribute(xmppPort) - cls._register_attribute(xmppPassword) cls._register_attribute(mode) cls._register_attribute(type) cls._register_attribute(essid) @@ -111,6 +104,12 @@ class OMFWifiInterface(ResourceManager): return False + @property + def exp_id(self): + if self.ec.exp_id.startswith('exp-'): + return None + return self.ec.exp_id + @property def node(self): rm_list = self.get_connected(OMFNode.rtype()) @@ -176,7 +175,7 @@ class OMFWifiInterface(ResourceManager): if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) if not self._omf_api : msg = "Credentials are not initialzed. XMPP Connections impossible" @@ -222,7 +221,7 @@ class OMFWifiInterface(ResourceManager): if self._omf_api : OMFAPIFactory.release_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) super(OMFWifiInterface, self).release() diff --git a/src/nepi/resources/omf/messages_5_4.py b/src/nepi/resources/omf/messages_5_4.py index b27531ae..7e518935 100644 --- a/src/nepi/resources/omf/messages_5_4.py +++ b/src/nepi/resources/omf/messages_5_4.py @@ -102,6 +102,26 @@ class MessageHandler(): path = self._attr_element(execute,"PATH",path) return payload + def stdin_function(self, target, value, appid): + """ Build an Execute Message + + :param value: parameter that go in the stdin + :type value: str + :param target: Hrn of the target node (ex : omf.plexus.wlab17) + :type target: str + :param appid: Application id + :type appid: str + + """ + payload = ET.Element("omf-message") + stdin = self._id_element(payload,"STDIN") + value = self._attr_element(stdin,"TARGET",target) + sliceid = self._attr_element(stdin,"SLICEID",self._slice_id) + expid = self._attr_element(stdin,"EXPID",self._exp_id) + target = self._attr_element(stdin,"TARGET",target) + appid = self._attr_element(stdin,"APPID",appid) + return payload + def exit_function(self, target, appid): """ Build an Exit Message diff --git a/src/nepi/resources/omf/node.py b/src/nepi/resources/omf/node.py index b6b65efd..68b4df39 100644 --- a/src/nepi/resources/omf/node.py +++ b/src/nepi/resources/omf/node.py @@ -19,7 +19,7 @@ # Julien Tribino -from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \ +from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \ reschedule_delay from nepi.execution.attribute import Attribute, Flags from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource @@ -28,7 +28,7 @@ from nepi.resources.omf.omf_api import OMFAPIFactory import time -@clsinit +@clsinit_copy class OMFNode(OMFResource): """ .. class:: Class Args : @@ -71,6 +71,12 @@ class OMFNode(OMFResource): self._omf_api = None + @property + def exp_id(self): + if self.ec.exp_id.startswith('exp-'): + return None + return self.ec.exp_id + def valid_connection(self, guid): """ Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. @@ -103,7 +109,7 @@ class OMFNode(OMFResource): if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) if not self._omf_api : msg = "Credentials are not initialzed. XMPP Connections impossible" @@ -163,7 +169,7 @@ class OMFNode(OMFResource): OMFAPIFactory.release_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), - self.get('xmppPassword'), exp_id = self.ec.exp_id) + self.get('xmppPassword'), exp_id = self.exp_id) super(OMFNode, self).release() diff --git a/src/nepi/resources/omf/omf_api.py b/src/nepi/resources/omf/omf_api.py index dc03b937..377dc93f 100644 --- a/src/nepi/resources/omf/omf_api.py +++ b/src/nepi/resources/omf/omf_api.py @@ -245,6 +245,23 @@ class OMFAPI(Logger): xmpp_node = self._host_session_id(hostname) self._client.publish(payload, xmpp_node) + def send_stdin(self, hostname, value, app_id): + """ Send to the stdin of the application the value + + :param hostname: Full hrn of the node + :type hostname: str + :param appid: Application Id (Any id that represents in a unique + way the application) + :type appid: str + :param value: parameter to execute in the stdin of the application + :type value: str + + """ + payload = self._message.stdin_function(hostname, value, app_id) + xmpp_node = self._host_session_id(hostname) + self._client.publish(payload, xmpp_node) + + def execute(self, hostname, app_id, arguments, path, env): """ Execute command on the node diff --git a/src/nepi/resources/omf/omf_resource.py b/src/nepi/resources/omf/omf_resource.py index f6a473a5..ddd4ad7e 100644 --- a/src/nepi/resources/omf/omf_resource.py +++ b/src/nepi/resources/omf/omf_resource.py @@ -19,7 +19,7 @@ # Lucia Guevgeozian from nepi.execution.attribute import Attribute, Flags, Types -from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \ +from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \ reschedule_delay class ResourceGateway: @@ -28,11 +28,12 @@ class ResourceGateway: """ TestbedtoGateway = dict({ "wilabt" : "ops.wilab2.ilabt.iminds.be", - "nitos" : "??.??.??", + "nitos" : "nitlab.inf.uth.gr", "nicta" : "??.??.??", + }) -@clsinit_copy +@clsinit class OMFResource(ResourceManager): """ Generic resource gathering XMPP credential information and common methods diff --git a/test/resources/omf/set_hook.py b/test/resources/omf/set_hook.py new file mode 100644 index 00000000..08abb005 --- /dev/null +++ b/test/resources/omf/set_hook.py @@ -0,0 +1,104 @@ +#!/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. +# +# 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 . +# +# Author: Julien Tribino + + +from nepi.execution.resource import ResourceFactory, clsinit_copy, ResourceManager, ResourceAction, ResourceState +from nepi.execution.ec import ExperimentController +from nepi.execution.attribute import Attribute, Flags + +from nepi.resources.omf.node import OMFNode +from nepi.resources.omf.application import OMFApplication + +from nepi.util.timefuncs import * + +import time +import unittest + +class DummyEC(ExperimentController): + pass + +@clsinit_copy +class DummyOMFApplication(OMFApplication): + _rtype = "DummyOMFApplication" + + @classmethod + def _register_attributes(cls): + test = Attribute("test", "Input of the application", default = 0, set_hook = cls.test_hook) + cls._register_attribute(test) + + @classmethod + def test_hook(cls, old_value, new_value): + new_value *= 10 + print "Change the value of test from "+ str(old_value) +" to : " + str(new_value) + return new_value + + +class OMFTestSet(unittest.TestCase): + + def test_set_hook(self): + self.ec = DummyEC(exp_id = "30") + + ResourceFactory.register_type(DummyOMFApplication) + + self.node1 = self.ec.register_resource("OMFNode") + self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17') + self.ec.set(self.node1, 'xmppSlice', "nepi") + self.ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.node1, 'xmppPort', "5222") + self.ec.set(self.node1, 'xmppPassword', "1234") + + self.app1 = self.ec.register_resource("DummyOMFApplication") + self.ec.set(self.app1, 'appid', 'Test#1') + self.ec.set(self.app1, 'path', "/usr/bin/ping") + self.ec.set(self.app1, 'args', "") + self.ec.set(self.app1, 'env', "") + self.ec.set(self.app1, 'xmppSlice', "nepi") + self.ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.app1, 'xmppPort', "5222") + self.ec.set(self.app1, 'xmppPassword', "1234") + + self.ec.register_connection(self.app1, self.node1) + + self.ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s") + + self.ec.deploy() + + time.sleep(3) + print "First try to change the STDIN" + self.ec.set(self.app1, 'test', 3) + + self.assertEquals(self.ec.get(self.app1, 'test'), 30) + + time.sleep(3) + print "Second try to change the STDIN" + self.ec.set(self.app1, 'test', 101) + self.assertEquals(self.ec.get(self.app1, 'test'), 1010) + + self.ec.wait_finished([self.app1]) + + # Stop Experiment + self.ec.shutdown() + + +if __name__ == '__main__': + unittest.main() + + + diff --git a/test/resources/omf/vlc.py b/test/resources/omf/vlc.py index a86af14f..a42f5669 100755 --- a/test/resources/omf/vlc.py +++ b/test/resources/omf/vlc.py @@ -172,7 +172,6 @@ class OMFEachTestCase(unittest.TestCase): self.assertEquals(len(self.ec.get_resource(self.app5).conditions[ResourceAction.START]), 2) - class OMFVLCTestCaseComplete(unittest.TestCase): def test_deploy(self): -- 2.47.0