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.evpn.impl.esi.types.ASGenParser.java

License:Open Source License

@Override
public Esi parseEsi(final ByteBuf buffer) {
    final AsGenerated asGen = new AsGeneratedBuilder().setAs(new AsNumber(buffer.readUnsignedInt()))
            .setLocalDiscriminator(buffer.readUnsignedInt()).build();
    return new AsGeneratedCaseBuilder().setAsGenerated(asGen).build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.esi.types.RouterIdParser.java

License:Open Source License

@Override
public Esi parseEsi(final ByteBuf buffer) {
    final RouterIdGenerated routerID = new RouterIdGeneratedBuilder()
            .setRouterId(Ipv4Util.addressForByteBuf(buffer)).setLocalDiscriminator(buffer.readUnsignedInt())
            .build();/*from  w w  w .ja va2s.  co  m*/
    return new RouterIdGeneratedCaseBuilder().setRouterIdGenerated(routerID).build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.extended.communities.MACMobExtCom.java

License:Open Source License

@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
        throws BGPDocumentedException, BGPParsingException {
    final boolean isStatic = buffer.readBoolean();
    buffer.skipBytes(RESERVED);//  w  w w. jav  a2 s .co m
    final long seqNumber = buffer.readUnsignedInt();
    return new MacMobilityExtendedCommunityCaseBuilder().setMacMobilityExtendedCommunity(
            new MacMobilityExtendedCommunityBuilder().setStatic(isStatic).setSeqNumber(seqNumber).build())
            .build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParser.java

License:Open Source License

@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
    Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH,
            "Wrong length of array of bytes. Passed: %s ;", buffer);
    final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
    final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
    final MplsLabel label = mplsLabelForByteBuf(buffer);
    final EthernetADRouteBuilder builder = new EthernetADRouteBuilder().setEsi(esi).setEthernetTagId(eti)
            .setMplsLabel(label);//from  w w w  .ja  va  2s .co  m
    return new EthernetADRouteCaseBuilder().setEthernetADRoute(builder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.IncMultEthTagRParser.java

License:Open Source License

@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
    Preconditions.checkArgument(/*from  ww w  . ja v  a2 s .co m*/
            buffer.readableBytes() == CONTENT_LENGTH || buffer.readableBytes() == CONTENT_LENGTH2,
            "Wrong length of array of bytes. Passed: %s ;", buffer);

    final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
    IpAddress ip = Preconditions.checkNotNull(EthSegRParser.parseOrigRouteIp(buffer));
    final IncMultiEthernetTagResBuilder builder = new IncMultiEthernetTagResBuilder().setEthernetTagId(eti)
            .setOrigRouteIp(ip);
    return new IncMultiEthernetTagResCaseBuilder().setIncMultiEthernetTagRes(builder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.MACIpAdvRParser.java

License:Open Source License

@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
    final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
    final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
    buffer.skipBytes(1);/*  ww  w  . j a  v a  2s.c om*/
    final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH));
    final IpAddress ip = parseIp(buffer);
    final MplsLabel label1 = mplsLabelForByteBuf(buffer);
    MplsLabel label2;
    if (buffer.readableBytes() > 0) {
        label2 = mplsLabelForByteBuf(buffer);
    } else {
        label2 = null;
    }
    final MacIpAdvRouteBuilder builder = new MacIpAdvRouteBuilder().setEsi(esi).setEthernetTagId(eti)
            .setMacAddress(mac).setIpAddress(ip).setMplsLabel1(label1).setMplsLabel2(label2);
    return new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(builder.build()).build();
}

From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsFourOctetEcHandler.java

License:Open Source License

@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
        throws BGPDocumentedException, BGPParsingException {
    final RedirectAs4Builder builder = new RedirectAs4Builder();
    builder.setGlobalAdministrator(new AsNumber(buffer.readUnsignedInt()));
    builder.setLocalAdministrator(buffer.readUnsignedShort());
    return new RedirectAs4ExtendedCommunityCaseBuilder().setRedirectAs4(builder.build()).build();
}

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

License:Open Source License

@Override
public LuLabelIndexTlv parseBgpPrefixSidTlv(final ByteBuf buffer) {
    buffer.readBytes(RESERVED);/* ww  w  .  jav  a  2 s.c o m*/
    buffer.readBytes(LABEL_INDEX_FLAGS_BYTES);
    final Long value = buffer.readUnsignedInt();
    return new LuLabelIndexTlvBuilder().setLabelIndexTlv(value).build();
}

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

License:Open Source License

/**
 * Parse Link Attributes.//  ww  w.  j av  a2  s .  c  o m
 *
 * @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<SrAdjIds>();
    final List<SrLanAdjIds> srLanAdjIds = new ArrayList<SrLanAdjIds>();
    final List<PeerSetSids> peerSetSids = new ArrayList<PeerSetSids>();
    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), Charsets.US_ASCII));
            LOG.debug("Parsed Link Name : {}", builder.getLinkName());
            break;
        case SR_ADJ_ID:
            srAdjIds.add(new SrAdjIdsBuilder(
                    SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId)).build());
            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.parseAdjacencySegmentIdentifier(value, null))
                            .build());
            LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
            break;
        case PEER_ADJ_SID_CODE:
            builder.setPeerAdjSid(
                    new PeerAdjSidBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, null))
                            .build());
            LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
            break;
        case PEER_SET_SID_CODE:
            peerSetSids.add(
                    new PeerSetSidsBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, null))
                            .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.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()));
    }/*  w w w  . j a  v a 2s.c  om*/
    builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
    LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
}