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));
}
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();
}
Aggregations