예제 #1
0
  /**
   * TODO
   *
   * @param physicalPort TODO
   * @param physicalResourceRequirements TODO
   * @return TODO
   */
  private boolean checkPhysicalPortSatisfied(
      PhysicalPort physicalPort, List<PhysicalResourceRequirement> physicalResourceRequirements)
      throws VNMappingException {
    List<Attribute> attributes = physicalPort.getAttribute();
    Attribute attribute;

    for (PhysicalResourceRequirement physicalResourceRequirement : physicalResourceRequirements) {
      attribute =
          getPhysicalPortAttribute(attributes, physicalResourceRequirement.getAttributeName());

      if (null == attribute) {
        return false;
      }

      if (!checkPhysicalPortAttributeSatisfied(attribute, physicalResourceRequirement)) {
        return false;
      }
    }

    return true;
  }
예제 #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;
  }