Exemplo n.º 1
0
  /**
   * TODO
   *
   * @param attributes TODO
   * @param attributeName TODO
   * @return TODO
   */
  private Attribute getPhysicalPortAttribute(
      List<Attribute> attributes, AttributeName attributeName) {
    for (Attribute attribute : attributes) {
      if (attribute.getAttributeName().equals(attributeName)) {
        return attribute;
      }
    }

    return null;
  }
Exemplo n.º 2
0
  /**
   * TODO
   *
   * @param attribute TODO
   * @param physicalResourceRequirement TODO
   * @return TODO
   */
  private boolean checkPhysicalPortAttributeSatisfied(
      Attribute attribute, PhysicalResourceRequirement physicalResourceRequirement)
      throws VNMappingException {
    ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();

    InstanceIdentifier<PhysicalPortAttributeDefinition> physicalPortAttributeDefinitionIid =
        InstanceIdentifier.builder(PhysicalPortAttributeDefinitions.class)
            .child(
                PhysicalPortAttributeDefinition.class,
                new PhysicalPortAttributeDefinitionKey(attribute.getAttributeName()))
            .build();
    Optional<PhysicalPortAttributeDefinition> result;

    try {
      result =
          readOnlyTransaction
              .read(LogicalDatastoreType.CONFIGURATION, physicalPortAttributeDefinitionIid)
              .get();
    } catch (InterruptedException exception) {
      throw new VNMappingException(
          "Can not read the physical port attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    } catch (ExecutionException exception) {
      throw new VNMappingException(
          "Can not read the physical port attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    }

    if (!result.isPresent()) {
      throw new VNMappingException(
          "The physical port attribute definition with attribute name "
              + attribute.getAttributeName().getValue()
              + " does not exist.");
    }

    PhysicalPortAttributeDefinition physicalPortAttributeDefinition = result.get();
    List<AttributeMatchPatterns.AttributeMatchPattern> attributeMatchPatterns =
        physicalPortAttributeDefinition.getAttributeMatchPatterns().getAttributeMatchPattern();
    PhysicalResourceRequirement.AttributeMatchPattern attributeMatchPattern =
        physicalResourceRequirement.getAttributeMatchPattern();

    if (!checkAttributeMatchPatternSpecified(attributeMatchPatterns, attributeMatchPattern)) {
      throw new VNMappingException(
          "The attribute match pattern "
              + attributeMatchPattern
              + " is not specified in the physical port attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    }

    switch (physicalPortAttributeDefinition.getAttributeValueType()) {
      case String:
        return checkAttributeStringValueSatisfied(
            attribute.getAttributeValue().getStringValue(),
            physicalResourceRequirement.getAttributeValue().getStringValue(),
            attributeMatchPattern);

      case Int:
        return checkAttributeIntegerValueSatisfied(
            attribute.getAttributeValue().getIntValue(),
            physicalResourceRequirement.getAttributeValue().getIntValue(),
            attributeMatchPattern);

      case Range:
        return checkAttributeRangeValueSatisfied(
            attribute.getAttributeValue().getIntValue(),
            physicalResourceRequirement.getAttributeValue().getRangeValue(),
            attributeMatchPattern);

      default:
        throw new VNMappingException(
            "Unsupported physical port attribute value type "
                + physicalPortAttributeDefinition.getAttributeValueType()
                + ".");
        //                break;
    }

    //        return false;
  }