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.protocol.bgp.linkstate.nlri.NodeNlriParser.java

License:Open Source License

static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier parseNodeDescriptors(
        final ByteBuf buffer, final NlriType nlriType, final boolean local) throws BGPParsingException {
    AsNumber asnumber = null;/*from   ww  w .ja  va 2 s  .  co m*/
    DomainIdentifier bgpId = null;
    AreaIdentifier ai = null;
    CRouterIdentifier routerId = null;
    AsNumber memberAsn = null;
    Ipv4Address bgpRouterId = null;
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        final ByteBuf value = buffer.readSlice(length);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value));
        }
        switch (type) {
        case AS_NUMBER:
            asnumber = new AsNumber(value.readUnsignedInt());
            LOG.debug("Parsed {}", asnumber);
            break;
        case BGP_LS_ID:
            bgpId = new DomainIdentifier(value.readUnsignedInt());
            LOG.debug("Parsed {}", bgpId);
            break;
        case AREA_ID:
            ai = new AreaIdentifier(value.readUnsignedInt());
            LOG.debug("Parsed area identifier {}", ai);
            break;
        case IGP_ROUTER_ID:
            routerId = parseRouterId(value);
            LOG.debug("Parsed Router Identifier {}", routerId);
            break;
        case BGP_ROUTER_ID:
            bgpRouterId = Ipv4Util.addressForByteBuf(value);
            LOG.debug("Parsed BGP Router Identifier {}", bgpRouterId);
            break;
        case MEMBER_AS_NUMBER:
            memberAsn = new AsNumber(value.readUnsignedInt());
            LOG.debug("Parsed Member AsNumber {}", memberAsn);
            break;
        default:
            throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
        }
    }
    LOG.trace("Finished parsing Node descriptors.");
    return correctType(nlriType, local, asnumber, ai, routerId, bgpId, bgpRouterId, memberAsn);
}

From source file:org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriParser.java

License:Open Source License

static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4)
        throws BGPParsingException {
    final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        final ByteBuf value = buffer.readSlice(length);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value));
        }// w w w  .java  2 s. c o m
        switch (type) {
        case TlvUtil.MULTI_TOPOLOGY_ID:
            final TopologyIdentifier topologyId = new TopologyIdentifier(
                    value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
            builder.setMultiTopologyId(topologyId);
            LOG.trace("Parsed Topology Identifier: {}", topologyId);
            break;
        case OSPF_ROUTE_TYPE:
            final int rt = value.readByte();
            final OspfRouteType routeType = OspfRouteType.forValue(rt);
            if (routeType == null) {
                throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
            }
            builder.setOspfRouteType(routeType);
            LOG.trace("Parser RouteType: {}", routeType);
            break;
        case IP_REACHABILITY:
            final IpPrefix prefix = (ipv4) ? new IpPrefix(Ipv4Util.prefixForByteBuf(value))
                    : new IpPrefix(Ipv6Util.prefixForByteBuf(value));
            builder.setIpReachabilityInformation(prefix);
            LOG.trace("Parsed IP reachability info: {}", prefix);
            break;
        default:
            throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
        }
    }
    LOG.debug("Finished parsing Prefix descriptors.");
    return builder.build();
}

From source file:org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil.java

License:Open Source License

/**
 * Util method for writing TLV header./*from  w  w w .j a va2s. c om*/
 *
 * @param type TLV type (2B)
 * @param value TLV value (2B)
 * @param byteAggregator final ByteBuf where the tlv should be serialized
 */
public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator) {
    byteAggregator.writeShort(type);
    byteAggregator.writeShort(value.writerIndex());
    byteAggregator.writeBytes(value);
    if (LOG.isDebugEnabled()) {
        value.readerIndex(0);
        LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
    }
}

From source file:org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser.java

License:Open Source License

/**
 * Serializes BGP Notification message.//from  w ww .j ava  2s . c  o m
 *
 * @param msg to be serialized
 * @param bytes ByteBuf where the message will be serialized
 */
@Override
public void serializeMessage(final Notification msg, final ByteBuf bytes) {
    Preconditions.checkArgument(msg instanceof Notify, "Message needs to be of type Notify");
    final Notify ntf = (Notify) msg;

    final ByteBuf msgBody = Unpooled.buffer();
    msgBody.writeByte(ntf.getErrorCode());
    msgBody.writeByte(ntf.getErrorSubcode());
    final byte[] data = ntf.getData();
    if (data != null) {
        msgBody.writeBytes(data);
    }
    LOG.trace("Notification message serialized to: {}", ByteBufUtil.hexDump(msgBody));
    MessageUtil.formatMessage(TYPE, msgBody, bytes);
}

From source file:org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser.java

License:Open Source License

private void fillParams(final ByteBuf buffer, final List<BgpParameters> params) throws BGPDocumentedException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "BUffer cannot be null or empty.");
    if (LOG.isTraceEnabled()) {
        LOG.trace("Started parsing of BGP parameter: {}", ByteBufUtil.hexDump(buffer));
    }//from   w ww.  j av  a  2s . c om
    while (buffer.isReadable()) {
        if (buffer.readableBytes() <= 2) {
            throw new BGPDocumentedException(
                    "Malformed parameter encountered (" + buffer.readableBytes() + " bytes left)",
                    BGPError.OPT_PARAM_NOT_SUPPORTED);
        }
        final int paramType = buffer.readUnsignedByte();
        final int paramLength = buffer.readUnsignedByte();
        final ByteBuf paramBody = buffer.readSlice(paramLength);

        final BgpParameters param;
        try {
            param = this.reg.parseParameter(paramType, paramBody);
        } catch (final BGPParsingException e) {
            throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR,
                    e);
        }
        if (param != null) {
            params.add(param);
        } else {
            LOG.debug("Ignoring BGP Parameter type: {}", paramType);
        }
    }
    LOG.trace("Parsed BGP parameters: {}", params);
}

From source file:org.opendaylight.protocol.bgp.parser.impl.message.BGPRouteRefreshMessageParser.java

License:Open Source License

/**
 * Serializes BGP Route Refresh message.
 *
 * @param message to be serialized/*from  w  ww . jav a 2  s .co m*/
 * @param bytes ByteBuf where the message will be serialized
 */
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
    Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh.");
    final RouteRefresh msg = (RouteRefresh) message;

    final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE);
    MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(),
            msgBuf);

    LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf));
    MessageUtil.formatMessage(TYPE, msgBuf, bytes);
}

From source file:org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser.java

License:Open Source License

private void serializeOptionalCapability(final OptionalCapabilities optionalCapa,
        final ByteBuf byteAggregator) {
    if (optionalCapa.getCParameters() != null) {
        final CParameters cap = optionalCapa.getCParameters();
        final ByteBuf bytes = Unpooled.buffer();
        this.reg.serializeCapability(cap, bytes);
        Preconditions.checkArgument(bytes != null, "Unhandled capability class %s",
                cap.getImplementedInterface());

        if (LOG.isTraceEnabled()) {
            LOG.trace("BGP capability serialized to: {}", ByteBufUtil.hexDump(bytes));
        }//from  w  w  w. j  a va 2  s . co m
        byteAggregator.writeBytes(bytes);
    }
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPByteToMessageDecoder.java

License:Open Source License

@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out)
        throws BGPDocumentedException, BGPParsingException {
    if (in.isReadable()) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
        }/*from  w ww.j  a v  a 2 s  .c om*/
        out.add(this.registry.parseMessage(in, this.constraints));
    } else {
        LOG.trace("No more content in incoming buffer.");
    }
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPMessageToByteEncoder.java

License:Open Source License

@Override
protected void encode(final ChannelHandlerContext ctx, final Notification msg, final ByteBuf out) {
    LOG.trace("Encoding message: {}", msg);
    this.registry.serializeMessage(msg, out);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Encoded message: {}", ByteBufUtil.hexDump(out));
    }//ww w.  ja va 2s  .  com
    LOG.debug("Message sent to output: {}", msg);
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl.java

License:Open Source License

/**
 * Handles incoming message based on their type.
 *
 * @param msg incoming message//  w ww.j  a  va  2  s .  c  om
 */
synchronized void handleMessage(final Notification msg) throws BGPDocumentedException {
    // Update last reception time
    this.lastMessageReceivedAt = System.nanoTime();

    if (msg instanceof Open) {
        // Open messages should not be present here
        this.terminate(new BGPDocumentedException(null, BGPError.FSM_ERROR));
    } else if (msg instanceof Notify) {
        final Notify notify = (Notify) msg;
        // Notifications are handled internally
        LOG.info("Session closed because Notification message received: {} / {}, data={}",
                notify.getErrorCode(), notify.getErrorSubcode(),
                notify.getData() != null ? ByteBufUtil.hexDump(notify.getData()) : null);
        this.closeWithoutMessage();
        this.listener.onSessionTerminated(this,
                new BGPTerminationReason(BGPError.forValue(notify.getErrorCode(), notify.getErrorSubcode())));
    } else if (msg instanceof Keepalive) {
        // Keepalives are handled internally
        LOG.trace("Received KeepAlive message.");
        this.kaCounter++;
        if (this.kaCounter >= 2) {
            this.sync.kaReceived();
        }
    } else if (msg instanceof RouteRefresh) {
        this.listener.onMessage(this, msg);
    } else if (msg instanceof Update) {
        this.listener.onMessage(this, msg);
        this.sync.updReceived((Update) msg);
    } else {
        LOG.warn("Ignoring unhandled message: {}.", msg.getClass());
    }

    this.sessionStats.updateReceivedMsg(msg);
}