Example usage for io.netty.buffer ByteBuf readUnsignedShort

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

Introduction

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

Prototype

public abstract int readUnsignedShort();

Source Link

Document

Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

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

License:Open Source License

private static List<BindingSubTlvs> parseBindingSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
    final List<BindingSubTlvs> subTlvs = new ArrayList<BindingSubTlvs>();
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        final ByteBuf slice = buffer.readSlice(length);
        final BindingSubTlvsBuilder builder = new BindingSubTlvsBuilder();
        parseSubTlv(type, slice, builder, protocolId);
        subTlvs.add(builder.build());/*w w w  .  j  a va 2 s  . c  o  m*/
    }
    return subTlvs;
}

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

License:Open Source License

public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) {
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    final SrRangeBuilder range = new SrRangeBuilder();
    if (protocolId.equals(ProtocolId.Ospf)) {
        range.setInterArea(flags.get(INNER_AREA));
    } else {// www  .  j av a 2s .  c  o m
        range.setInterArea(Boolean.FALSE);
    }
    buffer.skipBytes(RESERVED);
    range.setRangeSize(buffer.readUnsignedShort());
    range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId));
    return range.build();
}

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

License:Open Source License

private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
    final List<SubTlvs> subTlvs = new ArrayList<>();
    while (buffer.isReadable()) {
        final SubTlvsBuilder subTlv = new SubTlvsBuilder();
        RangeSubTlv subTlvCase = null;/*from   www  .  ja v  a  2  s . c o m*/
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        switch (type) {
        case PrefixAttributesParser.PREFIX_SID:
            subTlvCase = new PrefixSidTlvCaseBuilder(
                    SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build();
            break;
        case PrefixAttributesParser.BINDING_SID:
            subTlvCase = new BindingSidTlvCaseBuilder(
                    BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
            break;
        case SidLabelIndexParser.SID_TYPE:
            subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(
                    SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length)))
                    .build();
            break;
        default:
            LOG.info("Unknown type of range sub-tlv: {}", type);
            buffer.skipBytes(length);
            continue;
        }
        subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build());
    }
    return subTlvs;
}

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

License:Open Source License

static SidLabelIndex parseSidSubTlv(final ByteBuf buffer) {
    final int type = buffer.readUnsignedShort();
    if (type != SID_TYPE) {
        LOG.warn("Unexpected type in SID/index/label field, expected {}, actual {}, ignoring it", SID_TYPE,
                type);/* ww  w  .j a  v a 2s.  c o  m*/
        return null;
    }
    final int length = buffer.readUnsignedShort();
    return parseSidLabelIndex(Size.forValue(length), buffer);
}

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 {/*  www.  java2s. 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.RangeTlvParser.java

License:Open Source License

private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
    final List<SubTlvs> subTlvs = new ArrayList<>();
    while (buffer.isReadable()) {
        final SubTlvsBuilder subTlv = new SubTlvsBuilder();
        final RangeSubTlv subTlvCase;
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        switch (type) {
        case PREFIX_SID:
            subTlvCase = new PrefixSidTlvCaseBuilder(
                    SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build();
            break;
        case IPV6_PREFIX_SID:
            subTlvCase = new Ipv6PrefixSidTlvCaseBuilder(
                    Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build();
            break;
        case BINDING_SID:
            subTlvCase = new BindingSidTlvCaseBuilder(
                    BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
            break;
        case SID_TYPE:
            subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(
                    SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length)))
                    .build();//from  w ww .  ja v  a2  s .  co m
            break;
        default:
            LOG.info("Unknown type of range sub-tlv: {}", type);
            buffer.skipBytes(length);
            continue;
        }
        subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build());
    }
    return subTlvs;
}

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 {//w ww.j  av  a2s  .  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.nlri.TeLspIpv4NlriParser.java

License:Open Source License

@Override
protected ObjectType parseObjectType(final ByteBuf buffer) {
    final TeLspCaseBuilder builder = new TeLspCaseBuilder();
    final Ipv4CaseBuilder ipv4CaseBuilder = new Ipv4CaseBuilder();
    ipv4CaseBuilder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
    builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
    builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
    ipv4CaseBuilder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
    return builder.setAddressFamily(ipv4CaseBuilder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.nlri.TeLspIpv6NlriParser.java

License:Open Source License

@Override
protected ObjectType parseObjectType(final ByteBuf buffer) {
    final TeLspCaseBuilder builder = new TeLspCaseBuilder();
    final Ipv6CaseBuilder ipv6CaseBuilder = new Ipv6CaseBuilder();
    ipv6CaseBuilder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer));
    builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
    builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
    ipv6CaseBuilder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(buffer));
    return builder.setAddressFamily(ipv6CaseBuilder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser.java

License:Open Source License

static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
    final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        final ByteBuf value = buffer.readSlice(length);
        LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value));
        switch (type) {
        case LINK_LR_IDENTIFIERS:
            builder.setLinkLocalIdentifier(value.readUnsignedInt());
            builder.setLinkRemoteIdentifier(value.readUnsignedInt());
            LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
                    builder.getLinkRemoteIdentifier());
            break;
        case IPV4_IFACE_ADDRESS:
            final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(
                    Ipv4Util.addressForByteBuf(value));
            builder.setIpv4InterfaceAddress(lipv4);
            LOG.debug("Parsed IPv4 interface address {}.", lipv4);
            break;
        case IPV4_NEIGHBOR_ADDRESS:
            final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(
                    Ipv4Util.addressForByteBuf(value));
            builder.setIpv4NeighborAddress(ripv4);
            LOG.debug("Parsed IPv4 neighbor address {}.", ripv4);
            break;
        case IPV6_IFACE_ADDRESS:
            final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(
                    Ipv6Util.addressForByteBuf(value));
            builder.setIpv6InterfaceAddress(lipv6);
            LOG.debug("Parsed IPv6 interface address {}.", lipv6);
            break;
        case IPV6_NEIGHBOR_ADDRESS:
            final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(
                    Ipv6Util.addressForByteBuf(value));
            builder.setIpv6NeighborAddress(ripv6);
            LOG.debug("Parsed IPv6 neighbor address {}.", ripv6);
            break;
        case TlvUtil.MULTI_TOPOLOGY_ID:
            final TopologyIdentifier topId = new TopologyIdentifier(
                    value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
            builder.setMultiTopologyId(topId);
            LOG.debug("Parsed topology identifier {}.", topId);
            break;
        default://from   w w w . j  ava 2s  .  c  om
            throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
        }
    }
    LOG.trace("Finished parsing Link descriptors.");
    return builder.build();
}