List of usage examples for io.netty.buffer ByteBuf readUnsignedShort
public abstract int readUnsignedShort();
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.multipart.OF10StatsRequestAggregateTest.java
License:Open Source License
/** * Tests {@link OF10StatsRequestInputFactory} for correct serialization * @throws Exception/*from www .j ava 2 s .c o m*/ */ @Test public void test() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPAGGREGATE); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder aggBuilder = new MultipartRequestAggregateBuilder(); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 8); matchBuilder.setNwDstMask((short) 16); matchBuilder.setInPort(51); matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05")); matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00")); matchBuilder.setDlVlan(52); matchBuilder.setDlVlanPcp((short) 53); matchBuilder.setDlType(54); matchBuilder.setNwTos((short) 55); matchBuilder.setNwProto((short) 56); matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1")); matchBuilder.setNwDst(new Ipv4Address("10.0.0.2")); matchBuilder.setTpSrc(57); matchBuilder.setTpDst(58); aggBuilder.setMatchV10(matchBuilder.build()); aggBuilder.setTableId((short) 5); aggBuilder.setOutPort(42L); caseBuilder.setMultipartRequestAggregate(aggBuilder.build()); builder.setMultipartRequestBody(caseBuilder.build()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); statsFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, (byte) 16, 56); Assert.assertEquals("Wrong type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); out.skipBytes(40); // skip match check Assert.assertEquals("Wrong table-id", 5, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong out port", 42, out.readUnsignedShort()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.multipart.OF10StatsRequestExperimenterTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Experimenter) for correct serialization * @throws Exception/* w w w . j av a2 s . c om*/ */ @Test public void testExperimenter() throws Exception { Mockito.when(mockRegistry .getSerializer(Matchers.<ExperimenterIdTypeSerializerKey<ExperimenterDataOfChoice>>any())) .thenReturn(serializer); OF10StatsRequestInputFactory multipartFactory = new OF10StatsRequestInputFactory(); multipartFactory.injectSerializerRegistry(mockRegistry); MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPEXPERIMENTER); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder(); MultipartRequestExperimenterBuilder expBuilder = new MultipartRequestExperimenterBuilder(); expBuilder.setExperimenter(new ExperimenterId(42L)); expBuilder.setExpType(21L); expBuilder.setExperimenterDataOfChoice(vendorData); caseBuilder.setMultipartRequestExperimenter(expBuilder.build()); builder.setMultipartRequestBody(caseBuilder.build()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); multipartFactory.serialize(message, out); BufferHelper.checkHeaderV10(out, (byte) 16, 16); Assert.assertEquals("Wrong type", 65535, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Mockito.verify(serializer, Mockito.times(1)).serialize(vendorData, out); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.multipart.TableFeaturesTest.java
License:Open Source License
/** * @throws Exception//from ww w. j av a 2 s . co m * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(12)); builder.setFlags(new MultipartRequestFlags(true)); MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder(); MultipartRequestTableFeaturesBuilder featuresBuilder = new MultipartRequestTableFeaturesBuilder(); List<TableFeatures> tableFeaturesList = new ArrayList<>(); TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); tableFeaturesBuilder.setTableId((short) 8); tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); tableFeaturesBuilder .setMetadataMatch(new BigInteger(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 })); tableFeaturesBuilder .setMetadataWrite(new BigInteger(new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 })); tableFeaturesBuilder.setConfig(new TableConfig(true)); tableFeaturesBuilder.setMaxEntries(65L); List<TableFeatureProperties> properties = new ArrayList<>(); TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLES); NextTableRelatedTableFeaturePropertyBuilder nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); List<NextTableIds> nextIds = new ArrayList<>(); nextIds.add(new NextTableIdsBuilder().setTableId((short) 1).build()); nextIds.add(new NextTableIdsBuilder().setTableId((short) 2).build()); nextPropBuilder.setNextTableIds(nextIds); propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS); nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); nextIds = new ArrayList<>(); nextIds.add(new NextTableIdsBuilder().setTableId((short) 3).build()); nextPropBuilder.setNextTableIds(nextIds); propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONS); InstructionRelatedTableFeaturePropertyBuilder insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); List<Instruction> insIds = new ArrayList<>(); InstructionBuilder insBuilder = new InstructionBuilder(); insBuilder.setType(WriteActions.class); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(GotoTable.class); insIds.add(insBuilder.build()); insPropBuilder.setInstruction(insIds); propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS); insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); insIds = new ArrayList<>(); insBuilder = new InstructionBuilder(); insBuilder.setType(WriteMetadata.class); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(ApplyActions.class); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(Meter.class); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(ClearActions.class); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(GotoTable.class); insIds.add(insBuilder.build()); insPropBuilder.setInstruction(insIds); propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); properties.add(propBuilder.build()); tableFeaturesBuilder.setTableFeatureProperties(properties); tableFeaturesList.add(tableFeaturesBuilder.build()); tableFeaturesBuilder = new TableFeaturesBuilder(); tableFeaturesBuilder.setTableId((short) 8); tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); tableFeaturesBuilder .setMetadataMatch(new BigInteger(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 })); tableFeaturesBuilder .setMetadataWrite(new BigInteger(new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 })); tableFeaturesBuilder.setConfig(new TableConfig(true)); tableFeaturesBuilder.setMaxEntries(67L); properties = new ArrayList<>(); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTMATCH); OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(InPhyPort.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(Nxm0Class.class); entriesBuilder.setOxmMatchField(InPort.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); oxmBuilder.setMatchEntries(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(IpProto.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(Nxm1Class.class); entriesBuilder.setOxmMatchField(IpEcn.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); oxmBuilder.setMatchEntries(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); tableFeaturesBuilder.setTableFeatureProperties(properties); tableFeaturesList.add(tableFeaturesBuilder.build()); featuresBuilder.setTableFeatures(tableFeaturesList); caseBuilder.setMultipartRequestTableFeatures(featuresBuilder.build()); builder.setMultipartRequestBody(caseBuilder.build()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort()); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong length", 120, out.readUnsignedShort()); Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte()); out.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(out, 32)); byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(metadataMatch); Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }, metadataMatch); byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(metadataWrite); Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }, metadataWrite); Assert.assertEquals("Wrong config", 8, out.readUnsignedInt()); Assert.assertEquals("Wrong max-entries", 65, out.readUnsignedInt()); Assert.assertEquals("Wrong property type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong next-table-id", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong next-table-id", 2, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong property type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong next-table-id", 3, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong property type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong property type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 24, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong length", 96, out.readUnsignedShort()); Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte()); out.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(out, 32)); metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(metadataMatch); Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }, metadataMatch); metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(metadataWrite); Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }, metadataWrite); Assert.assertEquals("Wrong config", 8, out.readUnsignedInt()); Assert.assertEquals("Wrong max-entries", 67, out.readUnsignedInt()); Assert.assertEquals("Wrong property type", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match class", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte()); out.skipBytes(4); Assert.assertEquals("Wrong property type", 14, out.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 20, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match class", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte()); out.skipBytes(4); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(12)); MultipartReplyTableFeaturesCaseBuilder caseBuilder = new MultipartReplyTableFeaturesCaseBuilder(); MultipartReplyTableFeaturesBuilder featuresBuilder = new MultipartReplyTableFeaturesBuilder(); List<TableFeatures> tableFeaturesList = new ArrayList<>(); TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); tableFeaturesBuilder.setTableId((short) 8); tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); tableFeaturesBuilder.setMetadataMatch(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }); tableFeaturesBuilder.setMetadataWrite(new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }); tableFeaturesBuilder.setConfig(new TableConfig(true)); tableFeaturesBuilder.setMaxEntries(65L); List<TableFeatureProperties> properties = new ArrayList<>(); TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLES); NextTableRelatedTableFeaturePropertyBuilder nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); List<NextTableIds> nextIds = new ArrayList<>(); nextIds.add(new NextTableIdsBuilder().setTableId((short) 1).build()); nextIds.add(new NextTableIdsBuilder().setTableId((short) 2).build()); nextPropBuilder.setNextTableIds(nextIds); propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS); nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); nextIds = new ArrayList<>(); nextPropBuilder.setNextTableIds(nextIds); propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONS); InstructionRelatedTableFeaturePropertyBuilder insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); List<Instruction> insIds = new ArrayList<>(); InstructionBuilder insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new WriteActionsCaseBuilder().build()); insIds.add(insBuilder.build());/*from w w w . j ava2 s . c o m*/ insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new GotoTableCaseBuilder().build()); insIds.add(insBuilder.build()); insPropBuilder.setInstruction(insIds); propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS); insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); insIds = new ArrayList<>(); insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new WriteMetadataCaseBuilder().build()); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new ApplyActionsCaseBuilder().build()); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new MeterCaseBuilder().build()); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new ClearActionsCaseBuilder().build()); insIds.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setInstructionChoice(new GotoTableCaseBuilder().build()); insIds.add(insBuilder.build()); insPropBuilder.setInstruction(insIds); propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); properties.add(propBuilder.build()); tableFeaturesBuilder.setTableFeatureProperties(properties); tableFeaturesList.add(tableFeaturesBuilder.build()); tableFeaturesBuilder = new TableFeaturesBuilder(); tableFeaturesBuilder.setTableId((short) 8); tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); byte[] metadataMatch = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }; tableFeaturesBuilder.setMetadataMatch(metadataMatch); byte[] metadataWrite = new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }; tableFeaturesBuilder.setMetadataWrite(metadataWrite); tableFeaturesBuilder.setConfig(new TableConfig(true)); tableFeaturesBuilder.setMaxEntries(67L); properties = new ArrayList<>(); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONS); ActionRelatedTableFeaturePropertyBuilder actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setActionChoice(new OutputActionCaseBuilder().build()); actions.add(actionBuilder.build()); actBuilder.setAction(actions); propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS); actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); actions = new ArrayList<>(); actBuilder.setAction(actions); propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONS); actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); actions = new ArrayList<>(); actBuilder.setAction(actions); propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS); actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); actions = new ArrayList<>(); actBuilder.setAction(actions); propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTMATCH); OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); List<MatchEntry> entries = new ArrayList<>(); MatchEntryBuilder entriesBuilder = new MatchEntryBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(InPhyPort.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntryBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(InPort.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTWILDCARDS); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELD); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); entriesBuilder = new MatchEntryBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(IpProto.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); entriesBuilder = new MatchEntryBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(IpEcn.class); entriesBuilder.setHasMask(false); entries.add(entriesBuilder.build()); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); propBuilder = new TableFeaturePropertiesBuilder(); propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS); oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); entries = new ArrayList<>(); oxmBuilder.setMatchEntry(entries); propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); properties.add(propBuilder.build()); tableFeaturesBuilder.setTableFeatureProperties(properties); tableFeaturesList.add(tableFeaturesBuilder.build()); featuresBuilder.setTableFeatures(tableFeaturesList); caseBuilder.setMultipartReplyTableFeatures(featuresBuilder.build()); builder.setMultipartReplyBody(caseBuilder.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 520); Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLEFEATURES.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); Assert.assertEquals("Wrong length", 232, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong registry-id", 8, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 32)); byte[] metadataMatchOutput = new byte[metadataMatch.length]; serializedBuffer.readBytes(metadataMatchOutput); Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }, metadataMatchOutput); serializedBuffer.skipBytes(64 - metadataMatch.length); byte[] metadataWriteOutput = new byte[metadataWrite.length]; serializedBuffer.readBytes(metadataWriteOutput); Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }, metadataWriteOutput); serializedBuffer.skipBytes(64 - metadataWrite.length); Assert.assertEquals("Wrong config", 1, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong max-entries", 65, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong property type", 2, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 6, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong next-registry-id", 1, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong next-registry-id", 2, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong property type", 3, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 0, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 3, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 24, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 2, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 6, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 5, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction type", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong length", 272, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong registry-id", 8, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(5); Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG", ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 32)); metadataMatchOutput = new byte[metadataMatch.length]; serializedBuffer.readBytes(metadataMatchOutput); serializedBuffer.skipBytes(64 - metadataMatch.length); Assert.assertArrayEquals("Wrong metadata-match", new byte[] { 0x00, 0x01, 0x02, 0x03, 0x01, 0x04, 0x08, 0x01 }, metadataMatchOutput); metadataWriteOutput = new byte[metadataWrite.length]; serializedBuffer.readBytes(metadataWriteOutput); serializedBuffer.skipBytes(64 - metadataWrite.length); Assert.assertArrayEquals("Wrong metadata-write", new byte[] { 0x00, 0x07, 0x01, 0x05, 0x01, 0x00, 0x03, 0x01 }, metadataWriteOutput); Assert.assertEquals("Wrong config", 1, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong max-entries", 67, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong property type", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 8, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action length", 4, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property type", 5, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 6, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 7, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 8, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 2, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 0, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match length", 4, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 10, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 12, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 13, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 14, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 12, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 20, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match class", 0x8000, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong match field&mask", 18, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong match length", 1, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong property type", 15, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong property length", 4, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(4); Assert.assertTrue("Unread data", serializedBuffer.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testGroupDescSerialize() throws Exception { MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(7)); MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder(); MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder(); group.setGroupDesc(createGroupDesc()); groupCase.setMultipartReplyGroupDesc(group.build()); builder.setMultipartReplyBody(groupCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 64); Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPDESC.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); MultipartReplyGroupDescCase body = (MultipartReplyGroupDescCase) message.getMultipartReplyBody(); MultipartReplyGroupDesc messageOutput = body.getMultipartReplyGroupDesc(); GroupDesc groupDesc = messageOutput.getGroupDesc().get(0); Assert.assertEquals("Wrong length", 48, serializedBuffer.readShort()); Assert.assertEquals("Wrong type", groupDesc.getType().getIntValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1);/* w w w . j av a 2 s. c o m*/ Assert.assertEquals("Wrong group id", groupDesc.getGroupId().getValue().intValue(), serializedBuffer.readInt()); BucketsList bucketList = groupDesc.getBucketsList().get(0); Assert.assertEquals("Wrong length", 40, serializedBuffer.readShort()); Assert.assertEquals("Wrong weight", bucketList.getWeight().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong watch port", bucketList.getWatchPort().getValue().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong watch group", bucketList.getWatchGroup().intValue(), serializedBuffer.readInt()); serializedBuffer.skipBytes(4); Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action type", 45, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong action type", 55, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(6); Assert.assertEquals("Wrong action type", 23, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong action type", 64, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3); Assert.assertTrue("Not all data were read", serializedBuffer.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
private static List<Bands> decodeBandsList(ByteBuf input) { List<Bands> bandsList = new ArrayList<>(); BandsBuilder bandsBuilder = new BandsBuilder(); MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder(); MeterBandDropBuilder dropBand = new MeterBandDropBuilder(); dropBand.setType(MeterBandType.forValue(input.readUnsignedShort())); input.skipBytes(Short.SIZE / Byte.SIZE); dropBand.setRate(input.readUnsignedInt()); dropBand.setBurstSize(input.readUnsignedInt()); dropCaseBuilder.setMeterBandDrop(dropBand.build()); bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build()); MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder(); MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder(); dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort())); input.skipBytes(Short.SIZE / Byte.SIZE); dscpRemarkBand.setRate(input.readUnsignedInt()); dscpRemarkBand.setBurstSize(input.readUnsignedInt()); dscpRemarkBand.setPrecLevel((short) 3); dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build()); bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build()); return bandsList; }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
/** * @throws Exception//w w w . j a v a 2 s.com * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestExperimenterMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(0xffff)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestExperimenter()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong experimenterBody", message.getMultipartRequestBody(), decodeRequestExperimenter(out)); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
/** * @throws Exception/*from w w w . ja va2 s . com*/ * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestDescMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(0)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestDesc()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactoryTest.java
License:Open Source License
/** * @throws Exception //from w ww . j av a2 s .c o m * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO */ @Test public void testFlowModInputMessageFactory() throws Exception { FlowModInputBuilder builder = new FlowModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 0); matchBuilder.setNwDstMask((short) 0); matchBuilder.setInPort(58); matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); matchBuilder.setDlVlan(18); matchBuilder.setDlVlanPcp((short) 5); matchBuilder.setDlType(42); matchBuilder.setNwTos((short) 4); matchBuilder.setNwProto((short) 7); matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); matchBuilder.setTpSrc(6653); matchBuilder.setTpDst(6633); builder.setMatchV10(matchBuilder.build()); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 }; builder.setCookie(new BigInteger(1, cookie)); builder.setCommand(FlowModCommand.forValue(0)); builder.setIdleTimeout(12); builder.setHardTimeout(16); builder.setPriority(1); builder.setBufferId(2L); builder.setOutPort(new PortNumber(4422L)); builder.setFlagsV10(new FlowModFlagsV10(true, false, true)); List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetNwDst.class); IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2")); actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetTpSrc.class); PortActionBuilder portBuilder = new PortActionBuilder(); portBuilder.setPort(new PortNumber(42L)); actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); actions.add(actionBuilder.build()); builder.setAction(actions); FlowModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance(); factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt()); Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort()); byte[] dlSrc = new byte[6]; out.readBytes(dlSrc); Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; out.readBytes(dlDst); Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort()); Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort()); Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt()); Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt()); Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort()); Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort()); byte[] cookieRead = new byte[8]; out.readBytes(cookieRead); Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); Assert.assertEquals("Wrong command", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt()); Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt()); Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort()); Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort()); out.skipBytes(2); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowRemovedMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 0); matchBuilder.setNwDstMask((short) 0); matchBuilder.setInPort(58);/* w w w. j a va2s.com*/ matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); matchBuilder.setDlVlan(18); matchBuilder.setDlVlanPcp((short) 5); matchBuilder.setDlType(42); matchBuilder.setNwTos((short) 4); matchBuilder.setNwProto((short) 7); matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); matchBuilder.setTpSrc(6653); matchBuilder.setTpDst(6633); builder.setMatchV10(matchBuilder.build()); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x01, 0x01, 0x04, 0x01 }; builder.setCookie(new BigInteger(1, cookie)); builder.setPriority(1); builder.setReason(FlowRemovedReason.forValue(1)); builder.setDurationSec(1L); builder.setDurationNsec(1L); builder.setIdleTimeout(12); builder.setPacketCount(BigInteger.valueOf(1L)); builder.setByteCount(BigInteger.valueOf(2L)); FlowRemovedMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 88); Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort()); byte[] dlSrc = new byte[6]; serializedBuffer.readBytes(dlSrc); Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; serializedBuffer.readBytes(dlDst); Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort()); byte[] cookieRead = new byte[8]; serializedBuffer.readBytes(cookieRead); Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); Assert.assertEquals("Wrong priority", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong reason", 1, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); Assert.assertEquals("Wrong duration", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong duration nsec", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong idle timeout", 12, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong packet count", 1L, serializedBuffer.readLong()); Assert.assertEquals("Wrong byte count", 2L, serializedBuffer.readLong()); }