Search in sources :

Example 6 with MeterConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testMeterConfigSerialize.

@Test
public void testMeterConfigSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(10));
    MultipartReplyMeterConfigCaseBuilder meterConfigCase = new MultipartReplyMeterConfigCaseBuilder();
    MultipartReplyMeterConfigBuilder meterConfigBuilder = new MultipartReplyMeterConfigBuilder();
    meterConfigBuilder.setMeterConfig(createMeterConfig());
    meterConfigCase.setMultipartReplyMeterConfig(meterConfigBuilder.build());
    builder.setMultipartReplyBody(meterConfigCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 48);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERCONFIG.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyMeterConfigCase body = (MultipartReplyMeterConfigCase) message.getMultipartReplyBody();
    MultipartReplyMeterConfig messageOutput = body.getMultipartReplyMeterConfig();
    MeterConfig meterConfig = messageOutput.getMeterConfig().get(0);
    Assert.assertEquals("Wrong len", 32, serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", meterConfig.getFlags(), createMeterFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong meterId", meterConfig.getMeterId().getValue().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong bands", meterConfig.getBands(), decodeBandsList(serializedBuffer));
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyMeterConfigCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCaseBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartReplyMeterConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MultipartReplyMeterConfigCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase) ByteBuf(io.netty.buffer.ByteBuf) MeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig) MultipartReplyMeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig) MultipartReplyMeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig) Test(org.junit.Test)

Example 7 with MeterConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method setMeterConfig.

private MultipartReplyMeterConfigCase setMeterConfig(final ByteBuf input) {
    MultipartReplyMeterConfigCaseBuilder caseBuilder = new MultipartReplyMeterConfigCaseBuilder();
    MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();
    List<MeterConfig> meterConfigList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();
        int meterConfigBodyLength = input.readUnsignedShort();
        meterConfigBuilder.setFlags(createMeterFlags(input.readUnsignedShort()));
        meterConfigBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
        int actualLength = METER_CONFIG_LENGTH;
        List<Bands> bandsList = new ArrayList<>();
        while (actualLength < meterConfigBodyLength) {
            int bandStartIndex = input.readerIndex();
            BandsBuilder bandsBuilder = new BandsBuilder();
            int bandType = input.readUnsignedShort();
            switch(bandType) {
                case 1:
                    final MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
                    MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
                    bandDropBuilder.setType(MeterBandType.forValue(bandType));
                    actualLength += input.readUnsignedShort();
                    bandDropBuilder.setRate(input.readUnsignedInt());
                    bandDropBuilder.setBurstSize(input.readUnsignedInt());
                    input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
                    bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build());
                    bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
                    break;
                case 2:
                    final MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
                    MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
                    bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
                    actualLength += input.readUnsignedShort();
                    bandDscpRemarkBuilder.setRate(input.readUnsignedInt());
                    bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt());
                    bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte());
                    input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                    bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
                    bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
                    break;
                case 0xFFFF:
                    actualLength += input.readUnsignedShort();
                    final long expId = input.getUnsignedInt(input.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
                    input.readerIndex(bandStartIndex);
                    OFDeserializer<MeterBandExperimenterCase> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId));
                    bandsBuilder.setMeterBand(deserializer.deserialize(input));
                    break;
                default:
                    break;
            }
            bandsList.add(bandsBuilder.build());
        }
        meterConfigBuilder.setBands(bandsList);
        meterConfigList.add(meterConfigBuilder.build());
    }
    builder.setMeterConfig(meterConfigList);
    caseBuilder.setMultipartReplyMeterConfig(builder.build());
    return caseBuilder.build();
}
Also used : MultipartReplyMeterConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder) MeterConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfigBuilder) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) MultipartReplyMeterConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder) ArrayList(java.util.ArrayList) MeterBandDropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder) MeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId) MeterBandDscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands) MeterBandDropCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder) MultipartReplyMeterConfigCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCaseBuilder) BandsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.BandsBuilder)

Aggregations

MeterConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig)6 ArrayList (java.util.ArrayList)4 Bands (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands)4 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId)3 MeterBandExperimenterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase)3 MultipartReplyMeterConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig)3 MultipartReplyMeterConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder)3 MeterConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfigBuilder)3 ByteBuf (io.netty.buffer.ByteBuf)2 MeterFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags)2 MeterBandDropCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase)2 MeterBandDropCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder)2 MeterBandDscpRemarkCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase)2 MeterBandDscpRemarkCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder)2 MeterBandDrop (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDrop)2 MeterBandDropBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder)2 MeterBandDscpRemark (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemark)2 MeterBandExperimenter (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter)2 MultipartReplyMeterConfigCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase)2 Test (org.junit.Test)1