File tree Expand file tree Collapse file tree
main/java/com/cloud/utils/net
test/java/com/cloud/utils/net Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -921,7 +921,7 @@ public static String getCidrSubNet(final String cidr) {
921921 }
922922
923923 public static String getCidrNetmask (final long cidrSize ) {
924- final long numericNetmask = 0xffffffff >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize ;
924+ final long numericNetmask = ( long ) 0xffffffff >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize ;
925925 return long2Ip (numericNetmask );
926926 }
927927
Original file line number Diff line number Diff line change @@ -419,6 +419,13 @@ public void testIs31PrefixCidr() {
419419 assertTrue ("It should pass! 31 bit prefix." , is31PrefixCidr );
420420 }
421421
422+ @ Test
423+ public void testGetCidrNetMask () {
424+ final String cidr = "10.10.0.0/16" ;
425+ String netmask = NetUtils .getCidrNetmask ("10.10.10.10/16" );
426+ assertTrue (cidr + " does not generate valid netmask " + netmask ,NetUtils .isValidNetmask (netmask ));
427+ }
428+
422429 @ Test
423430 public void testGetCidrSubNet () {
424431 final String cidr = "10.10.0.0/16" ;
@@ -430,6 +437,6 @@ public void testGetCidrSubNet() {
430437 public void testGetCidrSubNetWithWidth () {
431438 final String cidr = "10.10.0.0/16" ;
432439 String subnet = NetUtils .getCidrSubNet ("10.10.10.10" , 16 );
433- assertTrue (NetUtils .isIpWithtInCidrRange (subnet , cidr ));
440+ assertTrue (cidr + " does not contain " + subnet , NetUtils .isIpWithtInCidrRange (subnet , cidr ));
434441 }
435442}
You can’t perform that action at this time.
0 commit comments