Quickfix - fixed missing output ByteBuf in MatchSerializer 73/2773/1
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Fri, 15 Nov 2013 12:48:37 +0000 (13:48 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Fri, 15 Nov 2013 12:48:54 +0000 (13:48 +0100)
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java

index d17f3a0a29fd509089dd971efbf06e35eca88ca5..b5e6b486d34e732989df3e1b031ed003535baf32 100644 (file)
@@ -501,7 +501,6 @@ public abstract class MatchDeserializer {
     }\r
 \r
     private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) {\r
-//         TODO - check if matchEntryLength is in bytes\r
         MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
         byte[] mask = new byte[matchEntryLength];\r
         in.readBytes(mask);\r
index a6dabe1ced732b2855474938e5b99c185d03915e..7af3e11ccddddbb190953e71fea0834e78ae3153 100644 (file)
@@ -139,7 +139,7 @@ public class MatchSerializer {
         }\r
         for (MatchEntries entry : matchEntries) {\r
             encodeClass(entry.getOxmClass(), out);\r
-            encodeRest(entry, null);\r
+            encodeRest(entry, out);\r
         }\r
     }\r
 \r
index 28376ed6c21bf753fbd50d9365ddf0724a07b787..7fcd9b889957470550b67d5baa2d45d534cd8fe6 100644 (file)
@@ -5,17 +5,39 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
 import java.math.BigInteger;\r
+import java.util.ArrayList;\r
+import java.util.List;\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.augments.rev131002.EcnMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;\r
 \r
 /**\r
  * @author timotej.kubas\r
@@ -31,9 +53,9 @@ public class FlowModInputMessageFactoryTest {
     public void testFlowModInputMessageFactory() throws Exception {\r
         FlowModInputBuilder builder = new FlowModInputBuilder();\r
         BufferHelper.setupHeader(builder);\r
-        byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};\r
+        byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};\r
         builder.setCookie(new BigInteger(cookie));\r
-        byte[] cookieMask = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\r
+        byte[] cookieMask = new byte[]{0x01, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30};\r
         builder.setCookieMask(new BigInteger(cookieMask));\r
         builder.setTableId(new TableId(65L));\r
         builder.setCommand(FlowModCommand.forValue(2));\r
@@ -44,6 +66,40 @@ public class FlowModInputMessageFactoryTest {
         builder.setOutPort(new PortNumber(4422L));\r
         builder.setOutGroup(98L);\r
         builder.setFlags(new FlowModFlags(true, false, true, false, true));\r
+        MatchBuilder matchBuilder = new MatchBuilder();\r
+        matchBuilder.setType(OxmMatchType.class);\r
+        List<MatchEntries> entries = new ArrayList<>();\r
+        MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();\r
+        entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
+        entriesBuilder.setOxmMatchField(InPhyPort.class);\r
+        entriesBuilder.setHasMask(false);\r
+        PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder();\r
+        portNumberBuilder.setPortNumber(new PortNumber(42L));\r
+        entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());\r
+        entries.add(entriesBuilder.build());\r
+        entriesBuilder.setOxmClass(Nxm0Class.class);\r
+        entriesBuilder.setOxmMatchField(IpEcn.class);\r
+        entriesBuilder.setHasMask(false);\r
+        EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();\r
+        ecnBuilder.setEcn((short) 4);\r
+        entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());\r
+        entries.add(entriesBuilder.build());\r
+        matchBuilder.setMatchEntries(entries);\r
+        builder.setMatch(matchBuilder.build());\r
+        List<Instructions> instructions = new ArrayList<>();\r
+        InstructionsBuilder insBuilder = new InstructionsBuilder();\r
+        insBuilder.setType(GotoTable.class);\r
+        TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder();\r
+        idBuilder.setTableId((short) 43);\r
+        insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build());\r
+        instructions.add(insBuilder.build());\r
+        insBuilder.setType(WriteMetadata.class);\r
+        MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder();\r
+        metaBuilder.setMetadata(cookie);\r
+        metaBuilder.setMetadataMask(cookieMask);\r
+        insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());\r
+        instructions.add(insBuilder.build());\r
+        builder.setInstructions(instructions);\r
         FlowModInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
@@ -53,21 +109,47 @@ public class FlowModInputMessageFactoryTest {
         BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));\r
         Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), out.readLong());\r
         Assert.assertEquals("Wrong cookieMask", message.getCookieMask().longValue(), out.readLong());\r
-        Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readByte());\r
-        Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readByte());\r
+        Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());\r
+        Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());\r
         Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());\r
         Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());\r
         Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort());\r
         Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt());\r
         Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());\r
         Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());\r
-        Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFalgsFromBitmap(out.readShort()));\r
+        Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort()));\r
         out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);\r
-        // TODO implementation of match structure\r
-        // TODO implementation of instructions\r
+        Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());\r
+        out.skipBytes(Short.SIZE / Byte.SIZE);\r
+        Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());\r
+        short fieldAndMask = out.readUnsignedByte();\r
+        Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);\r
+        Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);\r
+        out.skipBytes(Byte.SIZE / Byte.SIZE);\r
+        Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt());\r
+        Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort());\r
+        fieldAndMask = out.readUnsignedByte();\r
+        Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);\r
+        Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);\r
+        out.skipBytes(Byte.SIZE / Byte.SIZE);\r
+        Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte());\r
+        out.skipBytes(7);\r
+        Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
+        out.skipBytes(Short.SIZE / Byte.SIZE);\r
+        Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte());\r
+        out.skipBytes(3);\r
+        Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());\r
+        out.skipBytes(Short.SIZE / Byte.SIZE);\r
+        out.skipBytes(Integer.SIZE / Byte.SIZE);\r
+        byte[] cookieRead = new byte[Long.SIZE / Byte.SIZE];\r
+        out.readBytes(cookieRead);\r
+        byte[] cookieMaskRead = new byte[Long.SIZE / Byte.SIZE];\r
+        out.readBytes(cookieMaskRead);\r
+        Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);\r
+        Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); \r
     }\r
     \r
-    private static FlowModFlags createFlowModFalgsFromBitmap(short input){\r
+    private static FlowModFlags createFlowModFlagsFromBitmap(int input){\r
         final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) > 0;\r
         final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) > 0;\r
         final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) > 0; \r
index 6e30ae6e8c618693f8f84bc9d9788f28db313b5e..7e78f561c02dd660e43e7c1fcfeb1e894fbd27bf 100644 (file)
@@ -3,11 +3,23 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
-import junit.framework.Assert;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\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.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder;\r
@@ -18,8 +30,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class PacketOutInputMessageFactoryTest {\r
     private static final byte MESSAGE_TYPE = 13;\r
-    private static final int MESSAGE_LENGTH = 24;\r
     private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
+    private static final int PADDING_IN_ACTION_HEADER = 4;\r
        \r
     /**\r
      * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO\r
@@ -31,17 +43,39 @@ public class PacketOutInputMessageFactoryTest {
         BufferHelper.setupHeader(builder);\r
         builder.setBufferId(256L);\r
         builder.setInPort(new PortNumber(256L));\r
+        List<ActionsList> actions = new ArrayList<>();\r
+        ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
+        ActionBuilder actionBuilder = new ActionBuilder();\r
+        actionBuilder.setType(PushVlan.class);\r
+        EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder();\r
+        ethertypeBuilder.setEthertype(new EtherType(25));\r
+        actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build());\r
+        actionsListBuilder.setAction(actionBuilder.build());\r
+        actions.add(actionsListBuilder.build());\r
+        actionBuilder = new ActionBuilder();\r
+        actionBuilder.setType(PopVlan.class);\r
+        actionsListBuilder.setAction(actionBuilder.build());\r
+        actions.add(actionsListBuilder.build());\r
+        builder.setActionsList(actions);\r
+        builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));\r
         PacketOutInput message = builder.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance();\r
         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
         \r
-        BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);\r
+        BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56);\r
         Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());\r
         Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt());\r
-        // TODO make test for actions after its implementation in factory \r
-        // TODO data\r
+        Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort());\r
         out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE);\r
+        Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort());\r
+        out.skipBytes(Short.SIZE / Byte.SIZE);\r
+        Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());\r
+        Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+        out.skipBytes(PADDING_IN_ACTION_HEADER);\r
+        Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array());\r
     }\r
 }\r