X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowjava%2Fopenflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FFlowModInputMessageFactoryTest.java;h=01aede96d814a99644d97ae64fb3f5f7e498c32a;hb=a0543340afd14d8ab4aac0f6c13ddcbf8ec1c761;hp=f98564bd064df6e2b014d587abb2d21810d1a432;hpb=8e54802677177ddcb7cacc1324862b7e46a38910;p=openflowplugin.git diff --git a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowModInputMessageFactoryTest.java b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowModInputMessageFactoryTest.java index f98564bd06..01aede96d8 100644 --- a/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowModInputMessageFactoryTest.java +++ b/openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowModInputMessageFactoryTest.java @@ -8,7 +8,6 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; -import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import org.junit.Assert; @@ -49,45 +48,49 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; +import org.opendaylight.yangtools.yang.common.Uint8; /** - * @author giuseppex.petralia@intel.com + * Unit tests for FlowModInputMessageFactory. * + * @author giuseppex.petralia@intel.com */ public class FlowModInputMessageFactoryTest { private OFDeserializer flowFactory; /** - * Initializes deserializer registry and lookups correct deserializer + * Initializes deserializer registry and lookups correct deserializer. */ @Before public void startUp() { DeserializerRegistry registry = new DeserializerRegistryImpl(); registry.init(); flowFactory = registry - .getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 14, FlowModInput.class)); + .getDeserializer(new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 14, FlowModInput.class)); } @Test - public void test() throws Exception { - ByteBuf bb = BufferHelper - .buildBuffer("ff 01 04 01 06 00 07 01 ff 05 00 00 09 30 00 30 41 02 00 0c 00 00 00 7e 00 " - + "00 00 02 00 00 11 46 00 00 00 62 00 0b 00 00 00 01 00 11 80 00 02 04 00 00 00 2a 80 00 12 01 04 00 " - + "00 00 00 00 00 00 00 01 00 08 2b 00 00 00 00 02 00 18 00 00 00 00 ff 01 04 01 06 00 07 01 ff 05 00 00 " - + "09 30 00 30 00 04 00 18 00 00 00 00 00 00 00 10 00 00 00 2a 00 34 00 00 00 00 00 00"); + public void test() { + ByteBuf bb = BufferHelper.buildBuffer( + "ff 01 04 01 06 00 07 01 ff 05 00 00 09 30 00 30 41 02 00 0c 00 00 00 7e 00 " + + "00 00 02 00 00 11 46 00 00 00 62 00 0b 00 00 00 01 00 11 80 00 02 04 00 00 00 2a 80 00 12 01 04 00 " + + "00 00 00 00 00 00 00 01 00 08 2b 00 00 00 00 02 00 18 00 00 00 00 ff 01 04 01 06 00 07 01 ff 05 00 00 " + + "09 30 00 30 00 04 00 18 00 00 00 00 00 00 00 10 00 00 00 2a 00 34 00 00 00 00 00 00"); FlowModInput deserializedMessage = BufferHelper.deserialize(flowFactory, bb); BufferHelper.checkHeaderV13(deserializedMessage); - byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 }; - Assert.assertEquals("Wrong cookie", new BigInteger(1, cookie), deserializedMessage.getCookie()); - byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 }; - Assert.assertEquals("Wrong cookie mask", new BigInteger(1, cookieMask), deserializedMessage.getCookieMask()); - Assert.assertEquals("Wrong table id", new TableId(65L), deserializedMessage.getTableId()); + Assert.assertEquals("Wrong cookie", Uint64.valueOf("FF01040106000701", 16), deserializedMessage.getCookie()); + Assert.assertEquals("Wrong cookie mask", Uint64.valueOf("FF05000009300030", 16), + deserializedMessage.getCookieMask()); + Assert.assertEquals("Wrong table id", new TableId(Uint32.valueOf(65)), deserializedMessage.getTableId()); Assert.assertEquals("Wrong command", FlowModCommand.forValue(2), deserializedMessage.getCommand()); Assert.assertEquals("Wrong idle timeout", 12, deserializedMessage.getIdleTimeout().intValue()); Assert.assertEquals("Wrong hard timeout", 0, deserializedMessage.getHardTimeout().intValue()); Assert.assertEquals("Wrong priority", 126, deserializedMessage.getPriority().intValue()); Assert.assertEquals("Wrong buffer id ", 2L, deserializedMessage.getBufferId().longValue()); - Assert.assertEquals("Wrong out port", new PortNumber(4422L), deserializedMessage.getOutPort()); + Assert.assertEquals("Wrong out port", new PortNumber(Uint32.valueOf(4422)), deserializedMessage.getOutPort()); Assert.assertEquals("Wrong out group", 98L, deserializedMessage.getOutGroup().longValue()); Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), deserializedMessage.getFlags()); @@ -96,12 +99,12 @@ public class FlowModInputMessageFactoryTest { } - private List createInstructions() { - List instructions = new ArrayList<>(); + private static List createInstructions() { + final List instructions = new ArrayList<>(); InstructionBuilder insBuilder = new InstructionBuilder(); GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder(); GotoTableBuilder instructionBuilder = new GotoTableBuilder(); - instructionBuilder.setTableId((short) 43); + instructionBuilder.setTableId(Uint8.valueOf(43)); goToCaseBuilder.setGotoTable(instructionBuilder.build()); insBuilder.setInstructionChoice(goToCaseBuilder.build()); instructions.add(insBuilder.build()); @@ -115,14 +118,14 @@ public class FlowModInputMessageFactoryTest { insBuilder.setInstructionChoice(metadataCaseBuilder.build()); instructions.add(insBuilder.build()); insBuilder = new InstructionBuilder(); - ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); - ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder(); - List actions = new ArrayList<>(); - ActionBuilder actionBuilder = new ActionBuilder(); + final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); + final ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder(); + final List actions = new ArrayList<>(); + final ActionBuilder actionBuilder = new ActionBuilder(); OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder(); OutputActionBuilder outputBuilder = new OutputActionBuilder(); - outputBuilder.setPort(new PortNumber(42L)); - outputBuilder.setMaxLength(52); + outputBuilder.setPort(new PortNumber(Uint32.valueOf(42))); + outputBuilder.setMaxLength(Uint16.valueOf(52)); caseBuilder.setOutputAction(outputBuilder.build()); actionBuilder.setActionChoice(caseBuilder.build()); actions.add(actionBuilder.build()); @@ -133,31 +136,30 @@ public class FlowModInputMessageFactoryTest { return instructions; } - private Match createMatch() { + private static Match createMatch() { MatchBuilder matchBuilder = new MatchBuilder(); - matchBuilder.setType(OxmMatchType.class); - List entries = new ArrayList<>(); + matchBuilder.setType(OxmMatchType.VALUE); + final List entries = new ArrayList<>(); MatchEntryBuilder entriesBuilder = new MatchEntryBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(InPhyPort.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.VALUE); + entriesBuilder.setOxmMatchField(InPhyPort.VALUE); entriesBuilder.setHasMask(false); InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder(); InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder(); - inPhyPortBuilder.setPortNumber(new PortNumber(42L)); + inPhyPortBuilder.setPortNumber(new PortNumber(Uint32.valueOf(42))); inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build()); entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build()); entries.add(entriesBuilder.build()); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(IpEcn.class); + entriesBuilder.setOxmClass(OpenflowBasicClass.VALUE); + entriesBuilder.setOxmMatchField(IpEcn.VALUE); entriesBuilder.setHasMask(false); IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder(); IpEcnBuilder ipEcnBuilder = new IpEcnBuilder(); - ipEcnBuilder.setEcn((short) 4); + ipEcnBuilder.setEcn(Uint8.valueOf(4)); ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build()); entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build()); entries.add(entriesBuilder.build()); matchBuilder.setMatchEntry(entries); return matchBuilder.build(); } - }