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.object.PCEPClassTypeObjectParser.java

License:Open Source License

@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (!header.isProcessingRule()) {
        LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it");
        return null;
    }//from w  w  w .j  av a  2  s  .c  om
    if (bytes.readableBytes() != SIZE) {
        throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE
                + "; Passed: " + bytes.readableBytes());
    }
    final ClassTypeBuilder builder = new ClassTypeBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());

    final short ct = (short) bytes.readUnsignedInt();
    builder.setClassType(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType(
                    ct));

    final Object obj = builder.build();
    if (ct < 0 || ct > Byte.SIZE) {
        LOG.debug("Invalid class type {}", ct);
        return new UnknownObject(PCEPErrors.INVALID_CT, obj);
    }
    return obj;
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser.java

License:Open Source License

@Override
public CClose parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final CCloseBuilder builder = new CCloseBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
    builder.setReason(bytes.readUnsignedByte());
    final TlvsBuilder tlvsBuilder = new TlvsBuilder();
    parseTlvs(tlvsBuilder, bytes.slice());
    builder.setTlvs(tlvsBuilder.build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv4ObjectParser.java

License:Open Source License

@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final EndpointsObjBuilder builder = new EndpointsObjBuilder();
    if (!header.isProcessingRule()) {
        LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
        return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, builder.build());
    }/*  w  w w. j  a  v  a2 s . co m*/
    if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) {
        throw new PCEPDeserializerException("Wrong length of array of bytes.");
    }
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    final Ipv4Builder b = new Ipv4Builder();
    b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes));
    b.setDestinationIpv4Address((Ipv4Util.addressForByteBuf(bytes)));
    builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv6ObjectParser.java

License:Open Source License

@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final EndpointsObjBuilder builder = new EndpointsObjBuilder();
    if (!header.isProcessingRule()) {
        LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
        return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, builder.build());
    }//from   w  w  w . j  ava 2  s .  co  m
    if (bytes.readableBytes() != Ipv6Util.IPV6_LENGTH * 2) {
        throw new PCEPDeserializerException("Wrong length of array of bytes.");
    }
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    final Ipv6Builder b = new Ipv6Builder();
    b.setSourceIpv6Address(Ipv6Util.addressForByteBuf(bytes));
    b.setDestinationIpv6Address(Ipv6Util.addressForByteBuf(bytes));
    builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(b.build()).build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.java

License:Open Source License

@Override
public ErrorObject parseObject(final ObjectHeader header, final ByteBuf bytes)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final ErrorObjectBuilder builder = new ErrorObjectBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
    builder.setType(bytes.readUnsignedByte());
    builder.setValue(bytes.readUnsignedByte());
    parseTlvs(builder, bytes.slice());/*  www .  j  a  v  a2s.  c  om*/
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser.java

License:Open Source License

@Override
public Xro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final XroBuilder builder = new XroBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    bytes.skipBytes(FLAGS_OFFSET);/*from w  w  w. j a va  2 s  .  c om*/
    builder.setFlags(new Flags(bytes.readBoolean()));
    builder.setSubobject(parseSubobjects(bytes.slice()));
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPExistingBandwidthObjectParser.java

License:Open Source License

@Override
public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (bytes.readableBytes() != PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
                + "; Expected: " + PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH + ".");
    }//from  ww  w  . j av  a  2 s.co m
    final BandwidthBuilder builder = new BandwidthBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    builder.setBandwidth(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(
                    ByteArray.getAllBytes(bytes)));
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser.java

License:Open Source License

@Override
public Gc parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final GcBuilder builder = new GcBuilder();

    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());

    builder.setMaxHop(bytes.readUnsignedByte());
    builder.setMaxUtilization(bytes.readUnsignedByte());
    builder.setMinUtilization(bytes.readUnsignedByte());
    builder.setOverBookingFactor(bytes.readUnsignedByte());
    final TlvsBuilder tlvsBuilder = new TlvsBuilder();
    parseTlvs(tlvsBuilder, bytes.slice());
    builder.setTlvs(tlvsBuilder.build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser.java

License:Open Source License

@Override
public Iro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final IroBuilder builder = new IroBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    final List<Subobject> subs = new ArrayList<>();
    for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject s : parseSubobjects(
            bytes)) {//  w  w  w. jav a2s  .c  om
        subs.add(new SubobjectBuilder().setSubobjectType(s.getSubobjectType()).build());
    }
    builder.setSubobject(subs);
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser.java

License:Open Source License

@Override
public LoadBalancing parseObject(final ObjectHeader header, final ByteBuf bytes)
        throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (bytes.readableBytes() != SIZE) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
                + "; Expected: " + SIZE + ".");
    }//  w  w w  . j  a  va 2s .  c  o  m
    final LoadBalancingBuilder builder = new LoadBalancingBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
    builder.setMaxLsp(bytes.readUnsignedByte());
    builder.setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)));
    return builder.build();
}