Example usage for io.netty.buffer ByteBufUtil hexDump

List of usage examples for io.netty.buffer ByteBufUtil hexDump

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufUtil hexDump.

Prototype

public static String hexDump(byte[] array) 

Source Link

Document

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified byte array.

Usage

From source file:org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder.java

License:Open Source License

@Override
public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out)
        throws IOException, SAXException {
    if (in.isReadable()) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
        }/*from w w  w. j a v  a  2 s .c om*/

        /* According to the XML 1.0 specifications, when there is an XML declaration
         * at the beginning of an XML document, it is invalid to have
         * white spaces before that declaration (reminder: a XML declaration looks like:
         * <?xml version="1.0" encoding="UTF-8"?>). In contrast, when there is no XML declaration,
         * it is valid to have white spaces at the beginning of the document.
         *
         * When they send a NETCONF message, several NETCONF servers start with a new line (either
         * LF or CRLF), presumably to improve readability in interactive sessions with a human being.
         * Some NETCONF servers send an XML declaration, some others do not.
         *
         * If a server starts a NETCONF message with white spaces and follows with an XML
         * declaration, XmlUtil.readXmlToDocument() will fail because this is invalid XML.
         * But in the spirit of the "NETCONF over SSH" RFC 4742 and to improve interoperability, we want
         * to accept those messages.
         *
         * To do this, the following code strips the leading bytes before the start of the XML messages.
         */

        // Skip all leading whitespaces by moving the reader index to the first non whitespace character
        while (in.isReadable()) {
            if (!isWhitespace(in.readByte())) {
                // return reader index to the first non whitespace character
                in.readerIndex(in.readerIndex() - 1);
                break;
            }
        }

        // Warn about leading whitespaces
        if (in.readerIndex() != 0 && LOG.isWarnEnabled()) {
            final byte[] strippedBytes = new byte[in.readerIndex()];
            in.getBytes(0, strippedBytes, 0, in.readerIndex());
            LOG.warn("XML message with unwanted leading bytes detected. Discarded the {} leading byte(s): '{}'",
                    in.readerIndex(), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(strippedBytes)));
        }
    }
    if (in.isReadable()) {
        out.add(new NetconfMessage(XmlUtil.readXmlToDocument(new ByteBufInputStream(in))));
    } else {
        LOG.debug("No more content in incoming buffer.");
    }
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.attributes.tunnel.identifier.MldpP2mpLspParser.java

License:Open Source License

@Override
public TunnelIdentifier parse(final ByteBuf buffer) {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.p2mp.lsp.MldpP2mpLspBuilder mldpP2mpLsp = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.p2mp.lsp.MldpP2mpLspBuilder();
    buffer.skipBytes(RESERVED);/*  w w w.  j a va2s  .com*/
    final Class<? extends AddressFamily> addressFamily = this.addressFamilyRegistry
            .classForFamily(buffer.readUnsignedShort());
    if (addressFamily == null) {
        LOG.debug("Skipping serialization of TunnelIdentifier {}, address family type  supported",
                ByteBufUtil.hexDump(buffer));
        return null;
    }
    mldpP2mpLsp.setAddressFamily(addressFamily);
    final short rootNodeLength = buffer.readUnsignedByte();
    mldpP2mpLsp.setRootNodeAddress(parseIpAddress(rootNodeLength, buffer.readBytes(rootNodeLength)));
    final int opaqueValueLength = buffer.readUnsignedShort();
    mldpP2mpLsp.setOpaqueValue(OpaqueUtil.parseOpaqueList(buffer.readBytes(opaqueValueLength)));
    return new MldpP2mpLspBuilder().setMldpP2mpLsp(mldpP2mpLsp.build()).build();
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.attributes.tunnel.identifier.OpaqueUtil.java

License:Open Source License

private static HexString buildOpaqueValue(final ByteBuf buffer) {
    final int length = buffer.readUnsignedShort();
    final byte[] value = ByteArray.readBytes(buffer, length);
    final String hexDump = ByteBufUtil.hexDump(value);
    final Iterable<String> splitted = Splitter.fixedLength(2).split(hexDump);
    return new HexString(Joiner.on(SEPARATOR).join(splitted));
}

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

License:Open Source License

/**
 * Parse Link Attributes./*from w  ww  .j a v  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.NodeAttributesParser.java

License:Open Source License

/**
 * Parse Node Attributes./*from   w w  w. j  a v  a 2s .co  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 parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes,
        final ProtocolId protocolId) {
    final List<TopologyIdentifier> topologyMembership = new ArrayList<>();
    final List<IsisAreaIdentifier> areaMembership = new ArrayList<>();
    final NodeAttributesBuilder builder = new NodeAttributesBuilder();
    for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
        final int key = entry.getKey();
        final ByteBuf value = entry.getValue();
        LOG.trace("Node attribute TLV {}", key);
        switch (key) {
        case TlvUtil.MULTI_TOPOLOGY_ID:
            parseTopologyId(topologyMembership, value);
            break;
        case NODE_FLAG_BITS:
            final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
            builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT),
                    flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT), flags.get(ROUTER_BIT), flags.get(V6_BIT)));
            LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
                    flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT),
                    flags.get(ABBR_BIT));
            break;
        case NODE_OPAQUE:
            if (LOG.isDebugEnabled()) {
                LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
            }
            break;
        case DYNAMIC_HOSTNAME:
            builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), Charsets.US_ASCII));
            LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
            break;
        case ISIS_AREA_IDENTIFIER:
            final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
            areaMembership.add(ai);
            LOG.debug("Parsed AreaIdentifier {}", ai);
            break;
        case TlvUtil.LOCAL_IPV4_ROUTER_ID:
            final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
            builder.setIpv4RouterId(ip4);
            LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
            break;
        case TlvUtil.LOCAL_IPV6_ROUTER_ID:
            final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
            builder.setIpv6RouterId(ip6);
            LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
            break;
        case SR_CAPABILITIES:
            final SrCapabilities caps = SrNodeAttributesParser.parseSrCapabilities(value, protocolId);
            builder.setSrCapabilities(caps);
            LOG.debug("Parsed SR Capabilities {}", caps);
            break;
        case SR_ALGORITHMS:
            final SrAlgorithm algs = SrNodeAttributesParser.parseSrAlgorithms(value);
            builder.setSrAlgorithm(algs);
            LOG.debug("Parsed SR Algorithms {}", algs);
            break;
        default:
            LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
        }
    }
    LOG.trace("Finished parsing Node Attributes.");
    builder.setTopologyIdentifier(topologyMembership);
    builder.setIsisAreaId(areaMembership);
    return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
}

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;// ww  w  .j  av a  2  s. c o  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.impl.attribute.LinkAttributesParser.java

License:Open Source License

/**
 * Parse Link Attributes./*from  w w w .  jav  a  2s  . com*/
 *
 * @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.NodeAttributesParser.java

License:Open Source License

/**
 * Parse Node Attributes./*from   ww  w  .  j  av  a  2s .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 parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes,
        final ProtocolId protocolId) {
    final List<TopologyIdentifier> topologyMembership = new ArrayList<>();
    final List<IsisAreaIdentifier> areaMembership = new ArrayList<>();
    final NodeAttributesBuilder builder = new NodeAttributesBuilder();
    for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
        final int key = entry.getKey();
        final ByteBuf value = entry.getValue();
        LOG.trace("Node attribute TLV {}", key);
        switch (key) {
        case TlvUtil.MULTI_TOPOLOGY_ID:
            parseTopologyId(topologyMembership, value);
            break;
        case NODE_FLAG_BITS:
            parseNodeFlags(value, builder);
            break;
        case NODE_OPAQUE:
            if (LOG.isDebugEnabled()) {
                LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
            }
            break;
        case DYNAMIC_HOSTNAME:
            builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
            LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
            break;
        case ISIS_AREA_IDENTIFIER:
            final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
            areaMembership.add(ai);
            LOG.debug("Parsed AreaIdentifier {}", ai);
            break;
        case TlvUtil.LOCAL_IPV4_ROUTER_ID:
            final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
            builder.setIpv4RouterId(ip4);
            LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
            break;
        case TlvUtil.LOCAL_IPV6_ROUTER_ID:
            final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
            builder.setIpv6RouterId(ip6);
            LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
            break;
        case SR_CAPABILITIES:
            final SrCapabilities caps = SrNodeAttributesParser.parseSrCapabilities(value, protocolId);
            builder.setSrCapabilities(caps);
            LOG.debug("Parsed SR Capabilities {}", caps);
            break;
        case SR_ALGORITHMS:
            final SrAlgorithm algs = SrNodeAttributesParser.parseSrAlgorithms(value);
            builder.setSrAlgorithm(algs);
            LOG.debug("Parsed SR Algorithms {}", algs);
            break;
        default:
            LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
        }
    }
    LOG.trace("Finished parsing Node Attributes.");
    builder.setTopologyIdentifier(topologyMembership);
    builder.setIsisAreaId(areaMembership);
    return new NodeAttributesCaseBuilder().setNodeAttributes(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);/*  ww  w.j ava  2 s .  c  om*/
        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.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://w ww  .j  ava 2  s.  c  o m
            throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
        }
    }
    LOG.trace("Finished parsing Link descriptors.");
    return builder.build();
}