Add omf example and send ip message after channel
authorJulien Tribino <julien.tribino@inria.fr>
Wed, 31 Jul 2013 12:40:30 +0000 (14:40 +0200)
committerJulien Tribino <julien.tribino@inria.fr>
Wed, 31 Jul 2013 12:40:30 +0000 (14:40 +0200)
examples/omf/nepi_omf_vlc_experiment.py [new file with mode: 0644]
examples/omf/nepi_omf_vlc_nitos.py [new file with mode: 0644]
examples/omf/nepi_omf_xeyes_nitos.py [new file with mode: 0644]
src/nepi/resources/omf/channel.py
src/nepi/resources/omf/interface.py

diff --git a/examples/omf/nepi_omf_vlc_experiment.py b/examples/omf/nepi_omf_vlc_experiment.py
new file mode 100644 (file)
index 0000000..3e5e7c4
--- /dev/null
@@ -0,0 +1,130 @@
+"""
+    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 <http://www.gnu.org/licenses/>.
+
+"""
+
+#!/usr/bin/env python
+from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState, populate_factory
+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')
+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")
+
+# 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, '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, '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', "--quiet /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.XX,port=1234,mux=ts} '")
+#ec.set(app1, 'args', "--quiet /opt/big_buck_bunny_240p_mpeg4_lq.ts --sout '#rtp{dst=10.0.0.XX,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
+ec.shutdown()
diff --git a/examples/omf/nepi_omf_vlc_nitos.py b/examples/omf/nepi_omf_vlc_nitos.py
new file mode 100644 (file)
index 0000000..5a1237a
--- /dev/null
@@ -0,0 +1,140 @@
+"""
+    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 <http://www.gnu.org/licenses/>.
+
+    Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+            Julien Tribino <julien.tribino@inria.fr>
+
+"""
+
+#!/usr/bin/env python
+from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
+from nepi.execution.ec import ExperimentController
+
+# Create the EC
+ec = ExperimentController()
+
+
+# Create and Configure the Nodes
+node1 = ec.register_resource("OMFNode")
+ec.set(node1, 'hostname', 'omf.nitos.node0XX')
+ec.set(node1, 'xmppSlice', "ZZZ")
+ec.set(node1, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(node1, 'xmppPort', "5222")
+ec.set(node1, 'xmppPassword', "1234")
+
+node2 = ec.register_resource("OMFNode")
+ec.set(node2, 'hostname', "omf.nitos.node0YY")
+ec.set(node2, 'xmppSlice', "ZZZ")
+ec.set(node2, 'xmppHost', "nitlab.inf.uth.gr")
+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, 'ip', "192.168.0.XX")
+ec.set(iface1, 'xmppSlice', "ZZZ")
+ec.set(iface1, 'xmppHost', "nitlab.inf.uth.gr")
+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, 'ip', "192.168.0.YY")
+ec.set(iface2, 'xmppSlice', "ZZZ")
+ec.set(iface2, 'xmppHost', "nitlab.inf.uth.gr")
+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', "ZZZ")
+ec.set(channel, 'xmppHost', "nitlab.inf.uth.gr")
+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', "/root/vlc-1.1.13/cvlc")
+ec.set(app1, 'args', "/root/10-by-p0d.avi --sout '#rtp{dst=192.168.0.YY,port=1234,mux=ts}'")
+ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
+ec.set(app1, 'xmppSlice', "ZZZ")
+ec.set(app1, 'xmppHost', "nitlab.inf.uth.gr")
+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', "/root/vlc-1.1.13/cvlc")
+ec.set(app2, 'args', "rtp://192.168.0.YY:1234")
+ec.set(app2, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
+ec.set(app2, 'xmppSlice', "ZZZ")
+ec.set(app2, 'xmppHost', "nitlab.inf.uth.gr")
+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_app")
+ec.set(app3, 'env', " ")
+ec.set(app3, 'xmppSlice', "ZZZ")
+ec.set(app3, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(app3, 'xmppPort', "5222")
+ec.set(app3, 'xmppPassword', "1234")
+
+app4 = ec.register_resource("OMFApplication")
+ec.set(app4, 'appid', 'Kill#1')
+ec.set(app4, 'path', "/usr/bin/killall")
+ec.set(app4, 'args', "vlc_app")
+ec.set(app4, 'env', " ")
+ec.set(app4, 'xmppSlice', "ZZZ")
+ec.set(app4, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(app4, 'xmppPort', "5222")
+ec.set(app4, '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)
+ec.register_connection(app4, 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, app4], ResourceAction.START, app2, ResourceState.STARTED , "25s")
+ec.register_condition([app3, app4], ResourceAction.STOP, app3, ResourceState.STARTED , "1s")
+
+# Deploy
+ec.deploy()
+
+ec.wait_finished([app1, app2, app3, app4])
+
+# Stop Experiment
+ec.shutdown()
diff --git a/examples/omf/nepi_omf_xeyes_nitos.py b/examples/omf/nepi_omf_xeyes_nitos.py
new file mode 100644 (file)
index 0000000..1049ff8
--- /dev/null
@@ -0,0 +1,96 @@
+"""
+    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 <http://www.gnu.org/licenses/>.
+
+    Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+            Julien Tribino <julien.tribino@inria.fr>
+
+"""
+
+#!/usr/bin/env python
+from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
+from nepi.execution.ec import ExperimentController
+
+# Create the EC
+ec = ExperimentController()
+
+# Create and Configure the Nodes
+node1 = ec.register_resource("OMFNode")
+ec.set(node1, 'hostname', 'omf.nitos.node0XX')
+ec.set(node1, 'xmppSlice', "ZZZ")
+ec.set(node1, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(node1, 'xmppPort', "5222")
+ec.set(node1, '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', "xeyes")
+ec.set(iface1, 'ip', "192.168.0.XX")
+ec.set(iface1, 'xmppSlice', "ZZZ")
+ec.set(iface1, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(iface1, 'xmppPort', "5222")
+ec.set(iface1, 'xmppPassword', "1234")
+
+# Create and Configure the Channel
+channel = ec.register_resource("OMFChannel")
+ec.set(channel, 'channel', "6")
+ec.set(channel, 'xmppSlice', "ZZZ")
+ec.set(channel, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(channel, 'xmppPort', "5222")
+ec.set(channel, 'xmppPassword', "1234")
+
+# Create and Configure the Application
+app1 = ec.register_resource("OMFApplication")
+ec.set(app1, 'appid', 'XEyes#1')
+ec.set(app1, 'path', "/usr/bin/xeyes")
+ec.set(app1, 'args', " ")
+ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
+ec.set(app1, 'xmppSlice', "ZZZ")
+ec.set(app1, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(app1, 'xmppPort', "5222")
+ec.set(app1, 'xmppPassword', "1234")
+
+app2 = ec.register_resource("OMFApplication")
+ec.set(app2, 'appid', 'Kill#1')
+ec.set(app2, 'path', "/usr/bin/kill")
+ec.set(app2, 'args', "xeyes")
+ec.set(app2, 'env', " ")
+ec.set(app2, 'xmppSlice', "ZZZ")
+ec.set(app2, 'xmppHost', "nitlab.inf.uth.gr")
+ec.set(app2, 'xmppPort', "5222")
+ec.set(app2, 'xmppPassword', "1234")
+
+# Connection
+ec.register_connection(app2, node1)
+ec.register_connection(app1, node1)
+ec.register_connection(node1, iface1)
+ec.register_connection(iface1, channel)
+
+# 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")
+
+# Deploy
+ec.deploy()
+
+ec.wait_finished([app1, app2])
+
+# Stop Experiment
+ec.shutdown()
index deb2dfa..bc4f9b5 100644 (file)
@@ -115,7 +115,7 @@ class OMFChannel(ResourceManager):
             for conn in rm_iface.connections:
                 rm_node = self.ec.get_resource(conn)
                 if rm_node.rtype() == "OMFNode" and rm_node.get('hostname'):
-                    if rm_iface.state < ResourceState.READY or rm_node.state < ResourceState.READY:
+                    if rm_iface.state < ResourceState.PROVISIONED or rm_node.state < ResourceState.READY:
                         return "reschedule"
                     couple = [rm_node.get('hostname'), rm_iface.get('alias')]
                     #print couple
index d064c66..c2be38e 100644 (file)
@@ -23,6 +23,7 @@ from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \
 from nepi.execution.attribute import Attribute, Flags 
 
 from nepi.resources.omf.node import OMFNode
+from nepi.resources.omf.channel import OMFChannel
 from nepi.resources.omf.omf_api import OMFAPIFactory
 
 
@@ -118,6 +119,57 @@ class OMFWifiInterface(ResourceManager):
         if rm_list: return rm_list[0]
         return None
 
+    @property
+    def channel(self):
+        rm_list = self.get_connected(OMFChannel.rtype())
+        if rm_list: return rm_list[0]
+        return None
+
+
+    def configure_iface(self):
+        """ Configure the interface without the ip
+
+        """
+        if self.node.state < ResourceState.READY:
+            self.ec.schedule(reschedule_delay, self.deploy)
+            return False
+
+        try :
+            for attrname in ["mode", "type", "essid"]:
+                attrval = self.get(attrname)
+                attrname = "net/%s/%s" % (self._alias, attrname)
+                self._omf_api.configure(self.node.get('hostname'), attrname, attrval)
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.debug(msg)
+            #raise
+        
+        super(OMFWifiInterface, self).provision()
+        return True
+
+    def configure_ip(self):
+        """ Configure the ip of the interface
+
+        """
+
+        if self.channel.state < ResourceState.READY:
+            self.ec.schedule(reschedule_delay, self.deploy)
+            return False
+
+        try :
+            attrval = self.get("ip")
+            attrname = "net/%s/%s" % (self._alias, "ip")
+            self._omf_api.configure(self.node.get('hostname'), attrname, attrval)
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.debug(msg)
+            #raise
+
+        return True
+
+
     def deploy(self):
         """Deploy the RM. It means : Get the xmpp client and send messages using OMF 5.4 protocol to configure the interface
            It becomes DEPLOYED after sending messages to configure the interface
@@ -149,22 +201,17 @@ class OMFWifiInterface(ResourceManager):
             self.get('essid') + " : " + self.get('ip'))
     
         # Check if the node is already deployed
-        if self.node.state < ResourceState.READY:
-            self.ec.schedule(reschedule_delay, self.deploy)
-            return
-
-        try :
-            for attrname in ["mode", "type", "essid", "ip"]:
-                attrval = self.get(attrname)
-                attrname = "net/%s/%s" % (self._alias, attrname)
-                self._omf_api.configure(self.node.get('hostname'), attrname, attrval)
-        except AttributeError:
-            self._state = ResourceState.FAILED
-            msg = "Credentials are not initialzed. XMPP Connections impossible"
-            self.debug(msg)
-            #raise
+        chk1 = True
+        if self.state < ResourceState.PROVISIONED:
+            chk1 = self.configure_iface()
+        if chk1:
+            chk2 = self.configure_ip()
 
+        if not (chk1 and chk2) :
+            return False
+            
         super(OMFWifiInterface, self).deploy()
+        return True
 
     def start(self):
         """Start the RM. It means nothing special for an interface for now