2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 # Julien Tribino <julien.tribino@inria.fr>
21 from nepi.execution.resource import ResourceManager, clsinit, ResourceState
22 from nepi.execution.attribute import Attribute, Flags
24 from nepi.resources.omf.omf_api import OMFAPIFactory
26 reschedule_delay = "0.5s"
29 class OMFChannel(ResourceManager):
31 .. class:: Class Args :
33 :param ec: The Experiment controller
34 :type ec: ExperimentController
35 :param guid: guid of the RM
37 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
42 This class is used only by the Experiment Controller through the Resource Factory
46 _authorized_connections = ["OMFWifiInterface", "OMFNode"]
50 def _register_attributes(cls):
51 """Register the attributes of an OMF channel
53 channel = Attribute("channel", "Name of the application")
54 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
55 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
56 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
57 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
58 cls._register_attribute(channel)
59 cls._register_attribute(xmppSlice)
60 cls._register_attribute(xmppHost)
61 cls._register_attribute(xmppPort)
62 cls._register_attribute(xmppPassword)
64 def __init__(self, ec, guid):
66 :param ec: The Experiment controller
67 :type ec: ExperimentController
68 :param guid: guid of the RM
70 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
74 super(OMFChannel, self).__init__(ec, guid)
76 self._nodes_guid = list()
80 def _validate_connection(self, guid):
81 """Check if the connection is available.
83 :param guid: Guid of the current RM
88 rm = self.ec.get_resource(guid)
89 if rm.rtype() in self._authorized_connections:
90 msg = "Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid)
93 msg = "Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid)
97 def _get_target(self, conn_set):
99 Get the couples (host, interface) that used this channel
101 :param conn_set: Connections of the current Guid
104 :return: self._nodes_guid
108 rm_iface = self.ec.get_resource(elt)
109 for conn in rm_iface.connections:
110 rm_node = self.ec.get_resource(conn)
111 if rm_node.rtype() == "OMFNode":
112 if rm_iface.state < ResourceState.READY or rm_node.state < ResourceState.READY:
114 couple = [rm_node.get('hostname'), rm_iface.get('alias')]
116 self._nodes_guid.append(couple)
117 return self._nodes_guid
123 if not self._omf_api :
124 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
125 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
127 if self.get('channel'):
128 set_nodes = self._get_target(self._connections)
129 if set_nodes == "reschedule" :
130 self.ec.schedule(reschedule_delay, self.deploy)
133 for couple in set_nodes:
134 #print "Couple node/alias : " + couple[0] + " , " + couple[1]
135 attrval = self.get('channel')
136 attrname = "net/%s/%s" % (couple[1], 'channel')
137 self._omf_api.configure(couple[0], attrname, attrval)
139 super(OMFChannel, self).deploy()
142 """ Discover the availables channels
148 """ Provision some availables channels
154 """Send Xmpp Message Using OMF protocol to configure Channel
158 super(OMFChannel, self).start()
161 """Send Xmpp Message Using OMF protocol to put down the interface
164 super(OMFChannel, self).stop()
167 """Clean the RM at the end of the experiment
170 OMFAPIFactory.release_api(self.get('xmppSlice'),
171 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))