use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats 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.MeterStats in project openflowplugin by opendaylight.
the class MeterDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyMeterCase MeterCase = mock(MultipartReplyMeterCase.class);
final MultipartReplyMeter meter = mock(MultipartReplyMeter.class);
final MeterStats meterStat = new MeterStatsBuilder().setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId(METER_NO)).setByteInCount(BigInteger.ONE).setPacketInCount(BigInteger.ONE).setDurationSec(1L).setDurationNsec(1L).setFlowCount(0L).setMeterBandStats(Collections.emptyList()).build();
final List<MeterStats> meterStats = Collections.singletonList(meterStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(meter.getMeterStats()).thenReturn(meterStats);
when(MeterCase.getMultipartReplyMeter()).thenReturn(meter);
when(reply.getMultipartReplyBody()).thenReturn(MeterCase);
final GetMeterStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getMeterStats().size() > 0);
final org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats stats = output.getMeterStats().get(0);
assertEquals(stats.getMeterId().getValue(), METER_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class OpenflowpluginStatsTestCommandProvider method _meterStats.
public void _meterStats(CommandInterpreter ci) {
int meterCount = 0;
int meterStatsCount = 0;
NodeMeterStatistics data = null;
List<Node> nodes = getNodes();
for (Node node2 : nodes) {
NodeKey nodeKey = node2.getKey();
InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
if (node != null) {
if (node.getMeter() != null) {
List<Meter> meters = node.getMeter();
for (Meter meter2 : meters) {
meterCount++;
MeterKey meterKey = meter2.getKey();
InstanceIdentifier<Meter> meterRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Meter.class, meterKey);
Meter meter = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, meterRef);
if (meter != null) {
data = meter.getAugmentation(NodeMeterStatistics.class);
if (null != data) {
meterStatsCount++;
}
}
}
}
}
}
if (meterCount == meterStatsCount) {
LOG.debug("---------------------------meterStats - Success-------------------------------------");
} else {
LOG.debug("----------------------------meterStats - Failed-------------------------------------");
LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MeterStatsResponseConvertorTest method testToSALMeterStatsList.
@Test
public /**
* Test of basic mapping functionality of {@link MeterStatsResponseConvertor#convert(java.util.List)}
*/
void testToSALMeterStatsList() {
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
Optional<List<MeterStats>> meterStatsListOptional = convertorManager.convert(createMeterStatsLit(), new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MeterStats> meterStatsList = meterStatsListOptional.orElse(Collections.emptyList());
assertEquals(PRESET_COUNT, meterStatsList.size());
int cnt = 0;
for (MeterStats meterStats : meterStatsList) {
assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId((long) cnt)).getMeterId(), meterStats.getKey().getMeterId());
assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
assertEquals(new Long(1000 * cnt), meterStats.getDuration().getNanosecond().getValue());
assertEquals(new Long(10 * cnt), meterStats.getDuration().getSecond().getValue());
assertEquals(new Long(cnt), meterStats.getFlowCount().getValue());
assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
assertEquals(PRESET_COUNT, meterStats.getMeterBandStats().getBandStat().size());
int bandStatCount = 0;
for (BandStat bandStat : meterStats.getMeterBandStats().getBandStat()) {
assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getByteBandCount().getValue());
assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getPacketBandCount().getValue());
bandStatCount++;
}
assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId((long) cnt)).getMeterId(), meterStats.getMeterId());
assertEquals(BigInteger.valueOf(cnt), meterStats.getPacketInCount().getValue());
cnt++;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method serializeMeterBody.
private void serializeMeterBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
MultipartReplyMeterCase meterCase = (MultipartReplyMeterCase) body;
MultipartReplyMeter meter = meterCase.getMultipartReplyMeter();
for (MeterStats meterStats : meter.getMeterStats()) {
ByteBuf meterStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
meterStatsBuff.writeInt(meterStats.getMeterId().getValue().intValue());
meterStatsBuff.writeInt(EncodeConstants.EMPTY_LENGTH);
meterStatsBuff.writeZero(METER_PADDING);
meterStatsBuff.writeInt(meterStats.getFlowCount().intValue());
meterStatsBuff.writeLong(meterStats.getPacketInCount().longValue());
meterStatsBuff.writeLong(meterStats.getByteInCount().longValue());
meterStatsBuff.writeInt(meterStats.getDurationSec().intValue());
meterStatsBuff.writeInt(meterStats.getDurationNsec().intValue());
for (MeterBandStats meterBandStats : meterStats.getMeterBandStats()) {
meterStatsBuff.writeLong(meterBandStats.getPacketBandCount().longValue());
meterStatsBuff.writeLong(meterBandStats.getByteBandCount().longValue());
}
meterStatsBuff.setInt(METER_LENGTH_INDEX, meterStatsBuff.readableBytes());
outBuffer.writeBytes(meterStatsBuff);
}
}
Aggregations