summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/main/java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-11-20 14:00:32 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-11-20 14:00:35 +0100
commitc3524b9d3b8579f1aa79bf8c123299a94f4dcc18 (patch)
treea15cdec8ef50b5e0ad05acaea65df622a1e82e0e /lisp/lisp2vpp/src/main/java
parent87e37b4f78ff60e3b8c84c3c6670e20c18e20b04 (diff)
Use InetAddresses.forString instead of InetAddress.getByName
Unlike InetAddress.getByName(), Guava's InetAddresses.forString() never cause DNS services to be accessed. JDK equivalents whenever you are expecting to handle only IP address string literals, so there is no blocking DNS penalty for a malformed string. See: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/net/InetAddresses.html#forString-java.lang.String- Change-Id: I7972c09f1f0a3a2688021302acbf6df112be7f72 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/main/java')
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java18
1 files changed, 4 insertions, 14 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
index c8e868086..039aa1bf9 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
@@ -18,6 +18,7 @@ package io.fd.hc2vpp.lisp.translate.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.net.InetAddresses.forString;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4_PREFIX;
@@ -25,12 +26,9 @@ import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDump
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6_PREFIX;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC;
import static java.lang.Integer.parseInt;
-import static java.lang.String.format;
import inet.ipaddr.IPAddress;
import io.fd.hc2vpp.common.translate.util.AddressTranslator;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Arrays;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
@@ -200,7 +198,7 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
static String prefixValue(final String prefix, final String suffix) {
// normalize prefix based address to prevent duplicates
- IPAddress normalizedForm = IPAddress.from(getAddress(prefix)).toSubnet(parseInt(suffix));
+ IPAddress normalizedForm = IPAddress.from(forString(prefix)).toSubnet(parseInt(suffix));
return normalizedForm.toCompressedString();
}
@@ -601,9 +599,9 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
final String[] secondPrefixParts = getPrefixParts(secondPrefix);
IPAddress firstAddress =
- IPAddress.from(getAddress(firstPrefixParts[0])).toSubnet(parseInt(firstPrefixParts[1]));
+ IPAddress.from(forString(firstPrefixParts[0])).toSubnet(parseInt(firstPrefixParts[1]));
IPAddress secondAddress =
- IPAddress.from(getAddress(secondPrefixParts[0])).toSubnet(parseInt(secondPrefixParts[1]));
+ IPAddress.from(forString(secondPrefixParts[0])).toSubnet(parseInt(secondPrefixParts[1]));
return firstAddress.compareTo(secondAddress) == 0;
}
@@ -613,12 +611,4 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
checkArgument(split.length == 2, "%s is not a valid ip prefix", prefixString);
return split;
}
-
- static InetAddress getAddress(final String value) {
- try {
- return InetAddress.getByName(value);
- } catch (UnknownHostException e) {
- throw new IllegalArgumentException(format("Unable to convert %s", value), e);
- }
- }
}