private void checkOverlapPrivateIpRange(final Long zoneId, final String startIp, final String endIp) { final List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId); for (final HostPodVO hostPod : podsInZone) { final String[] existingPodIpRanges = hostPod.getDescription().split(","); for(String podIpRange: existingPodIpRanges) { final String[] existingPodIpRange = podIpRange.split("-"); if (existingPodIpRange.length > 1) { if (!NetUtils.isValidIp4(existingPodIpRange[0]) || !NetUtils.isValidIp4(existingPodIpRange[1])) { continue; } if (NetUtils.ipRangesOverlap(startIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { throw new InvalidParameterValueException("The Start IP and EndIP address range overlap with private IP :" + existingPodIpRange[0] + ":" + existingPodIpRange[1]); } } } } }
private void checkOverlapPrivateIpRange(long podId, String startIp, String endIp) { HostPodVO pod = _podDao.findById(podId); if (pod == null) { throw new CloudRuntimeException("Cannot find pod " + podId); } final String[] existingPodIpRanges = pod.getDescription().split(","); for(String podIpRange: existingPodIpRanges) { final String[] existingPodIpRange = podIpRange.split("-"); if (existingPodIpRange.length > 1) { if (!NetUtils.isValidIp4(existingPodIpRange[0]) || !NetUtils.isValidIp4(existingPodIpRange[1])) { continue; } if (NetUtils.ipRangesOverlap(startIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { throw new InvalidParameterValueException("The Storage network Start IP and endIP address range overlap with private IP :" + existingPodIpRange[0] + ":" + existingPodIpRange[1]); } } } }
@Test public void test31BitPrefixIpRangesOverlapd() { final String gw = "192.168.0.0"; String ip1; String ip2; for (int i = 1, j = 2; i <= 254; i++, j++) { ip1 = "192.168.0." + i; ip2 = "192.168.0." + j; final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); assertFalse("It should overlap, but it's a 31-bit ip", doesOverlap); } }
@Test public void test31BitPrefixIpRangesOverlapdFail() { String gw; String ip1; String ip2; for (int i = 10, j = 12; i <= 254; i++, j++) { gw = "192.168.0." + i; ip1 = "192.168.0." + i; ip2 = "192.168.0." + j; final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); assertTrue("It overlaps!", doesOverlap); } }
private void checkOverlapStorageIpRange(long podId, String startIp, String endIp) { List<StorageNetworkIpRangeVO> curRanges = _sNwIpRangeDao.listByPodId(podId); for (StorageNetworkIpRangeVO range : curRanges) { if (NetUtils.ipRangesOverlap(startIp, endIp, range.getStartIp(), range.getEndIp())) { throw new InvalidParameterValueException("The Storage network Start IP and endIP address range overlap with private IP :" + range.getStartIp() + " - " + range.getEndIp()); } } }
if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) { throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses");
if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) { throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses"); if (NetUtils.ipRangesOverlap(startIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { throw new InvalidParameterValueException("The new range overlaps with existing range. Please add a mutually exclusive range.");
if (NetUtils.ipRangesOverlap(existingPodIpRange[0], existingPodIpRange[1], gateway, gateway)) { throw new InvalidParameterValueException("The gateway shouldn't overlap some start/end ip addresses");
if (ipv4 && NetUtils.ipRangesOverlap(startIP, endIP, vlanDetails.first(), vlanDetails.first())) { throw new InvalidParameterValueException("The gateway ip should not be the part of the ip range being added.");
if (NetUtils.ipRangesOverlap(startIP, endIP, vlanGateway, vlanGateway)) { throw new InvalidParameterValueException( "The gateway ip should not be the part of the ip range being added.");
if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP.");
@Test public void test31BitPrefixIpRangesOverlapdFail() { String gw; String ip1; String ip2; for (int i = 10, j = 12; i <= 254; i++, j++) { gw = "192.168.0." + i; ip1 = "192.168.0." + i; ip2 = "192.168.0." + j; final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); assertTrue("It overlaps!", doesOverlap); } }
@Test public void test31BitPrefixIpRangesOverlapd() { final String gw = "192.168.0.0"; String ip1; String ip2; for (int i = 1, j = 2; i <= 254; i++, j++) { ip1 = "192.168.0." + i; ip2 = "192.168.0." + j; final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); assertFalse("It should overlap, but it's a 31-bit ip", doesOverlap); } }
if (NetUtils.ipRangesOverlap(range[0], range[1], guestIpRange[0], guestIpRange[1])) { throw new InvalidParameterValueException("Invalid ip range: " + ipRange + " overlaps with guest ip range " + guestIpRange[0] + "-" + guestIpRange[1]);