Search in sources :

Example 6 with Bands

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.

the class MeterModInputMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public MeterModInput deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    MeterModInputBuilder builder = new MeterModInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setCommand(MeterModCommand.forValue(rawMessage.readUnsignedShort()));
    builder.setFlags(createMeterFlags(rawMessage.readUnsignedShort()));
    builder.setMeterId(new MeterId(rawMessage.readUnsignedInt()));
    List<Bands> bandsList = new ArrayList<>();
    while (rawMessage.readableBytes() > 0) {
        BandsBuilder bandsBuilder = new BandsBuilder();
        int bandStartIndex = rawMessage.readerIndex();
        int bandType = rawMessage.readUnsignedShort();
        switch(bandType) {
            case 1:
                final MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
                MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
                bandDropBuilder.setType(MeterBandType.forValue(bandType));
                rawMessage.readUnsignedShort();
                bandDropBuilder.setRate(rawMessage.readUnsignedInt());
                bandDropBuilder.setBurstSize(rawMessage.readUnsignedInt());
                rawMessage.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));
                rawMessage.readUnsignedShort();
                bandDscpRemarkBuilder.setRate(rawMessage.readUnsignedInt());
                bandDscpRemarkBuilder.setBurstSize(rawMessage.readUnsignedInt());
                bandDscpRemarkBuilder.setPrecLevel(rawMessage.readUnsignedByte());
                rawMessage.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
                bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
                break;
            case 0xFFFF:
                long expId = rawMessage.getUnsignedInt(rawMessage.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
                rawMessage.readerIndex(bandStartIndex);
                OFDeserializer<MeterBandExperimenterCase> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId));
                bandsBuilder.setMeterBand(deserializer.deserialize(rawMessage));
                break;
            default:
                break;
        }
        bandsList.add(bandsBuilder.build());
    }
    builder.setBands(bandsList);
    return builder.build();
}
Also used : MeterModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) 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) 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.meter.mod.Bands) MeterBandDropCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder) BandsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with Bands

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.

the class MeterModInputMessageFactoryTest method createBandsList.

private static List<Bands> createBandsList() {
    final List<Bands> bandsList = new ArrayList<>();
    final BandsBuilder bandsBuilder = new BandsBuilder();
    final MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
    MeterBandDropBuilder dropBand = new MeterBandDropBuilder();
    dropBand.setType(MeterBandType.OFPMBTDROP);
    dropBand.setRate(1L);
    dropBand.setBurstSize(2L);
    dropCaseBuilder.setMeterBandDrop(dropBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build());
    final MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
    MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder();
    dscpRemarkBand.setType(MeterBandType.OFPMBTDSCPREMARK);
    dscpRemarkBand.setRate(1L);
    dscpRemarkBand.setBurstSize(2L);
    dscpRemarkBand.setPrecLevel((short) 3);
    dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
    return bandsList;
}
Also used : 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.meter.mod.Bands) MeterBandDropCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) 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) BandsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder)

Example 8 with Bands

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method decodeBandsList.

private static List<Bands> decodeBandsList(ByteBuf input) {
    final List<Bands> bandsList = new ArrayList<>();
    final BandsBuilder bandsBuilder = new BandsBuilder();
    final 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());
    final 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;
}
Also used : 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) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) 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) 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)

Example 9 with Bands

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands 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 10 with Bands

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testMeterFeaturesSerialize.

@Test
public void testMeterFeaturesSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(11));
    final MultipartReplyMeterFeaturesCaseBuilder meterFeaturesCase = new MultipartReplyMeterFeaturesCaseBuilder();
    MultipartReplyMeterFeaturesBuilder meterFeatures = new MultipartReplyMeterFeaturesBuilder();
    meterFeatures.setMaxMeter(1L);
    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());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.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);
}
Also used : MultipartReplyMeterFeaturesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartReplyMeterFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder) MultipartReplyMeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MeterBandTypeBitmap(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap) ByteBuf(io.netty.buffer.ByteBuf) MultipartReplyMeterFeaturesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)14 MeterBandDropCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder)9 MeterBandDscpRemarkCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder)9 MeterBandDropBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder)9 MeterBandDscpRemarkBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder)9 Bands (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands)9 MeterBandExperimenterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase)8 Test (org.junit.Test)7 MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)6 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId)6 MeterModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder)6 MeterBand (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand)6 MeterBandDropCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase)6 MeterBandDscpRemarkCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase)6 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)6 MeterBandType (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType)5 DscpRemarkBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder)5 MeterBandHeadersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder)5 MeterBandHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder)5 MeterBandTypesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder)5