2 from neco.execution.resource import ResourceManager, clsinit
3 from neco.execution.attribute import Attribute, Flags
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFWifiInterface(ResourceManager):
13 .. class:: Class Args :
15 :param ec: The Experiment controller
16 :type ec: ExperimentController
17 :param guid: guid of the RM
19 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
24 This class is used only by the Experiment Controller through the Resource Factory
27 _rtype = "OMFWifiInterface"
28 _authorized_connections = ["OMFNode" , "OMFChannel"]
30 #alias2name = dict({'w0':'wlan0', 'w1':'wlan1'})
33 def _register_attributes(cls):
34 """Register the attributes of an OMF interface
37 alias = Attribute("alias","Alias of the interface", default_value = "w0")
38 mode = Attribute("mode","Mode of the interface")
39 type = Attribute("type","Type of the interface")
40 essid = Attribute("essid","Essid of the interface")
41 ip = Attribute("ip","IP of the interface")
42 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
43 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
44 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
45 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
46 cls._register_attribute(alias)
47 cls._register_attribute(xmppSlice)
48 cls._register_attribute(xmppHost)
49 cls._register_attribute(xmppPort)
50 cls._register_attribute(xmppPassword)
51 cls._register_attribute(mode)
52 cls._register_attribute(type)
53 cls._register_attribute(essid)
54 cls._register_attribute(ip)
56 def __init__(self, ec, guid):
58 :param ec: The Experiment controller
59 :type ec: ExperimentController
60 :param guid: guid of the RM
62 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
66 super(OMFWifiInterface, self).__init__(ec, guid)
69 self._alias = self.get('alias')
71 self._logger = logging.getLogger("neco.omf.omfIface ")
72 self._logger.setLevel(neco.LOGLEVEL)
74 def _validate_connection(self, guid):
75 """ Check if the connection is available.
77 :param guid: Guid of the current RM
82 rm = self.ec.get_resource(guid)
83 if rm.rtype() in self._authorized_connections:
84 self._logger.debug("Connection between %s %s and %s %s accepted" %
85 (self.rtype(), self._guid, rm.rtype(), guid))
87 self._logger.debug("Connection between %s %s and %s %s refused" %
88 (self.rtype(), self._guid, rm.rtype(), guid))
91 def _get_nodes(self, conn_set):
92 """ Get the RM of the node to which the application is connected
94 :param conn_set: Connections of the current Guid
96 :rtype: ResourceManager
100 rm = self.ec.get_resource(elt)
101 if rm.rtype() == "OMFNode":
109 super(OMFWifiInterface, self).deploy()
110 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
111 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
115 """Send Xmpp Messages Using OMF protocol to configure Interface
118 self._logger.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " +
119 self.get('mode') + " : " + self.get('type') + " : " +
120 self.get('essid') + " : " + self.get('ip'))
122 if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'):
123 rm_node = self._get_nodes(self._connections)
124 for attrname in ["mode", "type", "essid", "ip"]:
125 attrval = self.get(attrname)
126 attrname = "net/%s/%s" % (self._alias, attrname)
127 #print "Send the configure message"
128 self._omf_api.configure(rm_node.get('hostname'), attrname, attrval)
129 super(OMFWifiInterface, self).start()
132 """Send Xmpp Message Using OMF protocol to put down the interface
135 super(OMFWifiInterface, self).stop()
138 """Clean the RM at the end of the experiment
141 OMFAPIFactory.release_api(self.get('xmppSlice'),
142 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))