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 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());
}
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 GroupDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyGroupCase groupCase = mock(MultipartReplyGroupCase.class);
final MultipartReplyGroup group = mock(MultipartReplyGroup.class);
final GroupStats groupStat = new GroupStatsBuilder().setGroupId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId(GROUP_NO)).setByteCount(BigInteger.ONE).setPacketCount(BigInteger.ONE).setBucketStats(Collections.emptyList()).setDurationSec(1L).setDurationNsec(1L).setRefCount(0L).build();
final List<GroupStats> groupStats = Collections.singletonList(groupStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(group.getGroupStats()).thenReturn(groupStats);
when(groupCase.getMultipartReplyGroup()).thenReturn(group);
when(reply.getMultipartReplyBody()).thenReturn(groupCase);
final GetGroupStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getGroupStats().size() > 0);
final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stats = output.getGroupStats().get(0);
assertEquals(stats.getGroupId().getValue(), GROUP_NO);
}
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 serializeGroupBody.
private void serializeGroupBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
MultipartReplyGroupCase groupCase = (MultipartReplyGroupCase) body;
MultipartReplyGroup group = groupCase.getMultipartReplyGroup();
for (GroupStats groupStats : group.getGroupStats()) {
ByteBuf groupStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
groupStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
groupStatsBuff.writeZero(GROUP_STATS_PADDING_1);
groupStatsBuff.writeInt(groupStats.getGroupId().getValue().intValue());
groupStatsBuff.writeInt(groupStats.getRefCount().intValue());
groupStatsBuff.writeZero(GROUP_STATS_PADDING_2);
groupStatsBuff.writeLong(groupStats.getPacketCount().longValue());
groupStatsBuff.writeLong(groupStats.getByteCount().longValue());
groupStatsBuff.writeInt(groupStats.getDurationSec().intValue());
groupStatsBuff.writeInt(groupStats.getDurationNsec().intValue());
for (BucketStats bucketStats : groupStats.getBucketStats()) {
groupStatsBuff.writeLong(bucketStats.getPacketCount().longValue());
groupStatsBuff.writeLong(bucketStats.getByteCount().longValue());
}
groupStatsBuff.setShort(GROUP_STATS_LENGTH_INDEX, groupStatsBuff.readableBytes());
outBuffer.writeBytes(groupStatsBuff);
}
}
Aggregations