Example usage for io.netty.buffer ByteBuf isReadable

List of usage examples for io.netty.buffer ByteBuf isReadable

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf isReadable.

Prototype

public abstract boolean isReadable();

Source Link

Document

Returns true if and only if (this.writerIndex - this.readerIndex) is greater than 0 .

Usage

From source file:org.opendaylight.protocol.pcep.impl.subobject.RROPathKey32SubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: >" + CONTENT_LENGTH + ".");
    }/*from  w ww  .java  2  s .  com*/
    final int pathKey = buffer.readUnsignedShort();
    final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
    final SubobjectBuilder builder = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(pceId));
    pBuilder.setPathKey(new PathKey(pathKey));
    builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + CONTENT_LENGTH + ".");
    }//from   w ww  .  j a  va2  s .c  o  m
    final SubobjectBuilder builder = new SubobjectBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
    builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
    final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
    buffer.skipBytes(RESERVED);
    ubuilder.setRouterId(buffer.readUnsignedInt());
    ubuilder.setInterfaceId(buffer.readUnsignedInt());
    builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser.java

License:Open Source License

@Override
public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != LABEL_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + LABEL_LENGTH + ".");
    }//w w w  .  j a v  a  2  s.c  o m
    return new Type1LabelCaseBuilder()
            .setType1Label(new Type1LabelBuilder().setType1Label(buffer.readUnsignedInt()).build()).build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser.java

License:Open Source License

@Override
public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + CONTENT_LENGTH + ".");
    }//from ww w.ja  va 2  s  . co  m
    final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
    builder.setWavebandId(buffer.readUnsignedInt());
    builder.setStartLabel(buffer.readUnsignedInt());
    builder.setEndLabel(buffer.readUnsignedInt());
    return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROIpv4PrefixSubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final SubobjectBuilder builder = new SubobjectBuilder();
    builder.setMandatory(mandatory);/*  w w w .j ava2 s  .  c  om*/
    if (buffer.readableBytes() != CONTENT4_LENGTH) {
        throw new PCEPDeserializerException(
                "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
    }
    final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
    final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(
            new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length)));
    builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
    buffer.skipBytes(PREFIX_F_LENGTH);
    builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROIpv6PrefixSubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final SubobjectBuilder builder = new SubobjectBuilder();
    builder.setMandatory(mandatory);//from   w  w  w.j a  va  2 s.  c om
    if (buffer.readableBytes() != CONTENT6_LENGTH) {
        throw new PCEPDeserializerException(
                "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
    }
    final int length = buffer.getUnsignedByte(PREFIX6_F_OFFSET);
    final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(
            new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length)));
    builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
    buffer.skipBytes(PREFIX_F_LENGTH);
    builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROPathKey128SubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT128_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: >" + CONTENT128_LENGTH + ".");
    }/*from   w  ww  . j av  a 2 s  .  c o m*/
    final int pathKey = buffer.readUnsignedShort();
    final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
    final SubobjectBuilder builder = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(pceId));
    pBuilder.setPathKey(new PathKey(pathKey));
    builder.setMandatory(mandatory);
    builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROPathKey32SubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: >" + CONTENT_LENGTH + ".");
    }//from w  w w  .ja  v  a  2s . co m
    final int pathKey = buffer.readUnsignedShort();
    final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
    final SubobjectBuilder builder = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(pceId));
    pBuilder.setPathKey(new PathKey(pathKey));
    builder.setMandatory(mandatory);
    builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + CONTENT_LENGTH + ".");
    }//from   w w w  .j  a v a 2s.  c  o  m
    final SubobjectBuilder builder = new SubobjectBuilder();
    builder.setMandatory(mandatory);

    builder.setSubobjectType(new SrlgCaseBuilder()
            .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer.readUnsignedInt())).build()).build());
    buffer.readByte();
    builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser.java

License:Open Source License

@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + CONTENT_LENGTH + ".");
    }/*w  ww.j a v a 2  s . c om*/
    buffer.readerIndex(buffer.readerIndex() + RESERVED);
    final SubobjectBuilder builder = new SubobjectBuilder();
    builder.setMandatory(mandatory);
    builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
    final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
    ubuilder.setRouterId(buffer.readUnsignedInt());
    ubuilder.setInterfaceId(buffer.readUnsignedInt());
    builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
    return builder.build();
}