Minor model refactor
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / FlowModInputMessageFactoryTest.java
index 6a9ee5623f1e317d50c563a8f16a8860fff6b0b0..7dbd6bf237328a8a9cc10e64f2ea483e94ba4f72 100644 (file)
@@ -28,10 +28,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
@@ -41,11 +42,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
 
 /**
  * @author timotej.kubas
@@ -62,10 +63,10 @@ public class FlowModInputMessageFactoryTest {
     public void testFlowModInputMessageFactory() throws Exception {
         FlowModInputBuilder builder = new FlowModInputBuilder();
         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
-        byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};
-        builder.setCookie(new BigInteger(cookie));
-        byte[] cookieMask = new byte[]{0x01, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30};
-        builder.setCookieMask(new BigInteger(cookieMask));
+        byte[] cookie = new byte[]{(byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};
+        builder.setCookie(new BigInteger(1, cookie));
+        byte[] cookieMask = new byte[]{(byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30};
+        builder.setCookieMask(new BigInteger(1, cookieMask));
         builder.setTableId(new TableId(65L));
         builder.setCommand(FlowModCommand.forValue(2));
         builder.setIdleTimeout(12);
@@ -95,8 +96,8 @@ public class FlowModInputMessageFactoryTest {
         entries.add(entriesBuilder.build());
         matchBuilder.setMatchEntries(entries);
         builder.setMatch(matchBuilder.build());
-        List<Instructions> instructions = new ArrayList<>();
-        InstructionsBuilder insBuilder = new InstructionsBuilder();
+        List<Instruction> instructions = new ArrayList<>();
+        InstructionBuilder insBuilder = new InstructionBuilder();
         insBuilder.setType(GotoTable.class);
         TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder();
         idBuilder.setTableId((short) 43);
@@ -108,7 +109,11 @@ public class FlowModInputMessageFactoryTest {
         metaBuilder.setMetadataMask(cookieMask);
         insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
         instructions.add(insBuilder.build());
-        builder.setInstructions(instructions);
+        insBuilder = new InstructionBuilder();
+        insBuilder.setType(ApplyActions.class);
+        insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
+        instructions.add(insBuilder.build());
+        builder.setInstruction(instructions);
         FlowModInput message = builder.build();
         
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
@@ -116,8 +121,12 @@ public class FlowModInputMessageFactoryTest {
         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
         
         BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
-        Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), out.readLong());
-        Assert.assertEquals("Wrong cookieMask", message.getCookieMask().longValue(), out.readLong());
+        cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        out.readBytes(cookie);
+        Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
+        cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        out.readBytes(cookieMask);
+        Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1,  cookieMask));
         Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());
         Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());
         Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
@@ -155,7 +164,11 @@ public class FlowModInputMessageFactoryTest {
         byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
         out.readBytes(cookieMaskRead);
         Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
-        Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); 
+        Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
+        Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
+        Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
+        out.skipBytes(4);
+        Assert.assertTrue("Unread data", out.readableBytes() == 0);
     }
     
     private static FlowModFlags createFlowModFlagsFromBitmap(int input){