Search in sources :

Example 1 with MessageConsumer

use of org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer in project openflowplugin by opendaylight.

the class OFDatagramPacketDecoder method channelRead0.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void channelRead0(final ChannelHandlerContext ctx, final VersionMessageUdpWrapper msg) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("UdpVersionMessageWrapper received");
        LOG.debug("<< {}", ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
    }
    try {
        final DataObject dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(), msg.getVersion());
        if (dataObject == null) {
            LOG.warn("Translated POJO is null");
        } else {
            MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.getAddress());
            consumer.consume(dataObject);
        }
    } catch (RuntimeException e) {
        LOG.warn("Message deserialization failed", e);
    // TODO: delegate exception to allow easier deserialization
    // debugging / deserialization problem awareness
    } finally {
        msg.getMessageBuffer().release();
    }
}
Also used : MessageConsumer(org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with MessageConsumer

use of org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer in project openflowplugin by opendaylight.

the class OFDatagramPacketHandler method decode.

@Override
protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
    LOG.debug("OFDatagramPacketFramer");
    MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.sender());
    if (consumer == null) {
        ConnectionFacade connectionFacade = adapterFactory.createConnectionFacade(ctx.channel(), msg.sender(), false, channelOutboundQueueSize);
        connectionHandler.onSwitchConnected(connectionFacade);
        connectionFacade.checkListeners();
        UdpConnectionMap.addConnection(msg.sender(), connectionFacade);
    }
    ByteBuf bb = msg.content();
    int readableBytes = bb.readableBytes();
    if (readableBytes < LENGTH_OF_HEADER) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("skipping bytebuf - too few bytes for header: {} < {}", readableBytes, LENGTH_OF_HEADER);
            LOG.debug("bb: {}", ByteBufUtils.byteBufToHexString(bb));
        }
        return;
    }
    int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER);
    LOG.debug("length of actual message: {}", length);
    if (readableBytes < length) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("skipping bytebuf - too few bytes for msg: {} < {}", readableBytes, length);
            LOG.debug("bytebuffer: {}", ByteBufUtils.byteBufToHexString(bb));
        }
        return;
    }
    LOG.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1));
    byte version = bb.readByte();
    if (version == EncodeConstants.OF13_VERSION_ID || version == EncodeConstants.OF10_VERSION_ID) {
        LOG.debug("detected version: {}", version);
        ByteBuf messageBuffer = bb.slice();
        out.add(new VersionMessageUdpWrapper(version, messageBuffer, msg.sender()));
        messageBuffer.retain();
    } else {
        LOG.warn("detected version: {} - currently not supported", version);
    }
    bb.skipBytes(bb.readableBytes());
}
Also used : MessageConsumer(org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer) ConnectionFacade(org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

MessageConsumer (org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer)2 ByteBuf (io.netty.buffer.ByteBuf)1 ConnectionFacade (org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade)1 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)1