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.bgp.linkstate.attribute.NodeAttributesParser.java

License:Open Source License

private static void parseTopologyId(final List<TopologyIdentifier> topologyMembership, final ByteBuf value) {
    while (value.isReadable()) {
        final TopologyIdentifier topId = new TopologyIdentifier(
                value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
        topologyMembership.add(topId);/*from   w  ww.  j a  v  a  2  s.  com*/
        LOG.debug("Parsed Topology Identifier: {}", topId);
    }
}

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

License:Open Source License

private static void parseRouteTags(final List<RouteTag> routeTags, final ByteBuf value) {
    while (value.isReadable()) {
        final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
        routeTags.add(routeTag);//from www.  j  a v  a  2 s  . c  om
        LOG.debug("Parsed Route Tag: {}", routeTag);
    }
}

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

License:Open Source License

private static void parseExtendedRouteTags(final List<ExtendedRouteTag> exRouteTags, final ByteBuf value) {
    while (value.isReadable()) {
        final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(
                ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH));
        exRouteTags.add(exRouteTag);//from   w w  w.  j ava2 s .c  o m
        LOG.debug("Parsed Extended Route Tag: {}", exRouteTag);
    }
}

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());/*from   www . j a  v  a2  s  . c  om*/
    }
    return subTlvs;
}

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  w ww  . ja v a  2s  .  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.SrLinkAttributesParser.java

License:Open Source License

public static AdjSidTlv 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_SIZE);
        adjFlags = parseFlags(flags, protocolId);
        weight = new Weight(buffer.readUnsignedByte());
        buffer.skipBytes(RESERVED);// www .j  av  a2  s  .  c o m
        sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer);
    } else {
        adjFlags = null;
        weight = null;
        sidValue = null;
    }
    return new AdjSidTlv() {
        @Override
        public Class<? extends DataContainer> getImplementedInterface() {
            return AdjSidTlv.class;
        }

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

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

        @Override
        public Flags getFlags() {
            return adjFlags;
        }
    };
}

From source file:org.opendaylight.protocol.bgp.linkstate.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 .ja v  a  2 s .c  o m*/
    final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
    srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED);
    if (protocolId.equals(ProtocolId.IsisLevel1) || protocolId.equals(ProtocolId.IsisLevel2)) {
        srLanAdjIdBuilder
                .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
    } else if (protocolId.equals(ProtocolId.Ospf)) {
        srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
    }
    // 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.attribute.sr.SrNodeAttributesParser.java

License:Open Source License

public static SrAlgorithm parseSrAlgorithms(final ByteBuf buffer) {
    final SrAlgorithmBuilder builder = new SrAlgorithmBuilder();
    final List<Algorithm> algs = new ArrayList<>();
    while (buffer.isReadable()) {
        algs.add(Algorithm.forValue(buffer.readUnsignedByte()));
    }/*from  w  w w.  j a  va2  s . c om*/
    builder.setAlgorithms(algs);
    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  ww w  .  jav  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.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  ww w.j  av  a2s  .  c om
            break;
        default:
            LOG.info("Unknown type of range sub-tlv: {}", type);
            buffer.skipBytes(length);
            continue;
        }
        subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build());
    }
    return subTlvs;
}