Remove ByteBufUtils.readIpv6Address() 13/92713/5
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Sep 2020 10:22:33 +0000 (12:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Oct 2020 09:38:41 +0000 (11:38 +0200)
This method is not used anywhere, with readIetfIpv6Address() being
its replacement. Remove it along with
EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES.

Change-Id: Icc33beb47c4212f3fc187a39fc84cea74931c2dd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/util/EncodeConstants.java
openflowjava/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ByteBufUtils.java
openflowjava/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ByteBufUtilsTest.java

index be727c9b299aed743511a4b6dba7ddaa9c3d6d82..d2f87e520ae619ff45e126b8a2722de855611248 100644 (file)
@@ -66,9 +66,6 @@ public interface EncodeConstants {
     /** Number of groups in ipv4 address. */
     byte GROUPS_IN_IPV4_ADDRESS = 4;
 
-    /** Number of groups in ipv6 address. */
-    byte GROUPS_IN_IPV6_ADDRESS = 8;
-
     /** Length of ipv6 address in bytes. */
     byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = 8 * Short.BYTES;
 
index f67039565023a31618c569bb8a617a76b24f956e..9be764dcc2310afb8b29faf095be231d9618ee72 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public abstract class ByteBufUtils {
     public static final Splitter DOT_SPLITTER = Splitter.on('.');
     public static final Splitter COLON_SPLITTER = Splitter.on(':');
-    private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
     private static final Splitter HEXSTRING_SPLITTER =  Splitter.onPattern("\\s+").omitEmptyStrings();
     private static final Splitter HEXSTRING_NOSPACE_SPLITTER = Splitter.onPattern("(?<=\\G.{2})").omitEmptyStrings();
 
@@ -218,13 +217,6 @@ public abstract class ByteBufUtils {
         return sb.toString().trim();
     }
 
-    private static void appendHexUnsignedShort(final StringBuilder sb, final int val) {
-        sb.append(ByteBufUtils.HEX_CHARS[val >>> 12 & 15]);
-        sb.append(ByteBufUtils.HEX_CHARS[val >>>  8 & 15]);
-        sb.append(ByteBufUtils.HEX_CHARS[val >>>  4 & 15]);
-        sb.append(ByteBufUtils.HEX_CHARS[val        & 15]);
-    }
-
     /**
      * Reads and parses null-terminated string from ByteBuf.
      *
@@ -256,26 +248,6 @@ public abstract class ByteBufUtils {
         return sb.toString();
     }
 
-
-    /**
-     * Read an IPv6 address from a buffer and format it into a string of eight groups of four
-     * hexadecimal digits separated by colons.
-     *
-     * @param buf Input buffer
-     * @return IPv6 address in string format
-     */
-    public static String readIpv6Address(final ByteBuf buf) {
-        final StringBuilder sb = new StringBuilder(EncodeConstants.GROUPS_IN_IPV6_ADDRESS * 5 - 1);
-
-        appendHexUnsignedShort(sb, buf.readUnsignedShort());
-        for (int i = 1; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) {
-            sb.append(':');
-            appendHexUnsignedShort(sb, buf.readUnsignedShort());
-        }
-
-        return sb.toString();
-    }
-
     public static Ipv4Address readIetfIpv4Address(final ByteBuf buf) {
         final byte[] tmp = new byte[4];
         buf.readBytes(tmp);
index e6221202100544b8a12ca92e0b5eec0b4b026cbe..87ef71b87e99e9da2f821d9ea7863a5903dc683c 100644 (file)
@@ -303,29 +303,6 @@ public class ByteBufUtilsTest {
         ipv4Address = ByteBufUtils.readIpv4Address(buffer2);
     }
 
-    /**
-     * Test ipv6 address conversion.
-     */
-    @Test(expected = IndexOutOfBoundsException.class)
-    public void testReadIpv6Address() {
-        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
-        buffer.writeShort(10);
-        buffer.writeShort(65535);
-        buffer.writeShort(4096);
-        buffer.writeShort(0);
-        buffer.writeShort(1024);
-        buffer.writeShort(42);
-        buffer.writeShort(2568);
-        buffer.writeShort(45689);
-        String ipv4Address = ByteBufUtils.readIpv6Address(buffer);
-        Assert.assertEquals("Wrong conversion", "000A:FFFF:1000:0000:0400:002A:0A08:B279", ipv4Address);
-        Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);
-
-        ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
-        buffer.writeShort(10);
-        ipv4Address = ByteBufUtils.readIpv6Address(buffer2);
-    }
-
     @Test
     public void testSerializeList() {