@org.junit.Test public void testGetVirtualNode() throws Exception { when(virtualNode.getNodeId()).thenReturn(virtualNodeId); Assert.assertEquals( intentResolverUtils.getVirtualNode(virtualNodeList, virtualNodeId), virtualNode); }
/** * TODO * * @param virtualNetwork TODO * @param userVnPnMapping TODO * @param physicalPaths TODO */ public void virtualNetworkMapping( VirtualNetwork virtualNetwork, UserVnPnMapping userVnPnMapping, List<PhysicalPath> physicalPaths) throws VNMappingException { ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction(); InstanceIdentifier<PhysicalNodes> physicalNodesIid = InstanceIdentifier.builder(PhysicalNetwork.class).child(PhysicalNodes.class).build(); Optional<PhysicalNodes> result; try { result = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, physicalNodesIid).get(); } catch (InterruptedException exception) { throw new VNMappingException("Can not read the physical nodes."); } catch (ExecutionException exception) { throw new VNMappingException("Can not read the physical nodes."); } if (!result.isPresent()) { throw new VNMappingException( "Failed virtual network mapping caused by " + "absent underlying network topology."); } PhysicalNodes physicalNodes = result.get(); List<PhysicalNode> physicalNodeList = physicalNodes.getPhysicalNode(); UserId userId = virtualNetwork.getUserId(); List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); List<VirtualNode> virtualNodes = virtualNetwork.getVirtualNodes().getVirtualNode(); List<VirtualPort> virtualPorts; PhysicalNode physicalNode; PhysicalPort physicalPort; VnPnMappingResult vnPnMappingResult; for (VirtualNode virtualNode : virtualNodes) { physicalNode = virtualNodeMapping(virtualNetwork.getNetworkId(), virtualNode, physicalNodeList); if (null == physicalNode) { // If mapping failed, reset the user physical resources. pnResourcesTracker.resetResource(userId); throw new VNMappingException( "Failed mapping for the virtual node " + virtualNode.getNodeId().getValue() + " in the virtual network " + virtualNetwork.getNetworkId().getValue()); } // Keep physical resource. pnResourcesTracker.addPhysicalNode(userId, physicalNode); virtualPorts = virtualNode.getVirtualPort(); for (VirtualPort virtualPort : virtualPorts) { if (VirtualPort.PortType.External == virtualPort.getPortType()) { physicalPort = virtualPortMapping( virtualNetwork.getNetworkId(), virtualNode.getNodeId(), virtualPort, physicalNode); if (null == physicalPort) { // If mapping failed, reset the user physical resources. pnResourcesTracker.resetResource(userId); throw new VNMappingException( "Failed mapping for the virtual port " + virtualPort.getPortId().getValue() + " of the virtual node " + virtualNode.getNodeId().getValue() + " in the virtual network " + virtualNetwork.getNetworkId().getValue()); } // Keep physical resource. pnResourcesTracker.addPhysicalPort(userId, physicalPort); vnPnMappingResult = new VnPnMappingResultBuilder() .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString())) .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vport) .setVirtualResourceEntityId( new VirtualResourceEntityId(virtualPort.getPortId().getValue())) .setParentVirtualResourceEntityId( new VirtualResourceEntityId(virtualNode.getNodeId().getValue())) .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString())) .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Port) .setPhysicalResourceEntityId( new PhysicalResourceEntityId(physicalPort.getPortId().getValue())) .setParentPhysicalResourceEntityId( new PhysicalResourceEntityId(physicalNode.getNodeId().getValue())) .build(); vnPnMappingResults.add(vnPnMappingResult); } } vnPnMappingResult = new VnPnMappingResultBuilder() .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString())) .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vnode) .setVirtualResourceEntityId( new VirtualResourceEntityId(virtualNode.getNodeId().getValue())) .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString())) .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Node) .setPhysicalResourceEntityId( new PhysicalResourceEntityId(physicalNode.getNodeId().getValue())) .build(); vnPnMappingResults.add(vnPnMappingResult); } List<VirtualLink> virtualLinks = virtualNetwork.getVirtualLinks().getVirtualLink(); List<VirtualLink> newVirtualLinks = new ArrayList<VirtualLink>(virtualLinks.size()); PhysicalPath physicalPath; VirtualLink newVirtualLink; for (VirtualLink virtualLink : virtualLinks) { physicalPath = virtualLinkMapping(virtualNetwork.getNetworkId(), virtualLink, userVnPnMapping); if (null == physicalPath) { // If mapping failed, reset the user physical resources. pnResourcesTracker.resetResource(userId); throw new VNMappingException( "Failed mapping for the virtual link " + virtualLink.getLinkId().getValue() + " in the virtual network " + virtualNetwork.getNetworkId().getValue()); } // Keep physical resource. pnResourcesTracker.addPhysicalPath(userId, physicalPath); physicalPaths.add(physicalPath); newVirtualLink = new VirtualLinkBuilder(virtualLink) .setMetric(physicalPath.getMetric()) .setDelay(physicalPath.getDelay()) .build(); newVirtualLinks.add(newVirtualLink); vnPnMappingResult = new VnPnMappingResultBuilder() .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString())) .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vlink) .setVirtualResourceEntityId( new VirtualResourceEntityId(virtualLink.getLinkId().getValue())) .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString())) .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Path) .setPhysicalResourceEntityId( new PhysicalResourceEntityId(physicalPath.getPathId().getValue())) .build(); vnPnMappingResults.add(vnPnMappingResult); } virtualLinks.clear(); virtualLinks.addAll(newVirtualLinks); return; }
/** * 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; }
/** * TODO * * @param virtualNetworkId TODO * @param virtualNode TODO * @param physicalNodes TODO * @return TODO */ private PhysicalNode virtualNodeMapping( VirtualNetworkId virtualNetworkId, VirtualNode virtualNode, List<PhysicalNode> physicalNodes) throws VNMappingException { List< org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network .rev151010.virtual.node.instance.PhysicalResourceRequirement> physicalResourceRequirements = virtualNode.getPhysicalResourceRequirement(); List<PhysicalNode> candidates = new LinkedList<PhysicalNode>(); switch (virtualNode.getNodeType()) { case Vswitch: for (PhysicalNode physicalNode : physicalNodes) { if (PhysicalNode.NodeType.Switch == physicalNode.getNodeType()) { if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) { candidates.add(physicalNode); } } } break; case Vrouter: for (PhysicalNode physicalNode : physicalNodes) { if (PhysicalNode.NodeType.Router == physicalNode.getNodeType()) { if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) { candidates.add(physicalNode); } } } break; case Vfirewall: for (PhysicalNode physicalNode : physicalNodes) { if (PhysicalNode.NodeType.Firewall == physicalNode.getNodeType()) { if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) { candidates.add(physicalNode); } } } break; case Vloadbalancer: for (PhysicalNode physicalNode : physicalNodes) { if (PhysicalNode.NodeType.Loadbalancer == physicalNode.getNodeType()) { if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) { candidates.add(physicalNode); } } } break; default: throw new VNMappingException( "Unsupported virtual node type " + virtualNode.getNodeType() + "."); // break; } if (candidates.isEmpty()) { return null; } return candidates.get(0); }