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.linkstate.attribute.sr.SrPrefixAttributesParser.java

License:Open Source License

public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) {
    final SrPrefixBuilder builder = new SrPrefixBuilder();
    builder.setFlags(parsePrefixFlags(BitArray.valueOf(buffer, FLAGS_SIZE), protocol));
    builder.setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED_PREFIX);/*from   w  w  w .j  a  va  2 s  .c o  m*/
    builder.setSidLabelIndex(
            SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
    return builder.build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.attribute.TeLspAttributesParser.java

License:Open Source License

public static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry,
        final ByteBuf attributes) throws BGPParsingException {

    final TeLspAttributesBuilder builder = new TeLspAttributesBuilder();
    LOG.trace("Initiated parsing TE LSP Objects.");
    while (attributes.isReadable()) {
        final int length = attributes.readUnsignedShort();
        final int classNum = attributes.readUnsignedByte();
        final int cType = attributes.readUnsignedByte();
        final ByteBuf value = attributes.readSlice(length);
        try {//from w  ww . j a v  a 2 s  . c  o m
            addObject(builder, registry.parseRSPVTe(classNum, cType, value));
        } catch (final RSVPParsingException e) {
            LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType,
                    value, e);
            throw new BGPParsingException(e.getMessage());
        }
    }
    LOG.trace("Finished parsing TE LSP Objects.");
    return new TeLspAttributesCaseBuilder().setTeLspAttributes(builder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.BindingSidLabelParser.java

License:Open Source License

public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) {
    final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder();
    bindingSid.setWeight(new Weight(buffer.readUnsignedByte()));
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    bindingSid.setFlags(parseBindingSidFlags(flags, protocolId));
    buffer.skipBytes(RESERVED_BINDING_SID);
    bindingSid.setBindingSubTlvs(/*from  w ww. j a v  a2 s.  c o m*/
            SimpleBindingSubTlvsRegistry.getInstance().parseBindingSubTlvs(buffer, protocolId));
    return bindingSid.build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser.java

License:Open Source License

public static Ipv6SrPrefix parseSrIpv6Prefix(final ByteBuf buffer) {
    final Ipv6SrPrefixBuilder builder = new Ipv6SrPrefixBuilder();
    buffer.skipBytes(FLAGS_SIZE);// www  .j a v a2s .co  m
    builder.setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
    return builder.build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser.java

License:Open Source License

public static SrAdjIds parseAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
    final Flags adjFlags;
    final Weight weight;
    final SidLabelIndex sidValue;
    if (buffer.isReadable()) {
        final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
        adjFlags = parseFlags(flags, protocolId);
        weight = new Weight(buffer.readUnsignedByte());
        buffer.skipBytes(RESERVED);/* w  ww.j a  v a2 s .  c o m*/
        sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer);
    } else {
        adjFlags = null;
        weight = null;
        sidValue = null;
    }
    return new SrAdjIdsBuilder().setFlags(adjFlags).setSidLabelIndex(sidValue).setWeight(weight).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser.java

License:Open Source License

public static EpeAdjSidTlv parseEpeAdjacencySegmentIdentifier(final ByteBuf buffer) {
    final Weight weight;
    final SidLabelIndex sidValue;
    if (buffer.isReadable()) {
        buffer.skipBytes(FLAGS_BYTE_SIZE);
        weight = new Weight(buffer.readUnsignedByte());
        buffer.skipBytes(RESERVED);//from   w w w  . ja va  2  s . c  om
        sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer);
    } else {
        weight = null;
        sidValue = null;
    }
    return new EpeAdjSidTlv() {
        @Override
        public Class<? extends DataContainer> getImplementedInterface() {
            return EpeAdjSidTlv.class;
        }

        @Override
        public Weight getWeight() {
            return weight;
        }

        @Override
        public SidLabelIndex getSidLabelIndex() {
            return sidValue;
        }
    };
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser.java

License:Open Source License

public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer,
        final ProtocolId protocolId) {
    if (!buffer.isReadable()) {
        return new SrLanAdjIdsBuilder().build();
    }// w  w  w  .  j a  v  a2  s  . c om
    final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
    srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
    srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED);
    switch (protocolId) {
    case IsisLevel1:
    case IsisLevel2:
        srLanAdjIdBuilder
                .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
        break;
    case Ospf:
    case OspfV3:
        srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
        break;
    default:
        return null;
    }
    // length determines a type of next field, which is used for parsing
    srLanAdjIdBuilder.setSidLabelIndex(
            SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
    return srLanAdjIdBuilder.build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.TeLspAttributesParser.java

License:Open Source License

static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes)
        throws BGPParsingException {

    final TeLspAttributesBuilder builder = new TeLspAttributesBuilder();
    LOG.trace("Initiated parsing TE LSP Objects.");
    while (attributes.isReadable()) {
        final int length = attributes.readUnsignedShort();
        final int classNum = attributes.readUnsignedByte();
        final int cType = attributes.readUnsignedByte();
        final ByteBuf value = attributes.readSlice(length);
        try {/*ww  w .j a va2  s  .  com*/
            addObject(builder, registry.parseRSPVTe(classNum, cType, value));
        } catch (final RSVPParsingException e) {
            LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType,
                    value, e);
            throw new BGPParsingException(e.getMessage());
        }
    }
    LOG.trace("Finished parsing TE LSP Objects.");
    return new TeLspAttributesCaseBuilder().setTeLspAttributes(builder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser.java

License:Open Source License

@Override
public OspfRouteType parseTlvBody(final ByteBuf value) {
    return OspfRouteType.forValue(value.readUnsignedByte());
}

From source file:org.opendaylight.protocol.bgp.linkstate.spi.AbstractNlriTypeCodec.java

License:Open Source License

@Override
public final CLinkstateDestination parseTypeNlri(final ByteBuf nlri) {
    final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
    builder.setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte()));
    builder.setIdentifier(new Identifier(BigInteger.valueOf(nlri.readLong())));
    builder.setObjectType(parseObjectType(nlri));
    return builder.build();
}