@Override\r
public void onPacketInMessage(PacketInMessage notification) {\r
LOGGER.debug("PacketIn message received");\r
- \r
+ LOGGER.debug("BufferId: " + notification.getBufferId());\r
+ LOGGER.debug("TotalLength: " + notification.getTotalLen());\r
+ LOGGER.debug("Reason: " + notification.getReason());\r
+ LOGGER.debug("TableId: " + notification.getTableId());\r
+ LOGGER.debug("Cookie: " + notification.getCookie());\r
+ LOGGER.debug("Class: " + notification.getMatch().getMatchEntries().get(0).getOxmClass());\r
+ LOGGER.debug("Field: " + notification.getMatch().getMatchEntries().get(0).getOxmMatchField());\r
+ LOGGER.debug("Datasize: " + notification.getData().length);\r
}\r
\r
@Override\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+
+package org.opendaylight.openflowjava.protocol.impl.clients;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for decoding incoming messages into message frames.
+ *
+ * @author michal.polkorab
+ */
+public class SimpleClientFramer extends ByteToMessageDecoder {
+
+ /** Length of OpenFlow 1.3 header */
+ public static final byte LENGTH_OF_HEADER = 8;
+ private static final byte LENGTH_INDEX_IN_HEADER = 2;
+ private static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientFramer.class);
+
+ /**
+ * Constructor of class.
+ */
+ public SimpleClientFramer() {
+ LOGGER.debug("Creating OFFrameDecoder");
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ LOGGER.warn("Unexpected exception from downstream.", cause);
+ ctx.close();
+ }
+
+ @Override
+ protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
+ if (bb.readableBytes() < LENGTH_OF_HEADER) {
+ LOGGER.debug("skipping bb - too few data for header: " + bb.readableBytes());
+ return;
+ }
+
+ int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER);
+ if (bb.readableBytes() < length) {
+ LOGGER.debug("skipping bb - too few data for msg: " +
+ bb.readableBytes() + " < " + length);
+ return;
+ }
+ LOGGER.info("OF Protocol message received, type:{}", bb.getByte(1));
+
+ ByteBuf messageBuffer = bb.slice(bb.readerIndex(), length);
+ list.add(messageBuffer);
+ messageBuffer.retain();
+ bb.skipBytes(length);
+ }
+
+}
public class SimpleClientHandler extends ChannelInboundHandlerAdapter {\r
\r
protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class);\r
- private static final int OFP_HEADER_LENGTH = 8;\r
+ private static final int LENGTH_INDEX_IN_HEADER = 2;\r
private SettableFuture<Boolean> isOnlineFuture;\r
protected ScenarioHandler scenarioHandler;\r
\r
\r
@Override\r
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\r
- LOGGER.info("SimpleClientHandler - start of read");\r
ByteBuf bb = (ByteBuf) msg;\r
if (LOGGER.isDebugEnabled()) {\r
LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb));\r
}\r
- \r
- if (bb.readableBytes() < OFP_HEADER_LENGTH) {\r
- LOGGER.debug("too few bytes received: "+bb.readableBytes()+" - wait for next data portion");\r
- return;\r
- }\r
- int msgSize = bb.getUnsignedShort(2);\r
- byte[] message = new byte[msgSize];\r
+ int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER);\r
+ LOGGER.info("SimpleClientHandler - start of read");\r
+ byte[] message = new byte[length];\r
bb.readBytes(message);\r
scenarioHandler.addOfMsg(message);\r
LOGGER.info("end of read");\r