diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-08-23 11:50:47 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-08-28 11:02:30 +0200 |
commit | 5859ab539c59d76c0f433a5936bda716affa65a3 (patch) | |
tree | 270d50cd1a200fea5a6b4191dae242daa55d2b95 /vpp-common/vpp-translate-utils/src | |
parent | 29456ce94c09768405c31f8fb315425b3c98638f (diff) |
Fix Ipv6Translator.arrayToIpv6Prefix to support single address block
Change-Id: I91353a0c780ac2f61d15c677c25f647f826f71c3
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils/src')
2 files changed, 22 insertions, 11 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 664bdc37d..457c172c1 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,15 +16,20 @@ package io.fd.hc2vpp.common.translate.util; -import com.google.common.net.InetAddresses; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.*; +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 javax.annotation.Nonnull; +import com.google.common.net.InetAddresses; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; - -import static com.google.common.base.Preconditions.*; +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; /** * Trait providing logic for translation of ipv6-related data @@ -73,9 +78,8 @@ public interface Ipv6Translator extends ByteDataTranslator { /** * Converts byte array to {@link Ipv6Prefix} with specified prefixLength */ - default Ipv6Prefix arrayToIpv6Prefix(final byte[] address, byte prefixLength) { + default Ipv6Prefix arrayToIpv6Prefix(final byte[] address, int prefixLength) { Ipv6AddressNoZone addressPart = arrayToIpv6AddressNoZone(address); - return new Ipv6Prefix(addressPart.getValue().concat("/").concat(String.valueOf(prefixLength))); } 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 3d289c7e7..fb4c61b55 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,16 @@ package io.fd.hc2vpp.common.translate.util; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +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.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}; @@ -61,8 +63,13 @@ public class Ipv6TranslatorTest implements Ipv6Translator { } @Test - public void testArrayToIpv6Prefix() throws Exception { - assertEquals(IPV6_COMPRESSED + "/64", arrayToIpv6Prefix(IPV6_BYTES, (byte) 64).getValue()); + public void testArrayToIpv6Prefix64() throws Exception { + assertEquals(IPV6_COMPRESSED + "/64", arrayToIpv6Prefix(IPV6_BYTES, 64).getValue()); + } + + @Test + public void testArrayToIpv6Prefix128() throws Exception { + assertEquals(IPV6_COMPRESSED + "/128", arrayToIpv6Prefix(IPV6_BYTES, 128).getValue()); } @Test |