summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/AddressTranslatorTest.java11
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java11
4 files changed, 43 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) {
diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/AddressTranslatorTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/AddressTranslatorTest.java
index ba850af89..89f89f8a5 100644
--- a/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/AddressTranslatorTest.java
+++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/AddressTranslatorTest.java
@@ -20,18 +20,23 @@ import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
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;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
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;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
public class AddressTranslatorTest {
private final static IpAddress IPV6_ADDR = new IpAddress(new Ipv6Address("a::"));
+ private final static IpAddressNoZone IPV6_ADDR_NO_ZONE = new IpAddressNoZone(new Ipv6AddressNoZone("a::"));
private final static IpPrefix IPV6_PREFIX = new IpPrefix(new Ipv6Prefix("a::/48"));
private final static byte IPV6_BYTE_PREFIX = 48;
private final static IpAddress IPV4_ADDR = new IpAddress(new Ipv4Address("10.0.0.1"));
+ private final static IpAddressNoZone IPV4_ADDR_NO_ZONE = new IpAddressNoZone(new Ipv4AddressNoZone("10.0.0.1"));
private final static IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("10.0.0.1/24"));
private final static byte IPV4_BYTE_PREFIX = 24;
private static final byte[] IPV6_BYTE_ARRAY =
@@ -49,6 +54,12 @@ public class AddressTranslatorTest {
}
@Test
+ public void ipAddressNoZoneToArrayTest() {
+ Assert.assertTrue(Arrays.equals(IPV6_BYTE_ARRAY, ADDR_TRANSLATOR.ipAddressToArray(IPV6_ADDR_NO_ZONE)));
+ Assert.assertTrue(Arrays.equals(IPV4_BYTE_ARRAY, ADDR_TRANSLATOR.ipAddressToArray(IPV4_ADDR_NO_ZONE)));
+ }
+
+ @Test
public void arrayToIpAddressTest() {
Assert.assertTrue(
ADDR_TRANSLATOR.addressesEqual(IPV6_ADDR, ADDR_TRANSLATOR.arrayToIpAddress(true, IPV6_BYTE_ARRAY)));
diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java
index 3ed7433ea..57d7a657f 100644
--- a/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java
+++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
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.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
@@ -95,6 +96,16 @@ public class Ipv6TranslatorTest implements Ipv6Translator {
}
@Test
+ public void testIsIpv6NoZoneCompressed() throws Exception {
+ assertTrue(isIpv6(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6_COMPRESSED))));
+ }
+
+ @Test
+ public void testIsIpv6NoZoneFull() throws Exception {
+ assertTrue(isIpv6(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6_FULL))));
+ }
+
+ @Test
public void testTruncateIp4Array() throws Exception {
assertArrayEquals(new byte[]{-64, -84, 2, 1}, truncateIp4Array(new byte[]{-64, -84, 2, 1, 0, 0, 0, 0}));
}