+ def _get_factory_id(self, guid):
+ """ Returns the factory ID of the (perhaps not yet) created object """
+ return self._create.get(guid, None)
+
+ def _validate_guid(self, guid):
+ if not guid in self._create:
+ raise RuntimeError("Element guid %d doesn't exist" % guid)
+
+ def _validate_not_guid(self, guid):
+ if guid in self._create:
+ raise AttributeError("Cannot add elements with the same guid: %d" %
+ guid)
+
+ def _validate_factory_id(self, factory_id):
+ if factory_id not in self._factories:
+ raise AttributeError("Invalid element type %s for testbed version %s" %
+ (factory_id, self._testbed_version))
+
+ def _validate_testbed_attribute(self, name):
+ if not self._attributes.has_attribute(name):
+ raise AttributeError("Invalid testbed attribute %s for testbed" % \
+ name)
+
+ def _validate_testbed_value(self, name, value):
+ if not self._attributes.is_attribute_value_valid(name, value):
+ raise AttributeError("Invalid value %r for testbed attribute %s" % \
+ (value, name))
+
+ def _validate_box_attribute(self, guid, name):
+ factory = self._get_factory(guid)
+ if not factory.box_attributes.has_attribute(name):
+ raise AttributeError("Invalid attribute %s for element type %s" %
+ (name, factory.factory_id))
+
+ def _validate_box_value(self, guid, name, value):
+ factory = self._get_factory(guid)
+ if not factory.box_attributes.is_attribute_value_valid(name, value):
+ raise AttributeError("Invalid value %r for attribute %s" % \
+ (value, name))
+
+ def _validate_factory_attribute(self, guid, name):
+ factory = self._get_factory(guid)
+ if not factory.has_attribute(name):
+ raise AttributeError("Invalid attribute %s for element type %s" %
+ (name, factory.factory_id))
+
+ def _validate_factory_value(self, guid, name, value):
+ factory = self._get_factory(guid)
+ if not factory.is_attribute_value_valid(name, value):
+ raise AttributeError("Invalid value %r for attribute %s" % \
+ (value, name))
+
+ def _validate_trace(self, guid, trace_name):
+ factory = self._get_factory(guid)
+ if not trace_name in factory.traces_list:
+ raise RuntimeError("Element type '%s' has no trace '%s'" %
+ (factory.factory_id, trace_name))
+
+ def _validate_allow_addresses(self, guid):
+ factory = self._get_factory(guid)
+ if not factory.allow_addresses:
+ raise RuntimeError("Element type '%s' doesn't support addresses" %
+ factory.factory_id)
+ attr_name = "maxAddresses"
+ if guid in self._create_set and attr_name in self._create_set[guid]:
+ max_addresses = self._create_set[guid][attr_name]
+ else:
+ factory = self._get_factory(guid)
+ max_addresses = factory.box_attributes.get_attribute_value(attr_name)
+ if guid in self._add_address:
+ count_addresses = len(self._add_address[guid])
+ if max_addresses == count_addresses:
+ raise RuntimeError("Element guid %d of type '%s' can't accept \
+ more addresses" % (guid, factory.factory_id))
+
+ def _validate_allow_routes(self, guid):
+ factory = self._get_factory(guid)
+ if not factory.allow_routes:
+ raise RuntimeError("Element type '%s' doesn't support routes" %
+ factory.factory_id)
+
+ def _validate_connection(self, guid1, connector_type_name1, guid2,
+ connector_type_name2, cross = False):
+ # can't connect with self
+ if guid1 == guid2:
+ raise AttributeError("Can't connect guid %d to self" % \
+ (guid1))
+ # the connection is already done, so ignore
+ connected = self.get_connected(guid1, connector_type_name1,
+ connector_type_name2)
+ if guid2 in connected:
+ return
+ count1 = self._get_connection_count(guid1, connector_type_name1)
+ factory1 = self._get_factory(guid1)
+ connector_type1 = factory1.connector_type(connector_type_name1)
+ if count1 == connector_type1.max:
+ raise AttributeError("Connector %s is full for guid %d" % \
+ (connector_type_name1, guid1))
+
+ def _validate_modify_box_value(self, guid, name):
+ factory = self._get_factory(guid)
+ if self._status > TS.STATUS_STARTED and \
+ (factory.box_attributes.is_attribute_exec_read_only(name) or \
+ factory.box_attributes.is_attribute_exec_immutable(name)):
+ raise AttributeError("Attribute %s can only be modified during experiment design" % name)
+