Source:
<code>private String getVirtualRouterIP(Network network, Collection<String[]> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException { String virtualRouterIp; String subnet = NetUtils.getCidrSubNet(network.getCidr()); String netmask = NetUtils.getCidrNetmask(network.getCidr()); long cidrSize = NetUtils.getCidrSize(netmask); Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>()); if (allIPsInCidr.size() > 3) { Iterator<Long> ipIterator = allIPsInCidr.iterator(); long vip = ipIterator.next(); if (NetUtils.ip2Long(network.getGateway()) == vip) { <START> s_logger.debug("Gateway of the Network(" + network.getName() + ") has the first IP " + NetUtils.long2Ip(vip)); <END> vip = ipIterator.next(); virtualRouterIp = NetUtils.long2Ip(vip); s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getName() + ")"); } else { virtualRouterIp = NetUtils.long2Ip(vip); s_logger.debug("1nd IP is not used as the gateway IP. So, reserving" + virtualRouterIp + " for the Virtual Router IP for " + "Network(" + network.getName() + ")"); } String[] ipAddressRange = new String[2]; ipAddressRange[0] = NetUtils.long2Ip(ipIterator.next()); ipAddressRange[1] = NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize); ipAddressRanges.add(ipAddressRange); return virtualRouterIp; } throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 4 hosts ", Network.class, network.getId()); }</code><technical_language>Wrap in a if (s_logger.isDebugEnabled()) { ... } block avoid unnecessary pressure string pool debug logging is enabled</technical_language>

Target:
private String getVirtualRouterIP(Network network, Collection<String[]> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException { String virtualRouterIp; String subnet = NetUtils.getCidrSubNet(network.getCidr()); String netmask = NetUtils.getCidrNetmask(network.getCidr()); long cidrSize = NetUtils.getCidrSize(netmask); Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>()); if (allIPsInCidr == null || !(allIPsInCidr instanceof TreeSet)) { throw new IllegalStateException("The IPs in CIDR for subnet " + subnet + " where null or returned in a non-ordered set."); } if (allIPsInCidr.size() > 3) { Iterator<Long> ipIterator = allIPsInCidr.iterator(); long vip = ipIterator.next(); if (NetUtils.ip2Long(network.getGateway()) == vip) { vip = ipIterator.next(); virtualRouterIp = NetUtils.long2Ip(vip); if (s_logger.isDebugEnabled()) { s_logger.debug("1st IP is used as gateway IP. Reserving " + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")"); } } else { virtualRouterIp = NetUtils.long2Ip(vip); if (s_logger.isDebugEnabled()) { s_logger.debug("1st IP is not used as the gateway IP. Reserving" + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")"); } } ipAddressRanges.add(new String[] { NetUtils.long2Ip(ipIterator.next()), NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize) }); return virtualRouterIp; } throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 4 hosts ", Network.class, network.getId()); }