2 # -*- coding: utf-8 -*-
4 from nepi.core.attributes import AttributesMap
7 class ConnectorType(object):
8 def __init__(self, testbed_id, factory_id, name, max = -1, min = 0):
9 super(ConnectorType, self).__init__()
14 "The maximum number of connections allowed need to be more than 0")
17 "The minimum number of connections allowed needs to be at least 0")
18 # connector_type_id -- univoquely identifies a connector type
20 self._connector_type_id = (testbed_id.lower(), factory_id.lower(),
22 # name -- display name for the connector type
24 # max -- maximum amount of connections that this type support,
27 # min -- minimum amount of connections required by this type of connector
29 # from_connections -- connections where the other connector is the "From"
30 # to_connections -- connections where the other connector is the "To"
31 # keys in the dictionary correspond to the
32 # connector_type_id for possible connections. The value is a tuple:
33 # (can_cross, connect)
34 # can_cross: indicates if the connection is allowed accros different
36 # code: is the connection function to be invoked when the elements
38 self._from_connections = dict()
39 self._to_connections = dict()
42 def connector_type_id(self):
43 return self._connector_type_id
57 def add_from_connection(self, testbed_id, factory_id, name, can_cross, code):
58 self._from_connections[(testbed_id.lower(), factory_id.lower(),
59 name.lower())] = (can_cross, code)
61 def add_to_connection(self, testbed_id, factory_id, name, can_cross, code):
62 self._to_connections[(testbed_id.lower(), factory_id.lower(),
63 name.lower())] = (can_cross, code)
65 def can_connect(self, testbed_id, factory_id, name, count,
67 connector_type_id = (testbed_id.lower(), factory_id.lower(),
69 if connector_type_id in self._from_connections:
70 (can_cross, code) = self._from_connections[connector_type_id]
71 elif connector_type_id in self._to_connections:
72 (can_cross, code) = self._to_connections[connector_type_id]
75 return not must_cross or can_cross
77 def code_to_connect(self, testbed_id, factory_id, name):
78 connector_type_id = (testbed_id.lower(), factory_id.lower(),
80 if not connector_type_id in self._to_connections.keys():
82 (can_cross, code) = self._to_connections[connector_type_id]
85 # TODO: create_function, start_function, stop_function, status_function
87 class Factory(AttributesMap):
88 def __init__(self, factory_id, create_function, start_function,
89 stop_function, status_function, allow_addresses = False,
90 allow_routes = False):
91 super(Factory, self).__init__()
92 self._factory_id = factory_id
93 self._allow_addresses = (allow_addresses == True)
94 self._allow_routes = (allow_routes == True)
95 self._create_function = create_function
96 self._start_function = start_function
97 self._stop_function = stop_function
98 self._status_function = status_function
99 self._connector_types = dict()
100 self._traces = list()
103 def factory_id(self):
104 return self._factory_id
107 def allow_addresses(self):
108 return self._allow_addresses
111 def allow_routes(self):
112 return self._allow_routes
115 def create_function(self):
116 return self._create_function
119 def start_function(self):
120 return self._start_function
123 def stop_function(self):
124 return self._stop_function
127 def status_function(self):
128 return self._status_function
134 def connector_type(self, name):
135 return self._connector_types[name]
137 def add_connector_type(self, connector_type):
138 self._connector_types[connector_type.name] = connector_type
140 def add_trace(self, trace_id):
141 self._traces.append(trace_id)
143 class TestbedConfiguration(AttributesMap):
146 class TestbedInstance(object):
147 def __init__(self, testbed_version, configuration):
150 def create(self, guid, factory_id):
151 """Instructs creation of element """
152 raise NotImplementedError
154 def create_set(self, guid, name, value):
155 """Instructs setting an attribute on an element"""
156 raise NotImplementedError
159 """After do_create all instructed elements are created and
161 raise NotImplementedError
163 def connect(self, guid1, connector_type_name1, guid2,
164 connector_type_name2):
165 raise NotImplementedError
167 def cross_connect(self, guid, connector_type_name, cross_guid,
168 cross_testbed_id, cross_factory_id, cross_connector_type_name):
169 raise NotImplementedError
171 def do_connect(self):
172 raise NotImplementedError
174 def add_trace(self, guid, trace_id):
175 raise NotImplementedError
177 def add_adddress(self, guid, family, address, netprefix, broadcast):
178 raise NotImplementedError
180 def add_route(self, guid, family, destination, netprefix, nexthop,
182 raise NotImplementedError
184 def do_configure(self):
185 raise NotImplementedError
187 def do_cross_connect(self):
188 raise NotImplementedError
190 def set(self, time, guid, name, value):
191 raise NotImplementedError
193 def get(self, time, guid, name):
194 raise NotImplementedError
196 def start(self, time):
197 raise NotImplementedError
199 def action(self, time, guid, action):
200 raise NotImplementedError
202 def stop(self, time):
203 raise NotImplementedError
205 def status(self, guid):
206 raise NotImplementedError
208 def trace(self, guid, trace_id):
209 raise NotImplementedError
212 raise NotImplementedError