use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage in project openflowplugin by opendaylight.
the class MeterMessageDeserializer method deserialize.
@Override
public MeterMessage deserialize(ByteBuf message) {
final MeterMessageBuilder builder = new MeterMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCommand(MeterModCommand.forValue(message.readUnsignedShort())).setFlags(readMeterFlags(message)).setMeterId(new MeterId(message.readUnsignedInt()));
final List<MeterBandHeader> bands = new ArrayList<>();
while (message.readableBytes() > 0) {
final MeterBandHeaderBuilder bandBuilder = new MeterBandHeaderBuilder();
final int bandStartIndex = message.readerIndex();
final int bandType = message.readUnsignedShort();
switch(bandType) {
case OFPMBTDROP:
{
bandBuilder.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:
{
bandBuilder.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
long expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
message.readerIndex(bandStartIndex);
OFDeserializer<Experimenter> deserializer = registry.getDeserializer(new ExperimenterIdDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, Experimenter.class));
bandBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, false, true)).build()).setBandType(deserializer.deserialize(message));
break;
}
default:
}
bands.add(bandBuilder.build());
}
return builder.setMeterBandHeaders(new MeterBandHeadersBuilder().setMeterBandHeader(bands).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage in project openflowplugin by opendaylight.
the class SingleLayerMeterServiceTest method buildRequest.
@Test
public void buildRequest() throws Exception {
final AddMeterInput input = new AddMeterInputBuilder().setMeterId(new MeterId(METER_ID)).build();
final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
assertEquals(MeterMessage.class, ofHeader.getImplementedInterface());
final MeterMessage result = MeterMessage.class.cast(ofHeader);
assertEquals(MeterModCommand.OFPMCADD, result.getCommand());
assertEquals(METER_ID, result.getMeterId().getValue().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage in project openflowplugin by opendaylight.
the class MeterMessageSerializer method serialize.
@Override
public void serialize(final MeterMessage message, final ByteBuf outBuffer) {
final int index = outBuffer.writerIndex();
super.serialize(message, outBuffer);
outBuffer.writeShort(message.getCommand().getIntValue());
outBuffer.writeShort(createMeterFlagsBitMask(MoreObjects.firstNonNull(message.getFlags(), new MeterFlags(false, false, true, false))));
outBuffer.writeInt(message.getMeterId().getValue().intValue());
serializeBands(message.getMeterBandHeaders(), outBuffer);
outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage in project openflowplugin by opendaylight.
the class MeterMessageDeserializerTest method deserialize.
@Test
public void deserialize() throws Exception {
// Message type
buffer.writeByte(TYPE);
buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
buffer.writeInt(XID);
buffer.writeShort(COMMAND.getIntValue());
buffer.writeShort(ByteBufUtils.fillBitMask(0, IS_KBPS, IS_PKTPS, IS_BURST, IS_STATS));
buffer.writeInt(ID);
// Drop band
buffer.writeShort(1);
buffer.writeInt(DROP_RATE);
buffer.writeInt(DROP_BURST);
buffer.writeZero(PADDING_IN_METER_BAND_DROP_HEADER);
// Dscp remark band
buffer.writeShort(2);
buffer.writeInt(DSCP_RATE);
buffer.writeInt(DSCP_BURST);
buffer.writeByte(DSCP_PREC);
buffer.writeZero(PADDING_IN_METER_BAND_DSCP_HEADER);
final MeterMessage message = (MeterMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
assertEquals(message.getXid().intValue(), XID);
assertEquals(message.getCommand().getIntValue(), COMMAND.getIntValue());
assertEquals(message.getFlags().isMeterBurst(), IS_BURST);
assertEquals(message.getFlags().isMeterKbps(), IS_KBPS);
assertEquals(message.getFlags().isMeterPktps(), IS_PKTPS);
assertEquals(message.getFlags().isMeterStats(), IS_STATS);
assertEquals(message.getMeterId().getValue().intValue(), ID);
final List<MeterBandHeader> meterBandHeader = message.getMeterBandHeaders().getMeterBandHeader();
assertEquals(meterBandHeader.size(), 2);
// Drop band
final MeterBandHeader dropHeader = meterBandHeader.get(0);
assertEquals(Drop.class, dropHeader.getBandType().getImplementedInterface());
assertTrue(dropHeader.getMeterBandTypes().getFlags().isOfpmbtDrop());
final Drop drop = Drop.class.cast(dropHeader.getBandType());
assertEquals(DROP_RATE, drop.getDropRate().intValue());
assertEquals(DROP_BURST, drop.getDropBurstSize().intValue());
// Dscp band
final MeterBandHeader dscpHeader = meterBandHeader.get(1);
assertEquals(DscpRemark.class, dscpHeader.getBandType().getImplementedInterface());
assertTrue(dscpHeader.getMeterBandTypes().getFlags().isOfpmbtDscpRemark());
final DscpRemark dscpRemark = DscpRemark.class.cast(dscpHeader.getBandType());
assertEquals(DSCP_RATE, dscpRemark.getDscpRemarkRate().intValue());
assertEquals(DSCP_BURST, dscpRemark.getDscpRemarkBurstSize().intValue());
assertEquals(buffer.readableBytes(), 0);
}
Aggregations