use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setMeter.
private static MultipartReplyMeterCase setMeter(final ByteBuf input) {
MultipartReplyMeterCaseBuilder caseBuilder = new MultipartReplyMeterCaseBuilder();
MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder();
List<MeterStats> meterStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
final int meterStatsBodyLength = input.readUnsignedShort();
input.skipBytes(PADDING_IN_METER_STATS_HEADER);
meterStatsBuilder.setFlowCount(input.readUnsignedInt());
byte[] packetInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetInCount);
meterStatsBuilder.setPacketInCount(new BigInteger(1, packetInCount));
byte[] byteInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteInCount);
meterStatsBuilder.setByteInCount(new BigInteger(1, byteInCount));
meterStatsBuilder.setDurationSec(input.readUnsignedInt());
meterStatsBuilder.setDurationNsec(input.readUnsignedInt());
int actualLength = METER_BODY_LENGTH;
List<MeterBandStats> meterBandStatsList = new ArrayList<>();
while (actualLength < meterStatsBodyLength) {
MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
byte[] packetBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetBandCount);
meterBandStatsBuilder.setPacketBandCount(new BigInteger(1, packetBandCount));
byte[] byteBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteBandCount);
meterBandStatsBuilder.setByteBandCount(new BigInteger(1, byteBandCount));
meterBandStatsList.add(meterBandStatsBuilder.build());
actualLength += METER_BAND_STATS_LENGTH;
}
meterStatsBuilder.setMeterBandStats(meterBandStatsList);
meterStatsList.add(meterStatsBuilder.build());
}
builder.setMeterStats(meterStatsList);
caseBuilder.setMultipartReplyMeter(builder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder in project openflowplugin by opendaylight.
the class MeterDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MeterStats meterStat = new MeterStatsBuilder().setMeterId(new MeterId(METER_NO)).setByteInCount(new Counter64(BigInteger.ONE)).setPacketInCount(new Counter64(BigInteger.ONE)).setDuration(new DurationBuilder().setSecond(new Counter32(1L)).setNanosecond(new Counter32(1L)).build()).setFlowCount(new Counter32(0L)).setMeterBandStats(new MeterBandStatsBuilder().build()).build();
final MultipartReply reply = new MultipartReplyBuilder().setMultipartReplyBody(new MultipartReplyMeterStatsBuilder().setMeterStats(Collections.singletonList(meterStat)).build()).build();
final List<MultipartReply> input = Collections.singletonList(reply);
final GetMeterStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getMeterStats().size() > 0);
final MeterStats stats = output.getMeterStats().get(0);
assertEquals(stats.getMeterId().getValue(), METER_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder in project openflowplugin by opendaylight.
the class MeterStatsResponseConvertor method convert.
@Override
public List<MeterStats> convert(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats> source, VersionConvertorData data) {
List<MeterStats> convertedSALMeters = new ArrayList<>();
for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats meterStats : source) {
// Convert MeterStats message from library to MD SAL defined MeterStats
MeterStatsBuilder salMeterStats = new MeterStatsBuilder();
salMeterStats.setByteInCount(new Counter64(meterStats.getByteInCount()));
DurationBuilder time = new DurationBuilder();
time.setSecond(new Counter32(meterStats.getDurationSec()));
time.setNanosecond(new Counter32(meterStats.getDurationNsec()));
salMeterStats.setDuration(time.build());
salMeterStats.setFlowCount(new Counter32(meterStats.getFlowCount()));
salMeterStats.setMeterId(new MeterId(meterStats.getMeterId().getValue()));
salMeterStats.setPacketInCount(new Counter64(meterStats.getPacketInCount()));
salMeterStats.setKey(new MeterStatsKey(salMeterStats.getMeterId()));
List<MeterBandStats> allMeterBandStats = meterStats.getMeterBandStats();
MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
List<BandStat> listAllBandStats = new ArrayList<>();
int bandKey = 0;
for (MeterBandStats meterBandStats : allMeterBandStats) {
BandStatBuilder bandStatBuilder = new BandStatBuilder();
bandStatBuilder.setByteBandCount(new Counter64(meterBandStats.getByteBandCount()));
bandStatBuilder.setPacketBandCount(new Counter64(meterBandStats.getPacketBandCount()));
BandId bandId = new BandId((long) bandKey);
bandStatBuilder.setKey(new BandStatKey(bandId));
bandStatBuilder.setBandId(bandId);
bandKey++;
listAllBandStats.add(bandStatBuilder.build());
}
meterBandStatsBuilder.setBandStat(listAllBandStats);
salMeterStats.setMeterBandStats(meterBandStatsBuilder.build());
convertedSALMeters.add(salMeterStats.build());
}
return convertedSALMeters;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder in project openflowplugin by opendaylight.
the class MeterStatsResponseConvertorTest method createMeterStatsLit.
private static List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats> createMeterStatsLit() {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats> allMeterStats = new ArrayList<>();
MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
for (int i = 0; i < PRESET_COUNT; i++) {
meterStatsBuilder.setByteInCount(BigInteger.valueOf(i));
meterStatsBuilder.setDurationNsec((long) 1000 * i);
meterStatsBuilder.setDurationSec((long) 10 * i);
meterStatsBuilder.setFlowCount((long) i);
MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
List<MeterBandStats> meterBandStatses = new ArrayList<>();
for (int j = 0; j < PRESET_COUNT; j++) {
meterBandStatsBuilder.setByteBandCount(BigInteger.valueOf(j));
meterBandStatsBuilder.setPacketBandCount(BigInteger.valueOf(j));
meterBandStatses.add(meterBandStatsBuilder.build());
}
meterStatsBuilder.setMeterBandStats(meterBandStatses);
meterStatsBuilder.setMeterId(new MeterId((long) i));
meterStatsBuilder.setPacketInCount(BigInteger.valueOf(i));
allMeterStats.add(meterStatsBuilder.build());
}
return allMeterStats;
}
Aggregations