2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import metadata
6 from nepi.core.attributes import Attribute
7 from nepi.util import validation, tags
8 from nepi.util.constants import ApplicationStatus as AS
14 ### Connection functions ####
16 def connect_cross(testbed_instance, guid, cross_data):
18 testbed_instance.set(guid, "cross", True)
20 ### Creation functions ###
22 def create_node(testbed_instance, guid):
23 testbed_instance.elements[guid] = NODE
25 def create_iface(testbed_instance, guid):
26 testbed_instance.elements[guid] = IFACE
28 def create_application(testbed_instance, guid):
29 testbed_instance.elements[guid] = APP
31 ### Start/Stop functions ###
33 ### Status functions ###
35 def status_application(testbed_instance, guid):
36 return AS.STATUS_FINISHED
38 ### Factory information ###
40 connector_types = dict({
42 "help": "Connector from node to applications",
48 "help": "Connector from node to network interfaces",
54 "help": "Connector to a Node",
60 "help": "Connector to a Interface",
66 "help": "Connector to an Interface in other testbed",
75 "from": (TESTBED_ID, NODE, "devs"),
76 "to": (TESTBED_ID, IFACE, "node"),
80 "from": (TESTBED_ID, IFACE, "iface"),
81 "to": (TESTBED_ID, IFACE, "iface"),
85 "from": (TESTBED_ID, NODE, "apps"),
86 "to": (TESTBED_ID, APP, "node"),
90 "from": (TESTBED_ID, IFACE, "cross"),
91 "to": ("mock2", IFACE, "cross"),
92 "init_code": connect_cross,
99 "help": "fake attribute",
100 "type": Attribute.BOOL,
102 "validation_function": validation.is_bool
106 "help": "test attribute",
107 "type": Attribute.STRING,
108 "validation_function": validation.is_string
112 "help": "Attribute that indicates if cross connection was performed",
113 "type": Attribute.BOOL,
115 "validation_function": validation.is_bool
117 "MaxAddresses": dict({
118 "name": "MaxAddresses",
119 "help": "Attribute that indicates the maximum number of addresses for an interface",
120 "type": Attribute.INTEGER,
122 "flags": Attribute.Invisible,
123 "validation_function": validation.is_integer
134 factories_order = [ NODE, IFACE, APP ]
136 factories_info = dict({
139 "category": "topology",
140 "create_function": create_node,
141 "start_function": None,
142 "stop_function": None,
143 "status_function": None,
144 "box_attributes": ["fake","test"],
145 "connector_types": ["devs", "apps"],
146 "tags": [tags.MOBILE, tags.NODE, tags.ALLOW_ROUTES],
149 "help": "Fake iface",
150 "category": "devices",
151 "create_function": create_iface,
152 "start_function": None,
153 "stop_function": None,
154 "status_function": None,
155 "allow_addresses": True,
156 "factory_attributes": ["fake", "MaxAddresses"],
157 "box_attributes": ["fake", "test", "cross"],
158 "connector_types": ["node", "iface", "cross"],
159 "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
162 "help": "Fake application",
163 "category": "applications",
164 "create_function": create_application,
165 "start_function": None,
166 "stop_function": None,
167 "status_function": status_application,
168 "box_attributes": ["fake", "test"],
169 "connector_types": ["node"],
171 "tags": [tags.APPLICATION],
175 testbed_attributes = dict({
178 "help": "fake attribute",
179 "type": Attribute.BOOL,
183 "validation_function": validation.is_bool
187 "help": "test attribute",
188 "type": Attribute.STRING,
189 "validation_function": validation.is_string
193 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
195 def connector_types(self):
196 return connector_types
199 def connections(self):
203 def attributes(self):
211 def create_order(self):
212 return factories_order
215 def configure_order(self):
216 return factories_order
219 def factories_info(self):
220 return factories_info
223 def testbed_attributes(self):
224 return testbed_attributes