BUG-612 : switched PCEP Tlvs to ByteBuf 69/7569/1
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 1 Jun 2014 13:15:58 +0000 (15:15 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Sun, 1 Jun 2014 16:11:43 +0000 (18:11 +0200)
Change-Id: I103e4bf0c5104993cded9c281795571786379889
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
27 files changed:
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/LSPCleanupTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEStatefulCapabilityTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspDbVersionTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspSymbolicNameTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02NodeIdentifierTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02RSVPErrorSpecTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02StatefulCapabilityTlvParser.java
pcep/ietf-stateful02/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspSymbolicNameTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/AbstractVendorSpecificTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java

index 139eedb4c90eae2e3b17946d9019e74d49c50759..52cdd5f8b54c475a93b565038cfb6820552d7861 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.crabbe.initiated00;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
@@ -26,7 +28,10 @@ public final class LSPCleanupTlvParser implements TlvParser, TlvSerializer {
        }
 
        @Override
-       public Tlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new LspCleanupBuilder().setTimeout(ByteArray.bytesToLong(buffer)).build();
+       public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new LspCleanupBuilder().setTimeout(buffer.readUnsignedInt()).build();
        }
 }
index 1585ecd5901eaab12e3f834917cf5776834fac94..0401448760b34ad093c28364134db1a43092a99f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.crabbe.initiated00;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02StatefulCapabilityTlvParser;
@@ -27,16 +29,15 @@ public final class PCEStatefulCapabilityTlvParser extends Stateful02StatefulCapa
        private static final int I_FLAG_OFFSET = 29;
 
        @Override
-       public Stateful parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (buffer.length < FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+               if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
                }
-
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
 
                final StatefulBuilder sb = new StatefulBuilder();
                sb.setIncludeDbVersion(flags.get(S_FLAG_OFFSET));
index 5963068c4f956d0fda315d1f4e0aac998b0360eb..872cf83e5e8f8d94d2514f669c30458b1dc0e533 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful02;
 
+import io.netty.buffer.ByteBuf;
+
 import java.math.BigInteger;
 
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
@@ -30,8 +32,11 @@ public final class Stateful02LspDbVersionTlvParser implements TlvParser, TlvSeri
        private static final int DBV_F_LENGTH = 8;
 
        @Override
-       public LspDbVersion parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new LspDbVersionBuilder().setVersion(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, DBV_F_LENGTH)))).build();
+       public LspDbVersion parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new LspDbVersionBuilder().setVersion(BigInteger.valueOf(buffer.readLong())).build();
        }
 
        @Override
index 0b0c911a3bc061f3859a477cd0fcc698e467294c..bd32d59362b77b73af7761d41138959a7aacd386 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful02;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
@@ -23,9 +26,12 @@ public final class Stateful02LspSymbolicNameTlvParser implements TlvParser, TlvS
        public static final int TYPE = 17;
 
        @Override
-       public SymbolicPathName parseTlv(final byte[] buffer) throws PCEPDeserializerException {
+       public SymbolicPathName parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
                return new SymbolicPathNameBuilder().setPathName(
-                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName(buffer)).build();
+                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName(ByteArray.readAllBytes(buffer))).build();
        }
 
        @Override
index 37a6d51607f6e36c2dd2788780f766ecc637a9b9..efb4ba15c0045dcdde1924e45d4b2c8d1f3907ec 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful02;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.NodeIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
@@ -25,7 +28,10 @@ public final class Stateful02NodeIdentifierTlvParser implements TlvParser, TlvSe
        }
 
        @Override
-       public Tlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new NodeIdentifierBuilder().setNodeId(new NodeIdentifier(buffer)).build();
+       public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new NodeIdentifierBuilder().setNodeId(new NodeIdentifier(ByteArray.readAllBytes(buffer))).build();
        }
 }
\ No newline at end of file
index 7b3f561dc217c72b2f904d7098075cf87636e46f..d8af90a4f2988f3933bdccd241730244a42daa56 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful02;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -46,26 +48,21 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
        private static final int V6_RSVP_LENGTH = 20;
 
        @Override
-       public RsvpErrorSpec parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public RsvpErrorSpec parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               int byteOffset = 0;
                final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-               if (valueBytes.length == V4_RSVP_LENGTH) {
-                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
-                       byteOffset += IP4_F_LENGTH;
-               } else if (valueBytes.length == V6_RSVP_LENGTH) {
-                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
-                       byteOffset += IP6_F_LENGTH;
+               if (buffer.readableBytes() == V4_RSVP_LENGTH) {
+                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, IP4_F_LENGTH))));
+               } else if (buffer.readableBytes() == V6_RSVP_LENGTH) {
+                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, IP6_F_LENGTH))));
                }
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
-               byteOffset += FLAGS_F_LENGTH;
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
                builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
-               final short errorCode = (short) UnsignedBytes.toInt(valueBytes[byteOffset]);
-               byteOffset += ERROR_CODE_F_LENGTH;
+               final short errorCode = (short) UnsignedBytes.toInt(buffer.readByte());
                builder.setCode(errorCode);
-               final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
+               final int errorValue = buffer.readUnsignedShort();
                builder.setValue(errorValue);
                return new RsvpErrorSpecBuilder().setRsvpError(builder.build()).build();
        }
index c64546acf8d3772247be9240d2a7242a9666867a..aefe170a3e5c99e7d0e22598c953966a8262629e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful02;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
@@ -28,17 +30,15 @@ public class Stateful02StatefulCapabilityTlvParser implements TlvParser, TlvSeri
        protected static final int U_FLAG_OFFSET = 31;
 
        @Override
-       public Stateful parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (buffer.length < FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+               if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
                }
-
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
-
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
                final StatefulBuilder sb = new StatefulBuilder();
                sb.setIncludeDbVersion(flags.get(S_FLAG_OFFSET));
                sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
index 7a2e098192b133a493f84bc4eb5a495bb894014f..2b745384c3c9a98545cdd257bdf57f564ac2ac56 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.ietf;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
 
 import java.math.BigInteger;
 
@@ -52,7 +53,7 @@ public class PCEPTlvParserTest {
        public void testStatefulTlv() throws PCEPDeserializerException {
                final Stateful02StatefulCapabilityTlvParser parser = new Stateful02StatefulCapabilityTlvParser();
                final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).setIncludeDbVersion(false).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(statefulBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(statefulBytes, 4))));
                assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
        }
 
@@ -61,7 +62,7 @@ public class PCEPTlvParserTest {
                final Stateful02LspSymbolicNameTlvParser parser = new Stateful02LspSymbolicNameTlvParser();
                final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
                                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName("Med test of symbolic name".getBytes())).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.subByte(symbolicNameBytes, 4, 25)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.subByte(symbolicNameBytes, 4, 25))));
                assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
        }
 
@@ -69,7 +70,7 @@ public class PCEPTlvParserTest {
        public void testNodeIdentifier() throws PCEPDeserializerException {
                final Stateful02NodeIdentifierTlvParser parser = new Stateful02NodeIdentifierTlvParser();
                NodeIdentifier tlv = new NodeIdentifierBuilder().setNodeId(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.NodeIdentifier(ByteArray.subByte(nodeIdentifierBytes, 4, 25))).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.subByte(nodeIdentifierBytes, 4, 25)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.subByte(nodeIdentifierBytes, 4, 25))));
                assertArrayEquals(nodeIdentifierBytes, parser.serializeTlv(tlv));
        }
 
@@ -82,7 +83,7 @@ public class PCEPTlvParserTest {
                builder.setCode((short) 146);
                builder.setValue(5634);
                final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setRsvpError(builder.build()).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.subByte(rsvpErrorBytes, 4, 8)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.subByte(rsvpErrorBytes, 4, 8))));
                assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
        }
 
@@ -97,7 +98,7 @@ public class PCEPTlvParserTest {
                builder.setCode((short) 213);
                builder.setValue(50649);
                final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setRsvpError(builder.build()).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.subByte(rsvpError6Bytes, 4, 20)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.subByte(rsvpError6Bytes, 4, 20))));
                assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
        }
 
@@ -105,7 +106,7 @@ public class PCEPTlvParserTest {
        public void testLspDbVersionTlv() throws PCEPDeserializerException {
                final Stateful02LspDbVersionTlvParser parser = new Stateful02LspDbVersionTlvParser();
                final LspDbVersion tlv = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(180L)).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspDbBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspDbBytes, 4))));
                assertArrayEquals(lspDbBytes, parser.serializeTlv(tlv));
 
        }
index a9ccb0d2060f2d4153b2688324b7e0b2f3694ede..abdac029c7ccc439332cf66971ce1d8cfbb4d422 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.initiated00;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
@@ -27,15 +29,15 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
        private static final int I_FLAG_OFFSET = 29;
 
        @Override
-       public Stateful parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (buffer.length < FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+               if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
                }
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
 
                final StatefulBuilder sb = new StatefulBuilder();
                sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
index 64ed84ecc564b722cc0bb48785393c252a7ea302..dd9ae538f2bd0457bb3db93cb602617995fff44b 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -42,25 +44,19 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl
        private static final int V4_LENGTH = 16;
 
        @Override
-       public LspIdentifiers parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public LspIdentifiers parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (valueBytes.length != V4_LENGTH) {
-                       throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers Ipv4 tlv length.");
+               if (buffer.readableBytes() != V4_LENGTH) {
+                       throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv4 tlv length.");
                }
-               int position = 0;
                final Ipv4Builder builder = new Ipv4Builder();
-               builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
-               position = IP4_F_LENGTH;
-               final LspId lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
-               position += LSP_ID_F_LENGTH;
-               final TunnelId tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
-               position += TUNNEL_ID_F_LENGTH;
-               builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position,
-                               EX_TUNNEL_ID4_F_LENGTH))));
-               position += EX_TUNNEL_ID4_F_LENGTH;
-               builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
+               builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, IP4_F_LENGTH)));
+               final LspId lspId = new LspId((long) buffer.readUnsignedShort());
+               final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
+               builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, EX_TUNNEL_ID4_F_LENGTH))));
+               builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, IP4_F_LENGTH)));
                final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
                return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
        }
index 137d8f0d530730f700a7e41f2576fcf3f0d98e48..4ebcf8ced5036e234e6bdfb10d9e0b201ff8132e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -41,25 +43,19 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
        private static final int V6_LENGTH = 52;
 
        @Override
-       public LspIdentifiers parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public LspIdentifiers parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (valueBytes.length != V6_LENGTH) {
-                       throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers Ipv6 tlv length.");
+               if (buffer.readableBytes() != V6_LENGTH) {
+                       throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv6 tlv length.");
                }
-               int position = 0;
                final Ipv6Builder builder = new Ipv6Builder();
-               builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
-               position += IP6_F_LENGTH;
-               final LspId lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
-               position += LSP_ID_F_LENGTH;
-               final TunnelId tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
-               position += TUNNEL_ID_F_LENGTH;
-               builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position,
-                               EX_TUNNEL_ID6_F_LENGTH))));
-               position += EX_TUNNEL_ID6_F_LENGTH;
-               builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
+               builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, IP6_F_LENGTH)));
+               final LspId lspId = new LspId((long) buffer.readUnsignedShort());
+               final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
+               builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, EX_TUNNEL_ID6_F_LENGTH))));
+               builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, IP6_F_LENGTH)));
                final AddressFamily afi = new Ipv6CaseBuilder().setIpv6(builder.build()).build();
                return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
        }
index f7fd3977a7d3f260bf6469ee7f4767f1b0280891..1c2b66554bfffdb49150e4ec66832a47ea1d2200 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
@@ -23,9 +26,12 @@ public final class Stateful07LspSymbolicNameTlvParser implements TlvParser, TlvS
        public static final int TYPE = 17;
 
        @Override
-       public SymbolicPathName parseTlv(final byte[] buffer) throws PCEPDeserializerException {
+       public SymbolicPathName parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
                return new SymbolicPathNameBuilder().setPathName(
-                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName(buffer)).build();
+                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName(ByteArray.getAllBytes(buffer))).build();
        }
 
        @Override
index ce5a162b42cb7d87019b018e9fa09c277c1b46a6..839a425fda958c304df55ede6c25c39f6b35147a 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
@@ -26,8 +28,11 @@ public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSe
        private static final int UPDATE_ERR_CODE_LENGTH = 4;
 
        @Override
-       public LspErrorCode parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new LspErrorCodeBuilder().setErrorCode(ByteArray.bytesToLong(buffer)).build();
+       public LspErrorCode parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new LspErrorCodeBuilder().setErrorCode(buffer.readUnsignedInt()).build();
        }
 
        @Override
index 1fdee1c89fdcccbb8b0117b12682935078bda3e2..5fceff1ac1b7a69ff89b6d768e379464a481495f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -16,7 +18,6 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.rsvp.error.spec.tlv.RsvpErrorSpec;
@@ -67,21 +68,17 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
        private static final int V6_RSVP_LENGTH = 22;
 
        @Override
-       public RsvpErrorSpec parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public RsvpErrorSpec parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-
-               final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 0, 1));
-               final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 1, 1));
-
+               final int classNum = UnsignedBytes.toInt(buffer.readByte());
+               final int classType = UnsignedBytes.toInt(buffer.readByte());
                ErrorType errorType = null;
-               final int byteOffset = 2;
-
                if (classNum == RSVP_ERROR_CLASS_NUM) {
-                       errorType = parseRsvp(classType, ByteArray.cutBytes(valueBytes, byteOffset));
+                       errorType = parseRsvp(classType, buffer.slice());
                } else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
-                       errorType = parseUserError(ByteArray.cutBytes(valueBytes, byteOffset));
+                       errorType = parseUserError(buffer.slice());
                }
                return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
        }
@@ -102,19 +99,13 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
                }
        }
 
-       private UserCase parseUserError(final byte[] valueBytes) {
+       private UserCase parseUserError(final ByteBuf buffer) {
                final UserErrorBuilder error = new UserErrorBuilder();
-               int byteOffset = 0;
-               error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
-               byteOffset += ENTERPRISE_F_LENGTH;
-               error.setSubOrg((short) UnsignedBytes.toInt(valueBytes[byteOffset]));
-               byteOffset += SUB_ORG_F_LENGTH;
-               final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
-               byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
-               error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
-               byteOffset += USER_VALUE_F_LENGTH;
-               error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
-               byteOffset += errDescrLength;
+               error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt()));
+               error.setSubOrg((short) UnsignedBytes.toInt(buffer.readByte()));
+               final int errDescrLength = UnsignedBytes.toInt(buffer.readByte());
+               error.setValue(buffer.readUnsignedShort());
+               error.setDescription(ByteArray.bytesToHRString(ByteArray.readBytes(buffer, errDescrLength)));
                // if we have any subobjects, place the implementation here
                return new UserCaseBuilder().setUserError(error.build()).build();
        }
@@ -143,23 +134,18 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
                return bytes;
        }
 
-       private RsvpCase parseRsvp(final int classType, final byte[] valueBytes) {
-               int byteOffset = 0;
+       private RsvpCase parseRsvp(final int classType, final ByteBuf buffer) {
                final RsvpErrorBuilder builder = new RsvpErrorBuilder();
                if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
-                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
-                       byteOffset += IP4_F_LENGTH;
+                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, IP4_F_LENGTH))));
                } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
-                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
-                       byteOffset += IP6_F_LENGTH;
+                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, IP6_F_LENGTH))));
                }
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
-               byteOffset += FLAGS_F_LENGTH;
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
                builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
-               final short errorCode = (short) (valueBytes[byteOffset] & Values.BYTE_MAX_VALUE_BYTES);
-               byteOffset += ERROR_CODE_F_LENGTH;
+               final short errorCode = buffer.readUnsignedByte();
                builder.setCode(errorCode);
-               final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
+               final int errorValue = buffer.readUnsignedShort();
                builder.setValue(errorValue);
                return new RsvpCaseBuilder().setRsvpError(builder.build()).build();
        }
index 8c552451bf8b68771a6c4041b91a82e9ccc51df4..ddc2be658b523260bcde2cdcd2c8c74007c4e49b 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
@@ -30,15 +32,15 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
        protected static final int U_FLAG_OFFSET = 31;
 
        @Override
-       public Stateful parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (buffer.length < FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+               if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
                }
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
 
                final StatefulBuilder sb = new StatefulBuilder();
                sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
index b55d93c28139d95f32dcc83c6076564c918660d6..939ed9353abe200a7fdb72a1cb53fb36fd4eec73 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.ietf;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
 
 import org.junit.Test;
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -71,7 +72,7 @@ public class PCEPTlvParserTest {
        public void testStatefulTlv() throws PCEPDeserializerException {
                final Stateful07StatefulCapabilityTlvParser parser = new Stateful07StatefulCapabilityTlvParser();
                final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(statefulBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(statefulBytes, 4))));
                assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
        }
 
@@ -80,7 +81,7 @@ public class PCEPTlvParserTest {
                final Stateful07LspSymbolicNameTlvParser parser = new Stateful07LspSymbolicNameTlvParser();
                final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
                                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med test of symbolic nameeee".getBytes())).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(symbolicNameBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(symbolicNameBytes, 4))));
                assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
        }
 
@@ -88,7 +89,7 @@ public class PCEPTlvParserTest {
        public void testLspErrorCodeTlv() throws PCEPDeserializerException {
                final Stateful07LspUpdateErrorTlvParser parser = new Stateful07LspUpdateErrorTlvParser();
                final LspErrorCode tlv = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspUpdateErrorBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspUpdateErrorBytes, 4))));
                assertArrayEquals(lspUpdateErrorBytes, parser.serializeTlv(tlv));
        }
 
@@ -102,7 +103,7 @@ public class PCEPTlvParserTest {
                afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
                final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(
                                new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspIdentifiers4Bytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers4Bytes, 4))));
                assertArrayEquals(lspIdentifiers4Bytes, parser.serializeTlv(tlv));
        }
 
@@ -121,7 +122,7 @@ public class PCEPTlvParserTest {
                                (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
                final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv6CaseBuilder().setIpv6(afi.build()).build()).setLspId(
                                new LspId(4660L)).setTunnelId(new TunnelId(65535)).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(lspIdentifiers6Bytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers6Bytes, 4))));
                assertArrayEquals(lspIdentifiers6Bytes, parser.serializeTlv(tlv));
        }
 
@@ -134,7 +135,7 @@ public class PCEPTlvParserTest {
                builder.setCode((short) 146);
                builder.setValue(5634);
                final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(rsvpErrorBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(rsvpErrorBytes, 4))));
                assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
        }
 
@@ -149,7 +150,7 @@ public class PCEPTlvParserTest {
                builder.setCode((short) 213);
                builder.setValue(50649);
                final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(rsvpError6Bytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(rsvpError6Bytes, 4))));
                assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
        }
 
@@ -162,7 +163,7 @@ public class PCEPTlvParserTest {
                builder.setValue(38);
                builder.setDescription("user desc");
                final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(userErrorBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(userErrorBytes, 4))));
                assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
        }
 }
index d250f29bf2539b433851040afa8c4d17797a14e5..c0dcb5ecbfc009add4632b5ea385ea9995b3208e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -43,22 +45,19 @@ public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvS
        }
 
        @Override
-       public VsTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+       public VsTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-
-               byte[] enBytes = ByteArray.subByte(valueBytes, 0, ENTERPRISE_NUM_LENGTH);
-               long en = ByteArray.bytesToLong(enBytes);
+               VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
+               long en = buffer.readUnsignedInt();
                if (en == getEnterpriseNumber()) {
                        vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
-                       int byteOffset = ENTERPRISE_NUM_LENGTH;
-                       int payloadLength = valueBytes.length - byteOffset;
                        VendorPayload vendorPayload = null;
-                       if (payloadLength > 0) {
-                               byte[] payloadBytes = ByteArray.subByte(valueBytes, byteOffset, payloadLength);
-                               vendorPayload = parseVendorPayload(payloadBytes);
+                       if (buffer.isReadable()) {
+                               ByteBuf payloadBytes = buffer.slice();
+                               //FIXME: change this to ByteBuf
+                               vendorPayload = parseVendorPayload(ByteArray.getAllBytes(payloadBytes));
                                if (vendorPayload != null) {
                                        vsTlvBuider.setVendorPayload(vendorPayload);
                                }
index 8442475b63f6fda2eef923b1c5f2eec067663b7b..664e1ba333cbf89d4d19dc683db974f020389057 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -37,15 +39,15 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
        private static final int PCE_UNAVAILABLE = 31;
 
        @Override
-       public NoPathVector parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+       public NoPathVector parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (valueBytes.length != FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
+               if (buffer.readableBytes() != FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >="
                                        + FLAGS_F_LENGTH + ".");
                }
-               final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readAllBytes(buffer));
                return new NoPathVectorBuilder().setFlags(
                                new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
        }
index eb930518a93b9b25c805d1afede55a9082800153..ebf0fa3e57eab7bad2f426175f4f7e057caa5d9e 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
-import java.util.Arrays;
+import io.netty.buffer.ByteBuf;
+
 import java.util.List;
 
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -31,16 +32,16 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
        private static final int OF_CODE_ELEMENT_LENGTH = 2;
 
        @Override
-       public OfList parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public OfList parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + ".");
+               if (buffer.readableBytes() % OF_CODE_ELEMENT_LENGTH != 0) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ".");
                }
                final List<OfId> ofCodes = Lists.newArrayList();
-               for (int i = 0; i < valueBytes.length; i += OF_CODE_ELEMENT_LENGTH) {
-                       ofCodes.add(new OfId(ByteArray.bytesToShort(Arrays.copyOfRange(valueBytes, i, i + OF_CODE_ELEMENT_LENGTH)) & 0xFFFF));
+               while (buffer.isReadable()) {
+                       ofCodes.add(new OfId(buffer.readUnsignedShort()));
                }
                return new OfListBuilder().setCodes(ofCodes).build();
        }
index c883b3b94bea5e512978148721b23a470158e77a..49c9438fd8e5537e5acac709393ab883508c3839 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -27,9 +29,11 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
        private static final int ORDR_SETUP_LENGTH = 4;
 
        @Override
-       public Order parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new OrderBuilder().setDelete(Long.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, ORDR_DEL_LENGTH)))).setSetup(
-                               ByteArray.bytesToLong(ByteArray.subByte(buffer, ORDR_DEL_LENGTH, ORDR_SETUP_LENGTH))).build();
+       public Order parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build();
        }
 
        @Override
index b6772aa14af6a4cb7594ac19f6ea594972169a09..df333cb2cbacda07fbcb398ef9cc9201f4191449 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -25,8 +27,11 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
        private static final int OVERLOADED_DURATION_LENGTH = 4;
 
        @Override
-       public OverloadDuration parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new OverloadDurationBuilder().setDuration(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, OVERLOADED_DURATION_LENGTH))).build();
+       public OverloadDuration parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new OverloadDurationBuilder().setDuration(buffer.readUnsignedInt()).build();
        }
 
        @Override
index 3626f55218cb6f48a48503516851e3ebfaeca3ed..34931493e5fd0dd9eeff6a16d1207d25ee7bfa3a 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -26,8 +28,11 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
        private static final int REQ_ID_LENGTH = 4;
 
        @Override
-       public ReqMissing parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new ReqMissingBuilder().setRequestId(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, REQ_ID_LENGTH)))).build();
+       public ReqMissing parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
+               }
+               return new ReqMissingBuilder().setRequestId(new RequestId(buffer.readUnsignedInt())).build();
        }
 
        @Override
index 2a0e57356c892c912ffad094d8ee42f21558fff2..1cf1fe692824031e293c44531eab7c1daa9386f4 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
 
 import java.util.List;
 
@@ -81,7 +82,7 @@ public class PCEPTlvParserTest {
                final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
                final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
                                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(noPathVectorBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(noPathVectorBytes, 4))));
                assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
        }
 
@@ -89,14 +90,14 @@ public class PCEPTlvParserTest {
        public void testOverloadedDurationTlv() throws PCEPDeserializerException {
                final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
                final OverloadDuration tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(overloadedBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(overloadedBytes, 4))));
                assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
        }
 
        public void testReqMissingTlv() throws PCEPDeserializerException {
                final ReqMissingTlvParser parser = new ReqMissingTlvParser();
                final ReqMissing tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(reqMissingBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(reqMissingBytes, 4))));
                assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
        }
 
@@ -104,7 +105,7 @@ public class PCEPTlvParserTest {
        public void testOrderTlv() throws PCEPDeserializerException {
                final OrderTlvParser parser = new OrderTlvParser();
                final Order tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(orderBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(orderBytes, 4))));
                assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
        }
 
@@ -115,14 +116,14 @@ public class PCEPTlvParserTest {
                ids.add(new OfId(0x1234));
                ids.add(new OfId(0x5678));
                final OfList tlv = new OfListBuilder().setCodes(ids).build();
-               assertEquals(tlv, parser.parseTlv(ByteArray.cutBytes(ofListBytes, 4)));
+               assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(ofListBytes, 4))));
                assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
        }
 
        @Test
        public void testVendorSpecificTlv() throws PCEPDeserializerException {
                VsTlv tlv = new VsTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(9L)).setVendorPayload(this.vp).build();
-               assertEquals(tlv, this.vsParser.parseTlv(ByteArray.cutBytes(vsTlvBytes, 4)));
+               assertEquals(tlv, this.vsParser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(vsTlvBytes, 4))));
                assertArrayEquals(vsTlvBytes, this.vsParser.serializeTlv(tlv));
        }
 }
index 5a080c29a2e8036e3eaf9b245b746e709f160f5a..a80d0f23cf8f3ddc558c3a509b044ac4cf02d814 100644 (file)
@@ -12,7 +12,6 @@ import io.netty.buffer.ByteBufUtil;
 
 import java.util.Arrays;
 
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,8 +48,7 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
                        }
                        final ByteBuf tlvBytes = bytes.slice(bytes.readerIndex(), length);
                        LOG.trace("Attempt to parse tlv from bytes: {}", ByteBufUtil.hexDump(tlvBytes));
-                       //FIXME: switch to ByteBuf
-                       final Tlv tlv = this.tlvReg.parseTlv(type, ByteArray.readAllBytes(tlvBytes));
+                       final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
                        LOG.trace("Tlv was parsed. {}", tlv);
                        addTlv(builder, tlv);
                        bytes.readerIndex(bytes.readerIndex() + length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO));
index beb660906810bf395409393db00b5778911c10da..317e7564899e9180f7282bbc4dd508b670f7db9e 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 
 public interface TlvParser {
-       Tlv parseTlv(byte[] buffer) throws PCEPDeserializerException;
+       Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException;
 }
index 6631d34bd3cac81c73cd4957e8601a815bbb4ff0..311106b91c8240721333e74ed3fd474d89581b1a 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 
 public interface TlvRegistry {
-       Tlv parseTlv(final int type, final byte[] buffer) throws PCEPDeserializerException;
+       Tlv parseTlv(final int type, final ByteBuf buffer) throws PCEPDeserializerException;
        byte[] serializeTlv(final Tlv tlv);
 }
index 7f8462ad50855d9b823ca3d7e18e340494dc0af5..8a585d2987ff619b9818908d5dd1dc0fe5e71bfe 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.spi.pojo;
 
+import io.netty.buffer.ByteBuf;
+
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
@@ -35,7 +37,7 @@ public final class SimpleTlvRegistry implements TlvRegistry {
        }
 
        @Override
-       public Tlv parseTlv(final int type, final byte[] buffer) throws PCEPDeserializerException {
+       public Tlv parseTlv(final int type, final ByteBuf buffer) throws PCEPDeserializerException {
                Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
                final TlvParser parser = this.handlers.getParser(type);
                if (parser == null) {