--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories.multipart;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+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.serialization.factories.MultipartRequestInputFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeaturePropertyBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeaturePropertyBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;\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.Meter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;\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.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;\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.InPort;\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.IpProto;\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.Nxm1Class;\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.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.MultipartRequestInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeaturesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeaturePropertiesBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class TableFeaturesTest {\r
+ private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE =\r
+ MultipartRequestInputFactoryTest.PADDING_IN_MULTIPART_REQUEST_MESSAGE;\r
+\r
+ /**\r
+ * @throws Exception\r
+ * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO\r
+ */\r
+ @Test\r
+ public void testMultipartRequestTableFeaturesMessageFactory() throws Exception {\r
+ MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);\r
+ builder.setType(MultipartType.forValue(12));\r
+ builder.setFlags(new MultipartRequestFlags(true));\r
+ MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();\r
+ MultipartRequestTableFeaturesBuilder featuresBuilder = new MultipartRequestTableFeaturesBuilder();\r
+ List<TableFeatures> tableFeaturesList = new ArrayList<>();\r
+ TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder();\r
+ tableFeaturesBuilder.setTableId((short) 8);\r
+ tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG");\r
+ tableFeaturesBuilder.setMetadataMatch(new BigInteger(new byte[] {0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01}));\r
+ tableFeaturesBuilder.setMetadataWrite(new BigInteger(new byte[] {0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01}));\r
+ tableFeaturesBuilder.setConfig(new TableConfig(true));\r
+ tableFeaturesBuilder.setMaxEntries(65L);\r
+ List<TableFeatureProperties> properties = new ArrayList<>();\r
+ TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLES);\r
+ NextTableRelatedTableFeaturePropertyBuilder nextPropBuilder =\r
+ new NextTableRelatedTableFeaturePropertyBuilder();\r
+ List<NextTableIds> nextIds = new ArrayList<>();\r
+ nextIds.add(new NextTableIdsBuilder().setTableId((short) 1).build());\r
+ nextIds.add(new NextTableIdsBuilder().setTableId((short) 2).build());\r
+ nextPropBuilder.setNextTableIds(nextIds);\r
+ propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS);\r
+ nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder();\r
+ nextIds = new ArrayList<>();\r
+ nextIds.add(new NextTableIdsBuilder().setTableId((short) 3).build());\r
+ nextPropBuilder.setNextTableIds(nextIds);\r
+ propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONS);\r
+ InstructionRelatedTableFeaturePropertyBuilder insPropBuilder =\r
+ new InstructionRelatedTableFeaturePropertyBuilder();\r
+ List<Instructions> insIds = new ArrayList<>();\r
+ InstructionsBuilder insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(WriteActions.class);\r
+ insIds.add(insBuilder.build());\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(GotoTable.class);\r
+ insIds.add(insBuilder.build());\r
+ insPropBuilder.setInstructions(insIds);\r
+ propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS);\r
+ insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder();\r
+ insIds = new ArrayList<>();\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(WriteMetadata.class);\r
+ insIds.add(insBuilder.build());\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(ApplyActions.class);\r
+ insIds.add(insBuilder.build());\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(Meter.class);\r
+ insIds.add(insBuilder.build());\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(ClearActions.class);\r
+ insIds.add(insBuilder.build());\r
+ insBuilder = new InstructionsBuilder();\r
+ insBuilder.setType(GotoTable.class);\r
+ insIds.add(insBuilder.build());\r
+ insPropBuilder.setInstructions(insIds);\r
+ propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ tableFeaturesBuilder.setTableFeatureProperties(properties);\r
+ tableFeaturesList.add(tableFeaturesBuilder.build());\r
+ tableFeaturesBuilder = new TableFeaturesBuilder();\r
+ tableFeaturesBuilder.setTableId((short) 8);\r
+ tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG");\r
+ tableFeaturesBuilder.setMetadataMatch(new BigInteger(new byte[] {0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01}));\r
+ tableFeaturesBuilder.setMetadataWrite(new BigInteger(new byte[] {0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01}));\r
+ tableFeaturesBuilder.setConfig(new TableConfig(true));\r
+ tableFeaturesBuilder.setMaxEntries(67L);\r
+ properties = new ArrayList<>();\r
+ propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTMATCH);\r
+ OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder();\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
+ entries.add(entriesBuilder.build());\r
+ entriesBuilder = new MatchEntriesBuilder();\r
+ entriesBuilder.setOxmClass(Nxm0Class.class);\r
+ entriesBuilder.setOxmMatchField(InPort.class);\r
+ entriesBuilder.setHasMask(false);\r
+ entries.add(entriesBuilder.build());\r
+ oxmBuilder.setMatchEntries(entries);\r
+ propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ propBuilder = new TableFeaturePropertiesBuilder();\r
+ propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD);\r
+ oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder();\r
+ entries = new ArrayList<>();\r
+ entriesBuilder = new MatchEntriesBuilder();\r
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
+ entriesBuilder.setOxmMatchField(IpProto.class);\r
+ entriesBuilder.setHasMask(false);\r
+ entries.add(entriesBuilder.build());\r
+ entriesBuilder = new MatchEntriesBuilder();\r
+ entriesBuilder.setOxmClass(Nxm1Class.class);\r
+ entriesBuilder.setOxmMatchField(IpEcn.class);\r
+ entriesBuilder.setHasMask(false);\r
+ entries.add(entriesBuilder.build());\r
+ oxmBuilder.setMatchEntries(entries);\r
+ propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build());\r
+ properties.add(propBuilder.build());\r
+ tableFeaturesBuilder.setTableFeatureProperties(properties);\r
+ tableFeaturesList.add(tableFeaturesBuilder.build());\r
+ featuresBuilder.setTableFeatures(tableFeaturesList);\r
+ caseBuilder.setMultipartRequestTableFeatures(featuresBuilder.build());\r
+ builder.setMultipartRequestBody(caseBuilder.build());\r
+ MultipartRequestInput message = builder.build();\r
+\r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();\r
+ factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
+\r
+ BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));\r
+ Assert.assertEquals("Wrong type", 12, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());\r
+ out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);\r
+ Assert.assertEquals("Wrong length", 120, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+ out.skipBytes(5);\r
+ Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
+ ByteBufUtils.decodeNullTerminatedString(out, 32));\r
+ byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ out.readBytes(metadataMatch);\r
+ Assert.assertArrayEquals("Wrong metadata-match",\r
+ new byte[] {0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01}, metadataMatch);\r
+ byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ out.readBytes(metadataWrite);\r
+ Assert.assertArrayEquals("Wrong metadata-write",\r
+ new byte[] {0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01}, metadataWrite);\r
+ Assert.assertEquals("Wrong config", 8, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong max-entries", 65, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong property type", 2, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 6, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong next-table-id", 1, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong next-table-id", 2, out.readUnsignedByte());\r
+ out.skipBytes(2);\r
+ Assert.assertEquals("Wrong property type", 3, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 5, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong next-table-id", 3, out.readUnsignedByte());\r
+ out.skipBytes(3);\r
+ Assert.assertEquals("Wrong property type", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ out.skipBytes(4);\r
+ Assert.assertEquals("Wrong property type", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 24, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 5, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong length", 96, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+ out.skipBytes(5);\r
+ Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
+ ByteBufUtils.decodeNullTerminatedString(out, 32));\r
+ metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ out.readBytes(metadataMatch);\r
+ Assert.assertArrayEquals("Wrong metadata-match",\r
+ new byte[] {0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01}, metadataMatch);\r
+ metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
+ out.readBytes(metadataWrite);\r
+ Assert.assertArrayEquals("Wrong metadata-write",\r
+ new byte[] {0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01}, metadataWrite);\r
+ Assert.assertEquals("Wrong config", 8, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong max-entries", 67, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong property type", 8, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match field&mask", 2, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match class", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match field&mask", 0, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
+ out.skipBytes(4);\r
+ Assert.assertEquals("Wrong property type", 14, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match field&mask", 20, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match class", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
+ out.skipBytes(4);\r
+ Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
+ }\r
+\r
+}\r