List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.TableModInputMessageFactory.java
License:Open Source License
@Override public TableModInput deserialize(ByteBuf rawMessage) { TableModInputBuilder builder = new TableModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); rawMessage.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE); builder.setConfig(createTableConfig(rawMessage.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.NetIdeDeserializationFactory.java
License:Open Source License
/** * Transforms ByteBuf into correct POJO message * * @param rawMessage//from w w w .ja v a2 s . c om * @param version * version decoded from OpenFlow protocol message * @return correct POJO as DataObject */ public DataObject deserialize(final ByteBuf rawMessage, final short version) { DataObject dataObject = null; int type = rawMessage.readUnsignedByte(); Class<?> clazz = messageClassMap.get(new TypeToClassKey(version, type)); rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); OFDeserializer<DataObject> deserializer = registry .getDeserializer(new MessageCodeKey(version, type, clazz)); dataObject = deserializer.deserialize(rawMessage); return dataObject; }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.FlowRemovedMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { FlowRemovedMessageFactory serializer = new FlowRemovedMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();/*from w w w . ja v a 2 s . c o m*/ serializer.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72); Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte()); Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(), serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong match type", 1, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort()); short fieldAndMask = serializedBuffer.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 42, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort()); fieldAndMask = serializedBuffer.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 4, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(7); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.GetFeaturesOutputFactoryTest.java
License:Open Source License
@Test public void testSerialize() { GetFeaturesOutputFactory serializer = new GetFeaturesOutputFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();//from ww w .j a v a 2 s . co m serializer.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32); Assert.assertEquals("Wrong DatapathId", message.getDatapathId().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Buffer ID", message.getBuffers().longValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong auxiliary ID", message.getAuxiliaryId().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(PADDING); Assert.assertEquals("Wrong Capabilities", message.getCapabilities(), createCapabilities(serializedBuffer.readInt())); Assert.assertEquals("Wrong reserved", message.getReserved().longValue(), serializedBuffer.readInt()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { 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 www .j a v a 2 s .co 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()); message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.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.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testMeterFeaturesSerialize() { builder.setType(MultipartType.forValue(11)); MultipartReplyMeterFeaturesCaseBuilder meterFeaturesCase = new MultipartReplyMeterFeaturesCaseBuilder(); MultipartReplyMeterFeaturesBuilder meterFeatures = new MultipartReplyMeterFeaturesBuilder(); meterFeatures.setMaxMeter(1L);// w w w . j av a 2 s. c o m meterFeatures.setBandTypes(new MeterBandTypeBitmap(true, false)); meterFeatures.setCapabilities(new MeterFlags(true, false, true, false)); meterFeatures.setMaxBands((short) 1); meterFeatures.setMaxColor((short) 1); meterFeaturesCase.setMultipartReplyMeterFeatures(meterFeatures.build()); builder.setMultipartReplyBody(meterFeaturesCase.build()); message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 30); Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERFEATURES.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); MultipartReplyMeterFeaturesCase body = (MultipartReplyMeterFeaturesCase) message.getMultipartReplyBody(); MultipartReplyMeterFeatures messageOutput = body.getMultipartReplyMeterFeatures(); Assert.assertEquals("Wrong max meter", messageOutput.getMaxMeter().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong band type", messageOutput.getBandTypes(), createMeterBandTypeBitmap(serializedBuffer.readInt())); Assert.assertEquals("Wrong capabilities", messageOutput.getCapabilities(), createMeterFlags(serializedBuffer.readShort())); Assert.assertEquals("Wrong max bands", messageOutput.getMaxBands().shortValue(), serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong max color", messageOutput.getMaxColor().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(2); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testGroupDescSerialize() { builder.setType(MultipartType.forValue(7)); MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder(); MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder(); group.setGroupDesc(createGroupDesc()); groupCase.setMultipartReplyGroupDesc(group.build()); builder.setMultipartReplyBody(groupCase.build()); message = builder.build();// w w w .j av a 2s. co m ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.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); 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.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testTableSerialize() { builder.setType(MultipartType.forValue(3)); MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder table = new MultipartReplyTableBuilder(); table.setTableStats(createTableStats()); tableCase.setMultipartReplyTable(table.build()); builder.setMultipartReplyBody(tableCase.build()); message = builder.build();/*from w w w .j av a 2 s . c o m*/ ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 40); Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); MultipartReplyTableCase body = (MultipartReplyTableCase) message.getMultipartReplyBody(); MultipartReplyTable messageOutput = body.getMultipartReplyTable(); TableStats tableStats = messageOutput.getTableStats().get(0); Assert.assertEquals("Wrong tableId", tableStats.getTableId().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3); Assert.assertEquals("Wrong active count", tableStats.getActiveCount().longValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong lookup count", tableStats.getLookupCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong matched count", tableStats.getMatchedCount().longValue(), serializedBuffer.readLong()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
private static void testFlowBody(MultipartReplyBody body, ByteBuf output) { MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body; MultipartReplyFlow flow = flowCase.getMultipartReplyFlow(); FlowStats flowStats = flow.getFlowStats().get(0); Assert.assertEquals("Wrong length", 176, output.readShort()); Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte()); output.skipBytes(1);//w ww. j a v a 2 s . c o m Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt()); Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt()); Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort()); Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort()); Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort()); output.skipBytes(6); Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong()); Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong()); Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong()); Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort()); output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort()); short fieldAndMask = output.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt()); Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort()); fieldAndMask = output.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte()); output.skipBytes(7); Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte()); output.skipBytes(3); Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort()); output.skipBytes(4); byte[] actual = new byte[8]; output.readBytes(actual); Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual)); actual = new byte[8]; output.readBytes(actual); Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual)); Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt()); Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort()); Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt()); Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort()); output.skipBytes(6); Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte()); output.skipBytes(3); Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort()); output.skipBytes(2); Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); output.skipBytes(4); Assert.assertTrue("Not all data were read", output.readableBytes() == 0); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10FeaturesReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { OF10FeaturesReplyMessageFactory serializer = new OF10FeaturesReplyMessageFactory(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 80); Assert.assertEquals("Wrong datapath id", message.getDatapathId().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong n buffers", message.getBuffers().longValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong n tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3);/* w ww .j a v a 2s . c o m*/ Assert.assertEquals("Wrong capabilities", message.getCapabilitiesV10(), createCapabilities(serializedBuffer.readInt())); Assert.assertEquals("Wrong actions", message.getActionsV10(), createActionsV10(serializedBuffer.readInt())); PhyPort port = message.getPhyPort().get(0); Assert.assertEquals("Wrong port No", port.getPortNo().intValue(), serializedBuffer.readShort()); byte[] address = new byte[6]; serializedBuffer.readBytes(address); Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase()); byte[] name = new byte[16]; serializedBuffer.readBytes(name); Assert.assertEquals("Wrong name", port.getName(), new String(name).trim()); Assert.assertEquals("Wrong config", port.getConfigV10(), createPortConfig(serializedBuffer.readInt())); Assert.assertEquals("Wrong state", port.getStateV10(), createPortState(serializedBuffer.readInt())); Assert.assertEquals("Wrong current", port.getCurrentFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong advertised", port.getAdvertisedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong supported", port.getSupportedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong peer", port.getPeerFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); }