Example usage for io.netty.buffer ByteBuf readUnsignedByte

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

Introduction

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

Prototype

public abstract short readUnsignedByte();

Source Link

Document

Gets an unsigned byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROUnnumberedInterfaceSubobjectParser.java

License:Open Source License

@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
        throws RSVPParsingException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                + "; Expected: " + CONTENT_LENGTH + ".");
    }//from   w  ww .  j  a v  a 2 s. co  m
    buffer.readerIndex(buffer.readerIndex() + RESERVED);
    final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
    builder.setMandatory(mandatory);
    builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
    builder.setSubobjectType(parseUnnumeredInterface(buffer));
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.FastRerouteObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) {
    final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder();
    builder.setSetupPriority(byteBuf.readUnsignedByte());
    builder.setHoldPriority(byteBuf.readUnsignedByte());
    builder.setHopLimit(byteBuf.readUnsignedByte());
    builder.setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte()));
    final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
    builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
    builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.FlowSpecObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final FlowSpecObjectBuilder builder = new FlowSpecObjectBuilder();
    //skip version number, reserved, overall length
    byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
    builder.setServiceHeader(ServiceNumber.forValue(byteBuf.readUnsignedByte()));
    //skip reserved
    byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    //skip Length of controlled-load data
    byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    //skip parameter ID 127 and 127 flags
    byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
    final TspecObjectBuilder tBuilder = new TspecObjectBuilder();
    tBuilder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
    tBuilder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
    tBuilder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
    tBuilder.setMinimumPolicedUnit(byteBuf.readUnsignedInt());
    tBuilder.setMaximumPacketSize(byteBuf.readUnsignedInt());
    builder.setTspecObject(tBuilder.build());
    if (builder.getServiceHeader().getIntValue() == 2) {
        //skip parameter ID 130, flags, lenght
        byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
        builder.setRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
        builder.setSlackTerm(byteBuf.readUnsignedInt());
    }//www.jav  a  2s.  co m
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.InformationalFastRerouteObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder();
    builder.setSetupPriority(byteBuf.readUnsignedByte());
    builder.setHoldPriority(byteBuf.readUnsignedByte());
    builder.setHopLimit(byteBuf.readUnsignedByte());
    //skip reserved
    byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
    builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
    builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.MetricObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final MetricObjectBuilder builder = new MetricObjectBuilder();
    byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    final BitArray flags = BitArray.valueOf(byteBuf.readByte());
    builder.setBound(flags.get(BOUND));//from  ww  w .ja v  a  2  s. c  o m
    builder.setComputed(flags.get(COMPUTED));
    builder.setMetricType(byteBuf.readUnsignedByte());
    builder.setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.SessionAttributeLspObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder();
    builder.setSetupPriority(byteBuf.readUnsignedByte());
    builder.setHoldPriority(byteBuf.readUnsignedByte());
    final BitArray bs = BitArray.valueOf(byteBuf.readByte());
    builder.setLocalProtectionDesired(bs.get(LOCAL_PROTECTION));
    builder.setLabelRecordingDesired(bs.get(LABEL_RECORDING));
    builder.setSeStyleDesired(bs.get(SE_STYLE));
    final short nameLenght = byteBuf.readUnsignedByte();
    final ByteBuf auxBuf = byteBuf.readSlice(nameLenght);
    final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII);
    builder.setSessionName(name);/*from w  w w  .  j a  va 2 s .c o m*/
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.SessionAttributeLspRaObjectParser.java

License:Open Source License

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new SessionAttributeObjectWithResourcesAffinitiesBuilder();
    builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setSetupPriority(byteBuf.readUnsignedByte());
    builder.setHoldPriority(byteBuf.readUnsignedByte());
    final BitArray bs = BitArray.valueOf(byteBuf.readByte());
    builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION));
    builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING));
    builder.setSeStyleDesired(bs.get(SessionAttributeLspObjectParser.SE_STYLE));
    final short nameLenght = byteBuf.readUnsignedByte();
    final ByteBuf auxBuf = byteBuf.readSlice(nameLenght);
    final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII);
    builder.setSessionName(name);/*from w  w  w  .  j a  v  a2  s . co m*/
    return builder.build();
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.subobjects.EROSubobjectListParser.java

License:Open Source License

public List<SubobjectContainer> parseList(final ByteBuf buffer) throws RSVPParsingException {
    // Explicit approval of empty ERO
    Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
    final List<SubobjectContainer> subs = new ArrayList<>();
    while (buffer.isReadable()) {
        final boolean loose = ((buffer.getUnsignedByte(buffer.readerIndex())
                & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
        final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES)
                & ~(1 << Values.FIRST_BIT_OFFSET);
        final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
        if (length > buffer.readableBytes()) {
            throw new RSVPParsingException(
                    "Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes());
        }//from ww w.j  av  a2  s.  c o m
        LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
        final SubobjectContainer sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose);
        if (sub == null) {
            LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
        } else {
            LOG.debug("Subobject was parsed. {}", sub);
            subs.add(sub);
        }
    }
    return subs;
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.subobjects.EROSubobjectListParserTest.java

License:Open Source License

@Test
public void testAbstractRSVPObjParser() throws RSVPParsingException {
    final ByteBuf byteAggregator = Unpooled.buffer(4);
    byte[] output = new byte[] { 0, 1, 2, 3 };
    this.parser.serializeAttributeHeader(1, (short) 2, (short) 3, byteAggregator);
    assertArrayEquals(output, byteAggregator.array());

    final ByteBuf body = Unpooled.buffer(4);
    output = new byte[] { 0, 0, 0, 1 };
    final AttributeFilter filter = new AttributeFilter(1L);
    this.parser.writeAttributeFilter(filter, body);
    assertArrayEquals(output, body.array());

    final ByteBuf parseTeObj = Unpooled.buffer(1);
    assertNotNull(this.parser.parseObject(parseTeObj));
    assertNull(this.parser.parseObject(null));

    assertEquals(0, parseTeObj.readableBytes());
    this.parser.serializeObject(null, parseTeObj);
    assertEquals(0, parseTeObj.readableBytes());
    this.parser.serializeObject(this.rsvpTeObj, parseTeObj);
    assertEquals(1, parseTeObj.readableBytes());
    assertEquals((short) 3, parseTeObj.readUnsignedByte());
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.subobjects.RROSubobjectListParser.java

License:Open Source License

public List<SubobjectContainer> parseList(final ByteBuf buffer) throws RSVPParsingException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes is mandatory. Can't be null or empty.");
    final List<SubobjectContainer> subs = new ArrayList<>();
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedByte();
        final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
        if (length > buffer.readableBytes()) {
            throw new RSVPParsingException(
                    "Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes());
        }//from ww  w . j a va2 s  .  co  m
        LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
        final SubobjectContainer sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length));
        if (sub == null) {
            LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
        } else {
            LOG.debug("Subobject was parsed. {}", sub);
            subs.add(sub);
        }
    }
    return subs;
}