use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark in project openflowplugin by opendaylight.
the class MeterMessageSerializer method serializeBands.
private void serializeBands(final MeterBandHeaders meterBandHeaders, final ByteBuf outBuffer) {
if (Objects.nonNull(meterBandHeaders) && Objects.nonNull(meterBandHeaders.getMeterBandHeader())) {
meterBandHeaders.getMeterBandHeader().forEach(meterBandHeader -> Optional.ofNullable(meterBandHeader.getMeterBandTypes()).flatMap(m -> Optional.ofNullable(m.getFlags())).ifPresent(flags -> Optional.ofNullable(meterBandHeader.getBandType()).ifPresent(type -> {
if (flags.isOfpmbtDrop()) {
final Drop band = Drop.class.cast(type);
outBuffer.writeShort(MeterBandType.OFPMBTDROP.getIntValue());
outBuffer.writeShort(LENGTH_OF_METER_BANDS);
outBuffer.writeInt(band.getDropRate().intValue());
outBuffer.writeInt(band.getDropBurstSize().intValue());
outBuffer.writeZero(PADDING_IN_METER_BAND_DROP);
} else if (flags.isOfpmbtDscpRemark()) {
final DscpRemark band = DscpRemark.class.cast(type);
outBuffer.writeShort(MeterBandType.OFPMBTDSCPREMARK.getIntValue());
outBuffer.writeShort(LENGTH_OF_METER_BANDS);
outBuffer.writeInt(band.getDscpRemarkRate().intValue());
outBuffer.writeInt(band.getDscpRemarkBurstSize().intValue());
outBuffer.writeByte(band.getPrecLevel());
outBuffer.writeZero(PADDING_IN_METER_BAND_DSCP_REMARK);
} else if (flags.isOfpmbtExperimenter()) {
final Experimenter band = Experimenter.class.cast(type);
// TODO: finish experimenter serialization
final ExperimenterIdSerializerKey<Experimenter> key = new ExperimenterIdSerializerKey<>(EncodeConstants.OF13_VERSION_ID, band.getExperimenter(), (Class<Experimenter>) type.getImplementedInterface());
try {
final OFSerializer<Experimenter> serializer = registry.getSerializer(key);
serializer.serialize(band, outBuffer);
} catch (final IllegalStateException e) {
LOG.warn("Serializer for key: {} wasn't found, exception {}", key, e);
}
}
})));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark in project openflowplugin by opendaylight.
the class MeterConvertor method getBandsFromSAL.
private static void getBandsFromSAL(MeterBandHeaders meterBandHeaders, List<Bands> bands) {
for (MeterBandHeader meterBandHeader : meterBandHeaders.getMeterBandHeader()) {
// The band types :drop,DSCP_Remark or experimenter.
if (null != meterBandHeader.getMeterBandTypes() && null != meterBandHeader.getMeterBandTypes().getFlags()) {
if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDrop()) {
if (meterBandHeader.getBandType() != null) {
MeterBandDropBuilder meterBandDropBuilder = new MeterBandDropBuilder();
meterBandDropBuilder.setType(MeterBandType.OFPMBTDROP);
Drop drop = (Drop) meterBandHeader.getBandType();
meterBandDropBuilder.setBurstSize(drop.getDropBurstSize());
meterBandDropBuilder.setRate(drop.getDropRate());
MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
dropCaseBuilder.setMeterBandDrop(meterBandDropBuilder.build());
MeterBand meterBandItem = dropCaseBuilder.build();
BandsBuilder bandsB = new BandsBuilder();
bandsB.setMeterBand(meterBandItem);
// Bands list
bands.add(bandsB.build());
} else {
logBandTypeMissing(MeterBandType.OFPMBTDROP);
}
} else if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDscpRemark()) {
if (meterBandHeader.getBandType() != null) {
MeterBandDscpRemarkBuilder meterBandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
meterBandDscpRemarkBuilder.setType(MeterBandType.OFPMBTDSCPREMARK);
DscpRemark dscpRemark = (DscpRemark) meterBandHeader.getBandType();
meterBandDscpRemarkBuilder.setBurstSize(dscpRemark.getDscpRemarkBurstSize());
meterBandDscpRemarkBuilder.setRate(dscpRemark.getDscpRemarkRate());
meterBandDscpRemarkBuilder.setPrecLevel(dscpRemark.getPrecLevel());
MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
dscpCaseBuilder.setMeterBandDscpRemark(meterBandDscpRemarkBuilder.build());
MeterBand meterBandItem = dscpCaseBuilder.build();
BandsBuilder bandsB = new BandsBuilder();
bandsB.setMeterBand(meterBandItem);
// Bands list
bands.add(bandsB.build());
} else {
logBandTypeMissing(MeterBandType.OFPMBTDSCPREMARK);
}
} else if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtExperimenter()) {
if (meterBandHeader.getBandType() != null) {
MeterBandExperimenterBuilder meterBandExperimenterBuilder = new MeterBandExperimenterBuilder();
meterBandExperimenterBuilder.setType(MeterBandType.OFPMBTEXPERIMENTER);
Experimenter experimenter = (Experimenter) meterBandHeader.getBandType();
meterBandExperimenterBuilder.setBurstSize(experimenter.getExperimenterBurstSize());
meterBandExperimenterBuilder.setRate(experimenter.getExperimenterRate());
ExperimenterIdMeterBandBuilder expBuilder = new ExperimenterIdMeterBandBuilder();
expBuilder.setExperimenter(new ExperimenterId(experimenter.getExperimenter()));
meterBandExperimenterBuilder.addAugmentation(ExperimenterIdMeterBand.class, expBuilder.build());
// TODO - implement / finish experimenter meter band translation
MeterBandExperimenterCaseBuilder experimenterCaseBuilder = new MeterBandExperimenterCaseBuilder();
experimenterCaseBuilder.setMeterBandExperimenter(meterBandExperimenterBuilder.build());
MeterBand meterBandItem = experimenterCaseBuilder.build();
BandsBuilder bandsB = new BandsBuilder();
bandsB.setMeterBand(meterBandItem);
// Bands list
bands.add(bandsB.build());
} else {
logBandTypeMissing(MeterBandType.OFPMBTEXPERIMENTER);
}
}
} else {
LOG.error("Invalid meter band data found.");
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark in project openflowplugin by opendaylight.
the class MultipartReplyMeterConfigDeserializerTest method deserializeDscp.
@Test
public void deserializeDscp() throws Exception {
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
writeCommonAtributes(buffer);
buffer.writeShort(OFPMBTDSCP);
buffer.writeShort(SUB_ITEM);
buffer.writeInt(DSCP_REMARK_RATE);
buffer.writeInt(DSCP_REMARK_BURST_SIZE);
buffer.writeByte(PREC_LEVEL);
buffer.writeZero(PADDING_IN_METER_BAND_DSCP_HEADER);
final MultipartReplyMeterConfig reply = (MultipartReplyMeterConfig) deserializeMultipart(buffer);
final DscpRemark dscpRemark = (DscpRemark) reply.getMeterConfigStats().get(0).getMeterBandHeaders().getMeterBandHeader().get(0).getBandType();
assertEquals(DSCP_REMARK_RATE, dscpRemark.getDscpRemarkRate().intValue());
assertEquals(DSCP_REMARK_BURST_SIZE, dscpRemark.getDscpRemarkBurstSize().intValue());
assertEquals(PREC_LEVEL, dscpRemark.getPrecLevel().byteValue());
}
Aggregations