use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method serializeMeterFeaturesBody.
private void serializeMeterFeaturesBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
MultipartReplyMeterFeaturesCase meterFeaturesCase = (MultipartReplyMeterFeaturesCase) body;
MultipartReplyMeterFeatures meterFeatures = meterFeaturesCase.getMultipartReplyMeterFeatures();
outBuffer.writeInt(meterFeatures.getMaxMeter().intValue());
writeBandTypes(meterFeatures.getBandTypes(), outBuffer);
writeMeterFlags(meterFeatures.getCapabilities(), outBuffer);
outBuffer.writeByte(meterFeatures.getMaxBands());
outBuffer.writeByte(meterFeatures.getMaxColor());
outBuffer.writeZero(METER_FEATURES_PADDING);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures in project openflowplugin by opendaylight.
the class MultipartRequestMeterFeaturesTest method test.
/**
* Tests {@link MultipartRequestInputFactory} - MeterFeatures case.
*/
@Test
public void test() throws Exception {
MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setType(MultipartType.OFPMPMETERFEATURES);
builder.setFlags(new MultipartRequestFlags(false));
MultipartRequestMeterFeaturesCaseBuilder caseBuilder = new MultipartRequestMeterFeaturesCaseBuilder();
MultipartRequestMeterFeaturesBuilder featuresBuilder = new MultipartRequestMeterFeaturesBuilder();
featuresBuilder.setEmpty(true);
caseBuilder.setMultipartRequestMeterFeatures(featuresBuilder.build());
builder.setMultipartRequestBody(caseBuilder.build());
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
multipartFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, (byte) 18, 16);
Assert.assertEquals("Wrong type", 11, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
// skip padding
out.skipBytes(4);
Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}
Aggregations