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.bgp.parser.spi.pojo.SimpleExtendedCommunityRegistry.java

License:Open Source License

@Override
public ExtendedCommunities parseExtendedCommunity(final ByteBuf buffer)
        throws BGPDocumentedException, BGPParsingException {
    final short type = buffer.readUnsignedByte();
    final short subtype = buffer.readUnsignedByte();
    final ExtendedCommunityParser parser = this.handlers.getParser(createKey(type, subtype));
    if (parser == null) {
        buffer.skipBytes(EXTENDED_COMMUNITY_LENGTH);
        LOG.info("Skipping unknown extended-community type/sub-type {}/{}.", type, subtype);
        return null;
    }/*w  w w  .j av a2 s  . co  m*/
    return new ExtendedCommunitiesBuilder().setTransitive(isTransitive(type))
            .setExtendedCommunity(parser.parseExtendedCommunity(buffer)).build();
}

From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleNlriRegistry.java

License:Open Source License

private Class<? extends SubsequentAddressFamily> getSafi(final ByteBuf buffer) throws BGPParsingException {
    final int safiVal = buffer.readUnsignedByte();
    final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
    if (safi == null) {
        throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
    }/*from  www.  j  ava  2 s .c o m*/
    return safi;
}

From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleNlriRegistry.java

License:Open Source License

@Override
public MpReachNlri parseMpReach(final ByteBuf buffer, final PeerSpecificParserConstraint constraint)
        throws BGPParsingException {
    final MpReachNlriBuilder builder = new MpReachNlriBuilder();
    final Class<? extends AddressFamily> afi = getAfi(buffer);
    final Class<? extends SubsequentAddressFamily> safi = getSafi(buffer);
    builder.setAfi(afi);/* w  ww .  ja  v a2s .c  om*/
    builder.setSafi(safi);

    final BgpTableType key = createKey(builder.getAfi(), builder.getSafi());

    final int nextHopLength = buffer.readUnsignedByte();
    if (nextHopLength != 0) {
        final NextHopParserSerializer nextHopParser = this.nextHopParsers.get(key);
        if (nextHopParser != null) {
            builder.setCNextHop(nextHopParser.parseNextHop(buffer.readSlice(nextHopLength)));
        } else {
            builder.setCNextHop(NextHopUtil.parseNextHop(buffer.readSlice(nextHopLength)));
            LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi);
        }
    }
    buffer.skipBytes(RESERVED);

    final ByteBuf nlri = buffer.slice();
    final NlriParser parser = this.handlers.get(key);
    if (parser == null) {
        LOG.warn(PARSER_NOT_FOUND, key);
    } else {
        parser.parseNlri(nlri, builder, constraint);
    }
    return builder.build();
}

From source file:org.opendaylight.protocol.bmp.impl.message.PeerDownHandler.java

License:Open Source License

@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
    final PeerDownNotificationBuilder peerDown = new PeerDownNotificationBuilder()
            .setPeerHeader(parsePerPeerHeader(bytes));
    final Reason reason = Reason.forValue(bytes.readUnsignedByte());
    if (reason != null) {
        switch (reason) {
        case REASON_ONE:
            peerDown.setLocalSystemClosed(true);
            peerDown.setData(parseBgpNotificationMessage(bytes));
            break;
        case REASON_TWO:
            peerDown.setLocalSystemClosed(true);
            peerDown.setData(new FsmEventCodeBuilder().setFsmEventCode(bytes.readUnsignedShort()).build());
            break;
        case REASON_THREE:
            peerDown.setLocalSystemClosed(false);
            peerDown.setData(parseBgpNotificationMessage(bytes));
            break;
        case REASON_FOUR:
            peerDown.setLocalSystemClosed(false);
            peerDown.setData(parseBgpNotificationMessage(bytes));
            break;
        case REASON_FIVE:
            peerDown.setLocalSystemClosed(false);
            break;
        default://from  ww  w  .  j a  va  2s.  co m
            break;
        }
    }

    return peerDown.build();
}

From source file:org.opendaylight.protocol.bmp.impl.tlv.StatType009TlvHandler.java

License:Open Source License

@Override
public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
    if (buffer == null) {
        return null;
    }/*from www . j av a 2s  .c  o  m*/
    return new PerAfiSafiAdjRibInTlvBuilder()
            .setAfi(this.afiRegistry.classForFamily(buffer.readUnsignedShort()))
            .setSafi(this.safiRegistry.classForFamily(buffer.readUnsignedByte()))
            .setCount(new Gauge64(new BigInteger(ByteArray.readAllBytes(buffer)))).build();
}

From source file:org.opendaylight.protocol.bmp.impl.tlv.StatType010TlvHandler.java

License:Open Source License

@Override
public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
    if (buffer == null) {
        return null;
    }//from  w w w. ja  va 2s . c o  m
    return new PerAfiSafiLocRibTlvBuilder().setAfi(this.afiRegistry.classForFamily(buffer.readUnsignedShort()))
            .setSafi(this.safiRegistry.classForFamily(buffer.readUnsignedByte()))
            .setCount(new Gauge64(new BigInteger(ByteArray.readAllBytes(buffer)))).build();
}

From source file:org.opendaylight.protocol.bmp.spi.registry.SimpleBmpMessageRegistry.java

License:Open Source License

private int parseMessageHeader(final ByteBuf buffer) throws BmpDeserializationException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(),
            "Array of bytes cannot be null or empty.");
    Preconditions.checkArgument(buffer.readableBytes() >= COMMON_HEADER_LENGTH,
            "Too few bytes in passed array. Passed: %s. Expected: >= %s.", buffer.readableBytes(),
            COMMON_HEADER_LENGTH);//from  w ww.  j a va  2s. c  om
    final short messageVersion = buffer.readUnsignedByte();
    if (messageVersion != BMP_VERSION) {
        throw new BmpDeserializationException(
                "Unsuppoted BMP version. Passed: " + messageVersion + "; Expected: " + BMP_VERSION + ".");
    }
    final long messageLength = buffer.readUnsignedInt();
    final short msgType = buffer.readUnsignedByte();
    if (messageLength - COMMON_HEADER_LENGTH != buffer.readableBytes()) {
        throw new BmpDeserializationException("Size doesn't match size specified in header. Passed: "
                + buffer.readableBytes() + COMMON_HEADER_LENGTH + "; Expected: " + messageLength + ".");
    }
    return msgType;
}

From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspObjectParser.java

License:Open Source License

@Override
public Lsp 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 LspBuilder builder = new LspBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    final int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(),
            bytes.getUnsignedByte(2), };
    builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << FLAGS_SIZE) | (plspIdRaw[1] << FOUR_BITS_SHIFT)
            | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
    parseFlags(builder, bytes);/*from www .  ja v a 2s  .c  om*/
    final TlvsBuilder b = new TlvsBuilder();
    parseTlvs(b, bytes.slice());
    builder.setTlvs(b.build());
    return builder.build();
}

From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser.java

License:Open Source License

@Override
public RsvpErrorSpec parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
    if (buffer == null) {
        return null;
    }/* w  w  w  .j  av  a  2  s. co m*/
    // throw away contents of length field
    buffer.readUnsignedShort();
    final int classNum = buffer.readUnsignedByte();
    final int classType = buffer.readUnsignedByte();
    ErrorType errorType = null;
    if (classNum == RSVP_ERROR_CLASS_NUM) {
        errorType = parseRsvp(classType, buffer.slice());
    } else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
        errorType = parseUserError(buffer.slice());
    }
    return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
}

From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser.java

License:Open Source License

private UserCase parseUserError(final ByteBuf buffer) {
    final UserErrorBuilder error = new UserErrorBuilder();
    error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt()));
    error.setSubOrg(buffer.readUnsignedByte());
    final int errDescrLength = buffer.readUnsignedByte();
    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();
}