package org.opendaylight.neutron.spi;
+import com.google.common.net.InetAddresses;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
if (parts.length != 2) {
return false;
}
- try {
- int length = Integer.parseInt(parts[1]);
- //TODO?: limit check on length
- // convert to byte array
- byte[] addrBytes = ((Inet6Address) InetAddress.getByName(parts[0])).getAddress();
- for (int index = length; index < IPV6_LENGTH; index++) {
- if (((((int) addrBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK)
- & (1 << (IPV6_BYTE_OFFSET - (index % IPV6_LENGTH_BYTES)))) != 0) {
- return (false);
- }
+ int length = Integer.parseInt(parts[1]);
+ //TODO?: limit check on length
+ // convert to byte array
+ byte[] addrBytes = ((Inet6Address) InetAddresses.forString(parts[0])).getAddress();
+ for (int index = length; index < IPV6_LENGTH; index++) {
+ if (((((int) addrBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK)
+ & (1 << (IPV6_BYTE_OFFSET - (index % IPV6_LENGTH_BYTES)))) != 0) {
+ return (false);
}
- return (true);
- } catch (UnknownHostException e) {
- LOGGER.warn("Failure in isValidCIDR()", e);
- return (false);
}
+ return (true);
}
return false;
}
if (ipVersion == IPV6_VERSION) {
String[] parts = cidr.split("/");
- try {
- int length = Integer.parseInt(parts[1]);
- byte[] cidrBytes = ((Inet6Address) InetAddress.getByName(parts[0])).getAddress();
- byte[] ipBytes = ((Inet6Address) InetAddress.getByName(ipAddress)).getAddress();
- for (int index = 0; index < length; index++) {
- if (((((int) cidrBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK) & (1 << (IPV6_BYTE_OFFSET
- - (index % IPV6_LENGTH_BYTES)))) != (
- (((int) ipBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK)
- & (1 << (IPV6_BYTE_OFFSET - (index % IPV6_LENGTH_BYTES))))) {
- return (false);
- }
+ int length = Integer.parseInt(parts[1]);
+ byte[] cidrBytes = ((Inet6Address) InetAddresses.forString(parts[0])).getAddress();
+ byte[] ipBytes = ((Inet6Address) InetAddresses.forString(ipAddress)).getAddress();
+ for (int index = 0; index < length; index++) {
+ if (((((int) cidrBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK) & (1 << (IPV6_BYTE_OFFSET
+ - (index % IPV6_LENGTH_BYTES)))) != (
+ (((int) ipBytes[index / IPV6_LENGTH_BYTES]) & IPV6_LSB_MASK)
+ & (1 << (IPV6_BYTE_OFFSET - (index % IPV6_LENGTH_BYTES))))) {
+ return (false);
}
- return (true);
- } catch (UnknownHostException e) {
- LOGGER.warn("Failure in isValidIp()", e);
- return (false);
}
+ return (true);
}
return false;
}
package org.opendaylight.neutron.spi;
+import com.google.common.net.InetAddresses;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.Inet6Address;
-import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
if (inputString == null) {
return BigInteger.ZERO;
}
- try {
- return new BigInteger(((Inet6Address) InetAddress.getByName(inputString)).getAddress());
- } catch (UnknownHostException e) {
- LOGGER.error("convertV6 error", e);
- return BigInteger.ZERO;
- }
+ return new BigInteger(((Inet6Address) InetAddresses.forString(inputString)).getAddress());
}
/**