*/
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;
}
@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();
}
}
*/
package org.opendaylight.protocol.pcep.crabbe.initiated00;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02StatefulCapabilityTlvParser;
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));
*/
package org.opendaylight.protocol.pcep.ietf.stateful02;
+import io.netty.buffer.ByteBuf;
+
import java.math.BigInteger;
import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
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
*/
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;
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
*/
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;
}
@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
*/
package org.opendaylight.protocol.pcep.ietf.stateful02;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.concepts.Ipv4Util;
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();
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful02;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
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));
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
import java.math.BigInteger;
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));
}
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));
}
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));
}
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));
}
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));
}
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));
}
*/
package org.opendaylight.protocol.pcep.ietf.initiated00;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
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));
*/
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;
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();
}
*/
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;
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();
}
*/
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;
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
*/
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;
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
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.concepts.Ipv4Util;
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;
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();
}
}
}
- 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();
}
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();
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
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));
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;
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));
}
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));
}
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));
}
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));
}
(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));
}
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));
}
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));
}
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));
}
}
*/
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;
}
@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);
}
*/
package org.opendaylight.protocol.pcep.impl.tlv;
+import io.netty.buffer.ByteBuf;
+
import java.util.BitSet;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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();
}
*/
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;
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();
}
*/
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;
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
*/
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;
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
*/
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;
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
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
import java.util.List;
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));
}
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));
}
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));
}
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));
}
}
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;
}
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));
*/
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;
}
*/
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);
}
*/
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;
}
@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) {