Use IetfYangUtil.hexStringBytes()/hexStringFor() 53/87053/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 20 Jan 2020 13:44:23 +0000 (14:44 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 20 Jan 2020 13:44:23 +0000 (14:44 +0100)
Utility methods exposed by MD-SAL are quite a bit more efficient, use
them instead of dancing around with strings.

Change-Id: I16dec789353244416dae228f5151fbd2b4c27d6d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/extensions/mvpn/pom.xml
bgp/extensions/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/attributes/OpaqueUtil.java

index ef3c03f2ca4ec0b32ee51ee4e76e4f1d1558adec..6e93c1bd19f1cd57c0373d504754bae37703672e 100644 (file)
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-common-netty</artifactId>
         </dependency>
-        <dependency>
-            <groupId>javax.xml.bind</groupId>
-            <artifactId>jaxb-api</artifactId>
-        </dependency>
 
         <!-- test scope dependencies -->
         <dependency>
index d39f9c58dddfa42c33a829aa7970af6bb05e88c0..e32b2b0b3e65d18bf22bedc8790d53e6b5ec06ac 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.mvpn.impl.attributes;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
 import java.util.ArrayList;
 import java.util.List;
-import javax.xml.bind.DatatypeConverter;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.Opaque;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.p2mp.lsp.mldp.p2mp.lsp.OpaqueValue;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.p2mp.lsp.mldp.p2mp.lsp.OpaqueValueBuilder;
@@ -29,9 +26,6 @@ public final class OpaqueUtil {
     public static final short GENERIC_LSP_IDENTIFIER = 1;
     public static final short EXTENDED_TYPE = 255;
     private static final Logger LOG = LoggerFactory.getLogger(OpaqueUtil.class);
-    private static final String SEPARATOR = ":";
-    private static final Joiner SEPARATOR_JOINER = Joiner.on(SEPARATOR);
-    private static final Splitter TWO_CHAR_SPLITTER = Splitter.fixedLength(2);
 
     private OpaqueUtil() {
         // Hidden on purpose
@@ -56,20 +50,20 @@ public final class OpaqueUtil {
     }
 
     private static void writeExtended(final HexString opaque, final Uint16 opaqueExtendedType, final ByteBuf byteBuf) {
-        final byte[] output = writeOpaqueValue(opaque.getValue());
+        final byte[] output = writeOpaqueValue(opaque);
         ByteBufUtils.writeOrZero(byteBuf, opaqueExtendedType);
         byteBuf.writeShort(output.length);
         byteBuf.writeBytes(output);
     }
 
     private static void writeGeneric(final HexString opaque, final ByteBuf byteBuf) {
-        final byte[] output = writeOpaqueValue(opaque.getValue());
+        final byte[] output = writeOpaqueValue(opaque);
         byteBuf.writeShort(output.length);
         byteBuf.writeBytes(output);
     }
 
-    private static byte[] writeOpaqueValue(final String opaque) {
-        return DatatypeConverter.parseHexBinary(opaque.replace(SEPARATOR, ""));
+    private static byte[] writeOpaqueValue(final HexString opaque) {
+        return IetfYangUtil.INSTANCE.hexStringBytes(opaque);
     }
 
     public static Opaque parseOpaque(final ByteBuf buffer) {
@@ -99,8 +93,7 @@ public final class OpaqueUtil {
 
     private static HexString buildOpaqueValue(final ByteBuf buffer) {
         final int length = buffer.readUnsignedShort();
-        final byte[] value = ByteArray.readBytes(buffer, length);
-        return new HexString(SEPARATOR_JOINER.join(TWO_CHAR_SPLITTER.split(ByteBufUtil.hexDump(value))));
+        return IetfYangUtil.INSTANCE.hexStringFor(ByteArray.readBytes(buffer, length));
     }
 
     public static List<OpaqueValue> parseOpaqueList(final ByteBuf byteBuf) {