예제 #1
0
  /**
   * TODO
   *
   * @param user TODO
   * @param operation TODO
   * @param flow TODO
   * @param goThroughAction TODO
   * @param virtualNetwork TODO
   * @param userIntentVnMapping TODO
   */
  private void resolveGoThroughAction(
      User user,
      Operation operation,
      Flow flow,
      Action goThroughAction,
      VirtualNetwork virtualNetwork,
      UserIntentVnMapping userIntentVnMapping)
      throws IntentResolutionException {
    List<StringValue> parameterValues = goThroughAction.getParameterValues().getStringValue();

    if (!parameterValues.isEmpty()) {
      List<Node> nodes = user.getObjects().getNode();

      if (null == nodes || nodes.isEmpty()) {
        throw new IntentResolutionException(
            "The nodes specified by the action parameters "
                + "of the operation "
                + operation.getOperationId().getValue()
                + " does not exist.");
      }

      NodeId nodeId = new NodeId(parameterValues.get(0).getValue());
      Node node = IntentResolverUtils.getNode(nodes, nodeId);

      if (null == node) {
        throw new IntentResolutionException(
            "The node "
                + nodeId.getValue()
                + " specified by the"
                + " action parameter of the operation "
                + operation.getOperationId().getValue()
                + " does not exist.");
      }

      List<VirtualNode> virtualNodes = virtualNetwork.getVirtualNodes().getVirtualNode();
      List<VirtualLink> virtualLinks = virtualNetwork.getVirtualLinks().getVirtualLink();
      List<VirtualPath> virtualPaths = virtualNetwork.getVirtualPaths().getVirtualPath();
      List<IntentVnMappingResult> intentVnMappingResults =
          userIntentVnMapping.getIntentVnMappingResult();
      List<VirtualResource> virtualResources = null;

      if (node.getNodeType().equals(new NodeType("chain-group"))) {
        if (IntentResolverUtils.checkAllLayer2OperatingMode(node.getSubNode(), nodes)) {
          // TODO
        } else if (IntentResolverUtils.checkAllLayer3OperatingMode(node.getSubNode(), nodes)) {
          IntentVnMappingResult intentVnMappingResult =
              IntentResolverUtils.getIntentVnMappingResult(
                  intentVnMappingResults, new IntentId(node.getNodeId().getValue()));

          if (null == intentVnMappingResult) {
            throw new IntentResolutionException(
                "Can not get the intent-vn mapping result "
                    + "for the node "
                    + node.getNodeId().getValue()
                    + ".");
          }

          VirtualNode sourceVirtualNode =
              IntentResolverUtils.getSourceVirtualRouterOfFlow(
                  virtualNodes, flow, nodes, intentVnMappingResults);

          if (null == sourceVirtualNode) {
            throw new IntentResolutionException(
                "Can not get the source virtual node "
                    + "of the flow "
                    + flow.getFlowId().getValue()
                    + ".");
          }

          VirtualNode destinationVirtualNode =
              IntentResolverUtils.getDestinationVirtualRouterOfFlow(
                  virtualNodes, flow, nodes, intentVnMappingResults);

          if (null == destinationVirtualNode) {
            throw new IntentResolutionException(
                "Can not get the destination virtual node "
                    + "of the flow "
                    + flow.getFlowId().getValue()
                    + ".");
          }

          List<VirtualResource> virtualResources1 =
              IntentResolverUtils.sortVirtualResources(intentVnMappingResult.getVirtualResource());

          VirtualNodeId virtualNodeId =
              new VirtualNodeId(
                  virtualResources1.get(0).getParentVirtualResourceEntityId().getValue());
          VirtualNode virtualNode = IntentResolverUtils.getVirtualNode(virtualNodes, virtualNodeId);

          if (null == virtualNode) {
            throw new IntentResolutionException(
                "Can not get the virtual node"
                    + " created for the first sub-node of the node "
                    + intentVnMappingResult.getIntentId().getValue()
                    + ".");
          }

          virtualNodeId =
              new VirtualNodeId(
                  virtualResources1
                      .get(virtualResources1.size() - 1)
                      .getParentVirtualResourceEntityId()
                      .getValue());
          VirtualNode virtualNode1 =
              IntentResolverUtils.getVirtualNode(virtualNodes, virtualNodeId);

          if (null == virtualNode1) {
            throw new IntentResolutionException(
                "Can not get the virtual node"
                    + " created for the last sub-node of the node "
                    + intentVnMappingResult.getIntentId().getValue()
                    + ".");
          }

          virtualResources = new ArrayList<VirtualResource>(virtualResources1.size() + 2);
          VirtualLink virtualLink =
              IntentResolverUtils.getVirtualLink(
                  virtualLinks, sourceVirtualNode.getNodeId(), virtualNode.getNodeId());

          if (null == virtualLink) {
            VirtualPort virtualPort =
                new VirtualPortBuilder()
                    .setPortId(new VirtualPortId(UUID.randomUUID().toString()))
                    .setPortType(VirtualPort.PortType.Internal)
                    .build();
            sourceVirtualNode.getVirtualPort().add(virtualPort);

            VirtualPort virtualPort1 =
                new VirtualPortBuilder()
                    .setPortId(new VirtualPortId(UUID.randomUUID().toString()))
                    .setPortType(VirtualPort.PortType.Internal)
                    .build();
            virtualNode.getVirtualPort().add(virtualPort1);

            virtualLink =
                new VirtualLinkBuilder()
                    .setLinkId(new VirtualLinkId(UUID.randomUUID().toString()))
                    .setSrcNodeId(virtualNode.getNodeId())
                    .setSrcPortId(virtualPort1.getPortId())
                    .setDestNodeId(sourceVirtualNode.getNodeId())
                    .setDestPortId(virtualPort.getPortId())
                    .setBandwidth(0L)
                    .build();
            virtualLinks.add(virtualLink);

            virtualLink =
                new VirtualLinkBuilder()
                    .setLinkId(new VirtualLinkId(UUID.randomUUID().toString()))
                    .setSrcNodeId(sourceVirtualNode.getNodeId())
                    .setSrcPortId(virtualPort.getPortId())
                    .setDestNodeId(virtualNode.getNodeId())
                    .setDestPortId(virtualPort1.getPortId())
                    .setBandwidth(0L)
                    .build();
            virtualLinks.add(virtualLink);
          }

          List<
                  org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual
                      .network.rev151010.virtual.path.instance.VirtualLink>
              virtualLinks1 =
                  new ArrayList<
                      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic
                          .virtual.network.rev151010.virtual.path.instance.VirtualLink>(1);
          org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
                  .rev151010.virtual.path.instance.VirtualLink
              virtualLink1 =
                  new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic
                          .virtual.network.rev151010.virtual.path.instance.VirtualLinkBuilder()
                      .setLinkId(virtualLink.getLinkId())
                      .setOrder(0L)
                      .build();
          virtualLinks1.add(virtualLink1);

          VirtualPath virtualPath =
              new VirtualPathBuilder()
                  .setPathId(new VirtualPathId(UUID.randomUUID().toString()))
                  .setVirtualLink(virtualLinks1)
                  .setBandwidth(0L)
                  .build();
          virtualPaths.add(virtualPath);

          VirtualResource virtualResource =
              new VirtualResourceBuilder()
                  .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
                  .setVirtualResourceType(VirtualResource.VirtualResourceType.Vpath)
                  .setVirtualResourceEntityId(
                      new VirtualResourceEntityId(virtualPath.getPathId().getValue()))
                  .setOrder(0L)
                  .build();
          virtualResources.add(virtualResource);

          for (VirtualResource virtualResource1 : virtualResources1) {
            virtualResource =
                new VirtualResourceBuilder(virtualResource1)
                    .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
                    .setOrder((long) virtualResources.size())
                    .build();
            virtualResources.add(virtualResource);
          }

          virtualLink =
              IntentResolverUtils.getVirtualLink(
                  virtualLinks, virtualNode1.getNodeId(), destinationVirtualNode.getNodeId());

          if (null == virtualLink) {
            VirtualPort virtualPort =
                new VirtualPortBuilder()
                    .setPortId(new VirtualPortId(UUID.randomUUID().toString()))
                    .setPortType(VirtualPort.PortType.Internal)
                    .build();
            virtualNode1.getVirtualPort().add(virtualPort);

            VirtualPort virtualPort1 =
                new VirtualPortBuilder()
                    .setPortId(new VirtualPortId(UUID.randomUUID().toString()))
                    .setPortType(VirtualPort.PortType.Internal)
                    .build();
            destinationVirtualNode.getVirtualPort().add(virtualPort1);

            virtualLink =
                new VirtualLinkBuilder()
                    .setLinkId(new VirtualLinkId(UUID.randomUUID().toString()))
                    .setSrcNodeId(destinationVirtualNode.getNodeId())
                    .setSrcPortId(virtualPort1.getPortId())
                    .setDestNodeId(virtualNode1.getNodeId())
                    .setDestPortId(virtualPort.getPortId())
                    .setBandwidth(0L)
                    .build();
            virtualLinks.add(virtualLink);

            virtualLink =
                new VirtualLinkBuilder()
                    .setLinkId(new VirtualLinkId(UUID.randomUUID().toString()))
                    .setSrcNodeId(virtualNode1.getNodeId())
                    .setSrcPortId(virtualPort.getPortId())
                    .setDestNodeId(destinationVirtualNode.getNodeId())
                    .setDestPortId(virtualPort1.getPortId())
                    .setBandwidth(0L)
                    .build();
            virtualLinks.add(virtualLink);
          }

          virtualLinks1 =
              new ArrayList<
                  org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual
                      .network.rev151010.virtual.path.instance.VirtualLink>(1);
          virtualLink1 =
              new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual
                      .network.rev151010.virtual.path.instance.VirtualLinkBuilder()
                  .setLinkId(virtualLink.getLinkId())
                  .setOrder(0L)
                  .build();
          virtualLinks1.add(virtualLink1);

          virtualPath =
              new VirtualPathBuilder()
                  .setPathId(new VirtualPathId(UUID.randomUUID().toString()))
                  .setVirtualLink(virtualLinks1)
                  .setBandwidth(0L)
                  .build();
          virtualPaths.add(virtualPath);

          virtualResource =
              new VirtualResourceBuilder()
                  .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
                  .setVirtualResourceType(VirtualResource.VirtualResourceType.Vpath)
                  .setVirtualResourceEntityId(
                      new VirtualResourceEntityId(virtualPath.getPathId().getValue()))
                  .setOrder((long) virtualResources.size())
                  .build();
          virtualResources.add(virtualResource);
        } else {
          // TODO
        }
      } else {
        // TODO
      }

      IntentVnMappingResult intentVnMappingResult =
          new IntentVnMappingResultBuilder()
              .setIntentId(new IntentId(operation.getOperationId().getValue()))
              .setIntentType(IntentVnMappingResult.IntentType.Operation)
              .setVirtualResource(virtualResources)
              .build();

      intentVnMappingResults.add(intentVnMappingResult);
    }

    return;
  }
  @Test
  public void testCheckOperationTemplate() throws Exception {
    method =
        class1.getDeclaredMethod(
            "checkOperationTemplate", new Class[] {AbstractOperation.class, Map.class});
    method.setAccessible(true);
    field = class1.getDeclaredField("getDefinitions");
    field.setAccessible(true);

    GetDefinitions getDefinitions = mock(GetDefinitions.class);
    Action action = mock(Action.class);
    ActionName actionName = mock(ActionName.class);
    ActionDefinition actionDefinition = mock(ActionDefinition.class);
    AbstractOperation operation = mock(AbstractOperation.class);
    ConditionSegment conditionSegment = mock(ConditionSegment.class);
    ParameterName parameterName = mock(ParameterName.class);
    ParameterValues parameterValues = mock(ParameterValues.class);
    ConditionParameterName conditionParameterName = mock(ConditionParameterName.class);
    ConditionParameterDefinition definition = mock(ConditionParameterDefinition.class);
    ConditionParameterDefinition conditionParameterDefinition =
        mock(ConditionParameterDefinition.class);
    ConditionParameterTargetValue conditionParameterTargetValue =
        mock(ConditionParameterTargetValue.class);
    ConditionParameterDefinition.ParameterValueType type =
        ConditionParameterDefinition.ParameterValueType.String;
    TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
    ActionDefinition.ParameterValueType type1 = ActionDefinition.ParameterValueType.String;
    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action
            .instance.parameter.values.StringValue
        stringValue =
            mock(
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation
                    .rev151010.action.instance.parameter.values.StringValue.class);
    List<Action> actionList = new ArrayList<Action>();
    List<
            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation
                .rev151010.action.instance.parameter.values.StringValue>
        stringValues =
            new ArrayList<
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation
                    .rev151010.action.instance.parameter.values.StringValue>();
    List<ConditionSegment> conditionSegmentList = new ArrayList<ConditionSegment>();
    Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap =
        new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
    Map<ActionName, ActionDefinition> actionDefinitionMap =
        new HashMap<ActionName, ActionDefinition>();
    Map<ParameterName, ConditionParameterDefinition> conditionParameterDefinitionMap =
        mock(Map.class);

    field.set(updateTemplateDefinition, getDefinitions);
    conditionSegmentList.add(conditionSegment);
    parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType);
    conditionParameterDefinitionMap.put(parameterName, conditionParameterDefinition);

    when(getDefinitions.getActionDefinition()).thenReturn(actionDefinitionMap);
    when(getDefinitions.getConditionParameterDefinition())
        .thenReturn(conditionParameterDefinitionMap);
    when(operation.getConditionSegment()).thenReturn(null).thenReturn(conditionSegmentList);
    when(operation.getAction()).thenReturn(null).thenReturn(actionList);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
    // test condition
    when(conditionSegment.getConditionParameterName()).thenReturn(conditionParameterName);
    when(conditionParameterDefinitionMap.containsKey(conditionSegment.getConditionParameterName()))
        .thenReturn(false)
        .thenReturn(true);
    when(parameterName.getValue()).thenReturn("test");
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, operation, parameterValueTypeMap)
            .equals(
                "The Condition "
                    + conditionSegment.getConditionParameterName().getValue()
                    + " is not defined."));
    when(conditionSegment.getConditionParameterTargetValue())
        .thenReturn(null)
        .thenReturn(conditionParameterTargetValue);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
    when(conditionParameterDefinitionMap.get(conditionSegment.getConditionParameterName()))
        .thenReturn(definition);
    when(definition.getParameterValueType())
        .thenReturn(ConditionParameterDefinition.ParameterValueType.Int)
        .thenReturn(type);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
    when(conditionParameterTargetValue.getStringValue()).thenReturn("ParameterName");
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, operation, parameterValueTypeMap)
            .equals(
                "The condition "
                    + conditionSegment.getConditionParameterName().getValue()
                    + " type is not right."));

    // test action
    conditionSegmentList.clear();
    actionList.add(action);
    stringValues.add(stringValue);

    when(action.getActionName()).thenReturn(actionName);
    when(actionName.getValue()).thenReturn("test");
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, operation, parameterValueTypeMap)
            .equals("The action " + action.getActionName().getValue() + " is not defined."));
    actionDefinitionMap.put(actionName, actionDefinition);
    when(action.getParameterValues()).thenReturn(null).thenReturn(parameterValues);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
    when(actionDefinition.getParameterValueType()).thenReturn(type1);
    when(parameterValues.getStringValue()).thenReturn(stringValues);
    when(stringValue.getValue()).thenReturn("ParameterName");
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, operation, parameterValueTypeMap)
            .equals("The action " + action.getActionName().getValue() + " type is not right."));
  }