summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-utils/src
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
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')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java22
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/JvppReplyConsumer.java16
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/Ipv6TranslatorTest.java65
3 files changed, 80 insertions, 23 deletions
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 c4a4ba38e..664bdc37d 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
@@ -16,20 +16,15 @@
package io.fd.hc2vpp.common.translate.util;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.net.InetAddresses;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.*;
+
+import javax.annotation.Nonnull;
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.IpAddress;
-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;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+
+import static com.google.common.base.Preconditions.*;
/**
* Trait providing logic for translation of ipv6-related data
@@ -104,9 +99,7 @@ public interface Ipv6Translator extends ByteDataTranslator {
/**
* Detects whether {@code IpAddress} is ipv6
*/
- default boolean isIpv6(IpAddress address) {
- checkNotNull(address, "Address cannot be null");
-
+ default boolean isIpv6(@Nonnull final IpAddress address) {
checkState(!(address.getIpv4Address() == null && address.getIpv6Address() == null), "Invalid address");
return address.getIpv6Address() != null;
}
@@ -114,8 +107,7 @@ public interface Ipv6Translator extends ByteDataTranslator {
/**
* Detects whether {@code IpPrefix} is ipv6
*/
- default boolean isIpv6(IpPrefix address) {
- checkNotNull(address, "Address cannot be null");
+ default boolean isIpv6(@Nonnull final IpPrefix address) {
checkState(!(address.getIpv4Prefix() == null && address.getIpv6Prefix() == null), "Invalid address");
return address.getIpv6Prefix() != null;
}
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/JvppReplyConsumer.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/JvppReplyConsumer.java
index db656e721..d55446c82 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/JvppReplyConsumer.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/JvppReplyConsumer.java
@@ -16,20 +16,21 @@
package io.fd.hc2vpp.common.translate.util;
-import static com.google.common.base.Preconditions.checkArgument;
-
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.VppBaseCallException;
import io.fd.vpp.jvpp.dto.JVppReply;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import javax.annotation.Nonnegative;
+import javax.annotation.Nonnull;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import javax.annotation.Nonnegative;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import static com.google.common.base.Preconditions.checkArgument;
/**
* Trait providing logic for consuming reply's to jvpp api calls
@@ -38,6 +39,9 @@ public interface JvppReplyConsumer {
int DEFAULT_TIMEOUT_IN_SECONDS = 5;
+ JvppReplyConsumer INSTANCE = new JvppReplyConsumer() {
+ };
+
/**
* Consumes reply for jvpp call representing any write operation
* Should be used in case of calls where it's not clear which write crud operation respective
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");