use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats in project openflowplugin by opendaylight.
the class MultipartReplyMeterConfigDeserializer method deserialize.
@Override
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();
final List<MeterConfigStats> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final int itemLength = message.readUnsignedShort();
final MeterConfigStatsBuilder itemBuilder = new MeterConfigStatsBuilder().setFlags(readMeterFlags(message)).setMeterId(new MeterId(message.readUnsignedInt()));
final List<MeterBandHeader> subItems = new ArrayList<>();
int actualLength = METER_CONFIG_LENGTH;
while (actualLength < itemLength) {
final int itemStartIndex = message.readerIndex();
final int itemBandType = message.readUnsignedShort();
final MeterBandHeaderBuilder subItemBuilder = new MeterBandHeaderBuilder();
actualLength += message.readUnsignedShort();
switch(itemBandType) {
case OFPMBTDROP:
subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(true, false, false)).build()).setBandType(new DropBuilder().setDropRate(message.readUnsignedInt()).setDropBurstSize(message.readUnsignedInt()).build());
message.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
break;
case OFPMBTDSCP:
subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, true, false)).build()).setBandType(new DscpRemarkBuilder().setDscpRemarkRate(message.readUnsignedInt()).setDscpRemarkBurstSize(message.readUnsignedInt()).setPrecLevel(message.readUnsignedByte()).build());
message.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
break;
case OFPMBTEXPERIMENTER:
// TODO: Finish meter band experimenter deserialization
final long expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
message.readerIndex(itemStartIndex);
final OFDeserializer<Experimenter> deserializer = registry.getDeserializer(new ExperimenterIdDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, Experimenter.class));
subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, false, true)).build()).setBandType(deserializer.deserialize(message));
break;
default:
}
subItems.add(subItemBuilder.build());
}
items.add(itemBuilder.setKey(new MeterConfigStatsKey(itemBuilder.getMeterId())).setMeterBandHeaders(new MeterBandHeadersBuilder().setMeterBandHeader(subItems).build()).build());
}
return builder.setMeterConfigStats(items).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats in project openflowplugin by opendaylight.
the class MeterConfigStatsResponseConvertor method convert.
@Override
public List<MeterConfigStats> convert(List<MeterConfig> source, VersionConvertorData data) {
List<MeterConfigStats> listMeterConfigStats = new ArrayList<>();
for (MeterConfig meterConfig : source) {
MeterConfigStatsBuilder meterConfigStatsBuilder = new MeterConfigStatsBuilder();
meterConfigStatsBuilder.setMeterId(new MeterId(meterConfig.getMeterId().getValue()));
meterConfigStatsBuilder.setKey(new MeterConfigStatsKey(meterConfigStatsBuilder.getMeterId()));
MeterBandHeadersBuilder meterBandHeadersBuilder = new MeterBandHeadersBuilder();
List<Bands> bands = meterConfig.getBands();
MeterFlags meterFlags = new MeterFlags(meterConfig.getFlags().isOFPMFBURST(), meterConfig.getFlags().isOFPMFKBPS(), meterConfig.getFlags().isOFPMFPKTPS(), meterConfig.getFlags().isOFPMFSTATS());
meterConfigStatsBuilder.setFlags(meterFlags);
List<MeterBandHeader> listBandHeaders = new ArrayList<>();
int bandKey = 0;
for (Bands band : bands) {
MeterBandHeaderBuilder meterBandHeaderBuilder = new MeterBandHeaderBuilder();
if (band.getMeterBand() instanceof MeterBandDropCase) {
MeterBandDropCase dropCaseBand = (MeterBandDropCase) band.getMeterBand();
MeterBandDrop dropBand = dropCaseBand.getMeterBandDrop();
DropBuilder dropBuilder = new DropBuilder();
dropBuilder.setDropBurstSize(dropBand.getBurstSize());
dropBuilder.setDropRate(dropBand.getRate());
meterBandHeaderBuilder.setBandType(dropBuilder.build());
meterBandHeaderBuilder.setBandBurstSize(dropBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(dropBand.getRate());
BandId bandId = new BandId((long) bandKey);
meterBandHeaderBuilder.setKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
MeterBandTypesBuilder meterBandTypesBuilder = new MeterBandTypesBuilder();
meterBandTypesBuilder.setFlags(new MeterBandType(true, false, false));
meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesBuilder.build());
listBandHeaders.add(meterBandHeaderBuilder.build());
} else if (band.getMeterBand() instanceof MeterBandDscpRemarkCase) {
MeterBandDscpRemarkCase dscpRemarkCaseBand = (MeterBandDscpRemarkCase) band.getMeterBand();
MeterBandDscpRemark dscpRemarkBand = dscpRemarkCaseBand.getMeterBandDscpRemark();
DscpRemarkBuilder dscpRemarkBuilder = new DscpRemarkBuilder();
dscpRemarkBuilder.setDscpRemarkBurstSize(dscpRemarkBand.getBurstSize());
dscpRemarkBuilder.setDscpRemarkRate(dscpRemarkBand.getRate());
dscpRemarkBuilder.setPrecLevel(dscpRemarkBand.getPrecLevel());
meterBandHeaderBuilder.setBandType(dscpRemarkBuilder.build());
meterBandHeaderBuilder.setBandBurstSize(dscpRemarkBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(dscpRemarkBand.getRate());
BandId bandId = new BandId((long) bandKey);
meterBandHeaderBuilder.setKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
MeterBandTypesBuilder meterBandTypesBuilder = new MeterBandTypesBuilder();
meterBandTypesBuilder.setFlags(new MeterBandType(false, true, false));
meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesBuilder.build());
listBandHeaders.add(meterBandHeaderBuilder.build());
} else if (band.getMeterBand() instanceof MeterBandExperimenterCase) {
MeterBandExperimenterCase experimenterCaseBand = (MeterBandExperimenterCase) band.getMeterBand();
MeterBandExperimenter experimenterBand = experimenterCaseBand.getMeterBandExperimenter();
ExperimenterBuilder experimenterBuilder = new ExperimenterBuilder();
experimenterBuilder.setExperimenterBurstSize(experimenterBand.getBurstSize());
experimenterBuilder.setExperimenterRate(experimenterBand.getRate());
meterBandHeaderBuilder.setBandType(experimenterBuilder.build());
meterBandHeaderBuilder.setBandBurstSize(experimenterBand.getBurstSize());
meterBandHeaderBuilder.setBandRate(experimenterBand.getRate());
BandId bandId = new BandId((long) bandKey);
meterBandHeaderBuilder.setKey(new MeterBandHeaderKey(bandId));
meterBandHeaderBuilder.setBandId(bandId);
MeterBandTypesBuilder meterBandTypesBuilder = new MeterBandTypesBuilder();
meterBandTypesBuilder.setFlags(new MeterBandType(false, false, true));
meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesBuilder.build());
listBandHeaders.add(meterBandHeaderBuilder.build());
}
bandKey++;
}
meterBandHeadersBuilder.setMeterBandHeader(listBandHeaders);
meterConfigStatsBuilder.setMeterBandHeaders(meterBandHeadersBuilder.build());
listMeterConfigStats.add(meterConfigStatsBuilder.build());
}
return listMeterConfigStats;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorUtil method translateMeterConfig.
private static org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig translateMeterConfig(final MultipartReply msg, final VersionDatapathIdConvertorData data, final ConvertorExecutor convertorExecutor) {
MultipartReplyMeterConfigBuilder message = new MultipartReplyMeterConfigBuilder();
MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase) msg.getMultipartReplyBody();
MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig();
final Optional<List<MeterConfigStats>> meterConfigStatsList = convertorExecutor.convert(replyBody.getMeterConfig(), data);
message.setMeterConfigStats(meterConfigStatsList.orElse(Collections.emptyList()));
return message.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats in project openflowplugin by opendaylight.
the class MeterConfigStatsResponseConvertorTest method testToSALMeterConfigList.
@Test
public /**
* Test of basic mapping functionality of {@link MeterConfigStatsResponseConvertor#convert(java.util.List)} }
*/
void testToSALMeterConfigList() {
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
Optional<List<MeterConfigStats>> meterConfigsOptional = convertorManager.convert(createMeterConfigList(), new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MeterConfigStats> meterConfigs = meterConfigsOptional.orElse(Collections.emptyList());
assertEquals(PRESET_COUNT, meterConfigs.size());
int cnt = 0;
for (MeterConfigStats meterConfigStats : meterConfigs) {
assertEquals(new Long(cnt), meterConfigStats.getMeterId().getValue());
assertTrue(meterConfigStats.getFlags().isMeterBurst());
assertFalse(meterConfigStats.getFlags().isMeterKbps());
assertTrue(meterConfigStats.getFlags().isMeterPktps());
assertFalse(meterConfigStats.getFlags().isMeterStats());
cnt++;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats in project openflowplugin by opendaylight.
the class AllMeterConfigStatsService method transformToNotification.
@Override
public MeterConfigStatsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
MeterConfigStatsUpdatedBuilder message = new MeterConfigStatsUpdatedBuilder();
message.setId(getDeviceInfo().getNodeId());
message.setMoreReplies(Boolean.FALSE);
message.setTransactionId(emulatedTxId);
message.setMeterConfigStats(new ArrayList<>());
for (MultipartReply mpReply : result) {
MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase) mpReply.getMultipartReplyBody();
MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig();
final Optional<List<MeterConfigStats>> meterConfigStatsList = convertorExecutor.convert(replyBody.getMeterConfig(), data);
meterConfigStatsList.ifPresent(meterConfigStats -> message.getMeterConfigStats().addAll(meterConfigStats));
}
return message.build();
}
Aggregations