Example usage for io.netty.buffer ByteBuf readUnsignedInt

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

Introduction

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

Prototype

public abstract long readUnsignedInt();

Source Link

Document

Gets an unsigned 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

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

License:Open Source License

private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId,
        final PrefixAttributesBuilder builder, final List<RouteTag> routeTags,
        final List<ExtendedRouteTag> exRouteTags) {
    switch (key) {
    case IGP_FLAGS:
        final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
        final boolean upDownBit = flags.get(UP_DOWN_BIT);
        builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
        LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
        break;// w w w.  ja v  a  2s .  co  m
    case ROUTE_TAG:
        parseRouteTags(routeTags, value);
        break;
    case EXTENDED_ROUTE_TAG:
        parseExtendedRouteTags(exRouteTags, value);
        break;
    case PREFIX_METRIC:
        final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
        builder.setPrefixMetric(metric);
        LOG.debug("Parsed Metric: {}", metric);
        break;
    case FORWARDING_ADDRESS:
        final IpAddress fwdAddress = parseForwardingAddress(value);
        builder.setOspfForwardingAddress(fwdAddress);
        LOG.debug("Parsed FWD Address: {}", fwdAddress);
        break;
    case PREFIX_OPAQUE:
        if (LOG.isDebugEnabled()) {
            LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
        }
        break;
    case PREFIX_SID:
        final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId);
        builder.setSrPrefix(prefix);
        LOG.debug("Parsed SR Prefix: {}", prefix);
        break;
    case RANGE:
        final SrRange range = RangeTlvParser.parseSrRange(value, protocolId);
        builder.setSrRange(range);
        LOG.debug("Parsed SR Range: {}", range);
        break;
    case BINDING_SID:
        final SrBindingSidLabels label = BindingSidLabelParser.parseBindingSidLabel(value, protocolId);
        if (builder.getSrBindingSidLabels() != null) {
            builder.getSrBindingSidLabels().add(label);
        } else {
            final List<SrBindingSidLabels> labels = new ArrayList<SrBindingSidLabels>();
            labels.add(label);
            builder.setSrBindingSidLabels(labels);
        }
        LOG.debug("Parsed SR Binding SID {}", label);
        break;
    default:
        LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
    }
}

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

License:Open Source License

private static void parseSubTlv(final int type, final ByteBuf slice, final BindingSubTlvsBuilder builder,
        final ProtocolId protocolId) {
    switch (type) {
    case SidLabelIndexParser.SID_TYPE:
        final SidLabelIndex sid = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(slice.readableBytes()),
                slice);/*  w  ww .  j  a v  a  2 s .c  om*/
        builder.setBindingSubTlv(new SidLabelCaseBuilder().setSidLabelIndex(sid).build());
        break;
    case PrefixAttributesParser.PREFIX_SID:
        final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(slice, protocolId);
        builder.setBindingSubTlv(new PrefixSidCaseBuilder().setAlgorithm(prefix.getAlgorithm())
                .setFlags(prefix.getFlags()).setSidLabelIndex(prefix.getSidLabelIndex()).build());
        break;
    case ERO_METRIC:
        builder.setBindingSubTlv(
                new EroMetricCaseBuilder().setEroMetric(new TeMetric(slice.readUnsignedInt())).build());
        break;
    case ERO_IPV4:
        final Ipv4EroCase ipv4Ero = parseIpv4EroCase(slice);
        builder.setBindingSubTlv(
                new Ipv4EroCaseBuilder().setAddress(ipv4Ero.getAddress()).setLoose(ipv4Ero.isLoose()).build());
        break;
    case BACKUP_ERO_IPV4:
        final Ipv4EroCase ipv4Backup = parseIpv4EroCase(slice);
        builder.setBindingSubTlv(new Ipv4EroBackupCaseBuilder().setAddress(ipv4Backup.getAddress())
                .setLoose(ipv4Backup.isLoose()).build());
        break;
    case ERO_IPV6:
        final Ipv6EroCase ipv6ero = parseIpv6EroCase(slice);
        builder.setBindingSubTlv(
                new Ipv6EroCaseBuilder().setAddress(ipv6ero.getAddress()).setLoose(ipv6ero.isLoose()).build());
        break;
    case BACKUP_ERO_IPV6:
        final Ipv6EroCase ipv6backup = parseIpv6EroCase(slice);
        builder.setBindingSubTlv(new Ipv6EroBackupCaseBuilder().setAddress(ipv6backup.getAddress())
                .setLoose(ipv6backup.isLoose()).build());
        break;
    case UNNUMBERED_ERO:
        final UnnumberedInterfaceIdEroCase unnumbered = parseUnnumberedEroCase(slice);
        builder.setBindingSubTlv(new UnnumberedInterfaceIdEroCaseBuilder().setLoose(unnumbered.isLoose())
                .setRouterId(unnumbered.getRouterId()).setInterfaceId(unnumbered.getInterfaceId()).build());
        break;
    case BACKUP_UNNUMBERED_ERO:
        final UnnumberedInterfaceIdEroCase unnumberedBackup = parseUnnumberedEroCase(slice);
        builder.setBindingSubTlv(new UnnumberedInterfaceIdBackupEroCaseBuilder()
                .setLoose(unnumberedBackup.isLoose()).setRouterId(unnumberedBackup.getRouterId())
                .setInterfaceId(unnumberedBackup.getInterfaceId()).build());
        break;
    default:
        LOG.info("Unknown binding sub Tlv type {}", type);
        break;
    }
}

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

License:Open Source License

private static UnnumberedInterfaceIdEroCase parseUnnumberedEroCase(final ByteBuf buffer) {
    final UnnumberedInterfaceIdEroCaseBuilder builder = new UnnumberedInterfaceIdEroCaseBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    builder.setLoose(flags.get(LOOSE));//ww w.j a v a 2  s.  co m
    buffer.skipBytes(RESERVED_ERO);
    builder.setRouterId(buffer.readUnsignedInt());
    builder.setInterfaceId(buffer.readUnsignedInt());
    return builder.build();
}

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

License:Open Source License

static SidLabelIndex parseSidLabelIndex(final Size length, final ByteBuf buffer) {
    switch (length) {
    case LABEL:/*from  w  ww  .  j  a  v a  2s.c o  m*/
        return new LocalLabelCaseBuilder()
                .setLocalLabel(new MplsLabel(new Long(buffer.readUnsignedMedium() & LABEL_MASK))).build();
    case SID:
        return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build();
    case IPV6_ADD:
        return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build();
    default:
        return null;
    }
}

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

License:Open Source License

/**
 * Parse Link Attributes.// ww w.j a v  a 2s  .c om
 *
 * @param attributes key is the tlv type and value is the value of the tlv
 * @param protocolId to differentiate parsing methods
 * @return {@link LinkStateAttribute}
 */
static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes,
        final ProtocolId protocolId) {
    final LinkAttributesBuilder builder = new LinkAttributesBuilder();
    final List<SrAdjIds> srAdjIds = new ArrayList<>();
    final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
    final List<PeerSetSids> peerSetSids = new ArrayList<>();
    for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
        LOG.trace("Link attribute TLV {}", entry.getKey());
        final int key = entry.getKey();
        final ByteBuf value = entry.getValue();
        switch (key) {
        case TlvUtil.LOCAL_IPV4_ROUTER_ID:
            builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
            LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
            break;
        case TlvUtil.LOCAL_IPV6_ROUTER_ID:
            builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
            LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
            break;
        case REMOTE_IPV4_ROUTER_ID:
            builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
            LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
            break;
        case REMOTE_IPV6_ROUTER_ID:
            builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
            LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
            break;
        case ADMIN_GROUP:
            builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
            LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
            break;
        case MAX_BANDWIDTH:
            builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
            LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
            break;
        case MAX_RESERVABLE_BANDWIDTH:
            builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
            LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
            break;
        case UNRESERVED_BANDWIDTH:
            parseUnreservedBandwidth(value, builder);
            break;
        case TE_METRIC:
            builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
            LOG.debug("Parsed Metric {}", builder.getTeMetric());
            break;
        case LINK_PROTECTION_TYPE:
            builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
            LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
            break;
        case MPLS_PROTOCOL:
            final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
            builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
            LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
            break;
        case METRIC:
            // length can 3, 2 or 1
            builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
            LOG.debug("Parsed Metric {}", builder.getMetric());
            break;
        case SHARED_RISK_LINK_GROUP:
            parseSrlg(value, builder);
            break;
        case LINK_OPAQUE:
            LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
            break;
        case LINK_NAME:
            builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
            LOG.debug("Parsed Link Name : {}", builder.getLinkName());
            break;
        case SR_ADJ_ID:
            srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
            LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
            break;
        case SR_LAN_ADJ_ID:
            srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
            LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
            break;
        case PEER_NODE_SID_CODE:
            builder.setPeerNodeSid(
                    new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value))
                            .build());
            LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
            break;
        case PEER_ADJ_SID_CODE:
            builder.setPeerAdjSid(
                    new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value))
                            .build());
            LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
            break;
        case PEER_SET_SID_CODE:
            peerSetSids.add(
                    new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value))
                            .build());
            LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
            break;
        default:
            LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
        }
    }
    if (!srAdjIds.isEmpty()) {
        builder.setSrAdjIds(srAdjIds);
    }
    if (!srLanAdjIds.isEmpty()) {
        builder.setSrLanAdjIds(srLanAdjIds);
    }
    if (!peerSetSids.isEmpty()) {
        builder.setPeerSetSids(peerSetSids);
    }
    LOG.trace("Finished parsing Link Attributes.");
    return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}

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

License:Open Source License

private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId,
        final PrefixAttributesBuilder builder, final List<RouteTag> routeTags,
        final List<ExtendedRouteTag> exRouteTags) {
    switch (key) {
    case IGP_FLAGS:
        parseIgpFags(builder, value);/*  w w  w  . ja v a  2 s. c  o m*/
        break;
    case ROUTE_TAG:
        parseRouteTags(routeTags, value);
        break;
    case EXTENDED_ROUTE_TAG:
        parseExtendedRouteTags(exRouteTags, value);
        break;
    case PREFIX_METRIC:
        final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
        builder.setPrefixMetric(metric);
        LOG.debug("Parsed Metric: {}", metric);
        break;
    case FORWARDING_ADDRESS:
        final IpAddress fwdAddress = parseForwardingAddress(value);
        builder.setOspfForwardingAddress(fwdAddress);
        LOG.debug("Parsed FWD Address: {}", fwdAddress);
        break;
    case PREFIX_OPAQUE:
        if (LOG.isDebugEnabled()) {
            LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
        }
        break;
    case PREFIX_SID:
        final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId);
        builder.setSrPrefix(prefix);
        LOG.debug("Parsed SR Prefix: {}", prefix);
        break;
    case IPV6_PREFIX_SID:
        final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value);
        builder.setIpv6SrPrefix(ipv6Prefix);
        LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix);
        break;
    case RANGE:
        final SrRange range = RangeTlvParser.parseSrRange(value, protocolId);
        builder.setSrRange(range);
        LOG.debug("Parsed SR Range: {}", range);
        break;
    case BINDING_SID:
        parseBindingSid(builder, value, protocolId);
        break;
    default:
        LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
    }
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.EroMetricParser.java

License:Open Source License

@Override
public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
    return new EroMetricCaseBuilder().setEroMetric(new TeMetric(slice.readUnsignedInt())).build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser.java

License:Open Source License

static UnnumberedInterfaceIdEroCase parseUnnumberedEroCase(final ByteBuf buffer) {
    final UnnumberedInterfaceIdEroCaseBuilder builder = new UnnumberedInterfaceIdEroCaseBuilder();
    final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE);
    builder.setLoose(flags.get(Ipv4EroParser.LOOSE));
    buffer.skipBytes(Ipv4EroParser.RESERVED_ERO);
    builder.setRouterId(buffer.readUnsignedInt());
    builder.setInterfaceId(buffer.readUnsignedInt());
    return builder.build();
}

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

License:Open Source License

public static SidLabelIndex parseSidLabelIndex(final Size length, final ByteBuf buffer) {
    switch (length) {
    case LABEL:/*from   ww w . j ava  2  s.  c o m*/
        return new LocalLabelCaseBuilder()
                .setLocalLabel(new MplsLabel(new Long(buffer.readUnsignedMedium() & LABEL_MASK))).build();
    case SID:
        return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build();
    case IPV6_ADD:
        return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build();
    default:
        return null;
    }
}

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

License:Open Source License

@Override
public AreaIdentifier parseTlvBody(final ByteBuf value) {
    return new AreaIdentifier(value.readUnsignedInt());
}