use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase in project openflowplugin by opendaylight.
the class GroupDirectStatisticsService method buildReply.
@Override
protected GetGroupStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<GroupStats> groupStats = new ArrayList<>();
if (success) {
for (final MultipartReply mpReply : input) {
final MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody();
final MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
final Optional<List<GroupStats>> groupStatsList = getConvertorExecutor().convert(replyBody.getGroupStats(), data);
groupStatsList.ifPresent(groupStats::addAll);
}
}
return new GetGroupStatisticsOutputBuilder().setGroupStats(groupStats).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorUtil method translateGroup.
private static MultipartReplyGroupStats translateGroup(final MultipartReply msg, final VersionDatapathIdConvertorData data, final ConvertorExecutor convertorExecutor) {
MultipartReplyGroupStatsBuilder message = new MultipartReplyGroupStatsBuilder();
MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) msg.getMultipartReplyBody();
MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
final Optional<List<GroupStats>> groupStatsList = convertorExecutor.convert(replyBody.getGroupStats(), data);
message.setGroupStats(groupStatsList.orElse(Collections.emptyList()));
return message.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testMultipartReplyGroupBody.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyGroupBody() {
ByteBuf bb = BufferHelper.buildBuffer("00 06 00 01 00 00 00 00 " + // length
"00 48 " + // pad1
"00 00 " + // groupId
"00 00 00 10 " + // refCount
"00 00 00 12 " + // pad2
"00 00 00 00 " + // packetCount
"FF 01 01 01 01 01 01 01 " + // byteCount
"FF 01 01 01 01 01 01 01 " + // durationSec
"00 00 00 08 " + // durationNsec
"00 00 00 09 " + // packetCountBucket
"FF 01 01 01 01 01 01 01 " + // byteCountBucket
"FF 01 01 01 01 01 01 01 " + // packetCountBucket_2
"FF 02 02 02 02 02 02 02 " + // byteCountBucket_2
"FF 02 02 02 02 02 02 02 " + // length_2
"00 48 " + // pad1.2
"00 00 " + // groupId_2
"00 00 00 10 " + // refCount_2
"00 00 00 12 " + // pad2.2
"00 00 00 00 " + // packetCount_2
"FF 01 01 01 01 01 01 01 " + // byteCount_2
"FF 01 01 01 01 01 01 01 " + // durationSec_2
"00 00 00 08 " + // durationNsec_2
"00 00 00 09 " + // packetCountBucket_1.2
"FF 01 01 01 01 01 01 01 " + // byteCountBucket_1.2
"FF 01 01 01 01 01 01 01 " + // packetCountBucket_2.2
"FF 02 02 02 02 02 02 02 " + // byteCountBucket_2.2
"FF 02 02 02 02 02 02 02");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyGroupCase messageCase = (MultipartReplyGroupCase) builtByFactory.getMultipartReplyBody();
MultipartReplyGroup message = messageCase.getMultipartReplyGroup();
Assert.assertEquals("Wrong groupId", 16, message.getGroupStats().get(0).getGroupId().getValue().intValue());
Assert.assertEquals("Wrong refCount", 18, message.getGroupStats().get(0).getRefCount().intValue());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(0).getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(0).getByteCount());
Assert.assertEquals("Wrong durationSec", 8, message.getGroupStats().get(0).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 9, message.getGroupStats().get(0).getDurationNsec().intValue());
Assert.assertEquals("Wrong packetCountBucket", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(0).getBucketStats().get(0).getPacketCount());
Assert.assertEquals("Wrong byteCountBucket", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(0).getBucketStats().get(0).getByteCount());
Assert.assertEquals("Wrong packetCountBucket_2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getGroupStats().get(0).getBucketStats().get(1).getPacketCount());
Assert.assertEquals("Wrong byteCountBucket_2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getGroupStats().get(0).getBucketStats().get(1).getByteCount());
Assert.assertEquals("Wrong groupId_2", 16, message.getGroupStats().get(1).getGroupId().getValue().intValue());
Assert.assertEquals("Wrong refCount_2", 18, message.getGroupStats().get(1).getRefCount().intValue());
Assert.assertEquals("Wrong packetCount_2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(1).getPacketCount());
Assert.assertEquals("Wrong byteCount_2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(1).getByteCount());
Assert.assertEquals("Wrong durationSec_2", 8, message.getGroupStats().get(1).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec_2", 9, message.getGroupStats().get(1).getDurationNsec().intValue());
Assert.assertEquals("Wrong packetCountBucket_1.2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(1).getBucketStats().get(0).getPacketCount());
Assert.assertEquals("Wrong byteCountBucket_1.2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getGroupStats().get(1).getBucketStats().get(0).getByteCount());
Assert.assertEquals("Wrong packetCountBucket_2.2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getGroupStats().get(1).getBucketStats().get(1).getPacketCount());
Assert.assertEquals("Wrong byteCountBucket_2.2", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getGroupStats().get(1).getBucketStats().get(1).getByteCount());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase 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.MultipartReplyGroupCase in project openflowplugin by opendaylight.
the class GroupStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform statistics to notification.
* @param mpReplyList raw multipart response from device
* @param deviceInfo device state
* @param emulatedTxId emulated transaction id
* @param convertorExecutor convertor executor
* @return notification containing flow stats
*/
public static GroupStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList, final DeviceInfo deviceInfo, final TransactionId emulatedTxId, final ConvertorExecutor convertorExecutor) {
VersionConvertorData data = new VersionConvertorData(deviceInfo.getVersion());
GroupStatisticsUpdatedBuilder notification = new GroupStatisticsUpdatedBuilder();
notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
notification.setGroupStats(new ArrayList<>());
for (MultipartReply mpReply : mpReplyList) {
MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody();
MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
final Optional<List<GroupStats>> groupStatsList = convertorExecutor.convert(replyBody.getGroupStats(), data);
groupStatsList.ifPresent(groupStats -> notification.getGroupStats().addAll(groupStats));
}
return notification.build();
}
Aggregations