use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMeterStatsDeserializer method deserialize.
@Override
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyMeterStatsBuilder builder = new MultipartReplyMeterStatsBuilder();
final List<MeterStats> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final MeterStatsBuilder itemBuilder = new MeterStatsBuilder().setMeterId(new MeterId(message.readUnsignedInt()));
final int itemLength = message.readUnsignedShort();
message.skipBytes(PADDING_IN_METER_STATS_HEADER);
itemBuilder.setKey(new MeterStatsKey(itemBuilder.getMeterId())).setFlowCount(new Counter32(message.readUnsignedInt()));
final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(packetCount);
final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(byteCount);
itemBuilder.setPacketInCount(new Counter64(new BigInteger(1, packetCount))).setByteInCount(new Counter64(new BigInteger(1, byteCount))).setDuration(new DurationBuilder().setSecond(new Counter32(message.readUnsignedInt())).setNanosecond(new Counter32(message.readUnsignedInt())).build());
final List<BandStat> subItems = new ArrayList<>();
int actualLength = METER_BODY_LENGTH;
long bandKey = 0;
while (actualLength < itemLength) {
final byte[] packetCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(packetCountB);
final byte[] byteCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
message.readBytes(byteCountB);
subItems.add(new BandStatBuilder().setBandId(new BandId(bandKey)).setKey(new BandStatKey(new BandId(bandKey))).setPacketBandCount(new Counter64(new BigInteger(1, packetCountB))).setByteBandCount(new Counter64(new BigInteger(1, byteCountB))).build());
bandKey++;
actualLength += METER_BAND_STATS_LENGTH;
}
items.add(itemBuilder.setMeterBandStats(new MeterBandStatsBuilder().setBandStat(subItems).build()).build());
}
return builder.setMeterStats(items).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testGatherStatistics_meter.
@Test
public void testGatherStatistics_meter() throws Exception {
final MultipartType type = MultipartType.OFPMPMETER;
final long meterIdValue = 19L;
final MeterBandStatsBuilder meterBandStatsBld = new MeterBandStatsBuilder().setByteBandCount(BigInteger.valueOf(91L)).setPacketBandCount(BigInteger.valueOf(92L));
final MeterStatsBuilder meterStatsBld = new MeterStatsBuilder().setMeterId(new MeterId(meterIdValue)).setByteInCount(BigInteger.valueOf(111L)).setDurationSec(112L).setDurationNsec(113L).setFlowCount(114L).setPacketInCount(BigInteger.valueOf(115L)).setMeterBandStats(Lists.newArrayList(meterBandStatsBld.build()));
final MultipartReplyMeterBuilder mpReplyMeterBld = new MultipartReplyMeterBuilder();
mpReplyMeterBld.setMeterStats(Lists.newArrayList(meterStatsBld.build()));
final MultipartReplyMeterCaseBuilder mpReplyMeterCaseBld = new MultipartReplyMeterCaseBuilder();
mpReplyMeterCaseBld.setMultipartReplyMeter(mpReplyMeterBld.build());
final MultipartReply meterStatsUpdated = assembleMPReplyMessage(type, mpReplyMeterCaseBld.build());
final List<MultipartReply> statsData = Collections.singletonList(meterStatsUpdated);
fireAndCheck(type, statsData);
final InstanceIdentifier<MeterStatistics> meterPath = dummyNodePath.augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(meterIdValue))).augmentation(NodeMeterStatistics.class).child(MeterStatistics.class);
verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(meterPath), Matchers.any(MeterStatistics.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method createMeterBandStats.
private static List<MeterBandStats> createMeterBandStats() {
MeterBandStatsBuilder builder = new MeterBandStatsBuilder();
builder.setPacketBandCount(BigInteger.valueOf(1L));
builder.setByteBandCount(BigInteger.valueOf(1L));
List<MeterBandStats> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder 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.MeterBandStatsBuilder 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);
}
Aggregations