2 # -*- coding: utf-8 -*-
4 from nepi.core.attributes import Attribute, AttributesMap
5 from nepi.util import validation
8 class ConnectorType(object):
9 def __init__(self, testbed_id, factory_id, name, max = -1, min = 0):
10 super(ConnectorType, self).__init__()
15 "The maximum number of connections allowed need to be more than 0")
18 "The minimum number of connections allowed needs to be at least 0")
19 # connector_type_id -- univoquely identifies a connector type
21 self._connector_type_id = (testbed_id.lower(), factory_id.lower(),
23 # name -- display name for the connector type
25 # max -- maximum amount of connections that this type support,
28 # min -- minimum amount of connections required by this type of connector
30 # from_connections -- connections where the other connector is the "From"
31 # to_connections -- connections where the other connector is the "To"
32 # keys in the dictionary correspond to the
33 # connector_type_id for possible connections. The value is a tuple:
34 # (can_cross, connect)
35 # can_cross: indicates if the connection is allowed accros different
37 # code: is the connection function to be invoked when the elements
39 self._from_connections = dict()
40 self._to_connections = dict()
43 def connector_type_id(self):
44 return self._connector_type_id
58 def add_from_connection(self, testbed_id, factory_id, name, can_cross, code):
59 self._from_connections[(testbed_id.lower(), factory_id.lower(),
60 name.lower())] = (can_cross, code)
62 def add_to_connection(self, testbed_id, factory_id, name, can_cross, code):
63 self._to_connections[(testbed_id.lower(), factory_id.lower(),
64 name.lower())] = (can_cross, code)
66 def can_connect(self, testbed_id, factory_id, name, count,
68 connector_type_id = (testbed_id.lower(), factory_id.lower(),
70 if connector_type_id in self._from_connections:
71 (can_cross, code) = self._from_connections[connector_type_id]
72 elif connector_type_id in self._to_connections:
73 (can_cross, code) = self._to_connections[connector_type_id]
76 return not must_cross or can_cross
78 def code_to_connect(self, testbed_id, factory_id, name):
79 connector_type_id = (testbed_id.lower(), factory_id.lower(),
81 if not connector_type_id in self._to_connections.keys():
83 (can_cross, code) = self._to_connections[connector_type_id]
86 # TODO: create_function, start_function, stop_function, status_function
88 class Factory(AttributesMap):
89 def __init__(self, factory_id, create_function, start_function,
90 stop_function, status_function, allow_addresses = False,
91 allow_routes = False):
92 super(Factory, self).__init__()
93 self._factory_id = factory_id
94 self._allow_addresses = (allow_addresses == True)
95 self._allow_routes = (allow_routes == True)
96 self._create_function = create_function
97 self._start_function = start_function
98 self._stop_function = stop_function
99 self._status_function = status_function
100 self._connector_types = dict()
101 self._traces = list()
104 def factory_id(self):
105 return self._factory_id
108 def allow_addresses(self):
109 return self._allow_addresses
112 def allow_routes(self):
113 return self._allow_routes
116 def create_function(self):
117 return self._create_function
120 def start_function(self):
121 return self._start_function
124 def stop_function(self):
125 return self._stop_function
128 def status_function(self):
129 return self._status_function
135 def connector_type(self, name):
136 return self._connector_types[name]
138 def add_connector_type(self, connector_type):
139 self._connector_types[connector_type.name] = connector_type
141 def add_trace(self, trace_id):
142 self._traces.append(trace_id)
144 class TestbedConfiguration(AttributesMap):
146 super(TestbedConfiguration, self).__init__()
147 self.add_attribute("HomeDirectory",
148 "Path to the local directory where traces and other files \
150 Attribute.STRING, False, None, None, "",
151 validation.is_string)
153 class TestbedInstance(object):
154 def __init__(self, testbed_id, testbed_version, configuration):
155 self._testbed_id = testbed_id
156 self._testbed_version = testbed_version
157 self._configuration = configuration
158 self._home_directory = configuration.get_attribute_value(
162 def home_directory(self):
163 return self._home_directory
165 def create(self, guid, factory_id):
166 """Instructs creation of element """
167 raise NotImplementedError
169 def create_set(self, guid, name, value):
170 """Instructs setting an attribute on an element"""
171 raise NotImplementedError
174 """After do_create all instructed elements are created and
176 raise NotImplementedError
178 def connect(self, guid1, connector_type_name1, guid2,
179 connector_type_name2):
180 raise NotImplementedError
182 def cross_connect(self, guid, connector_type_name, cross_guid,
183 cross_testbed_id, cross_factory_id, cross_connector_type_name):
184 raise NotImplementedError
186 def do_connect(self):
187 raise NotImplementedError
189 def add_trace(self, guid, trace_id):
190 raise NotImplementedError
192 def add_adddress(self, guid, family, address, netprefix, broadcast):
193 raise NotImplementedError
195 def add_route(self, guid, destination, netprefix, nexthop):
196 raise NotImplementedError
198 def do_configure(self):
199 raise NotImplementedError
201 def do_cross_connect(self):
202 raise NotImplementedError
204 def set(self, time, guid, name, value):
205 raise NotImplementedError
207 def get(self, time, guid, name):
208 raise NotImplementedError
210 def start(self, time):
211 raise NotImplementedError
213 def action(self, time, guid, action):
214 raise NotImplementedError
216 def stop(self, time):
217 raise NotImplementedError
219 def status(self, guid):
220 raise NotImplementedError
222 def trace(self, guid, trace_id):
223 raise NotImplementedError
226 raise NotImplementedError