/** * TODO * * @param virtualNetwork TODO * @param unmappedVirtualLinks TODO * @param userVnPnMapping TODO * @param physicalPaths TODO * @throws VNMappingException */ public void virtualNetworkMapping( VirtualNetwork virtualNetwork, List<VirtualLink> unmappedVirtualLinks, UserVnPnMapping userVnPnMapping, List<PhysicalPath> physicalPaths) throws VNMappingException { UserId userId = virtualNetwork.getUserId(); List<VirtualLink> virtualLinks = virtualNetwork.getVirtualLinks().getVirtualLink(); List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); PhysicalPath physicalPath; VirtualLink newVirtualLink; VnPnMappingResult vnPnMappingResult; int i = virtualLinks.size() - unmappedVirtualLinks.size(); for (VirtualLink virtualLink : unmappedVirtualLinks) { 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(); virtualLinks.set(i++, 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); } return; }
/** * 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; }