From 2c0d6baf3a4ca0c6de5992d68e5f2eb200a918ed Mon Sep 17 00:00:00 2001 From: Timotej Kubas Date: Tue, 8 Oct 2013 08:31:51 +0200 Subject: [PATCH] new serialization factories and tests Change-Id: I85da9bc251724d0aa45254081ed3153c35a2a3f6 Signed-off-by: Timotej Kubas --- .../impl/deserialization/DecoderTable.java | 2 + .../GetAsyncReplyMessageFactory.java | 147 ++++++++++++++++++ .../factories/RoleReplyMessageFactory.java | 5 +- .../impl/serialization/EncoderTable.java | 3 + .../ExperimenterInputMessageFactory.java | 12 +- .../factories/HelloInputMessageFactory.java | 6 +- .../MultipartRequestMessageFactory.java | 64 ++++++++ .../FlowRemovedMessageFactoryTest.java | 2 +- .../GetAsyncReplyMessageFactoryTest.java | 83 ++++++++++ .../factories/PacketInMessageFactoryTest.java | 2 +- ...GetConfigReplyMessageFactoryMultiTest.java | 35 +---- ...QueueGetConfigReplyMessageFactoryTest.java | 39 +---- .../ExperimenterInputMessageFactoryTest.java | 28 ++-- .../GroupModInputMessageFactoryTest.java | 32 +--- .../MeterModInputMessageFactoryTest.java | 32 +--- .../MultipartRequestMessageFactoryTest.java | 51 ++++++ .../SetAsyncInputMessageFactoryTest.java | 70 ++------- 17 files changed, 405 insertions(+), 208 deletions(-) create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java index ba59351e..f470ae27 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java @@ -12,6 +12,7 @@ import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.Err import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory; import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory; import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory; import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory; import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory; import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory; @@ -100,6 +101,7 @@ public class DecoderTable { table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance()); table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance()); table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance()); } /** diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java new file mode 100644 index 00000000..56f682dd --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java @@ -0,0 +1,147 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.FlowRemovedMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PacketInMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PortStatusMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PortStatusMaskBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class GetAsyncReplyMessageFactory implements OFDeserializer { + private static GetAsyncReplyMessageFactory instance; + + private GetAsyncReplyMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static GetAsyncReplyMessageFactory getInstance() { + if (instance == null) { + instance = new GetAsyncReplyMessageFactory(); + } + return instance; + } + + @Override + public GetAsyncOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setPacketInMask(decodePacketInMask(rawMessage)); + builder.setPortStatusMask(decodePortStatusMask(rawMessage)); + builder.setFlowRemovedMask(decodeFlowRemovedMask(rawMessage)); + return builder.build(); + } + + private static List decodePacketInMask(ByteBuf outputBuf) { + List readPIRList = new ArrayList(); + List inMasks = new ArrayList(); + PacketInMaskBuilder maskBuilder = new PacketInMaskBuilder(); + + readPIRList.add(decodedPacketInReason((int) outputBuf.readUnsignedInt())); + readPIRList.add(decodedPacketInReason((int) outputBuf.readUnsignedInt())); + inMasks.add(maskBuilder.setMask(readPIRList).build()); + return inMasks; + } + + private static List decodePortStatusMask(ByteBuf outputBuf) { + List readPortReasonList = new ArrayList(); + List inMasks = new ArrayList(); + PortStatusMaskBuilder maskBuilder = new PortStatusMaskBuilder(); + + readPortReasonList.add(decodePortReason((int) outputBuf.readUnsignedInt())); + readPortReasonList.add(decodePortReason((int) outputBuf.readUnsignedInt())); + inMasks.add(maskBuilder.setMask(readPortReasonList).build()); + return inMasks; + } + + private static List decodeFlowRemovedMask(ByteBuf outputBuf) { + List readFlowRemovedReasonList = new ArrayList(); + List inMasks = new ArrayList(); + FlowRemovedMaskBuilder maskBuilder = new FlowRemovedMaskBuilder(); + + readFlowRemovedReasonList.add(decodeFlowRemovedReason((int) outputBuf.readUnsignedInt())); + readFlowRemovedReasonList.add(decodeFlowRemovedReason((int) outputBuf.readUnsignedInt())); + inMasks.add(maskBuilder.setMask(readFlowRemovedReasonList).build()); + return inMasks; + } + + private static PacketInReason decodedPacketInReason(int input) { + PacketInReason reason = null; + Boolean OFPRNOMATCH = (input & (1 << 0)) > 0; + Boolean OFPRACTION = (input & (1 << 1)) > 0; + Boolean OFPRINVALIDTTL = (input & (1 << 2)) > 0; + + if (OFPRNOMATCH) { + return PacketInReason.forValue(0); + } + if (OFPRACTION) { + return PacketInReason.forValue(1); + } + if (OFPRINVALIDTTL) { + return PacketInReason.forValue(2); + } + + return reason; + } + + private static PortReason decodePortReason(int input) { + PortReason reason = null; + Boolean OFPPRADD = (input & (1 << 0)) > 0; + Boolean OFPPRDELETE = (input & (1 << 1)) > 0; + Boolean OFPPRMODIFY = (input & (1 << 2)) > 0; + + if (OFPPRADD) { + return PortReason.forValue(0); + } + if (OFPPRDELETE) { + return PortReason.forValue(1); + } + if (OFPPRMODIFY) { + return PortReason.forValue(2); + } + + return reason; + } + + private static FlowRemovedReason decodeFlowRemovedReason(int input) { + FlowRemovedReason reason = null; + Boolean OFPRRIDLETIMEOUT = (input & (1 << 0)) > 0; + Boolean OFPRRHARDTIMEOUT = (input & (1 << 1)) > 0; + Boolean OFPRRDELETE = (input & (1 << 2)) > 0; + Boolean OFPRRGROUPDELETE = (input & (1 << 3)) > 0; + + if (OFPRRIDLETIMEOUT) { + return FlowRemovedReason.forValue(0); + } + if (OFPRRHARDTIMEOUT) { + return FlowRemovedReason.forValue(1); + } + if (OFPRRDELETE) { + return FlowRemovedReason.forValue(2); + } + if (OFPRRGROUPDELETE) { + return FlowRemovedReason.forValue(3); + } + + return reason; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java index cbdfe48e..e24da701 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java @@ -15,7 +15,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author michal.polkorab */ public class RoleReplyMessageFactory implements OFDeserializer{ - private static RoleReplyMessageFactory instance; private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4; @@ -39,9 +38,7 @@ public class RoleReplyMessageFactory implements OFDeserializer(OF13, GroupModInput.class), GroupModInputMessageFactory.getInstance()); table.put(new MessageTypeKey<>(OF13, HelloInput.class), HelloInputMessageFactory.getInstance()); table.put(new MessageTypeKey<>(OF13, MeterModInput.class), MeterModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, MultipartRequestMessage.class), MultipartRequestMessageFactory.getInstance()); table.put(new MessageTypeKey<>(OF13, PacketOutInput.class), PacketOutInputMessageFactory.getInstance()); table.put(new MessageTypeKey<>(OF13, PortModInput.class), PortModInputMessageFactory.getInstance()); table.put(new MessageTypeKey<>(OF13, RoleRequestInput.class), RoleRequestInputMessageFactory.getInstance()); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java index 351d7c09..4fe6a8e3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java @@ -15,7 +15,7 @@ public class ExperimenterInputMessageFactory implements OFSerializer{ public byte getMessageType() { return MESSAGE_TYPE; } - + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java new file mode 100644 index 00000000..d4a07f6f --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java @@ -0,0 +1,64 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage; + +/** + * @author timotej.kubas + * + */ +public class MultipartRequestMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 18; + private static final int MESSAGE_LENGTH = 16; + private static MultipartRequestMessageFactory instance; + private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; + private MultipartRequestMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static MultipartRequestMessageFactory getInstance() { + if (instance == null) { + instance = new MultipartRequestMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + MultipartRequestMessage message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getType().getIntValue()); + out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags())); + // TODO multipart body (message.getMultipartRequestBody()) + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out); + } + + @Override + public int computeLength() { + return MESSAGE_LENGTH; + } + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { + int multipartRequestFlagsBitmask = 0; + Map multipartRequestFlagsMap = new HashMap<>(); + multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); + + multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); + return multipartRequestFlagsBitmask; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java index e0c830a3..6e91cff9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java @@ -29,7 +29,7 @@ public class FlowRemovedMessageFactoryTest { Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L); Assert.assertTrue(builtByFactory.getPriority() == 0x03); Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue()); - Assert.assertEquals("Wrong tableId", new TableId((long) 4), builtByFactory.getTableId()); + Assert.assertEquals("Wrong tableId", new TableId(4L), builtByFactory.getTableId()); Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue()); Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue()); Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java new file mode 100644 index 00000000..b87fe4af --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java @@ -0,0 +1,83 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import java.util.ArrayList; +import java.util.List; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.FlowRemovedMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PacketInMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PortStatusMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.get.async.reply.PortStatusMaskBuilder; + +/** + * @author timotej.kubas + * + */ +public class GetAsyncReplyMessageFactoryTest { + + /** + * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testGetAsyncReplyMessage() { + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 "+ + "00 00 00 02 "+ + "00 00 00 02 "+ + "00 00 00 02 "+ + "00 00 00 04 "+ + "00 00 00 04"); + GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong packetInMask",createPacketInMask().get(0).getMask(), + builtByFactory.getPacketInMask().get(0).getMask()); + Assert.assertEquals("Wrong portStatusMask",createPortStatusMask().get(0).getMask(), + builtByFactory.getPortStatusMask().get(0).getMask()); + Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask().get(0).getMask(), + builtByFactory.getFlowRemovedMask().get(0).getMask()); + } + + private static List createPacketInMask() { + List readPIRList = new ArrayList(); + List inMasks = new ArrayList(); + PacketInMaskBuilder maskBuilder = new PacketInMaskBuilder(); + + readPIRList.add(PacketInReason.forValue(1)); + readPIRList.add(PacketInReason.forValue(1)); + inMasks.add(maskBuilder.setMask(readPIRList).build()); + return inMasks; + } + + private static List createPortStatusMask() { + List readPortReasonList = new ArrayList(); + List inMasks = new ArrayList(); + PortStatusMaskBuilder maskBuilder = new PortStatusMaskBuilder(); + + readPortReasonList.add(PortReason.forValue(1)); + readPortReasonList.add(PortReason.forValue(1)); + inMasks.add(maskBuilder.setMask(readPortReasonList).build()); + return inMasks; + } + + private static List createFlowRemovedMask() { + List readFlowRemovedReasonList = new ArrayList(); + List inMasks = new ArrayList(); + FlowRemovedMaskBuilder maskBuilder = new FlowRemovedMaskBuilder(); + + readFlowRemovedReasonList.add(FlowRemovedReason.forValue(2)); + readFlowRemovedReasonList.add(FlowRemovedReason.forValue(2)); + inMasks.add(maskBuilder.setMask(readFlowRemovedReasonList).build()); + return inMasks; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java index 4123842e..3c6103ac 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java @@ -29,7 +29,7 @@ public class PacketInMessageFactoryTest { Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().shortValue()); - Assert.assertEquals("Wrong tableID", new TableId((long) 4), builtByFactory.getTableId()); + Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId()); Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java index 3fbd8e86..e5d91706 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java @@ -53,9 +53,9 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { QueueGetConfigReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertTrue("Wrong port", 66051L == builtByFactory.getPort().getValue()); - Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(), - createQueuesList())); + Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), + createQueuesList()); } private static List createQueuesList() { @@ -78,33 +78,4 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { return propertiesList; } - private static boolean compareLists(List originalList, - List testList) { - boolean result = false; - int originalListLength = originalList.size(); - for (int i = 0; i < originalListLength; i++) { - if (originalList.get(i).getPort().equals(testList.get(i).getPort())) { - result = true; - } else { - result = false; - break; - } - if (originalList.get(i).getQueueId() - .equals(testList.get(i).getQueueId())) { - result = true; - } else { - result = false; - break; - } - if (originalList.get(i).getProperties().get(0).getProperty() - .equals(testList.get(i).getProperties().get(0).getProperty())) { - result = true; - } else { - result = false; - break; - } - } - return result; - } - } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java index 74c9a378..01a7d025 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java @@ -32,16 +32,15 @@ public class QueueGetConfigReplyMessageFactoryTest { ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00"); GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertTrue("Wrong port",66051L == builtByFactory.getPort().getValue()); - Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(), createQueuesList())); + Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); } public List createQueuesList(){ - final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; List queuesList = new ArrayList(); QueuesBuilder qb = new QueuesBuilder(); - qb.setQueueId(new QueueId((long) 1)); - qb.setPort(new PortNumber((long) 1)); + qb.setQueueId(new QueueId(1L)); + qb.setPort(new PortNumber(1L)); qb.setProperties(createPropertiesList()); queuesList.add(qb.build()); @@ -49,7 +48,6 @@ public class QueueGetConfigReplyMessageFactoryTest { } public List createPropertiesList(){ - final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; List propertiesList = new ArrayList(); PropertiesBuilder pb = new PropertiesBuilder(); pb.setProperty(QueueProperty.values()[2]); @@ -57,33 +55,4 @@ public class QueueGetConfigReplyMessageFactoryTest { return propertiesList; } - - public boolean compareLists(List originalList, List testList){ - boolean decision = false; - int originalListLength = originalList.size(); - int testListLength = testList.size(); - - for(int i=0; i createBucketsList(){ @@ -77,34 +77,4 @@ public class GroupModInputMessageFactoryTest { bucketsList.add(bucket); return bucketsList; } - - private static boolean compareBucketsLists(List bucketsFromMessage, List bucketsFromBuffer) { - boolean result = false; - int bucketsFromMessageLength = bucketsFromMessage.size(); - for (int i = 0; i < bucketsFromMessageLength; i++) { - if (bucketsFromMessage.get(i).getWeight().equals(bucketsFromBuffer.get(i).getWeight())) { - result = true; - } else { - result = false; - break; - } - if (bucketsFromMessage.get(i).getWatchPort() - .equals(bucketsFromBuffer.get(i).getWatchPort())) { - result = true; - } else { - result = false; - break; - } - if (bucketsFromMessage.get(i).getWatchGroup() - .equals(bucketsFromBuffer.get(i).getWatchGroup())) { - result = true; - } else { - result = false; - break; - } - } - // TODO get method for field length missing - // TODO actions structure missing - return result; - } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java index c8a5b762..535f30ed 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactoryTest.java @@ -49,7 +49,7 @@ public class MeterModInputMessageFactoryTest { Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readShort()); Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort())); Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong bands", true, compareBandsLists(createBandsList(), decodeBandsList(out))); + Assert.assertEquals("Wrong bands", createBandsList(), decodeBandsList(out)); } private static MeterFlags decodeMeterModFlags(short input){ @@ -83,34 +83,4 @@ public class MeterModInputMessageFactoryTest { bandsList.add(band); return bandsList; } - - private static boolean compareBandsLists(List bandsFromMessage, List bandsFromBuffer) { - boolean result = false; - int bandsFromMessageLength = bandsFromMessage.size(); - for (int i = 0; i < bandsFromMessageLength; i++) { - if (bandsFromMessage.get(i).getType().equals(bandsFromBuffer.get(i).getType())) { - result = true; - } else { - result = false; - break; - } - if (bandsFromMessage.get(i).getRate() - .equals(bandsFromBuffer.get(i).getRate())) { - result = true; - } else { - result = false; - break; - } - if (bandsFromMessage.get(i).getBurstSize() - .equals(bandsFromBuffer.get(i).getBurstSize())) { - result = true; - } else { - result = false; - break; - } - } - // TODO get method for field length missing - // TODO actions structure missing - return result; - } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java new file mode 100644 index 00000000..268a4dd7 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java @@ -0,0 +1,51 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import junit.framework.Assert; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessageBuilder; + +/** + * @author timotej.kubas + * + */ +public class MultipartRequestMessageFactoryTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; + + /** + * @throws Exception + * Testing of {@link MultipartRequestMessageFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestMessageFactory() throws Exception { + MultipartRequestMessageBuilder builder = new MultipartRequestMessageBuilder(); + BufferHelper.setupHeader(builder); + builder.setType(MultipartType.forValue(5)); + builder.setFlags(new MultipartRequestFlags(true)); + MultipartRequestMessage message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestMessageFactory factory = MultipartRequestMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength()); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + // TODO multipart body + } + + private static MultipartRequestFlags decodeMultipartRequestFlags(short input){ + final Boolean _oFPMPFREQMORE = (input & (1 << 0)) > 0; + return new MultipartRequestFlags(_oFPMPFREQMORE); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java index c9952e87..54395ca9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java @@ -41,9 +41,9 @@ public class SetAsyncInputMessageFactoryTest { factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength()); - Assert.assertTrue("Wrong packetInMask", comparePIRLists(message.getPacketInMask(), readPacketInMask(out))); - Assert.assertTrue("Wrong packetInMask", comparePortReasonLists(message.getPortStatusMask(), readPortStatusMask(out))); - Assert.assertTrue("Wrong packetInMask", compareFlowRemovedReasonLists(message.getFlowRemovedMask(), readFlowRemovedReasonMask(out))); + Assert.assertEquals("Wrong packetInMask", message.getPacketInMask(), readPacketInMask(out)); + Assert.assertEquals("Wrong packetInMask", message.getPortStatusMask(), readPortStatusMask(out)); + Assert.assertEquals("Wrong packetInMask", message.getFlowRemovedMask(), readFlowRemovedReasonMask(out)); } @@ -91,9 +91,9 @@ public class SetAsyncInputMessageFactoryTest { private static PacketInReason readPacketInReason(int input) { PacketInReason reason = null; - Boolean OFPRNOMATCH = (input & (1 << 0)) > 0; - Boolean OFPRACTION = (input & (1 << 1)) > 0; - Boolean OFPRINVALIDTTL = (input & (1 << 2)) > 0; + boolean OFPRNOMATCH = (input & (1 << 0)) > 0; + boolean OFPRACTION = (input & (1 << 1)) > 0; + boolean OFPRINVALIDTTL = (input & (1 << 2)) > 0; if (OFPRNOMATCH) { return PacketInReason.forValue(0); @@ -110,9 +110,9 @@ public class SetAsyncInputMessageFactoryTest { private static PortReason readPortReason(int input) { PortReason reason = null; - Boolean OFPPRADD = (input & (1 << 0)) > 0; - Boolean OFPPRDELETE = (input & (1 << 1)) > 0; - Boolean OFPPRMODIFY = (input & (1 << 2)) > 0; + boolean OFPPRADD = (input & (1 << 0)) > 0; + boolean OFPPRDELETE = (input & (1 << 1)) > 0; + boolean OFPPRMODIFY = (input & (1 << 2)) > 0; if (OFPPRADD) { return PortReason.forValue(0); @@ -129,10 +129,10 @@ public class SetAsyncInputMessageFactoryTest { private static FlowRemovedReason readFlowRemovedReason(int input) { FlowRemovedReason reason = null; - Boolean OFPRRIDLETIMEOUT = (input & (1 << 0)) > 0; - Boolean OFPRRHARDTIMEOUT = (input & (1 << 1)) > 0; - Boolean OFPRRDELETE = (input & (1 << 2)) > 0; - Boolean OFPRRGROUPDELETE = (input & (1 << 3)) > 0; + boolean OFPRRIDLETIMEOUT = (input & (1 << 0)) > 0; + boolean OFPRRHARDTIMEOUT = (input & (1 << 1)) > 0; + boolean OFPRRDELETE = (input & (1 << 2)) > 0; + boolean OFPRRGROUPDELETE = (input & (1 << 3)) > 0; if (OFPRRIDLETIMEOUT) { return FlowRemovedReason.forValue(0); @@ -149,48 +149,4 @@ public class SetAsyncInputMessageFactoryTest { return reason; } - - private static boolean comparePIRLists(List fromMessage, List fromBuffer) { - boolean result = false; - int romMessageLength = fromMessage.size(); - for (int i = 0; i < romMessageLength; i++) { - if ((fromMessage.get(i).getIntValue()) == (fromBuffer.get(i).getIntValue())) { - result = true; - } else { - result = false; - break; - } - } - return result; - } - - private static boolean comparePortReasonLists(List fromMessage, - List fromBuffer) { - boolean result = false; - int fromMessageLength = fromMessage.size(); - for (int i = 0; i < fromMessageLength; i++) { - if ((fromMessage.get(i).getIntValue()) == (fromBuffer.get(i).getIntValue())) { - result = true; - } else { - result = false; - break; - } - } - return result; - } - - private static boolean compareFlowRemovedReasonLists(List fromMessage, - List fromBuffer) { - boolean result = false; - int fromMessageLength = fromMessage.size(); - for (int i = 0; i < fromMessageLength; i++) { - if ((fromMessage.get(i).getIntValue()) == (fromBuffer.get(i).getIntValue())) { - result = true; - } else { - result = false; - break; - } - } - return result; - } } -- 2.36.6