mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CID-1116484 cast to long and use long as cidrsize type
and simpel test
This commit is contained in:
parent
637afb9b67
commit
2fadfe93dc
@ -47,6 +47,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
import com.googlecode.ipv6.IPv6AddressRange;
|
||||
@ -907,14 +908,14 @@ public class NetUtils {
|
||||
if (!isValidIp(cidrAddress)) {
|
||||
return null;
|
||||
}
|
||||
int cidrSizeNum = -1;
|
||||
long cidrSizeNum = -1;
|
||||
|
||||
try {
|
||||
cidrSizeNum = Integer.parseInt(cidrSize);
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new CloudRuntimeException("cidrsize is not valid", e);
|
||||
}
|
||||
final long numericNetmask = 0xffffffff >> MAX_CIDR - cidrSizeNum << MAX_CIDR - cidrSizeNum;
|
||||
final long numericNetmask = (long)0xffffffff >> MAX_CIDR - cidrSizeNum << MAX_CIDR - cidrSizeNum;
|
||||
final String netmask = NetUtils.long2Ip(numericNetmask);
|
||||
return getSubNet(cidrAddress, netmask);
|
||||
}
|
||||
|
||||
@ -418,8 +418,16 @@ public class NetUtilsTest {
|
||||
|
||||
assertTrue("It should pass! 31 bit prefix.", is31PrefixCidr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCidrSubNet() {
|
||||
final String cidr = "10.10.0.0/16";
|
||||
String subnet = NetUtils.getCidrSubNet("10.10.10.10/16");
|
||||
assertTrue(cidr + " does not contain " + subnet,NetUtils.isIpWithtInCidrRange(subnet, cidr));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCidrSubNetWithWidth() {
|
||||
final String cidr = "10.10.0.0/16";
|
||||
String subnet = NetUtils.getCidrSubNet("10.10.10.10", 16);
|
||||
assertTrue(NetUtils.isIpWithtInCidrRange(subnet, cidr));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user