use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder in project openflowplugin by opendaylight.
the class GroupStatsResponseConvertorTest method testSingleGroupStat.
/**
* Test single GroupStat conversion.
*/
@Test
public void testSingleGroupStat() {
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);
statsBuilder.setBucketStats(new ArrayList<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", 0, stat.getBuckets().getBucketCounter().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder in project openflowplugin by opendaylight.
the class GroupStatNotificationSupplierImpl method createNotification.
@Override
public GroupStatisticsUpdated createNotification(final GroupStatistics groupStatistics, final InstanceIdentifier<GroupStatistics> path) {
Preconditions.checkArgument(groupStatistics != null);
Preconditions.checkArgument(path != null);
final GroupStatisticsUpdatedBuilder builder = new GroupStatisticsUpdatedBuilder();
builder.setId(getNodeId(path));
builder.setMoreReplies(Boolean.FALSE);
// TODO : fix if it needs, but we have to ask DataStore for the NodeConnector list
builder.setNodeConnector(Collections.<NodeConnector>emptyList());
builder.setGroupStats(Collections.singletonList(new GroupStatsBuilder(groupStatistics).build()));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testGatherStatistics_group.
@Test
public void testGatherStatistics_group() throws Exception {
final MultipartType type = MultipartType.OFPMPGROUP;
final long groupIdValue = 19L;
final GroupStatsBuilder groupStatsBld = new GroupStatsBuilder().setBucketStats(Lists.newArrayList(createBucketStat(21L, 42L))).setByteCount(BigInteger.valueOf(84L)).setPacketCount(BigInteger.valueOf(63L)).setDurationSec(11L).setDurationNsec(12L).setRefCount(13L).setGroupId(new GroupId(groupIdValue));
final MultipartReplyGroupBuilder mpReplyGroupBld = new MultipartReplyGroupBuilder();
mpReplyGroupBld.setGroupStats(Lists.newArrayList(groupStatsBld.build()));
final MultipartReplyGroupCaseBuilder mpReplyGroupCaseBld = new MultipartReplyGroupCaseBuilder();
mpReplyGroupCaseBld.setMultipartReplyGroup(mpReplyGroupBld.build());
final MultipartReply groupStatsUpdated = assembleMPReplyMessage(type, mpReplyGroupCaseBld.build());
final List<MultipartReply> statsData = Collections.singletonList(groupStatsUpdated);
fireAndCheck(type, statsData);
final InstanceIdentifier<GroupStatistics> groupPath = dummyNodePath.augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId(groupIdValue))).augmentation(NodeGroupStatistics.class).child(GroupStatistics.class);
verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(groupPath), Matchers.any(GroupStatistics.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setGroup.
private static MultipartReplyGroupCase setGroup(final ByteBuf input) {
MultipartReplyGroupCaseBuilder caseBuilder = new MultipartReplyGroupCaseBuilder();
MultipartReplyGroupBuilder builder = new MultipartReplyGroupBuilder();
List<GroupStats> groupStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder();
final int bodyLength = input.readUnsignedShort();
input.skipBytes(PADDING_IN_GROUP_HEADER_01);
groupStatsBuilder.setGroupId(new GroupId(input.readUnsignedInt()));
groupStatsBuilder.setRefCount(input.readUnsignedInt());
input.skipBytes(PADDING_IN_GROUP_HEADER_02);
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCount);
groupStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
groupStatsBuilder.setByteCount(new BigInteger(1, byteCount));
groupStatsBuilder.setDurationSec(input.readUnsignedInt());
groupStatsBuilder.setDurationNsec(input.readUnsignedInt());
int actualLength = GROUP_BODY_LENGTH;
List<BucketStats> bucketStatsList = new ArrayList<>();
while (actualLength < bodyLength) {
BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();
byte[] packetCountBucket = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCountBucket);
bucketStatsBuilder.setPacketCount(new BigInteger(1, packetCountBucket));
byte[] byteCountBucket = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCountBucket);
bucketStatsBuilder.setByteCount(new BigInteger(1, byteCountBucket));
bucketStatsList.add(bucketStatsBuilder.build());
actualLength += BUCKET_COUNTER_LENGTH;
}
groupStatsBuilder.setBucketStats(bucketStatsList);
groupStatsList.add(groupStatsBuilder.build());
}
builder.setGroupStats(groupStatsList);
caseBuilder.setMultipartReplyGroup(builder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder in project openflowplugin by opendaylight.
the class GroupStatsResponseConvertorTest method testTwoGroupStats.
/**
* Test two GroupStats conversion.
*/
@Test
public void testTwoGroupStats() {
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);
statsBuilder.setBucketStats(new ArrayList<BucketStats>());
List<GroupStats> groupStats = new ArrayList<>();
groupStats.add(statsBuilder.build());
statsBuilder = new GroupStatsBuilder();
statsBuilder.setByteCount(new BigInteger("1"));
statsBuilder.setDurationNsec(2L);
statsBuilder.setDurationSec(3L);
statsBuilder.setGroupId(new GroupId(4L));
statsBuilder.setPacketCount(new BigInteger("5"));
statsBuilder.setRefCount(6L);
statsBuilder.setBucketStats(new ArrayList<BucketStats>());
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", 2, 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 key", 42, stat.getKey().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", 0, stat.getBuckets().getBucketCounter().size());
stat = salGroupStats.get(1);
Assert.assertEquals("Wrong group-id", 4, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong key", 4, stat.getKey().getGroupId().getValue().intValue());
Assert.assertEquals("Wrong ref-count", 6, stat.getRefCount().getValue().intValue());
Assert.assertEquals("Wrong packet count", 5, stat.getPacketCount().getValue().intValue());
Assert.assertEquals("Wrong byte count", 1, stat.getByteCount().getValue().intValue());
Assert.assertEquals("Wrong duration sec", 3, stat.getDuration().getSecond().getValue().intValue());
Assert.assertEquals("Wrong duration n sec", 2, stat.getDuration().getNanosecond().getValue().intValue());
Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size());
}
Aggregations