summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-utils/src/main/java/io
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-07-03 13:34:17 +0200
committerMarek Gradzki <mgradzki@cisco.com>2018-07-03 13:34:17 +0200
commit85cc9659e42eb637d25a0a456353149b63fcac93 (patch)
treeb096327c9370dd9158e901f25ac336f30240b1bc /vpp-common/vpp-translate-utils/src/main/java/io
parent7ec72df18c9fad8165b35ecf2b66ae1e9c344df4 (diff)
HC2VPP-79: provide AddressTranslator.ipAddressToArray for IpAddressNoZone
Change-Id: I637842ea6a582676ab305c29b5d8464987537be0 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils/src/main/java/io')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java11
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java10
2 files changed, 21 insertions, 0 deletions
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
index c2f9deecb..fbf8900f6 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
@@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Arrays;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
@@ -59,6 +60,16 @@ public interface AddressTranslator extends Ipv4Translator, Ipv6Translator, MacTr
}
}
+ default byte[] ipAddressToArray(IpAddressNoZone address) {
+ checkNotNull(address, "Cannot resolve null address");
+
+ if (isIpv6(address)) {
+ return ipv6AddressNoZoneToArray(address.getIpv6AddressNoZone());
+ } else {
+ return ipv4AddressNoZoneToArray(address.getIpv4AddressNoZone());
+ }
+ }
+
/**
* Converts array bytes to {@link IpAddress}.
*/
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
index dbfe81d6c..b1199d7f7 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
@@ -24,6 +24,7 @@ import com.google.common.net.InetAddresses;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
@@ -91,6 +92,15 @@ public interface Ipv6Translator extends ByteDataTranslator {
}
/**
+ * Detects whether {@code IpAddressZone} is ipv6
+ */
+ default boolean isIpv6(@Nonnull final IpAddressNoZone address) {
+ checkState(!(address.getIpv4AddressNoZone() == null && address.getIpv6AddressNoZone() == null),
+ "Invalid address");
+ return address.getIpv6AddressNoZone() != null;
+ }
+
+ /**
* Detects whether {@code IpPrefix} is ipv6
*/
default boolean isIpv6(@Nonnull final IpPrefix address) {