use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats 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.MeterStats 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.MeterStats in project openflowplugin by opendaylight.
the class MultipartReplyMeterStatsDeserializerTest method deserialize.
@Test
public void deserialize() throws Exception {
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
buffer.writeInt(METER_ID);
buffer.writeShort(ITEM_LENGTH);
buffer.writeZero(PADDING_IN_METER_STATS_HEADER);
buffer.writeInt(FLOW_COUNT);
buffer.writeLong(PACKET_IN_COUNT);
buffer.writeLong(BYTE_IN_COUNT);
buffer.writeInt(SECOND);
buffer.writeInt(NANOSECOND);
buffer.writeLong(PACKET_BAND_COUNT);
buffer.writeLong(BYTE_BAND_COUNT);
final MultipartReplyMeterStats reply = (MultipartReplyMeterStats) deserializeMultipart(buffer);
final MeterStats meterStats = reply.getMeterStats().get(0);
assertEquals(METER_ID, meterStats.getMeterId().getValue().intValue());
assertEquals(FLOW_COUNT, meterStats.getFlowCount().getValue().intValue());
assertEquals(PACKET_IN_COUNT, meterStats.getPacketInCount().getValue().longValue());
assertEquals(BYTE_IN_COUNT, meterStats.getByteInCount().getValue().intValue());
assertEquals(SECOND, meterStats.getDuration().getSecond().getValue().intValue());
assertEquals(NANOSECOND, meterStats.getDuration().getNanosecond().getValue().intValue());
assertEquals(PACKET_BAND_COUNT, meterStats.getMeterBandStats().getBandStat().get(0).getPacketBandCount().getValue().longValue());
assertEquals(BYTE_BAND_COUNT, meterStats.getMeterBandStats().getBandStat().get(0).getByteBandCount().getValue().longValue());
assertEquals(0, buffer.readableBytes());
}
Aggregations