Ejemplo n.º 1
0
    def set(self, guid, name, value, time=TIME_NOW):
        super(TestbedController, self).set(guid, name, value, time)

        # TODO: take on account schedule time for the task
        factory_id = self._create[guid]
        if factory_id in self.DUMMY_FACTORIES:
            return

        factory = self._factories[factory_id]
        element = self._elements[guid]
        if factory_id in self.LOCAL_FACTORIES:
            setattr(element, name, value)
        elif not factory.box_attributes.is_attribute_metadata(name):
            if name == "Up":
                ipv4_guid = _get_ipv4_protocol_guid(self, guid)
                if not ipv4_guid in self._elements:
                    return
                ipv4 = self._elements[ipv4_guid]
                if value == False:
                    nint = ipv4.GetNInterfaces()
                    for i in xrange(0, nint):
                        ipv4.SetDown(i)
                else:
                    nint = ipv4.GetNInterfaces()
                    for i in xrange(0, nint):
                        ipv4.SetUp(i)
            else:
                ns3_value = self._to_ns3_value(guid, name, value)
                self._set_attribute(name, ns3_value, element)
Ejemplo n.º 2
0
    def get(self, guid, name, time=TIME_NOW):
        value = super(TestbedController, self).get(guid, name, time)

        # TODO: take on account schedule time for the task
        factory_id = self._create[guid]
        if factory_id in self.DUMMY_FACTORIES:
            return

        factory = self._factories[factory_id]
        element = self._elements[guid]
        if factory_id in self.LOCAL_FACTORIES:
            if hasattr(element, name):
                return getattr(element, name)
            else:
                return value
        else:
            if name == "Up":
                ipv4_guid = _get_ipv4_protocol_guid(self, guid)
                if not ipv4_guid in self._elements:
                    return True
                ipv4 = self._elements[ipv4_guid]
                nint = ipv4.GetNInterfaces()
                value = True
                for i in xrange(0, nint):
                    value = ipv4.IsUp(i)
                    if not value:
                        break
                return value

        if factory.box_attributes.is_attribute_metadata(name):
            return value

        TypeId = self.ns3.TypeId()
        typeid = TypeId.LookupByName(factory_id)
        info = TypeId.AttributeInformation()
        if not typeid or not typeid.LookupAttributeByName(name, info):
            raise AttributeError("Invalid attribute %s for element type %d" % (name, guid))
        checker = info.checker
        ns3_value = checker.Create()
        self._get_attribute(name, ns3_value, element)
        value = ns3_value.SerializeToString(checker)
        attr_type = factory.box_attributes.get_attribute_type(name)

        if attr_type == Attribute.INTEGER:
            return int(value)
        if attr_type == Attribute.DOUBLE:
            return float(value)
        if attr_type == Attribute.BOOL:
            return value == "true"
        return value