@Test public void testVirtualLinkMapping() throws Exception{ method = class1.getDeclaredMethod("virtualLinkMapping",new Class[]{ VirtualNetworkId.class, VirtualLink.class, UserVnPnMapping.class }); method.setAccessible(true); VirtualNetworkId virtualNetworkId = mock(VirtualNetworkId.class); VirtualLink virtualLink = mock(VirtualLink.class); UserVnPnMapping userVnPnMapping = mock(UserVnPnMapping.class); VirtualNodeId virtualNodeId = mock(VirtualNodeId.class); VnPnMappingResult vnPnMappingResult = mock(VnPnMappingResult.class); PhysicalResourceEntityId physicalResourceEntityId = mock(PhysicalResourceEntityId.class); List<VnPnMappingResult> vnPnMappingResults = new ArrayList<VnPnMappingResult>(); vnPnMappingResults.add(vnPnMappingResult); when(userVnPnMapping.getVnPnMappingResult()).thenReturn(vnPnMappingResults); when(virtualLink.getSrcNodeId()).thenReturn(virtualNodeId); when(virtualLink.getDestNodeId()).thenReturn(virtualNodeId); when(virtualNodeId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); when(vnPnMappingResult.getVirtualResourceEntityId()).thenReturn(new VirtualResourceEntityId(new String("00001111-0000-0000-0000-000011112222"))); when(vnPnMappingResult.getPhysicalResourceEntityId()).thenReturn(physicalResourceEntityId); when(physicalResourceEntityId.getValue()) .thenReturn(new String("test")) .thenReturn(new String("test")) .thenReturn(new String("src")) .thenReturn(new String("dst")) .thenReturn(new String("src")) .thenReturn(new String("dst")); when(virtualLink.getBandwidth()) .thenReturn(1L) .thenReturn(0L) .thenReturn(1L); Assert.assertTrue((PhysicalPath) method.invoke(vnMappingUnit, virtualNetworkId, virtualLink, userVnPnMapping) != null); verify(virtualLink).getBandwidth(); when(pnComputationUnit.computePath(any(PhysicalNodeId.class), any(PhysicalNodeId.class))).thenReturn(null); when(pnComputationUnit.computePath(any(PhysicalNodeId.class), any(PhysicalNodeId.class), any(long.class))).thenReturn(null); Assert.assertTrue((PhysicalPath) method.invoke(vnMappingUnit, virtualNetworkId, virtualLink, userVnPnMapping) == null); Assert.assertTrue((PhysicalPath) method.invoke(vnMappingUnit, virtualNetworkId, virtualLink, userVnPnMapping) == null); verify(virtualLink,times(4)).getBandwidth(); }
private PhysicalPath virtualLinkMapping(VirtualNetworkId virtualNetworkId, VirtualLink virtualLink, UserVnPnMapping userVnPnMapping) throws VNMappingException { List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getSrcNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getSrcNodeId().getValue()); } PhysicalNodeId source = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getDestNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getDestNodeId().getValue()); } PhysicalNodeId target = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); if ( source.equals(target) ) { PhysicalPath physicalPath = new PhysicalPathBuilder() .setPathId(new PhysicalPathId(UUID.randomUUID().toString())) .setPhysicalLink(new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink>(0)) .setMetric(0L) .setBandwidth(virtualLink.getBandwidth()) .setDelay(0L) .build(); return physicalPath; } PhysicalPath physicalPath; if ( 0 == virtualLink.getBandwidth() ) { physicalPath = pnComputationUnit.computePath(source, target); } else { physicalPath = pnComputationUnit.computePath(source, target, virtualLink.getBandwidth()); } return physicalPath; }
VNMappingUnit implements AutoCloseable { private PhysicalPath virtualLinkMapping(VirtualNetworkId virtualNetworkId, VirtualLink virtualLink, UserVnPnMapping userVnPnMapping) throws VNMappingException { List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getSrcNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getSrcNodeId().getValue()); } PhysicalNodeId source = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getDestNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getDestNodeId().getValue()); } PhysicalNodeId target = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); if ( source.equals(target) ) { PhysicalPath physicalPath = new PhysicalPathBuilder() .setPathId(new PhysicalPathId(UUID.randomUUID().toString())) .setPhysicalLink(new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink>(0)) .setMetric(0L) .setBandwidth(virtualLink.getBandwidth()) .setDelay(0L) .build(); return physicalPath; } PhysicalPath physicalPath; if ( 0 == virtualLink.getBandwidth() ) { physicalPath = pnComputationUnit.computePath(source, target); } else { physicalPath = pnComputationUnit.computePath(source, target, virtualLink.getBandwidth()); } return physicalPath; } }
VNMappingUnit implements AutoCloseable { private PhysicalPath virtualLinkMapping(VirtualNetworkId virtualNetworkId, VirtualLink virtualLink, UserVnPnMapping userVnPnMapping) throws VNMappingException { List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getSrcNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getSrcNodeId().getValue()); } PhysicalNodeId source = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getDestNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getDestNodeId().getValue()); } PhysicalNodeId target = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); if ( source.equals(target) ) { PhysicalPath physicalPath = new PhysicalPathBuilder() .setPathId(new PhysicalPathId(UUID.randomUUID().toString())) .setPhysicalLink(new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink>(0)) .setMetric(0L) .setBandwidth(virtualLink.getBandwidth()) .setDelay(0L) .build(); return physicalPath; } PhysicalPath physicalPath; if ( 0 == virtualLink.getBandwidth() ) { physicalPath = pnComputationUnit.computePath(source, target); } else { physicalPath = pnComputationUnit.computePath(source, target, virtualLink.getBandwidth()); } return physicalPath; } VNMappingUnit(DataBroker dataBroker,
                         PNComputationUnit pnComputationUnit,
                         PNResourcesTracker pnResourcesTracker); }
VNMappingUnit implements AutoCloseable { private PhysicalPath virtualLinkMapping(VirtualNetworkId virtualNetworkId, VirtualLink virtualLink, UserVnPnMapping userVnPnMapping) throws VNMappingException { List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getSrcNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getSrcNodeId().getValue()); } PhysicalNodeId source = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getDestNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getDestNodeId().getValue()); } PhysicalNodeId target = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); if ( source.equals(target) ) { PhysicalPath physicalPath = new PhysicalPathBuilder() .setPathId(new PhysicalPathId(UUID.randomUUID().toString())) .setPhysicalLink(new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink>(0)) .setMetric(0L) .setBandwidth(virtualLink.getBandwidth()) .setDelay(0L) .build(); return physicalPath; } PhysicalPath physicalPath; if ( 0 == virtualLink.getBandwidth() ) { physicalPath = pnComputationUnit.computePath(source, target); } else { physicalPath = pnComputationUnit.computePath(source, target, virtualLink.getBandwidth()); } return physicalPath; } VNMappingUnit(DataBroker dataBroker,
                         PNComputationUnit pnComputationUnit,
                         PNResourcesTracker pnResourcesTracker); void virtualNetworkMapping(VirtualNetwork virtualNetwork, UserVnPnMapping userVnPnMapping,
                                      List<PhysicalPath> physicalPaths); void virtualNetworkMapping(VirtualNetwork virtualNetwork, List<VirtualLink> unmappedVirtualLinks,
                                      UserVnPnMapping userVnPnMapping, List<PhysicalPath> physicalPaths); @Override void close(); }
VNMappingUnit implements AutoCloseable { private PhysicalPath virtualLinkMapping(VirtualNetworkId virtualNetworkId, VirtualLink virtualLink, UserVnPnMapping userVnPnMapping) throws VNMappingException { List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getSrcNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getSrcNodeId().getValue()); } PhysicalNodeId source = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); vnPnMappingResult = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getDestNodeId().getValue())); if ( null == vnPnMappingResult ) { throw new VNMappingException("Can not get the vn-pn mapping result for " + "the virtual node " + virtualLink.getDestNodeId().getValue()); } PhysicalNodeId target = new PhysicalNodeId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); if ( source.equals(target) ) { PhysicalPath physicalPath = new PhysicalPathBuilder() .setPathId(new PhysicalPathId(UUID.randomUUID().toString())) .setPhysicalLink(new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink>(0)) .setMetric(0L) .setBandwidth(virtualLink.getBandwidth()) .setDelay(0L) .build(); return physicalPath; } PhysicalPath physicalPath; if ( 0 == virtualLink.getBandwidth() ) { physicalPath = pnComputationUnit.computePath(source, target); } else { physicalPath = pnComputationUnit.computePath(source, target, virtualLink.getBandwidth()); } return physicalPath; } VNMappingUnit(DataBroker dataBroker,
                         PNComputationUnit pnComputationUnit,
                         PNResourcesTracker pnResourcesTracker); void virtualNetworkMapping(VirtualNetwork virtualNetwork, UserVnPnMapping userVnPnMapping,
                                      List<PhysicalPath> physicalPaths); void virtualNetworkMapping(VirtualNetwork virtualNetwork, List<VirtualLink> unmappedVirtualLinks,
                                      UserVnPnMapping userVnPnMapping, List<PhysicalPath> physicalPaths); @Override void close();  }