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