@org.junit.Test
  public void testCheckAllLayer3OperatingMode() throws Exception {

    when(subNode.getNodeId()).thenReturn(nodeId);
    NodeId otherid;
    otherid = mock(NodeId.class);
    when(node.getNodeId()).thenReturn(otherid);
    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);

    when(node.getNodeId()).thenReturn(nodeId);
    when(subNode.getNodeId()).thenReturn(nodeId);
    // into getNodeProperty
    when(node.getProperty()).thenReturn(propertyList);
    propertyName = new PropertyName("operating-other");
    when(property.getPropertyName()).thenReturn(propertyName);
    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);

    when(node.getNodeId()).thenReturn(nodeId);
    when(subNode.getNodeId()).thenReturn(nodeId);
    when(node.getProperty()).thenReturn(propertyList);
    propertyName = new PropertyName("operating-mode");
    when(property.getPropertyName()).thenReturn(propertyName);
    when(property.getPropertyValues()).thenReturn(propertyValues);
    when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
    when(property.getPropertyValues().getStringValue().get(0).getValue())
        .thenReturn(new String("layer3"));

    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), true);
  }
 @org.junit.Test
 public void testGetPhysicalHost() throws Exception {
   when(node.getNodeId()).thenReturn(nodeId);
   when(node.getNodeId().getValue())
       .thenReturn(new String("00001111-0000-0000-0000-000011112222"));
   physicalHostId = new PhysicalHostId(node.getNodeId().getValue());
   // into getPhysicalHost
   when(physicalHost.getHostId()).thenReturn(physicalHostId);
   Assert.assertEquals(intentResolverUtils.getPhysicalHost(physicalHostList, node), physicalHost);
 }
  @org.junit.Test
  public void testGetObject() throws Exception {
    when(objects.getNode()).thenReturn(nodeList);
    when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
    NodeId nodeId2 = new NodeId(objectId.getValue());
    // into getnode
    when(node.getNodeId()).thenReturn(nodeId2);
    Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), node);

    when(objects.getNode()).thenReturn(nodeListnull);
    when(objects.getConnection()).thenReturn(connectionList);
    when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
    ConnectionId connectionId2 = new ConnectionId(objectId.getValue());
    // into getconnection
    when(connection.getConnectionId()).thenReturn(connectionId2);
    Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), connection);

    when(objects.getNode()).thenReturn(nodeListnull);
    when(objects.getConnection()).thenReturn(connectionListnull);
    when(objects.getFlow()).thenReturn(flowList);
    when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
    FlowId flowId2 = new FlowId(objectId.getValue());
    // into getflow
    when(flow.getFlowId()).thenReturn(flowId2);
    Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), flow);
  }
  @org.junit.Test
  public void testCheckExternalLayer3Group() throws Exception {
    when(node.getProperty()).thenReturn(propertyList);
    // into getNodeProperty
    propertyName = new PropertyName("ac-info-network");
    when(property.getPropertyName()).thenReturn(propertyName);
    when(property.getPropertyValues()).thenReturn(propertyValues);
    when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
    when(property.getPropertyValues().getStringValue().get(0).getValue())
        .thenReturn(new String("layer3"));

    Assert.assertEquals(intentResolverUtils.checkExternalLayer3Group(node), true);
  }
 @org.junit.Test
 public void testGetNode() throws Exception {
   when(node.getNodeId()).thenReturn(nodeId);
   Assert.assertEquals(intentResolverUtils.getNode(nodeList, nodeId), node);
 }
Beispiel #6
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;
  }