1 # -*- coding: utf-8 -*-
3 from constants import TESTBED_ID, TESTBED_VERSION
4 from nepi.core import metadata
5 from nepi.core.attributes import Attribute
6 from nepi.util import tags, validation
7 from nepi.util.constants import ApplicationStatus as AS, \
8 FactoryCategories as FC, DeploymentConfiguration as DC
12 WIFIIFACE = "WifiInterface"
13 ETHIFACE = "EthInterface"
15 APPLICATION = "Application"
17 ### Connection functions ####
19 ### Creation functions ###
21 def create_node(testbed_instance, guid):
22 parameters = testbed_instance._get_parameters(guid)
23 hostname = parameters['hostname']
24 testbed_instance._elements[guid] = hostname
25 testbed_instance._publish_and_enroll_host(hostname)
27 def create_wifiiface(testbed_instance, guid):
30 def create_ethiface(testbed_instance, guid):
33 def create_channel(testbed_instance, guid):
36 def create_application(testbed_instance, guid):
39 ### Start/Stop functions ###
41 def start_application(testbed_instance, guid):
42 # search for the node asociated with the device
43 node_guids = testbed_instance.get_connected(guid, "node", "apps")
44 if len(node_guids) == 0:
45 raise RuntimeError("Can't instantiate interface %d outside node" % guid)
48 node_parameters = testbed_instance._get_parameters(node_guids[0])
49 hostname = node_parameters['hostname']
51 # application attributes
52 parameters = testbed_instance._get_parameters(guid)
53 app_id = parameters.get("appId")
54 arguments = parameters.get("arguments")
55 path = parameters.get("path")
56 testbed_instance._publish_execute(hostname, app_id, arguments, path)
58 def stop_application(testbed_instance, guid):
61 ### Status functions ###
63 def status_application(testbed_instance, guid):
64 if guid not in testbed_instance.elements.keys():
65 return AS.STATUS_NOT_STARTED
66 return AS.STATUS_RUNNING
68 #return AS.STATUS_FINISHED
70 ### Configure functions ###
72 def configure_wifiiface(testbed_instance, guid):
73 # search for the node asociated with the device
74 node_guids = testbed_instance.get_connected(guid, "node", "devs")
75 if len(node_guids) == 0:
76 raise RuntimeError("Can't instantiate interface %d outside node" % guid)
79 node_parameters = testbed_instance._get_parameters(node_guids[0])
80 hostname = node_parameters['hostname']
82 # wifi iface attributes
83 parameters = testbed_instance._get_parameters(guid)
85 for attr in ["mode", "type", "channel", "essid"]:
86 attribute = "net/w0/%s" % attr
87 value = parameters.get(attr)
89 testbed_instance._publish_configure(hostname, attribute, value)
91 if guid in testbed_instance._add_address:
92 attribute = "net/w0/ip"
93 addresses = testbed_instance._add_address[guid]
94 (value, netprefix, broadcast) = addresses[0]
95 testbed_instance._publish_configure(hostname, attribute, value)
97 ### Factory information ###
99 connector_types = dict({
101 "help": "Connector from node to applications",
107 "help": "Connector to network interfaces",
113 "help": "Connector from a device to a channel",
119 "help": "Connector to a Node",
128 "from": (TESTBED_ID, NODE, "devs"),
129 "to": (TESTBED_ID, WIFIIFACE, "node"),
133 "from": (TESTBED_ID, NODE, "devs"),
134 "to": (TESTBED_ID, ETHIFACE, "node"),
138 "from": (TESTBED_ID, WIFIIFACE, "chan"),
139 "to": (TESTBED_ID, CHANNEL, "devs"),
143 "from": (TESTBED_ID, NODE, "apps"),
144 "to": (TESTBED_ID, APPLICATION, "node"),
152 "help": "Application id",
153 "type": Attribute.STRING,
154 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
155 "validation_function": validation.is_string
159 "help": "Application arguments",
160 "type": Attribute.STRING,
161 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
162 "validation_function": validation.is_string
166 "help": "Path to binary (e.g '/opt/vlc-1.1.13/vlc')",
167 "type": Attribute.STRING,
168 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
169 "validation_function": validation.is_string
173 "help": "Hostname for the target OMF node",
174 "type": Attribute.STRING,
175 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
176 "validation_function": validation.is_string
180 "help": "Corresponds to the OMF attributes net/w0/mode",
181 "type": Attribute.STRING,
182 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
183 "validation_function": validation.is_string
187 "help": "Corresponds to the OMF attributes net/w0/type",
188 "type": Attribute.STRING,
189 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
190 "validation_function": validation.is_string
194 "help": "Corresponds to the OMF attributes net/w0/channel",
195 "type": Attribute.STRING,
196 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
197 "validation_function": validation.is_string
201 "help": "Corresponds to the OMF attributes net/w0/essid",
202 "type": Attribute.STRING,
203 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
204 "validation_function": validation.is_string
212 create_order = [ NODE, WIFIIFACE, ETHIFACE, CHANNEL, APPLICATION ]
213 configure_order = [ WIFIIFACE, ETHIFACE, NODE, CHANNEL, APPLICATION ]
215 factories_info = dict({
218 "category": FC.CATEGORY_NODES,
219 "create_function": create_node,
220 "box_attributes": ["hostname"],
221 "connector_types": ["devs", "apps"],
222 "tags": [tags.NODE, tags.ALLOW_ROUTES],
225 "help": "Wireless network interface",
226 "category": FC.CATEGORY_DEVICES,
227 "create_function": create_wifiiface,
228 "configure_function": configure_wifiiface,
229 "box_attributes": ["mode", "type", "channel", "essid"],
230 "connector_types": ["node", "chan"],
231 "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
234 "help": "Ethernet network interface",
235 "category": FC.CATEGORY_DEVICES,
236 "create_function": create_ethiface,
237 #"box_attributes": [""],
238 "connector_types": ["node"],
239 "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
242 "help": "Wireless channel",
243 "category": FC.CATEGORY_DEVICES,
244 "create_function": create_channel,
245 "box_attributes": ["mode", "type", "channel", "essid"],
246 "connector_types": ["devs"],
249 "help": "Generic executable command line application",
250 "category": FC.CATEGORY_APPLICATIONS,
251 "create_function": create_application,
252 "start_function": start_application,
253 "stop_function": stop_application,
254 "status_function": status_application,
255 "box_attributes": ["appId", "arguments", "path"],
256 "connector_types": ["node"],
257 "tags": [tags.APPLICATION],
261 testbed_attributes = dict({
262 "enable_debug": dict({
263 "name": "enableDebug",
264 "help": "Enable netns debug output",
265 "type": Attribute.BOOL,
267 "validation_function": validation.is_bool
272 "type": Attribute.STRING,
273 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
274 "validation_function": validation.is_string
278 "help": "OMF XMPP server host",
279 "type": Attribute.STRING,
280 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
281 "validation_function": validation.is_string
285 "help": "OMF XMPP service port",
286 "type": Attribute.INTEGER,
287 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
288 "validation_function": validation.is_integer
290 "xmppPassword": dict({
291 "name": "xmppPassword",
292 "help": "OMF XMPP slice password",
293 "type": Attribute.STRING,
294 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
295 "validation_function": validation.is_string
299 supported_recovery_policies = [
303 class MetadataInfo(metadata.MetadataInfo):
305 def connector_types(self):
306 return connector_types
309 def connections(self):
313 def attributes(self):
321 def create_order(self):
325 def configure_order(self):
326 return configure_order
329 def factories_info(self):
330 return factories_info
333 def testbed_attributes(self):
334 return testbed_attributes
337 def testbed_id(self):
341 def testbed_version(self):
342 return TESTBED_VERSION
345 def supported_recover_policies(self):
346 return supported_recovery_policies