summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-utils/src/test/java/io/fd
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-02-07 13:50:59 +0100
committerJan Srnicek <jsrnicek@cisco.com>2017-02-08 08:29:29 +0000
commit3cecf2cd177bbcb87ad0d5eb19e8e0c80a016a5d (patch)
tree54c7c6df14bf0013a7a8ac7de259388b60a3a9f6 /vpp-common/vpp-translate-utils/src/test/java/io/fd
parent1e562c89ed44a33ffafd310a9e58a45bad65339e (diff)
HC2VPP-11/HC2VPP-12 - refactored ipv4/6 logic/tests
- all dumping logic moved under common abstract classes - added tests Change-Id: Ifdee84795bd8cf6f0d29349dd2cfcf9b2bbec1c9 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils/src/test/java/io/fd')
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java65
1 files changed, 63 insertions, 2 deletions
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 a620cbdd2..3d289c7e7 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
@@ -16,14 +16,75 @@
package io.fd.hc2vpp.common.translate.util;
-import static org.junit.Assert.assertEquals;
-
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.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;
+import static org.junit.Assert.*;
+
public class Ipv6TranslatorTest implements Ipv6Translator {
+ private static final byte[] IPV6_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
+ private static final String IPV6_FULL = "2001:0db8:0a0b:12f0:0000:0000:0000:0001";
+ private static final String IPV6_COMPRESSED = "2001:db8:a0b:12f0::1";
+
+ @Test
+ public void testIpv6AddressNoZoneToArrayFull() throws Exception {
+ assertArrayEquals(IPV6_BYTES, ipv6AddressNoZoneToArray(new Ipv6Address(IPV6_FULL)));
+ }
+
+ @Test
+ public void testIpv6AddressNoZoneToArrayCompressed() throws Exception {
+ assertArrayEquals(IPV6_BYTES, ipv6AddressNoZoneToArray(new Ipv6Address(IPV6_COMPRESSED)));
+ }
+
+ @Test
+ public void testIpv6AddressPrefixToArrayFull() throws Exception {
+ assertArrayEquals(IPV6_BYTES, ipv6AddressPrefixToArray(new Ipv6Prefix(IPV6_FULL + "/64")));
+ }
+
+ @Test
+ public void testIpv6AddressPrefixToArrayCompressed() throws Exception {
+ assertArrayEquals(IPV6_BYTES, ipv6AddressPrefixToArray(new Ipv6Prefix(IPV6_COMPRESSED + "/64")));
+ }
+
+ @Test
+ public void testExtractPrefixFull() throws Exception {
+ assertEquals(64, extractPrefix(new Ipv6Prefix(IPV6_FULL + "/64")));
+ }
+
+ @Test
+ public void testExtractPrefixCompressed() throws Exception {
+ assertEquals(64, extractPrefix(new Ipv6Prefix(IPV6_COMPRESSED + "/64")));
+ }
+
+ @Test
+ public void testArrayToIpv6Prefix() throws Exception {
+ assertEquals(IPV6_COMPRESSED + "/64", arrayToIpv6Prefix(IPV6_BYTES, (byte) 64).getValue());
+ }
+
+ @Test
+ public void testArrayToIpv6AddressNoZone() throws Exception {
+ assertEquals(IPV6_COMPRESSED, arrayToIpv6AddressNoZone(IPV6_BYTES).getValue());
+ }
+
+ @Test
+ public void testIsIpv6Compressed() throws Exception {
+ assertTrue(isIpv6(new IpAddress(new Ipv6Address(IPV6_COMPRESSED))));
+ }
+
+ @Test
+ public void testIsIpv6Full() throws Exception {
+ assertTrue(isIpv6(new IpAddress(new Ipv6Address(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}));
+ }
+
@Test
public void testIpv6NoZone() {
final Ipv6AddressNoZone ipv6Addr = new Ipv6AddressNoZone("3ffe:1900:4545:3:200:f8ff:fe21:67cf");