// TODO - finish implementation after enums are generated with proper funcionality\r
//emb.setType();\r
emb.setCode(rawMessage.readInt());\r
- //emb.setData(value);\r
+ byte[] data = new byte[rawMessage.readableBytes()];\r
+ rawMessage.readBytes(data);\r
+ emb.setData(data);\r
return emb.build();\r
}\r
\r
byte[] datapathId = new byte[8];\r
rawMessage.readBytes(datapathId);\r
gfob.setDatapathId(new BigInteger(datapathId));\r
- \r
gfob.setBuffers(rawMessage.readUnsignedInt());\r
gfob.setTables(rawMessage.readUnsignedByte());\r
gfob.setAuxiliaryId(rawMessage.readUnsignedByte());\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.math.BigInteger;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {\r
+ \r
+ private static FlowRemovedMessageFactory instance;\r
+ \r
+ private FlowRemovedMessageFactory() {\r
+ // singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static FlowRemovedMessageFactory getInstance(){\r
+ if(instance == null){\r
+ instance = new FlowRemovedMessageFactory();\r
+ }\r
+ \r
+ return instance;\r
+ }\r
+\r
+ @Override\r
+ public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+ FlowRemovedMessageBuilder frmb = new FlowRemovedMessageBuilder();\r
+ \r
+ frmb.setVersion(version);\r
+ frmb.setXid(rawMessage.readUnsignedInt());\r
+ \r
+ byte[] cookie = new byte[8];\r
+ rawMessage.readBytes(cookie);\r
+ frmb.setCookie(new BigInteger(cookie));\r
+ frmb.setPriority(rawMessage.readUnsignedShort());\r
+ \r
+// TODO enum! \r
+// frmb.setReason(FlowRemovedReason.values()[rawMessage.readInt()]);\r
+ rawMessage.skipBytes(1); //instead of setReason\r
+ \r
+ frmb.setTableId(new TableId((long)rawMessage.readUnsignedByte()));\r
+ frmb.setDurationSec(rawMessage.readUnsignedInt());\r
+ frmb.setDurationNsec(rawMessage.readUnsignedInt());\r
+ frmb.setIdleTimeout(rawMessage.readUnsignedShort());\r
+ frmb.setHardTimeout(rawMessage.readUnsignedShort());\r
+ \r
+ byte[] packet_count = new byte[8];\r
+ rawMessage.readBytes(packet_count);\r
+ frmb.setPacketCount(new BigInteger(packet_count));\r
+ \r
+ byte[] byte_count = new byte[8];\r
+ rawMessage.readBytes(byte_count);\r
+ frmb.setByteCount(new BigInteger(byte_count));\r
+ \r
+ return frmb.build();\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class GetConfigReplyMessageFactory implements OFDeserializer<GetConfigOutput> {\r
+\r
+ private static GetConfigReplyMessageFactory instance;\r
+ \r
+ private GetConfigReplyMessageFactory() {\r
+ // singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static GetConfigReplyMessageFactory getInstance(){\r
+ if(instance == null){\r
+ instance = new GetConfigReplyMessageFactory();\r
+ }\r
+ \r
+ return instance;\r
+ }\r
+\r
+ @Override\r
+ public GetConfigOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
+ GetConfigOutputBuilder gcob = new GetConfigOutputBuilder();\r
+ gcob.setVersion(version);\r
+ gcob.setXid(rawMessage.readUnsignedInt());\r
+ // TODO - waiting for enum funcionality\r
+// gcob.setFlags(SwitchConfigFlag.values()[rawMessage.readInt()]);\r
+ gcob.setMissSendLen(rawMessage.readUnsignedShort());\r
+ return gcob.build();\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class MultipartReplyMessageFactory implements OFDeserializer<MultipartReplyMessage> {\r
+\r
+ private static MultipartReplyMessageFactory instance;\r
+ private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4;\r
+ \r
+ private MultipartReplyMessageFactory() {\r
+ // singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static MultipartReplyMessageFactory getInstance(){\r
+ if (instance == null){\r
+\r
+ instance = new MultipartReplyMessageFactory();\r
+ }\r
+ \r
+ return instance;\r
+ }\r
+\r
+ @Override\r
+ public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+ MultipartReplyMessageBuilder mrmb = new MultipartReplyMessageBuilder();\r
+ mrmb.setVersion(version);\r
+ mrmb.setXid(rawMessage.readUnsignedInt());\r
+ \r
+// TODO enum MultipartType\r
+// mrmb.setType(MultipartType.values()[rawMessage.readInt()]);\r
+ rawMessage.skipBytes(2); //instead of enum\r
+ \r
+ mrmb.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) > 0));\r
+ rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);\r
+ mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+ \r
+ return mrmb.build();\r
+ } \r
+}\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.math.BigInteger;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class PacketInMessageFactory implements OFDeserializer<PacketInMessage> {\r
+\r
+ private static PacketInMessageFactory instance;\r
+ private static final byte PADDING_IN_PACKET_IN_HEADER = 2;\r
+ \r
+ private PacketInMessageFactory() {\r
+ // Singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static PacketInMessageFactory getInstance(){\r
+ if(instance == null){\r
+ instance = new PacketInMessageFactory();\r
+ }\r
+ \r
+ return instance;\r
+ }\r
+\r
+ @Override\r
+ public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+ PacketInMessageBuilder pimb = new PacketInMessageBuilder();\r
+ pimb.setVersion(version);\r
+ pimb.setXid(rawMessage.readUnsignedInt());\r
+ pimb.setBufferId(rawMessage.readUnsignedInt());\r
+ pimb.setTotalLen(rawMessage.readUnsignedShort());\r
+ pimb.setReason(rawMessage.readUnsignedByte());\r
+ pimb.setTableId(new TableId((long)rawMessage.readUnsignedByte()));\r
+ \r
+ byte[] cookie = new byte[8];\r
+ rawMessage.readBytes(cookie);\r
+ pimb.setCookie(new BigInteger(cookie));\r
+ // TODO - implement match factories to finish this factory \r
+ rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);\r
+ \r
+ pimb.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+ \r
+ return pimb.build();\r
+ }\r
+}\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {\r
+\r
+ private static PortStatusMessageFactory instance;\r
+ private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 7;\r
+ \r
+ private PortStatusMessageFactory() {\r
+ // Singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static PortStatusMessageFactory getInstance(){\r
+ if(instance == null){\r
+ \r
+ instance = new PortStatusMessageFactory();\r
+ }\r
+ \r
+ return instance;\r
+ }\r
+ \r
+ @Override\r
+ public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+ PortStatusMessageBuilder psmb = new PortStatusMessageBuilder(); \r
+ psmb.setVersion(version);\r
+ psmb.setXid(rawMessage.readUnsignedInt());\r
+ \r
+// TODO enum portReason\r
+// psmb.setReason(PortReason.values()[rawMessage.readInt()]);\r
+ rawMessage.skipBytes(1); //instead of portReason enum\r
+ \r
+ rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
+ return psmb.build();\r
+ }\r
+\r
+ \r
+ \r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterInput>{\r
+\r
+ /** Code type of Experimenter message */\r
+ public static final byte MESSAGE_TYPE = 4;\r
+ private static ExperimenterInputMessageFactory instance;\r
+ \r
+ private ExperimenterInputMessageFactory() {\r
+ // do nothing, just singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static ExperimenterInputMessageFactory getInstance() {\r
+ if (instance == null) {\r
+ instance = new ExperimenterInputMessageFactory();\r
+ }\r
+ return instance;\r
+ }\r
+ \r
+ @Override\r
+ public void messageToBuffer(short version, ByteBuf out,\r
+ ExperimenterInput message) {\r
+ out.writeByte(message.getVersion());\r
+ out.writeByte(MESSAGE_TYPE);\r
+ out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER + (Integer.SIZE/Byte.SIZE)*2);\r
+ out.writeInt(message.getXid().intValue());\r
+ out.writeInt(message.getExperimenter().intValue());\r
+ out.writeInt(message.getExpType().intValue());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{\r
+\r
+ /** Code type of PacketOut message */\r
+ public static final byte MESSAGE_TYPE = 13;\r
+ private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
+ private static PacketOutInputMessageFactory instance;\r
+ \r
+ private PacketOutInputMessageFactory() {\r
+ // do nothing, just singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static PacketOutInputMessageFactory getInstance() {\r
+ if (instance == null) {\r
+ instance = new PacketOutInputMessageFactory();\r
+ }\r
+ return instance;\r
+ }\r
+ \r
+ @Override\r
+ public void messageToBuffer(short version, ByteBuf out,\r
+ PacketOutInput message) {\r
+ out.writeByte(message.getVersion());\r
+ out.writeByte(MESSAGE_TYPE);\r
+ out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
+ out.writeInt(message.getXid().intValue());\r
+ out.writeInt(message.getBufferId().intValue());\r
+ out.writeInt(message.getInPort().getValue().intValue());\r
+ // TODO - finish implementation after Action serialization is done\r
+ //out.writeShort(message.getActions().size());\r
+ ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class RoleRequestInputMessageFactory implements OFSerializer<RoleRequestInput> {\r
+\r
+ /** Code type of RoleRequest message */\r
+ public static final byte MESSAGE_TYPE = 24;\r
+ private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;\r
+ private static RoleRequestInputMessageFactory instance;\r
+ \r
+ private RoleRequestInputMessageFactory() {\r
+ // do nothing, just singleton\r
+ }\r
+ \r
+ /**\r
+ * @return singleton factory\r
+ */\r
+ public static RoleRequestInputMessageFactory getInstance() {\r
+ if (instance == null) {\r
+ instance = new RoleRequestInputMessageFactory();\r
+ }\r
+ return instance;\r
+ }\r
+ \r
+ @Override\r
+ public void messageToBuffer(short version, ByteBuf out,\r
+ RoleRequestInput message) {\r
+ out.writeByte(message.getVersion());\r
+ out.writeByte(MESSAGE_TYPE);\r
+ out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
+ out.writeInt(message.getXid().intValue());\r
+ // TODO - finish implementation after enum support needed funcionality\r
+ //out.writeInt(message.getRole());\r
+ ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, out);\r
+ out.writeLong(message.getGenerationId().longValue());\r
+ }\r
+\r
+}\r
\r
import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsync;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncMessage;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;\r
\r
/**\r
out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
out.writeInt(message.getXid().intValue());\r
// TODO - finish implementation after enums provide needed funcionality\r
- \r
+ out.writeInt(message.getMissSendLen());\r
}\r
\r
}\r
package org.opendaylight.openflowjava.protocol.impl.util;\r
\r
import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
/** Class for common operations on ByteBuf\r
*\r
}\r
return sb.toString();\r
}\r
+ \r
+ /**\r
+ * Converts String into byte[]\r
+ * @param hexSrc input String\r
+ * @return byte[] filled with input data\r
+ */\r
+ public static byte[] hexStringToBytes(String hexSrc) {\r
+ String[] byteChips = hexSrc.split("\\s+");\r
+ byte[] result = new byte[byteChips.length];\r
+ for (int i = 0; i < byteChips.length; i++) {\r
+ result[i] = (byte) Short.parseShort(byteChips[i], 16);\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * Creates ByteBuf filled with specified data\r
+ * @param hexSrc input String of bytes in hex format\r
+ * @return ByteBuf with specified hexString converted\r
+ */\r
+ public static ByteBuf hexStringToByteBuf(String hexSrc) {\r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ hexStringToByteBuf(hexSrc, out);\r
+ return out;\r
+ }\r
+ \r
+ /**\r
+ * Creates ByteBuf filled with specified data\r
+ * @param hexSrc input String of bytes in hex format\r
+ * @param out ByteBuf with specified hexString converted\r
+ */\r
+ public static void hexStringToByteBuf(String hexSrc, ByteBuf out) {\r
+ out.writeBytes(hexStringToBytes(hexSrc));\r
+ }\r
+ \r
+ /**\r
+ * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding\r
+ * @param length\r
+ * @param out ByteBuf to be padded\r
+ */\r
+ public static void padBuffer(int length, ByteBuf out) {\r
+ for (int i = 0; i < length; i++) {\r
+ out.writeByte(0);\r
+ }\r
+ }\r
}\r
\r
import io.netty.buffer.ByteBuf;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
\r
*/\r
@Test\r
public void test() {\r
- ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
- BarrierOutput builtByFactory = BarrierReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer();\r
+ BarrierOutput builtByFactory = BufferHelper.decodeV13(\r
+ BarrierReplyMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
}\r
}\r
*/\r
@Test\r
public void testWithEmptyDataField() {\r
- ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
- EchoOutput builtByFactory = EchoReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer();\r
+ EchoOutput builtByFactory = BufferHelper.decodeV13(\r
+ EchoReplyMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
}\r
\r
/**\r
public void testWithDataFieldSet() {\r
byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};\r
ByteBuf bb = BufferHelper.buildBuffer(data);\r
- EchoOutput builtByFactory = EchoReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ EchoOutput builtByFactory = BufferHelper.decodeV13(\r
+ EchoReplyMessageFactory.getInstance(), bb);\r
+ \r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
Assert.assertArrayEquals(builtByFactory.getData(), data);\r
}\r
\r
*/\r
@Test\r
public void testWithEmptyDataField() {\r
- ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
- EchoRequestMessage builtByFactory = EchoRequestMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer();\r
+ EchoRequestMessage builtByFactory = BufferHelper.decodeV13(\r
+ EchoRequestMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
}\r
\r
/**\r
public void testWithDataFieldSet() {\r
byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};\r
ByteBuf bb = BufferHelper.buildBuffer(data);\r
- EchoRequestMessage builtByFactory = EchoRequestMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ EchoRequestMessage builtByFactory = BufferHelper.decodeV13(\r
+ EchoRequestMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ Assert.assertArrayEquals(builtByFactory.getData(), data);\r
}\r
\r
}\r
\r
import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;\r
\r
*/\r
@Test\r
public void test() {\r
- byte[] data = new byte[]{0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04};\r
- ByteBuf bb = BufferHelper.buildBuffer(data);\r
- ExperimenterMessage builtByFactory = ExperimenterMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04");\r
+ ExperimenterMessage builtByFactory = BufferHelper.decodeV13(\r
+ ExperimenterMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
- Assert.assertEquals(builtByFactory.getExperimenter().longValue(), 16909060L);\r
- Assert.assertEquals(builtByFactory.getExpType().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ Assert.assertEquals(builtByFactory.getExperimenter().longValue(), 0x01020304L);\r
+ Assert.assertEquals(builtByFactory.getExpType().longValue(), 0x01020304L);\r
}\r
\r
}\r
\r
import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
\r
*/\r
@Test\r
public void test() {\r
- byte[] data = new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \r
- 0x00, 0x01, 0x02, 0x03, 0x01, 0x01, 0x00, 0x00,\r
- 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03 };\r
- ByteBuf bb = BufferHelper.buildBuffer(data);\r
- GetFeaturesOutput builtByFactory = FeaturesReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"\r
+ + " 01 02 03 00 01 02 03");\r
+ GetFeaturesOutput builtByFactory = BufferHelper.decodeV13(\r
+ FeaturesReplyMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
- Assert.assertTrue(builtByFactory.getTables() == 1);\r
- Assert.assertTrue(builtByFactory.getAuxiliaryId() == 1);\r
- Assert.assertEquals(66051L, builtByFactory.getBuffers().longValue());\r
- Assert.assertEquals(66051L, builtByFactory.getCapabilities().longValue());\r
- Assert.assertEquals(66051L, builtByFactory.getReserved().longValue());\r
- Assert.assertTrue(builtByFactory.getDatapathId().longValue() == 283686952306183L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());\r
+ Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());\r
+ Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());\r
+ Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());\r
+ Assert.assertEquals("Wrong capabilities", 0x00010203L, builtByFactory.getCapabilities().longValue());\r
+ Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());\r
+ \r
}\r
\r
}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class FlowRemovedMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 00 04 00 00 00 02"\r
+ + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");\r
+ FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ \r
+ Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L);\r
+ Assert.assertTrue(builtByFactory.getPriority() == 0x03);\r
+\r
+ // TODO enum type!\r
+ // builtByFactory.getReason()\r
+ Assert.assertEquals("Wrong tableId", new TableId((long) 4), builtByFactory.getTableId());\r
+ Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue());\r
+ Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue());\r
+ Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue());\r
+ Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue());\r
+ Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());\r
+ Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());\r
+ }\r
+ \r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class GetConfigReplyMessageFactoryTest {\r
+\r
+\r
+ /**\r
+ * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03");\r
+ GetConfigOutput builtByFactory = BufferHelper.decodeV13(\r
+ GetConfigReplyMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ // TODO - enum problem !\r
+// Assert.assertEquals(builtByFactory.getFlags().toString(),"OFPCFRAGDROP"); \r
+ Assert.assertEquals("Wrong missSendLen", 0x01, builtByFactory.getMissSendLen().intValue());\r
+ \r
+ }\r
+ \r
+}\r
\r
import io.netty.buffer.ByteBuf;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
\r
/**\r
* @author michal.polkorab\r
- *\r
+ * \r
*/\r
public class HelloMessageFactoryTest {\r
- \r
+\r
/** Number of currently supported version / codec */\r
- public static final short VERSION_YET_SUPPORTED = 0x04;\r
- /** Index of Xid in OpenFlow 1.3 header */\r
- public static final byte INDEX_OF_XID_IN_HEADER = 4;\r
+ public static final Short VERSION_YET_SUPPORTED = 0x04;\r
\r
/**\r
* Testing {@link HelloMessageFactory} for correct translation into POJO\r
*/\r
@Test\r
public void test() {\r
- ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
- HelloMessage builtByFactory = HelloMessageFactory.getInstance().bufferToMessage(bb, VERSION_YET_SUPPORTED);\r
+ ByteBuf bb = BufferHelper.buildBuffer();\r
+ HelloMessage builtByFactory = BufferHelper.decodeV13(\r
+ HelloMessageFactory.getInstance(), bb);\r
\r
- Assert.assertTrue(builtByFactory.getVersion() == VERSION_YET_SUPPORTED);\r
- Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
}\r
}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class MultipartReplyMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 01 02 03 04");\r
+ MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb);\r
+ \r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ \r
+ Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());\r
+ Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody());\r
+ }\r
+ \r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ *\r
+ */\r
+public class PacketInMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link PacketInMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 00 01 02 03 04");\r
+ PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); \r
+ \r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ \r
+ Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());\r
+ Assert.assertEquals("Wrong totalLen", 0x0102, builtByFactory.getTotalLen().intValue());\r
+ Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().shortValue());\r
+ Assert.assertEquals("Wrong tableID", new TableId((long) 4), builtByFactory.getTableId());\r
+ Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());\r
+ Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());\r
+ }\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class PortStatusMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link PortStatusMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00");\r
+ \r
+ PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb);\r
+ \r
+ BufferHelper.checkHeaderV13(builtByFactory);\r
+ //Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason());\r
+ }\r
+}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;\r
\r
\r
/**\r
* Testing of {@link BarrierInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void test() {\r
+ public void test() throws Exception {\r
BarrierInputBuilder bib = new BarrierInputBuilder();\r
- bib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- bib.setXid(16909060L);\r
+ BufferHelper.setupHeader(bib);\r
BarrierInput bi = bib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance();\r
bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == BARRIER_REQUEST_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8);\r
}\r
\r
}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;\r
\r
\r
/**\r
* Testing of {@link EchoInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void test() {\r
+ public void test() throws Exception {\r
EchoInputBuilder eib = new EchoInputBuilder();\r
- eib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- eib.setXid(16909060L);\r
+ BufferHelper.setupHeader(eib);\r
EchoInput ei = eib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance();\r
eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, ei);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == ECHO_REQUEST_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);\r
}\r
\r
}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;\r
\r
\r
/**\r
* Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void test() {\r
+ public void test() throws Exception {\r
EchoReplyInputBuilder erib = new EchoReplyInputBuilder();\r
- erib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- erib.setXid(16909060L);\r
+ BufferHelper.setupHeader(erib);\r
EchoReplyInput eri = erib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance();\r
eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, eri);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == ECHO_REPLY_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);\r
}\r
\r
}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ExperimenterInputMessageFactoryTest {\r
+\r
+ private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE;\r
+ \r
+ /**\r
+ * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void test() throws Exception {\r
+ ExperimenterInputBuilder eib = new ExperimenterInputBuilder();\r
+ BufferHelper.setupHeader(eib);\r
+ eib.setExperimenter(0x0001020304L);\r
+ eib.setExpType(0x0001020304L);\r
+ ExperimenterInput ei = eib.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ ExperimenterInputMessageFactory eimf = ExperimenterInputMessageFactory.getInstance();\r
+ eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, ei);\r
+ \r
+ BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 16);\r
+ Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());\r
+ }\r
+\r
+\r
+}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder;\r
\r
\r
/**\r
* Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void test() {\r
+ public void test() throws Exception {\r
GetConfigInputBuilder gcib = new GetConfigInputBuilder();\r
- gcib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- gcib.setXid(16909060L);\r
+ BufferHelper.setupHeader(gcib);\r
GetConfigInput gci = gcib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();\r
gcimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, gci);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);\r
}\r
\r
}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder;\r
\r
\r
/**\r
* Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void test() {\r
+ public void test() throws Exception {\r
GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder();\r
- gfib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- gfib.setXid(16909060L);\r
+ BufferHelper.setupHeader(gfib);\r
GetFeaturesInput gfi = gfib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();\r
gfimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, gfi);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == FEATURES_REQUEST_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);\r
}\r
\r
}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
-import org.junit.Assert;\r
+import java.util.List;\r
+\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;\r
+\r
+import com.google.common.collect.Lists;\r
\r
/**\r
* @author michal.polkorab\r
\r
/**\r
* Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void testWithoutElementsSet() throws Exception {\r
+ HelloInputBuilder hib = new HelloInputBuilder();\r
+ BufferHelper.setupHeader(hib);\r
+ HelloInput hi = hib.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
+ himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
+ \r
+ BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
+ }\r
+ \r
+ /**\r
+ * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
*/\r
@Test\r
- public void testWithoutElementsSet() {\r
+ public void testWithElementsSet() throws Exception {\r
HelloInputBuilder hib = new HelloInputBuilder();\r
- hib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- hib.setXid(16909060L);\r
+ BufferHelper.setupHeader(hib);\r
+ ElementsBuilder eb = new ElementsBuilder();\r
+ eb.setType(HelloElementType.VERSIONBITMAP);\r
+ eb.setData(new byte[]{0x01, 0x02, 0x42, 0x03});\r
+ List<Elements> elementList = Lists.newArrayList(eb.build());\r
+ hib.setElements(elementList);\r
HelloInput hi = hib.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
\r
- Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
- Assert.assertTrue(out.readByte() == HELLO_MESSAGE_CODE_TYPE);\r
- Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
- Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+ BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
+ // TODO - element list\r
}\r
\r
}\r
import io.netty.buffer.ByteBuf;\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+\r
+import org.junit.Assert;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
/**\r
* @author michal.polkorab\r
- *\r
+ * \r
*/\r
public abstract class BufferHelper {\r
\r
/**\r
* \r
*/\r
- private static final byte[] XID = new byte[]{0x01, 0x02, 0x03, 0x04};\r
+ public static final Long DEFAULT_XID = 0x01020304L;\r
+ private static final byte[] XID = new byte[] { 0x01, 0x02, 0x03, 0x04 };\r
\r
/**\r
* @param payload\r
- * @return ByteBuf filled with OpenFlow protocol message without first 2 bytes\r
+ * @return ByteBuf filled with OpenFlow protocol message without first 4\r
+ * bytes\r
*/\r
public static ByteBuf buildBuffer(byte[] payload) {\r
ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer();\r
bb.writeBytes(payload);\r
return bb;\r
}\r
+ \r
+ /**\r
+ * @param payload String in hex format\r
+ * @return ByteBuf filled with OpenFlow protocol message without first 4\r
+ * bytes\r
+ */\r
+ public static ByteBuf buildBuffer(String payload) {\r
+ return buildBuffer(ByteBufUtils.hexStringToBytes(payload));\r
+ }\r
+ \r
+ /**\r
+ * @return ByteBuf filled with OpenFlow protocol header message without first 4\r
+ * bytes\r
+ */\r
+ public static ByteBuf buildBuffer() {\r
+ ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ bb.writeBytes(XID);\r
+ bb.writeBytes(new byte[0]);\r
+ return bb;\r
+ }\r
+\r
+ /**\r
+ * Use version 1.3 for encoded message\r
+ * @param input\r
+ * ByteBuf to be checked for correct OpenFlow Protocol header\r
+ * @param msgType\r
+ * type of received message\r
+ * @param length TODO\r
+ */\r
+ public static void checkHeaderV13(ByteBuf input, byte msgType, int length) {\r
+ checkHeader(input, msgType, length, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ }\r
+ \r
+ private static void checkHeader(ByteBuf input, byte msgType, int length, Short version) {\r
+ Assert.assertEquals("Wrong version", version, Short.valueOf(input.readByte()));\r
+ Assert.assertEquals("Wrong type", msgType, input.readByte());\r
+ Assert.assertEquals("Wrong length", length, input.readUnsignedShort());\r
+ Assert.assertEquals("Wrong Xid", DEFAULT_XID, Long.valueOf(input.readUnsignedInt()));\r
+ }\r
+ \r
\r
+ /**\r
+ * @param ofHeader OpenFlow protocol header\r
+ */\r
+ public static void checkHeaderV13(OfHeader ofHeader) {\r
+ checkHeader(ofHeader, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ }\r
+ \r
+ private static void checkHeader(OfHeader ofHeader, Short version) {\r
+ Assert.assertEquals("Wrong version", version, ofHeader.getVersion());\r
+ Assert.assertEquals("Wrong Xid", DEFAULT_XID, ofHeader.getXid());\r
+ }\r
+ \r
+ /**\r
+ * @param builder\r
+ * @throws NoSuchMethodException\r
+ * @throws SecurityException\r
+ * @throws IllegalAccessException\r
+ * @throws IllegalArgumentException\r
+ * @throws InvocationTargetException\r
+ */\r
+ public static void setupHeader(Object builder) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {\r
+ Method m = builder.getClass().getMethod("setVersion", Short.class);\r
+ m.invoke(builder, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ Method m2 = builder.getClass().getMethod("setXid", Long.class);\r
+ m2.invoke(builder, BufferHelper.DEFAULT_XID);\r
+ }\r
+ \r
+ /**\r
+ * Use version 1.3 for decoding message\r
+ * @param decoder decoder instance\r
+ * @param bb data input buffer\r
+ * @return message decoded pojo\r
+ */\r
+ public static <E extends DataObject> E decodeV13(OFDeserializer<E> decoder, ByteBuf bb) {\r
+ return bufferToMessage(decoder, HelloMessageFactoryTest.VERSION_YET_SUPPORTED, bb);\r
+ }\r
+ \r
+ private static <E extends DataObject> E bufferToMessage(OFDeserializer<E> decoder, short version, ByteBuf bb) {\r
+ return decoder.bufferToMessage(bb, version);\r
+ }\r
+ \r
+ /**\r
+ * Use OF-protocol version 1.3\r
+ * @param encoder serialize factory\r
+ * @param out buffer the result will be written into\r
+ * @param pojo input message\r
+ */\r
+ public static <E extends DataObject> void encodeV13(OFSerializer<E> encoder, ByteBuf out, E pojo) {\r
+ messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+ }\r
+ \r
+ private static <E extends DataObject> void messageToBuffer(\r
+ OFSerializer<E> encoder, ByteBuf out, E pojo, Short version) {\r
+ encoder.messageToBuffer(version, out, pojo);\r
+ }\r
}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ByteBufUtilsTest {\r
+\r
+ private byte[] expected = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};\r
+ \r
+ /**\r
+ * Test of {@link ByteBufUtils#hexStringToBytes(String)}\r
+ */\r
+ @Test\r
+ public void hexStringToBytesTest() {\r
+ byte[] data = ByteBufUtils.hexStringToBytes("01 02 03 04 05 ff");\r
+\r
+ Assert.assertArrayEquals(expected, data);\r
+ }\r
+ \r
+ /**\r
+ * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}\r
+ */\r
+ @Test\r
+ public void hexStringToByteBufTest() {\r
+ ByteBuf bb = ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff");\r
+ \r
+ Assert.assertArrayEquals(expected, byteBufToByteArray(bb));\r
+ }\r
+ \r
+ /**\r
+ * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}\r
+ */\r
+ @Test\r
+ public void hexStringToGivenByteBufTest() {\r
+ ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff", buffer);\r
+\r
+ Assert.assertArrayEquals(expected, byteBufToByteArray(buffer));\r
+ }\r
+ \r
+ private static byte[] byteBufToByteArray(ByteBuf bb) {\r
+ byte[] result = new byte[bb.readableBytes()];\r
+ bb.readBytes(result);\r
+ return result;\r
+ }\r
+\r
+}\r