use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup 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.multipart.reply.group._case.MultipartReplyGroup 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.multipart.reply.group._case.MultipartReplyGroup 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.multipart.reply.group._case.MultipartReplyGroup 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testGroupSerialize.
@Test
public void testGroupSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(6));
MultipartReplyGroupCaseBuilder groupCase = new MultipartReplyGroupCaseBuilder();
MultipartReplyGroupBuilder group = new MultipartReplyGroupBuilder();
group.setGroupStats(createGroupStats());
groupCase.setMultipartReplyGroup(group.build());
builder.setMultipartReplyBody(groupCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUP.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
MultipartReplyGroupCase body = (MultipartReplyGroupCase) message.getMultipartReplyBody();
MultipartReplyGroup messageOutput = body.getMultipartReplyGroup();
GroupStats groupStats = messageOutput.getGroupStats().get(0);
Assert.assertEquals("Wrong length", 56, serializedBuffer.readShort());
serializedBuffer.skipBytes(2);
Assert.assertEquals("Wrong group id", groupStats.getGroupId().getValue().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong ref count", groupStats.getRefCount().intValue(), serializedBuffer.readInt());
serializedBuffer.skipBytes(4);
Assert.assertEquals("Wrong Packet count", groupStats.getPacketCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong Byte count", groupStats.getByteCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong duration sec", groupStats.getDurationSec().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong duration nsec", groupStats.getDurationNsec().intValue(), serializedBuffer.readInt());
BucketStats bucketStats = groupStats.getBucketStats().get(0);
Assert.assertEquals("Wrong Packet count", bucketStats.getPacketCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong Byte count", bucketStats.getByteCount().longValue(), serializedBuffer.readLong());
}
Aggregations