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.l3vpn.AbstractVpnNlriParser.java

License:Open Source License

private static List<VpnDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi) {
    if (!nlri.isReadable()) {
        return null;
    }/*from   ww  w  .  jav a  2  s  .co  m*/
    final List<VpnDestination> dests = new ArrayList<>();

    while (nlri.isReadable()) {
        final VpnDestinationBuilder builder = new VpnDestinationBuilder();
        final short length = nlri.readUnsignedByte();
        builder.setLabelStack(LUNlriParser.parseLabel(nlri));
        final int labelNum = builder.getLabelStack().size();
        final int prefixLen = length - (LUNlriParser.LABEL_LENGTH * Byte.SIZE * labelNum)
                - (RouteDistinguisherUtil.RD_LENGTH * Byte.SIZE);
        builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
        Preconditions.checkState(prefixLen > 0, "A valid VPN IP prefix is required.");
        builder.setPrefix(LUNlriParser.parseIpPrefix(nlri, prefixLen, afi));
        dests.add(builder.build());
    }
    return dests;
}

From source file:org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser.java

License:Open Source License

@Override
public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
    if (!nlri.isReadable()) {
        return;/*w w  w.j  av a  2s .  c o m*/
    }
    final List<VpnDestination> dst = parseNlri(nlri, builder.getAfi());
    builder.setWithdrawnRoutes(getWithdrawnRoutesByDestination(dst));
}

From source file:org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser.java

License:Open Source License

@Override
public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
    if (!nlri.isReadable()) {
        return;//  w  ww.jav a  2  s . c o m
    }
    final List<VpnDestination> dst = parseNlri(nlri, builder.getAfi());
    builder.setAdvertizedRoutes(getAdvertizedRoutesByDestination(dst));
}

From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java

License:Open Source License

private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri,
        final Class<? extends AddressFamily> afi, final boolean mPathSupported) {
    if (!nlri.isReadable()) {
        return null;
    }//from   w  w  w.j a  v a2 s  . co m
    final List<CLabeledUnicastDestination> dests = new ArrayList<>();

    while (nlri.isReadable()) {
        final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder();
        if (mPathSupported) {
            builder.setPathId(PathIdUtil.readPathId(nlri));
        }
        final short length = nlri.readUnsignedByte();
        builder.setLabelStack(parseLabel(nlri));
        final int labelNum = builder.getLabelStack().size();
        final int prefixLen = length - (LABEL_LENGTH * Byte.SIZE * labelNum);
        builder.setPrefix(parseIpPrefix(nlri, prefixLen, afi));
        dests.add(builder.build());
    }
    return dests;
}

From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java

License:Open Source License

public static List<LabelStack> parseLabel(final ByteBuf nlri) {
    if (!nlri.isReadable()) {
        return null;
    }/*from   w w  w . j  a v a2 s  .  c om*/
    final List<LabelStack> labels = new ArrayList<>();
    boolean bottomBit;
    do {
        final ByteBuf slice = nlri.readSlice(LABEL_LENGTH);
        bottomBit = MplsLabelUtil.getBottomBit(slice);
        labels.add(new LabelStackBuilder().setLabelValue(MplsLabelUtil.mplsLabelForByteBuf(slice)).build());
    } while (!bottomBit);
    return labels;
}

From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java

License:Open Source License

@Override
public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder,
        @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
    if (!nlri.isReadable()) {
        return;// w w w.  j  av  a  2s  .  c  om
    }
    final Class<? extends AddressFamily> afi = builder.getAfi();
    final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
            new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
    final List<CLabeledUnicastDestination> dst = parseNlri(nlri, afi, mPathSupported);

    DestinationType destination = null;
    if (afi == Ipv4AddressFamily.class) {
        destination = new DestinationLabeledUnicastCaseBuilder()
                .setDestinationLabeledUnicast(
                        new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(dst).build())
                .build();
    } else if (afi == Ipv6AddressFamily.class) {
        destination = new DestinationIpv6LabeledUnicastCaseBuilder()
                .setDestinationIpv6LabeledUnicast(
                        new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(dst).build())
                .build();
    }
    builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(destination).build());
}

From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java

License:Open Source License

@Override
public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder,
        @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
    if (!nlri.isReadable()) {
        return;/*from  w  w  w.ja  v a  2 s.  com*/
    }
    final Class<? extends AddressFamily> afi = builder.getAfi();

    final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
            new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
    final List<CLabeledUnicastDestination> dst = parseNlri(nlri, afi, mPathSupported);

    DestinationType destination = null;
    if (afi == Ipv4AddressFamily.class) {
        destination = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
                .setDestinationLabeledUnicast(
                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
                                .setCLabeledUnicastDestination(dst).build())
                .build();
    } else if (afi == Ipv6AddressFamily.class) {
        destination = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
                .setDestinationIpv6LabeledUnicast(
                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
                                .setCLabeledUnicastDestination(dst).build())
                .build();
    }
    builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(destination).build());
}

From source file:org.opendaylight.protocol.bgp.labeled.unicast.OriginatorSrgbTlvParser.java

License:Open Source License

private static List<SrgbValue> parseSrgbs(final ByteBuf buffer) {
    Preconditions.checkState(buffer.readableBytes() % SRGB_LENGTH == 0,
            "Number of SRGBs doesn't fit available bytes.");
    final List<SrgbValue> ret = new ArrayList<SrgbValue>();
    while (buffer.isReadable()) {
        ret.add(new SrgbValueBuilder().setBase(new Srgb((long) buffer.readUnsignedMedium()))
                .setRange(new Srgb((long) buffer.readUnsignedMedium())).build());
    }// w  w  w  .j  a  v  a2 s .c o m
    return ret;
}

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

License:Open Source License

private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
    final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
    while (value.isReadable()) {
        sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
    }//from   w ww .  j ava  2s. c  om
    builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
    LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
}

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

License:Open Source License

private static Multimap<Integer, ByteBuf> getAttributesMap(final ByteBuf buffer) {
    /*//from  w w  w.  j ava 2s  .c o  m
     * e.g. IS-IS Area Identifier TLV can occur multiple times
     */
    final Multimap<Integer, ByteBuf> map = HashMultimap.create();
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        final ByteBuf value = buffer.readSlice(length);
        map.put(type, value);
    }
    return map;
}