use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder 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.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder 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.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder in project openflowplugin by opendaylight.
the class OpendaylightMeterStatisticsServiceImplTest method testGetAllMeterConfigStatistics.
@Test
public void testGetAllMeterConfigStatistics() throws Exception {
GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder().setNode(createNodeRef("unitProt:123"));
rpcResult = RpcResultBuilder.<Object>success(Collections.singletonList(new MultipartReplyMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setMultipartReplyBody(new MultipartReplyMeterConfigCaseBuilder().setMultipartReplyMeterConfig(new MultipartReplyMeterConfigBuilder().setMeterConfig(Collections.singletonList(new MeterConfigBuilder().setFlags(new MeterFlags(true, false, false, false)).setMeterId(METER_ID).setBands(Collections.singletonList(new BandsBuilder().setMeterBand(new MeterBandDropCaseBuilder().setMeterBandDrop(new MeterBandDropBuilder().setBurstSize(61L).setRate(62L).setType(MeterBandType.OFPMBTDROP).build()).build()).build())).build())).build()).build()).build())).build();
final Future<RpcResult<GetAllMeterConfigStatisticsOutput>> resultFuture = meterStatisticsService.getAllMeterConfigStatistics(input.build());
Assert.assertTrue(resultFuture.isDone());
final RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = resultFuture.get();
Assert.assertTrue(rpcResult.isSuccessful());
Assert.assertEquals(MultipartType.OFPMPMETERCONFIG, requestInput.getValue().getType());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder 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));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder 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();
}
Aggregations