Search in sources :

Example 1 with BucketCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter in project openflowplugin by opendaylight.

the class GroupStatsResponseConvertor method toSALBuckets.

private Buckets toSALBuckets(List<BucketStats> bucketStats) {
    BucketsBuilder salBuckets = new BucketsBuilder();
    List<BucketCounter> allBucketStats = new ArrayList<>();
    int bucketKey = 0;
    for (BucketStats bucketStat : bucketStats) {
        BucketCounterBuilder bucketCounter = new BucketCounterBuilder();
        bucketCounter.setByteCount(new Counter64(bucketStat.getByteCount()));
        bucketCounter.setPacketCount(new Counter64(bucketStat.getPacketCount()));
        BucketId bucketId = new BucketId((long) bucketKey);
        bucketCounter.setKey(new BucketCounterKey(bucketId));
        bucketCounter.setBucketId(bucketId);
        bucketKey++;
        allBucketStats.add(bucketCounter.build());
    }
    salBuckets.setBucketCounter(allBucketStats);
    return salBuckets.build();
}
Also used : BucketCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) ArrayList(java.util.ArrayList) BucketCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterKey) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.BucketsBuilder) BucketCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterBuilder) BucketId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId) BucketStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats)

Example 2 with BucketCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter in project openflowplugin by opendaylight.

the class GroupStatsResponseConvertorTest method testGroupStatsWithBuckets.

/**
 * Test GroupStats with buckets conversion.
 */
@Test
public void testGroupStatsWithBuckets() {
    GroupStatsBuilder statsBuilder = new GroupStatsBuilder();
    statsBuilder.setByteCount(new BigInteger("12345"));
    statsBuilder.setDurationNsec(1000000L);
    statsBuilder.setDurationSec(5000L);
    statsBuilder.setGroupId(new GroupId(42L));
    statsBuilder.setPacketCount(new BigInteger("54321"));
    statsBuilder.setRefCount(24L);
    List<BucketStats> bucketStats = new ArrayList<>();
    BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();
    bucketStatsBuilder.setByteCount(new BigInteger("987"));
    bucketStatsBuilder.setPacketCount(new BigInteger("654"));
    bucketStats.add(bucketStatsBuilder.build());
    bucketStatsBuilder = new BucketStatsBuilder();
    bucketStatsBuilder.setByteCount(new BigInteger("123"));
    bucketStatsBuilder.setPacketCount(new BigInteger("456"));
    bucketStats.add(bucketStatsBuilder.build());
    statsBuilder.setBucketStats(bucketStats);
    List<GroupStats> groupStats = new ArrayList<>();
    groupStats.add(statsBuilder.build());
    Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats>> salGroupStatsOptional = convertorManager.convert(groupStats, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
    Assert.assertTrue("Group stats response convertor not found", salGroupStatsOptional.isPresent());
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats> salGroupStats = salGroupStatsOptional.get();
    Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size());
    org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stat = salGroupStats.get(0);
    Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue());
    Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue());
    Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue());
    Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue());
    Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue());
    Assert.assertEquals("Wrong bucket stats", 2, stat.getBuckets().getBucketCounter().size());
    List<BucketCounter> list = stat.getBuckets().getBucketCounter();
    Assert.assertEquals("Wrong bucket-id", 0, list.get(0).getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong bucket packet count", 654, list.get(0).getPacketCount().getValue().intValue());
    Assert.assertEquals("Wrong bucket byte count", 987, list.get(0).getByteCount().getValue().intValue());
    Assert.assertEquals("Wrong bucket-id", 1, list.get(1).getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong bucket packet count", 456, list.get(1).getPacketCount().getValue().intValue());
    Assert.assertEquals("Wrong bucket byte count", 123, list.get(1).getByteCount().getValue().intValue());
}
Also used : ArrayList(java.util.ArrayList) BucketStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStatsBuilder) GroupStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats) ArrayList(java.util.ArrayList) List(java.util.List) BucketStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats) BucketCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter) GroupStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 3 with BucketCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter in project openflowplugin by opendaylight.

the class MultipartReplyGroupStatsDeserializer method deserialize.

@Override
public MultipartReplyBody deserialize(ByteBuf message) {
    final MultipartReplyGroupStatsBuilder builder = new MultipartReplyGroupStatsBuilder();
    final List<GroupStats> items = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final int itemLength = message.readUnsignedShort();
        message.skipBytes(PADDING_IN_GROUP_HEADER_01);
        final GroupStatsBuilder itemBuilder = new GroupStatsBuilder().setGroupId(new GroupId(message.readUnsignedInt())).setRefCount(new Counter32(message.readUnsignedInt()));
        message.skipBytes(PADDING_IN_GROUP_HEADER_02);
        final byte[] packetCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        message.readBytes(packetCountg);
        final byte[] byteCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        message.readBytes(byteCountg);
        itemBuilder.setKey(new GroupStatsKey(itemBuilder.getGroupId())).setPacketCount(new Counter64(new BigInteger(1, packetCountg))).setByteCount(new Counter64(new BigInteger(1, byteCountg))).setDuration(new DurationBuilder().setSecond(new Counter32(message.readUnsignedInt())).setNanosecond(new Counter32(message.readUnsignedInt())).build());
        final List<BucketCounter> subItems = new ArrayList<>();
        int actualLength = GROUP_BODY_LENGTH;
        long bucketKey = 0;
        while (actualLength < itemLength) {
            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);
            subItems.add(new BucketCounterBuilder().setBucketId(new BucketId(bucketKey)).setKey(new BucketCounterKey(new BucketId(bucketKey))).setPacketCount(new Counter64(new BigInteger(1, packetCount))).setByteCount(new Counter64(new BigInteger(1, byteCount))).build());
            bucketKey++;
            actualLength += BUCKET_COUNTER_LENGTH;
        }
        items.add(itemBuilder.setBuckets(new BucketsBuilder().setBucketCounter(subItems).build()).build());
    }
    return builder.setGroupStats(items).build();
}
Also used : BucketCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter) ArrayList(java.util.ArrayList) BucketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.BucketsBuilder) MultipartReplyGroupStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStatsBuilder) GroupStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder) BucketId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId) MultipartReplyGroupStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStatsBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) GroupStatsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsKey) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) GroupStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats) BigInteger(java.math.BigInteger) BucketCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterKey) BucketCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterBuilder) DurationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.DurationBuilder)

Aggregations

ArrayList (java.util.ArrayList)3 BucketCounter (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter)3 BigInteger (java.math.BigInteger)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 BucketId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId)2 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.BucketsBuilder)2 BucketCounterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterBuilder)2 BucketCounterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterKey)2 BucketStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats)2 List (java.util.List)1 Test (org.junit.Test)1 VersionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)1 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)1 MultipartReplyGroupStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStatsBuilder)1 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)1 DurationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.DurationBuilder)1 GroupStats (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats)1 GroupStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder)1 GroupStatsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsKey)1 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)1