NeutronSubnet extends NeutronBaseAttributes<NeutronSubnet> { public boolean isValidCIDR() { if (ipVersion == IPV4_VERSION) { try { SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); if (!info.getNetworkAddress().equals(info.getAddress())) { return false; } } catch (IllegalArgumentException e) { LOG.warn("Failure in isValidCIDR()", e); return false; } return true; } if (ipVersion == IPV6_VERSION) { String[] parts = cidr.split("/"); if (parts.length != 2) { return false; } int length = Integer.parseInt(parts[1]); byte[] addrBytes = ((Inet6Address) InetAddresses.forString(parts[0])).getAddress(); for (int index = length; index < IPV6_LENGTH; index++) { if ((addrBytes[index / IPV6_LENGTH_BYTES] & IPV6_LSB_MASK & 1 << IPV6_BYTE_OFFSET - index % IPV6_LENGTH_BYTES) != 0) { return false; } } return true; } return false; }  String getNetworkUUID(); void setNetworkUUID(String networkUUID); Integer getIpVersion(); void setIpVersion(Integer ipVersion); String getCidr(); void setCidr(String cidr); String getGatewayIp(); void setGatewayIp(String gatewayIp); List<String> getDnsNameservers(); void setDnsNameservers(List<String> dnsNameservers); List<NeutronSubnetIpAllocationPool> getAllocationPools(); void setAllocationPools(List<NeutronSubnetIpAllocationPool> allocationPools); List<NeutronRoute> getHostRoutes(); void setHostRoutes(List<NeutronRoute> hostRoutes); boolean isEnableDHCP(); Boolean getEnableDHCP(); void setEnableDHCP(Boolean newValue); String getIpV6AddressMode(); void setIpV6AddressMode(String ipV6AddressMode); String getIpV6RaMode(); void setIpV6RaMode(String ipV6RaMode); boolean isValidCIDR(); boolean gatewayIp_Pool_overlap(); @Override void initDefaults(); boolean isValidIp(String ipAddress); String getLowAddr(); @Override String toString();  }
@Test public void isValidCIDRTest() { NeutronSubnet objectUT = new NeutronSubnet(); objectUT.setIpVersion(4); objectUT.setCidr("10.18.0.0/24"); Assert.assertTrue("isValidCIDR Test 1: Testing valid CIDR (10.18.0.0/24) failed", objectUT.isValidCIDR()); objectUT.setCidr("10.18.0.0/16"); Assert.assertTrue("isValidCIDR Test 2: Testing valid CIDR (10.18.0.0/16) failed", objectUT.isValidCIDR()); objectUT.setCidr("10.18.0.0/8"); Assert.assertFalse("isValidCIDR Negative Test 1: Testing invalid CIDR (10.18.0.0/8) failed", objectUT.isValidCIDR()); objectUT.setIpVersion(6); objectUT.setCidr("2015:0:0:0:0:0:0:0/24"); Assert.assertTrue("isValidCIDR Test 1: Testing valid V6 CIDR (2015:0:0:0:0:0:0:0/24) failed", objectUT.isValidCIDR()); objectUT.setCidr("2015:0:0:0:0:0:0:1/24"); Assert.assertFalse("isValidCIDR Negative Test 1: Testing invalid CIDR (2015:0:0:0:0:0:0:1) failed", objectUT.isValidCIDR()); }