use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.
the class MeterModInputMessageFactory method serializeBands.
private void serializeBands(final List<Bands> bands, final ByteBuf outBuffer) {
if (bands != null) {
for (Bands currentBand : bands) {
MeterBand meterBand = currentBand.getMeterBand();
if (meterBand instanceof MeterBandDropCase) {
MeterBandDropCase dropBandCase = (MeterBandDropCase) meterBand;
MeterBandDrop dropBand = dropBandCase.getMeterBandDrop();
writeBandCommonFields(dropBand, outBuffer);
outBuffer.writeZero(PADDING_IN_METER_BAND_DROP);
} else if (meterBand instanceof MeterBandDscpRemarkCase) {
MeterBandDscpRemarkCase dscpRemarkBandCase = (MeterBandDscpRemarkCase) meterBand;
MeterBandDscpRemark dscpRemarkBand = dscpRemarkBandCase.getMeterBandDscpRemark();
writeBandCommonFields(dscpRemarkBand, outBuffer);
outBuffer.writeByte(dscpRemarkBand.getPrecLevel());
outBuffer.writeZero(PADDING_IN_METER_BAND_DSCP_REMARK);
} else if (meterBand instanceof MeterBandExperimenterCase) {
MeterBandExperimenterCase experimenterBandCase = (MeterBandExperimenterCase) meterBand;
MeterBandExperimenter experimenterBand = experimenterBandCase.getMeterBandExperimenter();
ExperimenterIdMeterBand expIdMeterBand = experimenterBand.getAugmentation(ExperimenterIdMeterBand.class);
if (expIdMeterBand != null) {
long expId = expIdMeterBand.getExperimenter().getValue();
Class<? extends ExperimenterMeterBandSubType> meterBandSubType = expIdMeterBand.getSubType();
try {
OFSerializer<MeterBandExperimenterCase> serializer = registry.getSerializer(ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(EncodeConstants.OF13_VERSION_ID, expId, meterBandSubType));
serializer.serialize(experimenterBandCase, outBuffer);
} catch (final IllegalStateException e) {
LOG.warn("Serializer for key: {} wasn't found, exception {}", ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(EncodeConstants.OF13_VERSION_ID, expId, meterBandSubType), e);
}
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testGatherStatistics_meterConfig.
@Test
public void testGatherStatistics_meterConfig() throws Exception {
final MultipartType type = MultipartType.OFPMPMETERCONFIG;
final Long meterIdValue = 55L;
final MeterConfigBuilder meterConfigBld = new MeterConfigBuilder().setMeterId(new MeterId(meterIdValue)).setFlags(new MeterFlags(false, true, false, true)).setBands(Collections.<Bands>emptyList());
final MultipartReplyMeterConfigBuilder mpReplyMeterConfigBld = new MultipartReplyMeterConfigBuilder();
mpReplyMeterConfigBld.setMeterConfig(Lists.newArrayList(meterConfigBld.build()));
final MultipartReplyMeterConfigCaseBuilder mpReplyMeterConfigCaseBld = new MultipartReplyMeterConfigCaseBuilder();
mpReplyMeterConfigCaseBld.setMultipartReplyMeterConfig(mpReplyMeterConfigBld.build());
final MultipartReply meterConfigUpdated = assembleMPReplyMessage(type, mpReplyMeterConfigCaseBld.build());
final List<MultipartReply> statsData = Collections.singletonList(meterConfigUpdated);
fireAndCheck(type, statsData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId meterId = new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(meterIdValue);
final KeyedInstanceIdentifier<Meter, MeterKey> meterPath = dummyNodePath.augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meterId));
verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
verify(deviceMeterRegistry).store(meterId);
verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(meterPath), Matchers.any(Meter.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.
the class MeterModInputMessageFactoryTest 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());
input.skipBytes(4);
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(input.readUnsignedByte());
input.skipBytes(3);
dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
return bandsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands in project openflowplugin by opendaylight.
the class MeterModInputMessageFactoryTest method testMeterModInputMessage.
/**
* Testing of {@link MeterModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testMeterModInputMessage() throws Exception {
MeterModInputBuilder builder = new MeterModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setCommand(MeterModCommand.forValue(1));
builder.setFlags(new MeterFlags(false, true, true, false));
builder.setMeterId(new MeterId(2248L));
builder.setBands(createBandsList());
MeterModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
meterModFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, (byte) 29, 48);
Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readUnsignedShort());
Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort()));
Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt());
Assert.assertEquals("Wrong bands", message.getBands(), decodeBandsList(out));
}
Aggregations